100 for (t=r; t !=
NULL; t=u)
116 fprintf(stdout,
"type: %d\n",r->type);
117 fprintf(stdout,
"name: %s\n",r->name);
118 fprintf(stdout,
"size: %d\n",r->count);
119 fprintf(stdout,
"dtype: %d\n",r->dtype);
120 for (i=0; i<r->count; i++)
124 fprintf(stdout,
" %d: %g\n",i,r->v.dval[i]);
break;
126 fprintf(stdout,
" %d: %f\n",i,r->v.fval[i]);
break;
128 fprintf(stdout,
" %d: %d\n",i,r->v.ival[i]);
break;
130 fprintf(stdout,
" %d: %d\n",i,r->v.sval[i]);
break;
132 fprintf(stdout,
" %d: %d\n",i,r->v.cval[i]);
break;
134 fprintf(stdout,
" %d: unknown\n",i);
141 char **names = hdr->field_name;
142 short *types = hdr->field_type;
143 int *dims = hdr->field_dimension;
146 hdr->field_name =
walloc(
char *,hdr->num_fields+1);
147 hdr->field_type =
walloc(
short,hdr->num_fields+1);
148 hdr->field_dimension =
walloc(
int,hdr->num_fields+1);
149 for (i=0; i < hdr->num_fields; i++)
151 hdr->field_name[i] = names[i];
152 hdr->field_type[i] = types[i];
153 hdr->field_dimension[i] = dims[i];
158 hdr->field_name[hdr->num_fields] =
wstrdup(name);
159 hdr->field_type[hdr->num_fields] = type;
160 hdr->field_dimension[hdr->num_fields] = dimension;
174 t->clength = strlen(name);
176 if (t->count < pos+1)
178 double *dval = t->v.dval;
179 t->v.dval =
walloc(
double,pos+1);
180 for (i=0; i<t->count; i++)
181 t->v.dval[i] = dval[i];
182 for (; i < pos+1; i++)
204 t->clength = strlen(name);
206 if (t->count < pos+1)
208 float *fval = t->v.fval;
209 t->v.fval =
walloc(
float,pos+1);
210 for (i=0; i<t->count; i++)
211 t->v.fval[i] = fval[i];
212 for (; i < pos+1; i++)
233 t->clength = strlen(name);
236 fprintf(stderr,
"%s",
"ESPS: add_fea_i: pos should not be < 0\n");
240 if (pos == INT_MAX) {
241 fprintf(stderr,
"%s",
"ESPS: add_fea_i: pos too large\n");
244 if (t->count < pos+1)
246 int *ival = t->v.ival;
247 t->v.ival =
walloc(
int,pos+1);
248 for (i=0; i<t->count; i++)
249 t->v.ival[i] = ival[i];
250 for (; i < pos+1; i++)
271 t->clength = strlen(name);
273 if (t->count < pos+1)
275 short *sval = t->v.sval;
276 t->v.sval =
walloc(
short,pos+1);
277 for (i=0; i<t->count; i++)
278 t->v.sval[i] = sval[i];
279 for (; i < pos+1; i++)
280 t->v.sval[i] = (
short)0;
300 t->clength = strlen(name);
302 if (t->count < pos+1)
304 char *cval = t->v.cval;
305 t->v.cval =
walloc(
char,pos+1);
306 for (i=0; i<t->count; i++)
307 t->v.cval[i] = cval[i];
308 for (; i < pos+1; i++)
309 t->v.cval[i] = (
char)0;
328 t->clength = strlen(name);
343 for (t=hdr->fea; t !=
NULL; t=t->next)
344 if (
streq(name,t->name))
348 fprintf(stderr,
"ESPS hdr: access non-double field \"%s\" as double\n",
364 for (t=hdr->fea; t !=
NULL; t=t->next)
365 if (
streq(name,t->name))
369 fprintf(stderr,
"ESPS hdr: access non-float field \"%s\" as float\n",
385 for (t=hdr->fea; t !=
NULL; t=t->next)
386 if (
streq(name,t->name))
390 fprintf(stderr,
"ESPS hdr: access non-short field \"%s\" as short\n",
406 for (t=hdr->fea; t !=
NULL; t=t->next)
407 if (
streq(name,t->name))
411 fprintf(stderr,
"ESPS hdr: access non-int field \"%s\" as int\n",
427 for (t=hdr->fea; t !=
NULL; t=t->next)
428 if (
streq(name,t->name))
432 fprintf(stderr,
"ESPS hdr: access non-char field \"%s\" as char\n",
443 static int esps_alloc_fea(esps_fea r)
450 r->v.dval =
walloc(
double,r->count);
break;
452 r->v.fval =
walloc(
float,r->count);
break;
454 r->v.ival =
walloc(
int,r->count);
break;
456 r->v.sval =
walloc(
short,r->count);
break;
458 r->v.cval =
walloc(
char,r->count);
break;
460 fprintf(stderr,
"ESPS file: unsupported FEA dtype\n");
475 fwrite(&t->type,2,1,fd);
476 clength = (strlen(t->name)+3)/4;
477 fwrite(&clength,2,1,fd);
478 nspace =
walloc(
char, clength*4);
479 memset(nspace,0,clength*4);
480 memmove(nspace,t->name,strlen(t->name));
481 fwrite(nspace,1,clength*4,fd);
483 if ((t->type == 11) ||
487 fwrite(&t->count,4,1,fd);
488 fwrite(&t->dtype,2,1,fd);
490 for (i=0; i<t->count; i++)
495 fwrite(&t->v.dval[i],8,1,fd);
break;
497 fwrite(&t->v.fval[i],4,1,fd);
break;
499 fwrite(&t->v.ival[i],4,1,fd);
break;
501 fwrite(&t->v.sval[i],2,1,fd);
break;
503 fwrite(&t->v.cval[i],1,1,fd);
break;
505 fprintf(stderr,
"ESPS write_hdr: unsupported FEA dtype %d\n",
518 for (i=0; i < r->num_fields; i++)
520 switch(r->field[i]->type)
523 fwrite(r->field[i]->v.dval,8,r->field[i]->dimension,fd);
526 fwrite(r->field[i]->v.fval,4,r->field[i]->dimension,fd);
529 fwrite(r->field[i]->v.ival,4,r->field[i]->dimension,fd);
532 fwrite(r->field[i]->v.sval,2,r->field[i]->dimension,fd);
535 fwrite(r->field[i]->v.cval,1,r->field[i]->dimension,fd);
538 fwrite(r->field[i]->v.sval,2,r->field[i]->dimension,fd);
542 fprintf(stderr,
"ESPS file: unsupported field type %d\n",
560 if (fread(&sdata,
sizeof(
short),1,fd) != 1) err = 1;
561 if (hdr->swapped) sdata =
SWAPSHORT(sdata);
565 if (fread(&sdata,
sizeof(
short),1,fd) != 1) err = 1;
566 if (hdr->swapped) sdata =
SWAPSHORT(sdata);
567 if (sdata < 0 || sdata > SHRT_MAX -1) {
568 fprintf(stderr,
"ESPS: fea record wrong size\n");
574 else if ((r->type == 13) ||
580 if (fread(&sdata,
sizeof(
short),1,fd) != 1) err = 1;
581 if (hdr->swapped) sdata =
SWAPSHORT(sdata);
582 if (sdata > SHRT_MAX/4) {
583 fprintf(stderr,
"ESPS: fea record too large\n");
588 fprintf(stderr,
"ESPS: fea record too small\n");
592 r->clength = sdata * 4;
593 if (r->clength > SHRT_MAX -1) {
594 fprintf(stderr,
"ESPS: fea record wrong size\n");
601 fprintf(stderr,
"ESPS: fea record unknown type\n");
605 r->name =
walloc(
char,r->clength+1);
606 if (fread(r->name,
sizeof(
char),r->clength,fd) != (
size_t) r->clength) err=1;
607 r->name[r->clength] =
'\0';
608 if ((r->type == 11) ||
612 if (fread(&idata,
sizeof(
int),1,fd) != 1) err = 1;
613 if (hdr->swapped) idata =
SWAPINT(idata);
615 fprintf(stderr,
"ESPS: negative r->count: Bad header\n");
620 if (fread(&sdata,
sizeof(
short),1,fd) != 1) err = 1;
621 if (hdr->swapped) sdata =
SWAPSHORT(sdata);
623 if (esps_alloc_fea(r) == -1) {
628 for (i=0; i<r->count; i++)
633 if (fread(&ddata,
sizeof(
double),1,fd) != 1) err=1;
635 r->v.dval[i] = ddata;
638 if (fread(&fdata,
sizeof(
float),1,fd) != 1) err=1;
640 r->v.fval[i] = fdata;
643 if (fread(&idata,
sizeof(
int),1,fd) != 1) err = 1;
644 if (hdr->swapped) idata =
SWAPINT(idata);
645 r->v.ival[i] = idata;
648 if (fread(&sdata,
sizeof(
short),1,fd) != 1) err=1;
649 if (hdr->swapped) sdata =
SWAPSHORT(sdata);
650 r->v.sval[i] = sdata;
653 if (fread(&cdata,
sizeof(
char),1,fd) != 1) err=1;
654 r->v.cval[i] = cdata;
657 fprintf(stderr,
"ESPS read_hdr: unsupported FEA dtype %d\n",r->dtype);
663 fprintf(stderr,
"ESPS read_hdr: Wrong format\n");
671 static char *esps_get_field_name(FILE *fd, esps_hdr hdr,
int expect_source)
677 if (fread(&size,2,1,fd) != 1)
679 fputs(
"error reading field name size\n", stderr);
682 if (hdr->swapped) size =
SWAPSHORT(size);
683 if (size < 0 || size > SHRT_MAX -1) {
684 fputs(
"error reading field size\n", stderr);
687 name =
walloc(
char, size+1);
688 if (fread(name,1,size,fd) != (
unsigned)size)
690 fputs(
"error reading field name\n", stderr);
691 strncpy(name,
"ERROR", size);
694 if (hdr->file_type ==
ESPS_SD || expect_source) {
696 fputs(
"error skipping some zeroes", stderr);
702 fputs(
"error skipping some zeroes", stderr);
710 if (fread(&size,
sizeof(
short),1,fd) != 1) {
711 fprintf(stderr,
"ESPS: wrong field format\n");
715 if (hdr->swapped) size =
SWAPSHORT(size);
717 fprintf(stderr,
"esps read error\n");
726 static void esps_put_field_name(
char *
name,FILE *fd, esps_hdr hdr)
729 short size = strlen(
name);
733 fwrite(&shortdata,2,1,fd);
734 fwrite(&size,2,1,fd);
735 fwrite(
name,1,size,fd);
739 fwrite(&shortdata,2,1,fd);
740 fwrite(&shortdata,2,1,fd);
741 fwrite(&shortdata,2,1,fd);
753 h->field_name =
NULL;
754 h->field_type =
NULL;
755 h->field_dimension =
NULL;
765 if (h->field_name !=
NULL)
767 for (i=0; i < h->num_fields; i++)
768 wfree(h->field_name[i]);
769 wfree(h->field_name);
781 r->field =
walloc(esps_field,hdr->num_fields);
782 for (size=0,i=0; i < hdr->num_fields; i++)
785 r->field[i]->type = hdr->field_type[i];
786 r->field[i]->dimension = hdr->field_dimension[i];
787 switch(r->field[i]->type)
790 r->field[i]->v.dval =
walloc(
double,r->field[i]->dimension);
794 r->field[i]->v.fval =
walloc(
float,r->field[i]->dimension);
798 r->field[i]->v.ival =
walloc(
int,r->field[i]->dimension);
802 r->field[i]->v.sval =
walloc(
short,r->field[i]->dimension);
806 r->field[i]->v.cval =
walloc(
char,r->field[i]->dimension);
810 r->field[i]->v.sval =
walloc(
short,r->field[i]->dimension);
814 fprintf(stderr,
"ESPS file: unsupported field type %d\n",
818 r->num_fields = hdr->num_fields;
828 for (i=0; i<r->num_fields; i++)
830 wfree(r->field[i]->v.ival);
847 for (i=0; i< r->num_fields; i++)
849 switch (r->field[i]->type)
852 for(j=0; j < r->field[i]->dimension; j++)
854 if (fread(&doubledata,8,1,fd) != 1)
return EOF;
856 r->field[i]->v.dval[j] = doubledata;
860 for(j=0; j < r->field[i]->dimension; j++)
862 if (fread(&floatdata,4,1,fd) != 1)
return EOF;
864 r->field[i]->v.fval[j] = floatdata;
868 for(j=0; j < r->field[i]->dimension; j++)
870 if (fread(&intdata,4,1,fd) != 1)
return EOF;
871 if (hdr->swapped) intdata =
SWAPINT(intdata);
872 r->field[i]->v.ival[j] = intdata;
876 for(j=0; j < r->field[i]->dimension; j++)
878 if (fread(&shortdata,2,1,fd) != 1)
return EOF;
879 if (hdr->swapped) shortdata =
SWAPSHORT(shortdata);
880 r->field[i]->v.sval[j] = shortdata;
884 if (fread(r->field[i]->v.cval,1,r->field[i]->dimension,fd) !=
885 (
unsigned)r->field[i]->dimension)
return EOF;
888 for(j=0; j < r->field[i]->dimension; j++)
890 if (fread(&shortdata,2,1,fd) != 1)
return EOF;
891 if (hdr->swapped) shortdata =
SWAPSHORT(shortdata);
892 r->field[i]->v.sval[j] = shortdata;
896 fprintf(stderr,
"ESPS file: unsupported field type %d\n",
909 return r->field[field]->v.dval[pos];
913 return r->field[field]->v.fval[pos];
917 return r->field[field]->v.ival[pos];
921 return r->field[field]->v.sval[pos];
925 return r->field[field]->v.cval[pos];
929 r->field[field]->v.dval[pos] = d;
933 r->field[field]->v.fval[pos] = d;
937 r->field[field]->v.ival[pos] = d;
941 r->field[field]->v.sval[pos] = d;
945 r->field[field]->v.cval[pos] = d;
958 static int esps_num_of_type(
int type,esps_hdr hdr)
964 for (sum=i=0; i < hdr->num_fields; i++)
965 if (hdr->field_type[i] == type)
999 double sd_sample_rate;
1004 if (fread(&(preamble.
machine_code),
sizeof(
int), 1, fd) != 1) err=1;
1005 if (fread(&(preamble.
check_code),
sizeof(
int), 1, fd) != 1) err=1;
1006 if (fread(&(preamble.
data_offset),
sizeof(
int), 1, fd) != 1) err=1;
1007 if (fread(&(preamble.
record_size),
sizeof(
int), 1, fd) != 1) err=1;
1008 if (fread(&(preamble.
check),
sizeof(
int), 1, fd) != 1) err=1;
1009 if (fread(&(preamble.
edr),
sizeof(
int), 1, fd) != 1) err=1;
1010 if (fread(&(preamble.
fil1),
sizeof(
int), 1, fd) != 1) err=1;
1011 if (fread(&(preamble.
foreign_hd),
sizeof(
int), 1, fd) != 1) err=1;
1020 hdr->swapped = swap;
1021 if (fread(&(fhdr.
thirteen),
sizeof(
short), 1, fd) != 1) err=1;
1022 if (fread(&(fhdr.
sdr_size),
sizeof(
short), 1, fd) != 1) err=1;
1023 if (fread(&(fhdr.
magic),
sizeof(
int), 1, fd) != 1) err=1;
1024 if (fread(&(fhdr.
date),
sizeof(
char), 26, fd) != 26) err=1;
1025 if (fread(&(fhdr.
version),
sizeof(
char), 8, fd) != 8) err=1;
1026 if (fread(&(fhdr.
prog),
sizeof(
char), 16, fd) != 16) err=1;
1027 if (fread(&(fhdr.
vers),
sizeof(
char), 8, fd) != 8) err=1;
1028 if (fread(&(fhdr.
progcompdate),
sizeof(
char), 26, fd) != 26) err=1;
1029 if (fread(&(fhdr.
num_samples),
sizeof(
int), 1, fd) != 1) err=1;
1030 if (fread(&(fhdr.
filler),
sizeof(
int), 1, fd) != 1) err=1;
1031 if (fread(&(fhdr.
num_doubles),
sizeof(
int), 1, fd) != 1) err=1;
1032 if (fread(&(fhdr.
num_floats),
sizeof(
int), 1, fd) != 1) err=1;
1033 if (fread(&(fhdr.
num_ints),
sizeof(
int), 1, fd) != 1) err=1;
1034 if (fread(&(fhdr.
num_shorts),
sizeof(
int), 1, fd) != 1) err=1;
1035 if (fread(&(fhdr.
num_chars),
sizeof(
int), 1, fd) != 1) err=1;
1036 if (fread(&(fhdr.
fsize),
sizeof(
int), 1, fd) != 1) err=1;
1037 if (fread(&(fhdr.
hsize),
sizeof(
int), 1, fd) != 1) err=1;
1038 if (fread(&(fhdr.
username),
sizeof(
char), 8, fd) != 8) err=1;
1039 if (fread(&(fhdr.
fil1),
sizeof(
int), 5, fd) != 5) err=1;
1040 if (fread(&(fhdr.
fea_type),
sizeof(
short), 1, fd) != 1) err=1;
1041 if (fread(&(fhdr.
fil2),
sizeof(
short), 1, fd) != 1) err=1;
1042 if (fread(&(fhdr.
num_fields),
sizeof(
short), 1, fd) != 1) err=1;
1044 cerr <<
"Wrong ESPS header: Wrong number of fields" << endl;
1050 if (fread(&(fhdr.
fil3),
sizeof(
short), 1, fd) != 1) err=1;
1051 if (fread(&(fhdr.
fil4),
sizeof(
int), 9, fd) != 9) err=1;
1052 if (fread(&(fhdr.
fil5),
sizeof(
int), 8, fd) != 8) err=1;
1056 cerr <<
"Could not read ESPS header." << endl;
1057 cerr <<
"Wrong format" << endl;
1114 hdr->num_fields = 1;
1115 hdr->field_dimension =
walloc(
int,hdr->num_fields);
1116 hdr->field_dimension[0] = 1;
1117 hdr->field_type =
walloc(
short,hdr->num_fields);
1119 hdr->field_name =
walloc(
char *,1);
1120 hdr->field_name[0] =
wstrdup(
"samples");
1127 float *tmpfloat = (
float *)&fhdr.
fil4[0];
1128 sd_sample_rate = *tmpfloat;
1129 add_fea_d(hdr,
"record_freq",0,(
double)sd_sample_rate);
1134 (hdr->num_fields == 1) &&
1142 hdr->field_dimension =
walloc(
int,hdr->num_fields);
1143 for (i=0; i<hdr->num_fields; i++)
1145 if (fread(&intdata,
sizeof(
int),1,fd) != 1) err = 1;
1146 if (hdr->swapped) intdata =
SWAPINT(intdata);
1147 hdr->field_dimension[i] = intdata;
1152 hdr->field_type =
walloc(
short,hdr->num_fields);
1153 for (i=0; i<hdr->num_fields; i++)
1155 if (fread(&shortdata,
sizeof(
short),1,fd) != 1) err = 1;
1156 if (hdr->swapped) shortdata =
SWAPSHORT(shortdata);
1157 hdr->field_type[i] = shortdata;
1160 if (fread(&intdata,
sizeof(
int),1,fd) != 1) err = 1;
1161 if (hdr->swapped) intdata =
SWAPINT(intdata);
1163 if (fread(&intdata,
sizeof(
int),1,fd) != 1) err = 1;
1164 if (hdr->swapped) intdata =
SWAPINT(intdata);
1166 if (fread(&intdata,
sizeof(
int),1,fd) != 1) err = 1;
1167 if (hdr->swapped) intdata =
SWAPINT(intdata);
1169 if (fread(&intdata,
sizeof(
int), 1, fd) !=1) err = 1;
1170 if (hdr->swapped) intdata =
SWAPINT(intdata);
1172 if (fread(&intdata,
sizeof(
int),1,fd) != 1) err = 1;
1173 if (hdr->swapped) intdata =
SWAPINT(intdata);
1175 if ((hdr->file_type !=
ESPS_SD) && (typematch ==
FALSE))
1177 fprintf(stderr,
"ESPS hdr: got lost in the header (record description)\n");
1184 fprintf(stderr,
"ESPS hdr: fseek error\n");
1188 fprintf(stderr,
"ESPS hdr: fseek error\n");
1192 hdr->field_name =
walloc(
char *,hdr->num_fields);
1194 if (fread(&name_flag,
sizeof(
short), 1, fd) != 1) err = 1;
1195 if (hdr->swapped) name_flag =
SWAPSHORT(name_flag);
1197 for (i=0; i < hdr->num_fields; i++)
1198 hdr->field_name[i] = esps_get_field_name(fd,hdr,name_flag);
1199 if (hdr->file_type ==
ESPS_SD)
1201 if (!
streq(hdr->field_name[0],
"samples"))
1203 fprintf(stderr,
"ESPS hdr: guessed wrong about FEA_SD file (no 'samples' field)\n");
1214 if (r ==
NULL)
break;
1226 fprintf(stderr,
"ESPS hdr: fseek error\n");
1234 fprintf(stderr,
"ESPS hdr: wrong format\n");
1248 time_t tx =
time(0);
1253 memset(&preamble,0,
sizeof(preamble));
1254 memset(&fhdr,0,
sizeof(fhdr));
1272 strncpy(fhdr.
date,ctime(&tx),26);
1273 fhdr.
date[25] =
'\0';
1275 sprintf(fhdr.
prog,
"EDST");
1276 sprintf(fhdr.
vers,
"0.1");
1289 if (hdr->file_type ==
ESPS_SD)
1297 fwrite(&(preamble.
check_code),
sizeof(
int),1,fd);
1300 fwrite(&(preamble.
check),
sizeof(
int),1,fd);
1301 fwrite(&(preamble.
edr),
sizeof(
int),1,fd);
1302 fwrite(&(preamble.
fil1),
sizeof(
int),1,fd);
1303 fwrite(&(preamble.
foreign_hd),
sizeof(
int),1,fd);
1306 fwrite(&(fhdr.
thirteen),
sizeof(
short),1,fd);
1307 fwrite(&(fhdr.
sdr_size),
sizeof(
short),1,fd);
1308 fwrite(&(fhdr.
magic),
sizeof(
int),1,fd);
1309 fwrite(&(fhdr.
date),
sizeof(
char),26,fd);
1310 fwrite(&(fhdr.
version),
sizeof(
char),8,fd);
1311 fwrite(&(fhdr.
prog),
sizeof(
char),16,fd);
1312 fwrite(&(fhdr.
vers),
sizeof(
char),8,fd);
1315 fwrite(&(fhdr.
filler),
sizeof(
int),1,fd);
1318 fwrite(&(fhdr.
num_ints),
sizeof(
int),1,fd);
1320 fwrite(&(fhdr.
num_chars),
sizeof(
int),1,fd);
1321 fwrite(&(fhdr.
fsize),
sizeof(
int),1,fd);
1322 fwrite(&(fhdr.
hsize),
sizeof(
int),1,fd);
1323 fwrite(&(fhdr.
username),
sizeof(
char),8,fd);
1324 fwrite(&(fhdr.
fil1),
sizeof(
int),5,fd);
1325 fwrite(&(fhdr.
fea_type),
sizeof(
short),1,fd);
1326 fwrite(&(fhdr.
fil2),
sizeof(
short),1,fd);
1327 fwrite(&(fhdr.
num_fields),
sizeof(
short),1,fd);
1328 fwrite(&(fhdr.
fil3),
sizeof(
short),1,fd);
1329 fwrite(&(fhdr.
fil4),
sizeof(
int),9,fd);
1330 fwrite(&(fhdr.
fil5),
sizeof(
int),8,fd);
1333 for (i=0; i < hdr->num_fields; i++)
1336 fwrite(&intdata,4,1,fd);
1338 for (i=0; i < hdr->num_fields; i++)
1340 if (hdr->file_type ==
ESPS_SD)
1344 for (i=0; i < hdr->num_fields; i++)
1345 fwrite(&shortdata,2,1,fd);
1346 for (i=0; i < hdr->num_fields; i++)
1348 shortdata = hdr->field_type[0];
1349 fwrite(&shortdata,2,1,fd);
1352 fwrite(&intdata,4,1,fd);
1354 fwrite(&intdata,4,1,fd);
1356 fwrite(&intdata,4,1,fd);
1358 fwrite(&intdata,4,1,fd);
1360 fwrite(&intdata,4,1,fd);
1362 for (i=0; i < 9; i++)
1363 fwrite(&shortdata,2,1,fd);
1364 for (i=0; i < hdr->num_fields; i++)
1365 fwrite(&shortdata,2,1,fd);
1367 for (i=0; i < hdr->num_fields; i++)
1368 esps_put_field_name(hdr->field_name[i],fd,hdr);
1369 if (hdr->file_type !=
ESPS_SD)
1370 fwrite(&shortdata,2,1,fd);
1372 for (t=hdr->fea; t !=
NULL; t=t->next)
1376 fwrite(&intdata,4,1,fd);
1381 fprintf(stderr,
"esps write header: can't fseek to start of file\n");
1384 if (fwrite(&(preamble.
machine_code),
sizeof(
int),1,fd) != 1) {
1385 fprintf(stderr,
"esps write header: Write error\n");
1388 if (fwrite(&(preamble.
check_code),
sizeof(
int),1,fd) != 1) {
1389 fprintf(stderr,
"esps write header: Write error\n");
1392 if (fwrite(&(preamble.
data_offset),
sizeof(
int),1,fd) != 1) {
1393 fprintf(stderr,
"esps write header: Write error\n");
1396 if (fwrite(&(preamble.
record_size),
sizeof(
int),1,fd) != 1) {
1397 fprintf(stderr,
"esps write header: Write error\n");
1400 if (fwrite(&(preamble.
check),
sizeof(
int),1,fd) != 1) {
1401 fprintf(stderr,
"esps write header: Write error\n");
1404 if (fwrite(&(preamble.
edr),
sizeof(
int),1,fd) != 1) {
1405 fprintf(stderr,
"esps write header: Write error\n");
1408 if (fwrite(&(preamble.
fil1),
sizeof(
int),1,fd) != 1) {
1409 fprintf(stderr,
"esps write header: Write error\n");
1412 if (fwrite(&(preamble.
foreign_hd),
sizeof(
int),1,fd) != 1) {
1413 fprintf(stderr,
"esps write header: Write error\n");
1418 if (fwrite(&(fhdr.
thirteen),
sizeof(
short),1,fd) != 1) {
1419 fprintf(stderr,
"esps write header: Write error\n");
1422 if (fwrite(&(fhdr.
sdr_size),
sizeof(
short),1,fd) != 1) {
1423 fprintf(stderr,
"esps write header: Write error\n");
1426 if (fwrite(&(fhdr.
magic),
sizeof(
int),1,fd) != 1) {
1427 fprintf(stderr,
"esps write header: Write error\n");
1430 if (fwrite(&(fhdr.
date),
sizeof(
char),26,fd) != 26) {
1431 fprintf(stderr,
"esps write header: Write error\n");
1434 if (fwrite(&(fhdr.
version),
sizeof(
char),8,fd) != 8) {
1435 fprintf(stderr,
"esps write header: Write error\n");
1438 if (fwrite(&(fhdr.
prog),
sizeof(
char),16,fd) != 16) {
1439 fprintf(stderr,
"esps write header: Write error\n");
1442 if (fwrite(&(fhdr.
vers),
sizeof(
char),8,fd) != 8) {
1443 fprintf(stderr,
"esps write header: Write error\n");
1446 if (fwrite(&(fhdr.
progcompdate),
sizeof(
char),26,fd) != 26) {
1447 fprintf(stderr,
"esps write header: Write error\n");
1450 if (fwrite(&(fhdr.
num_samples),
sizeof(
int),1,fd) != 1) {
1451 fprintf(stderr,
"esps write header: Write error\n");
1454 if (fwrite(&(fhdr.
filler),
sizeof(
int),1,fd) != 1) {
1455 fprintf(stderr,
"esps write header: Write error\n");
1458 if (fwrite(&(fhdr.
num_doubles),
sizeof(
int),1,fd) != 1) {
1459 fprintf(stderr,
"esps write header: Write error\n");
1462 if (fwrite(&(fhdr.
num_floats),
sizeof(
int),1,fd) != 1) {
1463 fprintf(stderr,
"esps write header: Write error\n");
1466 if (fwrite(&(fhdr.
num_ints),
sizeof(
int),1,fd) != 1) {
1467 fprintf(stderr,
"esps write header: Write error\n");
1470 if (fwrite(&(fhdr.
num_shorts),
sizeof(
int),1,fd) != 1) {
1471 fprintf(stderr,
"esps write header: Write error\n");
1474 if (fwrite(&(fhdr.
num_chars),
sizeof(
int),1,fd) != 1) {
1475 fprintf(stderr,
"esps write header: Write error\n");
1478 if (fwrite(&(fhdr.
fsize),
sizeof(
int),1,fd) != 1) {
1479 fprintf(stderr,
"esps write header: Write error\n");
1482 if (fwrite(&(fhdr.
hsize),
sizeof(
int),1,fd) != 1) {
1483 fprintf(stderr,
"esps write header: Write error\n");
1486 if (fwrite(&(fhdr.
username),
sizeof(
char),8,fd) != 8) {
1487 fprintf(stderr,
"esps write header: Write error\n");
1490 if (fwrite(&(fhdr.
fil1),
sizeof(
int),5,fd) != 5) {
1491 fprintf(stderr,
"esps write header: Write error\n");
1494 if (fwrite(&(fhdr.
fea_type),
sizeof(
short),1,fd) != 1) {
1495 fprintf(stderr,
"esps write header: Write error\n");
1498 if (fwrite(&(fhdr.
fil2),
sizeof(
short),1,fd) != 1) {
1499 fprintf(stderr,
"esps write header: Write error\n");
1502 if (fwrite(&(fhdr.
num_fields),
sizeof(
short),1,fd) != 1) {
1503 fprintf(stderr,
"esps write header: Write error\n");
1506 if (fwrite(&(fhdr.
fil3),
sizeof(
short),1,fd) != 1) {
1507 fprintf(stderr,
"esps write header: Write error\n");
1510 if (fwrite(&(fhdr.
fil4),
sizeof(
int),9,fd) != 9) {
1511 fprintf(stderr,
"esps write header: Write error\n");
1514 if (fwrite(&(fhdr.
fil5),
sizeof(
int),8,fd) != 8) {
1515 fprintf(stderr,
"esps write header: Write error\n");
1519 fprintf(stderr,
"esps write header: Write error\n");
esps_rec new_esps_rec(const esps_hdr hdr)
char * wstrdup(const char *s)
float end(const EST_Item &item)
#define walloc(TYPE, SIZE)
float get_field_f(esps_rec r, int field, int pos)
EST_FilePos EST_ftell(FILE *fp)
void print_esps_fea(esps_fea r)
double get_field_d(esps_rec r, int field, int pos)
void add_fea_d(esps_hdr hdr, const char *name, int pos, double d)
int fea_value_f(const char *name, int pos, esps_hdr hdr, float *d)
int fea_value_c(const char *name, int pos, esps_hdr hdr, char *d)
int read_esps_rec(esps_rec r, esps_hdr hdr, FILE *fd)
void add_fea_i(esps_hdr hdr, const char *name, int pos, int d)
esps_hdr make_esps_hdr(void)
void add_fea_c(esps_hdr hdr, const char *name, int pos, char d)
void err(const char *message, LISP x) EST_NORETURN
void add_fea_f(esps_hdr hdr, const char *name, int pos, float d)
enum EST_read_status read_esps_hdr(esps_hdr *uhdr, FILE *fd)
int get_field_i(esps_rec r, int field, int pos)
The file was written successfully.
int esps_record_size(esps_hdr hdr)
void set_field_d(esps_rec r, int field, int pos, double d)
void delete_esps_rec(esps_rec r)
esps_hdr new_esps_hdr(void)
void swapdouble(double *d)
float time(const EST_Item &item)
enum EST_write_status write_esps_hdr(esps_hdr hdr, FILE *fd)
short get_field_s(esps_rec r, int field, int pos)
int EST_fseek(FILE *fp, EST_FilePos offset, int whence)
void set_field_s(esps_rec r, int field, int pos, short d)
void set_field_f(esps_rec r, int field, int pos, float d)
int fea_value_s(const char *name, int pos, esps_hdr hdr, short *d)
char get_field_c(esps_rec r, int field, int pos)
esps_fea read_esps_fea(FILE *fd, esps_hdr hdr)
void write_esps_fea(FILE *fd, esps_fea t, esps_hdr hdr)
void add_fea_special(esps_hdr hdr, int type, const char *name)
int fea_value_d(const char *name, int pos, esps_hdr hdr, double *d)
float sum(const EST_FMatrix &a)
sum of elements
void set_field_i(esps_rec r, int field, int pos, int d)
void delete_esps_hdr(esps_hdr h)
int fea_value_i(const char *name, int pos, esps_hdr hdr, int *d)
void add_field(esps_hdr hdr, const char *name, int type, int dimension)
void set_field_c(esps_rec r, int field, int pos, char d)
esps_hdr make_esps_sd_hdr(void)
void add_fea_s(esps_hdr hdr, const char *name, int pos, short d)
void delete_esps_fea(esps_fea r)
int write_esps_rec(esps_rec r, esps_hdr h, FILE *fd)