void vfgname ( int *iret ) /************************************************************************ * vfgname * * * * This function gets the station information for the anchor points. * * * * vfgname ( iret ) * * * * Input parameters: * * * * Output parameters: * * *iret int Return Code * * * ** * * Log: * * A. Hardy/GSC 8/99 Created * * A. Hardy/GSC 11/99 Removed unused variables * * A. Hardy/GSC 01/00 Changed type from int to char * * A. Hardy/GSC 2/00 Extracted from SPCTXT * * A. Hardy/GSC 5/00 Removed FILE declarations * * A. Hardy/GSC 5/01 Initialized iret to 0 * * R. Tian/SAIC 7/03 Changed to call cst_gtag * ***********************************************************************/ { char stninfo[128]; char hunt[1], type[7]; int ier, nstns, maxlen, isrch; /*-------------------------------------------------------------------*/ *iret = 0; ier = 0; strcpy (type, "ANCHOR"); hunt[0] = '\0'; maxlen = sizeof(stninfo); isrch = 1; /* * Find the first point's information. */ clo_init ( &ier ); clo_findstn ( type, spcinfo.ancrpt.stn1, hunt, isrch, maxlen, &nstns, stninfo, &ier ); cst_gtag ( "NAME", stninfo, " ", spcinfo.ancrpt.stnnam1, &ier ); cst_gtag ( "ST", stninfo, " ", spcinfo.ancrpt.stateid1, &ier ); /* * Find the second point's information. */ clo_findstn ( type, spcinfo.ancrpt.stn2, hunt, 1, maxlen, &nstns, stninfo, &ier); cst_gtag ( "NAME", stninfo, " ", spcinfo.ancrpt.stnnam2, &ier ); cst_gtag ( "ST", stninfo, " ", spcinfo.ancrpt.stateid2, &ier ); }
void plot_slsc ( int *cval, int *nfips) { int bindex, ier; int col1, col2, ltype, lwidth, ifltyp; float szfil=0.5; char srchstr[30]; extern gpwarn_config_type gpwarn_config[]; clo_init(&ier); bindex = clo_which("CNTY_BNDS"); sprintf(srchstr,"<FIPS>%d<\0",*nfips); col1 = gpwarn_config[*cval].current_fill_color; col2 = gpwarn_config[*cval].current_line_color; ltype = gpwarn_config[*cval].current_line_type; lwidth = gpwarn_config[*cval].current_line_width; ifltyp = gpwarn_config[*cval].current_fill_type; gsfill(&szfil,&ifltyp,&ier); clo_off(srchstr, bindex, col1, col2, ltype, lwidth); }
int main ( int argc, char **argv ) /************************************************************************ * clipvgf * * * * This program clips elements in a VGF file based on a bounds * * specification. By default, a simple clipping algorithm is used * * where element points either inside or outside the polygon are kept * * or thrown away based on an input flag. Alternatively, an exact * * algorithm may be requested which clips precisely at the borders. * * * * The bound definition must be in the format: * * bound_name|<area_tag_name>area_tag_value * * and must be enclosed w/ quotes so the shell will ignore directives. * * * * Examples: * * clipvgf input.vgf "STATE_BNDS|<STATE>WY" keep output.vgf rough * * clipvgf input.vgf "STATE_BNDS|<STATE>WY" keep output.vgf exact * * Where "rough" uses the simple clipping algorithm and "exact" yields * * precise clipping at the bounds borders. * * * * The following element classes are not processed: * * CLASS_WATCHES, CLASS_TRACKS, CLASS_SIGMETS * * * * 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 2/02 * * D.W.Plummer/NCEP 5/02 Added exact clipping and label moving * * D.W.Plummer/NCEP 8/02 Account for text grouped with symbol * * D.W.Plummer/NCEP 8/02 Create output VGF, even if it is empty * * H. Zeng/XTRIA 02/03 converted CLASS_CIRCLE to CLASS LINES * * D.W.Plummer/NCEP 8/03 Bug fix - add pt to closed lines * * R. Tian/SAIC 11/04 Added clip jet element * * S. Danz/AWC 07/06 Update to new cvg_writef() parameter * * T. Piper/SAIC 03/07 Added ninout-- for closed line case * * L. Hinson/AWC 07/07 Added clip code for GFA elements * * L. Hinson/AWC 07/07 Add recalcGFAtLblArwLoc function * for GFA elements * * X.Guo/CWS 10/10 Bug fix - Low level graphic don't make * * it all the way north in central US * * L. Hinson/AWC 09/13 Fixed improperly clipped JET_ELM Barbs * * and hashes * ***********************************************************************/ { int ii, jj, ip, ibeg, iend, loc, ne, found, found_txt, joffset, kept, ier; int wrtflg, pagflg; int minpts, maxpts, npts, numpts, npoly; char vg_class, vg_type; char bnd[128], keep[32], bnd_name[64], bnd_tag[64]; char infile[128], ifname[128], outfile[128]; char *cptr; long ifilesize; int more, curpos; float flat, flon, filt, px[LLMXPT], py[LLMXPT]; float plat[LLMXPT], plon[LLMXPT], *ptrlat, *ptrlon; float tlat[LLMXPT], tlon[LLMXPT]; float fltmin, fltmax, flnmin, flnmax; int inout[LLMXPT], tinout[LLMXPT]; char device[8], dfilnam[128], pro[32]; float xsize, ysize, lllat, lllon, urlat, urlon; float prjang1, prjang2, prjang3; int mode, istat, iunit, itype; char errgrp[8]; int ninout; float xinout[LLMXPT], yinout[LLMXPT]; char precision[8]; int tltpts, nbarb, nhash; int tmaxpts, tnpts, tnclip; char hazList[ STD_STRLEN ]; VG_DBStruct el, el_t, el_q, el_lin; FILE *ifptr; int ninxarr, inxarr[100]; /*---------------------------------------------------------------------*/ /* * First check if number of input arguments is correct. */ if ( argc < 5 ) { pagflg = G_FALSE; strcpy ( errgrp, "CLIPVGF" ); ip_help ( errgrp, &pagflg, &ier, strlen(errgrp) ); exit (0); } /* * First input on command line is input vgf file name. */ strcpy ( infile, argv[1] ); wrtflg = 0; cvg_open ( infile, wrtflg, &(ifptr), &ier ); if ( ier != 0 ) { printf("Error opening VGF file %s\n", infile ); exit (0); } cfl_inqr ( infile, NULL, &ifilesize, ifname, &ier ); /* * Second input on command line is bounds name. */ clo_init ( &ier ); strcpy ( bnd, argv[2] ); cptr = cst_split( bnd, '|', sizeof(bnd_name), bnd_name, &ier ); clo_bstype ( bnd_name, &ier ); if ( ier != 0 ) { printf("Error finding bounds type %s\n", bnd_name ); exit (0); } if ( cptr != (char *)NULL ) { strcpy ( bnd_tag, cptr ); clo_bstag ( bnd_tag, &ier ); } fltmin = -90.0F; fltmax = 90.0F; flnmin = -180.0F; flnmax = 180.0F; clo_bsarea ( &fltmin, &flnmin, &fltmax, &flnmax, &ier ); minpts = 3; maxpts = sizeof(px)/sizeof(float); filt = 0.0F; clo_bgnext ( &minpts, &maxpts, &filt, &npoly, px, py, &ier ); if ( ier < 0 ) { printf("Error retrieving bound area %s|%s\n", bnd_name, bnd_tag ); exit (0); } /* * Third input on command line is keep flag. */ strcpy ( keep, argv[3] ); /* * Fourth input on command line is output vgf file name; create it. */ strcpy ( outfile, argv[4] ); cvg_crvgf ( outfile, &ier ); /* * Fifth input on command line is clip precision = "rough" or "exact" */ if ( argv[5] != (char *)NULL ) strcpy ( precision, argv[5] ); else strcpy ( precision, "ROUGH" ); cst_lcuc ( precision, precision, &ier ); /* * All input checks out OK; set up GAREA and PROJ for inpoly. */ mode = 1; ginitp ( &mode, &istat, &ier ); strcpy ( device, "GN" ); iunit = 1; strcpy ( dfilnam, "CLIPVGF" ); itype = 1; xsize = 500.0F; ysize = 500.0F; gsdeva ( device, &iunit, dfilnam, &itype, &xsize, &ysize, &ier, strlen(device), strlen(dfilnam)); /* * Something more sophisticated may be needed here in the future * to set up a proper proj and garea based on the clip area. * For instance, the following definitions probably won't work * on a clipping bound equivalent to Antartica. */ lllat = 0.0F; lllon = -135.0F; urlat = 0.0F; urlon = 45.0F; strcpy ( pro, "str" ); prjang1 = 90.0F; prjang2 = -105.0F; prjang3 = 0.0F; gsmprj ( pro, &prjang1, &prjang2, &prjang3, &lllat, &lllon, &urlat, &urlon, &ier, strlen(pro)); /* * Loop through all the elements to set the range records. */ crg_init ( &ier ); ne = 0; more = G_TRUE; curpos = 0; ifptr = (FILE *) cfl_ropn(ifname, "", &ier); while ( ne < MAX_EDITABLE_ELEMS && more == G_TRUE ) { cvg_rdrecnoc ( ifname, ifptr, curpos, &el, &ier ); if ( ier < 0 ) { more = G_FALSE; } else { crg_set ( &el, curpos, 1, &ier ); curpos += el.hdr.recsz; ne++; } } cfl_clos ( ifptr, &ier ); /* * Loop through all the elements. */ ne = 0; more = G_TRUE; curpos = 0; ifptr = (FILE *) cfl_ropn(ifname, "", &ier); while ( ne < MAX_EDITABLE_ELEMS && more == G_TRUE ) { cvg_rdrecnoc( ifname, ifptr, curpos, &el, &ier ); if ( ier < 0 ) { more = G_FALSE; } else if ( el.hdr.recsz > 0 ) { crg_gginx( el.hdr.grptyp, el.hdr.grpnum, sizeof(inxarr)/sizeof(inxarr[0]), inxarr, &ninxarr, &ier ); /* * Increment file pointer now because element hdrsz may change. */ curpos += el.hdr.recsz; vg_class = el.hdr.vg_class; vg_type = el.hdr.vg_type; switch ( (int)vg_class ) { case CLASS_SYMBOLS: case CLASS_TEXT: case CLASS_WINDS: case CLASS_COMSYM: case CLASS_MARKER: switch ( (int)vg_type ) { case TEXT_ELM: case TEXTC_ELM: flat = el.elem.txt.info.lat; flon = el.elem.txt.info.lon; break; case SPTX_ELM: flat = el.elem.spt.info.lat; flon = el.elem.spt.info.lon; break; case BARB_ELM: case ARROW_ELM: case DARR_ELM: case HASH_ELM: flat = el.elem.wnd.data.latlon[0]; flon = el.elem.wnd.data.latlon[1]; break; case WXSYM_ELM: case CTSYM_ELM: case ICSYM_ELM: case PTSYM_ELM: case PWSYM_ELM: case SKSYM_ELM: case SPSYM_ELM: case TBSYM_ELM: case MARK_ELM: case CMBSY_ELM: flat = el.elem.sym.data.latlon[0]; flon = el.elem.sym.data.latlon[1]; break; } npts = 1; cgr_inpoly ( "M", &npts, &flat, &flon, "M", &npoly, px, py, inout, &ier ); if ( ( inout[0] == 1 && strcmp(keep,"keep") == 0 ) || ( inout[0] == 0 && strcmp(keep,"keep") != 0 ) ) { /* * Check if element is TEXT grouped with a SYMBOL. If this text was going * to be kept but it's symbol was going to be throw away, throw it away also. */ if ( (int)vg_class == CLASS_TEXT && (int)el.hdr.grptyp != 0 && ninxarr > 1 ) { found = G_FALSE; ii = 0; while ( ii < ninxarr && found == G_FALSE ) { crg_goffset ( inxarr[ii], &joffset, &ier ); cvg_rdrecnoc( ifname, ifptr, joffset, &el_q, &ier ); if ( el_q.hdr.vg_class == CLASS_SYMBOLS ) { found = G_TRUE; flat = el_q.elem.sym.data.latlon[0]; flon = el_q.elem.sym.data.latlon[1]; npts = 1; cgr_inpoly ( "M", &npts, &flat, &flon, "M", &npoly, px, py, inout, &ier ); if ((inout[0] == 1 && strcmp(keep,"keep") == 0) || (inout[0] == 0 && strcmp(keep,"keep") != 0)) { cvg_writef( &el, -1, el.hdr.recsz, outfile, FALSE, &loc, &ier ); kept = G_TRUE; } else { kept = G_FALSE; } } ii++; } if ( found == G_FALSE ) { cvg_writef( &el, -1, el.hdr.recsz, outfile, FALSE, &loc, &ier ); kept = G_TRUE; } } else { /* * non-TEXT -- keep it. */ cvg_writef( &el, -1, el.hdr.recsz, outfile, FALSE, &loc, &ier ); kept = G_TRUE; } } else { /* * Element is not to be kept. */ kept = G_FALSE; } /* * Check if element was kept and is a SYMBOL element grouped with TEXT; * make sure any text elements are saved off they were going to be thrown away. */ if ( kept == G_TRUE && (int)vg_class == CLASS_SYMBOLS && (int)el.hdr.grptyp != 0 && ninxarr > 1 ) { ii = 0; while ( ii < ninxarr ) { crg_goffset ( inxarr[ii], &joffset, &ier ); cvg_rdrecnoc( ifname, ifptr, joffset, &el_q, &ier ); if ( el_q.hdr.vg_class == CLASS_TEXT ) { el_t = el_q; switch ( (int)el_t.hdr.vg_type ) { case TEXT_ELM: case TEXTC_ELM: flat = el_t.elem.txt.info.lat; flon = el_t.elem.txt.info.lon; break; case SPTX_ELM: flat = el_t.elem.spt.info.lat; flon = el_t.elem.spt.info.lon; break; } npts = 1; cgr_inpoly ( "M", &npts, &flat, &flon, "M", &npoly, px, py, inout, &ier ); if ( ( kept == G_TRUE ) && ( ( inout[0] == 1 && strcmp(keep,"keep") == 0 ) || ( inout[0] == 0 && strcmp(keep,"keep") != 0 ) ) ) { } else { cvg_writef ( &el_t, -1, el_t.hdr.recsz, outfile, FALSE, &loc, &ier ); } } ii++; } } break; case CLASS_CIRCLE: case CLASS_LINES: case CLASS_FRONTS: /* * convert a circle element to a line element */ if ( vg_class == CLASS_CIRCLE ) { cvg_cir2lin ( &el, 10, &el_lin, &ier ); el = el_lin; vg_class = el.hdr.vg_class; vg_type = el.hdr.vg_type; } switch ( (int)vg_type ) { case LINE_ELM: npts = el.elem.lin.info.numpts; ptrlat = &(el.elem.lin.latlon[ 0]); ptrlon = &(el.elem.lin.latlon[npts]); break; case SPLN_ELM: npts = el.elem.spl.info.numpts; ptrlat = &(el.elem.spl.latlon[ 0]); ptrlon = &(el.elem.spl.latlon[npts]); break; case FRONT_ELM: npts = el.elem.frt.info.numpts; ptrlat = &(el.elem.frt.latlon[ 0]); ptrlon = &(el.elem.frt.latlon[npts]); break; } memcpy ( plat, ptrlat, (size_t)npts*sizeof(float) ); memcpy ( plon, ptrlon, (size_t)npts*sizeof(float) ); if ( el.hdr.closed == 1 ) { plat[npts] = plat[0]; plon[npts] = plon[0]; npts++; } if ( strcmp(precision,"EXACT") == 0 ) { clip_line ( npoly, px, py, npts, plat, plon, (int)el.hdr.closed, sizeof(xinout)/sizeof(float), &ninout, xinout, yinout, inout, &ier ); } else if ( strcmp(precision,"ROUGH") == 0 ) { cgr_inpoly ( "M", &npts, plat, plon, "M", &npoly, px, py, inout, &ier ); ninout = npts; memcpy ( xinout, plat, (size_t)ninout*sizeof(float) ); memcpy ( yinout, plon, (size_t)ninout*sizeof(float) ); } /* * If element is closed, and some points are to be kept and others are not, * then rotate the locations arrays such that a transition point is the first point. */ if ( el.hdr.closed == 1 ) { ip = 0; ninout--; while ( inout[ip] == inout[0] && ip < ninout ) ip++; if ( ip != ninout ) { if (( inout[0] == 1 && strcmp(keep,"keep") == 0 ) || ( inout[0] == 0 && strcmp(keep,"keep") != 0 ) ) { memcpy ( tlat, xinout, (size_t)ninout*sizeof(float) ); memcpy ( tlon, yinout, (size_t)ninout*sizeof(float) ); memcpy ( tinout, inout, (size_t)ninout*sizeof(float) ); for ( ii = 0; ii < ninout; ii++ ) { xinout[ii] = tlat[(ii+ip) % ninout]; yinout[ii] = tlon[(ii+ip) % ninout]; inout[ii] = tinout[(ii+ip) % ninout]; } } } } ip = 0; while ( ip < ninout ) { ibeg = ip; iend = ip; while ( inout[ip] == inout[ibeg] && ip < ninout ) ip++; iend = ip - 1; numpts = iend - ibeg + 1; /* * If element is closed, and some points are to be kept and others are not, * then reset the closed flag. */ if ( el.hdr.closed == 1 && numpts != ninout ) el.hdr.closed = 0; if ( numpts > 1 ) { if (( inout[ibeg] == 1 && strcmp(keep,"keep") == 0 ) || ( inout[ibeg] == 0 && strcmp(keep,"keep") != 0 ) ) { switch ( (int)vg_type ) { case LINE_ELM: el.elem.lin.info.numpts = numpts; ptrlat = &(el.elem.lin.latlon[ 0]); ptrlon = &(el.elem.lin.latlon[numpts]); el.hdr.recsz = ( (int)((sizeof(float) * 2 * (size_t)numpts) + sizeof(VG_HdrStruct) + sizeof(LineInfo) )); break; case SPLN_ELM: el.elem.spl.info.numpts = numpts; ptrlat = &(el.elem.spl.latlon[ 0]); ptrlon = &(el.elem.spl.latlon[numpts]); el.hdr.recsz = ( (int)((sizeof(float) * 2 * (size_t)numpts) + sizeof(VG_HdrStruct) + sizeof(SpLineInfo) )); break; case FRONT_ELM: el.elem.frt.info.numpts = numpts; ptrlat = &(el.elem.frt.latlon[ 0]); ptrlon = &(el.elem.frt.latlon[numpts]); el.hdr.recsz = ( (int)((sizeof(float) * 2 * (size_t)numpts) + sizeof(VG_HdrStruct) + sizeof(FrontInfo) )); break; } memcpy(ptrlat, &(xinout[ibeg]), (size_t)numpts*sizeof(float)); memcpy(ptrlon, &(yinout[ibeg]), (size_t)numpts*sizeof(float)); cvg_writef ( &el, -1, el.hdr.recsz, outfile, FALSE, &loc, &ier ); if ( (int)el.hdr.grptyp != 0 && ninxarr > 1 ) { found = G_FALSE; found_txt = G_FALSE; ii = 0; while ( ii < ninxarr && found == G_FALSE ) { crg_goffset ( inxarr[ii], &joffset, &ier ); cvg_rdrecnoc( ifname, ifptr, joffset, &el_q, &ier ); if ( el_q.hdr.vg_class == CLASS_TEXT ) { found_txt = G_TRUE; el_t = el_q; switch ( (int)el_t.hdr.vg_type ) { case TEXT_ELM: case TEXTC_ELM: flat = el_t.elem.txt.info.lat; flon = el_t.elem.txt.info.lon; break; case SPTX_ELM: flat = el_t.elem.spt.info.lat; flon = el_t.elem.spt.info.lon; break; } npts = 1; cgr_inpoly ( "M", &npts, &flat, &flon, "M", &npoly, px, py, inout, &ier ); if ( ( inout[0] == 1 && strcmp(keep,"keep") == 0 ) || ( inout[0] == 0 && strcmp(keep,"keep") != 0 ) ) { found = G_TRUE; break; } } ii++; } if ( found == G_FALSE && ii == ninxarr && found_txt == G_TRUE ) { switch ( (int)vg_type ) { case LINE_ELM: flat = ( el.elem.lin.latlon[0] + el.elem.lin.latlon[1] ) / 2.0F; flon = ( el.elem.lin.latlon[numpts] + el.elem.lin.latlon[numpts+1] ) / 2.0F; break; case SPLN_ELM: flat = ( el.elem.spl.latlon[0] + el.elem.spl.latlon[1] ) / 2.0F; flon = ( el.elem.spl.latlon[numpts] + el.elem.spl.latlon[numpts+1] ) / 2.0F; break; case FRONT_ELM: flat = ( el.elem.frt.latlon[0] + el.elem.frt.latlon[1] ) / 2.0F; flon = ( el.elem.frt.latlon[numpts] + el.elem.frt.latlon[numpts+1] ) / 2.0F; break; } switch ( (int)el_t.hdr.vg_type ) { case TEXT_ELM: case TEXTC_ELM: el_t.elem.txt.info.lat = flat; el_t.elem.txt.info.lon = flon; break; case SPTX_ELM: el_t.elem.spt.info.lat = flat; el_t.elem.spt.info.lon = flon; break; } cvg_writef ( &el_t, -1, el_t.hdr.recsz, outfile, FALSE, &loc, &ier ); } } } } } break; case CLASS_MET: switch ( (int)vg_type ) { case JET_ELM: npts = tltpts = el.elem.jet.line.spl.info.numpts; ptrlat = &(el.elem.jet.line.spl.latlon[ 0]); ptrlon = &(el.elem.jet.line.spl.latlon[npts]); memcpy ( plat, ptrlat, (size_t)npts*sizeof(float) ); memcpy ( plon, ptrlon, (size_t)npts*sizeof(float) ); if ( strcmp(precision,"EXACT") == 0 ) { clip_line ( npoly, px, py, npts, plat, plon, (int)el.hdr.closed, sizeof(xinout)/sizeof(float), &ninout, xinout, yinout, inout, &ier ); } else if ( strcmp(precision,"ROUGH") == 0 ) { cgr_inpoly ( "M", &npts, plat, plon, "M", &npoly, px, py, inout, &ier ); ninout = npts; memcpy ( xinout, plat, (size_t)ninout*sizeof(float) ); memcpy ( yinout, plon, (size_t)ninout*sizeof(float) ); } ip = 0; while ( ip < ninout ) { ibeg = ip; iend = ip; while ( inout[ip] == inout[ibeg] && ip < ninout ) ip++; iend = ip - 1; numpts = iend - ibeg + 1; if ( numpts > 1 ) { if (( inout[ibeg] == 1 && strcmp(keep,"keep") == 0 ) || ( inout[ibeg] == 0 && strcmp(keep,"keep") != 0 ) ) { memcpy ( &(el_t.hdr), &(el.hdr), sizeof(VG_HdrStruct) ); el_t.elem.jet.line.splcol = el.elem.jet.line.splcol; memcpy ( &(el_t.elem.jet.line.spl.info), &(el.elem.jet.line.spl.info), sizeof(SpLineInfo) ); el_t.elem.jet.line.spl.info.numpts = numpts; ptrlat = &(el_t.elem.jet.line.spl.latlon[ 0]); ptrlon = &(el_t.elem.jet.line.spl.latlon[numpts]); memcpy(ptrlat, &(xinout[ibeg]), (size_t)numpts*sizeof(float)); memcpy(ptrlon, &(yinout[ibeg]), (size_t)numpts*sizeof(float)); nbarb = 0; for ( ii = 0; ii < el.elem.jet.nbarb; ii++ ) { flat = el.elem.jet.barb[ii].wnd.data.latlon[0]; flon = el.elem.jet.barb[ii].wnd.data.latlon[1]; npts = 1; cgr_inpoly ( "M", &npts, &flat, &flon, "M", &npoly, px, py, tinout, &ier ); if (( tinout[0] == 1 && strcmp(keep,"keep") == 0 ) || ( tinout[0] == 0 && strcmp(keep,"keep") != 0 ) ) { memcpy ( &(el_t.elem.jet.barb[nbarb]), &(el.elem.jet.barb[ii]), sizeof(BarbAttr) ); nbarb++; } } el_t.elem.jet.nbarb = nbarb; nhash = 0; for ( ii = 0; ii < el.elem.jet.nhash; ii++ ) { flat = el.elem.jet.hash[ii].wnd.data.latlon[0]; flon = el.elem.jet.hash[ii].wnd.data.latlon[1]; npts = 1; cgr_inpoly ( "M", &npts, &flat, &flon, "M", &npoly, px, py, tinout, &ier ); if (( tinout[0] == 1 && strcmp(keep,"keep") == 0 ) || ( tinout[0] == 0 && strcmp(keep,"keep") != 0 ) ) { memcpy ( &(el_t.elem.jet.hash[nhash]), &(el.elem.jet.hash[ii]), sizeof(HashAttr) ); nhash++; } } el_t.elem.jet.nhash = nhash; cvg_writef ( &el_t, -1, el.hdr.recsz, outfile, FALSE, &loc, &ier ); } } } break; case GFA_ELM: /* Get the Hazard Type... */ cvg_getFld ( &el, TAG_GFA_AREATYPE, hazList, &ier ); npts = el.elem.gfa.info.npts; ptrlat = &(el.elem.gfa.latlon[0]); ptrlon = &(el.elem.gfa.latlon[npts]); memcpy ( plat, ptrlat, (size_t)npts*sizeof(float) ); memcpy ( plon, ptrlon, (size_t)npts*sizeof(float) ); if ( el.hdr.closed == 1 ) { plat[npts] = plat[0]; plon[npts] = plon[0]; npts++; } if(strcmp(hazList,"FZLVL")==0) { /* Is this a Freezing Level? */ if ( strcmp(precision,"EXACT") == 0 ) { clip_line ( npoly, px, py, npts, plat, plon, (int)el.hdr.closed, sizeof(xinout)/sizeof(float), &ninout, xinout, yinout, inout, &ier ); } else if (strcmp(precision,"ROUGH") == 0 ) { cgr_inpoly ( "M", &npts, plat, plon, "M", &npoly, px, py, inout, &ier ); ninout = npts; memcpy ( xinout, plat, (size_t)ninout*sizeof(float) ); memcpy ( yinout, plon, (size_t)ninout*sizeof(float) ); } if ( el.hdr.closed == 1 ) { ip = 0; ninout--; while ( inout[ip] == inout[0] && ip < ninout ) ip++; if ( ip != ninout ) { if (( inout[0] == 1 && strcmp(keep,"keep") == 0 ) || ( inout[0] == 0 && strcmp(keep,"keep") != 0 ) ) { memcpy ( tlat, xinout, (size_t)ninout*sizeof(float) ); memcpy ( tlon, yinout, (size_t)ninout*sizeof(float) ); memcpy ( tinout, inout, (size_t)ninout*sizeof(float) ); for ( ii = 0; ii < ninout; ii++ ) { xinout[ii] = tlat[(ii+ip) % ninout]; yinout[ii] = tlon[(ii+ip) % ninout]; inout[ii] = tinout[(ii+ip) % ninout]; } } } } ip = 0; while ( ip < ninout ) { ibeg = ip; iend = ip; while ( inout[ip] == inout[ibeg] && ip < ninout ) ip++; iend = ip - 1; numpts = iend - ibeg + 1; if (el.hdr.closed == 1 && numpts != ninout ) el.hdr.closed = 0; if ( numpts > 1 ) { if (( inout[ibeg] == 1 && strcmp(keep,"keep") == 0 ) || ( inout[ibeg] == 0 && strcmp(keep,"keep") != 0 )) { el.elem.gfa.info.npts = numpts; ptrlat = &(el.elem.gfa.latlon[ 0]); ptrlon = &(el.elem.gfa.latlon[numpts]); memcpy(ptrlat, &(xinout[ibeg]), (size_t)numpts*sizeof(float)); memcpy(ptrlon, &(yinout[ibeg]), (size_t)numpts*sizeof(float)); /* Recompute Default Text Label & Arrow location */ recalcGFAtLblArwLoc( &el ); el.hdr.recsz = (int) (sizeof(VG_HdrStruct) + sizeof(int)*2 + sizeof(char)* STD_STRLEN * el.elem.gfa.info.nblocks ) + sizeof(float)*numpts*2; cvg_writef ( &el, -1, el.hdr.recsz, outfile, FALSE, &loc, &ier ); } } } } else { /* We have a GFA object (that's not a freezing level) to be clipped */ /* Use clo_clip to clip the GFA Polygon against the specified bounds area. The resulting number of clipped areas (tnclips), and max points (tmaxpts) is returned */ clo_clip(&npts, plat, plon, sys_M, bnd_name, bnd_tag, &tnclip, &tmaxpts, &ier); /* Foreach of the clipped areas, get the clipped area, and write it out to the VGF file */ for (ii = 0; ii < tnclip; ii++) { clo_clipget(&ii, &tnpts, tlat, tlon, &ier); el.elem.gfa.info.npts = tnpts; ptrlat = &(el.elem.gfa.latlon[ 0]); ptrlon = &(el.elem.gfa.latlon[tnpts]); /* Re-Initialize the latlon struct. */ for (jj =0; jj < MAXPTS*2; jj++) { el.elem.gfa.latlon[jj] = 0.00; } memcpy(ptrlat, &(tlat[0]), (size_t)tnpts*sizeof(float)); memcpy(ptrlon, &(tlon[0]), (size_t)tnpts*sizeof(float)); /* Recompute Default Text Label & Arrow location */ recalcGFAtLblArwLoc( &el ); el.hdr.recsz = (int) (sizeof(VG_HdrStruct) + sizeof(int)*2 + sizeof(char)* STD_STRLEN * el.elem.gfa.info.nblocks ) + sizeof(float)*tnpts*2; cvg_writef (&el, -1, el.hdr.recsz, outfile, FALSE, &loc, &ier ); } /* Free up memory left over from the clo routines */ clo_clipdone(&ier); } break; } break; } } ne++; } cfl_clos ( ifptr, &ier ); return(0); }
int main ( int argc, char *argv[] ) /************************************************************************ * DCISIG * * * * This program decodes international sigmet reports and writes the * * output to an ASCII file. * * * * Command line: * * dcisig [options] filename * * filename output file name/template * ** * * Log: * * D. Kidwell/NCEP 10/99 * * A. Hardy/GSC 1/01 Added full prototype * * S. Jacobs/NCEP 2/01 Removed all references to ulog * * F. J. Yen/NCEP 11/01 Set defstn to intlsig.tbl * * F. J. Yen/NCEP 9/03 Called clo_init for geographical points * * m.gamazaychikov/SAIC 07/05 Added parameters to CS of dc_gopt * * H. Zeng/SAIC 08/05 Added parameters to CS of dc_gopt * * L. Hinson/AWC 06/08 Added circflg parameter to dc_gopt * ***********************************************************************/ { /* ** Change the values of these default variables for the ** specific decoder. ** ** These variables are the number of expected command line ** parameters; the program name; the packing and station tables; ** values for the the number of additional stations and the ** number of times; and the number of hours, prior to the ** "current" time, to decode. */ #define NUMEXP 1 int nexp = NUMEXP; char *prgnam = "DCISIG"; char *defprm = " "; char *defstn = "intlsig.tbl"; char *dfstn2 = " "; int idfadd = 25; int idfmax = 24; int ndfhr1 = 5; int ndfhr2 = 24; int idfwdh = 0; /* ** Do not change these variables. These variables are used by all ** decoders for getting the command line parameters. */ char parms[NUMEXP][DCMXLN], curtim[DCMXLN]; int num, iret; char gemfil[DCMXLN], stntbl[DCMXLN], stntb2[DCMXLN], prmfil[DCMXLN]; int iadstn, maxtim, nhours, txtflg, circflg, iwndht; /*---------------------------------------------------------------------*/ /* ** Initialize the output logs, set the time out and ** parse the command line parameters. */ dc_init ( prgnam, argc, argv, nexp, parms, &num, &iret ); /* ** Check for an initialization error. ** On an error, exit gracefully. */ if ( iret < 0 ) { dc_exit ( &iret ); } /* ** Set the decoder parameters to the command line entries or ** default values. */ dc_gopt ( defprm, defstn, dfstn2, idfadd, idfmax, ndfhr1, ndfhr2, idfwdh, prmfil, stntbl, stntb2, &iadstn, &maxtim, curtim, &nhours, &txtflg, &circflg, &iwndht, &iret ); /* ** The output file name must be present. ** ** Change this section for the specific decoder. */ strcpy ( gemfil, parms[0] ); /* ** Initialize the clo library values. This call is required for ** this decoder because it uses the vor station table and ** associated clo library routines. */ clo_init ( &iret ); /* ** Call the decoding routine. ** ** Change this function call, and the define command, ** for the specific decoder. */ is_dcod ( curtim, gemfil, stntbl, prmfil, &iadstn, &maxtim, &nhours, &iret, strlen(curtim), strlen(gemfil), strlen(stntbl), strlen(prmfil) ); /* ** Send a shut down message to the logs and close the log files. */ dc_exit ( &iret ); return(0); }
void plot_ugc(int type, char *zone, int col1, int col2, int ltype, int lwidth, int ftype ) /****************************************************************/ /* int type 0=Zone, 1=County */ /* char *zone 6 character ugc, xxTiii */ /* xx = state or zone class id */ /* T = type (Zone Z or County C) */ /* int col1 Fill color */ /* int col2 Outline color */ /* int ltype Outline line type */ /* int lwidth Outline line width */ /* int ftype Fill pattern */ /* */ /* Chiz/Unidata */ /****************************************************************/ { int ier,iret; int FOUND,i; char srchstr[30]; int bindex,sindex, iftyp; float szfil=1.0; clo_init(&ier); iftyp = ftype; if(iftyp < 0) iftyp = 1; gsfill(&szfil,&iftyp,&ier); if(ier != 0) { iftyp = 1; gsfill(&szfil,&iftyp,&ier); } switch(type) { case 0: /* ** Lookup FIPS number in county table as search string */ sindex = clo_which("COUNTY"); i = 0; FOUND = 0; while((i<clo.loc[sindex].stn.nstn)&&(FOUND == 0)) { if(strcmp(clo.loc[sindex].stn.station[i].id,zone) == 0) { FOUND = 1; /*printf("%s %s %d\n",clo.loc[sindex].stn.station[i].id, clo.loc[sindex].stn.station[i].desc, clo.loc[sindex].stn.station[i].nm);*/ } else i++; } if(FOUND != 0) { bindex = clo_which("CNTY_BNDS"); sprintf(srchstr,"<FIPS>%d<\0", clo.loc[sindex].stn.station[i].nm); clo_off(srchstr, bindex, col1, col2, ltype, lwidth); } break; case 1: /* ** Use zone name to search for boundary */ /*sprintf(srchstr,"ZONE=%s\0",zone);*/ sprintf(srchstr,"<ZONE>%s\0",zone); bindex = clo_which("ZONE_BNDS"); clo_off(srchstr, bindex, col1, col2, ltype, lwidth); break; default: printf("this type %d not handled\n",type); } }
void wbc_area ( char *locnam, char *vorstr, int len, char *areastr, int *iret ) /************************************************************************ * wbc_area * * * * This function converts the VOR stations string to the VOR watch area * * string,containing distance, direction, county names and state ids. * * * * Input example: * * 17 WNW DEC;26 E FAM;26 WNW FAM;55 SSE COU;22 NNW UIN;47 ENE UIN; * * * * Output example: * * 17 WNW OF DECATUR, IL..TO 26 E OF FARMINGTON, MO..TO 26 WNW OF * * FARMINGTON, MO..TO 55 SSE OF COLUMBIA, MO..TO 22 NNW OF QUINCY, * * IL..TO 47 ENE OF QUINCY, IL. * * * * wbc_area ( locnam, vorstr, len, areastr, iret ) * * * * Input parameters: * * *locnam char Locator type * * *vorstr char Polygon text string * * len int Max length of 'areastr' * * * * Output parameters: * * *areastr char Polygon area text string * * *iret int Return value * * -5 = VORSTR too big * * * ** * * Log: * * A. Hardy/NCEP 5/03 From VF_AREA * ************************************************************************/ { int ii, nstn, maxlen, nstr, np, icnt, ier, exp, max, len1; char tmpstr[420], holdstr[200], qstate[1], pstn[180]; char arrgrp[15], **aryvor, county[30], state[3]; /*---------------------------------------------------------------------*/ *iret = 0; np = 1; icnt = 1; max = 6; exp = 4; qstate[0] = '\0'; tmpstr[0] = '\0'; maxlen = sizeof(pstn); if ( strcmp ( locnam, "VOR") != 0 ) { *iret = -2; return; } cst_lstr ( vorstr, &len1, &ier ); if ( len1 >= 400 ) { *iret = -5; return; } /* * Set up the memory space to break up the VOR area string. */ clo_init ( &ier ); aryvor = (char **) malloc(sizeof(char *) * 4); for ( ii = 0; ii < 4; ii++ ) { aryvor[ii] = (char *) malloc(6) ; } /* * Get the city and state of the VOR station. */ for ( ii = 0; ii < 6; ii++) { vorstr = (char *) cst_split ( vorstr, ';', 12, arrgrp, &ier); cst_clst ( arrgrp, ' ', " ", exp, max, aryvor, &nstr, &ier); if ( nstr == 3 ) { clo_findstn ( locnam, aryvor[2], qstate, np, maxlen, &nstn, pstn, &ier); } else if ( nstr == 2) { clo_findstn ( locnam, aryvor[1], qstate, np, maxlen, &nstn, pstn, &ier); } cst_gtag ( "NAME", pstn, " ", county, &ier ); cst_gtag ( "ST", pstn, " ", state, &ier ); cst_rnan (county, county, &ier); /* * Create the watch area string. */ holdstr[0] = '\0'; if ( icnt < 6 ) { if ( strcmp ( aryvor[0], "..") != 0 ) { sprintf( holdstr," %s %s OF %s, %s..TO ",aryvor[0], aryvor[1], county, state); } else { /* * Print string for zero distance and no direction. */ sprintf( holdstr," %s, %s..TO ", county, state); } } else { if ( strcmp ( aryvor[0], "..") != 0 ) { sprintf( holdstr," %s %s OF %s, %s.",aryvor[0], aryvor[1], county, state); } else { /* * Print string for zero distance and no direction. */ sprintf( holdstr," %s, %s.", county, state); } } icnt++; cst_ncat ( tmpstr, holdstr, &len1, &ier); } len1 = G_MIN ( len, (int)strlen(tmpstr) ); cst_ncpy( areastr, tmpstr, len1, &ier); /* * Free memory space. */ for ( ii = 0; ii < 4; ii++ ) { free ( aryvor[ii] ); } free ( aryvor); }
int main ( int argc, char **argv ) /************************************************************************ * mdp * * * * This program generates the mesoscale discussion latlon pairings. * * Pairings will be written to a file whose filename is based on the * * input filename (filename extension, if exists, is replaced w/ "mdp").* * * * Example: * * mdp input_vgf_file.vgf * * Produces latlon pairings in the ASCII file * * output_vgf_file.mdp * * * * 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 6/02 * * D.W.Plummer/NCEP 8/02 Bug fix for lons > 99.995 and < 100.0 * * G. Grosshans/SPC 11/02 Updated to decode multi-scalloped lines * * G. Grosshans/SPC 12/02 Updated to compute WFO/State * * S. Jacobs/NCEP 5/03 Clean up unused variables and headers * * G. Grosshans/SPC 10/03 Updated for precision * * T. Piper/SAIC 12/05 Updated cst_wrap for CSC * * J. Wu/SAIC 04/06 Added parameter in cst_wrap * * G. Grosshans/SPC 08/08 Updated for SCN 08-45 to add LAT...LON * * and list first point as last point * * to indicate a closed polygon. Add * * word wrapping for ATTN...WFO... * ***********************************************************************/ { int ii, ix, iy, ixfirst, iyfirst, pagflg, ne, ilen, npts, ier, iret, nitems, more, curpos; long ifilesize; float x, y, flat[MAXLISTITEMS], flon[MAXLISTITEMS]; char vg_class, vg_type, buffer[2048], bufferfinal[2048], bufferfinalwfo[2048],str[20], *cptr, errgrp[12], infile[128], ifname[128], outfile[128], info[2048], stpo[4], cstl_list[1000], cstl_liststate[1000], newLineStr[13]=" "; /* 13 spaces */ char blank[2]={' '}, device[13], dfilnam[73], pro[80]; int mode, istat, iunit, itype; float xsize, ysize, lllat, lllon, urlat, urlon, prjang1, prjang2, prjang3; VG_DBStruct el; FILE *ifptr, *ofptr; const int line_len = 66; /*---------------------------------------------------------------------*/ /* * Set defaults for gsdeva and gsmprj */ mode = 1; strcpy ( device, "GN" ); iunit = 1; strcpy ( dfilnam, "MDPSPC" ); itype = 1; xsize = 500.0F; ysize = 500.0F; lllat = 10.0F; lllon = -120.0F; urlat = 50.0F; urlon = -50.0F; strcpy ( pro, "str" ); prjang1 = 90.0F; prjang2 = -105.0F; prjang3 = 0.0F; cstl_list[0] = '\0'; cstl_liststate[0] = '\0'; in_bdta ( &ier ); ginitp ( &mode, &istat, &ier); gsdeva (device, &iunit, dfilnam, &itype, &xsize, &ysize, &iret, strlen(device), strlen(dfilnam)); gsmprj ( pro, &prjang1, &prjang2, &prjang3, &lllat, &lllon, &urlat, &urlon, &iret, strlen(pro)); clo_init ( &ier ); /* * Check if number of input arguments is correct. */ if ( argc < 2 ) { pagflg = G_FALSE; strcpy ( errgrp, "MDPSPC" ); ip_help ( errgrp, &pagflg, &ier, strlen(errgrp) ); gendp (&mode, &ier); exit (0); } /* * First input on command line is input vgf file name. */ strcpy ( infile, argv[1] ); cfl_inqr ( infile, NULL, &ifilesize, ifname, &ier ); ifptr = (FILE *) cfl_ropn(ifname, "", &ier); if ( ier != 0 ) { printf("Error opening VGF file %s\n", infile ); gendp (&mode, &ier); exit (0); } /* * Output filename is input filename w/ "mdp" filename extension. */ strcpy ( outfile, infile ); cptr = strrchr( outfile, '.' ); if ( cptr != (char *)NULL ) { cptr[0] = '\0'; } strcat( outfile, ".mdp" ); /* * Loop through all the elements until a line is found. */ ne = 0; more = G_TRUE; curpos = 0; buffer[0] = '\0'; bufferfinal[0] = '\0'; bufferfinalwfo[0] = '\0'; strcat ( buffer, "LAT...LON " ); while ( ne < MAX_EDITABLE_ELEMS && more == G_TRUE ) { cvg_rdrecnoc( ifname, ifptr, curpos, &el, &ier ); if ( ier < 0 ) { more = G_FALSE; } else { curpos += el.hdr.recsz; vg_class = el.hdr.vg_class; vg_type = el.hdr.vg_type; if ( ( (int)vg_class == CLASS_LINES ) && ( el.hdr.vg_type == SPLN_ELM ) && ( (int)el.elem.spl.info.spltyp == 3 ) ) { /* * Open output file. */ ofptr = (FILE *)cfl_wopn ( outfile, &ier ); if ( ier != 0 ) { printf("Error opening/creating output file %s\n", outfile ); gendp (&mode, &ier); exit (0); } /* * Find FIPS bounded by the closed line */ npts = el.elem.spl.info.numpts; /* FIND WHAT STATES ARE IN MD AREA */ clo_binpoly ( "CNTY_BNDS", npts, el.elem.spl.latlon, &(el.elem.spl.latlon[npts]), &ier ); clo_tgltln ( "CNTY_BNDS", MAXLISTITEMS, &nitems, flat, flon, &ier); for ( ii = 0; ii < nitems; ii++ ) { clo_bginfo( "CNTY_BNDS", ii, info, &ier ); cst_gtag( "STATE", info, "?", stpo, &ier); if (strstr(cstl_liststate, stpo)==NULL) { strcat(cstl_liststate, stpo); strcat(cstl_liststate, " "); } } /* FIND WHAT WFOs ARE IN MD AREA */ clo_binpoly ( "CWA_BNDS", npts, el.elem.spl.latlon, &(el.elem.spl.latlon[el.elem.spl.info.numpts]), &ier ); clo_tgltln ( "CWA_BNDS", MAXLISTITEMS, &nitems, flat, flon, &ier); for ( ii = 0; ii < nitems; ii++ ) { clo_bginfo( "CWA_BNDS", ii, info, &ier ); cst_gtag( "WFO", info, "?", stpo, &ier); strcat(cstl_list, stpo); strcat(cstl_list, "..."); } /* * Format lats and lons into buffer. */ if ( (int)vg_type == LINE_ELM ) { npts = el.elem.lin.info.numpts; } else if ( (int)vg_type == SPLN_ELM ) { npts = el.elem.spl.info.numpts; } for ( ii = 0; ii < npts; ii++ ) { if ( (int)vg_type == LINE_ELM ) { x = el.elem.lin.latlon[ii]; y = -el.elem.lin.latlon[ii+npts]; } else if ( (int)vg_type == SPLN_ELM ) { x = el.elem.spl.latlon[ii]; y = -el.elem.spl.latlon[ii+npts]; } /* * Make sure lats and lons are rounded * to 100ths of deg. */ x = ((int)(x*100.0F)) / 100.0F; y = ((int)(y*100.0F)) / 100.0F; if ( y >= 100.0F ) y -= 100.0F; ix = G_NINT(x*100.0F); iy = G_NINT(y*100.0F); sprintf( str, "%04d%04d ", ix, iy ); strcat ( buffer, str ); if ( ii == 0 ) { ixfirst = ix; iyfirst = iy; } } /* * Repeat first lat/lon point as last lat/lon point * to indicate a closed polygon. */ sprintf( str, "%04d%04d ", ixfirst, iyfirst); strcat ( buffer, str ); sprintf( str, "\n\n" ); strcat ( buffer, str ); /* * Wrap buffer such that only 6 pairs of lat,lons * on one line. * ilen = 55; * cst_wrap( buffer, blank, &ilen, "\n", (char *)NULL, buffer, &ier ); */ ilen = 66; cst_wrap( buffer, blank, &ilen, "\n", newLineStr, buffer, &ier ); } } ne++; } /* * wrap the ATTN...WFO... line */ strcat ( bufferfinalwfo, "ATTN...WFO..." ); strcat ( bufferfinalwfo, cstl_list ); cst_wrap( bufferfinalwfo, "...", &line_len, "\n", (char *)NULL, bufferfinalwfo, &ier ); /* * build the output file string and add the ATTN...WFO... string */ strcat ( bufferfinal,"STATES=" ); strcat ( bufferfinal, cstl_liststate ); strcat ( bufferfinal, "\n\n" ); strcat ( bufferfinal, bufferfinalwfo ); /* strcat ( bufferfinal,"ATTN...WFO..." ); strcat ( bufferfinal, cstl_list ); */ strcat ( bufferfinal, "\n\n" ); strcat ( bufferfinal, buffer ); /* * Write to output file. */ cfl_writ ( ofptr, (int)strlen(bufferfinal), (unsigned char *)bufferfinal, &ier ); /* * close files and exit. */ cfl_clos ( ifptr, &ier ); cfl_clos ( ofptr, &ier ); gendp (&mode, &ier); return(0); }
void clo_blasso ( char *bndtyp, char *key, int *npts, char *btags, gpc_polygon *union_poly, int *iret ) /************************************************************************ * clo_blasso * * * * This function takes a string of bound tags, semi-colon separated, and* * returns a polygon structure from the union of the polygons designated* * by the bound tags. A return code of 1 due to a bad bounds key tag * * could mean the tag name (eg., <FIPS>) is invalid and/or the tag value* * (eg., 51059 -- a FIPS code) is invalid. Processing continues, so the* * invoking routine may also want to check the number of polygons for 0,* * in which case it would most likely be caused by an invalid tag name. * * * * Note that the tag name may or may not be enclosed with '<' and '>'. * * If it is not, they will be added to the tag name. * * * * clo_blasso ( bndtyp, key, npts, btags, union_poly, iret ) * * * * Input parameters: * * *bndtyp char Bounds file alias name (eg., WBCMZ_BNDS)* * *key char Search tag name in bounds file * * (eg., <FIPS> or FIPS, <STATE> or STATE)* * *npts int No. of bounds tag values in string btags* * *btags char Bounds tag values, delimited by ";" * * (eg., 51059;51057;51053) * * * * Output parameters: * * *union_poly gpc_polygon GPC polygon structure of union * * iret int Return code * * = 0 Normal * * = 1 No bound area found for a tag * * due to bad tag name or value * * = -1 Bounds file open error return * * or illegal bounds name * * * ** * * Log: * * F. J. Yen/NCEP 1/05 * * F. J. Yen/NCEP 2/05 Increased size of btagkey; Enclosed tag * * name with '<' and '>' if missing. * * J. Wu/SAIC 6/05 remove reference to LLMXPT * * F.Yen&D.Plummer/NCEP 7/05 Redesigned for performance. * * D.W.Plummer/NCEP 8/05 Add final GPC_UNION to rm spurious pts * ***********************************************************************/ { char **arrptr, btagkey[80]; char *tag_start = { "<" }; char *tag_end = { ">" }; int ii, maxexp, minp, ier, ierro, mxpts, end; int narr, numTmp, len, hole, initl; float *xTmp, *yTmp; float rlatmn, rlonmn, dlatmx, dlonmx, filter; gpc_polygon polygon; gpc_vertex_list verts; /*---------------------------------------------------------------------*/ *iret = 0; ier = 0; minp = 0; hole = 0; filter = 0.0; maxexp = 400; /* * Initalize the gpc polygon structure variables */ union_poly->num_contours = 0; union_poly->hole = (int *)NULL; union_poly->contour = (gpc_vertex_list *)NULL; clo_bstype ( bndtyp , &ier ); /* Set the bounds file */ if ( ier != 0 ) { *iret = -1; return; } /* * Set the bounds area */ rlatmn = -90.0; dlatmx = +90.0; rlonmn = -180.0; dlonmx = +180.0; clo_bsarea ( &rlatmn, &rlonmn, &dlatmx, &dlonmx, &ier ); /* * Initialize the clo library */ clo_init ( &ier); /* * Allocate memory */ clo_qmxpts ( "BOUNDS", &mxpts, &ier ); G_MALLOC ( xTmp, float, mxpts, "CLO_BLASSO" ); G_MALLOC ( yTmp, float, mxpts, "CLO_BLASSO" ); /* * Break apart the bounds tag values */ arrptr = (char **)malloc(*npts * sizeof(char *)); for (ii = 0; ii < *npts; ii++) { arrptr[ii] = (char *) malloc(maxexp); } cst_clst ( btags, ';', " ", *npts, maxexp, arrptr, &narr, &ier ); /* * initialize single bounds polygon */ polygon.num_contours = 0; polygon.hole = (int *)NULL; polygon.contour = (gpc_vertex_list *)NULL; /* * Loop over bounds tag values */ for (ii=0;ii < narr; ii++) { cst_rmbl ( arrptr[ii], arrptr[ii], &len, &ier ); if ( len > 0 ) { ierro = 0; /* * Create the key tag to search on ( eg. <FIPS>51097 ). First, * check for '<' at beginning of tag. Add it if it isn't there. */ btagkey[0] = '\0'; if( key[0] != '<' ) { strcpy( btagkey, tag_start ); } strcat ( btagkey, key ); /* * Check for '>' at end of key tag. Add it if it isn't there. */ end = strlen ( key ); if ( key [ end - 1 ] != '>' ) { strcat ( btagkey, tag_end ); } strcat ( btagkey, arrptr[ii]); clo_bstype ( bndtyp , &ier ); /* Set the bounds file */ clo_bstag ( btagkey, &ier ); /* Set the bounds key tag (eg <FIPS>51097 ) */ /* * Find the bound key tag polygon */ initl = 1; while ( ierro == 0 ) { /* * Get next bounds */ clo_bgnext (&minp, &mxpts, &filter, &numTmp, xTmp, yTmp, &ierro ); if ( initl == 1 ) { initl = 0; if ( ierro != 0 ) { /* * No bound area (polygon) found for current bounds * key tag in btagkey due to either an invalid tag * name (eg, <FIPS> or <STATE>) and/or invalid tag * value (ie, if the tag name is <FIPS>, the tag * value would be a FIPS code such as 13009). */ *iret = 1; } } if ( ierro == 0 ) { /* * initialize vertex list */ verts.vertex = (gpc_vertex*)NULL; verts.num_vertices =0; gpc_cvlist (numTmp, xTmp, yTmp, &verts, &ier ); gpc_add_contour ( &polygon, &verts, hole); free ( verts.vertex ); } } /* end for while loop */ } /* end for length check */ } /* end for loop */ /* * union the polygon with a NULL polygon (union) to get the union */ gpc_polygon_clip (GPC_UNION, &polygon, union_poly, union_poly ); gpc_free_polygon ( &polygon); gpc_polygon_clip (GPC_UNION, &polygon, union_poly, union_poly ); /* * Free memory space. */ G_FREE ( xTmp, float ); G_FREE ( yTmp, float ); for ( ii = 0; ii < *npts; ii++ ) { free ( arrptr[ii] ); } free ( arrptr); }