void grdnav_init() { int ier, iret, nitm; char buf[255], subst[255], *cpos; FILE *fp; nav_list *q; if ( ( fp = cfl_tbop ( "grdnav.tbl", "grid", &ier) ) != NULL ) { while ( ier == 0 ) { cfl_trln ( fp, sizeof(buf), buf, &ier); if ( ( ier == 0 ) && ( ( q = (nav_list *)malloc( sizeof(nav_list) ) ) != NULL ) ) { cpos = cst_split( buf, ' ', sizeof(subst)-1, subst, &iret); if ( iret == 0 ) { cst_ncpy(q->id,subst,sizeof(q->id)-1, &iret); cst_ldsp(cpos, cpos, &nitm, &iret); } cpos = cst_split( cpos, ' ', sizeof(subst)-1, subst, &iret); if ( ( iret == 0 ) && ( cpos != NULL ) ) { iret = sscanf(subst,"%d",&(q->gnum)); cst_ldsp(cpos, cpos, &nitm, &iret); } else { free(q); continue; } cpos = cst_split( cpos, ' ', sizeof(subst)-1, subst, &iret); if ( ( iret == 0 ) && ( cpos != NULL ) ) { cst_ncpy(q->proj,subst,sizeof(q->proj)-1, &iret); cst_ldsp(cpos, cpos, &nitm, &iret); } else { free(q); continue; } iret = sscanf(cpos,"%f %f %f %f %f %f %f %d %d", &(q->angle[0]), &(q->angle[1]), &(q->angle[2]), &(q->llt), &(q->lln), &(q->ult), &(q->uln), &(q->kx), &(q->ky) ); if ( iret == 9 ) { q->next = nav_head; nav_head = q; } else { free(q); } } } } }
void cds_scal ( char *fname, int *iret ) /************************************************************************ * cds_scal * * * * This function sets the scaling factors for the objects. * * * * cds_scal ( fname, iret ) * * * * Input parameters: * * *fname char Scaling factor file name * * * * Output parameters: * * *iret int Return code * * 0 - successful * * -1 - file open error * * * ** * * Log: * * C. Lin/EAI 03/98 * * I. Durham/GSC 05/98 Changed underscore decl. to an include * * F. J. Yen/NCEP 05/98 Removed pip stroke * ***********************************************************************/ { int ier; char buffer[256], pname[64], ignore[20]; float val; FILE *fp; /*---------------------------------------------------------------------*/ *iret = 0; fp = (FILE *)cfl_tbop( fname, "pgen", &ier ); if ( fp == NULL || ier != 0 ) { *iret = -1; return; } while ( !feof(fp) ) { cfl_trln(fp, 256, buffer, &ier); if ( ier == 0 && strchr(buffer, '=') ) { sscanf(buffer, "%s %s %f", pname, ignore, &val ); if ( val <= SCALE_MIN || val > SCALE_MAX ) val = 1.0F; if ( strcmp(pname, "PIPSIZE") == 0 ) cdsPipSiz = val; else if ( strcmp(pname, "FRONTSTRENGTH") == 0 ) cdsFrntStrngth = val; else if ( strcmp(pname, "SYMWIDTH") == 0 ) cdsSymWdth = val; else if ( strcmp(pname, "SYMSIZE") == 0 ) cdsSymSiz = val; else if ( strcmp(pname, "WINDWIDTH") == 0 ) cdsWindWdth = val; else if ( strcmp(pname, "WINDSIZE") == 0 ) cdsWindSiz = val; else if ( strcmp(pname, "WINDHDSIZ") == 0 ) cdsWindHdsiz = val; else if ( strcmp(pname, "LINEWIDTH") == 0 ) cdsLineWdth = val; else if ( strcmp(pname, "SPLWIDTH") == 0 ) cdsSplWdth = val; else if ( strcmp(pname, "SPLSIZE") == 0 ) cdsSplSiz = val; else if ( strcmp(pname, "TEXTSIZE") == 0 ) cdsTxtSiz = val; else if ( strcmp(pname, "TEXTWIDTH") == 0 ) cdsTxtWdth = val; else if ( strcmp(pname, "SPTXTSIZE") == 0 ) cdsSptSiz = val; else if ( strcmp(pname, "SPTXTWIDTH") == 0 ) cdsSptWdth = val; } } fclose(fp); }
void ctb_g2rdvar ( char *tbname, G2vars_t *vartbl, int *iret ) /************************************************************************ * ctb_g2rdvar * * * * This routine will read a GRIB2 Parameter * * table into an array of structures. * * The table is allocated locally and a pointer to the new table is * * passed back to the user in argument vartbl. The user is resposible * * for freeing this memory, when the table is no longer needed, by * * free(vartbl.info) * * * * ctb_g2rdvar ( tbname, vartbl, iret ) * * * * Input parameters: * * *tbname char Filename of the table to read * * * * Output parameters: * * *vartbl G2vars_t Pointer to list of table entries * * *iret int Return code * * 0 = Successful * * -1 = Could not open * * -2 = Could not get count of * * of table entries. * ** * * Log: * * S. Gilbert/NCEP 11/04 Modified from ctb_g2rdcntr to read a * * GRIB2 Parameter Table. * ***********************************************************************/ { FILE *fp = NULL; int n, blen, nr, ier; char buffer[256]; char name[33], gname[13], unts[21]; int disc, cat, parm, pdtn, scl, ihzrmp, idrct; float msng; const int ncoln=110; /*---------------------------------------------------------------------*/ *iret = G_NORMAL; /* * Open the table. If not found return an error. */ fp = cfl_tbop( tbname, "grid", &ier); if ( fp == NULL || ier != 0 ) { if (fp) fclose(fp); *iret = -1; return; } cfl_tbnr(fp, &nr, &ier); if ( ier != 0 || nr == 0 ) { *iret = -2; cfl_clos(fp, &ier); return; } vartbl->info = malloc((size_t)nr*sizeof(G2Vinfo)); if (vartbl->info == NULL) { *iret = -1; cfl_clos(fp, &ier); return; } vartbl->nlines = nr; n = 0; while ( n < nr ) { cfl_trln( fp, 256, buffer, &ier ); if ( ier != 0 ) { free(vartbl->info); break; } cst_lstr ( buffer, &blen, &ier ); if ( blen > ncoln ) { sscanf( buffer, "%12d %12d %12d %12d %32c %20c %12s %12d %20f %12d %12d", &disc, &cat, &parm, &pdtn, name, unts, gname, &scl, &msng, &ihzrmp, &idrct ); } else { sscanf( buffer, "%12d %12d %12d %12d %32c %20c %12s %12d %20f", &disc, &cat, &parm, &pdtn, name, unts, gname, &scl, &msng); ihzrmp = 0; idrct = 0; } name[32] = '\0'; unts[20] = '\0'; gname[12] = '\0'; vartbl->info[n].discpln=disc; vartbl->info[n].categry=cat; vartbl->info[n].paramtr=parm; vartbl->info[n].pdtnmbr=pdtn; strcpy(vartbl->info[n].name, name); strcpy(vartbl->info[n].units, unts); strcpy(vartbl->info[n].gemname, gname); vartbl->info[n].scale=scl; vartbl->info[n].missing=msng; vartbl->info[n].hzremap = ihzrmp; vartbl->info[n].direction = idrct; n++; } cfl_clos(fp, &ier); }
int main (int argc , char **argv) /************************************************************************ * main * * * * Main program of createbinfo. * * * * Output (from printf) must be re-directed to the proper info file * * within the script. * * * * main(argc, argv) * * * * Input parameters: * * argc int number of parameters of command line * * argv char** parameter array of command line * * * * Output parameters: * * Return parameters: * * NONE * * * ** * * Log: * * D.W.Plummer/NCEP 12/98 * * T. Piper/GSC 8/00 Modified for new generic boundary info * * D.W.Plummer/NCEP 6/05 Incr accuracy from 2 decimal digits to 4* ***********************************************************************/ { char buff[256], id[7], name[64]; int i, ier, ilat, ilon, k, length, nparts, nptot, npts, num, pst; float fltptr[20], lat1, lat2, lon1, lon2, minlat, minlon, maxlat, maxlon; FILE *fp; long lpos, lposp; Bnd_t boundary; /*---------------------------------------------------------------------*/ /* * Print out the name of the BOUNDARY file. */ boundary.filename = (char *)malloc( sizeof(char) * strlen(argv[1]) + 1); strcpy ( boundary.filename, argv[1] ); printf("!\n! BOUNDARIES FILENAME \n%s\n!\n", boundary.filename ); fp = (FILE *)cfl_tbop ( boundary.filename, "bounds", &ier ); /* * Allocate and initialize boundary location structure */ boundary.nbnd = 0; boundary.bound = (BInfo_t *)malloc(MAX_BOUNDS*sizeof(BInfo_t)); for ( i = 0; i < MAX_BOUNDS; i++ ) { boundary.bound[i].name = (char *)malloc( sizeof(char) * MAX_NAMELEN + 1); boundary.bound[i].name[0] = '\0'; boundary.bound[i].info = (char *)malloc( sizeof(char) * MAX_NAMELEN + 1); boundary.bound[i].info[0] = '\0'; boundary.bound[i].strec = 0; boundary.bound[i].cenlat = RMISSD; boundary.bound[i].cenlon = RMISSD; boundary.bound[i].minlat = RMISSD; boundary.bound[i].minlon = RMISSD; boundary.bound[i].maxlat = RMISSD; boundary.bound[i].maxlon = RMISSD; boundary.bound[i].nparts = 0; } cfl_wher ( fp, &lpos, &ier ); cfl_trln ( fp, sizeof(buff), buff, &ier ); if ( ier == 0 ) { sscanf ( buff, "%s %s %d %d %d", id, name, &ilat, &ilon, &nparts ); boundary.bound[0].bndspt = (Bndsprt_t *)malloc(nparts*sizeof(Bndsprt_t)); /* Read the second header line */ cfl_trln ( fp, sizeof(buff), buff, &ier ); strcpy ( boundary.bound[0].info, buff); for ( k = 0; k < nparts; k++ ) { cfl_wher ( fp, &lposp, &ier ); cfl_trln ( fp, sizeof(buff), buff, &ier ); sscanf ( buff, "%d %f %f %f %f", &npts, &lat1, &lat2, &lon1, &lon2 ); boundary.bound[0].bndspt[k].minlat = G_MIN ( lat1, lat2 ); boundary.bound[0].bndspt[k].maxlat = G_MAX ( lat1, lat2 ); boundary.bound[0].bndspt[k].minlon = G_MIN ( lon1, lon2 ); boundary.bound[0].bndspt[k].maxlon = G_MAX ( lon1, lon2 ); boundary.bound[0].bndspt[k].strec = lposp; boundary.bound[0].bndspt[k].npts = npts / 2; cst_rxbl ( buff, buff, &length, &ier ); cst_rlst ( buff, ' ', RMISSD, (int) (sizeof(fltptr)/sizeof(float)), fltptr, &num, &ier); nptot = ( num - 5 ); while ( ier == 0 && nptot < npts ) { cfl_trln ( fp, sizeof(buff), buff, &ier ); if ( ier == 0 ) { cst_rxbl ( buff, buff, &length, &ier ); cst_rlst ( buff, ' ', RMISSD, sizeof(fltptr)/sizeof(float), fltptr, &num, &ier); nptot += num; } /* Loop over all points in one part */ } } /* Loop over all parts in one bound */ if ( ier == 0 ) { strcpy ( boundary.bound[0].name, name ); boundary.bound[0].strec = lpos; boundary.bound[0].cenlat = ilat / 100.0; boundary.bound[0].cenlon = ilon / 100.0; boundary.bound[0].nparts = nparts; boundary.nbnd++; } } while ( ier == 0 ) { cfl_wher ( fp, &lpos, &ier ); cfl_trln ( fp, sizeof(buff), buff, &ier ); if ( ier == 0 ) { boundary.nbnd++; pst = boundary.nbnd - 1; sscanf ( buff, "%s %s %d %d %d", id, name, &ilat, &ilon, &nparts ); strcpy ( boundary.bound[pst].name, name ); boundary.bound[pst].strec = lpos; boundary.bound[pst].cenlat = ilat / 100.0; boundary.bound[pst].cenlon = ilon / 100.0; boundary.bound[pst].nparts = nparts; /* Read the second header line */ cfl_trln ( fp, sizeof(buff), buff, &ier ); strcpy ( boundary.bound[pst].info, buff); boundary.bound[pst].bndspt = (Bndsprt_t *)malloc(nparts*sizeof(Bndsprt_t)); for ( k = 0; k < nparts; k++ ) { cfl_wher ( fp, &lposp, &ier ); cfl_trln ( fp, sizeof(buff), buff, &ier ); sscanf ( buff, "%d %f %f %f %f", &npts, &lat1, &lat2, &lon1, &lon2 ); boundary.bound[pst].bndspt[k].minlat = G_MIN(lat1,lat2); boundary.bound[pst].bndspt[k].maxlat = G_MAX(lat1,lat2); boundary.bound[pst].bndspt[k].minlon = G_MIN(lon1,lon2); boundary.bound[pst].bndspt[k].maxlon = G_MAX(lon1,lon2); boundary.bound[pst].bndspt[k].strec = lposp; boundary.bound[pst].bndspt[k].npts = npts / 2; cst_rxbl( buff, buff, &length, &ier ); cst_rlst( buff, ' ', RMISSD, (int) (sizeof(fltptr)/sizeof(float)), fltptr, &num, &ier); nptot = ( num - 5 ); while ( ier == 0 && nptot < npts ) { cfl_trln ( fp, sizeof(buff), buff, &ier ); if ( ier == 0 ) { cst_rxbl ( buff, buff, &length, &ier ); cst_rlst ( buff, ' ', RMISSD, sizeof(fltptr)/sizeof(float), fltptr, &num, &ier); nptot += num; } } } } } boundary.maxpts = 0; for ( i = 0; i < boundary.nbnd; i++ ) { minlat = 90.0; minlon = 360.0; maxlat = -90.0; maxlon = -360.0; for ( k = 0; k < boundary.bound[i].nparts; k++ ) { minlat=G_MIN ( minlat, boundary.bound[i].bndspt[k].minlat ); minlon=G_MIN ( minlon, boundary.bound[i].bndspt[k].minlon ); maxlat=G_MAX ( maxlat, boundary.bound[i].bndspt[k].maxlat ); maxlon=G_MAX ( maxlon, boundary.bound[i].bndspt[k].maxlon ); boundary.maxpts = G_MAX ( boundary.maxpts, boundary.bound[i].bndspt[k].npts ); } boundary.bound[i].minlat = minlat; boundary.bound[i].minlon = minlon; boundary.bound[i].maxlat = maxlat; boundary.bound[i].maxlon = maxlon; } /* * Print out number of bounds. */ printf("! TOTAL NUMBER OF BOUNDS\n%d\n!\n", boundary.nbnd ); printf("! MAX NUMBER OF POINTS per BOUND\n%d\n!\n", boundary.maxpts ); printf("! BOUNDARY STRUCTURE INFORMATION\n!\n" ); /* * Dump the information. */ for ( i = 0; i < boundary.nbnd; i++ ) { printf("!\n%-s %-12ld %-.2f %-.2f %-.2f %-.2f %-.2f %-.2f %-5d\n", boundary.bound[i].name, boundary.bound[i].strec, boundary.bound[i].cenlat, boundary.bound[i].cenlon, boundary.bound[i].minlat, boundary.bound[i].minlon, boundary.bound[i].maxlat, boundary.bound[i].maxlon, boundary.bound[i].nparts ); printf("%s\n", boundary.bound[i].info); for ( k = 0; k < boundary.bound[i].nparts; k++ ) { printf("\t%-12ld %-.2f %-.2f %-.2f %-.2f %-8d \n", boundary.bound[i].bndspt[k].strec, boundary.bound[i].bndspt[k].minlat, boundary.bound[i].bndspt[k].minlon, boundary.bound[i].bndspt[k].maxlat, boundary.bound[i].bndspt[k].maxlon, boundary.bound[i].bndspt[k].npts ); } } return(0); }
void clo_rdstn ( Stn_t *stn, char *fnm, char *alias, int *iret ) /************************************************************************ * clo_rdstn * * * * This function loads station table information into the standard * * station information structure. * * * * clo_rdstn ( stn, fnm, alias, iret ) * * * * Input parameters: * * *stn Stn_t station structure to fill * * *fnm char station file name to use * * *alias char alias of table name * * * * Output parameters: * * *iret int Return code * * -1 - Unable to open table * * -2 - No records in table * * -3 - Invalid type of point * ** * * Log: * * D.W.Plummer/NCEP 1/99 From (now replaced) cloancrd.c * * D.W.Plummer/NCEP 3/99 Add sorting index * * T. Piper/GSC 3/99 Corrected prolog * * D.W.Plummer/NCEP 4/99 Updated for MARINE & COASTAL types * * D.W.Plummer/NCEP 7/00 Updated for consolidated CLO structures * * D.W.Plummer/NCEP 8/00 Added conversion to upper case of desc * * T. Piper/GSC 6/01 Initialized c10 * * R. Tian/SAIC 8/03 Increased c10 size. * * B. Yin/SAIC 5/04 Modified code to handle blank id. * * B. Yin/SAIC 7/04 Modified for various break point types * * m.gamazaychikov 01/05 Corrected for proper column reading * ***********************************************************************/ { int counter, ier; char buff[120]; FILE *fp; char id[9], desc[64], state[8], cntry[8], c10[21]="\0", tmpstr[128]; int stnm, lat, lon, numstn, elv, pri; /*---------------------------------------------------------------------*/ *iret = G_NORMAL; /* * Open the table. If not found return an error. */ fp = (FILE *)cfl_tbop(fnm, "stns", &ier); if ( fp == NULL || ier != 0 ) { stn->nstn = 0; *iret = -1; return; } cfl_tbnr( fp, &numstn, &ier ); if ( numstn != 0 ) { /* * Allocate the structure elements. */ stn->nstn = numstn; stn->station = (SInfo_t *) malloc( (size_t)numstn * sizeof(SInfo_t) ); } else { cfl_clos(fp, &ier); *iret = -2; return; } rewind(fp); if ( strncmp( alias, "TCA_BKPTS_", 10 ) == 0 ) { clo_rdtcabkpts( stn, fp, alias, numstn, iret ); cfl_clos(fp, &ier); return; } /* * For every line in the station table list, read in the record, * parse out the fields, and add to the structure. */ counter = 0; while ( counter < numstn ) { cfl_trln(fp, sizeof(buff), buff, &ier); if ( ier == 0 ) { id[ 0 ] = '\0'; desc[ 0 ] = '\0'; state[ 0 ] = '\0'; cntry[ 0 ] = '\0'; c10[ 0 ] = '\0'; stnm = 0; lat = 9999; lon = 9999; elv = 9999; pri = 9999; strncpy( tmpstr, buff, 8 ); tmpstr[8]='\0'; sscanf( tmpstr, "%s", id ); stn->station[counter].id = (char *)malloc(sizeof(char)*strlen(id)+1); strcpy( stn->station[counter].id, id ); strncpy( tmpstr, &buff[9], 6 ); tmpstr[6]='\0'; sscanf( tmpstr, "%d", &stnm ); stn->station[counter].nm = stnm; strncpy( tmpstr, &buff[16], 32 ); tmpstr[32]='\0'; sscanf( tmpstr, "%s", desc ); stn->station[counter].desc = (char *)malloc(sizeof(char)*strlen(desc)+1); cst_lcuc ( desc, stn->station[counter].desc, &ier ); strncpy( tmpstr, &buff[49], 2 ); tmpstr[2]='\0'; sscanf( tmpstr, "%s", state ); stn->station[counter].state=(char *)malloc(sizeof(char)*strlen(state)+1); strcpy( stn->station[counter].state, state ); strncpy( tmpstr, &buff[52], 2 ); tmpstr[2]='\0'; sscanf( tmpstr, "%s", cntry ); stn->station[counter].cntry=(char *)malloc(sizeof(char)*strlen(cntry)+1); strcpy( stn->station[counter].cntry, cntry ); strncpy( tmpstr, &buff[55], 21 ); tmpstr[21]='\0'; sscanf( tmpstr, "%d %d %d %d", &lat, &lon, &elv, &pri ); stn->station[counter].lat = (float)lat / 100.0F; stn->station[counter].lon = (float)lon / 100.0F; stn->station[counter].elv = elv; stn->station[counter].pri = pri; strncpy( tmpstr, &buff[76], 20 ); tmpstr[20]='\0'; sscanf( tmpstr, "%s", c10 ); stn->station[counter].col10 = (char *)malloc(sizeof(char)*strlen(c10)+1); strcpy( stn->station[counter].col10, c10 ); counter++; } } cfl_clos(fp, &ier); }
static void pglpfw_readUsrTbl ( char *tblname, lpfutbl_t *lpfutbl, int *iret ) /************************************************************************ * pglpfw_readUsrTbl * * * * This routine will read LPF user table and create the data structure * * to store the information. * * * * void pglpfw_readUsrTbl( tblname, lpfutbl, iret) * * * * Input parameters: * * *tblname char table name * * * * Output parameters: * * *lpfutbl lpfutbl_t pointer to lpf user table struct* * *iret int 0 - success * * * * Return code: * * NONE * * * ** * * Log: * * T. Lee/SAIC 04/02 revise from vtbl_readUsrTbl() * ***********************************************************************/ { int ii, nn, num, ier; char buffer[256], title[60], path[256], cwd[256], format[256]; char dum1[256], dum2[256], dum3[256]; FILE *fp; /*---------------------------------------------------------------------*/ *iret = G_NORMAL; strcpy ( format, "%s %s" ); fp = cfl_tbop (tblname, "nmap", &ier); nn = 0; if (fp && ier == 0) { while (!feof(fp)) { /* * read a record */ cfl_trln (fp, 256, buffer, &ier); if ( ier == 0 ) { if ( nn == 0 ) { num = sscanf ( buffer, "%s %s %s", dum1, dum2, dum3 ); if ( num == 3 ) { strcpy ( format, "%s %*s %s" ); } } nn++; } } } /* * allocate one additional item in case the current user * has to be added in */ lpfutbl->nitems = nn; lpfutbl->items = (lpfusr_ent_t *) malloc ((nn+1) *sizeof (lpfusr_ent_t)); if (nn > 0) { rewind(fp); ii = 0; while ( ii < nn ) { cfl_trln( fp, 256, buffer, &ier ); if (ier == 0) { sscanf(buffer, format, title, path); lpfutbl->items[ii].title = (char *) malloc (strlen (title) + 1); strcpy( lpfutbl->items[ii].title, title ); lpfutbl->items[ii].usrpath = (char *) malloc (strlen(path) + 1); strcpy( lpfutbl->items[ii].usrpath, path ); ii++; } } } if (fp) fclose(fp); /* * set default user */ getcwd (cwd, sizeof (cwd)); ii = lpfutbl->nitems; lpfutbl->items[ii].title = (char *) malloc (strlen (CWD_TITLE) + 1); strcpy (lpfutbl->items[ii].title, CWD_TITLE); lpfutbl->items[ii].usrpath = (char *) malloc(strlen(cwd) + 1); strcpy ( lpfutbl->items[ii].usrpath, cwd ); nn = cfl_gfil (0, MAX_FILES, cwd, LPF_FILE_EXT, NULL); lpfutbl->nitems++; }
void ctb_g2read ( int *iret ) /************************************************************************ * ctb_g2read * * * * This routine will read a grib2 table into an array of structures. * * * * ctb_g2read ( iret ) * * * * Input parameters: * * * * Output parameters: * * *iret int Return code * ** * * Log: * * m.gamazaychikov/SAIC 5/03 * * m.gamazaychikov/SAIC 5/03 added parameter pdtnmbr to the table * * M. Li/SAIC 4/04 added hzremap, and direction * ***********************************************************************/ { FILE *fp = NULL; int n, nr, blen, ier; char buffer[256]; int disc, cat, parm, pdtn, scl, ihzrmp, idrct; char name[33], unts[21], gname[13]; float msng; /*---------------------------------------------------------------------*/ *iret = G_NORMAL; if ( Gr2Readin == 1 ) return; /* * Open the table. If not found return an error. */ fp = cfl_tbop( G2VARS_TBL, "grid", &ier); if ( fp == NULL || ier != 0 ) { if (fp) fclose(fp); *iret = -1; return; } cfl_tbnr(fp, &nr, &ier); if ( ier != 0 || nr == 0 ) { *iret = -2; cfl_clos(fp, &ier); return; } Gr2Tbl.info = (G2Vinfo *)malloc((size_t)nr*sizeof(G2Vinfo)); n = 0; while ( n < nr ) { cfl_trln( fp, 256, buffer, &ier ); if ( ier != 0 ) break; cst_lstr ( buffer, &blen, &ier ); if ( blen > NCOLN ) { sscanf( buffer, "%12d %12d %12d %12d %32c %20c %s %12d %f %12d %12d", &disc, &cat, &parm, &pdtn, name, unts, gname, &scl, &msng, &ihzrmp, &idrct ); } else { sscanf( buffer, "%12d %12d %12d %12d %32c %20c %s %12d %20f", &disc, &cat, &parm, &pdtn, name, unts, gname, &scl, &msng); ihzrmp = 0; idrct = 0; } name[32] = '\0'; unts[20] = '\0'; Gr2Tbl.info[n].discpln=disc; Gr2Tbl.info[n].categry=cat; Gr2Tbl.info[n].paramtr=parm; Gr2Tbl.info[n].pdtnmbr=pdtn; strcpy(Gr2Tbl.info[n].name, name); strcpy(Gr2Tbl.info[n].units, unts); strcpy(Gr2Tbl.info[n].gemname, gname); Gr2Tbl.info[n].scale=scl; Gr2Tbl.info[n].missing=msng; Gr2Tbl.info[n].hzremap = ihzrmp; Gr2Tbl.info[n].direction = idrct; n++; } cfl_clos(fp, &ier); Gr2Tbl.nlines = n; Gr2Readin = 1; }
int rsrc_readFile ( char *fname ) /************************************************************************ * rsrc_readFile * * * * This function opens an NMAP resource file and read it into memory. * * * * int rsrc_readFile(fname) * * * * Input parameters: * * *fname char resource filename * * * * Output parameters: * * NONE * * * * Return parameters: * * int 0 = successful * * -1 = file can not be opened * * -2 = syntax error * * * ** * * Log: * * C. Lin/EAI 9/96 * * C. Lin/EAI 1/97 add check after cfl_trln * ***********************************************************************/ { FILE *fp; char buffer[LINE_BUF], *ptr, *ptr1; int len, iret; rsrc_t *current, *next; /*---------------------------------------------------------------------*/ /* * free the previous resource when necessary */ if ( _rsrcTbl ) { current = _rsrcTbl; while(current) { next = current->next; free((rsrc_t *)current); current = next; } _rsrcTbl = NULL; } /* * open resource file */ fp = cfl_tbop(fname, "nmap", &iret); if (iret != 0) { return(-1); } else { /* parse each line */ while ( ! feof(fp) ) { cfl_trln(fp, LINE_BUF, buffer, &iret); if ( iret == 0 ) { if ( strstr(buffer, "=") == NULL ) continue; if ( _rsrcTbl == NULL ) { /* head */ _rsrcTbl = current = (rsrc_t *)malloc(sizeof(rsrc_t)); } else { current->next = (rsrc_t *)malloc(sizeof(rsrc_t)); current = current->next; } /* * get the name */ ptr = &buffer[0]; while ( *ptr == ' ' || *ptr == '\t' ) ptr++; /* remove leading space */ ptr1 = current->name; while ( *ptr && *ptr != '=' ) *ptr1++ = *ptr++; *ptr1 = '\0'; cst_rmbl(current->name, current->name, &len, &iret); /* * get the parm */ ptr++; while ( *ptr == ' ' || *ptr == '\t' ) ptr++; /* remove leading space */ strcpy(current->parm, ptr); cst_rmbl(current->parm, current->parm, &len, &iret); current->next = NULL; } } fclose(fp); } return(0); }
void tb_nidsdb ( char *prdnam, char *res, int *iprod, int *iret ) /************************************************************************ * tb_nidsdb * * * * This subroutine returns information about the radar image from the * * NIDS product table file. * * * * void tb_nidsdb ( prdnam, res, iprod, iret ) * * * * Input parameters: * * *prdnam char Product name * * *res char Data resolution in km * * * * Output parameters: * * *iprod int NIDS product ID * * *iret int Return code * * 0 = normal return * * +3 = No entry found for image * * -7 = Could not open imtyp table* ** * * Log: * * m.gamazaychikov/CWS 01/10 Created * ***********************************************************************/ { int found, ier, ier1, loglev=2; float ares; char *grp="TB", line[128]; size_t ii; static int nr; static FILE *fptr=NULL; static Radtbl_t *radtbl=NULL; /*---------------------------------------------------------------------*/ /* * Initialize output variables. */ *iprod = 0; *iret = 33; /* Not found */ cst_crnm ( res, &ares, &ier ); /* * If table not yet read into memory; open the image type table file. */ if ( fptr == NULL ) { fptr = cfl_tbop ( NIDPRD_TBL, "rad", &ier ); if ( ier != 0 ) { *iret = -7; er_lmsg (&loglev, grp, iret, NIDPRD_TBL, &ier1, strlen(grp), strlen(NIDPRD_TBL)); return; } /* * Load the structure. */ cfl_tbnr (fptr, &nr, &ier ); if ( ier != 0 || nr == 0 ) { *iret = -7; er_lmsg (&loglev, grp, iret, NIDPRD_TBL, &ier1, strlen(grp), strlen(NIDPRD_TBL)); cfl_clos(fptr, &ier); return; } G_MALLOC(radtbl, Radtbl_t, nr, "tb_nidsdb: radtbl"); for (ii = 0; ii < (size_t)nr; ii++ ) { /* * Read the next record. */ cfl_trln ( fptr, 127, line, &ier ); if ( ier == 0 ) { sscanf(line,"%s %s %i %i %s %f %s", radtbl[ii].type, radtbl[ii].name, &radtbl[ii].prod, &radtbl[ii].lvls, radtbl[ii].units, &radtbl[ii].res, radtbl[ii].desc); } } /* end of 'for (ii = 0; ii < nr; ii++ )' */ cfl_clos(fptr, &ier); } /* end of 'if ( *fptr == NULL )' */ ii = 0; found = G_FALSE; /* * Retrieve the product ID for the specified * product name and the resolution. */ while ( !found && ii < (size_t)nr ) { //if ( strstr (radtbl[ii].name, prdnam) != NULL ) { if ( strcmp (prdnam, radtbl[ii].name) == 0 ) { if ( G_DIFF(ares, radtbl[ii].res) ) { found = G_TRUE; *iprod = radtbl[ii].prod; *iret = G_NORMAL; } } ii++; } }
void ctb_g2rdcntr ( char *tbname, G2wmocntrs *cntrtbl, int *iret ) /************************************************************************ * ctb_g2rdcntr * * * * This routine will read a WMO originating Center table into an array * * of structures. * * The table is allocated locally and a pointer to the new table is * * passed back to the user in argument cntrtbl. The user is resposible * * for freeing this memory, when the table is no longer needed, by * * free(cntrtbl.info) * * * * ctb_g2rdcntr ( tbname, cntrtbl, iret ) * * * * Input parameters: * * *tbname char Filename of the table to read * * * * Output parameters: * * *cntrtbl G2wmocenter Pointer to list of table entries* * *iret int Return code * * 0 = Successful * * -1 = Could not open * * -1 = Could not get count of * * of teble entries. * ** * * Log: * * m.gamazaychikov/SAIC 5/03 * * m.gamazaychikov/SAIC 5/03 added parameter pdtnmbr to the table * * M. Li/SAIC 4/04 added hzremap, and direction * * S. Gilbert/NCEP 11/04 Modified from ctb_g2read to read a WMO * * Originating Center Table. * ***********************************************************************/ { FILE *fp; int n, blen, id, nr, ier; char buffer[256]; char name[65], abbrev[9]; /*---------------------------------------------------------------------*/ *iret = G_NORMAL; /* * Open the table. If not found return an error. */ fp = cfl_tbop( tbname, "grid", &ier); if ( fp == NULL || ier != 0 ) { *iret = -1; return; } cfl_tbnr(fp, &nr, &ier); if ( ier != 0 || nr == 0 ) { *iret = -2; cfl_clos(fp, &ier); return; } cntrtbl->info = (G2wmocenter *)malloc((size_t)nr*sizeof(G2wmocenter)); cntrtbl->nlines = nr; n = 0; while ( n < nr ) { cfl_trln( fp, 256, buffer, &ier ); if ( ier != 0 ) break; cst_lstr ( buffer, &blen, &ier ); sscanf( buffer, "%d %64c %s", &id, name, abbrev); name[64] = '\0'; abbrev[8] = '\0'; cntrtbl->info[n].id=id; strcpy(cntrtbl->info[n].name, name); strcpy(cntrtbl->info[n].abbrev, abbrev); n++; } cfl_clos(fp, &ier); }
void pds_by10 ( const char *cvcrd, const char *wmotb, const char *nceptb, unsigned char *byte10, int *ibyt10, int *iscale, int *iret ) /************************************************************************ * pds_by10 * * * * This subroutine uses the GEMPAK GRIB vertical coordinate lookup * * tables to determine the value of PDS octet 10. * * * * pds_by10 ( cvcrd, wmotb, nceptb, byte10, ibyt10, iscale, iret ) * * * * Input parameters: * * *cvcrd const char GEMPAK VCORD name string * * *wmotb const char WMO GRIB VCORD LUT file name * * *nceptb const char NCEP GRIB VCORD LUT file name * * * * Output parameters: * * *byte10 unsigned char Byte with GRIB VCORD # stored * * *ibyt10 int Integer value of byte 10 * * *iscale int Power of 10 scaling in GEMPAK * * *iret int Return code * * 0 = normal return * * -85 = VCORD not found * * -86 = VCORD # is invalid * ** * * Log: * * K. Brill/HPC 7/99 * * R. Tian/SAIC 10/06 Recoded from Fortran * ************************************************************************/ { char filnam[2][LLMXLN], record[LLMXLN], prmnam[17], chkprm[17]; int found; int ifile, iprm, iscl, ier; FILE *fp; /*----------------------------------------------------------------------*/ *iret = 0; *byte10 = (unsigned char)( 255 ); *ibyt10 = 255; *iscale = 0; /* * Check the tables. */ cst_lcuc ( (char *)cvcrd, chkprm, &ier ); strcpy ( filnam[0], wmotb ); strcpy ( filnam[1], nceptb ); found = G_FALSE; ifile = 0; while ( ifile < 2 && found == G_FALSE ) { fp = cfl_tbop ( filnam[ifile++], "grid", &ier ); if ( ier != 0 ) continue; while ( ! feof(fp) && found == G_FALSE ) { cfl_trln ( fp, sizeof(record), record, &ier ); if ( ier != 0 ) continue; sscanf ( record, "%d", &iprm ); sscanf ( &record[59], "%s %d", prmnam, &iscl ); if ( strcmp ( prmnam, chkprm ) == 0 ) { found = G_TRUE; *ibyt10 = iprm; *iscale = iscl; } } cfl_clos ( fp, &ier ); } if ( found == G_FALSE ) { *iret = -85; } else if ( *ibyt10 < 255 && *ibyt10 > 0 ) { *byte10 = (unsigned char)( *ibyt10 ); } else { *iret = -86; } return; }
void NxmCursor_rdTbls ( void ) /************************************************************************ * NxmCursor_rdTbls * * * * This function reads the cursor type table and cursor reference table * * * * void NxmCursor_rdTbls() * * * * Input parameters: * * Output parameters: * * Return parameters: * * NONE * * * ** * * Log: * * H. Zeng/EAI 04/00 initial coding * ***********************************************************************/ { int ii, jj, nr = 0, ignore, iret; char buffer[256]; FILE *fp; /*---------------------------------------------------------------------*/ /* * Read cursorsymb.tbl */ _cursymbTbl.nsymb = 0; fp = cfl_tbop( CURSORSYMB_TBL, "config", &iret ); if ( iret == 0 ) { cfl_tbnr( fp, &nr, &iret); } if ( nr == 0 ) { fclose(fp); } else { _cursymbTbl.nsymb = nr; _cursymbTbl.cursymbs = (cursorsymb_t*) malloc((size_t)_cursymbTbl.nsymb*sizeof(cursorsymb_t)); ii = 0; while (ii < _cursymbTbl.nsymb) { cfl_trln(fp, 256, buffer, &iret); if ( iret == 0 ) { sscanf(buffer, "%s %d", _cursymbTbl.cursymbs[ii].X_name, &(_cursymbTbl.cursymbs[ii].id) ); } ii++; } fclose(fp); } /* * Read cursortyp.tbl */ _curtypTbl.ntyp = 0; fp = cfl_tbop( CURSORTYPE_TBL, "config", &iret ); if ( iret == 0 ) { cfl_tbnr( fp, &nr, &iret); } if ( nr == 0 ) { fclose(fp); } else { _curtypTbl.ntyp = nr; _curtypTbl.curtyps = (cursortyp_t*) malloc((size_t)_curtypTbl.ntyp*sizeof(cursortyp_t)); ii = 0; while (ii < _curtypTbl.ntyp) { cfl_trln(fp, 256, buffer, &iret); if ( iret == 0 ) { sscanf(buffer, "%s %s", _curtypTbl.curtyps[ii].ext_name, _curtypTbl.curtyps[ii].int_name ); /* * By default id value is -1 which means it is a pixmap cursor. */ _curtypTbl.curtyps[ii].id = -1; if( strstr(_curtypTbl.curtyps[ii].int_name, "XC_") != NULL ) { for(jj=0; jj<_cursymbTbl.nsymb; jj++) { if(strcmp(_curtypTbl.curtyps[ii].int_name, _cursymbTbl.cursymbs[jj].X_name)==0 ) { _curtypTbl.curtyps[ii].id = _cursymbTbl.cursymbs[jj].id; break; } } /* the end of for() */ } /* the end of if(strstr...) */ } ii++; } fclose(fp); } /* * Read cursorref.tbl */ _currefTbl.nref = 0; fp = cfl_tbop( CURSORREF_TBL, "config", &iret ); if ( iret == 0 ) { cfl_tbnr( fp, &nr, &iret); } if ( nr == 0 ) { fclose(fp); } else { _currefTbl.nref = nr; _currefTbl.currefs = (cursorref_t*) malloc((size_t)_currefTbl.nref*sizeof(cursorref_t)); ii = 0; while (ii < _currefTbl.nref) { cfl_trln(fp, 256, buffer, &iret); if ( iret == 0 ) { sscanf(buffer, "%d %s %s %s", &ignore, _currefTbl.currefs[ii].ref_name, _currefTbl.currefs[ii].typ_name, _currefTbl.currefs[ii].color ); } ii++; } fclose(fp); } free(_cursymbTbl.cursymbs); }
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); }
void nmp_init ( int *iret ) /************************************************************************ * nmp_init * * * * This function reads the mapinfo.tbl and mapovl.tbl tables into * * the structure. * * * * void nmp_init( iret ) * * * * Input parameters: * * Output parameters: * * *iret int Return code * * = 0 - OK * * = -1 - map table not read * * = -2 - overlay table not read * * Return parameters: * * NONE * * * ** * * Log: * * M. Li/GSC 11/00 Created * * M. Li/GSC 12/00 Allocated saved_overlay * * M. Li/GSC 12/00 Added nmp_setmap * * M. Li/GSC 02/01 expanded map, lat/lon and STN * * E. Safford/GSC 04/01 init imgfile, imgtyp * * E. Safford/GSC 05/01 use SAT_STR && RAD_STR * * M. Li/GSC 05/01 replaced nmp_savovl with nmp_save * * J. Wu/SAIC 08/01 allocate space for default_overlay[] * * J. Wu/SAIC 08/01 save off default_map & default_overlay * * J. Wu/SAIC 08/03 save marker size as float number * * T. Piper/SAIC 08/04 Added check on nn (number of overlays) * * T. Piper/SAIC 08/04 Added itype 5 (scale legend) support * ***********************************************************************/ { int active, color, ier, ii, itype, lat_opt, lp, nn, val_opt, which; float lat, msize; char app[5][3], buffer[256], val_txt[64]; FILE *fp; nmpovlstr_t title, gname, ovlattr; /*---------------------------------------------------------------------*/ *iret = 0; /* * Read table mapinfo.tbl */ fp = cfl_tbop(MAPAREA_FILE, TBL_DIR, &ier); if (ier!= 0) { *iret = -1; } else { /* * figure out the total # of records */ nn = 0; while ( !feof(fp) ) { /* * read a record */ cfl_trln(fp, 256, buffer, &ier); if ( ier == 0 ) nn++; } } map_tbl = malloc((nn+EXTRA_PDFBTN)* sizeof(maptbl_ent_t)); if ( nn > 0 ) { num_maps = nn; rewind(fp); ii = 0; while ( ii < nn ) { cfl_trln(fp, 256, buffer, &ier); if ( ier == 0 ) { sscanf(buffer, "%s %s", map_tbl[ii].name, map_tbl[ii].geog); } ii++; } } if ( fp ) { fclose(fp); } /* * Add SAT and Custom */ num_maps += EXTRA_PDFBTN; /* * set satellite projection button */ which = num_maps-SAT_BTN; strcpy(map_tbl[which].name, SAT_STR); strcpy(map_tbl[which].geog, "DSET"); /* * set customize button */ which = num_maps - CUSTOM_BTN; strcpy(map_tbl[which].name, RAD_STR); strcpy(map_tbl[which].geog, "\0"); /* * Set the map object */ nmp_setmap(map_tbl[0].name, 0, TRUE, &ier); for (lp = 0; lp < MAX_LOOP; lp++) { maps[lp].mode = 1; maps[lp].imgtyp = NO_IMG; strcpy (maps[lp].imgfile, ""); } /* * Read table mapovl.tbl */ fp = cfl_tbop(MAPOVL_FILE, TBL_DIR, &ier); if (ier != 0) { *iret = -2; for (lp =0; lp < MAX_LOOP; lp ++) { overlay[lp].novl = 0; } return; } else { /* * figure out the total # of records */ nn = 0; while ( !feof(fp) ) { /* * read a record */ cfl_trln(fp, 256, buffer, &ier); if ( ier == 0 ) { nn++; } } } if ( nn > MAX_OVL ) nn = MAX_OVL; /* * Load the table into the structure */ if ( nn > 0 ) { for (lp=0; lp<MAX_LOOP; lp++) { overlay[lp].novl = nn; if (overlay[lp].mapovl == NULL) { overlay[lp].mapovl = (overlay_t *)malloc(overlay[lp].novl* sizeof(overlay_t)); } } rewind(fp); ii = 0; while ( ii < nn ) { cfl_trln(fp, 256, buffer, &ier); if ( ier == 0 ) { sscanf ( buffer, "%s %d", title, &itype); if ( itype == 1 ) { sscanf ( buffer, "%s %d %s %d %d %s %s", title, &itype, gname, &active, &color, app[0], app[1]); sprintf ( ovlattr, "%d %s %s", color, app[0], app[1] ); } else if ( itype == 0 ) { sscanf ( buffer, "%s %d %s %d %d %s %s %s %s", title, &itype, gname, &active, &color, app[0], app[1], app[2], app[3]); sprintf ( ovlattr, "%d %s %s %s %s", color, app[0], app[1], app[2], app[3] ); } else if ( itype == 2 ) { sscanf ( buffer, "%s %d %s %d %d %s %s %s %s %s", title, &itype, gname, &active, &color, app[0], app[1], app[2], app[3], app[4] ); msize = (float) atof ( app[1] ); if ( msize < 0.5 || msize > 3.0 ) msize = 1.0; sprintf ( ovlattr, "%d %s %2.1f %s %s %s", color, app[0], msize, app[2], app[3], app[4] ); } else if ( itype == 5 ) { sscanf ( buffer, "%s %d %s %d %d %s %s %s %s %s %f %s", title, &itype, gname, &active, &color, app[0], app[1], app[2], app[3], app[4], &lat, val_txt ); if ( !ERMISS(lat) ) { lat_opt = 1; /* Manual mode */ } else { lat_opt = 0; /* Auto mode */ } cst_lcuc(val_txt, val_txt, &ier); if ( strcmp(val_txt, "AUTO") == 0 ) { val_opt = 0; /* Auto mode */ val_txt[0] = '-'; val_txt[1] = '\0'; } else { val_opt = 1; /* Manual mode */ } sprintf ( ovlattr, "%d %s %d %f %d %s %s %s %s %s", color, app[0], lat_opt, lat, val_opt, val_txt, app[1], app[2], app[3], app[4] ); } for ( lp = 0; lp < MAX_LOOP; lp++ ) { strcpy ( overlay[lp].mapovl[ii].title, title ); strcpy ( overlay[lp].mapovl[ii].gname, gname ); overlay[lp].mapovl[ii].ityp = itype; overlay[lp].mapovl[ii].active = active; strcpy ( overlay[lp].mapovl[ii].attr, ovlattr ); } ii++; } } /* * Save a copy of map & overlay feature */ for (lp=0; lp<MAX_LOOP; lp++) { strcpy(default_map[lp].imgfile, maps[lp].imgfile); default_map[lp].imgtyp = maps[lp].imgtyp; strcpy(default_map[lp].mapfile, maps[lp].mapfile); strcpy(default_map[lp].mapattr, maps[lp].mapattr); strcpy(default_map[lp].map, maps[lp].map); strcpy(default_map[lp].proj, maps[lp].proj); strcpy(default_map[lp].garea[0], maps[lp].garea[0]); strcpy(default_map[lp].garea[1], maps[lp].garea[1]); default_map[lp].mode = maps[lp].mode; if (default_overlay[lp].mapovl == NULL) { default_overlay[lp].mapovl = (overlay_t *)malloc(nn * sizeof(overlay_t)); } if (saved_overlay[lp].mapovl == NULL) { saved_overlay[lp].mapovl = (overlay_t *)malloc(nn * sizeof(overlay_t)); } default_overlay[lp].novl = overlay[lp].novl; for (ii =0; ii < default_overlay[lp].novl; ii++ ) { default_overlay[lp].mapovl[ii].ityp = overlay[lp].mapovl[ii].ityp; strcpy (default_overlay[lp].mapovl[ii].attr, overlay[lp].mapovl[ii].attr); strcpy (default_overlay[lp].mapovl[ii].gname, overlay[lp].mapovl[ii].gname); strcpy (default_overlay[lp].mapovl[ii].title, overlay[lp].mapovl[ii].title); default_overlay[lp].mapovl[ii].active = overlay[lp].mapovl[ii].active; } } nmp_save(&ier); } cfl_clos(fp, &ier); }
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 gg_rtrk ( char *filtyp, char *filnam, char *stime, char *etime, int *itmclr, int *iskip, int *iret ) /************************************************************************ * gg_rtrk * * * * This routine reads the data from a Altimeter Ground Track Prediction * * file and plots it. * * * * gg_rtrk ( filtyp, filnam, stime, etime, itmclr, iskip, iret ) * * * * * * Input parameters: * * *filtyp char Data type * * *filnam char Data file name * * *stime char Start time of data * * *etime char End time of data * * *itmclr int Time stamp color * * *iskip int Skip value * * * * Output parameters: * * *iret int Return code * ** * * Log: * * G. McFadden/SAIC 12/08 Modeled after gg_qsrd * * S. Jacobs/NCEP 6/10 Removed underscore on function name * ***********************************************************************/ { int ier, incr, itarr[5], iyoff = 0, ixoff = -10, ntime, np2, pcount, gyear, ymd, hm; FILE *fptr; char buffer[256], textstr[8], final_ts[9], ymd_string[7], hm_string[5]; char gempak_dt[12]; char *cp, underscore[2]; float lat, lon, rotat = 0.0F; double dlat, dlon, dalt; size_t two = 2; /*---------------------------------------------------------------------*/ /* * Open the data file. */ fptr = cfl_ropn ( filnam, NULL, &ier ); if ( fptr == NULL || ier != 0 ) { *iret = -1; return; } *iret = 0; underscore[0] = '_'; underscore[1] = '\0'; /* * Set the skip factor. */ if ( *iskip <= 0 ) { incr = 1; } else { incr = *iskip + 1; } pcount = incr; while ( ier == 0 ) { /* * Read this prediction's data. */ cfl_trln( fptr, 256, buffer, &ier ); if ( ier != 0 ) { /* * Bad read...close the file and exit. */ cfl_clos ( fptr, &ier ); return; } /* * Extract this prediction's data. */ sscanf( buffer, "%d %d %d %d %d %lf %lf %lf", &itarr[0], &itarr[1], &itarr[2], &itarr[3], &itarr[4], &dlat, &dlon, &dalt ); lat = (float)dlat; lon = (float)dlon; /* * Get the gempak date/time of this prediction */ gyear = itarr[0] - 2000; ymd = gyear * 10000 + itarr[1] * 100 + itarr[2]; sprintf(ymd_string, "%6.6d", ymd ); hm = itarr[3] * 100 + itarr[4]; sprintf(hm_string, "%4.4d", hm ); gempak_dt[0] = '\0'; strcat(gempak_dt,ymd_string); strcat(gempak_dt,"/"); strcat(gempak_dt,hm_string); /* * The longitude is stored as 0 -> 360. PRNLON will correct the longitude to * the range -180 -> 180. */ np2 = 1; prnlon( &np2, &lon, &ier ); /* * Plot the prediction if it is not skipped and if it is within the valid * time range...plot "DD_HHMM" on the screen. */ ntime = itarr[2] * 10000 + itarr[3] * 100 + itarr[4]; sprintf(textstr, "%6.6d", ntime); final_ts[0] = '\0'; strncpy(final_ts,textstr,two); final_ts[2] = '\0'; strcat(final_ts,underscore); cp = textstr + 2; strcat(final_ts,cp); gscolr ( itmclr, &ier); if ( pcount % incr == 0 && PathTimeCheck( gempak_dt, stime, etime) ) { gtext ( sys_M, &lat, &lon, final_ts, &rotat, &ixoff, &iyoff, &ier, strlen(sys_M), strlen(final_ts) ); } pcount++; } /* * Close the file. */ cfl_clos ( fptr, &ier ); }
void cvg_rdfilter ( int *iret ) /************************************************************************ * cvg_rdfilter * * * * This function reads in all valid entries in the filter table. * * * * cvg_rdfilter ( filter, iret ) * * * * Input parameters: * * none * * * * Output parameters: * * *iret int Return code * * 0 = Normal * * -1 = unable to open table file * ** * * Log: * * J. Wu/SAIC 06/06 initial coding * ***********************************************************************/ { int ier; char buff[256], filtype[12], str[256], filstr[8]; FILE *fp; /*---------------------------------------------------------------------*/ *iret = 0; /* * Read the table only once. */ if ( filterLoaded ) return; /* * Initialize. */ nTblFilter = 0; /* * Set the flag to True. */ filterLoaded = True; /* * Open the filter table. If not found, return an error. */ fp = cfl_tbop ( FILTER_TBL, "pgen", &ier ); if ( fp == NULL || ier != 0 ) { printf ( "not loaded ....\n" ); *iret = -1; return; } /* * Scan table line-by-line and load valid entries. */ while ( !feof(fp) ) { cfl_trln ( fp, sizeof(buff), buff, &ier ); if ( ier == 0 ) { sscanf ( buff, "%s %s", filstr, filtype ); if ( strcmp ( filstr, "FILTER" ) != 0 ) { continue; /* Skip invalid lines */ } if ( ( strcmp ( filtype, "TIME") == 0 ) && ( nTblFilter < MAX_FILTER_NUM ) ) { sscanf ( buff, "%*s %*s %s", str ); _fillStrArray ( MAX_FILTER_NUM, DSPLY_FILTER_SZ, str, &nTblFilter, tblFilter ); } } } cfl_clos ( fp, &ier ); }
void ctb_g2rdlvl ( char *tbname, G2lvls *lvltbl, int *iret ) /************************************************************************ * ctb_g2rdlvl * * * * This routine will read a GRIB2 vertical coordinate level/layer * * table into an array of structures. * * The table is allocated locally and a pointer to the new table is * * passed back to the user in argument lvltbl. The user is responsible * * for freeing this memory, when the table is no longer needed, by * * free(lvltbl.info) * * * * ctb_g2rdlvl ( tbname, lvltbl, iret ) * * * * Input parameters: * * *tbname char Filename of the table to read * * * * Output parameters: * * *lvltbl G2lvls Pointer to list of table entries * * *iret int Return code * * 0 = Successful * * -1 = Could not open * * -2 = Could not get count of of table entries * * -52 = Memory allocation failure (G_NMEMRY) * ** * * Log: * * S. Gilbert/NCEP 11/04 Modified from ctb_g2rdcntr to read a * * GRIB2 level/layer Table. * * S. Emmerson/Unidata 12/15 Added check for malloc() returning NULL * ***********************************************************************/ { FILE *fp = NULL; int n, blen, id1, id2, scale, nr, ier; char buffer[256]; char name[34], abbrev[5], unit[21]; /*---------------------------------------------------------------------*/ *iret = G_NORMAL; /* * Open the table. If not found return an error. */ fp = cfl_tbop( tbname, "grid", &ier); if ( fp == NULL || ier != 0 ) { if (fp) fclose(fp); *iret = -1; return; } cfl_tbnr(fp, &nr, &ier); if ( ier != 0 || nr == 0 ) { *iret = -2; cfl_clos(fp, &ier); return; } lvltbl->info = (G2level *)malloc((size_t)nr*sizeof(G2level)); if (lvltbl->info == NULL) { *iret = G_NMEMRY; cfl_clos(fp, &ier); return; } lvltbl->nlines = nr; n = 0; while ( n < nr ) { cfl_trln( fp, 256, buffer, &ier ); if ( ier != 0 ) { free(lvltbl->info); break; } cst_lstr ( buffer, &blen, &ier ); sscanf( buffer, "%11d %11d %33c %20c %4s %11d", &id1, &id2, name, unit, abbrev, &scale); name[33] = '\0'; unit[20] = '\0'; abbrev[4] = '\0'; lvltbl->info[n].id1=id1; lvltbl->info[n].id2=id2; strcpy(lvltbl->info[n].name, name); strcpy(lvltbl->info[n].unit, unit); strcpy(lvltbl->info[n].abbrev, abbrev); lvltbl->info[n].scale=scale; n++; } cfl_clos(fp, &ier); }
void shp_rdException ( int *iret ) /************************************************************************ * shp_rdException * * * * This function reads the shape exception table. * * * * void shp_rdException ( iret ) * * * * Input parameters: * * * * Output parameters: * * *iret int Return value * * -1 - Unable to open table * * -2 - Information missing * * * ** * * Log: * * H. Zeng/SAIC 07/07 created * ***********************************************************************/ { int num, ilat, ilon, idx, ier; char tagstr1[128], tagstr2[128], tagstr3[128], tagstr4[128]; char tagstr5[128], tagstr6[128], tagstr7[128], buff[256]; FILE *fp; /*---------------------------------------------------------------------*/ *iret = 0; /* * Open the shape exception table. If not found, return an error. */ fp = cfl_tbop("shpexception.tbl", "stns", &ier); if ( fp == NULL || ier != 0 ) { *iret = -1; return; } /* * Count # of records on the table. */ cfl_tbnr (fp, &_numShpException, &ier); /* * Allocate space for _shpException. */ _shpException = (ShpException_t*) malloc( sizeof(ShpException_t) * _numShpException ); /* * Scan table line-by-line. */ idx = 0; rewind (fp); while ( !feof(fp) ) { cfl_trln(fp, sizeof(buff), buff, &ier); if ( ier != 0 ) continue; num = sscanf (buff, "%s %s %s %s %s %s %s", tagstr1, tagstr2, tagstr3, tagstr4, tagstr5, tagstr6, tagstr7); if ( num != 7 ) continue; if ( sscanf (tagstr6, "%d", &ilat) == 1 && sscanf (tagstr7, "%d", &ilon) == 1 ) { strcpy ( _shpException[idx].id, tagstr1); _shpException[idx].fips = 0; sscanf (tagstr2, "%lu", &(_shpException[idx].fips)); _shpException[idx].clat = ilat * 0.01; _shpException[idx].clon = ilon * 0.01; idx++; } } /* the end of while (... */ cfl_clos(fp, &ier); }
void ctb_permccrd ( char *tblnam, char *dirsym, Permclust_t *pc, int *iret ) /************************************************************************ * ctb_permccrd * * * * This routine will read the permanent clustered county table into a * * structure. * * * * ctb_permccrd ( tblnam, dirsym, pc, iret ) * * * * Input parameters: * * *tblnam char Data type table name * * *dirsym char Directory * * * * Output parameters: * * *pc Permclust_t Perm. clustered cnty structure * * *iret int Return code * ** * * Log: * * A. Hardy/NCEP 10/04 copied from ctb_ccrd * * A. Hardy/NCEP 1/05 Added creation of virtual cluster combos* * & added error check on 1st cst_split * ***********************************************************************/ { FILE *ftbl; char buff[256], pcname[32], *next; int ii, jj, ij, in, inx, numclust, fips[50], nfips, len, ier, ierr; int ik, kk, ll, nn, itotal, srchfip, inum, ivfips, cfips[20]; Boolean found, match; static Permclust_t vpc, tpc; /*---------------------------------------------------------------------*/ *iret = 0; /* * Open the table. */ ftbl = cfl_tbop ( tblnam, dirsym, iret ); if ( *iret != 0 ) { tpc.nclust = 0; return; } /* * Get number of valid table entries. */ cfl_tbnr( ftbl, &numclust, &ier ); if ( numclust != 0 ) { /* * Allocate the structure elements. */ tpc.nclust = numclust; tpc.clust = (PCinfo *) malloc( numclust * sizeof(PCinfo) ); } else { /* * Problem opening table file; set error code and return. */ cfl_clos( ftbl, &ier ); *iret = -2; return; } rewind ( ftbl ); /* * For every valid table entry, read in, parse, put in structure */ ii = 0; while ( ii < numclust ) { cfl_trln( ftbl, sizeof(buff), buff, &ier ); if ( ier == 0 ) { next = cst_split ( buff, '|', 4, tpc.clust[ii].pcwfo, &ier ); if ( ier == 0 ) { next = cst_split ( next, '|', 32, pcname, &ier ); tpc.clust[ii].pcname = (char *)malloc( (strlen(pcname)+1) * sizeof(char) ); strcpy ( tpc.clust[ii].pcname, pcname ); cst_rmbl ( next, next, &len, &ier ); cst_ilst ( next, '+', IMISSD, sizeof(fips)/sizeof(fips[0]), fips, &nfips, &ier ); tpc.clust[ii].npc = nfips; tpc.clust[ii].pc = (int *)malloc( nfips * sizeof(int) ); for ( jj = 0; jj < nfips; jj++ ) { tpc.clust[ii].pc[jj] = fips[jj]; } } else { ierr = 3; er_wmsg ( "CTB", &ierr, buff, &ier, 3, strlen (buff) ); } ii++; } } cfl_clos ( ftbl, &ier ); /* * Create virtual clusters. * Allocate the structure elements. */ vpc.nclust = 0; vpc.clust = (PCinfo *) malloc( (numclust*4) * sizeof(PCinfo) ); inum = vpc.nclust; ii = 0; /* * Loop over all perm clusters. */ while ( ii < numclust ) { for ( jj = 1;jj < tpc.clust[ii].npc; jj++ ) { found = False; srchfip = tpc.clust[ii].pc[jj]; /* * Compare search fip value to the other 1st fips codes. * Search permanent table first. */ ij = 0; while ( (!found) && (ij < numclust ) ) { if ( srchfip == tpc.clust[ij].pc[0] ) { found = True; } ij++; } /* * Search virtual cluster table next. */ ij = 0; while ( (!found) && (ij < vpc.nclust ) ) { if ( srchfip == vpc.clust[ij].pc[0] ) { found = True; } ij++; } /* * Didn't find a cluster group with search fip as first key. * Find all cluster groups in perm. table with this key in * the cluster groups. Create a new virtual cluster entry. */ if ( !found ) { cfips[0] = srchfip; ik = 0; /* Loop over rest of current clustered combo fips * and store the codes temporarily. */ for ( ij = 0; ij < tpc.clust[ii].npc;ij++ ) { if ( tpc.clust[ii].pc[ij] != srchfip ) { ik++; cfips[ik] = tpc.clust[ii].pc[ij]; } } /* Set the number of virtual fips codes we have so far*/ ivfips = ik+1; /* * Check rest of perm clusters combox for srchfip. * Start with the next perm cluster combo. */ inx = ii + 1; match = False; /* loop over rest of combo clusters */ for ( kk= inx; kk < numclust; kk++ ) { /* loop over number of counties in each cluster */ for ( ll = 0; ll < tpc.clust[kk].npc; ll++ ) { /* look for a match in a cluster */ if ( tpc.clust[kk].pc[ll] == srchfip ) { /* store all new codes in cfips array */ for ( nn = 0; nn < tpc.clust[kk].npc; nn++ ) { /* loop over current cluster array, store one's we don't have*/ in = 0; while ( (in < ivfips ) && ( !match) ) { if ( tpc.clust[kk].pc[nn] == cfips[in] ) { match = True; } in++; } /* didn't find fips in cfips array, keep it */ if ( !match ) { cfips[ivfips] = tpc.clust[kk].pc[nn]; ivfips++; } match = False; } } } } /* * Put temporary pcname, pcwfo, npc and fips array into * virtual perm clust. combos. * Increment number of virtual fip cluster combos */ strcpy ( vpc.clust[inum].pcwfo, tpc.clust[ii].pcwfo ); vpc.clust[inum].pcname = (char *)malloc( (strlen(pcname)+1) * sizeof(char) ); /* * Store the number of fips codes and the code numbers */ vpc.clust[inum].npc = ivfips; vpc.clust[inum].pc = (int *)malloc( ivfips * sizeof(int) ); for ( ij= 0; ij < ivfips; ij++ ) { vpc.clust[inum].pc[ij] = cfips[ij]; } vpc.nclust++; inum++; } /* (!found) loop */ } /* for jj loop */ ii++; } /* while ii loop */ /* * Fill out output permanent cluster structure. * Allocate the structure elements. */ itotal = numclust + vpc.nclust; pc->nclust = itotal; pc->clust = (PCinfo *) malloc( itotal * sizeof(PCinfo) ); ii = 0; /* * Write out permanent table cluster combos first. */ while ( ii < numclust ) { strcpy (pc->clust[ii].pcwfo, tpc.clust[ii].pcwfo); pc->clust[ii].pcname = (char *)malloc( (strlen(tpc.clust[ii].pcname)+1) * sizeof(char) ); strcpy ( pc->clust[ii].pcname, tpc.clust[ii].pcname ); pc->clust[ii].npc = tpc.clust[ii].npc; pc->clust[ii].pc = (int *)malloc( tpc.clust[ii].npc * sizeof(int) ); for ( jj = 0; jj < pc->clust[ii].npc; jj++ ) { pc->clust[ii].pc[jj] = tpc.clust[ii].pc[jj]; } ii++; } /* * Write out virtual cluster combos next. */ jj = 0; while ( ii < pc->nclust ) { strcpy (pc->clust[ii].pcwfo, vpc.clust[jj].pcwfo); pc->clust[ii].pcname = (char *)malloc( 12 * sizeof(char) ); sprintf ( pc->clust[ii].pcname, "VClust %d", jj+1 ); pc->clust[ii].npc = vpc.clust[jj].npc; pc->clust[ii].pc = (int *)malloc( vpc.clust[jj].npc * sizeof(int) ); for ( ij = 0; ij < pc->clust[ii].npc; ij++ ) { pc->clust[ii].pc[ij] = vpc.clust[jj].pc[ij]; } ii++; jj++; } }
int main ( int argc , char **argv) /************************************************************************ * main * * * * Main program of naminfo. * * * * This program will create an information file (table) about the * * cities table which has been sorted alphabetically. This information * * is printed out as standard output (via printf) and must be * * re-directed to the proper information file within the script. * * * * main(argc, argv) * * * * Input parameters: * * argc int number of parameters of command line * * argv char** parameter array of command line * * * * Output parameters: * * Return parameters: * * NONE * * * ** * * Log: * * D.W.Plummer/NCEP 12/98 * ***********************************************************************/ { char filename[128], buffer[80], string[512], str[32]; char alphabet[64], ab1, ab2; char c2[3], c2test[3]; int nstart, nlines, reclen, hdrlen, ier; size_t ii, jj; FILE *fptr; /*---------------------------------------------------------------------*/ /* * Print out the name of the (alphabetically sorted) city file. */ strcpy ( filename, argv[1] ); printf("!\n! CITY FILENAME (sorted alphabetically)\n%s\n!\n", filename ); /* * Alphabet characters must be in increasing ASCII order. * Print it out. */ strcpy ( alphabet, "'.1ABCDEFGHIJKLMNOPQRSTUVWXYZ" ); printf("! CHARACTER COMBINATIONS\n%s\n!\n", alphabet ); fptr = (FILE *)cfl_tbop ( filename, "cities", &ier ); cfl_trln ( fptr, sizeof(buffer), buffer, &ier ); reclen = strlen(buffer) + 1; hdrlen = (int)ftell( fptr ) - reclen; /* * Print out header length and (fixed) record length. */ printf("! HEADER LENGTH (bytes)\n%d\n!\n", hdrlen ); printf("! RECORD LENGTH (bytes)\n%d\n!\n", reclen ); /* * Scan the file looking for two-character combinations of * the chars in the alphabet string, ie., AA, AB, AC, AD, etc. * Print out, in sequence, the combination, starting record number * and number of records in format combo/strec/nrec, eg., * AA/strecAA/nrecAA AB/strecAB/nrecAB AC/strecAC/nrecAC etc... */ nstart = 0; nlines = 0; for ( ii = 0; ii < strlen(alphabet); ii++ ) { ab1 = alphabet[ii]; string[0] = '\0'; for ( jj = 0; jj < strlen(alphabet); jj++ ) { ab2 = alphabet[jj]; sprintf( c2, "%c%c", ab1, ab2 ); strncpy ( c2test, buffer, 2 ); nstart = nstart + nlines; nlines = 0; if ( strcmp(c2,c2test) == 0 ) { ier = 0; while ( strcmp(c2,c2test) == 0 && ier == 0 ) { nlines++; cfl_trln ( fptr, sizeof(buffer), buffer, &ier ); if ( ier == 0 ) strncpy ( c2test, buffer, 2 ); } } if ( strlen(string) > 0 ) strcat( string, " " ); sprintf ( str, "%s/%d/%d", c2, nstart, nlines ); strcat( string, str ); if ( strlen(string) > 68 ) { printf("%s\n", string ); string[0] = '\0'; } } if ( strlen(string) > 0 ) { printf("%s\n!\n", string ); } else { printf("!\n"); } } return(0); }
void ces_rtbl ( int *iret ) /************************************************************************ * ces_rtbl * * * * This function reads the setting table and loads the settings * * structure. * * * * ces_rtbl ( iret ) * * * * Input parameters: * * * * Output parameters: * * *iret int Return code * * 2 = Bad read. Ignore record. * * 1 = Setting array siz exceeded* * -1 = No setting table * ** * * Log: * * D. Keiser/GSC 7/97 Rewrote using union structure * * E. Wehner/EAi 8/97 Adopted from cpg_rstng * * C. Lin/EAi 9/97 Change default table name * * G. Krueger/EAI 10/97 CST_xLST: Removed RSPTB; Add str limit * * C. Lin/EAi 10/97 modify to remove cst_clst(), cleanup * * C. Lin/EAi 10/97 modify WBOX_ELM * * M. Linda/GSC 10/97 Corrected the prologue format * * C. Lin/EAi 11/97 use CLASS_WATCHES for WBOX_ELM * * C. Lin/EAi 11/97 add front strength and wind line width * * S. Law/GSC 03/98 Changed scanned values for CLASS_WINDS * * F. J. Yen/NCEP 4/98 Renamed from ces_rstng. Cleaned up. * * F. J. Yen/NCEP 4/98 Set hdsiz for BARB_ELM to 1. * * W. Li/EAI 04/98 Add darr and hash in CLASS_WINDS * * S. Jacobs/NCEP 6/98 Changed front pip size to type float * * W. Li/EAI 07/98 Added txt_attrib's text value setting * * C. Lin/EAI 09/98 Add smoothing level for line/front * * A. Hardy/GSC 10/98 Added CMBSY_ELM * * S. Jacobs/NCEP 12/98 Fixed typo * * A. Hardy/GSC 12/98 Added CIRCLE_ELM * * E. Safford/GSC 02/99 set default for wndtyp to 114 (cleared) * * W. Li/EAI 03/99 added latitude/longitude for symbols * * S. Law/GSC 03/99 added filled/closed = 0 * * W. Li/EAI 04/99 added MARK_ELM, removed lat/long symbol * * S. Law/GSC 05/99 Added CLASS_TRACKS * * S. Law/GSC 07/99 Added CLASS_SIGMETS * * S. Law/GSC 08/99 added remaining SIGMETs * * S. Law/GSC 02/00 added CCF * * H. Zeng/EAI 02/01 added group type info. * * E. Safford/SAIC 02/02 added initialization for new_subtyp * * J. Wu/SAIC 11/02 add class LIST * * M. Li/SAIC 01/03 delete vgstruct.h * * H. Zeng/XTRIA 01/03 added marker info. for Watch * * H. Zeng/XTRIA 03/03 added layer_flag * * D.W.Plummer/NCEP 06/03 added ASHCLD_ELM and VOLC_ELM * * J. Wu/SAIC 09/03 add CLASS_MET -> JET_ELM * * J. Wu/SAIC 01/04 add CLASS_MET -> GFA_ELM * * B. Yin/SAIC 02/04 added CLASS_MET -> TCA_ELM * * J. Wu/SAIC 05/04 add barb/hash color into JET_ELM * * J. Wu/SAIC 05/04 add initialization for "ppid" * * H. Zeng/SAIC 07/04 added check for ialign value * * J. Wu/SAIC 09/04 add text type for jet barb text * * J. Wu/SAIC 10/04 remove line width from GFA_ELM * * T. Piper/SAIC 12/05 redone with new Setting_t structure * * B. Yin/SAIC 12/05 added line width for GFA * * S. Jacobs 03/06 add initialization of special text (bug)* * S. Danz/AWC 04/06 initialized jet->barb[]spt.text * * B. Yin/SAIC 07/06 added line type and line elem for GFA * * L. Hinson/AWC 12/06 added text color, size, font, hw, width * * alignment, and text Layout for GFA * * L. Hinson/AWC 06/07 added arrow size for GFA * * L. Hinson/AWC 07/09 Add color, fills, linetype, szarrow, * * text size, font, hw, width, alignment, * * and text Layout to CCF * * L. Hinson/AWC 01/12 Add CLASS_MET -> SGWX_ELM * ***********************************************************************/ { char tstr[256], vg_classstr[64], vg_typestr[64], tmpstr[256]; int one=1, smooth, loglev, quit, ier1, ier, jj, align_val; int ii, tmpwid[3], tmpclr[3], ityp, ifnt, ithw, ialign, nn; char grp[4], *ptr; float tmpsiz, tmpsz[3]; FILE *fp; /*---------------------------------------------------------------------*/ *iret = G_NORMAL; /* * Open the setting table. If not found, return an error. */ if ( (fp = (FILE * )cfl_tbop(SETTING_TBL, "pgen", &ier)) == NULL) { *iret = -1; loglev = 2; strcpy(grp, "CES"); er_lmsg (&loglev, grp, iret, SETTING_TBL, &ier1, strlen(grp), strlen(SETTING_TBL)); return; } /* * For every line in the setting table list, read in the record, * parse out the fields, and compare to input type. */ jj = num_set = 0; quit = G_FALSE; while ( ( !quit ) && ( jj < MAX_SET ) ) { cfl_trln ( fp, sizeof(tstr), tstr, &ier ); if ( ier == 4 ) { /* * Here for end of file. */ quit = G_TRUE; } else if ( ier != 0 ) { /* * Here for a bad read; record is ignored. */ loglev = 2; strcpy(grp, "CES"); ier = 2; er_lmsg ( &loglev, grp, &ier, SETTING_TBL, &ier1, strlen(grp), strlen(SETTING_TBL) ); } else { /* * Here to process a good record. */ sscanf(tstr, "%s %s", vg_classstr, vg_typestr); num_set++; G_REALLOC(set, Setting_t, num_set, "set"); set[jj].smooth = 0; set[jj].filled = 0; set[jj].closed = 0; /* * +++++++++++++++++++++++++++++++++++++++++++ * HANDLE FRONTS CLASS * +++++++++++++++++++++++++++++++++++++++++++ */ if ( strcmp(vg_classstr, "CLASS_FRONTS" ) == 0 ) { set[jj].vg_class = CLASS_FRONTS; G_MALLOC(set[jj].info.frt, FrontInfo, one, "set[jj].info.frt"); sscanf(tstr, "%*s %*s %d %d %d %d %f %d %d %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &smooth, &tmpsiz, &(set[jj].info.frt->fpipdr), &(set[jj].info.frt->fwidth), set[jj].grp_typ ); set[jj].info.frt->fpipsz = (int)(tmpsiz * 100.0F); set[jj].info.frt->fcode = set[jj].subtyp; set[jj].info.frt->fpipst = 1; if ( smooth < 0 || smooth > 2 ) smooth = 0; set[jj].smooth = smooth; if ( strcmp(vg_typestr, "FRONT_ELM" ) == 0 ) { set[jj].vg_type = FRONT_ELM; } else if ( strcmp(vg_typestr, "-99" ) == 0 ) { set[jj].vg_type = DEFLTSET; } } /* * +++++++++++++++++++++++++++++++++++++++++++ * HANDLE CIRCLE CLASS * +++++++++++++++++++++++++++++++++++++++++++ */ else if ( strcmp(vg_classstr, "CLASS_CIRCLE") == 0 ) { set[jj].vg_class = CLASS_CIRCLE; G_MALLOC(set[jj].info.cir, LineInfo, one, "set[jj].info.cir"); if (strcmp(vg_typestr, "CIRCLE_ELM") == 0) { set[jj].vg_type = CIRCLE_ELM; sscanf(tstr, "%*s %*s %d %d %d %d %d %d %d %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &(set[jj].info.cir->lintyp), &(set[jj].info.cir->lthw), &(set[jj].info.cir->width), &(set[jj].info.cir->lwhw), set[jj].grp_typ ); } } /* * +++++++++++++++++++++++++++++++++++++++++++ * HANDLE LINES CLASS * +++++++++++++++++++++++++++++++++++++++++++ */ else if ( strcmp(vg_classstr, "CLASS_LINES") == 0 ) { set[jj].vg_class = CLASS_LINES; if (strcmp(vg_typestr, "LINE_ELM") == 0) { set[jj].vg_type = LINE_ELM; G_MALLOC(set[jj].info.lin, LineInfo, one, "set[jj].info.lin"); sscanf(tstr, "%*s %*s %d %d %d %d %d %d %d %d %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &smooth, &(set[jj].info.lin->lintyp), &(set[jj].info.lin->lthw), &(set[jj].info.lin->width), &(set[jj].info.lin->lwhw), set[jj].grp_typ ); } else if (strcmp(vg_typestr, "SPLN_ELM") == 0) { set[jj].vg_type = SPLN_ELM; G_MALLOC(set[jj].info.spl, SpLineInfo, one, "set[jj].info.spl"); set[jj].info.spl->splstr = 1; sscanf(tstr, "%*s %*s %d %d %d %d %d %d %f %d %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &smooth, &(set[jj].info.spl->spltyp), &(set[jj].info.spl->spldir), &(set[jj].info.spl->splsiz), &(set[jj].info.spl->splwid), set[jj].grp_typ ); } if (smooth < 0 || smooth > 2) smooth = 0; set[jj].smooth = smooth; } /* * +++++++++++++++++++++++++++++++++++++++++++ * HANDLE SYMBOLS CLASS * +++++++++++++++++++++++++++++++++++++++++++ */ else if ( strcmp(vg_classstr, "CLASS_SYMBOLS") == 0 ) { set[jj].vg_class = CLASS_SYMBOLS; G_MALLOC(set[jj].info.sym, SymType, one, "set[jj].info.sym"); if ( strcmp(vg_typestr, "WXSYM_ELM") == 0) { set[jj].vg_type = WXSYM_ELM; } else if ( strcmp(vg_typestr, "CTSYM_ELM") == 0) { set[jj].vg_type = CTSYM_ELM; } else if ( strcmp(vg_typestr, "ICSYM_ELM") == 0) { set[jj].vg_type = ICSYM_ELM; } else if ( strcmp(vg_typestr, "PTSYM_ELM") == 0) { set[jj].vg_type = PTSYM_ELM; } else if ( strcmp(vg_typestr, "PWSYM_ELM") == 0) { set[jj].vg_type = PWSYM_ELM; } else if ( strcmp(vg_typestr, "SKSYM_ELM") == 0) { set[jj].vg_type = SKSYM_ELM; } else if ( strcmp(vg_typestr, "SPSYM_ELM") == 0) { set[jj].vg_type = SPSYM_ELM; } else if ( strcmp(vg_typestr, "TBSYM_ELM") == 0) { set[jj].vg_type = TBSYM_ELM; } else if ( strcmp(vg_typestr, "CMBSY_ELM") == 0) { set[jj].vg_type = CMBSY_ELM; } else if ( strcmp(vg_typestr, "MARK_ELM" ) == 0 ) { set[jj].vg_type = MARK_ELM; } else if (strcmp(vg_typestr, "-99" ) == 0 ) { set[jj].vg_type = DEFLTSET; } sscanf(tstr, "%*s %*s %d %d %d %d %f %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &(set[jj].info.sym->info.width), &(set[jj].info.sym->info.size), set[jj].grp_typ ); } /* * +++++++++++++++++++++++++++++++++++++++++++ * HANDLE WINDS CLASS * +++++++++++++++++++++++++++++++++++++++++++ */ else if ( strcmp(vg_classstr, "CLASS_WINDS") == 0 ) { set[jj].vg_class = CLASS_WINDS; G_MALLOC(set[jj].info.wnd, WindInfo, one, "set[jj].info.wnd"); if ( strcmp(vg_typestr, "ARROW_ELM") == 0 ) { set[jj].vg_type = ARROW_ELM; sscanf(tstr, "%*s %*s %d %d %d %d %f %f %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &(set[jj].info.wnd->width), &(set[jj].info.wnd->size), &(set[jj].info.wnd->hdsiz), set[jj].grp_typ ); set[jj].info.wnd->wndtyp = 114; } else if ( strcmp(vg_typestr, "BARB_ELM") == 0 ) { set[jj].vg_type = BARB_ELM; sscanf(tstr, "%*s %*s %d %d %d %d %f %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &(set[jj].info.wnd->width), &(set[jj].info.wnd->size), set[jj].grp_typ ); set[jj].info.wnd->hdsiz = 1.0F; set[jj].info.wnd->wndtyp = 114; } else if ( strcmp(vg_typestr, "DARR_ELM") == 0 ) { set[jj].vg_type = DARR_ELM; sscanf(tstr, "%*s %*s %d %d %d %d %f %f %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &(set[jj].info.wnd->width), &(set[jj].info.wnd->size), &(set[jj].info.wnd->hdsiz), set[jj].grp_typ ); set[jj].info.wnd->wndtyp = 114; } else if ( strcmp(vg_typestr, "HASH_ELM") == 0 ) { set[jj].vg_type = HASH_ELM; sscanf(tstr, "%*s %*s %d %d %d %d %f %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &(set[jj].info.wnd->width), &(set[jj].info.wnd->size), set[jj].grp_typ ); set[jj].info.wnd->hdsiz = 1.0F; set[jj].info.wnd->wndtyp = 1; } } /* * +++++++++++++++++++++++++++++++++++++++++++ * HANDLE WBOX CLASS * +++++++++++++++++++++++++++++++++++++++++++ */ else if ( strcmp(vg_classstr, "CLASS_WATCHES") == 0 ) { set[jj].vg_class = CLASS_WATCHES; G_MALLOC(set[jj].info.wbx, WboxAttr, one, "set[jj].info.wbx"); sscanf (tstr, "%*s %*s %d %d %d %d %d %f %d %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &(set[jj].info.wbx->w_type), &(set[jj].info.wbx->w_mrktyp), &(set[jj].info.wbx->w_mrksiz), &(set[jj].info.wbx->w_mrkwid), set[jj].grp_typ ); set[jj].info.wbx->w_number = -9999; if (strcmp(vg_typestr, "WBOX_ELM") == 0) { set[jj].vg_type = WBOX_ELM; } else if (strcmp(vg_typestr, "-99") == 0) { set[jj].vg_type = DEFLTSET; } } /* * +++++++++++++++++++++++++++++++++++++++++++ * HANDLE TEXT CLASS * +++++++++++++++++++++++++++++++++++++++++++ */ else if ( strcmp(vg_classstr, "CLASS_TEXT") == 0 ) { set[jj].vg_class = CLASS_TEXT; if (strcmp(vg_typestr, "TEXT_ELM") == 0) { set[jj].vg_type = TEXT_ELM; G_MALLOC(set[jj].info.txt, TextType, one, "set[jj].info.txt"); sscanf (tstr, "%*s %*s %d %d %d %f %f %d %d %d %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &(set[jj].info.txt->info.rotn), &(set[jj].info.txt->info.sztext), &(set[jj].info.txt->info.itxfn), &(set[jj].info.txt->info.iwidth), &(set[jj].info.txt->info.ialign), set[jj].grp_typ ); set[jj].info.txt->info.ithw = set[jj].subtyp; set[jj].info.txt->text[0] = CHNULL; /* * Make sure ialign value is among (-1, 0, 1). */ align_val = set[jj].info.txt->info.ialign; if ( align_val != -1 && align_val != 0 && align_val != 1 ) { set[jj].info.txt->info.ialign = 0; } } else if (strcmp(vg_typestr, "TEXTC_ELM") == 0) { set[jj].vg_type = TEXTC_ELM; G_MALLOC(set[jj].info.txt, TextType, one, "set[jj].info.txt"); sscanf (tstr, "%*s %*s %d %d %d %f %f %d %d %d %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &(set[jj].info.txt->info.rotn), &(set[jj].info.txt->info.sztext), &(set[jj].info.txt->info.itxfn), &(set[jj].info.txt->info.iwidth), &(set[jj].info.txt->info.ialign), set[jj].grp_typ ); set[jj].info.txt->info.ithw = set[jj].subtyp; set[jj].info.txt->text[0] = CHNULL; /* * Make sure ialign value is among (-1, 0, 1). */ align_val = set[jj].info.txt->info.ialign; if ( align_val != -1 && align_val != 0 && align_val != 1 ) { set[jj].info.txt->info.ialign = 0; } } else if (strcmp(vg_typestr, "SPTX_ELM") == 0) { set[jj].vg_type = SPTX_ELM; G_MALLOC(set[jj].info.spt, SpTxtAttr, one, "set[jj].info.spt"); sscanf (tstr, "%*s %*s %d %d %d %f %f %d %d %d %d %d %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &(set[jj].info.spt->text.info.rotn), &(set[jj].info.spt->text.info.sztext), &(set[jj].info.spt->text.info.turbsym), &(set[jj].info.spt->text.info.itxfn), &(set[jj].info.spt->text.info.ithw), &(set[jj].info.spt->text.info.iwidth), &(set[jj].info.spt->text.info.ialign), set[jj].grp_typ ); set[jj].info.spt->text.info.sptxtyp = set[jj].subtyp; strcpy ( set[jj].info.spt->ppid, DEFLTPPID ); set[jj].info.spt->text.text[0] = CHNULL; /* * Make sure ialign value is among (-1, 0, 1). */ align_val = set[jj].info.spt->text.info.ialign; if ( align_val != -1 && align_val != 0 && align_val != 1 ) { set[jj].info.spt->text.info.ialign = 0; } } } /* * +++++++++++++++++++++++++++++++++++++++++++ * HANDLE TRACKS CLASS * +++++++++++++++++++++++++++++++++++++++++++ */ else if ( strcmp(vg_classstr, "CLASS_TRACKS") == 0 ) { set[jj].vg_class = CLASS_TRACKS; G_MALLOC(set[jj].info.trk, TrackInfo, one, "set[jj].info.trk"); if ( strcmp(vg_typestr, "TRKSTORM_ELM" ) == 0 ) { set[jj].vg_type = TRKSTORM_ELM; } else if ( strcmp(vg_typestr, "-99" ) == 0 ) { set[jj].vg_type = DEFLTSET; } sscanf(tstr, "%*s %*s %d %d %d %d %d %d %d %d %d %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &(set[jj].info.trk->ltype1), &(set[jj].info.trk->ltype2), &(set[jj].info.trk->mtype1), &(set[jj].info.trk->mtype2), &(set[jj].info.trk->width), &(set[jj].info.trk->incr), set[jj].grp_typ ); } /* * +++++++++++++++++++++++++++++++++++++++++++ * HANDLE SIGMETS CLASS * +++++++++++++++++++++++++++++++++++++++++++ */ else if ( strcmp(vg_classstr, "CLASS_SIGMETS") == 0 ) { set[jj].vg_class = CLASS_SIGMETS; if ( strcmp(vg_typestr, "SIGAIRM_ELM" ) == 0 ) { set[jj].vg_type = SIGAIRM_ELM; } else if ( strcmp(vg_typestr, "SIGCONV_ELM" ) == 0 ) { set[jj].vg_type = SIGCONV_ELM; } else if ( strcmp(vg_typestr, "SIGINTL_ELM" ) == 0 ) { set[jj].vg_type = SIGINTL_ELM; } else if ( strcmp(vg_typestr, "SIGNCON_ELM" ) == 0 ) { set[jj].vg_type = SIGNCON_ELM; } else if ( strcmp(vg_typestr, "SIGOUTL_ELM" ) == 0 ) { set[jj].vg_type = SIGOUTL_ELM; } else if ( strcmp(vg_typestr, "SIGCCF_ELM" ) == 0 ) { set[jj].vg_type = SIGCCF_ELM; } else if ( strcmp(vg_typestr, "ASHCLD_ELM" ) == 0 ) { set[jj].vg_type = ASHCLD_ELM; } else if ( strcmp(vg_typestr, "VOLC_ELM" ) == 0 ) { set[jj].vg_type = VOLC_ELM; } else if ( strcmp(vg_typestr, "-99" ) == 0 ) { set[jj].vg_type = DEFLTSET; } if (set[jj].vg_type == SIGCCF_ELM) { G_MALLOC(set[jj].info.ccf, CcfAttr, one, "set[jj].info.ccf"); sscanf(tstr, "%*s %*s %d %d %d %d %d %d %d %d %f %f %d %d %d %d %s %s", &(set[jj].subtyp), &(set[jj].smooth), &(set[jj].maj_col), &(set[jj].min_col), &(set[jj].info.ccf->fillhi), &(set[jj].info.ccf->fillmed), &(set[jj].info.ccf->filllow), &(set[jj].info.ccf->linetype), &(set[jj].info.ccf->szarrow), &(set[jj].info.ccf->info.sztext), &(set[jj].info.ccf->info.itxfn), &(set[jj].info.ccf->info.ithw), &(set[jj].info.ccf->info.iwidth), &(set[jj].info.ccf->info.ialign), set[jj].info.ccf->textLayout, set[jj].grp_typ ); /* printf("subtyp = %d, smooth=%d, maj_col=%d, min_col=%d, fillhi=%d, fillmed=%d, filllow=%d\n", set[jj].subtyp, set[jj].smooth, set[jj].maj_col, set[jj].min_col, set[jj].info.ccf->fillhi, set[jj].info.ccf->fillmed, set[jj].info.ccf->filllow); printf("linetype=%d, szarrow=%f, sztext=%f, itxfn=%d, ithw=%d, iwidth=%d ialign=%d\n", set[jj].info.ccf->linetype, set[jj].info.ccf->szarrow, set[jj].info.ccf->info.sztext, set[jj].info.ccf->info.itxfn, set[jj].info.ccf->info.ithw, set[jj].info.ccf->info.iwidth, set[jj].info.ccf->info.ialign); printf("tlayout=%s grptyp=%s\n",set[jj].info.ccf->textLayout, set[jj].grp_typ); */ } else if (set[jj].vg_type == ASHCLD_ELM) { G_MALLOC(set[jj].info.ash, SigAttr, one, "set[jj].info.ash"); sscanf(tstr, "%*s %*s %d %d %d %d %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &(set[jj].smooth), set[jj].grp_typ ); } else if (set[jj].vg_type == VOLC_ELM) { G_MALLOC(set[jj].info.vol, VolAttr, one, "set[jj].info.vol"); sscanf(tstr, "%*s %*s %d %d %d %d %f %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col),&(set[jj].info.vol->width), &(set[jj].info.vol->size), set[jj].grp_typ ); } else { G_MALLOC(set[jj].info.sig, SigAttr, one, "set[jj].info.sig"); sscanf(tstr, "%*s %*s %d %d %d %d %d %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &(set[jj].info.sig->lintyp), &(set[jj].info.sig->linwid), set[jj].grp_typ ); } } /* * +++++++++++++++++++++++++++++++++++++++++++ * HANDLE LIST CLASS * +++++++++++++++++++++++++++++++++++++++++++ */ else if ( strcmp(vg_classstr, "CLASS_LIST") == 0 ) { set[jj].vg_class = CLASS_LIST; G_MALLOC(set[jj].info.lst, ListInfo, one, "set[jj].info.lst"); if ( strcmp(vg_typestr, "LIST_ELM") == 0 ) { set[jj].vg_type = LIST_ELM; sscanf ( tstr, "%*s %*s %d %d %d %d %f %d %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &(set[jj].info.lst->mrktyp), &(set[jj].info.lst->mrksiz), &(set[jj].info.lst->mrkwid), set[jj].grp_typ ); set[jj].info.lst->subtyp = set[jj].subtyp; } } /* * +++++++++++++++++++++++++++++++++++++++++++ * HANDLE MET CLASS * +++++++++++++++++++++++++++++++++++++++++++ */ else if ( strcmp(vg_classstr, "CLASS_MET") == 0 ) { set[jj].vg_class = CLASS_MET; if ( strcmp(vg_typestr, "JET_ELM") == 0 ) { set[jj].vg_type = JET_ELM; G_MALLOC(set[jj].info.jet, JetInfo, one, "set[jj].info.jet"); /* * Check the number of items in setting.tbl. * ( 22 - version 5.7.4 & later; 21 for earlier versions. */ strcpy ( tmpstr, tstr ); cst_nocc ( tmpstr, '!', 1, 0, &nn, &ier ); if ( ier == 0 ) { tmpstr[nn] = '\0'; cst_lstr ( tmpstr, &nn, &ier ); tmpstr[nn] = '\0'; } nn = 0; ptr = strtok ( tmpstr, " " ); while ( (ptr != (char *)NULL) ) { ptr = strtok ( NULL, " " ); nn++; } if ( nn < 22 ) { /* Version 5.7.3 & before */ sscanf ( tstr, "%*s %*s %d %d %d %d %d %f %d %d %f %d %f %d %d %d %d %d %f %d %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &smooth, &(set[jj].info.jet->line.spltyp), &(set[jj].info.jet->line.splsiz), &(set[jj].info.jet->line.splwid), &tmpclr[0], &tmpsz[0], &tmpwid[0], /* Barb */ &tmpsz[1], &ifnt, &ithw, &tmpwid[1], &ialign, /* Text */ &tmpclr[1], &tmpsz[2], &tmpwid[2], /* Hash */ set[jj].grp_typ ); ityp = 0; } else { /* Version 5.7.4 and later */ sscanf ( tstr, "%*s %*s %d %d %d %d %d %f %d %d %f %d %d %f %d %d %d %d %d %f %d %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &smooth, &(set[jj].info.jet->line.spltyp), &(set[jj].info.jet->line.splsiz), &(set[jj].info.jet->line.splwid), &tmpclr[0], &tmpsz[0], &tmpwid[0], /* Barb */ &ityp, &tmpsz[1], &ifnt, &ithw, &tmpwid[1], &ialign, /* Text */ &tmpclr[1], &tmpsz[2], &tmpwid[2], /* Hash */ set[jj].grp_typ ); } if (smooth < 0 || smooth > 2) smooth = 0; set[jj].smooth = smooth; set[jj].info.jet->splcol = set[jj].maj_col; set[jj].info.jet->line.splstr = 1; set[jj].info.jet->line.spldir = 0; for ( ii = 0; ii < MAX_JETPTS; ii++ ) { set[jj].info.jet->barb[ii].wndcol = tmpclr[0]; set[jj].info.jet->barb[ii].wnd.info.size = tmpsz[0]; set[jj].info.jet->barb[ii].wnd.info.width = tmpwid[0]; set[jj].info.jet->barb[ii].wnd.info.wndtyp = 114; set[jj].info.jet->barb[ii].wnd.info.hdsiz = 1.0F; set[jj].info.jet->barb[ii].sptcol = tmpclr[0]; set[jj].info.jet->barb[ii].spt.info.sztext = tmpsz[1]; set[jj].info.jet->barb[ii].spt.info.itxfn = ifnt; set[jj].info.jet->barb[ii].spt.info.ithw = ithw; set[jj].info.jet->barb[ii].spt.info.iwidth = tmpwid[1]; set[jj].info.jet->barb[ii].spt.info.ialign = ialign; set[jj].info.jet->barb[ii].spt.info.rotn = 0.0F; set[jj].info.jet->barb[ii].spt.info.sptxtyp = ityp; set[jj].info.jet->barb[ii].spt.info.turbsym = 0; set[jj].info.jet->barb[ii].spt.info.txtcol = tmpclr[0]; set[jj].info.jet->barb[ii].spt.info.filcol = tmpclr[0]; set[jj].info.jet->barb[ii].spt.info.lincol = tmpclr[0]; set[jj].info.jet->barb[ii].spt.text[0] = CHNULL; set[jj].info.jet->hash[ii].wndcol = tmpclr[1]; set[jj].info.jet->hash[ii].wnd.info.size = tmpsz[2]; set[jj].info.jet->hash[ii].wnd.info.width = tmpwid[2]; set[jj].info.jet->hash[ii].wnd.info.wndtyp = 1; set[jj].info.jet->hash[ii].wnd.info.hdsiz = 1.0F; } } else if ( strcmp(vg_typestr, "GFA_ELM") == 0 ) { set[jj].vg_type = GFA_ELM; G_MALLOC(set[jj].info.gfa, GfaAttr, one, "set[jj].info.gfa"); sscanf(tstr, "%*s %*s %d %d %d %d %d %d %f %d %f %d %d %d %d %s %s", &(set[jj].subtyp), &(set[jj].maj_col), &(set[jj].min_col), &(set[jj].info.gfa->linelm), &(set[jj].info.gfa->lintyp),&(set[jj].info.gfa->linwid), &(set[jj].info.gfa->szarrow), &(set[jj].info.gfa->info.txtcol), &(set[jj].info.gfa->info.sztext), &(set[jj].info.gfa->info.itxfn), &(set[jj].info.gfa->info.ithw), &(set[jj].info.gfa->info.iwidth), &(set[jj].info.gfa->info.ialign), set[jj].info.gfa->textLayout, set[jj].grp_typ ); } else if ( strcmp(vg_typestr, "SGWX_ELM") == 0 ) { set[jj].vg_type = SGWX_ELM; G_MALLOC(set[jj].info.sgwx, SgwxAttr, one, "set[jj].info.sgwx"); sscanf(tstr, "%*s %*s %d %d %d %d %d %d %d %f %f %d %d %d %d %s", &(set[jj].subtyp), &(set[jj].smooth), &(set[jj].maj_col), &(set[jj].min_col), &(set[jj].info.sgwx->lineelm), &(set[jj].info.sgwx->linetype), &(set[jj].info.sgwx->linewidth), &(set[jj].info.sgwx->szarrow), &(set[jj].info.sgwx->info.sztext), &(set[jj].info.sgwx->info.itxfn), &(set[jj].info.sgwx->info.ithw), &(set[jj].info.sgwx->info.iwidth), &(set[jj].info.sgwx->info.ialign), set[jj].grp_typ ); } else if ( strcmp(vg_typestr, "TCA_ELM") == 0 ) { set[jj].vg_type = TCA_ELM; G_MALLOC(set[jj].info.tca, TcaInfo, one, "set[jj].info.tca"); sscanf(tstr, "%*s %*s %d %d %d %d %s", &set[jj].subtyp, &set[jj].maj_col, &set[jj].min_col, &set[jj].info.tca->wwNum, set[jj].grp_typ ); } } /* * ++++++++++++++++++++++++++++++++++++++++++++++++++++++ * DIDN'T RECOGNIZE THE CLASS; BAD READ, IGNORE RECORD * ++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ else { *iret = 2; loglev = 2; strcpy(grp, "CES"); er_lmsg (&loglev, grp, iret, SETTING_TBL, &ier1, strlen(grp), strlen(SETTING_TBL)); } /* * Set layer_flag according to set[jj].grp_typ */ cst_lcuc(set[jj].grp_typ, set[jj].grp_typ, &ier1); if ( strstr ( set[jj].grp_typ, "/LAYER" ) != NULL ) { set[jj].cds_or_ces.layer_flag = TRUE; } else { set[jj].cds_or_ces.layer_flag = FALSE; } /* * Increment jj */ jj++; } } if ( !quit ) { /* * Setting array (set) size exceeded. MAX_SET should * be increased. */ *iret = 1; loglev = 2; strcpy(grp, "CES"); er_lmsg (&loglev, grp, iret, SETTING_TBL, &ier1, strlen(grp), strlen(SETTING_TBL)); } /* close the settings file */ cfl_clos(fp, &ier); }
static void clo_rdtcabkpts( Stn_t *stn, FILE *fp, char *alias, int numstn, int *iret ) /************************************************************************ * clo_rdtcabkpts * * * * This function loads break point table information into the standard * * station information structure. * * * * * * void clo_rdtcabkpts( stn, fp, alias, numstn, iret ) * * * * Input parameters: * * *stn Stn_t station structure to fill * * *fp FILE FILE pointer to the table file * * *alias char alias name of the table * * numstn int total number of stations in the table * * * * Output parameters: * * *iret int Return code * ** * * Log: * * B. Yin/SAIC 7/04 Created * * m.gamazaychikov 01/05 Corrected for proper column reading * * D. Kidwell/NCEP 4/05 Added pri = 99 check for supplemental * ***********************************************************************/ { char buff[120]; char id[9], desc[64], state[8], cntry[8], c10[21]="\0", tmpstr[128]; int counter, ier, lat, lon, stnm, elv, pri; /*------------------------------------------------------------------------*/ counter = 0; ier = 0; while ( counter < numstn && ier != 4 ) { /* ier = 4 EOF */ cfl_trln(fp, sizeof(buff), buff, &ier); if ( ier == 0 ) { id[ 0 ] = '\0'; desc[ 0 ] = '\0'; state[ 0 ] = '\0'; cntry[ 0 ] = '\0'; c10[ 0 ] = '\0'; stnm = 0; lat = 9999; lon = 9999; elv = 9999; pri = 9999; strncpy( tmpstr, &buff[55], 21 ); tmpstr[21]='\0'; sscanf( tmpstr, "%d %d %d %d", &lat, &lon, &elv, &pri ); if ( ( ( strcmp( alias, "TCA_BKPTS_OFF" ) == 0 && pri % 10 == 0 && pri != 80 && pri != 50 ) /* official break points */ ||( strcmp( alias, "TCA_BKPTS_SUP" ) == 0 && (( pri == 19 ) || ( pri == 99 ) ||( pri % 10 == 0 && pri != 80 && pri != 50))) /* supplemental */ ||( strcmp( alias, "TCA_BKPTS_WAT" ) == 0 && pri == 80 ) /* water */ ||( strcmp( alias, "TCA_BKPTS_ISL" ) == 0 && pri == 50 ) ) ){ /* islands */ stn->station[counter].lat = (float)lat / 100.0F; stn->station[counter].lon = (float)lon / 100.0F; stn->station[counter].elv = elv; stn->station[counter].pri = pri; strncpy( tmpstr, buff, 8 ); tmpstr[8]='\0'; sscanf( tmpstr, "%s", id ); stn->station[counter].id = (char *)malloc(sizeof(char)*strlen(id)+1); strcpy( stn->station[counter].id, id ); strncpy( tmpstr, &buff[9], 6 ); tmpstr[6]='\0'; sscanf( tmpstr, "%d", &stnm ); stn->station[counter].nm = stnm; strncpy( tmpstr, &buff[16], 32 ); tmpstr[32]='\0'; sscanf( tmpstr, "%s", desc ); stn->station[counter].desc = (char *)malloc(sizeof(char)*strlen(desc)+1); cst_lcuc ( desc, stn->station[counter].desc, &ier ); strncpy( tmpstr, &buff[49], 2 ); tmpstr[2]='\0'; sscanf( tmpstr, "%s", state ); stn->station[counter].state=(char *)malloc(sizeof(char)*strlen(state)+1); strcpy( stn->station[counter].state, state ); strncpy( tmpstr, &buff[52], 2 ); tmpstr[2]='\0'; sscanf( tmpstr, "%s", cntry ); stn->station[counter].cntry=(char *)malloc(sizeof(char)*strlen(cntry)+1); strcpy( stn->station[counter].cntry, cntry ); strncpy( tmpstr, &buff[76], 20 ); tmpstr[20]='\0'; sscanf( tmpstr, "%s", c10 ); stn->station[counter].col10 = (char *)malloc(sizeof(char)*strlen(c10)+1); strcpy( stn->station[counter].col10, c10 ); counter++; } } } stn->nstn = counter; /* * Free extra memory */ stn->station = (SInfo_t *) realloc( stn->station, (size_t)counter * sizeof(SInfo_t) ); *iret = 0; }