void clo_times ( fdttms_t start, int inc, int ntimes, fdttms_t *time, int *iret ) /************************************************************************ * clo_times * * * * This function calculates a range of times based on the increment. * * * * clo_times (start, inc, ntimes, time, iret) * * * * Input parameters: * * start fdttms_t Point #2 Time (YYMMDD/HHMM) * * inc int Track increment in minutes * * ntimes int Number of future times * * * * Output parameters: * * *time fdttms_t Time array (YYMMDD/HHMM) * * *iret int Return value * * * ** * * Log: * * S. Law/GSC 05/99 moved from clo_track * * S. Law/GSC 07/00 changed to use GEMPAK times * * M. Li/GSC 10/00 changed increment to any integer * ***********************************************************************/ { int ii, iarray[5], ier, imod; /*---------------------------------------------------------------------*/ *iret = 0; ti_ctoi (start, iarray, &ier, strlen (start)); imod = inc - (iarray[4] % inc); for (ii = 0; ii < ntimes; ii++) { ti_addm (iarray, &imod, iarray, &ier); ti_itoc (iarray, time[ii], &ier, (FDTTMS_SIZE - 1)); time[ii][DTTMS_SIZE - 1] = '\0'; imod = inc; } }
void nim_flnm ( const char *imgtyp, const char *imginf, char *basetm, char *endtim, int mrange, int intrvl, Boolean bflag, Boolean bauto, char *path, char ***namarr, char ***timarr, int *ntimes, int *iret ) /************************************************************************ * nim_flnm * * * * This routine returns an array of file names given the image info. * * The type of image, SAT or RAD, and the image info, which is the * * directory of the data, are used to locate the image data files on * * disk. For satellite images, the info is the part of the directory * * path that defines the source/geog_area/channel. For radar images, * * the info is lcl_or_natl/area/type. * * * * void nim_flnm ( imgtyp, imginf, basetm, endtim, mrange, intrvl, * * bflag, bauto, path, namarr, timarr, nfound, iret ) * * * * Input parameters: * * *imgtyp const char Type of image * * *imginf const char Directory information * * *basetm char Base time * * *endtim char End time of range * * mrange int Minutes in time range * * intrvl int Minutes in time interval * * bflag Boolean Reference time flag * * bauto Boolean Auto update flag * * * * Output parameters: * * *path char Full directory path * * ***namarr char Array of all file names * * ***timarr char Array of all file times * * *ntimes int Number of files/times returned * * *iret int Return code * * -3 = no files found * ** * * Log: * * S. Jacobs/NCEP 8/99 Created * * S. Jacobs/NCEP 2/00 Use the path and templ from datatype.tbl* * S. Jacobs/NCEP 7/00 Moved error check to after FL_SCND call * * S. Jacobs/NCEP 8/00 Added check: len of tmpl = len of file * * S. Jacobs/NCEP 3/01 Increased file template to 48 chars * * S. Jacobs/NCEP 9/01 Ignore the non-date part of the template* * A. Hardy/SAIC 2/02 Changed call FL_SCND * * T. Lee/SAIC 6/02 Handled wild card template; return ipos * * T. Lee/SAIC 9/04 Replaced FL_TMPL with CTB_DTGET * * A. Hardy/NCEP 11/04 Added calls to ST_RNUL * * m.gamazaychikov/SAIC 12/04 Added ion flag to CTB_DTGET CS * * m.gamazaychikov/SAIC 01/06 Changed ctmpl string length to MXTMPL * * m.gamazaychikov/SAIC 04/06 Added idtmch flag to CTB_DTGET CS * * T. Piper/SAIC 04/07 Re-wrote in 'C'; dynamic arrays * * T. Piper/SAIC 10/07 Check value of nt before cti_tmln * * F. J. Yen/NCEP 4/08 Add bin mins and mstrct to CTB_DTGET CSC* ***********************************************************************/ { long istar; int ic, is, nf, ir, ii, kk, ion, ihb, iha, idtmch, iorder, lens; int imb, ima, mstrct; int ier, ier1, ier2, itarr[5], jtarr[5], lenf, lent, mdif, ndif, nt; int idir=-1, idelrt=-1, nfiles; size_t timlen=DTTMS_SIZE; /* * The following dimensions are based upon the sizes in the datatype.tbl * plus one for the null character; then rounded up to the neartest * multiple of four. */ char *pstar, **t_names=NULL, **t_times=NULL, **tarr=NULL; char cpath[28], ctmpl[MXTMPL], tmplt[MXTMPL]; dattm_t strtim; nmlst_t tfil; struct dirent **dnlist=NULL; /*---------------------------------------------------------------------*/ /* * Construct the directory name from the image data attributes. */ ctb_dtget ( (char*)imgtyp, cpath, ctmpl, &ic, &is, &nf, &ir, &ii, &ion, &ihb, &imb, &iha, &ima, &mstrct, &idtmch, &ier ); strcpy ( path, cpath ); strcat ( path, "/" ); strcat ( path, imginf ); /* * Scan the directory. */ iorder = 1; cfl_scnt ( path, ctmpl, iorder, &dnlist, &nfiles, &ier ); /* * If there are no files, there is an error. */ if ( nfiles > 0 ) { /* * Construct the full file name template for this directory. */ pstar = strchr(ctmpl, '*' ); if ( pstar == NULL ) { /* No '*' was found in the template. */ strcpy(tmplt, ctmpl); } else { /* An '*' was found in the template. */ istar = ( pstar - ctmpl ); if ( istar == 0 ) { /* An '*' was found at the beginning of the template. */ strcpy(tmplt, (ctmpl+2)); } else { cst_ncpy(tmplt, ctmpl, istar, &ier); } } /* * Convert each file name to a time. */ cst_lstr(tmplt, &lent, &ier ); cst_lstr(dnlist[0]->d_name, &lenf, &ier ); G_MALLOC(tarr, char*, nfiles, "nim_flnm: tarr"); for ( ii = 0; ii < nfiles; ii++ ) { G_CALLOC(tarr[ii], char, timlen, "nim_flnm: tarr[ii]"); if ( pstar == NULL ) { cfl_mdat(dnlist[ii]->d_name, tmplt, "YYMMDD/HHNN", tarr[ii], &ier ); } else { if ( istar == 0 ) { strcpy(tfil, dnlist[ii]->d_name+(lenf-lent)); } else { cst_ncpy(tfil, dnlist[ii]->d_name, lent, &ier); } cfl_mdat(tfil, tmplt, "YYMMDD/HHNN", tarr[ii], &ier ); } } /* * Sort the times. */ qsort( (void*)tarr, (size_t)nfiles, sizeof(char*), compare ); cti_yyyy(nfiles, tarr, tarr, &ier); /* * Compute the start time of the range from the end time * and the number of minutes. */ ti_ctoi ( endtim, itarr, &ier, strlen(endtim) ); ti_subm ( itarr, &mrange, jtarr, &ier ); ti_itoc ( jtarr, strtim, &ier, sizeof(strtim) ); st_null ( strtim, strtim, &lens, &ier, sizeof(strtim), sizeof(strtim) ); /* * Find the number of times to return. */ nt = 0; for ( ii = 0; ii < nfiles; ii++ ) { ti_diff ( strtim, tarr[ii], &mdif, &ier1, strlen(strtim), timlen-1 ); ti_diff ( tarr[ii], endtim, &ndif, &ier2, timlen-1, strlen(endtim)); if ( ( ier1 == 0 ) && ( ier2 == 0 ) ) { if ( ( mdif <= 0 ) && ( ndif <= 0 ) ) { G_REALLOC(t_names, char*, nt+1, "nim_flnm: t_names"); G_MALLOC(t_names[nt], char, (strlen(dnlist[ii]->d_name)+1), "nim_flnm: t_names[nt]"); strcpy(t_names[nt], dnlist[ii]->d_name); G_REALLOC(t_times, char*, nt+1, "nim_flnm: t_times"); G_MALLOC(t_times[nt], char, (strlen(tarr[ii])+1), "nim_flnm: t_times[nt]"); strcpy(t_times[nt], tarr[ii]); nt++; } } G_FREE(tarr[ii], char); free (dnlist[ii]); }
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); }