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

 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 int ReceiveSparseMatrix(Matrix **,int);
 20: EXTERN int ReceiveIntDenseMatrix(Matrix **,int);

 22: #define ERROR(a) {fprintf(stdout,"RECEIVE: %s n",a); return ;}
 23: /*-----------------------------------------------------------------*/
 24: /*                                                                 */
 25: /*-----------------------------------------------------------------*/
 26: #undef __FUNCT__  
 28: void mexFunction(int nlhs,Matrix *plhs[],int nrhs,Matrix *prhs[])
 29: {
 30:  int    type,t;

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

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

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

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