/* kernel_readin.c */ #include "mex.h" #include #include #include // #define batchfilename "beamletbatch0.bin" #define BATCHNAME (prhs[0]) #define BEAMLETS (plhs[0]) // output structure void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { FILE *fid; mxArray *field, *struc; int j,k; int celldims[2]; // dimensions in the output cell array for the beamlets int dims[3]; // dimensions of sparse grids int dims2[2]; // dimensions of arrays that will hold indices and data int Nind; // number of non-zero indices int Nbeamlets; // number of beamlets in file int num; // beamlet number int *intPtr; float *floatPtr; char errstr[200]; const int one = 1; char *batchfilename; // beamlet batch file name // information for sparse output data: int nfields = 6; const char *field_names[6] = {"num","x_count","y_count","z_count", "non_zero_indices","non_zero_values"}; batchfilename = mxArrayToString(BATCHNAME); // open the beamlet batch file if ((fid = fopen(batchfilename,"rb")) == NULL) { sprintf(errstr,"Failed to open beamlet batch file %s\n",batchfilename); mexErrMsgTxt(errstr); } // read in the number of beamlets that are in the batch file if (fread(&Nbeamlets,sizeof(int),1,fid) != 1) { sprintf(errstr,"Error reading the number of beamlets from %s\n",batchfilename); mexErrMsgTxt(errstr); } // declare the BEAMLETS structure celldims[0] = 1; celldims[1] = Nbeamlets; if ((BEAMLETS = mxCreateCellArray(2,celldims)) == NULL) mexErrMsgTxt("Error in the declaration of the beamlets cell array.\n"); // read in each of the beamlets from the file for (k=0;k