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

  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 ERROR(a) {fprintf(stdout,"RECEIVE %s \n",a); return -1;}
 18: /*-----------------------------------------------------------------*/
 21: int ReceiveDenseMatrix(Matrix *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))   ERROR("reading number columns");
 27:   if (PetscBinaryRead(t,&n,1,PETSC_INT))   ERROR("reading number rows");
 28:   if (PetscBinaryRead(t,&compx,1,PETSC_INT))   ERROR("reading if complex");
 29: 
 30:   /*allocate matrix */
 31:   plhs[0]  = mxCreateFull(m,n,compx);
 32:   /* read in matrix */
 33:   if (!compx) {
 34:     if (PetscBinaryRead(t,mxGetPr(plhs[0]),n*m,PETSC_DOUBLE)) 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))ERROR("read dense matrix");
 38:       if (PetscBinaryRead(t,mxGetPi(plhs[0])+i,1,PETSC_DOUBLE))ERROR("read dense matrix");
 39:     }
 40:   }
 41:   return 0;
 42: }

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

 58:   /* read in matrix */
 59:   array = (int*) malloc(m*sizeof(int)); if (!array) ERROR("reading allocating space");
 60:   PetscBinaryRead(t,array,m,PETSC_INT); if (ierr) 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: