//#include #include "css/3.0/wfdiscio.h" #include #include #include #include #include "wsgdate.h" #include "head.h" //LPCSTR section[]={"HEADER","SYSTEM","ALGORITHM","SCEDULE","GROUP","STREAM","CH"}; struct wfdisc wfd[NCHANNEL]; Head_rec *hd; char buffer[1000]; int bufferi[1000]; unsigned char ubuffer[1000]; int work_zagl(int rfile, CmnPrm *ds, char fname[100], char newtype[3], long fsize) { 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,cursize=0, ofsdat, f, freemem, od; short yr, mnth, day, hr, min; float sc, mlsec; double startime; short *sbuf; float *fbuf; int *ibuf; char *cbuf; unsigned short *usbuf; unsigned char *ucbuf; unsigned long *ulbuf; int z; // LPSTR pp; strcpy(fnam, fname); // GetPrivateProfileString(section[0],"HEADER_SIZE","",pp,2048,fnam); strcpy(strrchr(fnam, '.'), ".wfdisc"); 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)); //----------------------------------------------------------------------- //----------------------------------------------------------------------- offset=3072;//atoi((char *)pp); lseek(rfile, offset, SEEK_SET); read(rfile,buffer,sizeof(ds->CS)); usbuf=(unsigned short*)buffer; ds->CS=*usbuf; read(rfile,buffer,sizeof(ds->hd_len)); sbuf=(short*)buffer; ds->hd_len=*sbuf; read(rfile,buffer,sizeof(ds->data_offs)); sbuf=(short*)buffer; ds->data_offs=*sbuf; read(rfile,buffer,64);//sizeof(ds->SysType)); memcpy(ds->SysType,buffer,64);//sizeof(ds->SysType)); read(rfile,buffer,8);//sizeof(ds->SysName)); memcpy(ds->SysName,buffer,8);//sizeof(ds->SysName)); read(rfile,buffer,sizeof(ds->lat)); fbuf=(float*)buffer; ds->lat=*fbuf; read(rfile,buffer,sizeof(ds->lon)); fbuf=(float*)buffer; ds->lon=*fbuf; read(rfile,buffer,sizeof(ds->alt)); fbuf=(float*)buffer; ds->alt=*fbuf; read(rfile,buffer,sizeof(ds->N_ch)); cbuf=(char *)buffer; ds->N_ch=*cbuf; read(rfile,buffer,sizeof(ds->N_grp)); cbuf=(char *)buffer; ds->N_grp=*cbuf; read(rfile,buffer,sizeof(ds->N_sced)); cbuf=(char *)buffer; ds->N_sced=*cbuf; read(rfile,buffer,sizeof(ds->N_str)); cbuf=(char *)buffer; ds->N_str=*cbuf; //--------------------------------------------------------- //SysPrm //------------------------------------------------------------ read(rfile,buffer,sizeof(ds->sysprm.Freq)); sbuf=(short*)buffer; ds->sysprm.Freq=*sbuf; read(rfile,buffer,sizeof(ds->sysprm.Tpos)); sbuf=(short*)buffer; ds->sysprm.Tpos=*sbuf; read(rfile,buffer,sizeof(ds->sysprm.Tpre)); sbuf=(short*)buffer; ds->sysprm.Tpre=*sbuf; read(rfile,buffer,sizeof(ds->sysprm.Ntrig)); sbuf=(short*)buffer; ds->sysprm.Ntrig=*sbuf; read(rfile,buffer,sizeof(ds->sysprm.Tlim)); sbuf=(short*)buffer; ds->sysprm.Tlim=*sbuf; read(rfile,buffer,sizeof(ds->sysprm.Tset_h)); sbuf=(short*)buffer; ds->sysprm.Tset_h=*sbuf; read(rfile,buffer,sizeof(ds->sysprm.Tset_m)); sbuf=(short*)buffer; ds->sysprm.Tset_m=*sbuf; read(rfile,buffer,sizeof(ds->sysprm.Tset_s)); sbuf=(short*)buffer; ds->sysprm.Tset_s=*sbuf; read(rfile,buffer,sizeof(ds->sysprm.N_ch)); ds->sysprm.N_ch=*buffer; read(rfile,buffer,16);//sizeof(ds->sysprm.chan[NCHANNEL])); memcpy(ds->sysprm.chan,buffer,16);//sizeof(ds->grp[NGROUP].Type)); //------------------------------------------------------------ //Group //------------------------------------------------------------ for(i=0;i<6;i++) { read(rfile,buffer,sizeof(ds->grp[i].Type)); memcpy(ds->grp[i].Type,buffer,sizeof(ds->grp[i].Type)); read(rfile,buffer,sizeof(ds->grp[i].Freq)); sbuf=(short*)buffer; ds->grp[i].Freq=*sbuf; read(rfile,buffer,sizeof(ds->grp[i].Gain)); ds->grp[NGROUP].Gain=*buffer; read(rfile,buffer,sizeof(ds->grp[i].N_ch)); ds->grp[i].N_ch=*buffer; read(rfile,buffer,16);//sizeof(ds->grp[NGROUP].chan[NCHANNEL])); memcpy(ds->grp[i].chan,buffer,16);//sizeof(ds->grp[NGROUP].Type)); } //------------------------------------------------------------ //Stream //------------------------------------------------------------ for(i=0;i<2;i++) { read(rfile,buffer,sizeof(ds->str[i].Type)); ds->str[i].Type=*buffer; read(rfile,buffer,sizeof(ds->str[i].iRec_len)); ds->str[i].iRec_len=*buffer; read(rfile,buffer,sizeof(ds->str[i].iFile_size)); sbuf=(short*)buffer; ds->str[i].iFile_size=*sbuf; read(rfile,buffer,sizeof(ds->str[i].N_ch)); ds->str[i].N_ch=*buffer; read(rfile,buffer,16);//sizeof(ds->str[NSTREAM].chan[NCHANNEL])); memcpy(ds->str[i].chan,buffer,16);//sizeof(ds->grp[NGROUP].Type)); } //------------------------------------------------------------ //Data //------------------------------------------------------------ for(i=0;i<2;i++) { read(rfile,buffer,2);//sizeof(ds->sced[i].da_on.da_year)); sbuf=(short *)buffer; ds->sced[i].da_on.da_year=*sbuf; read(rfile,buffer,1);//sizeof(ds->sced[i].da_on.da_day)); ds->sced[i].da_on.da_day=*buffer; read(rfile,buffer,1);//sizeof(ds->sced[i].da_on.da_mon)); ds->sced[i].da_on.da_mon=*buffer; //------------------------------------------------------------ //Time //------------------------------------------------------------ read(rfile,buffer,1);//sizeof(ds->sced->ti_on.ti_min)); ucbuf=(unsigned char*)buffer; ds->sced[i].ti_on.ti_min=*ucbuf; // ds->sced->ti_on.ti_min=*buffer; read(rfile,buffer,1);//sizeof(ds->sced->ti_on.ti_hour)); ucbuf=(unsigned char*)buffer; ds->sced[i].ti_on.ti_hour=*ucbuf; read(rfile,buffer,1);//sizeof(ds->sced->ti_on.ti_hund)); ucbuf=(unsigned char*)buffer; ds->sced[i].ti_on.ti_hund=*ucbuf; read(rfile,buffer,1);//sizeof(ds->sced->ti_on.ti_sec)); ucbuf=(unsigned char*)buffer; ds->sced[i].ti_on.ti_sec=*ucbuf; read(rfile,buffer,1);//;sizeof(ds->sced->ti_on.ti_ms)); ucbuf=(unsigned char*)ucbuf; ds->sced[i].ti_on.ti_ms=*buffer; read(rfile,buffer,1);//sizeof(ds->sced->ti_on.ti_hlth)); ucbuf=(unsigned char*)buffer; ds->sced[i].ti_on.ti_hlth=*ucbuf; //------------------------------------------------------------ //Scedule //------------------------------------------------------------ read(rfile,buffer,2);//sizeof(ds->sced[i].iDuration)); sbuf=(short*)buffer; ds->sced[i].iDuration=*sbuf; read(rfile,buffer,2);//sizeof(ds->sced[i].iRepeate)); sbuf=(short*)buffer; ds->sced[i].iRepeate=*sbuf; read(rfile,buffer,2);//sizeof(ds->sced[i].iDelay)); sbuf=(short*)buffer; ds->sced[i].iDelay=*sbuf; read(rfile,buffer,40);//sizeof(ds->sced[NSCEDULE].sCalib)); memcpy(ds->sced[i].sCalib,buffer,40);//sizeof(ds->sced[NSCEDULE].sCalib)); } //------------------------------------------------------------ //ChPrm //------------------------------------------------------------ for(i=0;i<16;i++) { read(rfile,buffer,sizeof(ds->prm[i].glob_stat)); ds->prm[i].glob_stat=*buffer; read(rfile,buffer,sizeof(ds->prm[i].name)); memcpy(ds->prm[i].name,buffer,sizeof(ds->prm[i].name)); for(z=0;z<8;z++); read(rfile,buffer,sizeof(ds->prm[i].alg_stat)); ds->prm[i].alg_stat=*buffer; read(rfile,buffer,sizeof(ds->prm[i].STA)); fbuf=(float*)buffer; ds->prm[i].STA=*fbuf; read(rfile,buffer,sizeof(ds->prm[i].LTA)); fbuf=(float*)buffer; ds->prm[i].LTA=*fbuf; read(rfile,buffer,sizeof(ds->prm[i].KOEF)); fbuf=(float*)buffer; ds->prm[i].KOEF=*fbuf; read(rfile,buffer,sizeof(ds->prm[i].WEIGTH)); sbuf=(short*)buffer; ds->prm[i].WEIGTH=*sbuf; } //----------------------------------------------------------------------- //--------------------------------------------------------------------- p = strrchr(fnam,'\\'); if(p == NULL) p=fnam; else p++; strcpy(name,p); printf("Ok\nCreate WFDisc file.\n"); ptr = strncmp(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=4112;// 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; //----------------------------------------------------------------------- //HEAD_REC //----------------------------------------------------------------------- lseek(rfile, ofsdat, SEEK_SET); read(rfile,bufferi,8);//;sizeof(ds->sced->ti_on.ti_ms)); memcpy(hd->label,bufferi,8);//sizeof(ds->sced[NSCEDULE].sCalib)); read(rfile,buffer,2);//sizeof(hd->i_d)); sbuf=(short*)buffer; hd->i_d=*sbuf; read(rfile,buffer,2);//sizeof(hd->i_mo)); sbuf=(short*)buffer; hd->i_mo=*sbuf; read(rfile,buffer,2);//sizeof(hd->i_y)); sbuf=(short*)buffer; hd->i_y=*sbuf; read(rfile,buffer,2);//sizeof(hd->i_h)); sbuf=(short*)buffer; hd->i_h=*sbuf; read(rfile,buffer,2);//sizeof(hd->i_mi)); sbuf=(short*)buffer; hd->i_mi=*sbuf; read(rfile,buffer,2);//sizeof(hd->i_s)); sbuf=(short*)buffer; hd->i_s=*sbuf; read(rfile,buffer,2);//sizeof(hd->i_ms)); sbuf=(short*)buffer; hd->i_ms=*sbuf; read(rfile,buffer,2);//sizeof(hd->St)); sbuf=(short*)buffer; hd->St=*sbuf; read(rfile,buffer,2);//sizeof(hd->hdsz)); sbuf=(short*)buffer; hd->hdsz=*sbuf; read(rfile,buffer,2);//sizeof(hd->Ncomp)); sbuf=(short*)buffer; hd->Ncomp=*sbuf; read(rfile,buffer,2);//sizeof(hd->freq)); sbuf=(short*)buffer; hd->freq=*sbuf; read(rfile,buffer,4);//sizeof(hd->offs)); ulbuf=(unsigned long*)buffer; hd->offs=*ulbuf; read(rfile,buffer,2);//sizeof(hd->d_d)); sbuf=(short*)buffer; hd->d_d=*sbuf; read(rfile,buffer,2);//sizeof(hd->d_mo)); sbuf=(short*)buffer; hd->d_mo=*sbuf; read(rfile,buffer,2);//sizeof(hd->d_y)); sbuf=(short*)buffer; hd->d_y=*sbuf; read(rfile,buffer,2);//sizeof(hd->d_h)); sbuf=(short*)buffer; hd->d_h=*sbuf; read(rfile,buffer,2);//sizeof(hd->d_mi)); sbuf=(short*)buffer; hd->d_mi=*sbuf; read(rfile,buffer,2);//sizeof(hd->d_s)); sbuf=(short*)buffer; hd->d_s=*sbuf; read(rfile,buffer,2);//sizeof(hd->e_d)); sbuf=(short*)buffer; hd->e_d=*sbuf; read(rfile,buffer,2);//sizeof(hd->e_mo)); sbuf=(short*)buffer; hd->e_mo=*sbuf; read(rfile,buffer,2);//sizeof(hd->e_y)); sbuf=(short*)buffer; hd->e_y=*sbuf; read(rfile,buffer,2);//sizeof(hd->e_h)); sbuf=(short*)buffer; hd->e_h=*sbuf; read(rfile,buffer,2);//sizeof(hd->e_mi)); sbuf=(short*)buffer; hd->e_mi=*sbuf; read(rfile,buffer,2);//sizeof(hd->e_s)); sbuf=(short*)buffer; hd->e_s=*sbuf; read(rfile,buffer,2);//sizeof(hd->nch)); sbuf=(short*)buffer; hd->nch=*sbuf; read(rfile,ubuffer,16);//sizeof(ds->grp[NGROUP].chan[NCHANNEL])); memcpy(hd->gain,ubuffer,16);//sizeof(ds->grp[NGROUP].Type)); read(rfile,buffer,4);//sizeof(hd->lat)); fbuf=(float*)buffer; hd->lat=*fbuf; read(rfile,buffer,4);//sizeof(hd->lon)); fbuf=(float*)buffer; hd->lon=*fbuf; read(rfile,buffer,4);//sizeof(hd->alt)); fbuf=(float *)buffer; hd->alt=*fbuf; read(rfile,buffer,4);//sizeof(ds->SysType)); memcpy(hd->Name,buffer,4);//sizeof(ds->SysType)); read(rfile,buffer,16);//sizeof(ds->SysType)); memcpy(hd->ch,buffer,16);//sizeof(ds->SysType)); read(rfile,buffer,2);//sizeof(hd->secInBlock)); sbuf=(short*)buffer; hd->secInBlock=*sbuf; read(rfile,buffer,148);//sizeof(hd->secInBlock)); //----------------------------------------------------------------------- //--------------------------------------------------------------------- */ 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); }