int main(int argc,char *argv[]) { FILE *fp; struct RfileIndex *inx=NULL; int yr=2005,mo=3,dy=31,hr=10,mt=30; double sc=0,atme; int s; if (argc>2) { fp=fopen(argv[2],"r"); if (fp==NULL) { fprintf(stderr,"Index not found.\n"); exit(-1); } inx=RfileLoadIndex(fp); fclose(fp); if (inx==NULL) { fprintf(stderr,"Error loading index.\n"); exit(-1); } } fp=fopen(argv[1],"r"); if (fp==NULL) { fprintf(stderr,"File not found.\n"); exit(-1); } s=OldCnvMapFseek(fp,yr,mo,dy,hr,mt,(int) sc,inx,&atme); if (s==-1) { fprintf(stderr,"file does not contain that interval.\n"); exit(-1); } fprintf(stdout,"Requested:%.4d-%.2d-%.2d %.2d:%.2d:%.2d\n", yr,mo,dy,hr,mt,(int) sc); TimeEpochToYMDHMS(atme,&yr,&mo,&dy,&hr,&mt,&sc); fprintf(stdout,"Found:%.4d-%.2d-%.2d %.2d:%.2d:%.2d\n", yr,mo,dy,hr,mt,(int) sc); while(OldCnvMapFread(fp,&map,&grd) !=-1) { TimeEpochToYMDHMS(map.st_time,&yr,&mo,&dy,&hr,&mt,&sc); fprintf(stdout,"%.4d-%.2d-%.2d %.2d:%.2d:%.2d pnts=%d\n", yr,mo,dy,hr,mt,(int) sc,grd.vcnum); } fclose(fp); return 0; }
static IDL_VPTR IDLOldCnvMapSeek(int argc,IDL_VPTR *argv,char *argk) { struct OldCnvMapIDLInx *ifptr; int s=0,n; struct RfileIndex *finx=NULL; static IDL_VPTR vatme; double atme=0; int outargc=0; IDL_VPTR outargv[8]; static IDL_KW_PAR kw_pars[]={IDL_KW_FAST_SCAN, {"ATME",IDL_TYP_UNDEF,1, IDL_KW_OUT | IDL_KW_ZERO,0, IDL_CHARA(vatme)}, {NULL}}; IDL_LONG unit=0,yr=0,mo=0,dy=0,hr=0,mt=0,sc=0; IDL_FILE_STAT stat; FILE *fp=NULL; IDL_KWCleanup(IDL_KW_MARK); outargc=IDL_KWGetParams(argc,argv,argk,kw_pars,outargv,1); IDL_ENSURE_SCALAR(outargv[0]); IDL_ENSURE_SCALAR(outargv[1]); IDL_ENSURE_SCALAR(outargv[2]); IDL_ENSURE_SCALAR(outargv[3]); IDL_ENSURE_SCALAR(outargv[4]); IDL_ENSURE_SCALAR(outargv[5]); IDL_ENSURE_SCALAR(outargv[6]); if (outargc>7) IDL_ENSURE_ARRAY(outargv[7]); unit=IDL_LongScalar(outargv[0]); s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_USER); if (s==FALSE) { s=-1; return (IDL_GettmpLong(s)); } /* Get information about the file */ IDL_FileFlushUnit(unit); IDL_FileStat(unit,&stat); /* Find the file pointer */ fp=stat.fptr; if (fp==NULL) { s=-1; return (IDL_GettmpLong(s)); } yr=IDL_LongScalar(outargv[1]); mo=IDL_LongScalar(outargv[2]); dy=IDL_LongScalar(outargv[3]); hr=IDL_LongScalar(outargv[4]); mt=IDL_LongScalar(outargv[5]); sc=IDL_LongScalar(outargv[6]); /* test for existence of index */ if (outargc>7) { /* decode index here */ finx=malloc(sizeof(struct RfileIndex)); if (finx==NULL) { s=-1; return (IDL_GettmpLong(s)); } finx->num=outargv[7]->value.s.arr->n_elts; finx->time.start=malloc(sizeof(double)*finx->num); if (finx->time.start==NULL) { s=-1; free(finx); return (IDL_GettmpLong(s)); } finx->time.end=malloc(sizeof(double)*finx->num); if (finx->time.end==NULL) { s=-1; free(finx->time.start); free(finx); return (IDL_GettmpLong(s)); } finx->offset=malloc(sizeof(int)*finx->num); if (finx->offset==NULL) { s=-1; free(finx->time.start); free(finx->time.end); free(finx); return (IDL_GettmpLong(s)); } for (n=0;n<finx->num;n++) { ifptr=(struct OldCnvMapIDLInx *) (outargv[7]->value.s.arr->data+ n*outargv[7]->value.s.arr->elt_len); finx->time.start[n]=ifptr->st_time; finx->time.end[n]=ifptr->ed_time; finx->offset[n]=ifptr->offset; } finx->st_time=finx->time.start[0]; finx->ed_time=finx->time.end[finx->num-1]; } s=OldCnvMapFseek(fp,yr,mo,dy,hr,mt,sc,finx,&atme); if (vatme) IDL_StoreScalar(vatme,IDL_TYP_DOUBLE,(IDL_ALLTYPES *) &atme); if (finx !=NULL) { free(finx->time.start); free(finx->time.end); free(finx->offset); free(finx); } IDL_KWCleanup(IDL_KW_CLEAN); return (IDL_GettmpLong(s)); }
int32 OldCnvMapIDLSeek(int argc,char *argv[]) { struct RfileIndex inx; IDL_FILE_STAT stat; FILE *fp; int unit,s; int32 yr,mo,dy,hr,mt; double sc; double *atme; inx.num=0; inx.time.start=NULL; inx.time.end=NULL; inx.offset=NULL; unit = *( (int32 *) argv[0]); /* Make sure that the "STDIO" keyword was used to * open the file in IDL. */ s=IDL_FileEnsureStatus(IDL_MSG_RET,unit,IDL_EFS_STDIO); if (s==FALSE) return -1; /* Get information about the file */ IDL_FileStat(unit,&stat); /* Find the file pointer */ fp=stat.fptr; if (fp==NULL) return -1; fflush(fp); yr=*( (int32 *) argv[1]); mo=*( (int32 *) argv[2]); dy=*( (int32 *) argv[3]); hr=*( (int32 *) argv[4]); mt=*( (int32 *) argv[5]); sc=*( (double *) argv[6]); atme=(double *) argv[7]; if (argc>8) { inx.num=*( (int32 *) argv[8]); if (inx.num !=0) inx.time.start=malloc(sizeof(double)*inx.num); if (inx.time.start !=NULL) inx.time.end=malloc(sizeof(double)*inx.num); if ((inx.time.start !=NULL) && (inx.time.end !=NULL)) inx.offset=malloc(sizeof(int32)*inx.num); if (inx.offset==NULL) { if (inx.time.start !=NULL) free(inx.time.start); if (inx.time.end !=NULL) free(inx.time.end); inx.time.start=NULL; inx.time.end=NULL; inx.num=0; } if ((inx.time.start !=NULL) && (inx.time.end !=NULL) && (inx.offset !=NULL)) { memcpy(inx.time.start,argv[9],sizeof(double)*inx.num); memcpy(inx.time.end,argv[10],sizeof(double)*inx.num); memcpy(inx.offset,argv[11],sizeof(int32)*inx.num); inx.st_time=inx.time.start[0]; inx.ed_time=inx.time.end[inx.num-1]; } } if (inx.num !=0) s=OldCnvMapFseek(fp,yr,mo,dy,hr,mt,(int) sc,&inx,atme); else s=OldCnvMapFseek(fp,yr,mo,dy,hr,mt,(int) sc,NULL,atme); if (inx.num !=0) { free(inx.offset); free(inx.time.start); free(inx.time.end); } return s; }