Пример #1
0
int main(int argc,char *argv[]) {
  int ptr;
  int arg;
  FILE *fp;
  int yr,mo,dy,hr,mt; 
  double sc;
  double tme[2];
  void *tptr[2];
  unsigned char help=0;
  unsigned char option=0;

 

  OptionAdd(&opt,"-help",'x',&help);
  OptionAdd(&opt,"-option",'x',&option);

  arg=OptionProcess(1,argc,argv,&opt,NULL);   

 
  if (help==1) {
    OptionPrintInfo(stdout,hlpstr);
    exit(0);
  }
  
  if (option==1) {
    OptionDump(stdout,&opt);
    exit(0);
  }



  if (arg<argc) {
    fp=fopen(argv[arg],"r");
    if (fp==NULL) {
      fprintf(stderr,"File not found.\n");
      exit(-1);
    }
  } else fp=stdin;
  
  tptr[0]=tme;

  ptr=ftell(fp);

  while (RfileRead(fp,0,NULL,tptr) !=-1) {
    TimeEpochToYMDHMS(tme[0],&yr,&mo,&dy,&hr,&mt,&sc);
    fprintf(stdout,"%.4d %.2d %.2d %.2d %.2d %g ",yr,mo,dy,hr,mt,sc);
    TimeEpochToYMDHMS(tme[1],&yr,&mo,&dy,&hr,&mt,&sc);
    fprintf(stdout,"%.4d %.2d %.2d %.2d %.2d %g ",yr,mo,dy,hr,mt,sc);
    fprintf(stdout,"%d\n",ptr);
    ptr=ftell(fp);
  }
  if (arg<argc) fclose(fp);
  return 0;

}
Пример #2
0
int main(int argc,char *argv[]) {

  FILE *fp;
 
  RfileDecoder decode[2];
  void *dptr[2];
  int i;
  int yr,mo,dy,hr,mt; 
  double sc;
 

  if (argc>1) {
    fp=fopen(argv[1],"r");
    if (fp==NULL) {
      fprintf(stderr,"File not found.\n");
      exit(-1);
    }
  } else fp=stdin;
  
  decode[0]=decode_blk1;
  decode[1]=decode_blk2;
  dptr[0]=&data.blk1;
  dptr[1]=&data.blk2;

  while (RfileRead(fp,2,decode,dptr) !=-1) {
    TimeEpochToYMDHMS(data.blk1.st_time,&yr,&mo,&dy,&hr,&mt,&sc);
    fprintf(stdout,"%d-%d-%d %d:%d:%d to ",yr,mo,dy,hr,mt,(int) sc);
    TimeEpochToYMDHMS(data.blk1.ed_time,&yr,&mo,&dy,&hr,&mt,&sc);
    fprintf(stdout,"%d-%d-%d %d:%d:%d\n",yr,mo,dy,hr,mt,(int) sc);
 
    fprintf(stdout,"Block 1\n");
  
    fprintf(stdout,"pnt\tlat\tlon\thgt\tflg\n");
    for (i=0;i<data.blk1.npnt;i++) {
      fprintf(stdout,"%d\t%g\t%g\t%g\t%d\n",i,
             data.blk1.lat[i],data.blk1.lon[i],
             data.blk1.hgt[i],data.blk1.flg[i]);
    
    }
    fprintf(stdout,"Block 2\n");
    fprintf(stdout,"pnt\ta\tb\n");
    for (i=0;i<data.blk2.npnt;i++) {
      fprintf(stdout,"%d\t%d\t%d\n",i,
             data.blk2.a[i],data.blk2.b[i]);
    
    }
    fprintf(stdout,"\n"); 


  }
  if (fp !=stdin) fclose(fp);
  return 0;
}
Пример #3
0
int OldCnvMapFread(FILE *fp,struct CnvMapData *map,struct GridData *grd) {

  RfileDecoder decode[17];
  void *dptr[17];

  decode[0]=OldGridDecodeOne;
  decode[1]=OldGridDecodeTwo;
  decode[2]=OldGridDecodeThree;
  decode[3]=OldGridDecodeFour;
  decode[4]=OldGridDecodeFive;
  decode[5]=OldGridDecodeSix;

  decode[6]=OldCnvMapDecodeOne;
  decode[7]=OldCnvMapDecodeTwo;
  decode[8]=OldCnvMapDecodeThree;
  decode[9]=OldCnvMapDecodeFour;
  decode[10]=OldCnvMapDecodeFourOld;

  decode[11]=OldCnvMapDecodeFive;
  decode[12]=OldCnvMapDecodeSix;
  decode[13]=OldCnvMapDecodeSeven;
  decode[14]=OldCnvMapDecodeEight;
  decode[15]=OldCnvMapDecodeNine;
  decode[16]=OldCnvMapDecodeTen;


  dptr[0]=grd;
  dptr[1]=grd;
  dptr[2]=grd;
  dptr[3]=grd;
  dptr[4]=grd;
  dptr[5]=grd;

  dptr[6]=map;
  dptr[7]=map;
  dptr[8]=map;
  dptr[9]=map;
  dptr[10]=map;
  dptr[11]=map;
  dptr[12]=map;
  dptr[13]=map;
  dptr[14]=map;
  dptr[15]=map;
  dptr[16]=map;

  return RfileRead(fp,17,decode,dptr);

}
Пример #4
0
int RfileSeek(FILE *fp,
	      int yr,int mo,int dy,int hr,int mt,double sc,
              struct RfileIndex *inx,
              double *aval) {

  
  int status=0;

  int tval;

  tval=TimeYMDHMSToEpoch(yr,mo,dy,hr,mt,sc);
  
  if (inx !=NULL) {
    int rec=0,prec=-1;
    int st_rec;
    int ed_rec;

    /* search using index records */

    double st_time,ed_time;
    st_time=inx->st_time;
    ed_time=inx->ed_time;

    st_rec=0;
    ed_rec=inx->num;

    if (tval<st_time) { /* before start of file */
      if (aval !=NULL) *aval=st_time;
      fseek(fp,inx->offset[st_rec],SEEK_SET);
      return 0;
    } else if (tval>ed_time) { /* after end of file */
      if (aval !=NULL) *aval=st_time;
      fseek(fp,inx->offset[ed_rec-1],SEEK_SET);
      return 0;
    }

    do {
     
      prec=rec;
      rec=st_rec+(int) ((tval-st_time)*(ed_rec-st_rec))/(ed_time-st_time);
      if (inx->time.start[rec]==tval) break;
      if (inx->time.start[rec]<tval) {
         st_rec=rec;
         st_time=inx->time.start[rec];
      } else {
         ed_rec=rec;
         ed_time=inx->time.end[rec];
      }
    } while (prec != rec);
    if (aval !=NULL) *aval=inx->time.start[rec]; 
    fseek(fp,inx->offset[rec],SEEK_SET);
    return 0;
  } else {
    int ptr=0,pptr=0;
    double tme[2];
    void *tptr[2];
    tptr[0]=tme;
 
    /* search manually */
    ptr=ftell(fp);
    status=RfileRead(fp,0,NULL,tptr);
    if (status==0) {
      if (tme[0]>tval) fseek(fp,0,SEEK_SET); /* need to rewind to start */
    } else {
      fseek(fp,0,SEEK_SET); /* set to the start of the file */
      status=0;
    }

    if (aval !=NULL) *aval=tme[0];
    while ((tval>tme[0]) && (status !=-1)) {
      pptr=ptr;
      ptr=ftell(fp);
      status=RfileRead(fp,0,NULL,tptr);
      if (aval !=NULL) *aval=tme[0];
    }
    
    if (status==-1) {
      fseek(fp,pptr,SEEK_SET);
      return -1;
    }
    fseek(fp,ptr,SEEK_SET);
   
  }
  return 0;
}