| 1 | // |
| 2 | // UFPE_BioSig.c |
| 3 | // Biosig interface in IGOR |
| 4 | // |
| 5 | |
| 6 | #include "../biosig.h" |
| 7 | |
| 8 | #include "XOPStandardHeaders.h" // Include ANSI headers, Mac headers, IgorXOP.h, XOP.h and XOPSupport.h |
| 9 | |
| 10 | static HDRTYPE *hdr = NULL; |
| 11 | |
| 12 | int xopSLOAD( void * ); // ...Handle FName; Handle sRes; }* p) |
| 13 | /* |
| 14 | int UFPE_BioSigOpen( void * ); // ...Handle FName; Handle sRes; }* p) |
| 15 | int UFPE_BioSigClose( void * ); // double hnd; Handle sRes; }* p) |
| 16 | int UFPE_BioSigRead( void * ); // double hnd; Handle sRes; }* p) |
| 17 | */ |
| 18 | |
| 19 | ///////////////////////////////////////////////////////////////////////////////////////// |
| 20 | |
| 21 | // SAME ORDER HERE IN '(*sFunc[])' AND IN UF_UtilsWinCustom.RC |
| 22 | /* |
| 23 | int (*)sFunc(void)[] = |
| 24 | // Der Name der Direct Call method |
| 25 | // Funktion or Message method Used that often |
| 26 | { |
| 27 | { UFPE_BioSigOpen }, |
| 28 | { UFPE_BioSigClose }, |
| 29 | // { UFPE_BioSigRead }, |
| 30 | { NULL } // Endemarkierung |
| 31 | }; |
| 32 | */ |
| 33 | //////////////////////////////////////////////////////////////////////// |
| 34 | |
| 35 | |
| 36 | typedef struct { char *FileName; waveHndl data; double res; HDRTYPE* hdr;} inSLOAD_t; |
| 37 | typedef struct { char *FileName; double res; } inSOpen_t; |
| 38 | typedef struct { double res; } inSClose_t; |
| 39 | |
| 40 | int sload( inSLOAD_t* p) |
| 41 | // IGOR wrapper for Biosig.SLoad() |
| 42 | { |
| 43 | // read header |
| 44 | hdr = sopen( p->FileName, "r", hdr ); |
| 45 | p->res = serror2(hdr); |
| 46 | if (p->res) return(0); |
| 47 | |
| 48 | // read data |
| 49 | biosig_data_type* data = NULL; |
| 50 | sread(data, 0, -1, hdr); |
| 51 | p->res = serror2(hdr); |
| 52 | if (p->res) return(0); |
| 53 | |
| 54 | // close file |
| 55 | sclose(hdr); |
| 56 | p->res = serror2(hdr); |
| 57 | return(0); |
| 58 | } |
| 59 | |
| 60 | |
| 61 | int UFPE_BioSigOpen( inSOpen_t* p) |
| 62 | // IGOR wrapper for Biosig.SOpen() |
| 63 | { |
| 64 | |
| 65 | int hState; |
| 66 | hdr = sopen( p->FileName, "r", hdr ); |
| 67 | p->res = (double)hdr->AS.B4C_ERRNUM; // |
| 68 | if ( hdr->AS.B4C_ERRNUM ) |
| 69 | { |
| 70 | char buf[500]; |
| 71 | sprintf( buf, "\t\tUFPE_BioSigOpen...receives '%s' : %s, returns code=%d \r", |
| 72 | p->FileName, hdr->AS.B4C_ERRMSG, hdr->AS.B4C_ERRNUM ); |
| 73 | XOPNotice( buf ); |
| 74 | hdr->AS.B4C_ERRNUM = B4C_NO_ERROR; |
| 75 | } |
| 76 | p->res = 0; |
| 77 | return 0; // Returning 0 prevents IGOR from doing anything with the error (no error box, no debugger) |
| 78 | } |
| 79 | |
| 80 | |
| 81 | int UFPE_BioSigClose( inSClose_t *p) |
| 82 | { |
| 83 | short code = sclose( hdr ); |
| 84 | p->res = serror2(hdr); // ..we return the error code to the calling function. After having done all that... |
| 85 | return 0; // ..we don't want IGOR to do anything with the error (no error box, no debugger) |
| 86 | } |
| 87 | |
| 88 | |
| 89 | /* |
| 90 | int UFPE_BioSigRead( struct { double ErrMode; waveHndl wDataADS; double Bytes; double StartOffset; double DataSection; double hnd; double res; }* p) |
| 91 | // IGOR wrappper for CFS ReadData() |
| 92 | // Difference to CFS: as IGOR doesn't know pointers the CFS buffer is passed as a wave |
| 93 | { |
| 94 | short hnd = (short)p->hnd; |
| 95 | WORD DataSection = (WORD)p->DataSection; |
| 96 | long StartOffset = (long)p->StartOffset; |
| 97 | WORD Bytes = (WORD)p->Bytes; |
| 98 | short code; |
| 99 | void *Raw; |
| 100 | |
| 101 | // DebugPrintWaveProperties( "UFPE_CfsReadData ", p->wDataADS ); // 050128 |
| 102 | |
| 103 | if ( p->wDataADS == NIL ) // check if wave handle is valid |
| 104 | { |
| 105 | SetNaN64( &p->res ); // return NaN if wave is not valid |
| 106 | return( NON_EXISTENT_WAVE ); |
| 107 | } |
| 108 | if ( WaveType(p->wDataADS) != NT_I16 ) // check wave's numeric type |
| 109 | { |
| 110 | SetNaN64( &p->res ); // return NaN if wave is not 2Byte int |
| 111 | return( IS_NOT_2BYTE_INT_WAVE ); |
| 112 | } |
| 113 | |
| 114 | Raw = WaveData( p->wDataADS ); // char pointer to IGOR wave data |
| 115 | |
| 116 | code = ReadData( hnd, DataSection, StartOffset, Bytes, Raw ); |
| 117 | if ( code < 0 ) |
| 118 | PrintFileError( (int)p->ErrMode ); |
| 119 | |
| 120 | p->res = (double)code; // We handle the errors here, but we also return the error code to the calling function |
| 121 | return 0; // ..we don't want IGOR to do anything with the error (no error box, no debugger) |
| 122 | } |
| 123 | |
| 124 | // END OF BIOSIG INTERFACE |
| 125 | ///////////////////////////////////////////////////////////////////////////////////////// |
| 126 | |
| 127 | */ |