void wbc_mzrm ( char *states, char *ststr, int *len1, int *iret ) /************************************************************************ * wbc_mzrm * * * * This function removes the specific marine zones listed above from * * the state id string. * * * * wbc_mzrm ( states, len1, len2, stzstr, sttstr, iret ) * * * * Input parameters: * * *states char String of state ids * * * * Output parameters: * * *ststr char States id string; no Mar. Zones * * *len1 int Length of ststr * * *iret int Return Code * * * ** * * Log: * * A. Hardy/NCEP 5/03 * * A. Hardy/NCEP 9/04 Added "SL" * * T. Piper/SAIC 02/05 Removed unused variable 'stnam' * ***********************************************************************/ { int ii, ier, ilen, ipos; /*-------------------------------------------------------------------*/ *iret = 0; ier = 0; ststr[0] = '\0'; /* * Remove unwanted marine zones listed above from state strings. */ ii = 0; while ( ( ii < NUM_ZNS ) ) { cst_rmst ( states, _mzones[ii], &ipos, states, &ier); if ( ipos > 0 ) { cst_rxbl ( states, states, &ilen, &ier); } ii++; } cst_lstr ( states, &ilen, &ier ); cst_ncpy ( ststr, states, ilen, &ier ); }
static void gemInfo_init( Geminfo* const gemInfo, Gribmsg* const gribMsg) { gb2_2gem(&curr_g2, &curr_gem, tbllist, &ier); if (ier != 0) { sprintf(g2name,"UNK\0"); sprintf(levelstmp,"LVL\0"); sprintf(fdats,"FHRS\0"); } else { sprintf(g2name,"%s\0",curr_gem.parm); cst_rmbl (g2name, g2name, &ilen, &ier ); if ( n > 0 ) strncat ( prods, ";", 1); sprintf(prods+strlen(prods),"%s\0",g2name); strptr[0] = (char *)malloc(12); cst_itoc ( &curr_gem.vcord, 1, (char **)(&strptr), &ier); cst_rxbl (curr_gem.unit, curr_gem.unit, &ilen, &ier); if ( ilen == 0 ) sprintf (curr_gem.unit, "-\0"); if ( curr_gem.level[1] == -1 ) sprintf(levelstmp,"%d %s %s\0",curr_gem.level[0],curr_gem.unit,strptr[0]); else sprintf(levelstmp,"%d-%d %s %s\0",curr_gem.level[0],curr_gem.level[1],curr_gem.unit,strptr[0]); cst_rmbl (curr_gem.gdattm1, curr_gem.gdattm1, &ilen, &ier ); cst_rmbl (curr_gem.gdattm2, curr_gem.gdattm2, &ilen, &ier ); if ( ilen > 0 ) sprintf(fdats,"%s-%s\0",curr_gem.gdattm1,curr_gem.gdattm2); else sprintf(fdats,"%s\0",curr_gem.gdattm1); ilen = 1; while ( ilen > 0 ) cst_rmst(fdats, "/", &ilen, fdats, &ier); free(strptr[0]); } }
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); } }
/** * Generates an LDM product-identifier from a GRIB edition 2 message. * * Atomic, * Idempotent, * Not thread-safe * * @param[in] data Pointer to the GRIB message. * @param[in] sz Length of the GRIB message in bytes. * @param[in] wmohead Pointer to the associated WMO header string. * @param[out] ident Pointer to a buffer to receive the LDM * product-identifier. * @param[in] identSize Size of the \c ident buffer in bytes. * @retval 0 Success. \c ident is set and NUL-terminated. * @retval 1 Invalid GRIB message. * @retval 2 GRIB message isn't edition 2. * @retval 3 System error. */ int grib2name ( char* const data, const size_t sz, const char* const wmohead, char* const ident, const size_t identSize) { #if USE_GRIB2_DECODER int status; DecodedGrib2Msg* decoded; if (status = g2d_new(&decoded, (unsigned char*)data, sz)) { log_add("Couldn't decode GRIB message"); status = G2D_INVALID == status ? 1 : G2D_NOT_2 ? 2 : 3; } else { if (status = setIdent(ident, identSize, decoded, wmohead)) { log_add("Couldn't set LDM product-identifier"); status = 1; } g2d_free(decoded); } /* "decoded" allocated */ return status; #else static StringBuf* paramNames; /* Buffer for parameter name(s) */ int iField; /* GRIB-2 field index */ int status; /* Function return code */ g2int listsec0[3]; /* GRIB-2 section 0 parameters */ g2int listsec1[13]; /* GRIB-2 section 1 parameters */ g2int numlocal; /* Number of GRIB section 2-s */ int model_id; /* ID of model */ int grid_id; /* ID of grid */ char fdats[80]; /* No idea */ char levelstmp[80]; /* Level? */ Gribmsg g2Msg; /* GRIB-2 message structure */ if (paramNames) { strBuf_clear(paramNames); } else { paramNames = strBuf_new(127); if (NULL == paramNames) { log_add("Couldn't allocate buffer for parameter name(s)"); return 3; } } g2Msg.cgrib2 = (unsigned char*)data; g2Msg.mlength = sz; g2Msg.gfld = NULL; g2Msg.field_tot = 0; if ((status = g2_info(g2Msg.cgrib2, g2Msg.mlength, listsec0, listsec1, &(g2Msg.field_tot), &numlocal)) != 0) return (2 == status) ? 2 : 1; if (g2Msg.field_tot <= 0) { log_add("GRIB-2 message has no data fields"); return 1; } for (iField = 0; iField < g2Msg.field_tot; iField++) { static char g2tables[5][LLMXLN]; /* GRIB tables */ static char* tbllist[5] = {g2tables[0], g2tables[1], g2tables[2], g2tables[3], g2tables[4]}; /* Addresses of GRIB tables */ Geminfo gemInfo; /* GEMPAK structure */ int const lastField = iField == g2Msg.field_tot - 1; status = g2_getfld(g2Msg.cgrib2, g2Msg.mlength, iField+1, 0, 0, &g2Msg.gfld); if (status) { log_add("Invalid GRIB-2 message: g2_getfld() status=%d", status); return (2 == status) ? 2 : 1; } /* "g2Msg.gfld" is allocated */ /* Initialize strings in Geminfo structure */ (void)memset(gemInfo.cproj, 0, sizeof(gemInfo.cproj)); (void)memset(gemInfo.parm, 0, sizeof(gemInfo.parm)); (void)memset(gemInfo.gdattm1, 0, sizeof(gemInfo.gdattm1)); (void)memset(gemInfo.gdattm2, 0, sizeof(gemInfo.gdattm2)); /* * In the original code, the last field determined the model ID. */ if (lastField) model_id = g2Msg.gfld->ipdtmpl[4]; /* * This assignment to "grid_id" isn't under the above "lastField" * conditional because "decode_g2gnum()" might have side-effects upon * which "gb2_2gem()" depends. */ grid_id = (g2Msg.gfld->griddef == 0) ? decode_g2gnum(g2Msg.gfld) : g2Msg.gfld->griddef; gb2_2gem(&g2Msg, &gemInfo, tbllist, &status); if (status) { log_add("Couldn't decode GRIB2 message. WMO header=\"%s\"", wmohead); log_flush_error(); if (lastField) { (void)strcpy(fdats, "FHRS"); /* safe */ (void)strcpy(levelstmp, "LVL"); /* safe */ } } else { char g2name[13]; /**< Name of product/parameter */ int ilen; /**< Length of resulting string */ (void)strcpy(g2name, gemInfo.parm); /* both 13 bytes */ cst_rmbl(g2name, g2name, &ilen, &status); if (iField) strBuf_appendString(paramNames, ";"); strBuf_appendString(paramNames, g2name); cst_rxbl(gemInfo.unit, gemInfo.unit, &ilen, &status); if (ilen == 0) (void)strcpy(gemInfo.unit, "-"); /* safe */ cst_rmbl(gemInfo.gdattm1, gemInfo.gdattm1, &ilen, &status); cst_rmbl(gemInfo.gdattm2, gemInfo.gdattm2, &ilen, &status); /* * In the original code, the last field determined the following * parameters. */ if (lastField) { static char strBuf[5]; /* Holds 4-char string */ static char* strptr = strBuf; /* For "cst_itoc()" */ if (ilen > 0) (void)snprintf(fdats, sizeof(fdats), "%s-%s", gemInfo.gdattm1, gemInfo.gdattm2); else (void)snprintf(fdats, sizeof(fdats), "%s", gemInfo.gdattm1); for (ilen = 1; ilen > 0; cst_rmst(fdats, "/", &ilen, fdats, &status)); cst_itoc(&gemInfo.vcord, 1, &strptr, &status); if (gemInfo.level[1] == -1) (void)snprintf(levelstmp, sizeof(levelstmp), "%d %s %s", gemInfo.level[0], gemInfo.unit, strptr); else (void)snprintf(levelstmp, sizeof(levelstmp), "%d-%d %s %s", gemInfo.level[0], gemInfo.level[1], gemInfo.unit, strptr); } } g2_free(g2Msg.gfld); g2Msg.gfld = NULL; } /* * See if the WMO header can be used for grid 0 products */ if ((grid_id == 0) && (strlen(wmohead) > 11) && (wmohead[7] == 'K') && (wmohead[8] == 'W')) { int wmoGridId = wmo_to_gridid(&wmohead[0], &wmohead[2]); if (wmoGridId > 0) grid_id = wmoGridId; } (void)snprintf(ident, identSize, "grib2/%s/%s/#%03d/%s/%s/%s", s_pds_center((int)listsec1[0], (int)listsec1[1]), s_pds_model((int)listsec1[0], model_id), grid_id, fdats, strBuf_toString(paramNames), levelstmp); return 0; #endif }
void grib2name ( char *filename, int seqno, char *data, size_t sz, char *ident ) { int i, n, ier, ilen; int unpack=0, expand=0; g2int listsec0[3],listsec1[13],numlocal; int model_id, grid_id; char g2name[13], fdats[80]; char prodtmp[255]; char levelstmp[80]; char prods[128]; static char datyp[]="grib2", slashstr[]="/"; static int tblinit=0; static char *strptr[5]; Gribmsg curr_g2; Geminfo curr_gem; static char g2tables[5][LLMXLN] = { 0 }, *tbllist[5]; curr_g2.cgrib2 = (unsigned char *)data; curr_g2.mlength = sz; curr_g2.gfld = NULL; curr_g2.field_tot = 0; if ( !tblinit) { for (i = 0; i < 5; i++) tbllist[i] = g2tables[i]; tblinit = !0; } /* modify below to pass message size as a failsafe check */ /*if ( ( ier = g2_info ( curr_g2.cgrib2, listsec0,listsec1, &(curr_g2.field_tot), &numlocal) ) != 0 ) */ if ( ( ier = g2_info ( curr_g2.cgrib2, curr_g2.mlength, listsec0,listsec1, &(curr_g2.field_tot), &numlocal) ) != 0 ) return; prods[0] = '\0'; for ( n=0; n < curr_g2.field_tot; n++) { ier=g2_getfld( curr_g2.cgrib2, curr_g2.mlength, n+1, unpack, expand, &curr_g2.gfld); /* initialize strings in geminfo structure */ memset ( curr_gem.cproj, 0, sizeof(curr_gem.cproj)); memset ( curr_gem.parm, 0, sizeof(curr_gem.parm)); memset ( curr_gem.gdattm1, 0, sizeof(curr_gem.gdattm1)); memset ( curr_gem.gdattm2, 0, sizeof(curr_gem.gdattm2)); model_id = curr_g2.gfld->ipdtmpl[4]; grid_id = curr_g2.gfld->griddef; gb2_2gem (&curr_g2, &curr_gem, tbllist, &ier); if ( ier != 0 ) { sprintf(g2name,"UNK\0"); sprintf(levelstmp,"LVL\0"); sprintf(fdats,"FHRS\0"); } else { sprintf(g2name,"%s\0",curr_gem.parm); cst_rmbl (g2name, g2name, &ilen, &ier ); if ( n > 0 ) strncat ( prods, ";", 1); sprintf(prods+strlen(prods),"%s\0",g2name); strptr[0] = (char *)malloc(12); cst_itoc ( &curr_gem.vcord, 1, (char **)(&strptr), &ier); cst_rxbl (curr_gem.unit, curr_gem.unit, &ilen, &ier); if ( ilen == 0 ) sprintf (curr_gem.unit, "-\0"); if ( curr_gem.level[1] == -1 ) sprintf(levelstmp,"%d %s %s\0",curr_gem.level[0],curr_gem.unit,strptr[0]); else sprintf(levelstmp,"%d-%d %s %s\0",curr_gem.level[0],curr_gem.level[1],curr_gem.unit,strptr[0]); cst_rmbl (curr_gem.gdattm1, curr_gem.gdattm1, &ilen, &ier ); cst_rmbl (curr_gem.gdattm2, curr_gem.gdattm2, &ilen, &ier ); if ( ilen > 0 ) sprintf(fdats,"%s-%s\0",curr_gem.gdattm1,curr_gem.gdattm2); else sprintf(fdats,"%s\0",curr_gem.gdattm1); ilen = 1; while ( ilen > 0 ) cst_rmst(fdats, slashstr, &ilen, fdats, &ier); free(strptr[0]); } g2_free(curr_g2.gfld); curr_g2.gfld = NULL; } sprintf(prodtmp,"%s/%s/%s/#%03d/%s/%s/%s! %06d\0", datyp, s_pds_center((int)listsec1[0],(int)listsec1[1]), s_pds_model((int)listsec1[0],model_id), grid_id, fdats, prods, levelstmp,seqno); if(strlen(filename) < 253) { strcpy(ident,filename); strncat(ident," !",2); strncat(ident,prodtmp,253-strlen(filename)); } else { strncpy(ident,filename,255); ident[255] = '\0'; } return; }
static void bnd_mzcn ( shp_record *onerec, char *header, char *subhdr, char *hdrnam, float *cenlat, float *cenlon, int *iret ) /************************************************************************ * bnd_mzcn * * * * This function generates the marine bound header and sub-header lines * * * * bnd_mzcn ( onerec, header, subhdr, hdrnam, cenlat, cenlon, iret ) * * * * Input parameters: * * *onerec shp_record One shape record * * * * Output parameters: * * *header char Bound header line * * *subhdr char Bound sub-header line * * *hdrnam char Bound header name * * *cenlat float Center latitude * * *cenlon float Center longitude * * *iret int Return code * * 0 = Normal * * 1 = Incomplete record * ** * * Log: * * R. Tian/SAIC 3/04 Initial coding * ***********************************************************************/ { char ctynam[25], cwanam[10], stabbr[3]; int ifips, izone, istno, iclat, iclon, nparts; float shplat, shplon; int i, pos, len, ier; /*---------------------------------------------------------------------*/ *iret = 0; nparts = onerec->numprt; for ( i = 0; i < onerec->numfld; i++ ) { if ( strncmp ( onerec->fields[i].name, "COUNTYNAME", strlen("COUNTYNAME") ) == 0 ) { strcpy ( ctynam, onerec->fields[i].data ); cst_lstr ( ctynam, &len, &ier ); ctynam[len] = '\0'; cst_rspc ( ctynam, &ier ); /* * Remove "Lower_Keys_in_" from county name */ cst_rmst ( ctynam, "Lower_Keys_in_", &pos, ctynam, &ier ); /* * Remove "Outer_Banks_" from county name */ cst_rmst ( ctynam, "Outer_Banks_", &pos, ctynam, &ier ); /* * Remove "Mainland_" from county name */ cst_rmst ( ctynam, "Mainland_", &pos, ctynam, &ier ); } else if ( strncmp ( onerec->fields[i].name, "FIPS", strlen("FIPS") ) == 0 ) { izone = ifips = atoi ( onerec->fields[i].data ); } else if ( strncmp ( onerec->fields[i].name, "CWA", strlen ( "CWA" ) ) == 0 ) { strcpy ( cwanam, onerec->fields[i].data ); cst_lstr ( cwanam, &len, &ier ); cwanam[len] = '\0'; } else if ( strncmp ( onerec->fields[i].name, "ID", strlen("ID") ) == 0 ) { strcpy ( ctynam, onerec->fields[i].data ); strncpy ( stabbr, onerec->fields[i].data, 2 ); stabbr[2] = '\0'; izone = atoi ( onerec->fields[i].data + 3 ); for ( istno = 0; istno < NUMSTNO; istno++ ) { if ( strncmp ( stateno[istno], stabbr, 2 ) == 0 ) { break; } } ifips = istno * 10000 + izone * 10; } else if ( strncmp ( onerec->fields[i].name, "WFO", strlen ( "WFO" ) ) == 0 ) { strcpy ( cwanam, onerec->fields[i].data ); } else if ( strncmp ( onerec->fields[i].name, "LAT", strlen("LAT") ) == 0 ) { shplat = atof ( onerec->fields[i].data ); } else if ( strncmp ( onerec->fields[i].name, "LON", strlen("LON") ) == 0 ) { shplon = atof ( onerec->fields[i].data ); } } if ( ERMISS ( onerec->cenlat ) || ERMISS ( onerec->cenlon ) ) { iclat = (int)(ROUNDUP(shplat)*100.); iclon = (int)(ROUNDUP(shplon)*100.); *cenlat = shplat; *cenlon = shplon; } else { iclat = (int)(ROUNDUP(onerec->cenlat)*100.); iclon = (int)(ROUNDUP(onerec->cenlon)*100.); *cenlat = onerec->cenlat; *cenlon = onerec->cenlon; } sprintf ( header, "B%5.5d %-32.32s %5d %6d %3d %s", izone, ctynam, iclat, iclon, nparts, cwanam ); sprintf ( subhdr, "<FIPS>%d", ifips ); sprintf ( hdrnam, "%s", ctynam ); }
static void bnd_cnty ( shp_record *onerec, char *header, char *subhdr, char *hdrnam, float *cenlat, float *cenlon, int *iret ) /************************************************************************ * bnd_cnty * * * * This function generates the county bound header and sub-header lines * * * * bnd_cnty ( onerec, header, subhdr, hdrnam, cenlat, cenlon, iret ) * * * * Input parameters: * * *onerec shp_record One shape record * * * * Output parameters: * * *header char Bound header line * * *subhdr char Bound sub-header line * * *hdrnam char Bound header name * * *cenlat float Center latitude * * *cenlon float Center longitude * * *iret int Return code * * 0 = Normal * * 1 = Incomplete record * ** * * Log: * * R. Tian/SAIC 3/04 Initial coding * ***********************************************************************/ { char ctynam[25], cwanam[10], fearea[3], tmzone[3], stabbr[3]; int ifips, iclat, iclon, nparts; float shplat, shplon; int ifld, pos, len, ier; /*---------------------------------------------------------------------*/ *iret = 0; nparts = onerec->numprt; for ( ifld = 0; ifld < onerec->numfld; ifld++ ) { if ( strncmp ( onerec->fields[ifld].name, "COUNTYNAME", strlen("COUNTYNAME") ) == 0 ) { strcpy ( ctynam, onerec->fields[ifld].data ); cst_lstr ( ctynam, &len, &ier ); ctynam[len] = '\0'; cst_rspc ( ctynam, &ier ); /* * Remove "Lower_Keys_in_" from county name */ cst_rmst ( ctynam, "Lower_Keys_in_", &pos, ctynam, &ier ); /* * Remove "Outer_Banks_" from county name */ cst_rmst ( ctynam, "Outer_Banks_", &pos, ctynam, &ier ); /* * Remove "Mainland_" from county name */ cst_rmst ( ctynam, "Mainland_", &pos, ctynam, &ier ); } else if ( strncmp ( onerec->fields[ifld].name, "FIPS", strlen("FIPS") ) == 0 ) { ifips = atoi ( onerec->fields[ifld].data ); } else if ( strncmp ( onerec->fields[ifld].name, "CWA", strlen ( "CWA" ) ) == 0 ) { strcpy ( cwanam, onerec->fields[ifld].data ); cst_lstr ( cwanam, &len, &ier ); cwanam[len] = '\0'; } else if ( strncmp ( onerec->fields[ifld].name, "FE_AREA", strlen ( "FE_AREA" ) ) == 0 ) { strcpy ( fearea, onerec->fields[ifld].data ); } else if ( strncmp ( onerec->fields[ifld].name, "TIME_ZONE", strlen ( "TIME_ZONE" ) ) == 0 ) { strcpy ( tmzone, onerec->fields[ifld].data ); } else if ( strncmp ( onerec->fields[ifld].name, "STATE", strlen ( "STATE" ) ) == 0 ) { strcpy ( stabbr, onerec->fields[ifld].data ); } else if ( strncmp ( onerec->fields[ifld].name, "LAT", strlen("LAT") ) == 0 ) { shplat = atof ( onerec->fields[ifld].data ); } else if ( strncmp ( onerec->fields[ifld].name, "LON", strlen("LON") ) == 0 ) { shplon = atof ( onerec->fields[ifld].data ); } } if ( strlen ( ctynam ) == (size_t)0 || strlen ( stabbr ) == (size_t)0 ) { *iret = 1; return; } if ( ERMISS ( onerec->cenlat ) || ERMISS ( onerec->cenlon ) ) { iclat = (int)(ROUNDUP(shplat)*100.); iclon = (int)(ROUNDUP(shplon)*100.); *cenlat = shplat; *cenlon = shplon; } else { iclat = (int)(ROUNDUP(onerec->cenlat)*100.); iclon = (int)(ROUNDUP(onerec->cenlon)*100.); *cenlat = onerec->cenlat; *cenlon = onerec->cenlon; } sprintf ( header, "B%5.5d %-32.32s %5d %6d %3d %s", ifips, ctynam, iclat, iclon, nparts, cwanam ); sprintf ( subhdr, "<FIPS>%d<STATE>%s<TIME_ZONE>%s<FE_AREA>%s", ifips, stabbr, tmzone, fearea ); sprintf ( hdrnam, "%s", ctynam ); }
static void tbl_mzcn ( shp_record *shprec, int numrec, int *iret ) /************************************************************************ * tbl_mzcn * * * * This function creates the combined county and marine station tables. * * * * tbl_mzcn ( shprec, numrec, iret ) * * * * Input parameters: * * *shprec shp_record Shape record list * * numrec int Total number of records * * * * Output parameters: * * *iret int Return code * * 0 = Normal * ** * * Log: * * R. Tian/SAIC 3/04 Initial coding * * S. Jacobs/NCEP 3/11 Changed header keys for determining * * the type of file - county or marine * * X.Guo/CWS 9/11 Increased fulname size and chnaged * * SHAPE_LENG to COUNTYNAME * ***********************************************************************/ { shp_record *currec; /* * The array size is from the Costal Marine Zones and AWIPS Counties * attributes specification. */ char fulnam[500], shrnam[33], cwanam[10], stabbr[3]; int ifips, istno, izone, ilat, ilon; int irec, jfld, kfld, pos, len, ier; char *stntbl = MZCNTYTBL, *namtbl = MZCNTYNAMTBL; float shplat, shplon; FILE *tblfp, *namfp; /*---------------------------------------------------------------------*/ *iret = 0; tblfp = cfl_wopn ( stntbl, &ier ); if ( ier != 0 ) { fprintf ( stderr, "File %s open failed.\n", stntbl ); exit ( -1 ); } namfp = cfl_wopn ( namtbl, &ier ); if ( ier != 0 ) { fprintf ( stderr, "File %s open failed.\n", namtbl ); exit ( -1 ); } for ( currec = shprec, irec = 0; irec < numrec; irec++, currec = currec->nxtrec ) { for ( jfld = 0; jfld < currec->numfld; jfld++ ) { if ( strncmp ( currec->fields[jfld].name, "COUNTYNAME", strlen("COUNTYNAME") ) == 0 ) { /* * County. */ for ( kfld = 0; kfld < currec->numfld; kfld++ ) { if ( strncmp ( currec->fields[kfld].name, "COUNTYNAME", strlen("COUNTYNAME") ) == 0 ) { strcpy ( fulnam, currec->fields[kfld].data ); cst_lstr ( fulnam, &len, &ier ); fulnam[len] = '\0'; cst_rspc ( fulnam, &ier ); abbreviate ( fulnam, 32, shrnam, &ier ); /* * Remove "City_of_" from county name */ cst_rmst ( shrnam, "City_of_", &pos, shrnam, &ier ); /* * Remove "Lower_Keys_in_" from county name */ cst_rmst ( shrnam, "Lower_Keys_in_", &pos, shrnam, &ier ); /* * Remove "Outer_Banks_" from county name */ cst_rmst ( shrnam, "Outer_Banks_", &pos, shrnam, &ier ); /* * Remove "Mainland_" from county name */ cst_rmst ( shrnam, "Mainland_", &pos, shrnam, &ier ); } else if ( strncmp ( currec->fields[kfld].name, "STATE", strlen ( "STATE" ) ) == 0 ) { strcpy ( stabbr, currec->fields[kfld].data ); } else if ( strncmp ( currec->fields[kfld].name, "CWA", strlen ( "CWA" ) ) == 0 ) { strcpy ( cwanam, currec->fields[kfld].data ); cst_lstr ( cwanam, &len, &ier ); cwanam[len] = '\0'; } else if ( strncmp ( currec->fields[kfld].name, "FIPS", strlen("FIPS") ) == 0 ) { ifips = atoi ( currec->fields[kfld].data ); } else if ( strncmp ( currec->fields[kfld].name, "LAT", strlen("LAT") ) == 0 ) { shplat = atof ( currec->fields[kfld].data ); } else if ( strncmp ( currec->fields[kfld].name, "LON", strlen("LON") ) == 0 ) { shplon = atof ( currec->fields[kfld].data ); } } if ( strlen ( shrnam ) == (size_t)0 || strlen ( stabbr ) == (size_t)0 ) { continue; } if ( ERMISS ( currec->cenlat ) || ERMISS ( currec->cenlon ) ) { ilat = (int)(ROUNDUP(shplat)*100.); ilon = (int)(ROUNDUP(shplon)*100.); } else { ilat = (int)(ROUNDUP(currec->cenlat)*100.); ilon = (int)(ROUNDUP(currec->cenlon)*100.); } fprintf ( tblfp, "%2.2sC%3.3d %6d %-32.32s %2.2s US %5d %6d %5d %2d %-3.3s\n", stabbr, ifips%1000, ifips, shrnam, stabbr, ilat, ilon, 0, 0, cwanam ); } else if ( strncmp ( currec->fields[jfld].name, "NAME", strlen("NAME") ) == 0 ) { /* * Marine. */ for ( kfld = 0; kfld < currec->numfld; kfld++ ) { if ( strncmp ( currec->fields[kfld].name, "ID", strlen("ID") ) == 0 ) { strcpy ( shrnam, currec->fields[kfld].data ); strncpy ( stabbr, currec->fields[kfld].data, 2 ); stabbr[2] = '\0'; izone = atoi ( currec->fields[kfld].data + 3 ); for ( istno = 0; istno < NUMSTNO; istno++ ) { if ( strncmp ( stateno[istno], stabbr, 2 ) == 0 ) { break; } } ifips = istno * 10000 + izone * 10; } else if ( strncmp ( currec->fields[kfld].name, "WFO", strlen ( "WFO" ) ) == 0 ) { strcpy ( cwanam, currec->fields[kfld].data ); } else if ( strncmp ( currec->fields[kfld].name, "NAME", strlen ( "NAME" ) ) == 0 ) { strcpy ( fulnam, currec->fields[kfld].data ); cst_lstr ( fulnam, &len, &ier ); fulnam[len] = '\0'; cst_rspc ( fulnam, &ier ); } else if ( strncmp ( currec->fields[kfld].name, "LAT", strlen("LAT") ) == 0 ) { shplat = atof ( currec->fields[kfld].data ); } else if ( strncmp ( currec->fields[kfld].name, "LON", strlen("LON") ) == 0 ) { shplon = atof ( currec->fields[kfld].data ); } } if ( ERMISS ( currec->cenlat ) || ERMISS ( currec->cenlon ) ) { ilat = (int)(ROUNDUP(shplat)*100.); ilon = (int)(ROUNDUP(shplon)*100.); } else { ilat = (int)(ROUNDUP(currec->cenlat)*100.); ilon = (int)(ROUNDUP(currec->cenlon)*100.); } fprintf ( tblfp, "%6.6s %6d %-32.32s %2.2s US %5d %6d %5d %2d %-3.3s\n", shrnam, ifips, shrnam, stabbr, ilat, ilon, 0, 0, cwanam ); fprintf (namfp, "%s %s\n", shrnam, fulnam ); } } } cfl_clos ( tblfp, &ier ); cfl_clos ( namfp, &ier ); }
static void tbl_cnty ( shp_record *shprec, int numrec, int *iret ) /************************************************************************ * tbl_cnty * * * * This function creates the county station table files. * * * * tbl_cnty ( shprec, numrec, iret ) * * * * Input parameters: * * *shprec shp_record Shape record list * * numrec int Total number of records * * * * Output parameters: * * *iret int Return code * * 0 = Normal * ** * * Log: * * R. Tian/SAIC 3/04 Initial coding * ***********************************************************************/ { shp_record *currec; char ctynam[25], shrnam[33], cwanam[10], stabbr[3]; int ifips, ilat, ilon; int irec, jfld, pos, len, ier; float shplat, shplon; char *ctytbl = COUNTYTBL, *namtbl = COUNTYNAMTBL; FILE *tblfp, *namfp; /*---------------------------------------------------------------------*/ *iret = 0; tblfp = cfl_wopn ( ctytbl, &ier ); if ( ier != 0 ) { fprintf ( stderr, "File %s open failed.\n", ctytbl ); exit ( -1 ); } namfp = cfl_wopn ( namtbl, &ier ); if ( ier != 0 ) { fprintf ( stderr, "File %s open failed.\n", namtbl ); exit ( -1 ); } for ( currec = shprec, irec = 0; irec < numrec; irec++, currec = currec->nxtrec ) { for ( jfld = 0; jfld < currec->numfld; jfld++ ) { if ( strncmp ( currec->fields[jfld].name, "COUNTYNAME", strlen("COUNTYNAME") ) == 0 ) { strcpy ( ctynam, currec->fields[jfld].data ); cst_lstr ( ctynam, &len, &ier ); ctynam[len] = '\0'; cst_rspc ( ctynam, &ier ); abbreviate ( ctynam, 32, shrnam, &ier ); /* * Remove "City_of_" from county name */ cst_rmst ( shrnam, "City_of_", &pos, shrnam, &ier ); /* * Remove "Lower_Keys_in_" from county name */ cst_rmst ( shrnam, "Lower_Keys_in_", &pos, shrnam, &ier ); /* * Remove "Outer_Banks_" from county name */ cst_rmst ( shrnam, "Outer_Banks_", &pos, shrnam, &ier ); /* * Remove "Mainland_" from county name */ cst_rmst ( shrnam, "Mainland_", &pos, shrnam, &ier ); } else if ( strncmp ( currec->fields[jfld].name, "STATE", strlen ( "STATE" ) ) == 0 ) { strcpy ( stabbr, currec->fields[jfld].data ); } else if ( strncmp ( currec->fields[jfld].name, "CWA", strlen ( "CWA" ) ) == 0 ) { strcpy ( cwanam, currec->fields[jfld].data ); cst_lstr ( cwanam, &len, &ier ); cwanam[len] = '\0'; } else if ( strncmp ( currec->fields[jfld].name, "FIPS", strlen("FIPS") ) == 0 ) { ifips = atoi ( currec->fields[jfld].data ); } else if ( strncmp ( currec->fields[jfld].name, "LAT", strlen("LAT") ) == 0 ) { shplat = atof ( currec->fields[jfld].data ); } else if ( strncmp ( currec->fields[jfld].name, "LON", strlen("LON") ) == 0 ) { shplon = atof ( currec->fields[jfld].data ); } } if ( strlen ( shrnam ) == (size_t)0 || strlen ( stabbr ) == (size_t)0 ) { continue; } if ( ERMISS ( currec->cenlat ) || ERMISS ( currec->cenlon ) ) { ilat = (int)(ROUNDUP(shplat)*100.); ilon = (int)(ROUNDUP(shplon)*100.); } else { ilat = (int)(ROUNDUP(currec->cenlat)*100.); ilon = (int)(ROUNDUP(currec->cenlon)*100.); } fprintf ( tblfp, "%2.2sC%3.3d %6d %-32.32s %2.2s US %5d %6d %5d %2d %-3.3s\n", stabbr, ifips%1000, ifips, shrnam, stabbr, ilat, ilon, 0, 0, cwanam ); fprintf ( namfp, "%-8.8s %6d %-32.32s %2.2s US %5d %6d %5d %2d %-3.3s\n", shrnam, ifips, shrnam, stabbr, ilat, ilon, 0, 0, cwanam ); } cfl_clos ( tblfp, &ier ); cfl_clos ( namfp, &ier ); }
void vfwsel ( char strin[], int *iret ) /************************************************************************ * vfwsel * * * * This program opens, creates and closes the Weather Watch SEL text * * product file. * * * * vfwsel ( strin, iret ) * * * * Input parameters: * * strin[] char Continuing Watches String * * * * Output parameters: * * *iret int Return Code * * * ** * * Log: * * A. Hardy/GSC 8/99 Created * * A. Hardy/GSC 9/99 Changed truncation method for lats/lons * * M. Li/GSC 10/99 Added two more arguments to clo_cmpwds * * M. Li/GSC 10/99 Modified output format * * A. Hardy/GSC 11/99 Added ongoing/replacement statements; * * Cleaned up line lengths * * A. Hardy/GSC 2/00 Extracted from SPCTXT * * A. Hardy/GSC 3/00 Removed \r\n after lightning.Fixed lens.* * A. Hardy/GSC 3/00 Used cst_wrap to even line lengths * * A. Hardy/GSC 5/00 Changed cfl_aopn to cfl_wopn; Use * * AWIPS/WMO header ids.;removed 'NNNN' * * A. Hardy/GSC 5/00 Added check for continue watch nos. * * A. Hardy/GSC 10/00 Added ck for '0' dist. anchor points * * A. Hardy/GSC 12/00 Removed '&' from iret and ti_dayw * * A. Hardy/GSC 5/01 Removed parameter 'vmin' from vfgtod * * A. Hardy/SAIC 10/01 Added check for old/new WMO header flag * * A. Hardy/SAIC 12/01 Removed unused varible 'i' * * R. Tian/SAIC 06/02 Modified to meet the SPC requirement * * R. Tian/SAIC 06/02 Added 'NWS' before 'STORM PRED...' * * R. Tian/SAIC 04/03 Corrected if(iret == 0) syntax error * * A. Hardy/NCEP 4/03 Fixed replacement time;removed '...' * * fixed line length with 'EFFECTIVE' line * * G. Grosshans/SPC 5/03 Add 'OCCASIONALLY' statement;fixed typo * * A. Hardy/NCEP 5/03 Change hail size to string for decimals * * A. Hardy/NCEP 11/03 Modified to use wbc/utl libraries; and * * to check if 'TEST' watch * * G. Grosshans/SPC 3/04 Removed extra EOLs before and after * * OTHER WATCH section * * A. Hardy/NCEP 10/04 Corrected replace. wtch ck 1000->10000 * * G. Grosshans/SPC 10/04 Added ADD_WATCH_APPROX check * * A. Hardy/NCEP 3/05 Added irmzn to wbc_dsts call seq. * * G. Grosshans/SPC 10/05 Added LATLON_SAW_FORMAT tag to turn * * off lat-lon info at bottom of product. * * T. Piper/SAIC 12/05 Updated for cst_wrap CSC * * J. Wu/SAIC 04/06 Added parameter in cst_wrap * * H. Zeng/SAIC 06/06 Removed MIDNIGHT processing(fix wch#281)* ***********************************************************************/ { FILE *ifpsel; char ifname[256], chmon[4], chdwk[4], iampm[3], vampm[3]; char blank[2]={' '}, words1[16], words2[16], *arrch; char cname1[32], cname2[32], eampm[3]; char chnum[5], lclzn[4], avnstr[500], constr[500], perstr[180]; char tmpsel[500], holdsel[200], selstr[100], newname[132], efen[12], efst[12], stzstr[500], sttstr[500], hdlstr[180], stlst[256], hailstr[4]; char prefs_tag[20]; int ier, time, datwk, inewtm, vnewtm, enewtm; int itmarr[5], iarr[5],etime[5], earr[5], vtime[5], varr[5]; int j, ipos, iin, iout, ireplace, newnum, irplen; int len, leng, lenc, lenp, lena, len1, len2, irmzn; Boolean useln; /*-------------------------------------------------------------------*/ ier = 0; inewtm = 0; vnewtm = 0; enewtm = 0; ireplace = 0; /* * Create output file for appending. */ sprintf ( ifname, "WW%04d.SEL", spcinfo.wnum ); ifpsel = cfl_wopn ( ifname, &ier ); /* * Set up state zones and state name information. */ irmzn = 1; len1 = sizeof ( stzstr ); len2 = sizeof ( sttstr ); strcpy (stlst, spcinfo.states); wbc_dsts ( stlst, &len1, &irmzn, stzstr, sttstr, &ier ); spcinfo.sssnum = spcinfo.wnum % 10; fprintf ( ifpsel, "WWUS20 KWNS %02d%s\n", spcinfo.itime.day, spcinfo.itime.hour); fprintf( ifpsel, "SEL%d\n", spcinfo.sssnum); fprintf ( ifpsel, "%cSPC WW %02d%s\n", CHRS, spcinfo.itime.day, spcinfo.itime.hour); fprintf ( ifpsel, "%s-%02d%s-\n\n", stzstr, spcinfo.etime.day, spcinfo.etime.hour ); /* * Set up urgent section. */ hdlstr[0] = '\0'; len = sizeof ( hdlstr ); wbc_dhdl ( spcinfo.wtype, spcinfo.status, &(spcinfo.wnum), len, hdlstr, &ier ); strcat (hdlstr, EOL ); fprintf ( ifpsel, hdlstr ); /* * Getting all of the information to create the the time line string. */ time = atoi(spcinfo.itime.hour); itmarr[0] = spcinfo.itime.year; itmarr[1] = spcinfo.itime.month; itmarr[2] = spcinfo.itime.day; itmarr[3] = time / 100; itmarr[4] = time % 100; time = atoi(spcinfo.vtime.hour); vtime[0] = spcinfo.vtime.year; vtime[1] = spcinfo.vtime.month; vtime[2] = spcinfo.vtime.day; vtime[3] = time / 100; vtime[4] = time % 100; time = atoi(spcinfo.etime.hour); etime[0] = spcinfo.etime.year; etime[1] = spcinfo.etime.month; etime[2] = spcinfo.etime.day; etime[3] = time / 100; etime[4] = time % 100; strcpy ( lclzn, spcinfo.timzone ); utl_ivet ( lclzn, itmarr, vtime, etime, iarr, &inewtm, iampm, chmon, chdwk, varr, &vnewtm, vampm, earr, &enewtm, eampm, &datwk, &ier ); fprintf ( ifpsel, "%d%02d %s %s %s %s %d %d\n\n", inewtm, iarr[4], iampm, spcinfo.timzone, chdwk, chmon, iarr[2], iarr[0]); /* * Set up general area description section. * Check status of watch. */ if ( strcmp(spcinfo.status, "TEST") == 0 ) { fprintf ( ifpsel, "THE NWS STORM PREDICTION CENTER HAS ISSUED "); fprintf ( ifpsel, "A...TEST...\n "); } else { fprintf ( ifpsel, "THE NWS STORM PREDICTION CENTER HAS ISSUED A\n"); } fprintf ( ifpsel, "%s WATCH FOR PORTIONS OF \n", spcinfo.wtype ); fprintf ( ifpsel, sttstr); fprintf ( ifpsel, "\n\n"); /* * Get the general time of day string. */ leng = sizeof ( spcinfo.genday ); utl_gtod ( vnewtm, enewtm, earr[4], vampm, eampm, datwk, leng, spcinfo.genday, &ier); /* * Set up effective time of day string. */ len1 = sizeof ( efst ); len2 = sizeof ( efen ); wbc_defl ( vnewtm, varr[4], vampm, enewtm, earr[4], eampm, spcinfo.timzone, len1, len2, efst, efen, &ier ); len = LINE_LEN; tmpsel[0] = '\0'; sprintf ( tmpsel, "EFFECTIVE THIS%s FROM %s UNTIL %s.", spcinfo.genday, efst, efen ); strcat (tmpsel, EOL ); strcat (tmpsel, EOL ); len = LINE_LEN; cst_wrap ( tmpsel, blank, &len, EOL, (char *)NULL, tmpsel, &ier ); fprintf ( ifpsel, tmpsel); /* * Add some phases if the watch is a 'PDS' */ if ( strcmp ( spcinfo.pdsn,"PDS" ) == 0 ) fprintf ( ifpsel, "...THIS IS A PARTICULARLY DANGEROUS SITUATION...\n\n"); /* * Change hail size to string. */ if ( ( (int) (spcinfo.hailsz * 10.0F) % 2) == 0 ) { sprintf( hailstr, "%1.*f", 0, spcinfo.hailsz ); } else { sprintf( hailstr, "%3.*f", 1, spcinfo.hailsz ); } /* * Set up hail, wind gusts and lightning section. */ if ( strcmp(spcinfo.wtype,"TORNADO") == 0 ) { if ( strcmp(spcinfo.pdsn, "PDS") == 0 ) { tmpsel[0] = '\0'; holdsel[0] = '\0'; sprintf ( tmpsel, "DESTRUCTIVE TORNADOES..."); if ( G_DIFF(spcinfo.hailsz, 0.0F) ){ sprintf ( holdsel, "THUNDERSTORM WIND GUSTS TO %d MPH", spcinfo.maxmph ); strcat(tmpsel, holdsel); } else if ( (spcinfo.hailsz > 0.0F ) && (spcinfo.hailsz <= 1.0F ) ) { sprintf ( holdsel, "LARGE HAIL TO %s INCH ", hailstr ); strcat(tmpsel, holdsel); sprintf ( holdsel, "IN DIAMETER... THUNDERSTORM WIND GUSTS TO %d MPH", spcinfo.maxmph ); strcat(tmpsel, holdsel); } else if ( spcinfo.hailsz > 1.0F ){ sprintf ( holdsel, "LARGE HAIL TO %s INCHES ", hailstr ); strcat(tmpsel, holdsel); sprintf ( holdsel, "IN DIAMETER... THUNDERSTORM WIND GUSTS TO %d MPH", spcinfo.maxmph ); strcat(tmpsel, holdsel); } sprintf ( holdsel, "...AND DANGEROUS LIGHTNING ARE POSSIBLE IN THESE AREAS."); strcat(tmpsel, holdsel); strcat (tmpsel, EOL ); strcat (tmpsel, EOL ); len = LINE_LEN; cst_wrap ( tmpsel, blank, &len, EOL, (char *)NULL, tmpsel, &ier ); fprintf ( ifpsel, tmpsel); } else { tmpsel[0] = '\0'; holdsel[0] = '\0'; sprintf ( tmpsel, "TORNADOES..."); if ( G_DIFF(spcinfo.hailsz,0.0F) ) { sprintf ( holdsel, "THUNDERSTORM WIND GUSTS TO %d MPH...AND DANGEROUS LIGHTNING ", spcinfo.maxmph); strcat(tmpsel, holdsel); } else if ( ( spcinfo.hailsz > 0.0F ) && ( spcinfo.hailsz <= 1.0F ) ) { sprintf ( holdsel, "HAIL TO %s INCH IN DIAMETER...THUNDERSTORM WIND ", hailstr); strcat(tmpsel, holdsel); sprintf ( holdsel, "GUSTS TO %d MPH...AND DANGEROUS LIGHTNING ", spcinfo.maxmph); strcat(tmpsel, holdsel); } else { sprintf ( holdsel, "HAIL TO %s INCHES IN DIAMETER...THUNDERSTORM WIND ", hailstr); strcat(tmpsel, holdsel); sprintf ( holdsel, "GUSTS TO %d MPH...AND DANGEROUS LIGHTNING ", spcinfo.maxmph); strcat(tmpsel, holdsel); } sprintf ( holdsel, "ARE POSSIBLE IN THESE AREAS."); strcat(tmpsel, holdsel); strcat (tmpsel, EOL ); strcat (tmpsel, EOL ); len = LINE_LEN; cst_wrap ( tmpsel, blank, &len, EOL, (char *)NULL, tmpsel, &ier ); fprintf ( ifpsel, tmpsel); } } if ( strcmp(spcinfo.wtype,"SEVERE THUNDERSTORM") == 0 ) { if ( strcmp(spcinfo.pdsn, "PDS") == 0 ) { tmpsel[0] = '\0'; holdsel[0] = '\0'; sprintf ( tmpsel, "EXTREMELY DAMAGING THUNDERSTORM WIND GUSTS TO %d ", spcinfo.maxmph ); if ( ( spcinfo.hailsz > 0.0F ) && ( spcinfo.hailsz <= 1.0F ) ) { sprintf ( holdsel, "MPH...LARGE HAIL TO %s INCH IN DIAMETER...", hailstr); strcat(tmpsel, holdsel); } if ( spcinfo.hailsz > 1.0F ) { sprintf ( holdsel, "MPH...LARGE HAIL TO %s INCHES IN DIAMETER...", hailstr); strcat(tmpsel, holdsel); } sprintf ( holdsel, "AND DANGEROUS LIGHTNING ARE POSSIBLE IN THESE AREAS."); strcat(tmpsel, holdsel); strcat (tmpsel, EOL ); strcat (tmpsel, EOL ); len = LINE_LEN; cst_wrap ( tmpsel, blank, &len, EOL, (char *)NULL, tmpsel, &ier ); fprintf ( ifpsel, tmpsel); } else { tmpsel[0] = '\0'; holdsel[0] = '\0'; if ( G_DIFF(spcinfo.hailsz,0.0F) ) { sprintf ( tmpsel, "THUNDERSTORM WIND GUSTS TO %d MPH...",spcinfo.maxmph); strcat(tmpsel, holdsel); } else if ( ( spcinfo.hailsz > 0.0F ) && (spcinfo.hailsz <= 1.0F ) ) { sprintf ( holdsel, "HAIL TO %s INCH IN DIAMETER...THUNDERSTORM WIND ", hailstr); strcat(tmpsel, holdsel); sprintf ( holdsel, "GUSTS TO %d MPH...", spcinfo.maxmph); strcat(tmpsel, holdsel); } else if ( spcinfo.hailsz > 1.0F ) { sprintf ( holdsel, "HAIL TO %s INCHES IN DIAMETER...THUNDERSTORM WIND ", hailstr); strcat(tmpsel, holdsel); sprintf ( holdsel, "GUSTS TO %d MPH...", spcinfo.maxmph); strcat(tmpsel, holdsel); } sprintf ( holdsel, "AND DANGEROUS LIGHTNING ARE POSSIBLE IN THESE AREAS."); strcat(tmpsel, holdsel); strcat (tmpsel, EOL ); strcat (tmpsel, EOL ); len = LINE_LEN; cst_wrap ( tmpsel, blank, &len, EOL, (char *)NULL, tmpsel, &ier ); fprintf ( ifpsel, tmpsel); } } /* * Set watch area section. */ clo_cmpwds ( spcinfo.ancrpt.dirct1, &iin, words1, &iout, &ier ); clo_cmpwds ( spcinfo.ancrpt.dirct2, &iin, words2, &iout, &ier ); utl_gname ( spcinfo.ancrpt.stn1, spcinfo.ancrpt.stnnam1, spcinfo.ancrpt.stateid1, &ier ); utl_gname ( spcinfo.ancrpt.stn2, spcinfo.ancrpt.stnnam2, spcinfo.ancrpt.stateid2, &ier ); tb_idst ( spcinfo.ancrpt.stateid1, spcinfo.ancrpt.statnm1, &ier, strlen ( spcinfo.ancrpt.stateid1), sizeof(spcinfo.ancrpt.statnm1)); tb_idst ( spcinfo.ancrpt.stateid2, spcinfo.ancrpt.statnm2, &ier, strlen ( spcinfo.ancrpt.stateid2), sizeof(spcinfo.ancrpt.statnm2)); cst_rnan ( spcinfo.ancrpt.stnnam1, cname1, &ier ); cst_rmst ( cname1, ".", &ipos, cname1, &ier ); cst_rnan ( spcinfo.ancrpt.stnnam2, cname2, &ier ); cst_rmst ( cname2, ".", &ipos, cname2, &ier ); /* * Set up the watch area lines. */ tmpsel[0] = '\0'; holdsel[0] = '\0'; /* * Check status of watch and also check if the APPROXIMATE verbage * needs to be included in the text. */ strcpy (prefs_tag, "ADD_WATCH_APPROX"); ctb_pfbool (prefs_tag, &useln, &ier ); if ( useln == TRUE ) { if (strcmp (spcinfo.status, "TEST") == 0 ) { sprintf ( tmpsel, "THE TEST %s WATCH AREA IS APPROXIMATELY ALONG AND %d STATUTE MILES ", spcinfo.wtype, spcinfo.ancatt.dist); } else { sprintf ( tmpsel, "THE %s WATCH AREA IS APPROXIMATELY ALONG AND %d STATUTE MILES ", spcinfo.wtype, spcinfo.ancatt.dist); } } else { if (strcmp (spcinfo.status, "TEST") == 0 ) { sprintf ( tmpsel, "THE TEST %s WATCH AREA IS ALONG AND %d STATUTE MILES ", spcinfo.wtype, spcinfo.ancatt.dist); } else { sprintf ( tmpsel, "THE %s WATCH AREA IS ALONG AND %d STATUTE MILES ", spcinfo.wtype, spcinfo.ancatt.dist); } } if ( (spcinfo.ancrpt.dist1 > 0 ) && ( spcinfo.ancrpt.dist2 > 0 ) ){ sprintf ( holdsel, "%s OF A LINE FROM %d MILES %s OF %s %s", spcinfo.ancatt.dirc, spcinfo.ancrpt.dist1, words1, cname1, spcinfo.ancrpt.statnm1); strcat(tmpsel, holdsel); sprintf ( holdsel, " TO %d MILES %s OF %s %s.", spcinfo.ancrpt.dist2, words2, cname2, spcinfo.ancrpt.statnm2); } else if ( (spcinfo.ancrpt.dist1 <= 0 ) && ( spcinfo.ancrpt.dist2 > 0 ) ){ sprintf ( holdsel, "%s OF A LINE FROM %s %s", spcinfo.ancatt.dirc, cname1, spcinfo.ancrpt.statnm1); strcat(tmpsel, holdsel); sprintf ( holdsel, " TO %d MILES %s OF %s %s.", spcinfo.ancrpt.dist2, words2, cname2, spcinfo.ancrpt.statnm2); } else if ( (spcinfo.ancrpt.dist1 > 0 ) && ( spcinfo.ancrpt.dist2 <= 0 ) ){ sprintf ( holdsel, "%s OF A LINE FROM %d MILES %s OF %s %s", spcinfo.ancatt.dirc, spcinfo.ancrpt.dist1, words1, cname1, spcinfo.ancrpt.statnm1); strcat(tmpsel, holdsel); sprintf ( holdsel, " TO %s %s.", cname2, spcinfo.ancrpt.statnm2); } else if ( (spcinfo.ancrpt.dist1 <= 0 ) && ( spcinfo.ancrpt.dist2 <= 0 ) ){ sprintf ( holdsel, "%s OF A LINE FROM %s %s", spcinfo.ancatt.dirc, cname1, spcinfo.ancrpt.statnm1); strcat(tmpsel, holdsel); sprintf ( holdsel, " TO %s %s.", cname2, spcinfo.ancrpt.statnm2); } strcat(tmpsel, holdsel); if ( useln == TRUE ) { sprintf (holdsel, " FOR A COMPLETE DEPICTION OF THE WATCH SEE THE "); strcat(tmpsel, holdsel); sprintf (holdsel, "ASSOCIATED WATCH OUTLINE UPDATE (WOUS64 KWNS WOU%d).", spcinfo.sssnum); strcat(tmpsel, holdsel); } strcat (tmpsel, EOL ); strcat (tmpsel, EOL ); len = LINE_LEN; cst_wrap ( tmpsel, blank, &len, EOL, (char *)NULL, tmpsel, &ier ); fprintf ( ifpsel, tmpsel); /* * Set up watch explanation section. */ tmpsel[0] = '\0'; lenc = sizeof ( constr ); lenp = sizeof ( perstr ); wbc_dcon ( spcinfo.wtype, lenc, lenp, constr, perstr, &ier ); strcat ( tmpsel, "REMEMBER..."); strcat ( tmpsel, constr ); strcat ( tmpsel, perstr ); if ( strcmp(spcinfo.wtype,"SEVERE THUNDERSTORM") == 0 ){ strcat ( tmpsel, " SEVERE THUNDERSTORMS CAN AND OCCASIONALLY DO "); strcat ( tmpsel, "PRODUCE TORNADOES."); } strcat (tmpsel, EOL ); len = LINE_LEN; cst_wrap ( tmpsel, blank, &len, EOL, (char *)NULL, tmpsel, &ier ); fprintf ( ifpsel, tmpsel); /* * Check for ongoing and replacement watches. */ tmpsel[0] = '\0'; holdsel[0] = '\0'; if ( strcmp ( spcinfo.replcnm[0], "NONE") != 0 ) { strcat (tmpsel, EOL); strcat ( tmpsel, "OTHER WATCH INFORMATION..."); /* * If there are replacement watches listed, retrieve the type * for each replacement watch. */ if ( strcmp ( spcinfo.replcnm[0], "NONE") != 0 ) { strcpy ( newname, "ww"); strcat ( newname, spcinfo.replcnm[0] ); strcat ( newname, ".txt" ); strcpy ( newinfo.file_info.filnam,newname); vfrptxt (newname, iret); if ( *iret == 0 ){ sprintf ( holdsel, "THIS %s WATCH REPLACES %s WATCH NUMBER %d.", spcinfo.wtype, newinfo.wtype, atoi(spcinfo.replcnm[0]) ); strcat (tmpsel, holdsel ); } } /* * If there are more that 1 replacement watches listed, * proceed with the loop. */ if ( spcinfo.wwrepnm >= 1 ){ for(j = 1; j <= spcinfo.wwrepnm; j++) { strcpy ( newname, "ww"); strcat ( newname, spcinfo.replcnm[j] ); strcat ( newname, ".txt" ); strcpy ( newinfo.file_info.filnam,newname); vfrptxt (newname, iret); if ( *iret == 0 ){ sprintf ( holdsel, "..%s WATCH NUMBER %d.", newinfo.wtype, atoi(spcinfo.replcnm[j]) ); strcat (tmpsel, holdsel ); } } } sprintf ( holdsel, " WATCH NUMBER "); strcat (tmpsel, holdsel ); for(j = 0; j <= spcinfo.wwrepnm; j++) { strcpy ( newname, "ww"); strcat ( newname, spcinfo.replcnm[j] ); strcat ( newname, ".txt" ); strcpy ( newinfo.file_info.filnam,newname); vfrptxt (newname, iret); if ( *iret == 0 ){ sprintf ( holdsel, "%d ", atoi(spcinfo.replcnm[j]) ) ; strcat (tmpsel, holdsel ); } } /* * Set cancellation time with the replacement watch's valid time. */ strcat ( tmpsel, "WILL NOT BE IN EFFECT AFTER " ); if ( (vnewtm == 12) && (varr[4] ==0) && (strcmp(vampm, "AM") == 0) ) { sprintf ( holdsel, "MIDNIGHT %s. ", spcinfo.timzone ); strcat (tmpsel, holdsel ); } else if ( (vnewtm == 12) && (varr[4] ==0) && (strcmp(vampm, "PM") == 0) ) { sprintf ( holdsel, "NOON %s. ", spcinfo.timzone ); strcat (tmpsel, holdsel ); } else { sprintf ( holdsel, "%d%02d %s %s. ", vnewtm, varr[4], vampm, spcinfo.timzone ); strcat (tmpsel, holdsel ); } ireplace = 1; } cst_lstr ( strin, &irplen, iret ); strcpy ( selstr, strin); if ( irplen > 0 ) { holdsel[0] = '\0'; if ( ireplace != 1 ) { strcat (tmpsel, EOL); strcat( tmpsel, "OTHER WATCH INFORMATION..."); } strcat ( tmpsel, "CONTINUE..."); arrch = strtok( selstr, " " ); while ( arrch != NULL ) { newnum = atoi(arrch); if ( (newnum > 0 ) && ( newnum < 10000 ) ) { strcat ( tmpsel,"WW "); cst_inch ( newnum, chnum, iret); strcat ( tmpsel, chnum); strcat ( tmpsel, "..."); } arrch = strtok( NULL," " ); } strcat (tmpsel, EOL); } if (( ireplace == 1 ) && ( irplen < 1 )) { strcat (tmpsel, EOL); } cst_wrap ( tmpsel, blank, &len, EOL, (char *)NULL, tmpsel, &ier ); fprintf ( ifpsel, tmpsel); /* * Check status of watch. */ if (strcmp (spcinfo.status, "TEST") == 0 ) { fprintf ( ifpsel, "\nDISCUSSION...THIS IS A TEST..."); fprintf ( ifpsel, "THIS IS A TEST...\n\n"); } else { fprintf ( ifpsel, "\nDISCUSSION...\n\n"); } /* * Create the aviation string. */ lena = sizeof ( avnstr ); wbc_davn ( spcinfo.wtype, &(spcinfo.hailsz), &(spcinfo.maxgust), &(spcinfo.maxtops), &(spcinfo.motion.deg), &(spcinfo.motion.speed), lena, avnstr, &ier ); strcat (avnstr, EOL ); strcat (avnstr, EOL ); strcat (avnstr, EOL ); len = LINE_LEN; cst_wrap ( avnstr, blank, &len, EOL, (char *)NULL, avnstr, &ier ); fprintf ( ifpsel, avnstr); /* * Print out forecaster's name. */ fprintf ( ifpsel, "...%s\n\n",spcinfo.frcstr); /* * Get the value for LATLON_SAW_FORMAT flag from the prefs.tbl * If FALSE then its before February 2006 and the less * precise lat-lon data is retained in the SEL. When this * is TRUE then more precise lat-lon data will be located * in the SAW product. */ strcpy (prefs_tag, "LATLON_SAW_FORMAT"); ctb_pfbool (prefs_tag, &useln, &ier ); if ( useln == FALSE ) { /* * Converting hundreths into minutes. */ utl_tomin ( &(spcinfo.wcpnt1.lat), &(spcinfo.wcpnt1.lon), &(spcinfo.wcpnt1.newlat), &(spcinfo.wcpnt1.newlon), iret ); utl_tomin ( &(spcinfo.wcpnt2.lat), &(spcinfo.wcpnt2.lon), &(spcinfo.wcpnt2.newlat), &(spcinfo.wcpnt2.newlon), iret ); utl_tomin ( &(spcinfo.wcpnt3.lat), &(spcinfo.wcpnt3.lon), &(spcinfo.wcpnt3.newlat), &(spcinfo.wcpnt3.newlon), iret ); utl_tomin ( &(spcinfo.wcpnt4.lat), &(spcinfo.wcpnt4.lon), &(spcinfo.wcpnt4.newlat), &(spcinfo.wcpnt4.newlon), iret ); /* * The statement below will truncate the minutes at the 10's position. * No rounding takes place. */ fprintf ( ifpsel, ";%d,%04d %d,%04d %d,%04d %d,%04d; \n\n", (int)(spcinfo.wcpnt1.newlat*10.0F), (int)(spcinfo.wcpnt1.newlon*10.0F), (int)(spcinfo.wcpnt2.newlat*10.0F), (int)(spcinfo.wcpnt2.newlon*10.0F), (int)(spcinfo.wcpnt3.newlat*10.0F), (int)(spcinfo.wcpnt3.newlon*10.0F), (int)(spcinfo.wcpnt4.newlat*10.0F), (int)(spcinfo.wcpnt4.newlon*10.0F)); } /* * Close output file. */ cfl_clos ( ifpsel, &ier ); }