Actual source code: receivedense.c

      1: /*
      2:    This is part of the MatlabSockettool Package. It is called by
      3:  the receive.mex4 Matlab program.
      4:
      5:         Written by Barry Smith, bsmith@mcs.anl.gov 4/14/92
      6:          Updated by Ridhard Katz, katz@ldeo.columbia.edu 9/28/03

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

     14: #include <stdio.h>
     15:  #include petscsys.h
     16: #include "mex.h"
     17: #define PETSC_MEX_ERROR(a) {fprintf(stdout,"RECEIVE %s \n",a); return -1;}
     18: /*-----------------------------------------------------------------*/
     21: PetscErrorCode ReceiveDenseMatrix(mxArray *plhs[],int t)
     22: {
     23:   int    m,n,compx = 0,i;
     24:
     25:   /* get size of matrix */
     26:   if (PetscBinaryRead(t,&m,1,PETSC_INT))   PETSC_MEX_ERROR("reading number columns");
     27:   if (PetscBinaryRead(t,&n,1,PETSC_INT))   PETSC_MEX_ERROR("reading number rows");
     28:   if (PetscBinaryRead(t,&compx,1,PETSC_INT))   PETSC_MEX_ERROR("reading if complex");
     29:
     30:   /*allocate matrix */
     31:   plhs[0]  = mxCreateDoubleMatrix(m,n,compx);
     32:   /* read in matrix */
     33:   if (!compx) {
     34:     if (PetscBinaryRead(t,mxGetPr(plhs[0]),n*m,PETSC_DOUBLE)) PETSC_MEX_ERROR("read dense matrix");
     35:   } else {
     36:     for (i=0; i<n*m; i++) {
     37:       if (PetscBinaryRead(t,mxGetPr(plhs[0])+i,1,PETSC_DOUBLE))PETSC_MEX_ERROR("read dense matrix");
     38:       if (PetscBinaryRead(t,mxGetPi(plhs[0])+i,1,PETSC_DOUBLE))PETSC_MEX_ERROR("read dense matrix");
     39:     }
     40:   }
     41:   return 0;
     42: }

     46: PetscErrorCode ReceiveDenseIntMatrix(mxArray *plhs[],int t)
     47: {
     48:   int            m,compx = 0,i,*array;
     49:   double         *values;
     51:
     52:   /* get size of matrix */
     53:   PetscBinaryRead(t,&m,1,PETSC_INT); if (ierr) PETSC_MEX_ERROR("reading number columns");
     54:
     55:   /*allocate matrix */
     56:   plhs[0] = mxCreateDoubleMatrix(m,1,mxREAL);

     58:   /* read in matrix */
     59:   array = (int*) malloc(m*sizeof(int)); if (!array) PETSC_MEX_ERROR("reading allocating space");
     60:   PetscBinaryRead(t,array,m,PETSC_INT); if (ierr) PETSC_MEX_ERROR("read dense matrix");

     62:   values = mxGetPr(plhs[0]);
     63:   for (i =0; i<m; i++) {
     64:     values[i] = array[i];
     65:   }
     66:   free(array);

     68:   return 0;
     69: }
     70:
     71: