void next_img(char *filpath, char *templ, char *gemtim, char *filnm, int *numc, int *idelt, int *ier) { int nfile, i,iret; int tarr1[5], tarr2[5]; char fname[FILE_FULLSZ],fmnam[80],outtim[20],cgemtim[16]; struct dirent **namelist=NULL; *idelt = 0; st_null(gemtim,cgemtim,&i,&iret,15,16); ti_ctoi(gemtim,tarr1,ier,15); if(*ier != 0) return; /* create the name for which we will compare against */ cfl_mnam(cgemtim, templ, fmnam, &iret); /* return list of files reverse sorted (newest time first) */ cfl_scnt(filpath, templ, -1, &namelist, &nfile, &iret); /* find the first file whose time is older than our current time */ i = 0; while ( i < nfile ) { strcpy(fname, namelist[i]->d_name); cfl_mdat(fname, templ, cgemtim, outtim, &iret); ti_ctoi(outtim,tarr2,&iret,strlen(outtim)); ti_mdif(tarr1, tarr2, idelt, &iret); if ( iret == 0 && *idelt >= 0 ) { sprintf(filnm,"%s/%s\0",filpath,fname); *numc = strlen(filnm); break; } i++; } if ( i >= nfile ) *ier = -1; for ( i=0; i < nfile; i++) { free(namelist[i]); } if ( namelist != NULL ) free(namelist); }
void dgc_nrdt ( const int *ifpn, const char *time1, const char *time2, const int *level1, const int *level2, const int *ivcord, const char *parm, float *grid, int *igx, int *igy, int *ighd, int *iret ) /************************************************************************ * dgc_nrdt * * * * This subroutine reads the requested grid from a grid file by calling * * GD_RDAT. It also applies any specific functions to the grid, for * * example, adding a column of data or subsetting. * * * * dgc_nrdt ( ifpn, time1, time2, level1, level2, ivcord, parm, grid, * * igx, igy, ighd, iret ) * * * * Input parameters: * * *ifpn const int GDFILE entry position number * * *time1 const char GEMPAK grid date-time * * *time2 const char GEMPAK grid date-time * * *level1 const int GEMPAK grid levle * * *level2 const int GEMPAK grid levle * * *ivcord const int GEMPAK vertical coordinate * * 0 = NONE * * 1 = PRES * * 2 = THTA * * 3 = HGHT * * *parm const char GEMPAK parameter name * * * * Output parameters: * * *grid float Grid data * * *igx int Number of horizontal points * * *igy int Number of vertical points * * *ighd int Grid header * * *iret int Return code * * 0 = normal return * * -7 = grid not found * * -30 = open grid failed * * -31 = navigation not same * ** * * Log: * * R. Tian/SAIC 10/03 * * K. Brill/HPC 01/04 Check Ret code from GD subroutines; do * * not pass parameter as returnable arg * * K. Brill/HPC 02/04 CALL ER_WMSG for -31 * * K. Brill/HPC 02/04 Remove all other ER_WMSG calls * * R. Tian/SAIC 2/04 Modified to use new GD file management * * R. Tian/SAIC 5/04 Added call to DG_T2IG * * R. Tian/SAIC 11/04 Added check for PARM == DRCT * * R. Tian/SAIC 2/06 Recoded from Fortran * * D.W.Plummer/NCEP 10/06 Dynamically allocate transfer grid * ************************************************************************/ { char filnam[MXFLSZ+1], tmpnam[MXFLSZ+1], uparm[14]; float rnvblk[LLNNAV], adum; int ifidx, igdf, mxgd, navsz, zero, ier; float *transfer_grid; /*----------------------------------------------------------------------*/ *iret = 0; navsz = LLNNAV; zero = 0; ifidx = (*ifpn) - 1; if ( strlen ( _nfile.ntmplt[ifidx] ) == 0 || ( strcmp ( time1, _nfile.crtgdt1[ifidx] ) == 0 && strcmp ( time2, _nfile.crtgdt2[ifidx] ) == 0 ) ) { /* * This GDFILE entry is an actual file */ strcpy ( filnam, _nfile.crtfnm[ifidx] ); } else { /* * This GDFILE entry is a template */ cfl_mnam ( (char *)time1, _nfile.ntmplt[ifidx], tmpnam, &ier ); strcpy ( filnam, _nfile.gflpth[ifidx] ); strcat ( filnam, "/" ); strcat ( filnam, tmpnam ); strcpy ( _nfile.crtfnm[ifidx], filnam ); } gd_open ( filnam, &_nfile.outflg[ifidx], &zero, &navsz, &igdf, &adum, rnvblk, &mxgd, &ier, strlen(filnam) ); if ( ier != 0 ) { *iret = -30; return; } /* * Allocate the transfer grid based on the kx and ky of the nav block. * Add 1 to kx to account for the possibility of adding a column later. */ G_MALLOC ( transfer_grid, float, ((int)((rnvblk[4]+1)*rnvblk[5])), "Error allocating transfer grid" ); cgd_rdat ( &igdf, time1, time2, level1, level2, ivcord, parm, transfer_grid, igx, igy, ighd, &ier ); if ( ier != 0 ) { *iret = -7; } else { strcpy ( _nfile.crtgdt1[ifidx], time1 ); strcpy ( _nfile.crtgdt2[ifidx], time2 ); /* * Transfer just-read grid navigation to internal grid navigation. */ cst_lcuc ( (char *)parm, uparm, &ier ); if ( strcmp ( uparm, "DRCT" ) == 0 ) { ighd[1] = 1; } dg_t2ig ( rnvblk, ighd, transfer_grid, grid, igx, igy, &ier ); if ( ier != 0 ) { *iret = -7; } } G_FREE ( transfer_grid, float ); return; }
void dcflnam ( char *gemfil, char *filnam, int *maxgrids, int *ier) { int itime[3],iaccm; char dattim[DTTMSZ]; char ftmpl[256]; char *cpos; int lens, iret; *ier = 0; gb_ftim ( itime, &iaccm, &iret); /*tg_itoc ( itime, dattim, &iret, sizeof(dattim) - 1 );*/ dattim[0] = '\0'; ctg_itoc ( itime, dattim, &iret); cst_rmbl ( dattim, dattim, &lens, &iret); if((gemfil != NULL)&&(gemfil[0] != '\0')) { strcpy(filnam,gemfil); cfl_mnam ( dattim, gemfil, filnam, &iret); } else { tbtmpl(pds.center,pds.izero,pds.process,pds.grid_id,ftmpl,maxgrids,&iret); if(iret != 0) { *ier = -1; filnam[0] = '\0'; return; } strcpy(filnam,ftmpl); cfl_mnam ( dattim, ftmpl, filnam, &iret); } if((cpos = (char *)strstr(filnam,"@@@")) != NULL) { cpos[0] = 48 + (pds.grid_id / 100); cpos[1] = 48 + ((pds.grid_id / 10)%10); cpos[2] = 48 + (pds.grid_id % 10); } if((cpos = (char *)strstr(filnam,"###")) != NULL) { cpos[0] = 48 + (pds.process / 100); cpos[1] = 48 + ((pds.process / 10)%10); cpos[2] = 48 + (pds.process % 10); } if((cpos = (char *)strstr(filnam,"%%%")) != NULL) { cpos[0] = 48 + (pds.izero / 100); cpos[1] = 48 + ((pds.izero / 10)%10); cpos[2] = 48 + (pds.izero % 10); } if((cpos = (char *)strstr(filnam,"%subc%")) != NULL) { if(pds.izero != 0) { char *subtemp; subtemp = tbsubcenter(&pds.center,&pds.izero); cst_rpst(filnam,"%subc%", subtemp, ftmpl, &iret); } else cst_rpst(filnam,"%subc%", "", ftmpl, &iret); if(iret == 0) sprintf(filnam,"%s\0",ftmpl); } }
void dgc_nwdt ( const float *grid, const char *time1, const char *time2, const int *level1, const int *level2, const int *ivcord, const char *parm, const int *igdhdr, const char *gpack, const int *rplc, int *iret ) /************************************************************************ * dgc_nwdt * * * * This subroutine writes a packed grid. * * * * dgc_nwdt ( grid, time1, time2, level1, level2, ivcord, parm, igdhdr, * * gpack, rplc, iret ) * * * * Input parameters: * * *grid const float Grid to write out * * *time1 const char GEMPAK times * * *time2 const char GEMPAK times * * *level1 const int GEMPAK grid levle * * *level2 const int GEMPAK grid levle * * *ivcord const int Vertical coordinate * * *parm const char GEMPAK parameter name * * *igdhdr const int Grid header * * *gpack const char Grid packing from user input * * *rplc const int Flag to replace existing grid * * * * Output parameters: * * *iret int Return code * * 0 = normal return * * -61 = grid file open failed * ** * * Log: * * R. Tian/SAIC 3/04 * * R. Tian/SAIC 1/05 Changed LLNANV to LLNNAV * * R. Tian/SAIC 5/05 Added outflg checking * * D.W.Plummer/NCEP 5/05 Add calls to ER_WMSG * * R. Tian/SAIC 3/06 Recoded from Fortran * ************************************************************************/ { char filnam[MXFLSZ+1], fullnm[MXFLSZ+1]; float rnvblk[LLNNAV], adum1; int same; int iout, ifn, mxgd, ipktyp, nbits, navsz, zero, i, ier, ierr; /*----------------------------------------------------------------------*/ *iret = 0; navsz = LLNNAV; zero = 0; iout = -1; for ( i = 0; i < NGDFLS; i++ ) { if ( _nfile.outflg[i] == G_TRUE ) { iout = i; break; } } if ( iout == -1 ) { *iret = -61; return; } /* * Open the output file */ if ( _nfile.ntmplt[iout][0] != '\0' ) { /* * This entry is a template */ cfl_mnam ( (char *)time1, _nfile.ntmplt[iout], filnam, &ier ); strcpy ( fullnm, _nfile.gflpth[iout] ); strcat ( fullnm, "/" ); strcat ( fullnm, filnam ); } else { /* * This entry is an actual file */ strcpy ( fullnm, _nfile.crtfnm[iout] ); } gd_open ( fullnm , &_nfile.outflg[iout], &zero, &navsz, &ifn, &adum1, rnvblk, &mxgd, &ier, strlen(fullnm) ); if ( ier != 0 ) { er_wmsg ( "GD", &ier, " ", &ierr, strlen("GD"), strlen(" ") ); *iret = -61; return; } /* * Compare the returned navigation with the internal navigation */ grc_cnav ( rnvblk, _dgfile.snav, &navsz, &same, &ier ); if ( ier != 0 ) { er_wmsg ( "GR", &ier, " ", &ierr, strlen("GD"), strlen(" ") ); } if ( same == G_FALSE ) { *iret = -64; return; } /* * Write the packed grid */ grc_pack ( gpack, &ipktyp, &nbits, &ier ); cgd_wpgd ( &ifn, grid, &_dgfile.kxd, &_dgfile.kyd, igdhdr, time1, time2, level1, level2, ivcord, parm, rplc, &ipktyp, &nbits, &ier ); if ( ier != 0 ) { er_wmsg ( "GD", &ier, " ", &ierr, strlen("GD"), strlen(" ") ); *iret = -65; return; } return; }
int write_point(nldn_file ltgf, nldn_flash flashdat, int *iret) { int i,numerr,loglev,ier,isfull; char errstr[80],filnam[256]; static char tmplnam[256], oldnam[256]; static char errgrp[] = {"write_point"}; static int iflno=-1; char cparms[40][4],stid[5]; int nparms; float ndata[8]; static int jparms[40]; static char stnfil[] = {" "}; static int nadstn = 0; int year, month, day, hour, minute, seconds, isecoff; int idtarr[5],idate,itime,ihhmm; time_t obs_time; char timestr[81],gemtime[20]; struct tm *gmt_time=NULL,new_time; static int filseq=-1; /* printf("flashdat.angle = %f\n", flashdat.angle); */ if(iflno < 0) { tmplnam[0] = '\0'; oldnam[0] = '\0'; } obs_time = (time_t) flashdat.sec; gmt_time = gmtime(&obs_time); new_time = *gmt_time; /* copy the time since gmtime pointer is volotile */ timestr[0] = '\0'; strftime(timestr,80,"%Y %m %d %H %M %S",&new_time); sscanf(timestr,"%d %d %d %d %d %d",&year,&month,&day,&hour,&minute,&seconds); idtarr[0] = year; idtarr[1] = month; idtarr[2] = day; idtarr[3] = hour; /* if itype ==4 using minute bins, use bin for NN template */ if(ltgf.itype == 4) idtarr[4] = ltgf.ibin*(minute / ltgf.ibin); else idtarr[4] = minute; ti_itoc(idtarr,gemtime,&ier,sizeof(gemtime)); for(i=0;i<sizeof(gemtime);i++) if(gemtime[i] <= ' ') gemtime[i] = '\0'; /* get ihhmm idate and itime for data storage using sfnldn */ idate = (year % 100 ) * 10000 + month * 100 + day; ihhmm = hour * 100 + minute; /* do ifactor */ if(ltgf.itype == 4) itime = ltgf.ifactor*(minute / ltgf.ifactor); else itime = 0; itime = itime + (hour * 100); /* calculate seconds in the day */ isecoff = (new_time.tm_hour * 3600) + (new_time.tm_min * 60) + new_time.tm_sec; cfl_mnam(gemtime, ltgf.gemfil, filnam, &ier ); strcpy(tmplnam,filnam); if( oldnam[0] == '\0' ) { filseq = 0; templseq(tmplnam,filnam,filseq); dc_fcyl(filnam,<gf.iflsrc,stnfil,&nadstn,<gf.maxtim, &iflno, &nparms, cparms, &ier, strlen(filnam),strlen(stnfil),sizeof(cparms[0])); sprintf(errstr,"Opened output file %s\0",filnam); loglev = 1; numerr = ier; dc_wclg(loglev, errgrp, numerr, errstr, &ier); setcparm(cparms,&nparms,jparms,4); } else { if(strcmp(oldnam,tmplnam) != 0) { nldnflush(&iflno,&ier); dc_fcls(&ier); filseq = 0; templseq(tmplnam,filnam,filseq); dc_fcyl(filnam,<gf.iflsrc,stnfil,&nadstn,<gf.maxtim, &iflno, &nparms, cparms, &ier, strlen(filnam),strlen(stnfil),sizeof(cparms[0])); sprintf(errstr,"New output file %s\0",filnam); loglev = 1; numerr = ier; dc_wclg(loglev, errgrp, numerr, errstr, &ier); setcparm(cparms,&nparms,jparms,4); } } /* do the write */ memset(stid,0,5); if( flashdat.sgnl < 0 ) strcat(stid,"- "); else strcat(stid,"+ "); for(i=0;i<8;i++) ndata[i] = -9999.; if( jparms[SGNL] != 0 ) ndata[jparms[SGNL] - 1] = flashdat.sgnl; if( jparms[MULT] != 0 ) ndata[jparms[MULT] - 1] = flashdat.mult; if( jparms[TSEC] != 0 ) ndata[jparms[TSEC] - 1] = isecoff; if( jparms[MSEC] != 0 ) ndata[jparms[MSEC] - 1] = flashdat.nsec/1e6; if( jparms[SMAJ] != 0 ) ndata[jparms[SMAJ] - 1] = flashdat.semimaj; if( jparms[ECNT] != 0 ) ndata[jparms[ECNT] - 1] = flashdat.eccent; if( jparms[ANGL] != 0 ) ndata[jparms[ANGL] - 1] = flashdat.angle; if( jparms[CHI2] != 0 ) ndata[jparms[CHI2] - 1] = flashdat.chisqr; sprintf(errstr,"%s %6.2f %7.2f\0",gemtime,flashdat.lat,flashdat.lon); loglev = 3; numerr = 0; dc_wclg(loglev, errgrp, numerr, errstr, &ier); isfull = 0; sfnldn(&iflno,&idate,&itime,stid,&flashdat.lat,&flashdat.lon, &ihhmm, ndata, &ier, 4); if(ier != 0) { if(ier == -1) isfull = -1; sprintf(errstr,"%s %d\0",filnam,ier); loglev = 1; numerr = 0; dc_wclg(loglev, errgrp, numerr, errstr, &ier); } while((isfull == -1)&&(filseq < 100)) { nldnflush(&iflno,&ier); dc_fcls(&ier); filseq++; templseq(tmplnam,filnam,filseq); dc_fcyl(filnam,<gf.iflsrc,stnfil,&nadstn,<gf.maxtim, &iflno, &nparms, cparms, &ier, strlen(filnam),strlen(stnfil),sizeof(cparms[0])); setcparm(cparms,&nparms,jparms,4); printf("got here...need to reload ndata\n"); sfnldn(&iflno,&idate,&itime,stid,&flashdat.lat,&flashdat.lon, &ihhmm, ndata, &ier, 4); isfull = ier; loglev = 1; numerr = ier; sprintf(errstr,"New output file %s\0",filnam); dc_wclg(loglev, errgrp, numerr, errstr, &ier); } oldnam[0] = '\0'; strcat(oldnam,tmplnam); *iret = ier; return(iflno); }