⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 four2one.c

📁 实现ipvlbi数据记录
💻 C
📖 第 1 页 / 共 2 页
字号:
       }    }    return iwork;}int main(int argc, char *argv[]){       int sfreq, adbit, numch, kpos;       long int startoffset; // start time offset in sec       long int counts;        //sample counter       long int counts2;        //extract sample counter       long int sofst_pos;    // start sample position from sec tic       int nloop;       int i,imax, m, k;       int smode,usampl;       int obuf[1024];       int nwrite=1024;       int iwrite;       int idat32[32];       int idat,ipick;       int ibcount;       int opos, nrepeat;       unsigned char *ibuf;       int nbyte=5000;       fpos_t pos;       int bytesread;       int bits, bytes, numb;	   int nch;       int span,secc;       double fsampl,tsampl,fact;       int *idata;	   double soffset, fsec;       char fname[80],oname[80];       char lab2[60], ltime1st[60];       char labfsampl[10];       char dflt_oname[80];       char* dflt_fname="tds.data";       ip_vlbi_file_t X;       FILE *fo;       IPBOARD_T ipb;       if(argc == 1){          printf("Usage: four2one filename [ch [outfile]]\n");          printf("\n");          printf("         where  filename ---- Data file name\n");          printf("                ch   -------- Channel # to extract\n");          printf("                             default is 1\n");                   printf("                outfile ---- Extract data outfile name\n");          printf("                             default is filename+.ch#\n");                   printf("                secofst ---- Extract start time offset (sec)\n");          printf("                             default is 0\n");                   printf("                span    ---- Extract span (sec)\n");          printf("                             default is all\n");                   exit(0);       }       /* data file name get */       strcpy(fname,*(argv+1));       if (fname[0]=='0'){          strcpy(fname,dflt_fname);       }       X.fname=fname;       /* Ch# to extract get */       if (argc>=3)       {          nch = atoi(*(argv + 2 ));       } else {          nch=1;          }       /* default oname create */       sprintf(dflt_oname,"%s.%d\0",fname,nch);       /* Out file name get */       if (argc>=4)       {           strcpy(oname,*(argv+3));       } else {           strcpy(oname,dflt_oname);       }       /* start offset get */       if (argc>=5)       {          soffset = atof(*(argv + 4 ));       } else {          soffset =0.0;          }       /* span get */       if (argc>=6)       {          span = atoi(*(argv + 5 ));       } else {          span =0;          }       /* Run condition monitor for debug*/       printf("Data File is %s\n",fname);       printf("Out File is %s\n",oname);       printf("nch  %d %f %f\n",nch);       /* Program Name Display */       printf("*******************************************************\n");       printf("* IP-VLBI DATA CH NUMBER REDUCTION PROGRAM (four2one) *\n");       printf("*      Ver 1.0   2003-03-13  by  T.KONDO/CRL          *\n");       printf("*******************************************************\n");       printf("\n");       /* Data file open */       if( (X.stream  = fopen( X.fname, "rb" )) == NULL )       {           printf("Data File %s   Open Error! \n",fname);		   goto exitend2;       }       /* output file create */       if( (fo  = fopen( oname, "wb" )) == NULL )       {          printf("File  %s  Open Error! \n",oname);          goto exitend3;	   }        /* Data header check to get sampling parameters */       if(checkheader(&X) < 0){            goto exitend3;       }       /* parameter set */        sfreq=X.sfreq;        adbit=X.adbit;        numch=X.numch;        fsampl=1000.0*(float)sfreq;   // sampling frequency (Hz)        tsampl=1.0/fsampl;            // sampling period (sec)        bits=((long)fsampl)*adbit*numch;  // # of bits in 1 sec data except header        bytes=bits/8;                     // # of bytes in 1 sec data except header        X.fsample=(float)fsampl;        sofst_pos=0;        nrepeat=32/adbit;        /* nothing to do in case of 1 ch board*/        if(numch == 1){            goto exitend3;        }           /* header parameters setup fot output */        ipb.adbit=X.adbit;        ipb.numch=1;   // compulsory set to 1ch mode        ipb.sfreq=X.sfreq;        ipb.seconds=X.seconds;        ip_hd_make_ini(&ipb);        /* File read buffer size set */        smode=1;                         // low resolution mode        if(smode ==1){ usampl=10000; }        else {           usampl=50000;           if(sfreq == 40){ usampl=40000; }           if(sfreq == 100){ usampl=100000; }           if(sfreq == 200){ usampl=200000; }        }        imax=(sfreq*1000)/usampl;        numb=usampl*adbit*numch/8;   // # of bytes in unit # of samples        //printf("imax numb  %d %d\n",imax,numb);    //debug        ibuf = (unsigned char *)malloc(numb);        idata = (int *)malloc(4*usampl*sizeof(int));        fact=((float)usampl)*((float)usampl);                /* sampling frequency in text for print */        if(sfreq == 40){strcpy(labfsampl,"40kHz"); }        if(sfreq == 100){strcpy(labfsampl,"100kHz"); }        if(sfreq == 200){strcpy(labfsampl,"200kHz"); }        if(sfreq == 500){strcpy(labfsampl,"500kHz"); }        if(sfreq == 1000){strcpy(labfsampl,"1MHz"); }        if(sfreq == 2000){strcpy(labfsampl,"2MHz"); }        if(sfreq == 4000){strcpy(labfsampl,"4MHz"); }        if(sfreq == 8000){strcpy(labfsampl,"8MHz"); }        if(sfreq == 16000){strcpy(labfsampl,"16MHz"); }       /* Data extract start point set */        //soffset=0;  // if you need to give offset, change this       startoffset=(long int)soffset;       fsec=soffset-(double)startoffset;       sofst_pos=(long int)(fsec/tsampl + 0.01);       /* Data extraction period set */           //   smpl_count=(long int)(period/tsampl + 0.01);       /* Run condition display */       //printf("startoffset, sofst_pos, smpl_count %d %d %d\n",startoffset,sofst_pos,smpl_count);       printf("\n");       printf("  Data File : %s\n",fname);       printf("  Sampling Freq : %s\n",labfsampl);       printf("  A/D bits      : %d\n",adbit);       printf("  Number of CHs : %d\n",numch);       printf("  Extracted CH# : %d\n",nch);       /* foward startffset seconds */       if(fwdNsec(ibuf, startoffset, numb, imax, &X) <0){              goto exitend;       }       printf("  Time %02d:%02d:%02d   Sec in Day = %d\n",X.hh,X.mm,X.ss,X.seconds);       sprintf(ltime1st,"Time(UT) %02d:%02d:%02d\0",X.hh,X.mm,X.ss);       strcpy(lab2,ltime1st);               /* continue run info display */       printf("  Start Time of Extraction : %02d:%02d:%02d.%08d\n",X.hh,X.mm,X.ss,(long int)(fsec*1.0e8));     //  printf("  Period (sec)             : %f\n",period);       printf("  Out File : %s\n",oname);       /* header data update */       ipb.seconds=X.seconds;       ip_hd_make(&ipb);       /* Data info out to out_file *///       if(omode == 0) {//          fprintf(fo,"**  Data File : %s\n",fname);//          fprintf(fo,"**  Sampling Freq : %s\n",labfsampl);//          fprintf(fo,"**  A/D bits      : %d\n",adbit);//          fprintf(fo,"**  Number of CHs : %d\n",numch);//          fprintf(fo,"**  Extracted CH# : %d\n",nch);//          fprintf(fo,"**  Start Time of Data : %02d:%02d:%02d.%08d\n",X.hh,X.mm,X.ss,(long int)(fsec*1.0e8));//         fprintf(fo,"**  Period (sec)       : %f\n",period);//      }              /* Data extraction start */	   counts=0;	   counts2=0;       secc=0;       //m=nch-1;       nloop=0;       ibcount=0;       opos=0;       obuf[opos]=conv4byte2int(ipb.hd);       opos++;       obuf[opos]=conv4byte2int(ipb.hd+4);       opos++;       /* Data read loop start here */loop1:        if(nloop >0) {           if(checkheader(&X) < 0){ goto exitend; }         //   printf("  Time %02d:%02d:%02d   Sec in Day = %d\n",X.hh,X.mm,X.ss,X.seconds);           if(span != 0 && secc > span) goto exitend;           secc++;           /* header data update */           ipb.seconds=X.seconds;           ip_hd_make(&ipb);           /* put K5 header data into obuf */           obuf[opos]=conv4byte2int(ipb.hd);           opos++;           if(opos == nwrite){                //printf("Debug %d\n",nloop);                iwrite=fwrite(obuf,sizeof(int),nwrite,fo);                opos=0;           }           obuf[opos]=conv4byte2int(ipb.hd+4);           opos++;           if(opos == nwrite){                //printf("Debug %d\n",nloop);                iwrite=fwrite(obuf,sizeof(int),nwrite,fo);                opos=0;           }        }        for(i=0; i< imax; i++)        {             bytesread = fread( ibuf, sizeof( char ), numb, X.stream );             //printf("bytes read 2 %d\n",bytesread); //debug             if( ferror( X.stream ) || bytesread==0 ){ goto exithere; }             parseADdata_2(ibuf,numb,adbit,idata, &kpos);        	 //printf("adbit= %d\n",adbit);             for(k=0; k<kpos/numch; k++)             {               	counts++;                idat=idata[k*numch+nch-1];                for(m=0; m< adbit; m++){                    ipick=idat & 0x1;                    //printf(" %d",ipick);                    idat32[ibcount]=ipick;                    ibcount++;                    idat=idat >> 1;                }                if(ibcount==32){                    obuf[opos]=conv32bit2int(idat32);                    opos++;                    if(opos == nwrite){                        //printf("Debug %d\n",nloop);                        iwrite=fwrite(obuf,sizeof(int),nwrite,fo);                        opos=0;                    }                    ibcount=0;                }             }       }       nloop++;       goto loop1;exithere:       printf("\n");       printf("4ch data to 1ch conversion finished.\n");       fgetpos(X.stream,&pos);  //debug       //printf("\n %d bytes read\n",pos);        //counts2--;       //printf("counts2 = %d\n",counts2);       i=fclose( fo ) ;exitend:               free(ibuf);       free(idata);exitend3:        i=fclose( X.stream ) ; exitend2:        return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -