| 1 | /* |
| 2 | |
| 3 | Copyright (C) 2013 Alois Schloegl <[email protected]> |
| 4 | Copyright (C) 1999 Wavematrix, Inc. Lake Oswego OR, USA |
| 5 | |
| 6 | This file is part of the "BioSig for C/C++" repository |
| 7 | (biosig4c++) at http://biosig.sf.net/ |
| 8 | |
| 9 | |
| 10 | BioSig is free software; you can redistribute it and/or |
| 11 | modify it under the terms of the GNU General Public License |
| 12 | as published by the Free Software Foundation; either version 3 |
| 13 | of the License, or (at your option) any later version. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | |
| 27 | // IgorBin.h -- structures and #defines for dealing with Igor binary data. |
| 28 | |
| 29 | #include <inttypes.h> |
| 30 | |
| 31 | #ifdef __cplusplus |
| 32 | extern "C" { |
| 33 | #endif |
| 34 | |
| 35 | // All structures written to disk are 2-byte-aligned. |
| 36 | #if __GNUC__ |
| 37 | #pragma pack(push,2) |
| 38 | /* |
| 39 | igor uses a 32bit memory model, all pointers are 32 bit. |
| 40 | in order to keep the structs containing poiners aligned, |
| 41 | all pointers need to be remapped to uint32_t. |
| 42 | */ |
| 43 | #define ptr_t uint32_t |
| 44 | #define Handle uint32_t |
| 45 | #elif GENERATINGPOWERPC |
| 46 | #pragma options align=mac68k |
| 47 | #endif |
| 48 | |
| 49 | |
| 50 | // From IgorMath.h |
| 51 | #define NT_CMPLX 1 // Complex numbers. |
| 52 | #define NT_FP32 2 // 32 bit fp numbers. |
| 53 | #define NT_FP64 4 // 64 bit fp numbers. |
| 54 | #define NT_I8 8 // 8 bit signed integer. Requires Igor Pro 2.0 or later. |
| 55 | #define NT_I16 0x10 // 16 bit integer numbers. Requires Igor Pro 2.0 or later. |
| 56 | #define NT_I32 0x20 // 32 bit integer numbers. Requires Igor Pro 2.0 or later. |
| 57 | #define NT_UNSIGNED 0x40 // Makes above signed integers unsigned. Requires Igor Pro 3.0 or later. |
| 58 | |
| 59 | |
| 60 | // From wave.h |
| 61 | #define MAXDIMS 4 |
| 62 | |
| 63 | |
| 64 | // From binary.h |
| 65 | |
| 66 | typedef struct BinHeader1 { |
| 67 | int16_t version; // Version number for backwards compatibility. |
| 68 | int32_t wfmSize; // The size of the WaveHeader2 data structure plus the wave data plus 16 bytes of padding. |
| 69 | int16_t checksum; // Checksum over this header and the wave header. |
| 70 | } BinHeader1; |
| 71 | |
| 72 | typedef struct BinHeader2 { |
| 73 | int16_t version; // Version number for backwards compatibility. |
| 74 | int32_t wfmSize; // The size of the WaveHeader2 data structure plus the wave data plus 16 bytes of padding. |
| 75 | int32_t noteSize; // The size of the note text. |
| 76 | int32_t pictSize; // Reserved. Write zero. Ignore on read. |
| 77 | int16_t checksum; // Checksum over this header and the wave header. |
| 78 | } BinHeader2; |
| 79 | |
| 80 | typedef struct BinHeader3 { |
| 81 | int16_t version; // Version number for backwards compatibility. |
| 82 | int32_t wfmSize; // The size of the WaveHeader2 data structure plus the wave data plus 16 bytes of padding. |
| 83 | int32_t noteSize; // The size of the note text. |
| 84 | int32_t formulaSize; // The size of the dependency formula, if any. |
| 85 | int32_t pictSize; // Reserved. Write zero. Ignore on read. |
| 86 | int16_t checksum; // Checksum over this header and the wave header. |
| 87 | } BinHeader3; |
| 88 | |
| 89 | typedef struct BinHeader5 { |
| 90 | int16_t version; // Version number for backwards compatibility. |
| 91 | int16_t checksum; // Checksum over this header and the wave header. |
| 92 | int32_t wfmSize; // The size of the WaveHeader5 data structure plus the wave data. |
| 93 | int32_t formulaSize; // The size of the dependency formula, if any. |
| 94 | int32_t noteSize; // The size of the note text. |
| 95 | int32_t dataEUnitsSize; // The size of optional extended data units. |
| 96 | int32_t dimEUnitsSize[MAXDIMS]; // The size of optional extended dimension units. |
| 97 | int32_t dimLabelsSize[MAXDIMS]; // The size of optional dimension labels. |
| 98 | int32_t sIndicesSize; // The size of string indicies if this is a text wave. |
| 99 | int32_t optionsSize1; // Reserved. Write zero. Ignore on read. |
| 100 | int32_t optionsSize2; // Reserved. Write zero. Ignore on read. |
| 101 | } BinHeader5; |
| 102 | |
| 103 | |
| 104 | // From wave.h |
| 105 | |
| 106 | #define MAX_WAVE_NAME2 18 // Maximum length of wave name in version 1 and 2 files. Does not include the trailing null. |
| 107 | #define MAX_WAVE_NAME5 31 // Maximum length of wave name in version 5 files. Does not include the trailing null. |
| 108 | #define MAX_UNIT_CHARS 3 |
| 109 | |
| 110 | // Header to an array of waveform data. |
| 111 | |
| 112 | struct WaveHeader2 { |
| 113 | int16_t type; // See types (e.g. NT_FP64) above. Zero for text waves. |
| 114 | // struct WaveHeader2 **next; // Used in memory only. Write zero. Ignore on read. |
| 115 | ptr_t next; |
| 116 | |
| 117 | char bname[MAX_WAVE_NAME2+2]; // Name of wave plus trailing null. |
| 118 | int16_t whVersion; // Write 0. Ignore on read. |
| 119 | int16_t srcFldr; // Used in memory only. Write zero. Ignore on read. |
| 120 | Handle fileName; // Used in memory only. Write zero. Ignore on read. |
| 121 | |
| 122 | char dataUnits[MAX_UNIT_CHARS+1]; // Natural data units go here - null if none. |
| 123 | char xUnits[MAX_UNIT_CHARS+1]; // Natural x-axis units go here - null if none. |
| 124 | |
| 125 | int32_t npnts; // Number of data points in wave. |
| 126 | |
| 127 | int16_t aModified; // Used in memory only. Write zero. Ignore on read. |
| 128 | double hsA,hsB; // X value for point p = hsA*p + hsB |
| 129 | |
| 130 | int16_t wModified; // Used in memory only. Write zero. Ignore on read. |
| 131 | int16_t swModified; // Used in memory only. Write zero. Ignore on read. |
| 132 | int16_t fsValid; // True if full scale values have meaning. |
| 133 | double topFullScale,botFullScale; // The min full scale value for wave. |
| 134 | |
| 135 | char useBits; // Used in memory only. Write zero. Ignore on read. |
| 136 | char kindBits; // Reserved. Write zero. Ignore on read. |
| 137 | //void **formula; // Used in memory only. Write zero. Ignore on read. |
| 138 | ptr_t formula; |
| 139 | |
| 140 | int32_t depID; // Used in memory only. Write zero. Ignore on read. |
| 141 | uint32_t creationDate; // DateTime of creation. Not used in version 1 files. |
| 142 | char wUnused[2]; // Reserved. Write zero. Ignore on read. |
| 143 | |
| 144 | uint32_t modDate; // DateTime of last modification. |
| 145 | Handle waveNoteH; // Used in memory only. Write zero. Ignore on read. |
| 146 | |
| 147 | float wData[4]; // The start of the array of waveform data. |
| 148 | }; |
| 149 | typedef struct WaveHeader2 WaveHeader2; |
| 150 | typedef WaveHeader2 *WavePtr2; |
| 151 | typedef WavePtr2 *waveHandle2; |
| 152 | |
| 153 | |
| 154 | struct WaveHeader5 { |
| 155 | //struct WaveHeader5 **next; // link to next wave in linked list. |
| 156 | ptr_t next; |
| 157 | |
| 158 | uint32_t creationDate; // DateTime of creation. |
| 159 | uint32_t modDate; // DateTime of last modification. |
| 160 | |
| 161 | int32_t npnts; // Total number of points (multiply dimensions up to first zero). |
| 162 | int16_t type; // See types (e.g. NT_FP64) above. Zero for text waves. |
| 163 | int16_t dLock; // Reserved. Write zero. Ignore on read. |
| 164 | |
| 165 | char whpad1[6]; // Reserved. Write zero. Ignore on read. |
| 166 | int16_t whVersion; // Write 1. Ignore on read. |
| 167 | char bname[MAX_WAVE_NAME5+1]; // Name of wave plus trailing null. |
| 168 | int32_t whpad2; // Reserved. Write zero. Ignore on read. |
| 169 | //struct DataFolder **dFolder; // Used in memory only. Write zero. Ignore on read. |
| 170 | ptr_t dFolder; |
| 171 | |
| 172 | // Dimensioning info. [0] == rows, [1] == cols etc |
| 173 | int32_t nDim[MAXDIMS]; // Number of of items in a dimension -- 0 means no data. |
| 174 | double sfA[MAXDIMS]; // Index value for element e of dimension d = sfA[d]*e + sfB[d]. |
| 175 | double sfB[MAXDIMS]; |
| 176 | |
| 177 | // SI units |
| 178 | char dataUnits[MAX_UNIT_CHARS+1]; // Natural data units go here - null if none. |
| 179 | char dimUnits[MAXDIMS][MAX_UNIT_CHARS+1]; // Natural dimension units go here - null if none. |
| 180 | |
| 181 | int16_t fsValid; // TRUE if full scale values have meaning. |
| 182 | int16_t whpad3; // Reserved. Write zero. Ignore on read. |
| 183 | double topFullScale,botFullScale; // The max and max full scale value for wave. |
| 184 | |
| 185 | Handle dataEUnits; // Used in memory only. Write zero. Ignore on read. |
| 186 | Handle dimEUnits[MAXDIMS]; // Used in memory only. Write zero. Ignore on read. |
| 187 | Handle dimLabels[MAXDIMS]; // Used in memory only. Write zero. Ignore on read. |
| 188 | |
| 189 | Handle waveNoteH; // Used in memory only. Write zero. Ignore on read. |
| 190 | int32_t whUnused[16]; // Reserved. Write zero. Ignore on read. |
| 191 | |
| 192 | // The following stuff is considered private to Igor. |
| 193 | |
| 194 | int16_t aModified; // Used in memory only. Write zero. Ignore on read. |
| 195 | int16_t wModified; // Used in memory only. Write zero. Ignore on read. |
| 196 | int16_t swModified; // Used in memory only. Write zero. Ignore on read. |
| 197 | |
| 198 | char useBits; // Used in memory only. Write zero. Ignore on read. |
| 199 | char kindBits; // Reserved. Write zero. Ignore on read. |
| 200 | //void **formula; // Used in memory only. Write zero. Ignore on read. |
| 201 | ptr_t formula; |
| 202 | int32_t depID; // Used in memory only. Write zero. Ignore on read. |
| 203 | |
| 204 | int16_t whpad4; // Reserved. Write zero. Ignore on read. |
| 205 | int16_t srcFldr; // Used in memory only. Write zero. Ignore on read. |
| 206 | Handle fileName; // Used in memory only. Write zero. Ignore on read. |
| 207 | |
| 208 | //int32_t **sIndices; // Used in memory only. Write zero. Ignore on read. |
| 209 | ptr_t sIndices; |
| 210 | |
| 211 | float wData[1]; // The start of the array of data. Must be 64 bit aligned. |
| 212 | }; |
| 213 | typedef struct WaveHeader5 WaveHeader5; |
| 214 | typedef WaveHeader5 *WavePtr5; |
| 215 | typedef WavePtr5 *WaveHandle5; |
| 216 | |
| 217 | #if __GNUC__ |
| 218 | #pragma pack(pop) |
| 219 | #undef ptr_t |
| 220 | #undef Handle |
| 221 | #elif GENERATINGPOWERPC |
| 222 | #pragma options align=reset |
| 223 | #endif |
| 224 | |
| 225 | // All structures written to disk are 2-byte-aligned. |
| 226 | |
| 227 | #ifdef __cplusplus |
| 228 | } |
| 229 | #endif |