#include #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" //LPCSTR section[]={"HEADER","SYSTEM","ALGORITHM","SCEDULE","GROUP","STREAM","CH"}; struct wfdisc wfd[NCHANNEL]; Head_rec *hd; int work_zagl(int rfile, CmnPrm *ds, char fname[100], char newtype[3]) { int grps[8]; short stype; FILE *fwfd; char *hdbuf; int rbuf, i, ndat, j, k, ngrp=0, chgrp=0, n, tlim, dtype; int yr, mnth, day, hr, min, stop=1, dfile[NCHANNEL], sdat=0; char fnam[100], *p, name[100], per[5]="p", *ptr; long offset, fsize, cursize=0, ofsdat, f, freemem, od; float sc, mlsec; double startime; // LPSTR pp; fsize=filelength(rfile); strcpy(fnam, fname); // GetPrivateProfileString(section[0],"HEADER_SIZE","",pp,2048,fnam); strcpy(strrchr(fnam, '.'), ".wfdisk"); printf("Open wfd-file: %s ... ", fnam); fwfd=fopen(fnam,"at"); if(fwfd == NULL) { printf (" ERROR\n"); return(-2); } // buf = malloc(sizeof(CmnPrm)+1); // offset=searchoffset(); offset=3072;//atoi((char *)pp); lseek(rfile, offset, SEEK_SET); rbuf = read(rfile, ds, sizeof(CmnPrm)); p = strrchr(fnam,'\\'); if(p == NULL) p=fnam; else p++; strcpy(name,p); printf("Ok\nCreate WFDisc file.\n"); ptr = strncmpi(fname, per, 1); stype=1; // if(ptr==0) stype=1; else stype=0; if(ds->str[stype].iFile_size!=0) tlim=ds->str[stype].iFile_size; else tlim=ds->sysprm.Tlim; j=sizeof(wfdisc_null); k=_stklen; for(i=0;istr[stype].N_ch;i++) memcpy(&(wfd[i]),&wfdisc_null,j); 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; strcpy(name, p); 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;} while(stop!=0) { for(j=0;jgrp[grps[j]].N_ch; k++) { n=j*((ds->grp[grps[j]].N_ch))+k; p=strrchr(name,'.'); p++; sprintf(p,"%s",ds->prm[ds->grp[grps[j]].chan[k]].name); strcpy(wfd[n].dfile, name); strcpy(wfd[n].chan, ds->prm[ds->grp[grps[j]].chan[k]].name); strcpy(wfd[n].dir,"."); strcpy(wfd[n].sta, ds->SysName); wfd[n].time = startime; wfd[n].jdate = jdate(yr, mnth, day); wfd[n].smprate = ds->grp[grps[j]].Freq; wfd[n].endtime = wfd[n].time + ds->str[stype].iRec_len*(i+1); wfd[n].nsamp = (wfd[n].endtime-wfd[n].time)*wfd[n].smprate; wfd[n].foff = 0l; strcpy(wfd[n].datatype, newtype); // strcpy(wfd[n].datatype, "i2"); // strcpy(fname,wfd[n].dfile); 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; if(cursize>=fsize || wfd[n].time-wfd[n].endtime == tlim) stop=0; } // for(i=0;istr[stype].N_ch;i++) close(dfile[i]); for(i=0;istr[stype].N_ch;i++) { fprintf(fwfd, WFDISC_WCS, WFDISC_WVL((&wfd[i]))); // wfd[i].sta, wfd[i].chan, wfd[i].time, wfd[i].wfid, wfd[i].chanid, //wfd[i].jdate, wfd[i].endtime, wfd[i].nsamp, wfd[i].smprate, //wfd[i].calib, wfd[i].calper, wfd[i].instype, wfd[i].segtype, wfd[i].datatype, //wfd[i].clip, wfd[i].dir, wfd[i].dfile, wfd[i].foff, wfd[i].commid, //wfd[i].lddate); } // free(hdbuf); // free(buf); fclose(fwfd); return(0); }