/* Program*/ /* Reading SDAS format*/ #include "css\3.0\WFDISCIO.H" #include #include #include #include #include #include #include #include "wsgdate.h" #include "sdas.h" #include "head.h" //#include "INI\prf.h" //struct wfdisc wfd[NCHANNEL]; int convert(void *buf, void *newbuf, char newtype[3], long numsamp) { float *fltptr; unsigned int *uintptr; int *intptr, intgr, step, i, dtp; long *lngptr, lng; unsigned long ulng; double *dblptr; if (strcmp("i2", newtype)==0) {dtp=1; intptr=(int*)newbuf;} else if (strcmp("i4", newtype)==0) {dtp=2; lngptr=(long*)newbuf;} else if (strcmp("f4", newtype)==0) {dtp=3; fltptr=(float*)newbuf;} else {dtp=4; dblptr=(double*)newbuf; } uintptr=(unsigned int*)buf; switch (dtp) { case 1: { for(i=0;istr[stype].iFile_size!=0) tlim=ds->str[stype].iFile_size; else tlim=ds->sysprm.Tlim; for(i=0;iN_grp;i++) { chgrp=0; for(j=0;jstr[stype].N_ch;j++) for(k=0;kgrp[i].N_ch;k++) if(ds->str[stype].chan[j]==ds->grp[i].chan[k]) chgrp++; if(ds->grp[i].N_ch==chgrp) {grps[ngrp]=i; ngrp++;} } ofsdat=4608; lseek(rfile, ofsdat, SEEK_SET); hdbuf = malloc(sizeof(Head_rec)+1); read(rfile, hdbuf, sizeof(Head_rec)); hd=(Head_rec *)hdbuf; yr=hd->i_y; mnth=hd->i_mo; day=hd->i_d; hr=hd->i_h; min=hd->i_mi; mlsec=hd->i_ms; sc=hd->i_s+mlsec; startime=etoh(yr, mnth, day, hr, min, sc); i=0; cursize=ofsdat; // free(hdbuf); // hdbuf = malloc(sizeof(Head_rec)+1); ofsdat+=256; if (strcmp("i2", newtype)==0) {dtype=2;} else if (strcmp("i4", newtype)==0) {dtype=4;} else if (strcmp("f4", newtype)==0) {dtype=4;} else if (strcmp("f8", newtype)==0) {dtype=8;} datbuf = malloc(2000); newbuf = malloc(2500); while(stop!=0) { for(j=0;jgrp[grps[j]].N_ch; k++) { n=j*((ds->grp[grps[j]].N_ch))+k; if(i==0) { printf("Open data-file: %s ... ", name); strcpy(fnams, fnam); p=strrchr(fnams,'.'); p++; sprintf(p,"%s",ds->prm[ds->grp[grps[j]].chan[k]].name); dfile[n] = open(fnams, O_WRONLY | O_CREAT | O_BINARY, S_IWRITE); if(dfile[n] == -1) { printf("ERROR\n"); free(hdbuf); return(-7); } printf("Ok\n"); printf("Create data-file: %s.\n", name); } else { strcpy(fnams, fnam); p=strrchr(fnams,'.'); p++; sprintf(p,"%s",ds->prm[ds->grp[grps[j]].chan[k]].name); dfile[n] = open(fnams, O_WRONLY | O_BINARY, S_IWRITE); } f=ds->str[stype].iRec_len*ds->grp[grps[j]].Freq*2; od=ds->str[stype].iRec_len*ds->grp[grps[j]].Freq*dtype; // datbuf = malloc(f+1); // newbuf = malloc(od+1); lseek(rfile, ofsdat, SEEK_SET); read(rfile, datbuf, f); convert(datbuf, newbuf, newtype, f/2); ls=lseek(dfile[n], 0, SEEK_END); write(dfile[n], newbuf, od); close(dfile[n]); // free(datbuf); // free(newbuf); ofsdat+=f; f=ds->str[stype].iRec_len*ds->grp[grps[j]].Freq*2; // ofsdat+=f; } cursize=cursize+f*ds->str[stype].N_ch+256; i++; // lseek(rfile, ofsdat, SEEK_SET); // read(rfile, hdbuf, sizeof(Head_rec)); // hd=(Head_rec *)hdbuf; ofsdat+=256; sdat+=od; if(cursize>=fsize /*|| wfd[n].time-wfd[n].endtime == tlim*/) stop=0; } free(hdbuf); free(datbuf); free(newbuf); return(0); }