Actual source code: receive.c

      1: /*
      2:
      3:   This is a MATLAB Mex program which waits at a particular
      4:   portnumber until a matrix arrives,it then returns to
      5:   matlab with that matrix.

      7:   Usage: A = receive(portnumber);  portnumber obtained with openport();
      8:
      9:         Written by Barry Smith, bsmith@mcs.anl.gov 4/14/92
     10:          Updated by Ridhard Katz, katz@ldeo.columbia.edu 9/28/03

     12:   Since this is called from Matlab it cannot be compiled with C++.
     13: */

     15: #include <stdio.h>
     16:  #include petscsys.h
     17:  #include src/sys/src/viewer/impls/socket/socket.h
     18: #include "mex.h"
     19: EXTERN PetscErrorCode ReceiveSparseMatrix(mxArray **,int);
     20: EXTERN PetscErrorCode ReceiveDenseIntMatrix(mxArray **,int);
     21: EXTERN PetscErrorCode ReceiveDenseMatrix(mxArray **,int);

     23: #define PETSC_MEX_ERROR(a) {fprintf(stdout,"RECEIVE: %s \n",a); return ;}
     24: /*-----------------------------------------------------------------*/
     25: /*                                                                 */
     26: /*-----------------------------------------------------------------*/
     29: void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
     30: {
     31:  int    type,t;

     33:   /* check output parameters */
     34:   if (nlhs != 1) PETSC_MEX_ERROR("Receive requires one output argument.");

     36:   if (!nrhs) PETSC_MEX_ERROR("Receive requires one input argument.");
     37:   t = (int)*mxGetPr(prhs[0]);

     39:   /* get type of matrix */
     40:   if (PetscBinaryRead(t,&type,1,PETSC_INT))   PETSC_MEX_ERROR("reading type");

     42:   if (type == DENSEREAL) ReceiveDenseMatrix(plhs,t);
     43:   if (type == DENSEINT) ReceiveDenseIntMatrix(plhs,t);
     44:   if (type == DENSECHARACTER) {
     45:     if (ReceiveDenseMatrix(plhs,t)) return;
     46:     /* mxSetDispMode(plhs[0],1); */
     47:   }
     48:   if (type == SPARSEREAL) ReceiveSparseMatrix(plhs,t);
     49:   return;
     50: }