Actual source code: receivedense.c
1: /*$Id: receivedense.c,v 1.15 2001/03/23 23:19:53 balay Exp $*/
2: /*
3: This is part of the MatlabSockettool Package. It is called by
4: the receive.mex4 Matlab program.
5:
6: Written by Barry Smith, bsmith@mcs.anl.gov 4/14/92
7: Updated by Ridhard Katz, katz@ldeo.columbia.edu 9/28/03
9: Since this is called from Matlab it cannot be compiled with C++.
10: */
15: #include <stdio.h>
16: #include petscsys.h
17: #include "mex.h"
18: #define ERROR(a) {fprintf(stdout,"RECEIVE %s \n",a); return -1;}
19: /*-----------------------------------------------------------------*/
22: int ReceiveDenseMatrix(mxArray *plhs[],int t)
23: {
24: int m,n,compx = 0,i;
25:
26: /* get size of matrix */
27: if (PetscBinaryRead(t,&m,1,PETSC_INT)) ERROR("reading number columns");
28: if (PetscBinaryRead(t,&n,1,PETSC_INT)) ERROR("reading number rows");
29: if (PetscBinaryRead(t,&compx,1,PETSC_INT)) ERROR("reading if complex");
30:
31: /*allocate matrix */
32: plhs[0] = mxCreateDoubleMatrix(m,n,compx);
33: /* read in matrix */
34: if (!compx) {
35: if (PetscBinaryRead(t,mxGetPr(plhs[0]),n*m,PETSC_DOUBLE)) ERROR("read dense matrix");
36: } else {
37: for (i=0; i<n*m; i++) {
38: if (PetscBinaryRead(t,mxGetPr(plhs[0])+i,1,PETSC_DOUBLE))ERROR("read dense matrix");
39: if (PetscBinaryRead(t,mxGetPi(plhs[0])+i,1,PETSC_DOUBLE))ERROR("read dense matrix");
40: }
41: }
42: return 0;
43: }
47: int ReceiveDenseIntMatrix(mxArray *plhs[],int t)
48: {
49: int m,compx = 0,i,*array;
50: double *values;
51: int ierr;
52:
53: /* get size of matrix */
54: PetscBinaryRead(t,&m,1,PETSC_INT); if (ierr) ERROR("reading number columns");
55:
56: /*allocate matrix */
57: plhs[0] = mxCreateDoubleMatrix(m,1,mxREAL);
59: /* read in matrix */
60: array = (int*) malloc(m*sizeof(int)); if (!array) ERROR("reading allocating space");
61: PetscBinaryRead(t,array,m,PETSC_INT); if (ierr) ERROR("read dense matrix");
63: values = mxGetPr(plhs[0]);
64: for (i =0; i<m; i++) {
65: values[i] = array[i];
66: }
67: free(array);
69: return 0;
70: }
71:
72: