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]); }
void de_mbr1 ( const int *k, const char *infl, char *outfl, int *iret ) /************************************************************************ * de_mbr1 * * * * This subroutine parses a GDFILE entry to find and handle ensemble * * specifications. It is called from DG_NFIL. The routine turns an * * ensemble entry into a single entry that DG_NFIL can handle. * * * * de_mbr1 ( k, infl, outfl, iret ) * * * * Input parameters: * * *k const int GDFILE entry position number * * *infl const char Input file entry * * * * Output parameters: * * *outfl char* Output file replaces INFL * * *iret int Return code * * 0 = normal return * * -2 = grid file or template not * * exist * * * * Log: * * T. Lee/SAIC 12/04 * * T. Lee/SAIC 06/05 Parsed weight value * * R. Tian/SAIC 12/05 Translated from Fortran * * m.gamazaychikov/SAIC 04/06 Added idtmch flag to CTB_DTGET CS * * T. Piper/SAIC 04/07 Modified for cfl_scnt CSC * * F. J. Yen/NCEP 4/08 Added bin mins & mstrct to CTB_DTGET CSC* * S. Jacobs/NCEP 12/11 Fixed check if there is no table entry * * returned by ctb_dtget * ***********************************************************************/ { int index, nfarr, ic, is, iff, ir, ii, ino, ihb, mnb, iha, mna, mstrct, idtmch, nfile, istar, last, len, ier; long lens; char lsv[MXFLSZ], newfil[MXFLSZ], filnam[MXFLSZ], cycle[DTTMSZ], path[MXFLSZ], tmplt[MXFLSZ], dum[DTTMSZ], rplc[DTTMSZ], membr[17]; char *opnptr, *clsptr, *starp, *ptr, **farr, *def = " "; struct dirent **dnlist=NULL; /*----------------------------------------------------------------------*/ *iret = 0; outfl[0] = '\0'; /* * Check if INFL contains a curly-bracket enclosed ensemble spec. * If not, the first entry is not an ensemble grid. Do nothing. */ opnptr = strchr ( infl, '{' ); if ( ! opnptr ) { strcpy ( outfl, infl ); return; } /* * Save the string between curly brackets to ensspc (k). Get * the first element of the file(s). */ cst_opcl ( infl, opnptr, &clsptr, &ier ); if ( ier != 0 ) { *iret = -2; return; } for ( index = 0, ptr = opnptr + 1; ptr < clsptr; index++, ptr++ ) { _ensdiag.ensspc[*k-1][index] = *ptr; } _ensdiag.ensspc[*k-1][index] = '\0'; clsptr = strchr ( _ensdiag.ensspc[*k-1], ',' ); if ( ! clsptr ) { strcpy ( lsv, _ensdiag.ensspc[*k-1] ); } else { for ( index = 0, ptr = _ensdiag.ensspc[*k-1]; ptr < clsptr; index++, ptr++ ) { lsv[index] = *ptr; } lsv[index] = '\0'; } /* * If file name is not an alias, do nothing. */ cfl_inqr ( lsv, NULL, &lens, newfil, &ier ); if ( ier == 0 ) { strcpy ( outfl, lsv ); return; } /* * Get the template. If the template does not end with "*", * do nothing. */ farr = (char **)cmm_malloc2d ( 2, MXFLSZ, sizeof(char), &ier ); if ( strchr ( lsv, '%' ) ) { cst_clst ( lsv, '%', def, 2, MXFLSZ, farr, &nfarr, &ier ); strcpy ( lsv, farr[1] ); } cst_clst ( lsv, '|', def, 2, MXFLSZ, farr, &nfarr, &ier ); strcpy ( filnam, farr[0] ); strcpy ( cycle, farr[1] ); cmm_free2d ( (void **)farr, &ier ); ctb_dtget ( filnam, path, tmplt, &ic, &is, &iff, &ir, &ii, &ino, &ihb, &mnb, &iha, &mna, &mstrct, &idtmch, &ier ); if ( ier != 0 ) { strcpy ( outfl, lsv ); return; } else { starp = strchr ( tmplt, '*' ); istar = (int)( starp - tmplt ); if ( ! starp ) { strcpy ( outfl, lsv ); return; } } /* * If the template contains an "*", then it is an ensemble with * multiple members. The last member is the one sought. */ if ( strcmp ( cycle, def ) != 0 ) { cti_stan ( cycle, "YYMMDD/HHNN", dum, &ier ); if ( strstr ( tmplt, "YYYYMMDD" ) ) { strcpy ( rplc, "YY" ); strncat ( rplc, dum, 6 ); rplc[8] = '\0'; cst_rpst ( tmplt, "YYYYMMDD", rplc, tmplt, &ier ); } else { strncpy ( rplc, dum, 6 ); rplc[6] = '\0'; cst_rpst ( tmplt, "YYMMDD", rplc, tmplt, &ier ); } strncpy ( rplc, &dum[7], 2 ); rplc[2] = '\0'; cst_rpst ( tmplt, "HH", rplc, tmplt, &ier ); } /* * Retrieve the last member of the ensemble alias. */ cfl_scnt ( path, tmplt, -1, &dnlist, &nfile, &ier ); if ( nfile == 0 ) { *iret = -2; er_wmsg ( "DE", iret, " ", &ier, strlen("DE"), strlen(" ") ); return; } strcpy ( newfil, dnlist[0]->d_name ); for (ii=0;ii<nfile;ii++){ free(dnlist[ii]); } if ( dnlist != NULL ) free(dnlist); /* * Replace "*" in the template with member names. Note * that "*" may be embedded in the template. */ if ( *(starp+1) == '\0' ) { last = G_TRUE; } else { last = G_FALSE; } if ( last == G_TRUE ) { strcpy ( membr, &newfil[istar] ); } else { len = strlen ( newfil ) - strlen ( tmplt ) + 1; cst_ncpy ( membr, &newfil[istar], len, &ier ); } /* * Recombine the alias and last member with the cycle. */ strcpy ( outfl, filnam ); strcat ( outfl, ":" ); strcat ( outfl, membr ); if ( strcmp ( cycle, def ) != 0 ) { strcat ( outfl, "|" ); strcat ( outfl, cycle ); } return; }