/* Help and usage message */ void usage(void) { show_version(); puts("\nUsage: t50 <host[/cidr]> [options]"); general_help(); gre_help(); tcp_udp_dccp_help(); tcp_help(); ip_help(); icmp_help(); egp_help(); rip_help(); dccp_help(); rsvp_help(); ipsec_help(); eigrp_help(); ospf_help(); puts("Some considerations while running this program:\n" " 1. There is no limitation of using as many options as possible.\n" " 2. Report " PACKAGE " bugs at " PACKAGE_URL ".\n" " 3. Some header fields with default values MUST be set to \'0\' for RANDOM.\n" " 4. Mandatory arguments to long options are mandatory for short options too.\n" " 5. Be nice when using " PACKAGE ", the author DENIES its use for DoS/DDoS purposes.\n" " 6. Running " PACKAGE " with \'--protocol T50\' option sends ALL protocols sequentially."); exit(EXIT_FAILURE); }
void dc_init ( char *prgnam, int argc, char **argv, int numexp, char parms[][DCMXLN], int *num, int *iret ) /************************************************************************ * dc_init * * * * This routine initializes the bridge and decoder parameters and * * processes the command line options. * * * * dc_init ( prgnam, argc, argv, numexp, parms, num, iret ) * * * * Input parameters: * * *prgnam char Program name * * argc int Number of command line args * * **argv char Command line arguments * * numexp int Number of expected parameters * * * * Output parameters: * * parms[][DCMXLN] char Parameters found on command line* * *num int Number of parameters found * * *iret int Return code * * 0 = normal return * * -11 = no command line args * * * ** * * Log: * * A. Chang/EAi 5/95 * * S. Jacobs/NMC 7/95 Update and clean up * * S. Jacobs/NCEP 6/96 Updated documentation; Changed atoi to * * cst_numb; Removed the +3 return code; * * Changed ldfd to a FILE stream - fplog * * S. Jacobs/NCEP 7/96 Reorganized the source code * * K. Tyle/GSC 7/96 NT_HELP --> IP_HELP * * S. Jacobs/NCEP 7/96 Removed log file open * * K. Tyle/GSC 1/97 Added calls to IN_BDTA and ER_STAT; * * changed numerr in startup dc_wclg call * * K. Tyle/GSC 1/97 Use iflg in call to ER_STAT * * D. Kidwell/NCEP 9/97 Added version number to help option * * I. Durham/GSC 5/98 Changed underscore decl. to an include * * S. Jacobs/NCEP 1/00 Added command line input of env vars * * S. Jacobs/NCEP 2/01 Removed all references to ulog * * R. Tian/SAIC 8/02 Added version to log file * * m.gamazaychikov/SAIC 07/05 Added -w input parameter * * H. Zeng/SAIC 08/05 Added second station table * * L. Hinson/AWC 06/08 Add -r circular flag switch * * S. Jacobs/NCEP 3/12 Add $HOME to the logs directory * * S. Jacobs/NCEP 12/13 Added more options for log location * ***********************************************************************/ { int ch, i, errflg, ier; int pagflg = G_FALSE; int iflg = G_TRUE; /* ** These variables are used for logging errors and notices. */ char tdclog[DCMXLN]; int logflg, ibuf; char errstr[DCMXLN]; char version[128]; /* ** These variables are used by getopt. Unset the error reporting. */ char optver[20]; /*---------------------------------------------------------------------*/ *iret = 0; /* ** Set the process ID for log messages. */ ipid = (int) getpid (); /* ** Initialize the bulletin counter. */ nbull = 0; /* ** Save the program name as a global variable. */ strcpy ( cprgnm, prgnam ); /* ** Set up the signal handlers. */ dc_sgnl ( ); /* ** Get and process the command line options. ** ** Set the default values for parsing the command line. */ strcpy ( curtim, "SYSTEM" ); cst_uclc ( cprgnm, tdclog, &ier ); strcat ( tdclog, ".log" ); logflg = G_FALSE; itmout = DCDFTM; irltim = G_TRUE; txtflg = G_TRUE; circflg = G_FALSE; ivrblv = 0; prmfil[0] = CHNULL; stntbl[0] = CHNULL; iadstn = IMISSD; maxtim = IMISSD; nhours = IMISSD; iwndht = IMISSD; /* ** Get the valid options from the command line. ** The valid options are: ** -v Set the level of verbosity for the logs ** -c Set the "current" time ** -b Number of hours to decode prior to "current" time ** -d Set the decoder log file name ** -t Set the interval for the time out ** -p Set the parameter packing table ** -s Set the station table ** -S Set the second station table ** -a Set the number of additional stations ** -m Set the max number of times ** -e Set an environment variable=value ** -n Set a flag to NOT save the text data ** -r Set a flag to force circular files ** -w Set the cutoff "close-to-the-surface" height ** -h Print the help file, then exit the program */ opterr = 1; errflg = 0; while ( ( ch = getopt ( argc, argv, "v:c:b:d:t:p:s:S:a:m:e:w:nhr" ) ) != EOF ) { switch ( ch ) { case 'v': cst_numb ( optarg, &ivrblv, &ier ); if ( ivrblv < 0 ) ivrblv = 0; break; case 'c': strcpy ( curtim, optarg ); irltim = G_FALSE; break; case 'b': cst_numb ( optarg, &nhours, &ier ); break; case 'd': strcpy ( tdclog, optarg ); logflg = G_TRUE; break; case 't': cst_numb ( optarg, &itmout, &ier ); if ( itmout < 1 ) itmout = DCDFTM; break; case 'p': strcpy ( prmfil, optarg ); break; case 's': strcpy ( stntbl, optarg ); break; case 'S': strcpy ( stntb2, optarg ); break; case 'a': cst_numb ( optarg, &iadstn, &ier ); break; case 'm': cst_numb ( optarg, &maxtim, &ier ); break; case 'e': envobj = (envlist *) malloc ( sizeof(envlist) ); envobj->env = malloc ( strlen(optarg)+1 ); strcpy ( envobj->env, optarg ); envobj->env[strlen(optarg)] = '\0'; envobj->next = envhead; envhead = envobj; break; case 'n': txtflg = G_FALSE; break; case 'w': cst_numb ( optarg, &iwndht, &ier ); break; case 'r': circflg = G_TRUE; break; case 'h': ip_help ( cprgnm, &pagflg, &ier, strlen(cprgnm) ); strcpy ( cprgnm, "DECODE" ); ip_help ( cprgnm, &pagflg, &ier, strlen(cprgnm) ); ss_vers ( optver, &ier, sizeof (optver) ); printf ( ">%s<\n", optver ); exit ( 0 ); break; case '?': errflg++; break; } } /* ** Initialize GEMPAK and set error reporting parameters. */ in_bdta ( &ier ); ibuf = 1; er_stat ( &ivrblv, &ibuf, &iflg, &ier ); /* ** Open the decoder log. ** ** If the processing is in real-time add the directory to the ** file name. */ if ( !logflg && irltim ) { if ( tdclog[0] == '/' ) { strcpy ( dcdlog, tdclog ); } else if ( getenv("GEMPAK_DECODER_LOGS") ) { strcpy ( dcdlog, "$GEMPAK_DECODER_LOGS/" ); strcat ( dcdlog, tdclog ); } else { strcpy ( dcdlog, "$HOME/" ); strcat ( dcdlog, tdclog ); } } else { strcpy ( dcdlog, tdclog ); } /* ** Send a start up message to the decoder log. */ ss_vers ( version, &ier, sizeof(version) ); dc_wclg ( 0, "DCINIT", 3, version, &ier ); /* ** Set all of the environment variables. */ envobj = envhead; while ( envobj != NULL ) { if ( putenv ( envobj->env ) != 0 ) { strcpy ( errstr, envobj->env ); dc_wclg ( 0, "DCINIT", -17, errstr, &ier ); } envobj = envobj->next; } /* ** Adjust argc and argv by the option index. */ argc -= optind; argv += optind; /* ** Initialize the output string array. */ for ( i = 0; i < numexp; i++ ) strcpy ( parms[i], " " ); /* ** Get the decoder specific parameters. */ *num = argc; if ( *num == 0 ) { /* ** If there are no parameters write a message and return ** with an error. */ *iret = -11; dc_wclg ( 0, "DCINIT", *iret, " ", &ier ); } else { /* ** Otherwise, set the parameters to be returned. */ for ( i = 0; i < *num; i++ ) if ( i < numexp ) strcpy ( parms[i], argv[i] ); } }
int main ( int argc, char *argv[] ) /************************************************************************ * main * * * * Main program of shpcv. * * * * int 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: * * R. Tian/SAIC 3/04 Initial coding * * R. Tian/SAIC 2/05 Modified shp_mtyp * * T. Piper/SAIC 01/06 Call ip_help if inputs incorrect * * H. Zeng/SAIC 07/07 added calling to shp_rdException() * * S. Jacobs/NCEP 3/11 Added debug_flag and print statements * * S. Jacobs/NCEP 6/14 Moved split func to after dump output * ***********************************************************************/ { dbf_header dbfhdr; shx_record shxrec; shp_record *reclst, *newrec, *currec; shp_part *curprt; char dbfnam[MAXSHP][LLPATH], shxnam[MAXSHP][LLPATH], shpnam[MAXSHP][LLPATH]; FILE *dbffp, *shxfp, *shpfp; long flen; int ifld, nf, opt, rec, prt, file_code, nbin, ier; float ratio, clat, clon; int lfld, dump, rdpt, cbnd, ctbl, pagflg; int numrec, numfil, ii; int mode, istat, iunit, itype; unsigned long shp_fips; char device[8], proj[8], filnam[20], prognm[6]; float xsize, ysize, angle1, angle2, angle3, lllat, lllon, urlat, urlon; Boolean exception_found; /*---------------------------------------------------------------------*/ lfld = G_FALSE; dump = G_FALSE; rdpt = G_FALSE; cbnd = G_FALSE; ctbl = G_FALSE; pagflg = G_FALSE; strcpy ( prognm, "shpcv" ); debug_flag = G_TRUE; /*=================== Parse command line arguments ====================*/ while ( ( opt = getopt ( argc, argv, "r:btldh" ) ) != -1 ) { switch ( opt ) { case 'r': /* reduce points ratio */ ratio = atof ( optarg ); if ( ratio <= 0.0 ) { ratio = 0.01; } rdpt = G_TRUE; break; case 'b': /* create bound and bound info */ cbnd = G_TRUE; break; case 't': /* create station table */ ctbl = G_TRUE; break; case 'l': /* list fields */ lfld = G_TRUE; break; case 'd': /* dump the shape file */ dump = G_TRUE; break; case 'h': /* display help */ default: ip_help ( prognm, &pagflg, &ier, strlen(prognm) ); exit ( 0 ); break; } } if ( optind == argc || argc - optind > MAXSHP ) { ip_help ( prognm, &pagflg, &ier, strlen(prognm) ); exit ( -1 ); } /*======================== Read the shape file ========================*/ /* * Loop over input files. */ currec = NULL; numrec = 0; numfil = argc - optind; for ( nf = 0; nf < numfil; nf++ ) { /* * Get the input names and open them. */ if ( debug_flag ) { printf ( "File %d: %s\n", nf, argv[optind+nf] ); } strcpy ( dbfnam[nf], argv[optind+nf] ); strcat ( dbfnam[nf], ".dbf" ); strcpy ( shxnam[nf], argv[optind+nf] ); strcat ( shxnam[nf], ".shx" ); strcpy ( shpnam[nf], argv[optind+nf] ); strcat ( shpnam[nf], ".shp" ); cfl_inqr ( dbfnam[nf], NULL, &flen, dbfnam[nf], &ier ); dbffp = cfl_ropn ( dbfnam[nf], NULL, &ier ); if ( ier != 0 ) { fprintf ( stderr, "File %s does not exist.\n", dbfnam[nf] ); exit ( -1 ); } cfl_inqr ( shxnam[nf], NULL, &flen, shxnam[nf], &ier ); shxfp = cfl_ropn ( shxnam[nf], NULL, &ier ); if ( ier != 0 ) { fprintf ( stderr, "File %s does not exist.\n", shxnam[nf] ); exit ( -1 ); } cfl_inqr ( shpnam[nf], NULL, &flen, shpnam[nf], &ier ); shpfp = cfl_ropn ( shpnam[nf], NULL, &ier ); if ( ier != 0 ) { fprintf ( stderr, "File %s does not exist.\n", shpnam[nf] ); exit ( -1 ); } /* * Detect platform endian. */ cfl_read ( shpfp, INTEGER_SIZE, (unsigned char *)&file_code, &nbin, &ier ); if ( file_code == 9994 ) { mch_endian = BIG; } else { mch_endian = LITTLE; } /* * Read database header. */ shp_rdbh ( dbffp, &dbfhdr, &ier ); numrec += dbfhdr.nrec; if ( lfld == G_TRUE ) { for ( ifld = 0; ifld < dbfhdr.nfld; ifld++ ) { printf ( "Field: %s\n", dbfhdr.dbflds[ifld].name ); } } else { /* * Read shape record and construct an internal list. */ for ( rec = 0; rec < dbfhdr.nrec; rec++ ) { /* * Read record field data. */ shp_rdbf ( dbffp, rec, &dbfhdr, &ier ); /* * Read record index. */ shp_rshx ( shxfp, rec, &shxrec, &ier ); /* * Read record data. */ shp_rshp ( shpfp, &dbfhdr, &shxrec, &newrec, &ier ); /* * Add the new record on record list. */ newrec->prvrec = currec; if ( currec != NULL ) { currec->nxtrec = newrec; } else { reclst = newrec; } currec = newrec; } } /* * Close up opened files. */ cfl_clos ( dbffp, &ier ); cfl_clos ( shxfp, &ier ); cfl_clos ( shpfp, &ier ); } if ( lfld == G_TRUE ) { shp_mfreeall ( ); exit ( 0 ); } /*======================== Read the shape exception table =============*/ _shpException = NULL; _numShpException = 0; shp_rdException ( &ier ); /*======================= Starting Post-Process =======================*/ /* * Dump shapefile records. */ if ( dump == G_TRUE ) { for ( rec = 0, currec = reclst; rec < numrec; rec++, currec = currec->nxtrec ) { shp_wfld ( stdout, currec, &ier ); shp_wrec ( stdout, currec, &ier ); } shp_mfreeall ( ); exit ( 0 ); } /* * Split record part if it has more than MAXOUT number of points * or it crosses the international dateline. */ shp_splt ( reclst, numrec, &ier ); /* * Detect the map type. */ shp_mtyp ( dbfnam, numfil, &ier ); if ( maptyp == 0 ) { fprintf ( stderr, "Unknown Map Type.\n" ); exit ( -1 ); } /* * Delete not used records. */ shp_drec ( &reclst, &numrec, &ier ); /* * Combine records that have the same key. */ shp_cmbn ( reclst, &numrec, &ier ); /* * Compute record centroid. */ mode = 1; iunit = itype = 1; xsize = ysize = 1.0F; strcpy ( device, "GN" ); strcpy ( filnam, "SHPCV" ); /* * Use North STR projection. */ strcpy ( proj, "STR" ); angle1 = 90.0F; angle2 = -90.0F; angle3 = 0.0F; lllat = -15.0F; lllon = -135.0F; urlat = -15.0F; urlon = -135.0F; ginitp ( &mode, &istat, &ier ); gsdeva ( device, &iunit, filnam, &itype, &xsize, &ysize, &ier, strlen(device), strlen(filnam) ); gsmprj ( proj, &angle1, &angle2, &angle3, &lllat, &lllon, &urlat, &urlon, &ier, strlen(proj) ); for ( currec = reclst, rec = 0; rec < numrec; rec++, currec = currec->nxtrec ) { /* * Get the shape fips code, check if there is a match in * Shape Exception Table. If yes, get manually set * clon&clat value from the table directly. */ if ( sscanf(currec->fields[3].data, "%lu", &shp_fips) == 1 ) { exception_found = FALSE; for ( ii = 0; ii < _numShpException; ii++ ) { if ( _shpException[ii].fips == shp_fips ) { currec->cenlat = _shpException[ii].clat; currec->cenlon = _shpException[ii].clon; exception_found = TRUE; break; } } if ( exception_found ) continue; } /* * Get the shape id, check if there is a match in * Shape Exception Table. If yes, get manually set * clon&clat value from the table directly. */ exception_found = FALSE; for ( ii = 0; ii < _numShpException; ii++ ) { if ( strcasecmp(currec->fields[0].data, _shpException[ii].id) == 0 ) { currec->cenlat = _shpException[ii].clat; currec->cenlon = _shpException[ii].clon; exception_found = TRUE; break; } } if ( exception_found ) continue; /* * Calculate clon&clat mathematically from an algorithm. */ shp_gctr ( currec, &clon, &clat, &ier ); if ( ier == 0 ) { currec->cenlat = clat; currec->cenlon = clon; } else { currec->cenlat = RMISSD; currec->cenlon = RMISSD; } } /* the end of for ( currec ... */ /* * Reduce number of points. */ if ( rdpt == G_TRUE ) { for ( rec = 0, currec = reclst; rec < numrec; rec++, currec = currec->nxtrec ) { for ( prt = 0, curprt = currec->shpart; prt < currec->numprt; prt++, curprt = curprt->nxtprt ) { shp_thin ( curprt, ratio, &ier ); } } } /* * Create station table. */ if ( ctbl == G_TRUE ) { shp_ctbl ( reclst, numrec, &ier ); } /* * Create bound and bound info. */ if ( cbnd == G_TRUE ) { shp_cbnd ( reclst, numrec, &ier ); } /* * Clean up. */ shp_mfreeall ( ); return 0; }
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 ) /************************************************************************ * 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 * * m.gamazaychikov/SAIC 3/03 Made mdp work only on scallop lines * * added WFOs and STATES to output text * * m.gamazaychikov/SAIC 3/03 Made mdp work on lines grouped or not * * grouped with WFOs and/or STATES * * Made MDP exit upon encountering first * * scallop line in VGF file * * Made changes to format of output text * * T. Piper/SAIC 12/05 Updated cst_wrap for CSC * * J. Wu/SAIC 04/06 Added parameter in cst_wrap * ***********************************************************************/ { int ii, ix, iy, pagflg, ier; int ilen, npts; char vg_class, vg_type; char blank[2]={' '}, errgrp[8], infile[128], ifname[128], outfile[128]; float x, y; long ifilesize; int ne1, more1, curpos1; char buffer[1024], str[20], *cptr; int wrtoutfg, wrtwfofg, wrtsttfg; int grpnumbr1, grpnumbr2; int lintyp, jj, narea, areatype; int ne2, more2, curpos2; char strwfo[480], strstt[480], bufferlat[1024]; VG_DBStruct el; FILE *ifptr, *ofptr; /*---------------------------------------------------------------------*/ /* * Check if number of input arguments is correct. */ if ( argc < 2 ) { pagflg = G_FALSE; strcpy ( errgrp, "MDP" ); ip_help ( errgrp, &pagflg, &ier, strlen(errgrp) ); 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 ); 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. */ ne1 = 0; more1 = G_TRUE; curpos1 = 0; buffer[0] = '\0'; bufferlat[0] = '\0'; while ( ne1 < MAX_EDITABLE_ELEMS && more1 == G_TRUE ) { wrtoutfg = G_FALSE; wrtsttfg = G_FALSE; wrtwfofg = G_FALSE; cvg_rdrecnoc( ifname, ifptr, curpos1, &el, &ier ); if ( ier < 0 ) { more1 = G_FALSE; } else { curpos1 += el.hdr.recsz; vg_class = el.hdr.vg_class; vg_type = el.hdr.vg_type; grpnumbr1 = el.hdr.grpnum; if ( (int)vg_class == CLASS_LINES ) { /* * Open output file. */ ofptr = (FILE *)cfl_wopn ( outfile, &ier ); if ( ier != 0 ) { printf("Error opening/creating output file %s\n", outfile ); exit (0); } if ((int)vg_type == SPLN_ELM ) { /* * type of special line */ lintyp = el.elem.spl.info.spltyp; if (lintyp == 3 ) { /* * number of points in a line */ npts = el.elem.spl.info.numpts; /* * Format lats and lons into buffer. */ for ( ii = 0; ii < npts; ii++ ) { 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)) / 100.0F; y = ((int)(y*100)) / 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 ( bufferlat, str ); /* * this flag is here to ensure exit as soon * as a line is found */ more1 = G_FALSE; /* * this flag is here to ensure that lat-lon * pairs are written out even without wfo and states * grouped with it */ wrtoutfg = G_TRUE; } ne2 = 0; curpos2 = 0; more2 = G_TRUE; while ( ne2 < MAX_EDITABLE_ELEMS && more2 == G_TRUE ) { cvg_rdrecnoc( ifname, ifptr, curpos2, &el, &ier ); if ( ier < 0 ) { more2 = G_FALSE; } else { curpos2 += el.hdr.recsz; vg_class = el.hdr.vg_class; vg_type = el.hdr.vg_type; grpnumbr2 = el.hdr.grpnum; if (grpnumbr2 == grpnumbr1 && grpnumbr2 != 0) { if ((int)vg_type == LIST_ELM ) { areatype = 0; areatype = el.elem.lst.info.subtyp; if (areatype == 3) { wrtwfofg = G_TRUE; narea = el.elem.lst.data.nitems; strwfo[0] = '\0'; strcat( strwfo, "ATTN...WFO..."); jj = 0; for (jj = 0; jj < narea; jj++) { strcpy (str, el.elem.lst.data.item[jj]); strcat (strwfo, str); strcat (strwfo, "..." ); if ((jj+1)%9 == 0) { strcat (strwfo, "\n"); } } strcat (strwfo, "\n"); } if (areatype == 4) { wrtsttfg = G_TRUE; narea = el.elem.lst.data.nitems; strstt[0] = '\0'; jj = 0; for (jj = 0; jj < narea; jj++) { strcpy (str, el.elem.lst.data.item[jj]); strcat (strstt, str); strcat (strstt, "Z000-" ); } strcat (strstt, "\n"); } } } } ne2++; } } } } } ne1++; /* * Write to output file. */ if (wrtoutfg == G_TRUE) { /* * Wrap bufferlat such that only 6 pairs of lat,lons on one line */ ilen = 55; cst_wrap( bufferlat, blank, &ilen, "\n", (char *)NULL, bufferlat, &ier ); if (wrtsttfg == G_TRUE) { /* * Wrap strstt such that only 7 STATE IDs on one line * and dump strstt into buffer for further output */ ilen = 49; cst_wrap( strstt, blank, &ilen, "\n", (char *)NULL, strstt, &ier ); strcat ( buffer, strstt ); strcat ( buffer, "\n"); } if (wrtwfofg == G_TRUE) { /* * Wrap strwfo such that only 9 WFOs on one line * and dump strswo into buffer for further output */ ilen = 67; cst_wrap( strwfo, blank, &ilen, "\n", (char *)NULL, strwfo, &ier ); strcat ( buffer, strwfo ); strcat ( buffer, "\n"); } strcat ( buffer, bufferlat); strcat ( buffer, "\n"); cfl_writ( ofptr, (int)strlen(buffer), (unsigned char *)buffer, &ier ); bufferlat[0] = '\0'; } } /* * If no line is found, close files and exit. */ cfl_clos ( ifptr, &ier ); cfl_clos ( ofptr, &ier ); return(0); }
int main ( int argc, char *argv[] ) /************************************************************************ * sigavgf * * * * This program reads Significant Weather ASCII files and encodes the * * information into a VG file format. * * * * command line: * * sigavgf dattim hh * * dattim GEMPAK date/time string * * hh Valid time (hours) - must be 18 or 24 * ** * * Log: * * A. Hardy/SAIC 3/02 Created * * A. Hardy/SAIC 5/02 Added optional input file name; changed * * default input file name * * M. Li/SAIC 7/04 Removed grpch from sigajet * * M. Li/SAIC 9/04 Add idcent, chbase and chtop to cas_rdhdr* * M. Li/SAIC 1/05 Process SWM * * M. Li/SAIC 10/05 Checked for new format of jet info * ***********************************************************************/ { int ier, numerr, leverr, pagflg, grpid, iret; int itime[5], jtime[5], idcent; float chbase, chtop; int numtrp, rnum, lnum, hnum, membx, memhi, memlo; int memcld, memmcld, memfrt, memjet, memstm, memtur, memvlr; int numcld, nummcld, numfrt, numjet, numstm, numtur, numvlr; char fhour [3], fname[256], gtstr[12], grpch, chlvl[10]; char errgrp[8], cc[50], casgrp[4]; char path[256]; char newflvl[10]; long size; cloud_t *ptrc, *head, *ptr2; mcloud_t *ptrm, *headm, *ptr2m; jets_t *ptrj, *headj, *ptr2j; front_t *ptrf, *headf, *ptr2f; turb_t *ptrb, *headb, *ptr2b; storm_t *ptrs, *heads, *ptr2s; volrad_t *ptrv, *headv, *ptr2v; trop_t *ptrr, *headr, *ptr2r; trophi_t *ptrh, *headh, *ptr2h; troplo_t *ptrl, *headl, *ptr2l; Boolean readflg; FILE *ifpout; /*---------------------------------------------------------------------*/ iret = 0; leverr = 0; readflg = True; ifpout = NULL; strcpy ( errgrp, "SIGAVGF" ); strcpy ( casgrp, "CAS"); strcpy ( cc, " " ); rnum = lnum = hnum = 0; membx = memhi = memlo = 0; memcld = memmcld = memfrt = memjet = memstm = memtur = memvlr = 0; numcld = nummcld = numfrt = numjet = numstm = numtur = numvlr = 0; ptrc = NULL; ptrm = NULL; ptrj = NULL; ptrf = NULL; ptrb = NULL; ptrs = NULL; ptrv = NULL; ptrr = NULL; ptrh = NULL; ptrl = NULL; in_bdta ( &ier ); /* * If the forecast hour is not on the command line, print help * and exit. */ if ( argc < 3 ) { pagflg = G_FALSE; ip_help ( errgrp, &pagflg, &ier, strlen(errgrp) ); numerr = -1; er_lmsg ( &leverr, errgrp, &numerr, cc, &ier, strlen(errgrp), strlen(cc) ); exit (1); } strcpy ( fhour, argv[2] ); if ( strcmp ( fhour, "24") != 0 ) { if ( strcmp ( fhour, "18") != 0 ) { numerr = -2; er_lmsg ( &leverr, errgrp, &numerr, fhour, &ier, strlen(errgrp), strlen(fhour) ); exit (1); } } /* * Check for input file. */ if ( argv[3] != NULL ) { strcpy ( fname, argv[3] ); } else { /* * If an input file is not specified, check for the existence of * either SIGWXHI.txt or SIGWXMID.txt. */ sprintf ( fname, "SIGWXHI.txt" ); cfl_inqr ( fname, NULL, &size, path, &ier ); if ( ier != 0 ) { sprintf ( fname, "SIGWXMID.txt" ); cfl_inqr ( fname, NULL, &size, path, &ier ); if ( ier != 0 ) { numerr = -3; er_lmsg ( &leverr, errgrp, &numerr, fname, &ier, strlen(errgrp), strlen(fname) ); exit (1); } } } ifpout = cas_open ( fname, readflg, &ier ); /* * If input ASCII file failed to open, exit program. */ if ( ier != 0 ) { numerr = -3; er_lmsg ( &leverr, errgrp, &numerr, fname, &ier, strlen(errgrp), strlen(fname) ); exit (1); } /* * Read in the input ASCII file into the CAS structures. */ cas_rdhdr ( ifpout, itime, jtime, &idcent, &chbase, &chtop, &ier ); rewind (ifpout); if ( G_ABS ( HI_BASE - chbase ) < 0.5F && G_ABS ( HI_TOP - chtop ) < 0.5F ) { strcpy ( chlvl, "SWH" ); cas_rdcld ( ifpout, &numcld, &ptrc, &memcld, &ier ); } else if ( G_ABS ( MID_BASE - chbase ) < 0.5F && G_ABS ( MID_TOP - chtop ) < 0.5F ) { strcpy ( chlvl, "SWM" ); cas_rdmcld ( ifpout, &nummcld, &ptrm, &memmcld, &ier ); } rewind (ifpout); cas_rdjets ( ifpout, &numjet, &ptrj, &memjet, &ier ); rewind (ifpout); cas_rdturb ( ifpout, &numtur, &ptrb, &memtur, &ier ); rewind (ifpout); cas_rdfrt ( ifpout, &numfrt, &ptrf, &memfrt, &ier); rewind (ifpout); cas_rdtrop ( ifpout, &numtrp, &ptrr, &membx, &rnum, &ptrl, &memlo, &lnum, &ptrh, &memhi, &hnum, &ier ); rewind (ifpout); cas_rdstm ( ifpout, &numstm, &ptrs, &memstm, &ier ); rewind (ifpout); cas_rdvlrd ( ifpout, &numvlr, &ptrv, &memvlr, &ier ); /* * Close input file. */ cas_clos ( ifpout, &ier ); /* * If ASCII file failed to close, write error message. */ if ( ier != 0 ) { numerr = -4; er_lmsg ( &leverr, casgrp, &numerr, fname, &ier, strlen(casgrp), strlen(fname) ); } /* * Initialize the group type table. */ ces_gtrtbl ( &iret ); /* * Call appropriate VG file encoding subroutines. * * Create cloud VG file. */ strcpy ( gtstr, "CLOUD"); ces_gtgid (gtstr, &grpid, &ier); grpch = (char) grpid; if ( strcmp ( chlvl, "SWH" ) == 0 ) { sigacld ( fhour, numcld, ptrc, itime, grpch, &ier ); } else { sigamcld ( fhour, nummcld, ptrm, itime, grpch, &ier ); } /* * Create jets VG file. */ ctb_rdprf ( "prefs.tbl", "config", "SIGWX_FLIGHT_LEVELS", newflvl, &ier ); sigajet ( fhour, numjet, ptrj, itime, chlvl, newflvl, &ier ); /* * Create turbulence VG file. */ strcpy ( gtstr, "TURB"); ces_gtgid (gtstr, &grpid, &ier); grpch = (char) grpid; sigatur ( fhour, numtur, ptrb, itime, grpch, chlvl, &ier ); /* * Create front VG file. */ strcpy ( gtstr, "FRONT"); ces_gtgid (gtstr, &grpid, &ier); grpch = (char) grpid; sigafrt ( fhour, numfrt, ptrf, itime, grpch, chlvl, &ier ); /* * Create tropopause VG file. */ sigatrp ( fhour, rnum, ptrr, hnum, ptrh, lnum, ptrl, itime, chlvl, &ier ); /* * Create symbol VG file. */ strcpy ( gtstr, "LABEL"); ces_gtgid (gtstr, &grpid, &ier); grpch = (char) grpid; sigavts ( fhour, numstm, ptrs, numvlr, ptrv, itime, grpch, chlvl, &ier ); /* * Free all created linked lists. */ /* Free cloud */ if ( memcld ) { head = ptrc; ptr2 = head -> next; while ( ptr2 != NULL ) { free (head); head = ptr2; ptr2 = ptr2 -> next; } free ( head ); } /* Free mcloud */ if ( memmcld ) { headm = ptrm; ptr2m = headm -> next; while ( ptr2m != NULL ) { free (headm); headm = ptr2m; ptr2m = ptr2m -> next; } free ( headm ); } /* Free jet */ if ( memjet ) { headj = ptrj; ptr2j = headj -> next; while ( ptr2j != NULL ) { free (headj); headj = ptr2j; ptr2j = ptr2j -> next; } free ( headj ); } /* Free turb */ if ( memtur ) { headb = ptrb; ptr2b = headb -> next; while ( ptr2b != NULL ) { free (headb); headb = ptr2b; ptr2b = ptr2b -> next; } free ( headb ); } /* Free front*/ if ( memfrt ) { headf = ptrf; ptr2f = headf -> next; while ( ptr2f != NULL ) { free (headf); headf = ptr2f; ptr2f = ptr2f -> next; } free ( headf ); } /* Free trop*/ if ( membx ) { headr = ptrr; ptr2r = headr -> next; while ( ptr2r != NULL ) { free ( headr ); headr = ptr2r; ptr2r = ptr2r -> next; } free ( headr ); } if ( memhi ) { headh = ptrh; ptr2h = headh -> next; while ( ptr2h != NULL ) { free ( headh ); headh = ptr2h; ptr2h = ptr2h -> next; } free ( headh ); } if ( memlo ) { headl = ptrl; ptr2l = headl -> next; while ( ptr2l != NULL ) { free ( headl ); headl = ptr2l; ptr2l = ptr2l -> next; } free ( headl ); } if ( memstm ) { heads = ptrs; ptr2s = heads -> next; while ( ptr2s != NULL ) { free ( heads ); heads = ptr2s; ptr2s = ptr2s -> next; } free ( heads ); } if ( memvlr ) { headv = ptrv; ptr2v = headv -> next; while ( ptr2v != NULL ) { free ( headv ); headv = ptr2v; ptr2v = ptr2v -> next; } free ( headv ); } return 0; }
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); }
int main ( int argc, char *argv[] ) /************************************************************************ * main * * * * Main program of ssfgsf. * * * * int main ( argc, argv ) * * * * Input parameters: * * argc int Number of arguments * * **argv char arguments array * * * * Output parameters: * * Return parameters: * * NONE * * * ** * * Log: * * R. Tian/SAIC 2/06 Initial coding * ***********************************************************************/ { char infile[MXFLSZ], outfil[MXFLSZ], window[MXFLSZ], prognm[7]; int opt, hasgsf, pagflg, iret; /*---------------------------------------------------------------------*/ strcpy ( prognm, "ssfgsf" ); hasgsf = G_FALSE; pagflg = G_FALSE; /* * Set default subset window. */ strcpy ( window, "-9999.;-9999.;-9999.;-9999." ); /* * Parse command line arguments. */ while ( ( opt = getopt ( argc, argv, "o:w:h" ) ) != -1 ) { switch ( opt ) { case 'o': strcpy ( outfil, optarg ); hasgsf = G_TRUE; break; case 'w': strcpy ( window, optarg ); break; case 'h': default: ip_help ( prognm, &pagflg, &iret, strlen(prognm) ); exit (0); break; } } /* * Check for any input error. */ if ( argc - optind != 1 || hasgsf == G_FALSE ) { ip_help ( prognm, &pagflg, &iret, strlen(prognm) ); exit (-1); } /* * Get input SSF file name. */ strcpy ( infile, argv[optind] ); /* * Call Fortran subroutine to do the job. */ map_ssfgsf ( infile, outfil, window, &iret, strlen(infile), strlen(outfil), strlen(window) ); /* * Remove intermediate files. */ remove ( DAFILE ); remove ( SQFILE ); return 0; }
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); }