- Timestamp:
- 09/18/09 12:17:47 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/matlabread/matlabread.cc
r88 r102 4 4 // Use 'mex matlabread.cc RawDataCTX.o' in Matlab to compile. 5 5 // 6 // Oliver Grimm, July 2009 6 // When called with an empy filename, the previously open data file will be used. 7 // 8 // Oliver Grimm, September 2009 7 9 8 10 … … 14 16 15 17 18 // static declaration keep variable alive over invocations of mex file 19 static RawDataCTX *RD = NULL; 20 21 // Exit function called when Matlab is terminated (RD==NULL is OK for delete) 22 void ExitFcn() { 23 delete RD; 24 } 25 16 26 // Interface function to Matlab 17 27 void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { 28 29 mexAtExit(*ExitFcn); // Exit function to call when matlab terminates 18 30 19 RawDataCTX*RD = new RawDataCTX(true); // Instantiate without console output31 if (RD == NULL) RD = new RawDataCTX(true); // Instantiate without console output 20 32 21 33 // Check inputs and output arguments … … 23 35 mexErrMsgTxt("Usage: [Data TrigCells RHeader BStructs EHeader] = matlabread('Filename', EventNo)"); 24 36 } 25 26 switch (RD->OpenDataFile(mxArrayToString(prhs[0]), NULL)) { 27 case CTX_FOPEN: mexErrMsgTxt("Could not open file."); 28 case CTX_RHEADER: mexErrMsgTxt("Could not read run header."); 29 case CTX_BSTRUCT: mexErrMsgTxt("Could not read board structures."); 37 38 char *Filename = mxArrayToString(prhs[0]); 39 if (Filename == NULL) mexErrMsgTxt("Could not create filename string."); 40 41 if (strlen(Filename) != 0) { 42 switch (RD->OpenDataFile(Filename), NULL) { 43 case CTX_FOPEN: mexErrMsgTxt("Could not open file."); 44 case CTX_RHEADER: mexErrMsgTxt("Could not read run header."); 45 case CTX_BSTRUCT: mexErrMsgTxt("Could not read board structures."); 46 } 47 if (RD->RHeader->MagicNum == MAGICNUM_OPEN) { 48 mexWarnMsgTxt("Magic number in run header indicates that the file has not " 49 "been closed properly."); 50 } 51 if (RD->RHeader->MagicNum == MAGICNUM_ERROR) { 52 mexWarnMsgTxt("Magic number in run header indicates that an error occurred " 53 "while writing the file."); 54 } 30 55 } 31 if (RD->RHeader->MagicNum == MAGICNUM_OPEN) { 32 mexWarnMsgTxt("Magic number in run header indicates that the file has not " 33 "been closed properly."); 34 } 35 if (RD->RHeader->MagicNum == MAGICNUM_ERROR) { 36 mexWarnMsgTxt("Magic number in run header indicates that an error occurred " 37 "while writing the file."); 38 } 39 56 mxFree(Filename); 57 40 58 // ...some abbrevation for convenience 41 59 unsigned int Boards = RD->RHeader->NBoards; … … 44 62 unsigned int Samples = RD->RHeader->Samples; 45 63 46 // Print header data64 // Read event 47 65 if(RD->ReadEvent(mxIsDouble(prhs[1]) ? (int) mxGetScalar(prhs[1]):0, NULL) != CTX_OK) { 48 66 mexErrMsgTxt("Could not read event."); 49 67 } 50 68 51 while(true) { // Dummy loop to allow different number of return values (break will be issued depending on nlhs) 52 69 // Dummy loop to allow different return values (break will be issued depending on nlhs) 70 while(true) { 71 53 72 // ========= Data array ========== 54 73 … … 175 194 if (nlhs>=5) break; 176 195 177 } // Dummy while loop 178 179 180 delete RD; 196 } // Dummy while loop 181 197 }
Note:
See TracChangeset
for help on using the changeset viewer.