void set_maxtop(char *maxtop) { int iret; char *cpos,outstr[80]; cpos = cst_split(maxtop, ';', 79, outstr, &iret); if ( iret == 0 ) cst_numb( outstr, &maxtop_col, &iret); if ( cpos != NULL ) in_filt( cpos, &maxtop_filter, &iret, strlen(cpos)); }
void shn_dfhr ( int *idst, float *rlat, float *rlon, int *idiff, int *iret ) /************************************************************************ * shn_dfhr * * * * Given a location defined by a latitude/longitude pair, this function * * determines the offset (in hours) between GMT and the local time at * * that location. * * * * shn_dfhr ( *idst, *rlat, *rlon, *idiff, *iret ) * * * * Input parameters: * * *idst int Flag denoting whether the * * current report date-time occurs * * during Daylight Savings Time: * * 0 = No * * 1 = Yes * * *rlat float Latitude of location * * *rlon float Longitude of location * * * * Output parameters: * * *idiff int Difference (in hours) determined* * by subtracting GMT from the * * local time at the given location* * *iret int Return code: * * 0 = normal return * * -1 = a problem occurred * ** * * Log: * * J. Ator/NCEP 04/05 * ***********************************************************************/ { char cbndtp[8] = "TZ_BNDS"; char cwrkst[80]; char info[128]; int ier; *iret = -1; clo_tqbnd ( cbndtp, *rlat, *rlon, cwrkst, &ier ); if ( ier != 0 ) { LOG_ERROR(clo_tqbnd); return; } clo_bginfo ( cbndtp, 0, info, &ier ); if ( ier != 0 ) { LOG_ERROR(clo_bginfo); return; } if ( *idst ) { cst_gtag ( "GMT_DST_OFFSET", (const char *) info, " ", cwrkst, &ier ); } else { cst_gtag ( "GMT_OFFSET" , (const char *) info, " ", cwrkst, &ier ); } if ( ier != 0 ) { LOG_ERROR(cst_gtag); return; } cst_numb ( cwrkst, idiff, &ier ); if ( ier != 0 ) { LOG_ERROR(cst_numb); return; } *iret = 0; return; }
void wbc_dcty ( char **ugc_arr, char **cnam_arr, char **st_arr, int *ncnty, char *eday, char *ehour, int *len1, int *ugcln, int *vtecln, char *prdcod, char *actn, char *offid, char *phen, char *sigcd, char *etn, int vtime[], int etime[], char **ind_arr, char *cntystr, int *iret ) /************************************************************************ * wbc_dcty * * * * This program formats the UGC line for each state and the list of * * county names and independent city names. * * * * wbc_dcty ( ugc_arr, cnam_arr, st_arr, ncnty, eday, ehour, len1, * * ugcln, vtecln, prdcod, actn, offid, phen sigcd, etn, * * vtime, etime, ind_arr, cntystr, iret ) * * * * Input parameters: * * **ugc_arr char UG codes array * * **cnam_arr char County names array * * **st_arr char County states array * * ncnty int Number of counties in the arrays* * *eday int Date (DD) * * *ehour char Hour (HH) * * len1 int Max length of 'cntystr' * * *ugcln int Flag for printing UG codes * * 0 - Only county names * * 1 - UG codes and counties * * *vtecln int Flag for writing VTEC line * * 0 - No VTEC line in product * * 1 - Use VTEC; No prod code * * 2 - Use VTEC; Use prod code * * *prdcod char VTEC product type code * * *actn char VTEC action code * * *offid char VTEC issuing office id * * *phen char VTEC phenonmena code * * *sigcd char VTEC significant action code * * *etn char VTEC event tracking number * * vtime[] int VTEC start time * * etime[] int VTEC ending time * * * * Output parameters: * * **ind_arr char Independent cities array * * *cntystr char County/independent cities string* * *iret int Return Code * * 0 = normal return * * -1 = max size of cntystr reached * * ** * * Log: * * A. Hardy/NCEP 5/03 * * A. Hardy/NCEP 11/03 Fixed memory deallocation * * A. Hardy/NCEP 1/04 Added VTEC parameters to call * * T. Piper/SAIC 02/04 Removed unused variables lenug, itype, * * iugcnt, and oneln * * A. Hardy/NCEP 2/04 Removed printf statement * * A. Hardy/NCEP 4/04 Add 'NEW' vs. 'CON'/'CAN' start time * * A. Hardy/NCEP 4/04 Added marine zone logic and formatting * * A. Hardy/NCEP 7/04 Inc. arrays cntyname,cname,holdw,ugcstr * * T. Piper/SAIC 12/05 Updated cst_wrap for CSC * * F. J. Yen/NCEP 2/06 Use len1 to check for mem leaks;set iret* * J. Wu/SAIC 04/06 Added parameter in cst_wrap * ***********************************************************************/ { int ii, jj, ik, im, ier, len, six, srch; int lenc; int ier1; int inumb, iugc, indy, icnt, iind, numcnty, ietn; char stid[3], name[22], county[9], cname[33], ctyind[19]; char tmpw[5000], holdw[5000], parish[9], rmname[9], cntyname[33]; char blank[2]={' '}, ugcstr[1500], **cty_arr, vtec[49], zname[256]; /*-------------------------------------------------------------------*/ *iret = 0; ier = 0; ier1 = 0; ii = 0; jj = 0; six = 6; srch = 2; cntystr[0] = '\0'; strcpy( county, "COUNTIES"); strcpy( parish, "PARISHES"); strcpy( ctyind, "INDEPENDENT CITIES"); strcpy( rmname, "CITY OF "); cty_arr = (char **)malloc(*ncnty * sizeof(char *)); /* * Set up county watch section. */ iugc = 0; while ( ii < *ncnty ) { strcpy(stid, st_arr[ii]); tb_idst ( stid, name, &ier1, strlen(stid), sizeof(name) ); /* * Setting up the zone county string. */ if ( *ugcln == 1 ) { holdw[0] = '\0'; tmpw[0] = '\0'; cst_numb (ugc_arr[iugc]+3, &numcnty, &ier); ik = 0; while ( (iugc < *ncnty) && ( (strcmp(st_arr[iugc], stid) == 0 ) ) ){ if ( iugc < *ncnty ) { cty_arr[ik] = (char *)malloc((six+1) * sizeof(char)); strcpy ( cty_arr[ik], ugc_arr[iugc] ); iugc++; ik++; } } /* * Check if a Great Lake or Lake St. Clair is the name. * Reset error code if it is to group all lake UG codes * together. */ if ( ( strcmp(name,"LAKE HURON") == 0 ) || ( strcmp(name,"LAKE ONTARIO") == 0 ) || ( strcmp(name,"LAKE MICHIGAN") == 0 ) || ( strcmp(name,"LAKE ST. CLAIR") == 0 ) || ( strcmp(name,"LAKE ERIE") == 0 ) || ( strcmp(name,"LAKE SUPERIOR") == 0 ) ) ier1 = -15; /* * Check if another marine zone region follows. If so, append it to * the current marine zones in the UGC array. */ if ( (ier1 < 0 ) && ( (iugc < *ncnty) && (ugc_arr[iugc][2] == 'Z' ) ) ) { while ( (iugc < *ncnty) && (ugc_arr[iugc][2] == 'Z') ) { if ( iugc < *ncnty ) { cty_arr[ik] = (char *)malloc((six+1) * sizeof(char)); strcpy ( cty_arr[ik], ugc_arr[iugc] ); iugc++; ik++; } } } utl_ugcp ( cty_arr, &ik, eday, ehour, &len, ugcstr, &ier); if ( ik > 1 ) { for( im = 0; im < ik-1; im++ ) { free( cty_arr[im] ); } } else { free( cty_arr[0] ); } strcat (tmpw, ugcstr ); strcat (tmpw, EOL ); /* * Setting up the VTEC string. */ if ( *vtecln == 1 ) { cst_numb ( etn, &ietn, &ier); if ( strcmp ( actn, "NEW") == 0 ) { sprintf( vtec, "/%s.%s.%s.%s.%04d.%02d%02d%02dT%02d%02dZ-%02d%02d%02dT%02d%02dZ/", actn, offid, phen, sigcd, ietn, vtime[0]%100, vtime[1], vtime[2], vtime[3], vtime[4], etime[0]%100, etime[1], etime[2], etime[3], etime[4]); } else { sprintf( vtec, "/%s.%s.%s.%s.%04d.000000T0000Z-%02d%02d%02dT%02d%02dZ/", actn, offid, phen, sigcd, ietn, etime[0]%100, etime[1], etime[2], etime[3], etime[4]); } strcat (tmpw, vtec ); strcat (tmpw, EOL ); } else if ( *vtecln == 2 ) { cst_numb ( etn, &ietn, &ier); if ( strcmp ( actn, "NEW") == 0 ) { sprintf( vtec, "/%s.%s.%s.%s.%s.%04d.%02d%02d%02dT%02d%02dZ-%02d%02d%02dT%02d%02dZ/", prdcod, actn, offid, phen, sigcd, ietn, vtime[0]%100, vtime[1], vtime[2], vtime[3], vtime[4], etime[0]%100, etime[1], etime[2], etime[3], etime[4]); } else { sprintf( vtec, "/%s.%s.%s.%s.%s.%04d.000000T0000Z-%02d%02d%02dT%02d%02dZ/", prdcod, actn, offid, phen, sigcd, ietn, etime[0]%100, etime[1], etime[2], etime[3], etime[4]); } strcat (tmpw, vtec ); strcat (tmpw, EOL ); } strcat (tmpw, EOL ); strcat( cntystr, tmpw); } /* * Setting up the states included string. */ tmpw[0] = '\0'; if ( ugc_arr[ii][2] != 'Z' ) { sprintf ( tmpw, "%s \n", stid); strcat( cntystr, tmpw); if ( strcmp ( stid,"LA") != 0 ) { sprintf ( tmpw, ". %s %s INCLUDED ARE\n\n", name, county); } else { sprintf ( tmpw, ". %s %s INCLUDED ARE\n\n", name, parish); } strcat( cntystr, tmpw); jj = 0; iind = 0; indy = 0; holdw[0] = '\0'; while ( ( ii < *ncnty ) && ( strcmp(st_arr[ii], stid) == 0 ) ) { if ( jj == 3 ) { strcat(holdw, "\n"); strcat( cntystr, holdw); jj = 0; } cst_rnan ( cnam_arr[ii], cname, &ier ); cst_lcuc ( cname, cname, &ier ); /* * Check for independent cities. */ cst_rmst (cname, rmname, &inumb, cntyname, &ier); if ( inumb == 0 ) { strcpy ( cname, cntyname ); } cst_numb (ugc_arr[ii]+3, &numcnty, &ier); if ( numcnty > 509 ) { strcpy ( ind_arr[iind], cname ); iind++; indy = 1; } else { /* * Print out names of counties. Set spacing for columns * 2 and 3. */ if ( jj < 1 ) { sprintf ( holdw, "%-21s", cname); } else { sprintf ( holdw, "%-20s", cname); } strcat( cntystr, holdw); holdw[0] = '\0'; jj++; } ii++; } strcat( cntystr, holdw); tmpw[0] = '\0'; if ( indy == 0 ) { if ( ii >= *ncnty ) { strcat ( tmpw, "\n$$\n\n"); if ( *ugcln ) { strcat ( tmpw, "\n"); } strcat( cntystr, tmpw); } else { if ( (ii == ( *ncnty - 1) ) || ( strcmp(st_arr[ii+1], stid) != 0 ) ) { strcat ( tmpw, "\n$$\n\n"); if ( *ugcln ) { strcat ( tmpw, "\n"); } strcat( cntystr, tmpw); } } } /* * Print out independent cities list. */ tmpw[0] = '\0'; holdw[0] = '\0'; lenc = strlen (cntystr); /* Subtract 500 characters (for constant/known text throughout) */ lenc = lenc - 500; if ( indy != 0 ) { cst_sort( srch, &iind, ind_arr, &iind, ind_arr, &ier ); if ( ii == 0 ) { strcat(tmpw, "\n\n"); } else { strcat(tmpw, "\n\n\n"); } if ( *ugcln ) { sprintf ( holdw, "%s %s INCLUDED ARE\n\n", name, ctyind); } else { sprintf ( holdw, "%s %s INCLUDED \n\n", name, ctyind); } strcat( tmpw, holdw); lenc = lenc + strlen (tmpw); if ( lenc >= *len1 ) { *iret = -1; return; } strcat( cntystr, tmpw); tmpw[0] = '\0'; holdw[0] = '\0'; /* * Set spacing for columns 2 and 3. */ jj = 0; for ( icnt = 0; icnt < iind; icnt++ ){ if ( jj < 1 ) { sprintf ( holdw, "%-21s", ind_arr[icnt]); } else { sprintf ( holdw, "%-20s", ind_arr[icnt]); } strcat( cntystr, holdw); lenc = lenc + strlen (holdw); if ( lenc >= *len1 ) { *iret = -1; return; } /* * Only add new line if the column lengths aren't * even. */ jj++; if ( ( jj == 3 ) && ( icnt != iind-1 ) ){ strcat(cntystr, "\n"); jj = 0; } } strcat ( cntystr, "\n$$\n\n"); if ( *ugcln ) strcat ( cntystr, "\n"); } } else { /* * Write out all of the marine zone names under one heading. */ len = LINE_LEN; sprintf ( tmpw, "CW \n\n"); strcat ( cntystr, tmpw); sprintf ( tmpw, ". ADJACENT COASTAL WATERS INCLUDED ARE\n\n" ); strcat( cntystr, tmpw); holdw[0] = '\0'; tmpw[0] = '\0'; while ( (ii < *ncnty) && (ugc_arr[ii][2] == 'Z') ) { cst_rnan ( cnam_arr[ii], zname, &ier ); cst_rpst ( zname, ",", "", zname, &ier ); cst_rpst ( zname, ",", "", zname, &ier ); cst_lcuc ( zname, zname, &ier ); sprintf(holdw,"%s \n\n", zname); cst_wrap ( holdw, blank, &len, EOL, (char *)NULL, tmpw, &ier ); lenc = lenc + strlen (tmpw); if ( lenc >= *len1 ) { *iret = -1; return; } strcat(cntystr, tmpw); holdw[0] = '\0'; tmpw[0] = '\0'; ii++; } strcat ( cntystr, "$$\n"); } } if (cty_arr) { free( (char **) cty_arr); } }
void dc_init ( char *prgnam, int argc, char **argv, int numexp, char parms[][DCMXLN], int *num, int *iret ) /************************************************************************ * dc_init * * * * This routine initializes the bridge and decoder parameters and * * processes the command line options. * * * * dc_init ( prgnam, argc, argv, numexp, parms, num, iret ) * * * * Input parameters: * * *prgnam char Program name * * argc int Number of command line args * * **argv char Command line arguments * * numexp int Number of expected parameters * * * * Output parameters: * * parms[][DCMXLN] char Parameters found on command line* * *num int Number of parameters found * * *iret int Return code * * 0 = normal return * * -11 = no command line args * * * ** * * Log: * * A. Chang/EAi 5/95 * * S. Jacobs/NMC 7/95 Update and clean up * * S. Jacobs/NCEP 6/96 Updated documentation; Changed atoi to * * cst_numb; Removed the +3 return code; * * Changed ldfd to a FILE stream - fplog * * S. Jacobs/NCEP 7/96 Reorganized the source code * * K. Tyle/GSC 7/96 NT_HELP --> IP_HELP * * S. Jacobs/NCEP 7/96 Removed log file open * * K. Tyle/GSC 1/97 Added calls to IN_BDTA and ER_STAT; * * changed numerr in startup dc_wclg call * * K. Tyle/GSC 1/97 Use iflg in call to ER_STAT * * D. Kidwell/NCEP 9/97 Added version number to help option * * I. Durham/GSC 5/98 Changed underscore decl. to an include * * S. Jacobs/NCEP 1/00 Added command line input of env vars * * S. Jacobs/NCEP 2/01 Removed all references to ulog * * R. Tian/SAIC 8/02 Added version to log file * * m.gamazaychikov/SAIC 07/05 Added -w input parameter * * H. Zeng/SAIC 08/05 Added second station table * * L. Hinson/AWC 06/08 Add -r circular flag switch * * S. Jacobs/NCEP 3/12 Add $HOME to the logs directory * * S. Jacobs/NCEP 12/13 Added more options for log location * ***********************************************************************/ { int ch, i, errflg, ier; int pagflg = G_FALSE; int iflg = G_TRUE; /* ** These variables are used for logging errors and notices. */ char tdclog[DCMXLN]; int logflg, ibuf; char errstr[DCMXLN]; char version[128]; /* ** These variables are used by getopt. Unset the error reporting. */ char optver[20]; /*---------------------------------------------------------------------*/ *iret = 0; /* ** Set the process ID for log messages. */ ipid = (int) getpid (); /* ** Initialize the bulletin counter. */ nbull = 0; /* ** Save the program name as a global variable. */ strcpy ( cprgnm, prgnam ); /* ** Set up the signal handlers. */ dc_sgnl ( ); /* ** Get and process the command line options. ** ** Set the default values for parsing the command line. */ strcpy ( curtim, "SYSTEM" ); cst_uclc ( cprgnm, tdclog, &ier ); strcat ( tdclog, ".log" ); logflg = G_FALSE; itmout = DCDFTM; irltim = G_TRUE; txtflg = G_TRUE; circflg = G_FALSE; ivrblv = 0; prmfil[0] = CHNULL; stntbl[0] = CHNULL; iadstn = IMISSD; maxtim = IMISSD; nhours = IMISSD; iwndht = IMISSD; /* ** Get the valid options from the command line. ** The valid options are: ** -v Set the level of verbosity for the logs ** -c Set the "current" time ** -b Number of hours to decode prior to "current" time ** -d Set the decoder log file name ** -t Set the interval for the time out ** -p Set the parameter packing table ** -s Set the station table ** -S Set the second station table ** -a Set the number of additional stations ** -m Set the max number of times ** -e Set an environment variable=value ** -n Set a flag to NOT save the text data ** -r Set a flag to force circular files ** -w Set the cutoff "close-to-the-surface" height ** -h Print the help file, then exit the program */ opterr = 1; errflg = 0; while ( ( ch = getopt ( argc, argv, "v:c:b:d:t:p:s:S:a:m:e:w:nhr" ) ) != EOF ) { switch ( ch ) { case 'v': cst_numb ( optarg, &ivrblv, &ier ); if ( ivrblv < 0 ) ivrblv = 0; break; case 'c': strcpy ( curtim, optarg ); irltim = G_FALSE; break; case 'b': cst_numb ( optarg, &nhours, &ier ); break; case 'd': strcpy ( tdclog, optarg ); logflg = G_TRUE; break; case 't': cst_numb ( optarg, &itmout, &ier ); if ( itmout < 1 ) itmout = DCDFTM; break; case 'p': strcpy ( prmfil, optarg ); break; case 's': strcpy ( stntbl, optarg ); break; case 'S': strcpy ( stntb2, optarg ); break; case 'a': cst_numb ( optarg, &iadstn, &ier ); break; case 'm': cst_numb ( optarg, &maxtim, &ier ); break; case 'e': envobj = (envlist *) malloc ( sizeof(envlist) ); envobj->env = malloc ( strlen(optarg)+1 ); strcpy ( envobj->env, optarg ); envobj->env[strlen(optarg)] = '\0'; envobj->next = envhead; envhead = envobj; break; case 'n': txtflg = G_FALSE; break; case 'w': cst_numb ( optarg, &iwndht, &ier ); break; case 'r': circflg = G_TRUE; break; case 'h': ip_help ( cprgnm, &pagflg, &ier, strlen(cprgnm) ); strcpy ( cprgnm, "DECODE" ); ip_help ( cprgnm, &pagflg, &ier, strlen(cprgnm) ); ss_vers ( optver, &ier, sizeof (optver) ); printf ( ">%s<\n", optver ); exit ( 0 ); break; case '?': errflg++; break; } } /* ** Initialize GEMPAK and set error reporting parameters. */ in_bdta ( &ier ); ibuf = 1; er_stat ( &ivrblv, &ibuf, &iflg, &ier ); /* ** Open the decoder log. ** ** If the processing is in real-time add the directory to the ** file name. */ if ( !logflg && irltim ) { if ( tdclog[0] == '/' ) { strcpy ( dcdlog, tdclog ); } else if ( getenv("GEMPAK_DECODER_LOGS") ) { strcpy ( dcdlog, "$GEMPAK_DECODER_LOGS/" ); strcat ( dcdlog, tdclog ); } else { strcpy ( dcdlog, "$HOME/" ); strcat ( dcdlog, tdclog ); } } else { strcpy ( dcdlog, tdclog ); } /* ** Send a start up message to the decoder log. */ ss_vers ( version, &ier, sizeof(version) ); dc_wclg ( 0, "DCINIT", 3, version, &ier ); /* ** Set all of the environment variables. */ envobj = envhead; while ( envobj != NULL ) { if ( putenv ( envobj->env ) != 0 ) { strcpy ( errstr, envobj->env ); dc_wclg ( 0, "DCINIT", -17, errstr, &ier ); } envobj = envobj->next; } /* ** Adjust argc and argv by the option index. */ argc -= optind; argv += optind; /* ** Initialize the output string array. */ for ( i = 0; i < numexp; i++ ) strcpy ( parms[i], " " ); /* ** Get the decoder specific parameters. */ *num = argc; if ( *num == 0 ) { /* ** If there are no parameters write a message and return ** with an error. */ *iret = -11; dc_wclg ( 0, "DCINIT", *iret, " ", &ier ); } else { /* ** Otherwise, set the parameters to be returned. */ for ( i = 0; i < *num; i++ ) if ( i < numexp ) strcpy ( parms[i], argv[i] ); } }
void na_gtbl ( const char *cpyfil, char *name, char *proj, int *nxgd, int *nygd, float *garea, float *rnvblk, float *anlblk, int *iret ) /************************************************************************ * na_gtbl * * * * This subroutine finds grid INNAME (a numerical or character * * identifier prefaced by '#') in a grid navigation table, then makes * * the navigation and analysis blocks. The grid navigation is set up * * in GEMPLT in order to check its validity. * * * * na_gtbl ( cpyfil, name, proj, nxgd, nygd, garea, rnvblk, anlblk, * * iret ) * * * * Input parameters: * * *cpyfil const char Input for CPYFIL * * * * Output parameters: * * *name char Name of selected grid * * *proj char Grid projection * * *nxgd int Number of points in x dir * * *nygd int Number of points in y dir * * *garea float Grid corners * * *rnvblk float Grid navigation block * * *anlblk float Grid analysis block * * *iret int Return code * * +1 = EXIT entered * * 0 = normal return * * -4 = invalid navigation * * -9 = grid not found in table * ** * * Log: * * S. Jacobs/EAI 7/93 Copied from GDCTBL * * D. Keiser/GSC 12/95 Changed FL_TOPN to FL_TBOP * * R. Tian/SAIC 7/06 Recoded from Fortran * * S. Gilbert/NCEP 10/06 Added call to GR_VNAV * ************************************************************************/ { char gntrec[81], namgd[5], c2name[9], buffer[LLMXLN]; float angl1, angl2, angl3, dbnds[4], deln; int angflg, found, valid; int iebnds[4], ingrdn, numgd, extnd, ier, ier1, iernum, navsz, i; FILE *lungrd; /*----------------------------------------------------------------------*/ *iret = 0; name[0] = '\0'; /* * Get the grid number (INGRDN) out of NAME; a conversion error * sets IERNUM .ne. 0 and it is assumed that NAME is a type. */ cst_lcuc ( (char *)cpyfil, c2name, &ier ); strcpy ( name, &c2name[1] ); cst_numb ( name, &ingrdn, &iernum ); /* * Open the table of valid grid types. */ lungrd = cfl_tbop ( "grdnav.tbl", "grid", &ier ); if ( ier != 0 ) { er_wmsg ( "CFL", &ier, "grdnav.tbl", &ier1, strlen("CFL"), strlen("grdnav.tbl") ); *iret = -9; return; } /* * List the table contents for the user, if requested. */ if ( strcmp ( name, "LIST" ) == 0 ) { while ( ! feof ( lungrd) ) { cfl_trln ( lungrd, sizeof(gntrec), gntrec, &ier ); if ( ier != 0 ) break; printf ( "%-79.79s\n", gntrec ); } /* * Rewind the table file. */ cfl_seek ( lungrd, 0, SEEK_SET, &ier ); /* * Prompt user for grid choice. */ printf ( "Enter grid id or number or type EXIT: " ); scanf ( " %s", name ); if ( name[0] == 'e' || name[0] == 'E' ) { *iret = +1; return; } cst_lcuc ( name, name, &ier ); cst_numb ( name, &ingrdn, &iernum ); } /* * Read through the list of valid grid types/numbers to get * navigation/analysis information. */ found = G_FALSE; while ( ! feof ( lungrd ) ) { cfl_trln ( lungrd, sizeof(buffer), buffer, &ier ); if ( ier != 0 ) break; sscanf ( buffer, "%s %d %s %f %f %f %f %f %f %f %d %d %f %d", namgd, &numgd, proj, &angl1, &angl2, &angl3, &garea[0], &garea[1], &garea[2], &garea[3], nxgd, nygd, &deln, &extnd ); if ( strcmp ( name, namgd ) == 0 || ingrdn == numgd ) { found = G_TRUE; break; } } cfl_clos ( lungrd, &ier ); /* * Bail out if NAME wasn't found in the table. */ if ( found == G_FALSE ) { *iret = -9; return; } /* * Fill navigation block. */ angflg = G_TRUE; gr_vnav ( proj, nxgd, nygd, &garea[0], &garea[1], &garea[2], &garea[3], &angl1, &angl2, &angl3, &angflg, &valid, &ier, strlen(proj) ); if ( ier == 0 ) grc_mnav ( proj, nxgd, nygd, &garea[0], &garea[1], &garea[2], &garea[3], &angl1, &angl2, &angl3, &angflg, rnvblk, &ier ); else { *iret = -2; return; } /* * Set up navigation in GEMPLT to check validity. */ navsz = 13; grc_snav ( &navsz, rnvblk, &ier ); if ( ier != 0 ) { *iret = -4; return; } /* * Make an analysis block. */ for ( i = 0; i < 4; i++ ) { iebnds[i] = extnd; dbnds [i] = RMISSD; } grc_mbn2 ( &deln, iebnds, dbnds, rnvblk, anlblk, &ier ); return; }
void gdgwrt ( const float *grid, const char *time1, const char *time2, const int *level1, const int *level2, const int *ivcord, const char *parm, const char *grdnam, const char *gpack, const int *ihzrmp, const int *idrct, int *iret ) /************************************************************************ * gdgwrt * * * * This subrutine writes a warning message if a grid is already in * * the file. The grid identifier is written and the user is prompted * * to accept the grid, change the parameter name or exit. * * * * gdgwrt ( grid, time1, time2, level1, level2, ivcord, parm, grdnam, * * gpack, ihzrmp, idrct, iret ) * * * * Input parameters: * * *grid const float Grid of data * * *time1 const char Grid date/time * * *time2 const char Grid date/time * * *level1 const int Grid levels * * *level2 const int Grid levels * * *ivcord const int Grid vertical coordinate * * *parm const char Grid parameter name * * *grdnam const char User specified grid name * * *gpack const char Grid packing information * * *ihzrmp const int Horizontal remapping * * *idrct const int Directional flag * * * * Output parameters: * * *iret int Return code * * 2 = user entered EXIT * * 0 = normal return * * -7 = error writing grid * ** * * Log: * * M. Goodman/RDS 10/85 * * M. desJardins/GSFC 7/87 Rewritten * * M. desJardins/GSFC 8/88 GEMPAK 4 * * S. Schotz/GSC 6/90 Get respnd locally from IP_RESP * * K. Brill/NMC 02/91 Added in-line parameters * * K. Brill/NMC 07/92 Change gname to upper case (J. Whistler)* * K. Brill/NMC 07/92 Added % in-line parameter * * K. Brill/EMC 11/97 Fixed in-line parm: i->ii in DO ii loop * * M. Li/SAIC 04/04 Added ihzrmp, and idrct * * R. Tian/SAIC 1/05 Modified for time/file management * * T. Lee/SAIC 12/05 Initialized ighdr * * R. Tian/SAIC 9/06 Recoded from Fortran * ************************************************************************/ { char gname[13], gtime[21], glevl[13], gcord[13], answer[13], vparm[13], timout1[21], timout2[21], gdnbuf[LLMXLN+1], *pchr; int respnd, exist, tltflg, pagflg, newln, rplc; int ighdr[LLGDHD], levout1, levout2, ivcout; int dowhat, inam, ihat, iaat, ipct, len, zero, ii, ier; /*----------------------------------------------------------------------*/ *iret = 0; tltflg = G_TRUE; pagflg = G_FALSE; newln = G_FALSE; rplc = G_TRUE; zero = 0; inam = 0; ihat = 0; iaat = 0; ipct = 0; /* * Get name of grid to use along with in-line parameters. */ if ( strlen(grdnam) > 0 ) { dowhat = DONAM; cst_lcuc ( (char *)grdnam, gdnbuf, &ier ); for ( pchr = gdnbuf; *pchr != '\0'; pchr++ ) { if ( *pchr == '^' ) dowhat = DOHAT; if ( *pchr == '@' ) dowhat = DOAAT; if ( *pchr == '%' ) dowhat = DOPCT; switch ( dowhat ) { /* * Retrieve grid name. */ case DONAM: gname[inam++] = *pchr; break; /* * Retrieve in-line time. */ case DOHAT: if ( *pchr == '^' ) continue; gtime[ihat++] = *pchr; break; /* * Retrieve in-line level. */ case DOAAT: if ( *pchr == '@' ) continue; glevl[iaat++] = *pchr; break; /* * Retrieve in-line vertical coordinate. */ case DOPCT: if ( *pchr == '%' ) continue; gcord[ipct++] = *pchr; break; } } gname[inam] = '\0'; gtime[ihat] = '\0'; glevl[iaat] = '\0'; gcord[ipct] = '\0'; } if ( inam == 0 ) strcpy ( gname, parm ); if ( ihat > 0 ) { strcpy ( timout1, gtime ); timout2[0] = '\0'; } else { strcpy ( timout1, time1 ); strcpy ( timout2, time2 ); } if ( iaat > 0 ) { cst_numb ( glevl, &levout1, &ier ); levout2 = -1; } else { levout1 = *level1; levout2 = *level2; } if ( ipct > 0 ) { clv_cord ( gcord, vparm, &ivcout, &ier ); } else { ivcout = *ivcord; } /* * Check if the grid already exists in the grid file. * Write message that grid will be replaced. */ cst_lcuc ( gname, gname, &ier ); dgc_qgrd ( timout1, timout2, &levout1, &levout2, &ivcout, gname, &exist, &ier ); if ( ier == 0 && exist == G_TRUE ) { printf ( " This grid is already in file. It will be replaced.\n" ); } /* * Write the grid identifiers. */ printf ( "\n" ); grc_wtrm ( stdout, &tltflg, &zero, timout1, timout2, &levout1, &levout2, &ivcout, gname, &ier ); /* * Allow user to enter a new parameter name. */ ip_resp ( &respnd, &ier ); if ( respnd == G_TRUE ) { tm_str ( "Enter a new grid parameter name, <cr> to accept", &pagflg, &newln, answer, iret, strlen("Enter a new grid parameter name, <cr> to accept"), 13 ); st_null ( answer, answer, &len, &ier, 13, 13 ); /* * Return if the user typed EXIT. */ if ( *iret == 2 ) return; /* * Check if user entered new name. */ if ( *iret == 0 ) strcpy ( gname, answer ); } /* * Write out the grid and check for errors. */ for ( ii = 0; ii < LLGDHD; ii++ ) ighdr[ii] = 0; if ( *ihzrmp != IMISSD ) ighdr[0] = *ihzrmp; if ( *idrct != IMISSD ) ighdr[1] = *idrct; dgc_nwdt ( grid, timout1, timout2, &levout1, &levout2, &ivcout, gname, ighdr, gpack, &rplc, iret ); if ( *iret != 0 ) { er_wmsg ( "DG", iret, " ", &ier, strlen("DG"), strlen(" ") ); *iret = -7; } return; }
void cst_ilst ( char *str, char sep, int def, int nexp, int *intptr, int *num, int *iret ) /************************************************************************ * cst_ilst * * * * This subroutine breaks a string containing a list of integers into * * an array of integers. The separator for the integers is input as * * SEP. If the seperator is a blank, multiple blanks will be treated * * as one. If null strings are encounteded or fewer than NEXP strings * * are found in the string, the appropriate intptr locations are set to * * DEF. * * * * Range strings (with optional increments) are indicated with a hyphen * * (i.e., 3-9 or 3-12-3) and are processed into the INTPTR array. * * * * cst_ilst ( str, sep, def, nexp, intptr, num, iret ) * * * * Input parameters: * * *str char Input string * * sep char Separator * * def int Default value * * nexp int Number of expected values * * * * Output parameters: * * *intptr int Pointer to integer values * * *num int Number of integers returned * * *iret int Return code * * 1 = more than nexp values * * 0 = normal * * -1 = invalid nexp * * -3 = invalid substring * ** * * Log: * * L. Williams/EAI 4/96 * * L. Williams/EAI 6/96 check for missing data * * S. Jacobs/NCEP 8/96 Updated header format * * G. Krueger/EAI 10/97 Removed MALLOC, RSPTB * ***********************************************************************/ { char strbuf[160], alpha[10], omega[10], rinc[10]; int ielt, ichar, jchar, len, lenss; int begin, end, inc, tp, ival, intgr, ier, err; /*---------------------------------------------------------------------*/ *iret = 0; *num = 0; /* * check the number of expected values */ if( nexp <= 0 ) { intptr = 0; *iret = -1; return; } /* * initialize output array to default value */ for( ielt=0; ielt < nexp; ielt++ ) intptr[ielt] = def; /* * process the input string into an array of integer numbers */ jchar = 0; ielt = 0; *strbuf = '\0'; len = strlen (str); for ( ichar = 0; ichar < len; ichar++ ) { if (str[ichar] == '\t' || str[ichar] == ' ') { if (sep != ' ') { continue; } else if ( (sep == ' ') && (str[ichar+1] == '\t' && str[ichar+1] == ' ') ) { continue; } } if ( str[ichar] == sep ) { /* * character is a separator, finish the current array * element */ strbuf[jchar] = '\0'; cst_lstr( strbuf, &lenss, &ier ); if ( lenss != 0 ) { cst_rang( strbuf, alpha, omega, rinc, &tp, &ier ); if ( tp ) { /* * this is a range */ cst_numb( alpha, &begin, &ier ); cst_numb( omega, &end, &err ); if ( ( ier == -2 ) || ( err == -2 ) ) { *iret = -3; } else { inc = 1; if ( tp != 1 ) inc = atoi( rinc ); for ( ival=begin; ival <= end; ival += inc ) if ( ielt < nexp ) { intptr[ielt] = ival; ielt++; } ielt--; } } else { /* * this is a simple integer */ cst_numb( strbuf, &intgr, &ier ); if ( ier == -2 ) { *iret = -3; } else { intptr[ielt] = intgr; } } } ielt++; /* * work on the next array element */ jchar = 0; *strbuf = '\0'; if ( ielt >= nexp ) { *iret = 1; break; } } else { /* * otherwise, append the character to the buffer */ strbuf[jchar] = str[ichar]; jchar++; } } /* * finish the last array element */ strbuf[jchar] = '\0'; cst_lstr( strbuf, &lenss, &ier ); if ( lenss != 0 ) { cst_rang( strbuf, alpha, omega, rinc, &tp, &ier ); if ( tp ) { /* * this is a range */ cst_numb( alpha, &begin, &ier ); cst_numb( omega, &end, &err ); if ( ( ier == -2 ) || ( err == -2 ) ) { *iret = -3; } else { inc = 1; if ( tp != 1 ) inc = atoi( rinc ); for ( ival=begin; ival <= end; ival += inc ) if ( ielt < nexp ) { intptr[ielt] = ival; ielt++; } ielt--; } } else { /* * this is a simple integer */ cst_numb( strbuf, &intgr, &ier ); if ( ier == -2 ) { *iret = -3; } else { intptr[ielt] = intgr; } } } ielt++; *num = ielt; if ( *num > nexp ) *num = nexp; }
void dg_prft ( const char *time1, const char *time2, const int *level1, const int *level2, const int *ivcord, const char *parm, int *num, int *iret ) /************************************************************************ * dg_prft * * * * This subroutine accumulates precipitation over a given time period. * * The time period is hh hours given in the parameter name which has * * the form PhhM or PhhI. Conversions to inches or millimeters will * * be automatic. * * * * The following assumptions are made: * * * * 1. The precipitation totals exist at forecast times * * at regular intervals in whole hours. * * * * 2. At regular intervals the precipitation is given for * * the entire interval. This is a major interval. * * * * 3. At regular subintervals within the major intervals, * * the precipitation is accumulated since the start of * * the major interval. * * * * dg_prft ( time1, time2, level1, level2, ivcord, parm, num, iret ) * * * * Input parameters: * * *time1 const char Date/time * * *time2 const char Date/time * * *level1 const int Level * * *level2 const int Level * * *ivcord const int Vertical coordinate * * *parm const char Parameter name * * * * Input and output parameters: * * *num int Location of grid * * * * Output parameters: * * *iret int Return code * * 0 = normal return * * -7 = grid cannot be found * ** * * Log: * * K. Brill/NMC 10/92 * * K. Brill/NMC 2/93 Use first character of parm * * M. desJardins/NMC 7/92 DG_UHDR --> DG_UPSG * * K. Brill/NMC 11/93 Take care of negative precip * * M. desJardins/NMC 3/94 Reorganize * * S. Jacobs/NMC 10/94 Check for parms w/ PR which aren't rates* * K. Brill/NMC 5/95 Add 3-h major interval * * T. Lee/GSC 4/96 Single dimension for dgg * * K. Brill/HPC 11/02 Eliminate use of the SUBA logical array * * K. Brill/HPC 2/03 Call DG_FRIG to free internal grids * * T. Lee/SAIC 10/03 Increased temporal resolution for hrly * * T. Lee/SAIC 1/04 Handled Canadian precip. grids * * R. Tian/SAIC 1/05 Fixed bug for GFS data * * S. Jacobs/NCEP 9/05 Fixed counter when in CANADIAN mode * * R. Tian/SAIC 2/06 Recoded from Fortran * * S. Jacobs/NCEP 8/09 Added 1hr to major interval list * ************************************************************************/ { /* * Set possible subinterval accumulation periods. */ char cdt[NDT][3] = { "03", "06", "09", "12", "01", "02", "04", "05", "07", "08", "10", "11", "24", "48" }; int idt[NDT] = { 3, 6, 9, 12, 1, 2, 4, 5, 7, 8, 10, 11, 24, 48 }; /* * Set possible major interval lengths (hours). */ char cdtm[NDTM][4] = { "01", "03", "06", "12", "24" }; int idtm[NDTM] = { 1, 3, 6, 12, 24 }; char thold[5], pnum[14], fstchr, lstchr, accum[73], ftype, ftime[4], time21[21], time22[21]; float rmult, signp; int intdtf[3], jvcord, iacc, lenstr, ihrs, ihhlst, iptime, lenst, numsub, nummaj, majts, iz, itet, i, ier, ierr; int done; /*----------------------------------------------------------------------*/ *iret = -7; /* * Set the vertical coordinate to missing since it can be ignored. */ jvcord = -1; /* * Check to see if precipitation rate is requested. If so, * check for the data immediately. */ if ( strncmp ( parm, "PR", 2 ) == 0 ) { strcpy ( accum, &parm[2] ); cst_numb ( accum, &iacc, &ierr ); if ( ierr == 0 ) { dg_grdr ( time1, time2, level1, level2, &jvcord, parm, num, iret ); } return; } /* * Check that precipitation in form P|S|C nnn I|M has been requested. */ cst_lstr ( (char *)parm, &lenstr, &ier ); if ( lenstr <= 2 ) return; fstchr = parm[0]; if ( ( fstchr != 'P' ) && ( fstchr != 'S' ) && ( fstchr != 'C' ) ) return; lstchr = parm[lenstr-1]; if ( ( lstchr != 'I' ) && ( lstchr != 'M' ) ) return; /* * Get number of hours for the precipitation accumulation. */ strncpy ( pnum, &parm[1], lenstr - 2 ); pnum[lenstr-2] = '\0'; cst_numb ( pnum, &ihrs, &ier ); if ( ier != 0 ) return; /* * Check to see if precipitation can be found as a rate or as a * combination of P, S, C precipitation values. */ dg_prcp ( time1, time2, level1, level2, &jvcord, parm, num, iret ); if ( *iret == 0 ) return; /* * Get the forecast time for this grid. */ tg_ctoi ( (char *)time1, intdtf, &ier, strlen(time1) ); if ( intdtf[2] == 0 ) return; /* * Read data based on forecast hours (for Canadian data) */ ctg_cftm ( intdtf[2], &ftype, ftime, &ier ); if ( ftime[0] == '0' ) { pnum[0] = fstchr; strcpy ( &pnum[1], &ftime[1] ); lenstr = strlen ( pnum ); pnum[lenstr] = lstchr; pnum[lenstr+1] = '\0'; } else { pnum[0] = fstchr; strcpy ( &pnum[1], ftime ); lenstr = strlen ( pnum ); pnum[lenstr] = lstchr; pnum[lenstr+1] = '\0'; } dg_prcp ( time1, time2, level1, level2, &jvcord, pnum, num, &ier ); /* * Get the accumulation at present time, over x hours, where * x is to be determined by looping over the possiblities. */ if ( ier != 0 ) { i = -1; while ( ( ier != 0 ) && ( i < NDT - 1 ) ) { i++; if ( idt[i] != ihrs ) { pnum[0] = fstchr; strcpy ( &pnum[1], cdt[i] ); lenstr = strlen ( pnum ); pnum[lenstr] = lstchr; pnum[lenstr+1] = '\0'; dg_prcp ( time1, time2, level1, level2, &jvcord, pnum, num, &ier ); } } /* * If some value for precipitation was found, check the number * of hours accumulated. */ if ( ier == 0 ) { ihhlst = idt[i]; } else { return; } } else { cst_numb ( ftime, &ihhlst, iret ); } strcpy ( time22, time2 ); if ( ihhlst > ihrs ) { /* * Go back IHRS hours, get the accumulation at that * forecast time and subtract. */ intdtf[2] = intdtf[2] - ihrs * 100; ctg_itoc ( intdtf, time21, &ier ); iptime = ihhlst - ihrs; cst_inch ( iptime, thold, &ier ); cst_lstr ( thold, &lenst, &ier ); if ( lenst == 1 ) { pnum[0] = fstchr; pnum[1] = '0'; pnum[2] = thold[0]; pnum[3] = lstchr; pnum[4] = '\0'; } else { pnum[0] = fstchr; strcpy ( &pnum[1], thold ); lenstr = strlen ( pnum ); pnum[lenstr] = lstchr; pnum[lenstr+1] = '\0'; } dg_nxts ( &numsub, &ier ); dg_prcp ( time21, time22, level1, level2, &jvcord, pnum, &numsub, iret ); if ( *iret == 0 ) { rmult = -1.; pd_prcp ( _dggrid.dgg[(*num)-1].grid, _dggrid.dgg[numsub-1].grid, &rmult, &_dgfile.kxyd, _dggrid.dgg[(*num)-1].grid, &ier ); } dg_frig ( &numsub, &ier ); } else { /* * Accumulate the precipitation. Total elapsed time is itet. */ itet = ihhlst; dg_nxts ( &nummaj, &ier ); done = G_FALSE; while ( done == G_FALSE ) { /* * Go back IHHLST hours, get accum. and sum it in. */ intdtf[2] = intdtf[2] - ihhlst * 100; ctg_itoc ( intdtf, time21, &ier ); /* * Determine the major time step. */ ier = 999; i = -1; while ( ( ier != 0 ) && ( i < NDTM - 1 ) ) { i++; pnum[0] = fstchr; strcpy ( &pnum[1], cdtm[i] ); lenstr = strlen ( pnum ); pnum[lenstr] = lstchr; pnum[lenstr+1] = '\0'; dg_prcp ( time21, time22, level1, level2, &jvcord, pnum, &nummaj, &ier ); } if ( ier != 0 ) { *iret = -7; dg_frig ( &nummaj, &ier ); return; } majts = idtm[i]; /* * Add in the accumulation. */ signp = 1.; pd_prcp ( _dggrid.dgg[(*num)-1].grid, _dggrid.dgg[nummaj-1].grid, &signp, &_dgfile.kxyd, _dggrid.dgg[(*num)-1].grid, &ier ); /* * Increment elapsed time. */ itet += majts; if ( itet == ihrs ) { done = G_TRUE; *iret = 0; } else if ( itet < ihrs ) { ihhlst = majts; } else { /* * Subtract out over accumulation. */ iz = ( ihrs - itet ) + majts; intdtf[2] = intdtf[2] - iz * 100; ctg_itoc ( intdtf, time21, &ier ); iptime = majts - iz; cst_inch ( iptime, thold, &ier ); cst_lstr ( thold, &lenst, &ier ); if ( lenst == 1 ) { pnum[0] = fstchr; pnum[1] = '0'; pnum[2] = thold[0]; pnum[3] = lstchr; pnum[4] = '\0'; } else { pnum[0] = fstchr; strcpy ( &pnum[1], thold ); lenstr = strlen ( pnum ); pnum[lenstr] = lstchr; pnum[lenstr+1] = '\0'; } dg_prcp ( time21, time22, level1, level2, &jvcord, pnum, &nummaj, &ier ); if ( ier == 0 ) { signp = -1.; pd_prcp ( _dggrid.dgg[(*num)-1].grid, _dggrid.dgg[nummaj-1].grid, &signp, &_dgfile.kxyd, _dggrid.dgg[(*num)-1].grid, &ier ); *iret = 0; } else { *iret = -7; dg_frig ( &nummaj, &ier ); return; } done = G_TRUE; } } dg_frig ( &nummaj, &ier ); } return; }
void gdgpds ( const char *pdsval, const char *vercen, const float *rnvblk, const char *gparm, const int *ivcord, const int *level1, const int *level2, const int *havbms, const int *ip10sc, const char *lasttm, const char *gdttm1, const char *gdttm2, const char *gbtbls, const int *igpds, int *nbpds, unsigned char *cpds, char *cdd, char *chhmm, int *iret ) /************************************************************************ * gdgpds * * * * This subroutine bridges the gap between the user input and PDS_MAKE. * * The PDS byte array is returned. * * * * gdgpds ( pdsval, vercen, rnvblk, gparm, ivcord, level1, level2, * * havbms, ip10sc, lasttm, gdttm1, gdttm2, gbtbls, igpds, * * nbpds, cpds, cdd, chhmm, iret ) * * * * Input parameters: * * *pdsval const char User input override PDS numbers * * *vercen const char User input for octets 4,5,6,26 * * *rnvblk const float Grid navigation block * * *gparm const char Grid parameter from DG_GRID * * *ivcord connst int Grid vert coord # from DG_GRID * * *level1 const int Grid level from DG_GRID * * *level2 const int Grid level from DG_GRID * * *havbms const int Flag for existence of BMS * * *ip10sc const int Power of 10 scale factor * * *lasttm const char Last grid time * * *gdttm1 const char Grid time from DG_GRID * * *gdttm2 const char Grid time from DG_GRID * * *gbtbls const char User input for GRIB tables * * *igpds const int Grid navigation # from CPYFIL * * * * Input and output parameter: * * *nbpds int Input: Max length for PDS * * Output: Actual length of PDS * * Output parameters: * * *cpds unsigned char PDS array * * *cdd char 2-digit day of month * * *chhmm char Hour minute of data * * *iret int Return code * * 0 = normal return * ** * * Log: * * K. Brill/HPC 08/99 * * K. Brill/HPC 2/00 Add IGPDS * * K. Brill/HPC 3/00 Avoid character assignment to itself * * R. Tian/SAIC 10/06 Recoded from Fortran * ************************************************************************/ { char *pchr, gvcord[5], gdnbuf[LLMXLN], flgdtm1[21], flgdtm2[21], otime[21], oparm[13], ovcrd[13], olevl[17], c2d[3], cdum[3], cyr[3]; int dowhat, inam, ihat, iaat, ipct, iyr, num, noptv, idoc, idngp, idosc, ipos[4], ier; /*----------------------------------------------------------------------*/ *iret = 0; inam = 0; ihat = 0; iaat = 0; ipct = 0; oparm[0] = '\0'; otime[0] = '\0'; olevl[0] = '\0'; ovcrd[0] = '\0'; /* * Decode the override grid identifier parameters: */ if ( strlen(pdsval) > 0 ) { dowhat = DONAM; cst_lcuc ( (char *)pdsval, gdnbuf, &ier ); for ( pchr = gdnbuf; *pchr != '\0'; pchr++ ) { if ( *pchr == '^' ) dowhat = DOHAT; if ( *pchr == '@' ) dowhat = DOAAT; if ( *pchr == '%' ) dowhat = DOPCT; switch ( dowhat ) { /* * Retrieve grid name. */ case DONAM: oparm[inam++] = *pchr; break; /* * Retrieve in-line time. */ case DOHAT: if ( *pchr == '^' ) continue; otime[ihat++] = *pchr; break; /* * Retrieve in-line level. */ case DOAAT: if ( *pchr == '@' ) continue; olevl[iaat++] = *pchr; break; /* * Retrieve in-line vertical coordinate. */ case DOPCT: if ( *pchr == '%' ) continue; ovcrd[ipct++] = *pchr; break; } } oparm[inam] = '\0'; otime[ihat] = '\0'; olevl[iaat] = '\0'; ovcrd[ipct] = '\0'; } /* * Check for override on the date/time stamp. */ if ( ihat > 0 ) { strcpy ( flgdtm1, otime ); flgdtm2[0] = '\0'; } else { /* * Add century to YYMMDD. */ if ( strchr ( gdttm1, '/' ) - gdttm1 < 8 ) { strncpy ( cyr, gdttm1, 2 ); cyr[2] = '\0'; cst_numb ( cyr, &iyr, &ier ); if ( iyr < 70 ) { strcpy ( flgdtm1, "20" ); strcat ( flgdtm1, gdttm1 ); } else { strcpy ( flgdtm1, "19" ); strcat ( flgdtm1, gdttm1 ); } } else { strcpy ( flgdtm1, gdttm1 ); } flgdtm2[0] = '\0'; } /* * Next, set the OCTET 4, 5, 6, and 26 values. */ cst_ilst ( (char *)vercen, '/', 0, 4, ipos, &num, &ier ); if ( ipos[0] != 0 ) { noptv = ipos[0]; } else { noptv = 2; } if ( ipos[1] != 0 ) { idoc = ipos[1]; } else { idoc = 7; } if ( ipos[2] != 0 ) { idngp = ipos[2]; } else { idngp = 0; } if ( ipos[3] != 0 ) { idosc = ipos[3]; } else { idosc = 5; } /* * Translate vertical coordinate number as character string. */ if ( *ivcord == 0 ) { strcpy ( gvcord, "NONE" ); } else if ( *ivcord == 1 ) { strcpy ( gvcord, "PRES" ); } else if ( *ivcord == 2 ) { strcpy ( gvcord, "THTA" ); } else if ( *ivcord == 3 ) { strcpy ( gvcord, "HGHT" ); } else if ( *ivcord == 4 ) { strcpy ( gvcord, "SGMA" ); } else if ( *ivcord == 5 ) { strcpy ( gvcord, "DPTH" ); } else { strcpy ( gvcord, "NULL" ); } /* * Build the PDS now. */ pds_make( &noptv, &idoc, &idngp, &idosc, rnvblk, gparm, oparm, gvcord, ovcrd, level1, level2, olevl, havbms, ip10sc, lasttm, flgdtm1, flgdtm2, gbtbls, igpds, nbpds, cpds, ipos, iret ); /* * Convert day, hour, and minute in IPOS to characters. */ cst_inch ( ipos[0], c2d, &ier ); if ( ipos[0] < 10 ) { cdum[0] = '0'; cdum[1] = c2d[0]; cdum[2] = '\0'; } else { strcpy ( cdum, c2d ); } strcpy ( cdd, cdum ); cst_inch ( ipos[1], c2d, &ier ); if ( ipos[1] < 10 ) { cdum[0] = '0'; cdum[1] = c2d[0]; cdum[2] = '\0'; } else { strcpy ( cdum, c2d ); } strncpy ( chhmm, cdum, 2 ); cst_inch ( ipos[2], c2d, &ier ); if ( ipos[2] < 10 ) { cdum[0] = '0'; cdum[1] = c2d[0]; cdum[2] = '\0'; } else { strcpy ( cdum, c2d ); } strncpy ( &chhmm[2], cdum, 2 ); chhmm[4] = '\0'; return; }
void dg_pfun ( const char *func, int *iret ) /************************************************************************ * dg_pfun * * * * This subroutine parses a diagnostic function entered by the user. * * The output is returned in the diagnostic function tables. In-line * * parameters may be appended to an operand in any combination. The * * flags are: * * * * Parameter: time level ivcord * * Flag: ^ @ % * * * * dg_pfun ( func, iret ) * * * * Input parameters: * * *func const char Input function * * * * Output parameters: * * *iret int Return code * * 0 = normal return * ** * * Log: * * M. desJardins/GSFC 10/85 * * J. Nielsen/MIT 4/88 Added ^ and & * * M. desJardins/GSFC 7/88 Added %; changed & to @ for TAE * * K. Brill/GSC 9/89 Addd + * * K. Brill/NMC 5/93 Assume FUNC is already upper case * * M. desJardins/NMC 8/93 Use MMFILE as maximum number of files * * S. Jacobs/EAI 9/93 Fixed typo * * P. Bruehl/Unidata 8/94 Increased dimension on f from 20 to 36 * * to allow for grids w/ 2 times after "^" * * T. Piper/GSC 7/01 Fixed typo f*30 -> f*36 * * m.gamazaychikov/SAIC 09/05 Added call to ST_NARG * * R. Tian/SAIC 2/06 Recoded from Fortran * ************************************************************************/ { char f[37], c, dfunc[133]; int dtm, lev, vcr, fil; int nf, iend, ival, ier, i; /*----------------------------------------------------------------------*/ /* * Initialize variables. */ *iret = 0; _dgtabl.ltabl = -1; memset ( f, 0, sizeof(f) ); nf = 0; strcpy ( dfunc, func ); cst_lstr ( dfunc, &iend, &ier ); /* * First replace brackets with parentheses and semicolons with commas. * Brackets and semicolons may be used to make the function easier to * enter in the TAE tutor. */ for ( i = 0; i < iend; i++ ) { c = dfunc[i]; if ( c == '[' ) dfunc[i] = '('; if ( c == ']' ) dfunc[i] = ')'; if ( c == ';' ) dfunc[i] = ','; } /* * Loop through input string checking each character. */ dtm = G_FALSE; lev = G_FALSE; vcr = G_FALSE; fil = G_FALSE; for ( i = 0; i < iend; i++ ) { c = dfunc[i]; if ( c == ' ' ) { /* * Do nothing for blanks. */ } else if ( c == '(' ) { /* * Left parentheses, (, indicate the end of a function. */ if ( nf != 0 ) { _dgtabl.ltabl++; strcpy ( _dgtabl.ctabl[_dgtabl.ltabl], "*" ); strcat ( _dgtabl.ctabl[_dgtabl.ltabl], f ); cst_narg ( dfunc, i, ',', &_dgtabl.nfargs[_dgtabl.ltabl], &ier ); memset ( f, 0, sizeof(f) ); nf = 0; } } else if ( ( c == ')' ) || ( c == ',' ) || ( c == '%' ) || ( c == '^' ) || ( c == '@' ) || ( c == '+' ) ) { /* * Right parentheses, ), or commas indicate end of a parm. * %, ^, @, + flag end of parm and beginning of vcord, time * level or file number. */ if ( nf != 0 ) { if ( dtm == G_TRUE ) { if ( _dgtabl.ltabl > -1 ) { strcpy ( _dgtabl.cgdttm[_dgtabl.ltabl], f ); } dtm = G_FALSE; } else if ( lev == G_TRUE ) { if ( _dgtabl.ltabl > -1 ) { strcpy ( _dgtabl.clevel[_dgtabl.ltabl], f ); } lev = G_FALSE; } else if ( vcr == G_TRUE ) { if ( _dgtabl.ltabl > -1 ) { strcpy ( _dgtabl.cvcord[_dgtabl.ltabl], f ); } vcr = G_FALSE; } else if ( fil == G_TRUE ) { if ( _dgtabl.ltabl >= 0 ) { cst_numb ( f, &ival, &ier ); if ( ( ival > 0 ) && ( ival <= MMFILE ) ) { _dgtabl.icflnm[_dgtabl.ltabl] = ival; } } fil = G_FALSE; } else { _dgtabl.ltabl++; strcpy ( _dgtabl.ctabl[_dgtabl.ltabl], f ); _dgtabl.nfargs[_dgtabl.ltabl] = 0; _dgtabl.clevel[_dgtabl.ltabl][0] = '\0'; _dgtabl.cvcord[_dgtabl.ltabl][0] = '\0'; strcpy ( _dgtabl.cgdttm[_dgtabl.ltabl], _dginpt.ingdtm ); _dgtabl.icflnm[_dgtabl.ltabl] = 1; } memset ( f, 0, sizeof(f) ); nf = 0; if ( c == '%' ) vcr = G_TRUE; if ( c == '^' ) dtm = G_TRUE; if ( c == '@' ) lev = G_TRUE; if ( c == '+' ) fil = G_TRUE; } } else if ( i == iend - 1) { /* * At end of function, check for single parameter. */ f[nf++] = c; if ( dtm == G_TRUE ) { if ( _dgtabl.ltabl > -1 ) { strcpy ( _dgtabl.cgdttm[_dgtabl.ltabl], f ); } dtm = G_FALSE; } else if ( lev == G_TRUE ) { if ( _dgtabl.ltabl > -1 ) { strcpy ( _dgtabl.clevel[_dgtabl.ltabl], f ); } lev = G_FALSE; } else if ( vcr == G_TRUE ) { if ( _dgtabl.ltabl > -1 ) { strcpy ( _dgtabl.cvcord[_dgtabl.ltabl], f ); } vcr = G_FALSE; } else if ( fil == G_TRUE ) { if ( _dgtabl.ltabl > -1 ) { cst_numb ( f, &ival, &ier ); if ( ( ival > 0 ) && ( ival <= MMFILE ) ) { _dgtabl.icflnm[_dgtabl.ltabl] = ival; } } fil = G_FALSE; } else { _dgtabl.ltabl++; strcpy ( _dgtabl.ctabl[_dgtabl.ltabl], f ); _dgtabl.nfargs[_dgtabl.ltabl] = 0; _dgtabl.clevel[_dgtabl.ltabl][0] = '\0'; _dgtabl.cvcord[_dgtabl.ltabl][0] = '\0'; strcpy ( _dgtabl.cgdttm[_dgtabl.ltabl], _dginpt.ingdtm ); _dgtabl.icflnm[_dgtabl.ltabl] = 1; } } else { /* * Otherwise, add this character to the function name. */ f[nf++] = c; } } /* * Compute the area to include. */ dg_sare ( &ier ); return; }
void ctb_hfread ( int *iret ) /************************************************************************ * ctb_pfread * * * * This function reads the info from the Hershey Fonts tables. * * * * The Hershey Font coordinates are encoded using the ASCII characters. * * Each character pair represents a coordinate in the drawing system * * with 'R,R' as the origin. To get the coordinate values, subtract * * 'R' from the given character. For example, the pair 'SB' corresponds * * to (+1,-16). * * * * ctb_hfread ( iret ) * * * * Input parameters: * * * * Output parameters: * * *iret int Return code * * -1 = cannot open or read table* * -12 = cannot allocate memory * ** * * Log: * * S. Jacobs/NCEP 10/07 Created * * T. Piper/SAIC 03/08 Replaced cmm functions with Macros * ***********************************************************************/ { FILE *fp; char buffer[256], av[6]; int ii, nr, ier, ifont, ier2, jj, kk, nf, one = 1; font_tbl_name_t tbl[] = { {"hfont03.tbl", 3}, {"hfont23.tbl", 23}, {"hfont04.tbl", 4}, {"hfont14.tbl", 14}, {"hfont24.tbl", 24}, {"hfont34.tbl", 34} }; /*---------------------------------------------------------------------*/ *iret = G_NORMAL; /* * Allocate space for all of the font structures. */ nf = sizeof(tbl)/sizeof(tbl[0]); G_MALLOC ( _hfontTbl, HF_font_t, nf, "ctb_hfread - _hfontTbl"); if ( _hfontTbl == NULL ) { *iret = -12; return; } _nhfont = 0; for ( ifont = 0; ifont < nf; ifont++ ) { /* * Read the font table and add entries into the structure. */ nr = 0; fp = cfl_tbop ( tbl[ifont].table_name, "hershey", &ier ); if ( ier == 0 ) { cfl_tbnr ( fp, &nr, &ier); } if ( nr == 0 ) { cfl_clos ( fp, &ier ); *iret = -1; return; } _hfontTbl[ifont].font_code = tbl[ifont].font_num; /* * Allocate space for the characters. */ G_MALLOC ( _hfontTbl[ifont].character, HF_char_t, nr, "ctb_hfread - _hfontTbl[ifont].character"); if ( _hfontTbl[ifont].character == NULL ) { cfl_clos ( fp, &ier ); *iret = -12; return; } /* * Read table entries into the structure. */ ii = 0; /* Read the next line from the file */ cfl_trln ( fp, 256, buffer, &ier ); /* * Process the file while there is no error and * the end of the file has not been reached. */ while ( ier >= 0 && ier != 4 ) { if ( ier == 0 ) { G_MALLOC ( _hfontTbl[ifont].character[ii].point_code, char, strlen(buffer)+1, " ctb_hfread - _hfontTbl[ifont].character[ii].point_code"); if ( _hfontTbl[ifont].character[ii].point_code == NULL ) { cfl_clos ( fp, &ier ); *iret = -12; return; } strcpy ( _hfontTbl[ifont].character[ii].point_code, buffer ); /* Get the character ASCII code */ cst_ncpy ( av, &(buffer[0]), 5, &ier2 ); cst_numb ( av, &(_hfontTbl[ifont].character[ii].ascii_val), &ier2 ); /* * Get the number of points for the character * (The number in the file includes the X min and max, * so subtract one) */ cst_ncpy ( av, &(buffer[5]), 3, &ier2 ); cst_numb ( av, &(_hfontTbl[ifont].character[ii].npts), &ier2 ); (_hfontTbl[ifont].character[ii].npts)--; /* Get the X min and max */ _hfontTbl[ifont].character[ii].xmin = buffer[8] - 'R'; _hfontTbl[ifont].character[ii].xmax = buffer[9] - 'R'; /* Get the coordinates, if the number of points is > 0 */ if ( _hfontTbl[ifont].character[ii].npts > 0 ) { G_MALLOC ( _hfontTbl[ifont].character[ii].point, HF_point_t, _hfontTbl[ifont].character[ii].npts, " ctb_hfread - _hfontTbl[ifont].character[ii].point"); if ( _hfontTbl[ifont].character[ii].point == NULL ) { cfl_clos ( fp, &ier ); *iret = -12; return; } /* * Check for " R", which denotes a "pen up". * If there is a pen up code, set the points to missing. * Otherwise, decode the coordinate values. */ kk = 10; for ( jj = 0; jj < _hfontTbl[ifont].character[ii].npts; jj++ ) { if ( strncmp ( &(buffer[kk]), " R", 2 ) == 0 ) { _hfontTbl[ifont].character[ii].point[jj].x = -99; _hfontTbl[ifont].character[ii].point[jj].y = -99; kk += 2; } else { _hfontTbl[ifont].character[ii].point[jj].x = buffer[kk] - 'R'; kk++; _hfontTbl[ifont].character[ii].point[jj].y = buffer[kk] - 'R'; kk++; } } } /* * If there are no character codes, * set one point at the origin */ else { G_MALLOC ( _hfontTbl[ifont].character[ii].point, HF_point_t, one, " ctb_hfread - _hfontTbl[ifont].character[ii].point"); if ( _hfontTbl[ifont].character[ii].point == NULL ) { cfl_clos ( fp, &ier ); *iret = -12; return; } _hfontTbl[ifont].character[ii].point[0].x = 0; _hfontTbl[ifont].character[ii].point[0].y = 0; } ii++; } /* Read the next line from the file */ cfl_trln ( fp, 256, buffer, &ier ); } /* Set the number of characters for the font */ _hfontTbl[ifont].numchr = ii; /* Close the font table */ cfl_clos ( fp, &ier ); /* Increase the count for the number of fonts */ _nhfont++; }
int main ( void ) /************************************************************************ * TESTGPC * * * * This program tests the GPC contributed library public functions. * * * ** * * Log: * * D.W.Plummer/NCEP 2/04 * * D.W.Plummer/NCEP 10/06 Added GPC_SET_EPSILON * ***********************************************************************/ { int ii, cont, numsub, which, ier; int operation, readholeflag, writeholeflag, hole; int nverts=0; double e; char select[8]; float xv[LLMXPT], yv[LLMXPT]; char filnam[256], buffer[80]; int pagflg; char errgrp[8]; FILE *fpread, *fpwrite; gpc_polygon subject_polygon, clip_polygon, result_polygon; gpc_vertex_list contour; /*---------------------------------------------------------------------*/ cont = G_FALSE; /* * Structure initializations. */ subject_polygon.num_contours = 0; subject_polygon.hole = (int*)NULL; subject_polygon.contour = (gpc_vertex_list*)NULL; clip_polygon.num_contours = 0; result_polygon.num_contours = 0; contour.vertex = (gpc_vertex*)NULL; contour.num_vertices = 0; while ( cont == G_FALSE ) { printf ( "\n\n" ); printf ( "*** ORIGINAL GPC PUBLIC FUNCTIONS ***\n"); printf ( " 1 = GPC_READ_POLYGON 2 = GPC_WRITE_POLYGON \n"); printf ( " 3 = GPC_ADD_CONTOUR 4 = GPC_POLYGON_CLIP \n"); printf ( " 5 = GPC_FREE_POLYGON \n"); printf ( "*** GPC PUBLIC FUNCTION ADD-ONS ***\n"); printf ( " 11 = GPC_CREATE_VERTEX_LIST \n"); printf ( " 12 = GPC_GET_VERTEX_LIST \n"); printf ( " 13 = GPC_GET_VERTEX_AREA \n"); printf ( " 14 = GPC_SET_EPSILON \n"); printf ( "*** HELP ***\n"); printf ( " 99 = HELP on INPUT FILE FORMATS \n"); printf ( "\n" ); printf ( "Select a subroutine number or type EXIT: " ); scanf ( " %s", select ); switch ( select[0] ) { case 'e': case 'E': cont = G_TRUE; default: numsub = atoi ( select ); break; } /*---------------------------------------------------------------------*/ if ( numsub == 1 ) { printf("Make sure your polygon file is in the proper format:\n"); printf("<num-contours>\n"); printf("<num-vertices-in-first-contour>\n"); printf("[<first-contour-hole-flag>]\n"); printf("<vertex-list>\n"); printf("<num-vertices-in-second-contour>\n"); printf("[<second-contour-hole-flag>]\n"); printf("<vertex-list> \n"); printf("etc...\n"); printf ( "Enter filename to read polygon from : \n"); scanf ( " %s", filnam ); printf ( "Enter whether file format contains hole flags (%d-FALSE,%d-TRUE) :\n", G_FALSE, G_TRUE ); scanf ( " %d", &readholeflag ); printf ( "Enter which polygon (%d-SUBJECT,%d-CLIP) :\n", SUBJECT, CLIP ); scanf ( " %d", &which ); fpread = (FILE *)cfl_ropn ( filnam, "", &ier ); if ( ier == G_NORMAL ) { if ( which == SUBJECT ) gpc_read_polygon ( fpread, readholeflag, &subject_polygon ); else if ( which == CLIP ) gpc_read_polygon ( fpread, readholeflag, &clip_polygon ); else printf("Invalid polygon type\n"); cfl_clos ( fpread, &ier ); } else { printf("Unable to open file %s\n", filnam ); } } /*---------------------------------------------------------------------*/ if ( numsub == 2 ) { printf ( "Enter filename to write polygon to : \n"); scanf ( " %s", filnam ); printf ( "Enter the write hole flag (%d-FALSE,%d-TRUE):\n", G_FALSE, G_TRUE ); scanf ( " %d", &writeholeflag ); printf ( "Enter which polygon (%d-SUBJECT,%d-CLIP,%d-RESULT):\n", SUBJECT, CLIP, RESULT ); scanf ( " %d", &which ); fpwrite = (FILE *)cfl_wopn ( filnam, &ier ); if ( ier == G_NORMAL ) { if ( which == SUBJECT ) gpc_write_polygon ( fpwrite, writeholeflag, &subject_polygon ); else if ( which == CLIP ) gpc_write_polygon ( fpwrite, writeholeflag, &clip_polygon ); else if ( which == RESULT ) gpc_write_polygon ( fpwrite, writeholeflag, &result_polygon ); else printf("Invalid polygon type\n"); cfl_clos ( fpwrite, &ier ); } else { printf("Unable to open file %s\n", filnam ); } } /*---------------------------------------------------------------------*/ if ( numsub == 3 ) { if ( nverts == 0 ) { printf("Must first create a vertex list (option 11)\n"); } else { printf ( "Enter which polygon (%d-SUBJECT,%d-CLIP,%d-RESULT) to add vertex list to:\n", SUBJECT, CLIP, RESULT ); scanf ( " %d", &which ); printf ( "Enter the hole flag (%d-HOLE,%d-NOT A HOLE):\n", G_TRUE, G_FALSE ); scanf ( " %d", &hole ); if ( which == SUBJECT ) { gpc_add_contour ( &subject_polygon, &contour, hole ); } else if ( which == CLIP ) { gpc_add_contour ( &clip_polygon, &contour, hole ); } else { printf("Invalid polygon\n"); } } } /*---------------------------------------------------------------------*/ if ( numsub == 4 ) { printf ( "Enter operation (%d-GPC_DIFF,%d-GPC_INT,%d-GPC_XOR,%d-GPC_UNION):\n", GPC_DIFF, GPC_INT, GPC_XOR, GPC_UNION ); scanf ( " %d", &operation ); gpc_polygon_clip ( operation, &subject_polygon, &clip_polygon, &result_polygon ); } /*---------------------------------------------------------------------*/ if ( numsub == 5 ) { printf ( "Enter which polygon (%d-SUBJECT,%d-CLIP,%d-RESULT,%d-ALL) to free contours:\n ", SUBJECT, CLIP, RESULT, ALL ); scanf ( " %d", &which ); if ( which == SUBJECT || which == ALL ) { if ( subject_polygon.num_contours != 0 ) gpc_free_polygon ( &subject_polygon ); } else if ( which == CLIP || which == ALL ) { if ( clip_polygon.num_contours != 0 ) gpc_free_polygon ( &clip_polygon ); } else if ( which == RESULT || which == ALL ) { if ( result_polygon.num_contours != 0 ) gpc_free_polygon ( &result_polygon ); } } /*---------------------------------------------------------------------*/ if ( numsub == 11 ) { printf ( "Enter either the number of points in polygon (to be followed by entering the points), or a filename to read points from: \n"); scanf ( " %s", filnam ); cst_numb ( filnam, &nverts, &ier ); if ( ier == 0 ) { for ( ii = 0; ii < nverts; ii++ ) scanf ( "%f %f", &(xv[ii]), &(yv[ii]) ); if ( contour.vertex != (gpc_vertex*)NULL ) free ( contour.vertex ); gpc_cvlist ( nverts, xv, yv, &contour, &ier ); } else { printf ( "Note that the file format is simply a list of coordinate pairs separated by whitespace.\nThe number of points will be counted automatically. For instance, a file containing:\n0 0\n0 1\n1 1\nyields a vertex list of three points.\n\n"); nverts = 0; fpread = (FILE *)cfl_tbop ( filnam, "", &ier ); if ( ier == G_NORMAL ) { cfl_trln ( fpread, sizeof(buffer), buffer, &ier ); while ( ier == 0 ) { sscanf ( buffer, "%f %f", &(xv[nverts]), &(yv[nverts]) ); nverts += 1; cfl_trln ( fpread, sizeof(buffer), buffer, &ier ); } printf("EOF reached in file %s, number of vertices = %d\n", filnam, nverts ); cfl_clos( fpread, &ier ); if ( contour.vertex != (gpc_vertex*)NULL ) free ( contour.vertex ); gpc_cvlist ( nverts, xv, yv, &contour, &ier ); } } } /*---------------------------------------------------------------------*/ if ( numsub == 12 ) { gpc_gvlist ( &contour, &nverts, xv, yv, &ier ); printf("gpc_gvlist, ier = %d\n", ier ); printf("Number of vertices = %d\n", nverts ); for ( ii = 0; ii < nverts; ii++ ) printf ( "%d - %f %f\n", ii, xv[ii], yv[ii] ); } /*---------------------------------------------------------------------*/ if ( numsub == 13 ) { printf ( "Area of contour is %f\n", gpc_gvarea(&contour) ); } /*---------------------------------------------------------------------*/ if ( numsub == 14 ) { scanf ( " %lf", &e ); gpc_set_epsilon ( e ); } /*---------------------------------------------------------------------*/ if ( numsub == 99 ) { pagflg = G_FALSE; strcpy ( errgrp, "TESTGPC" ); ip_help ( errgrp, &pagflg, &ier, strlen(errgrp) ); } /*---------------------------------------------------------------------*/ } if ( subject_polygon.num_contours != 0 ) gpc_free_polygon ( &subject_polygon ); if ( clip_polygon.num_contours != 0 ) gpc_free_polygon ( &clip_polygon ); if ( result_polygon.num_contours != 0 ) gpc_free_polygon ( &result_polygon ); if ( contour.vertex != (gpc_vertex*)NULL ) free ( contour.vertex ); return(0); }