Actual source code: receive.c
1: /*$Id: receive.c,v 1.18 2001/03/23 23:19:53 balay Exp $*/
2: /*
3:
4: This is a MATLAB Mex program which waits at a particular
5: portnumber until a matrix arrives,it then returns to
6: matlab with that matrix.
8: Usage: A = receive(portnumber); portnumber obtained with openport();
9:
10: Written by Barry Smith, bsmith@mcs.anl.gov 4/14/92
11: Updated by Ridhard Katz, katz@ldeo.columbia.edu 9/28/03
13: Since this is called from Matlab it cannot be compiled with C++.
14: */
16: #include <stdio.h>
17: #include petscsys.h
18: #include src/sys/src/viewer/impls/socket/socket.h
19: #include "mex.h"
20: EXTERN int ReceiveSparseMatrix(mxArray **,int);
21: EXTERN int ReceiveDenseIntMatrix(mxArray **,int);
22: EXTERN int ReceiveDenseMatrix(mxArray **,int);
24: #define ERROR(a) {fprintf(stdout,"RECEIVE: %s \n",a); return ;}
25: /*-----------------------------------------------------------------*/
26: /* */
27: /*-----------------------------------------------------------------*/
30: void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
31: {
32: int type,t;
34: /* check output parameters */
35: if (nlhs != 1) ERROR("Receive requires one output argument.");
37: if (!nrhs) ERROR("Receive requires one input argument.");
38: t = (int)*mxGetPr(prhs[0]);
40: /* get type of matrix */
41: if (PetscBinaryRead(t,&type,1,PETSC_INT)) ERROR("reading type");
43: if (type == DENSEREAL) ReceiveDenseMatrix(plhs,t);
44: if (type == DENSEINT) ReceiveDenseIntMatrix(plhs,t);
45: if (type == DENSECHARACTER) {
46: if (ReceiveDenseMatrix(plhs,t)) return;
47: /* mxSetDispMode(plhs[0],1); */
48: }
49: if (type == SPARSEREAL) ReceiveSparseMatrix(plhs,t);
50: return;
51: }