| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
#include <ctype.h> |
| 27 |
#include <stdlib.h> |
| 28 |
#include <string.h> |
| 29 |
|
| 30 |
#include "../biosig.h" |
| 31 |
|
| 32 |
#define min(a,b) (((a) < (b)) ? (a) : (b)) |
| 33 |
#define max(a,b) (((a) > (b)) ? (a) : (b)) |
| 34 |
|
| 35 |
EXTERN_C void sopen_alpha_read(HDRTYPE* hdr) { |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
size_t count; |
| 46 |
unsigned int k; |
| 47 |
const char *FileName = hdr->FileName; |
| 48 |
|
| 49 |
fprintf(stdout,"Warning: support for alpha format is just experimental.\n"); |
| 50 |
|
| 51 |
char* fn = (char*)malloc(strlen(hdr->FileName)+15); |
| 52 |
strcpy(fn,hdr->FileName); |
| 53 |
|
| 54 |
const size_t bufsiz = 4096; |
| 55 |
char buf[bufsiz]; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
const char *f2 = "alpha.alp"; |
| 60 |
char *tmpstr = strrchr(fn,FILESEP); |
| 61 |
if (tmpstr) strcpy(tmpstr+1,f2); |
| 62 |
else strcpy(fn,f2); |
| 63 |
|
| 64 |
FILE *fid = fopen(fn,"r"); count = fread(buf,1,bufsiz-1,fid); fclose(fid); buf[count]=0; |
| 65 |
char *t = strtok(buf,"\xA\xD"); |
| 66 |
while (t) { |
| 67 |
|
| 68 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"0: %s \n",t); |
| 69 |
|
| 70 |
if (!strncmp(t,"Version = ",9)) |
| 71 |
hdr->VERSION = atof(t+9); |
| 72 |
else if (!strncmp(t,"Id = ",4)) { |
| 73 |
strncpy(hdr->ID.Manufacturer._field,t+5,MAX_LENGTH_MANUF); |
| 74 |
hdr->ID.Manufacturer.Name = hdr->ID.Manufacturer._field; |
| 75 |
} |
| 76 |
t = strtok(NULL,"\xA\xD"); |
| 77 |
} |
| 78 |
|
| 79 |
f2 = "rawhead"; |
| 80 |
if (tmpstr) strcpy(tmpstr+1,f2); |
| 81 |
else strcpy(fn,f2); |
| 82 |
|
| 83 |
int Notch = 0; |
| 84 |
int Bits = 0; |
| 85 |
double DigMax=0, DigMin=0; |
| 86 |
uint16_t gdftyp = 0; |
| 87 |
int ns = 0; |
| 88 |
fid = fopen(fn,"r"); count = fread(buf,1,bufsiz-1,fid); fclose(fid); buf[count]=0; |
| 89 |
t = strtok(buf,"\xA\xD"); |
| 90 |
char STATUS = 1; |
| 91 |
uint32_t *ChanOrder=NULL; |
| 92 |
char **ChanType = NULL; |
| 93 |
while ((t!=NULL) && (STATUS<9)) { |
| 94 |
char *t1 = strchr(t,'='); |
| 95 |
|
| 96 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"<%6.2f> %i- %s | %s\n",hdr->VERSION, STATUS,t,t1); |
| 97 |
|
| 98 |
if (t1) { |
| 99 |
t1[-1] = 0; t1++; |
| 100 |
|
| 101 |
if (STATUS == 1) { |
| 102 |
if (!strcmp(t,"Version")) |
| 103 |
hdr->VERSION = atof(t1); |
| 104 |
else if (!strcmp(t,"BitsPerValue")) { |
| 105 |
Bits = atoi(t1); |
| 106 |
switch (Bits) { |
| 107 |
case 12: gdftyp = 255+12; |
| 108 |
|
| 109 |
DigMax = (1<<(Bits-1))-1; |
| 110 |
DigMin = -(1<<(Bits-1)); |
| 111 |
break; |
| 112 |
case 16: gdftyp = 3; |
| 113 |
DigMax = 32752.0; |
| 114 |
DigMin = -32736.0; |
| 115 |
break; |
| 116 |
case 32: gdftyp = 5; break; |
| 117 |
DigMax = (1<<(Bits-1))-1; |
| 118 |
DigMin = -(1<<(Bits-1)); |
| 119 |
} |
| 120 |
} |
| 121 |
else if (!strcmp(t,"ChanCount")) { |
| 122 |
hdr->NS = atoi(t1); |
| 123 |
hdr->CHANNEL = (CHANNEL_TYPE*)realloc(hdr->CHANNEL, hdr->NS*sizeof(CHANNEL_TYPE)); |
| 124 |
ChanOrder = (uint32_t*)calloc(hdr->NS,sizeof(uint32_t)*2); |
| 125 |
ChanType = (char**)calloc(hdr->NS,sizeof(char*)); |
| 126 |
|
| 127 |
} |
| 128 |
else if (!strcmp(t,"SampleFreq")) |
| 129 |
hdr->SampleRate = atof(t1); |
| 130 |
else if (!strcmp(t,"SampleCount")) { |
| 131 |
hdr->NRec = atoi(t1); |
| 132 |
hdr->SPR = 1; |
| 133 |
} |
| 134 |
else if (!strcmp(t,"NotchFreq")) |
| 135 |
Notch = atof(t1); |
| 136 |
else if (!strcmp(t,"DispFlags") && (hdr->VERSION < 411.89)) |
| 137 |
STATUS = 2; |
| 138 |
else if (!strcmp(t,"Sec2Marker") && (hdr->VERSION > 411.89)) |
| 139 |
STATUS = 2; |
| 140 |
} |
| 141 |
|
| 142 |
else if (STATUS == 2) { |
| 143 |
if (ns>=hdr->NS) { |
| 144 |
ns = 0; |
| 145 |
STATUS = 3; |
| 146 |
} |
| 147 |
else { |
| 148 |
CHANNEL_TYPE *hc = hdr->CHANNEL+ns; |
| 149 |
hc->GDFTYP = gdftyp; |
| 150 |
hc->Notch = Notch; |
| 151 |
hc->LeadIdCode = 0; |
| 152 |
hc->SPR = hdr->SPR; |
| 153 |
|
| 154 |
hc->DigMax = DigMax; |
| 155 |
hc->DigMin = DigMin; |
| 156 |
hc->OnOff = 1; |
| 157 |
hc->Cal = 1.0; |
| 158 |
hc->Off = 0.0; |
| 159 |
hc->PhysMax = hc->DigMax; |
| 160 |
hc->PhysMin = hc->DigMin; |
| 161 |
hc->Transducer[0] = 0; |
| 162 |
|
| 163 |
strncpy(hc->Label, t, MAX_LENGTH_LABEL+1); |
| 164 |
char* t2= strchr(t1,','); |
| 165 |
t2[0] = 0; while (isspace((++t2)[0])); |
| 166 |
char* t3= strchr(t2,','); |
| 167 |
t3[0] = 0; while (isspace((++t3)[0])); |
| 168 |
char* t4= strchr(t3,','); |
| 169 |
t4[0] = 0; while (isspace((++t4)[0])); |
| 170 |
|
| 171 |
ChanOrder[ns*2] = atoi(t2); |
| 172 |
ChanOrder[ns*2+1] = ns; |
| 173 |
ChanType[ns] = t3; |
| 174 |
ns++; |
| 175 |
} |
| 176 |
} |
| 177 |
else if (STATUS == 3) { |
| 178 |
|
| 179 |
char *pd = NULL; |
| 180 |
float tmp1, tmp2, HighPass, LowPass; |
| 181 |
#if !defined __STDC_VERSION__ || __STDC_VERSION__ < 199901L |
| 182 |
sscanf(t1, "%f, %f, %f, %f, %as", &HighPass,&LowPass, &tmp1,&tmp2, &pd); |
| 183 |
#else |
| 184 |
sscanf(t1, "%f, %f, %f, %f, %ms", &HighPass,&LowPass, &tmp1,&tmp2, &pd); |
| 185 |
#endif |
| 186 |
strrchr(pd,',')[0]=0; |
| 187 |
if (!strcmp(pd,"%%")) pd[1]=0; |
| 188 |
uint16_t pdc = PhysDimCode(pd); |
| 189 |
if (pd) free(pd); |
| 190 |
|
| 191 |
char flag = 0; |
| 192 |
for (k=0; k < hdr->NS; k++) { |
| 193 |
if ((ChanType[k]!=NULL) && !strcmp(t,ChanType[k])) { |
| 194 |
CHANNEL_TYPE *hc = hdr->CHANNEL+k; |
| 195 |
hc->PhysDimCode = pdc; |
| 196 |
|
| 197 |
hc->LowPass = LowPass; |
| 198 |
hc->HighPass = HighPass; |
| 199 |
ChanType[k] = NULL; |
| 200 |
} |
| 201 |
if (ChanType[k] != NULL) flag = 1; |
| 202 |
} |
| 203 |
if (!flag) STATUS = 99; |
| 204 |
} |
| 205 |
} |
| 206 |
t = strtok(NULL,"\xA\xD"); |
| 207 |
} |
| 208 |
hdr->AS.bpb8 = (GDFTYP_BITS[gdftyp]*hdr->NS); |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
qsort(ChanOrder,hdr->NS,2*sizeof(uint32_t),&u32cmp); |
| 213 |
for (k=0; k<hdr->NS; k++) { |
| 214 |
hdr->CHANNEL[ChanOrder[2*k+1]].bi8 = GDFTYP_BITS[gdftyp]*k; |
| 215 |
hdr->CHANNEL[ChanOrder[2*k+1]].bi = (GDFTYP_BITS[gdftyp]*k)>>3; |
| 216 |
} |
| 217 |
free(ChanOrder); |
| 218 |
free(ChanType); |
| 219 |
|
| 220 |
|
| 221 |
f2 = "cal_res"; |
| 222 |
if (tmpstr) strcpy(tmpstr+1,f2); |
| 223 |
else strcpy(fn,f2); |
| 224 |
|
| 225 |
fid = fopen(fn,"r"); |
| 226 |
if (fid!=NULL) { |
| 227 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"cal_res: \n"); |
| 228 |
|
| 229 |
count = fread(buf,1,bufsiz-1,fid); fclose(fid); buf[count]=0; |
| 230 |
t = strtok(buf,"\xA\xD"); |
| 231 |
t = strtok(NULL,"\xA\xD"); |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
char *t0,*t1,*t2,*t3; |
| 238 |
unsigned n=0; |
| 239 |
for (k=0; max(k,n)<hdr->NS; k++) { |
| 240 |
t = strtok(NULL,"\xA\xD"); |
| 241 |
|
| 242 |
if (t==NULL) { |
| 243 |
fprintf(stderr,"Warning SOPEN(alpha): scaling coefficients not defined for all channels\n"); |
| 244 |
break; |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
t0 = strchr(t,'=');t0[0]=0;t0++; |
| 249 |
int ix = strlen(t)-1; |
| 250 |
while ((ix>0) && isspace(t[ix])) t[ix--] = 0; |
| 251 |
t1 = strchr(t0,',');t1[0]=0;t1++; |
| 252 |
t2 = strchr(t1,',');t2[0]=0;t2++; |
| 253 |
t3 = strchr(t2,',');t3[0]=0;t3++; |
| 254 |
|
| 255 |
n = atoi(t); |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"cal_res: %i %i <%s> %s %s %s\n",k,n,t,t1,t2,t3); |
| 267 |
|
| 268 |
CHANNEL_TYPE *hc = hdr->CHANNEL + (n>0 ? n-1 : k); |
| 269 |
hc->Cal = atof(t1); |
| 270 |
hc->Off = 0; |
| 271 |
|
| 272 |
if (VERBOSE_LEVEL>7) fprintf(stdout," <%s> %s = ###, %f, %f\n", t1,hc->Label,hc->Cal,hc->Off); |
| 273 |
|
| 274 |
hc->PhysMax = (hc->DigMax - hc->Off) * hc->Cal; |
| 275 |
hc->PhysMin = (hc->DigMin - hc->Off) * hc->Cal; |
| 276 |
hc->XYZ[0]=0; |
| 277 |
hc->XYZ[1]=0; |
| 278 |
hc->XYZ[2]=0; |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
f2 = "r_info"; |
| 283 |
if (tmpstr) strcpy(tmpstr+1,f2); |
| 284 |
else strcpy(fn,f2); |
| 285 |
|
| 286 |
fid = fopen(fn,"r"); |
| 287 |
if (fid!=NULL) { |
| 288 |
|
| 289 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"r_info: \n"); |
| 290 |
|
| 291 |
count = fread(buf,1,bufsiz-1,fid); fclose(fid); buf[count]=0; |
| 292 |
struct tm T; |
| 293 |
t = strtok(buf,"\xA\xD"); |
| 294 |
t = strtok(NULL,"\xA\xD"); |
| 295 |
while (t!=NULL) { |
| 296 |
char *t1 = strchr(t,'='); |
| 297 |
t1[0] = 0; |
| 298 |
while (isspace((++t1)[0])); |
| 299 |
for (k=strlen(t); (k>0) && isspace(t[--k]); t[k]=0); |
| 300 |
for (k=strlen(t1); (k>0) && isspace(t1[--k]); t1[k]=0); |
| 301 |
|
| 302 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"r_info: %s = %s\n",t,t1); |
| 303 |
|
| 304 |
if (0) {} |
| 305 |
else if (!strcmp(t,"RecId")) |
| 306 |
strncpy(hdr->ID.Recording,t1,MAX_LENGTH_RID); |
| 307 |
else if (!strcmp(t,"RecDate")) { |
| 308 |
sscanf(t1,"%02d.%02d.%04d",&T.tm_mday,&T.tm_mon,&T.tm_year); |
| 309 |
T.tm_year -=1900; |
| 310 |
T.tm_mon -=1; |
| 311 |
} |
| 312 |
else if (!strcmp(t,"RecTime")) |
| 313 |
sscanf(t1,"%02d.%02d.%02d",&T.tm_hour,&T.tm_min,&T.tm_sec); |
| 314 |
else if (!strcmp(t,"TechSal")) { |
| 315 |
if (hdr->ID.Technician) free(hdr->ID.Technician); |
| 316 |
hdr->ID.Technician = strdup(t1); |
| 317 |
} |
| 318 |
else if (!strcmp(t,"TechTitle") || !strcmp(t,"TechLast") || !strcmp(t,"TechFirst")) { |
| 319 |
size_t l0 = strlen(hdr->ID.Technician); |
| 320 |
size_t l1 = strlen(t1); |
| 321 |
hdr->ID.Technician = (char*)realloc(hdr->ID.Technician,l0+l1+2); |
| 322 |
hdr->ID.Technician[l0] = ' '; |
| 323 |
strcpy(hdr->ID.Technician+l0+1, t1); |
| 324 |
} |
| 325 |
|
| 326 |
t = strtok(NULL,"\xA\xD"); |
| 327 |
} |
| 328 |
hdr->T0 = tm_time2gdf_time(&T); |
| 329 |
} |
| 330 |
|
| 331 |
f2 = "marker"; |
| 332 |
if (tmpstr) strcpy(tmpstr+1,f2); |
| 333 |
else strcpy(fn,f2); |
| 334 |
fid = fopen(fn,"r"); |
| 335 |
if (fid != NULL) { |
| 336 |
size_t n,N; |
| 337 |
N=0; n=0; |
| 338 |
while (!feof(fid)) { |
| 339 |
hdr->AS.auxBUF = (uint8_t*) realloc(hdr->AS.auxBUF,N+bufsiz+1); |
| 340 |
N += fread(hdr->AS.auxBUF+N, 1, bufsiz, fid); |
| 341 |
} |
| 342 |
fclose(fid); |
| 343 |
hdr->AS.auxBUF[N] = 0; |
| 344 |
|
| 345 |
N = 0; |
| 346 |
t = (char*)hdr->AS.auxBUF+strcspn((char*)hdr->AS.auxBUF,"\xA\xD"); |
| 347 |
t = t+strspn(t,"\xA\xD"); |
| 348 |
while (t[0]) { |
| 349 |
char* t1 = t; |
| 350 |
size_t l1 = strcspn(t1,"="); |
| 351 |
size_t p2 = strspn(t1+l1,"= ")+l1; |
| 352 |
char* t2 = t+p2; |
| 353 |
size_t l2 = strcspn(t2," ,"); |
| 354 |
size_t p3 = strspn(t2+l2," ,")+l2; |
| 355 |
char* t3 = t2+p3; |
| 356 |
size_t l3 = strcspn(t3," ,"); |
| 357 |
size_t p4 = strspn(t3+l3," ,")+l3; |
| 358 |
char* t4 = t3+p4; |
| 359 |
size_t l4 = strcspn(t4,"\xA\xD"); |
| 360 |
size_t p5 = strspn(t4+l4,"\xA\xD")+l4; |
| 361 |
t1[l1] = 0; |
| 362 |
while (isspace(t1[--l1])) t1[l1]=0; |
| 363 |
t2[l2] = 0; |
| 364 |
t3[l3] = 0; |
| 365 |
t4[l4] = 0; |
| 366 |
t = t4 + p5; |
| 367 |
|
| 368 |
if (n+1 >= N) { |
| 369 |
const size_t sz = 100; |
| 370 |
hdr->EVENT.TYP = (typeof(hdr->EVENT.TYP)) realloc(hdr->EVENT.TYP,(N+sz)*sizeof(*hdr->EVENT.TYP)); |
| 371 |
hdr->EVENT.POS = (typeof(hdr->EVENT.POS)) realloc(hdr->EVENT.POS,(N+sz)*sizeof(*hdr->EVENT.POS)); |
| 372 |
N += sz; |
| 373 |
} |
| 374 |
|
| 375 |
hdr->EVENT.POS[n] = atol(t3); |
| 376 |
if (!strcmp(t1,"REC")) |
| 377 |
hdr->EVENT.TYP[n] = 0x7ffe; |
| 378 |
else if (!strcmp(t1,"MON")) |
| 379 |
hdr->EVENT.TYP[n] = 0; |
| 380 |
else if (!strcmp(t1,"TXT")) |
| 381 |
FreeTextEvent(hdr, n, t4); |
| 382 |
else |
| 383 |
FreeTextEvent(hdr, n, t1); |
| 384 |
|
| 385 |
if (!strcmp(t2,"off")) |
| 386 |
hdr->EVENT.TYP[n] |= 0x8000; |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
n++; |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
} |
| 395 |
hdr->EVENT.N = n; |
| 396 |
hdr->EVENT.SampleRate = hdr->SampleRate; |
| 397 |
|
| 398 |
} |
| 399 |
|
| 400 |
tmpstr = strrchr(fn,FILESEP); |
| 401 |
tmpstr[0] = 0; |
| 402 |
tmpstr = strrchr(fn,FILESEP); |
| 403 |
f2 = "s_info"; |
| 404 |
if (tmpstr) strcpy(tmpstr+1,f2); |
| 405 |
else strcpy(fn,f2); |
| 406 |
|
| 407 |
fid = fopen(fn,"r"); |
| 408 |
if (fid!=NULL) { |
| 409 |
count = fread(buf,1,bufsiz-1,fid); fclose(fid); buf[count]=0; |
| 410 |
char *Lastname = NULL; |
| 411 |
char *Firstname = NULL; |
| 412 |
struct tm T; |
| 413 |
t = strtok(buf,"\xA\xD"); |
| 414 |
t = strtok(NULL,"\xA\xD"); |
| 415 |
while (t!=NULL) { |
| 416 |
char *t1 = strchr(t,'='); |
| 417 |
t1[0] = 0; |
| 418 |
while (isspace((++t1)[0])); |
| 419 |
for (k=strlen(t); (k>0) && isspace(t[--k]); t[k]=0); |
| 420 |
for (k=strlen(t1); (k>0) && isspace(t1[--k]); t1[k]=0); |
| 421 |
|
| 422 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"s_info: <%s> = <%s>\n",t,t1); |
| 423 |
|
| 424 |
if (0) {} |
| 425 |
else if (!strcmp(t,"SubjId")) |
| 426 |
strncpy(hdr->Patient.Id,t1,MAX_LENGTH_PID); |
| 427 |
else if (!strcmp(t,"Gender")) |
| 428 |
switch (t1[0]) { |
| 429 |
case 'm': |
| 430 |
case 'M': |
| 431 |
hdr->Patient.Sex = 1; break; |
| 432 |
case 'w': |
| 433 |
case 'W': |
| 434 |
case 'f': |
| 435 |
case 'F': |
| 436 |
hdr->Patient.Sex = 2; break; |
| 437 |
default: |
| 438 |
hdr->Patient.Sex = 0; break; |
| 439 |
} |
| 440 |
else if (!strcmp(t,"Handedness")) |
| 441 |
switch (t1[0]) { |
| 442 |
case 'r': |
| 443 |
case 'R': |
| 444 |
hdr->Patient.Handedness = 1; break; |
| 445 |
case 'l': |
| 446 |
case 'L': |
| 447 |
hdr->Patient.Handedness = 2; break; |
| 448 |
default: |
| 449 |
hdr->Patient.Handedness = 0; break; |
| 450 |
} |
| 451 |
else if (!strcmp(t,"Size")) |
| 452 |
hdr->Patient.Height = atof(t1); |
| 453 |
else if (!strcmp(t,"Weight")) |
| 454 |
hdr->Patient.Weight = atof(t1); |
| 455 |
else if (!strcmp(t,"FirstName")) { |
| 456 |
Firstname = t1; |
| 457 |
} |
| 458 |
else if (!strcmp(t,"LastName")) { |
| 459 |
Lastname = t1; |
| 460 |
} |
| 461 |
else if (!strcmp(t,"BirthDay")) { |
| 462 |
int c = sscanf(t1,"%02d.%02d.%04d",&T.tm_mday,&T.tm_mon,&T.tm_year); |
| 463 |
T.tm_year -=1900; |
| 464 |
T.tm_mon -=1; |
| 465 |
T.tm_hour =12; |
| 466 |
T.tm_min =0; |
| 467 |
T.tm_sec =0; |
| 468 |
if (c > 2) hdr->Patient.Birthday = tm_time2gdf_time(&T); |
| 469 |
} |
| 470 |
t = strtok(NULL,"\xA\xD"); |
| 471 |
} |
| 472 |
|
| 473 |
size_t l0 = strlen(Firstname); |
| 474 |
size_t l1 = strlen(Lastname); |
| 475 |
if (l0+l1+1 <= MAX_LENGTH_NAME) { |
| 476 |
strcpy(hdr->Patient.Name, Firstname); |
| 477 |
hdr->Patient.Name[l0] = ' '; |
| 478 |
strcpy(hdr->Patient.Name + l0 + 1, Lastname); |
| 479 |
} else |
| 480 |
strncpy(hdr->Patient.Name, Lastname, MAX_LENGTH_NAME+1); |
| 481 |
|
| 482 |
} |
| 483 |
|
| 484 |
strcpy(fn,hdr->FileName); |
| 485 |
tmpstr = strrchr(fn,FILESEP); |
| 486 |
f2 = "rawdata"; |
| 487 |
if (tmpstr) strcpy(tmpstr+1,f2); |
| 488 |
else strcpy(fn,f2); |
| 489 |
|
| 490 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"rawdata11: %s \n",f2); |
| 491 |
|
| 492 |
hdr->FileName = fn; |
| 493 |
ifopen(hdr,"r"); |
| 494 |
|
| 495 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"rawdata22: %s open=%i\n",f2,hdr->FILE.OPEN); |
| 496 |
if (hdr->FILE.OPEN) { |
| 497 |
int16_t a[3]; |
| 498 |
ifread(a, 2, 3, hdr); |
| 499 |
hdr->VERSION = a[0]; |
| 500 |
hdr->HeadLen = 6; |
| 501 |
|
| 502 |
switch (a[2]) { |
| 503 |
case 12: gdftyp = 255+12; break; |
| 504 |
case 16: gdftyp = 3; break; |
| 505 |
case 32: gdftyp = 5; break; |
| 506 |
} |
| 507 |
for (k=a[1]; k<hdr->NS; k++) |
| 508 |
hdr->CHANNEL[k].OnOff = 0; |
| 509 |
for (k=0; k<hdr->NS; k++) { |
| 510 |
hdr->CHANNEL[k].GDFTYP = gdftyp; |
| 511 |
} |
| 512 |
|
| 513 |
hdr->AS.bpb = (GDFTYP_BITS[gdftyp]*a[1])>>3; |
| 514 |
hdr->FILE.POS = 0; |
| 515 |
|
| 516 |
size_t len = (GDFTYP_BITS[gdftyp]*a[1]*hdr->NRec*hdr->SPR)>>3; |
| 517 |
if ((GDFTYP_BITS[gdftyp]*a[1]) & 0x07) { |
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
len++; |
| 523 |
} |
| 524 |
hdr->AS.rawdata = (uint8_t*) realloc(hdr->AS.rawdata, len); |
| 525 |
size_t count = ifread(hdr->AS.rawdata,1,len,hdr); |
| 526 |
hdr->AS.first = 0; |
| 527 |
hdr->AS.length = (count<<3)/(GDFTYP_BITS[gdftyp]*a[1]); |
| 528 |
} |
| 529 |
|
| 530 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"rawdata55: %s c=%i [%i, %i] sizeof(CHAN)=%i\n",fn,(int)count,(int)hdr->AS.first,(int)hdr->AS.length,(int)sizeof(hdr->CHANNEL[0])); |
| 531 |
|
| 532 |
free(fn); |
| 533 |
hdr->FileName = FileName; |
| 534 |
} |
| 535 |
|