Exemple #1
0
void grdnav_init()
{
  int ier, iret, nitm;
  char buf[255], subst[255], *cpos;
  FILE *fp;
  nav_list *q;

  if ( ( fp = cfl_tbop ( "grdnav.tbl", "grid", &ier) ) != NULL ) {
    while ( ier == 0 ) {
      cfl_trln ( fp, sizeof(buf), buf, &ier);
      if  ( ( ier == 0 ) && ( ( q = (nav_list *)malloc( sizeof(nav_list) ) ) != NULL ) ) {

	cpos = cst_split( buf, ' ', sizeof(subst)-1, subst, &iret);
        if ( iret == 0 ) {
	  cst_ncpy(q->id,subst,sizeof(q->id)-1, &iret);
	  cst_ldsp(cpos, cpos, &nitm, &iret);
	}

	cpos = cst_split( cpos, ' ', sizeof(subst)-1, subst, &iret);
        if ( ( iret == 0 ) && ( cpos != NULL ) ) {
          iret = sscanf(subst,"%d",&(q->gnum));
	  cst_ldsp(cpos, cpos, &nitm, &iret);
	}
        else {
          free(q);
          continue;
        }

	cpos = cst_split( cpos, ' ', sizeof(subst)-1, subst, &iret);
        if ( ( iret == 0 ) && ( cpos != NULL ) ) {
	  cst_ncpy(q->proj,subst,sizeof(q->proj)-1, &iret);
	  cst_ldsp(cpos, cpos, &nitm, &iret);
	}
	else {
          free(q);
          continue;
        }

	iret = sscanf(cpos,"%f %f %f %f %f %f %f %d %d",
			&(q->angle[0]), &(q->angle[1]), &(q->angle[2]),
			&(q->llt), &(q->lln), &(q->ult), &(q->uln),
			&(q->kx), &(q->ky) );
        if ( iret == 9 ) {
	   q->next = nav_head;
	   nav_head = q;
        }
        else {
	   free(q);
	}
      }
    }
  }

  
}
void set_cntr(char *cntr)
{
int iret,nexp=3,num;
float rdef=0,rval[3];
static char sep[]="/";
char *cpos, outstr[80];


cpos = cst_split(cntr, ';', 79, outstr, &iret);

if(iret == 0)
   {
   st_rlst(outstr,sep,&rdef,&nexp,rval,&num,&iret,strlen(outstr),strlen(sep));

   cntr_col = (int)rval[0];

   if(rval[1] != rdef) cntr_sz = rval[1];
   if(rval[2] != rdef) cntr_wid = (int)rval[2];
   }

if(cpos != NULL)
   {
   in_filt( cpos, &cntr_filter, &iret, strlen(cpos));
   }

}
void set_maxtop(char *maxtop)
{
int iret;
char *cpos,outstr[80];
cpos = cst_split(maxtop, ';', 79, outstr, &iret);

if ( iret == 0 )
   cst_numb( outstr, &maxtop_col, &iret);

if ( cpos != NULL )
   in_filt( cpos, &maxtop_filter, &iret, strlen(cpos));
}
void set_meso(char *meso)
{
int iret;
char *cpos,outstr[80];

cpos = cst_split(meso, ';', 79, outstr, &iret);
if(iret == 0)
   {
   in_mark(outstr,&meso_col,&iret,strlen(outstr));
   gqmrkr(&meso_mark,&meso_hw,&meso_sz,&meso_wid,&iret);
   }

if( cpos != NULL )
   in_filt( cpos, &meso_filter, &iret, strlen(cpos));
}
void set_tvs(char *tvs)
{
int iret;
char *cpos,outstr[80];

cpos = cst_split(tvs, ';', 79, outstr, &iret);
if(iret == 0)
   {
   in_mark(outstr,&tvs_col,&iret, strlen(outstr));
   gqmrkr(&tvs_mark,&tvs_hw,&tvs_sz,&tvs_wid,&iret);
   }

if( cpos != NULL )
   in_filt( cpos, &tvs_filter, &iret, strlen(cpos));
}
void ctb_permccrd ( char *tblnam, char *dirsym, Permclust_t *pc, int *iret )
/************************************************************************
 * ctb_permccrd								*
 *									*
 * This routine will read the permanent clustered county table into a 	*
 * structure.								*
 *									*
 * ctb_permccrd ( tblnam, dirsym, pc, iret )				*
 *									*
 * Input parameters:							*
 *	*tblnam		char		Data type table name		*
 *	*dirsym		char		Directory			*
 *									*
 * Output parameters:							*
 *	*pc	Permclust_t 		Perm. clustered cnty structure	*
 *	*iret	int			Return code			*
 **									*
 * Log:									*
 * A. Hardy/NCEP	10/04		copied from ctb_ccrd		*
 * A. Hardy/NCEP        1/05	Added creation of virtual cluster combos*
 * 			      	& added error check on 1st cst_split    *
 ***********************************************************************/
{
    FILE    *ftbl;
    char    buff[256], pcname[32], *next;
    int	    ii, jj, ij, in, inx, numclust, fips[50], nfips, len, ier, ierr;
    int     ik, kk, ll, nn, itotal, srchfip, inum, ivfips, cfips[20];
    Boolean	found, match;
    static Permclust_t  vpc, tpc;

/*---------------------------------------------------------------------*/
    *iret = 0;

    /*
     *  Open the table.
     */
    ftbl = cfl_tbop ( tblnam, dirsym, iret );
    if ( *iret != 0 )  {
        tpc.nclust = 0;
        return;
    }

    /*
     *  Get number of valid table entries.
     */
    cfl_tbnr( ftbl, &numclust, &ier );

    if ( numclust != 0 )  {
        /*
         *  Allocate the structure elements.
         */
        tpc.nclust = numclust;
        tpc.clust = (PCinfo *) malloc( numclust * sizeof(PCinfo) );
    }
    else  {
        /*
         *  Problem opening table file; set error code and return.
         */
        cfl_clos( ftbl, &ier );
        *iret = -2;
        return;
    }

    rewind ( ftbl );

    /*
     *  For every valid table entry, read in, parse, put in structure
     */

    ii = 0;
    while ( ii < numclust )  {

	cfl_trln( ftbl, sizeof(buff), buff, &ier );

	if ( ier == 0 )  {

	    next = cst_split ( buff, '|', 4, tpc.clust[ii].pcwfo, &ier );

            if ( ier == 0 ) {
	        next = cst_split ( next, '|', 32, pcname, &ier );
	        tpc.clust[ii].pcname = 
		    (char *)malloc( (strlen(pcname)+1) * sizeof(char) );
	        strcpy ( tpc.clust[ii].pcname, pcname );

	        cst_rmbl ( next, next, &len, &ier );

	        cst_ilst ( next, '+', IMISSD, sizeof(fips)/sizeof(fips[0]),
		           fips, &nfips, &ier );

	        tpc.clust[ii].npc = nfips;
                tpc.clust[ii].pc = (int *)malloc( nfips * sizeof(int) );

	        for ( jj = 0; jj < nfips; jj++ )  {
		    tpc.clust[ii].pc[jj] = fips[jj];
	        }
            }
            else {
                ierr = 3; 
                er_wmsg ( "CTB", &ierr, buff, &ier, 3, strlen (buff) );
            }
	    ii++;

	}

    }

    cfl_clos ( ftbl, &ier );

   /*
    * Create virtual clusters.
    * Allocate the structure elements.
    */

    vpc.nclust = 0;
    vpc.clust = (PCinfo *) malloc( (numclust*4) * sizeof(PCinfo) );
    inum = vpc.nclust;
    ii = 0;
   /*
    * Loop over all perm clusters.
    */
    while ( ii < numclust ) {
        for ( jj = 1;jj < tpc.clust[ii].npc; jj++ ) {
            found = False;
            srchfip = tpc.clust[ii].pc[jj];
           /*
            * Compare search fip value to the other 1st fips codes.
            * Search permanent table first.
            */
            ij = 0;
            while ( (!found) && (ij < numclust ) ) {
               if ( srchfip == tpc.clust[ij].pc[0] ) {
                   found = True;
               }
               ij++;
            }
           /*
            * Search virtual cluster table next.
            */
            ij = 0;
            while ( (!found) && (ij < vpc.nclust ) ) {
                if ( srchfip == vpc.clust[ij].pc[0] ) {
                    found = True;
                }
                ij++;
            }

           /*
            * Didn't find a cluster group with search fip as first key.
            * Find all cluster groups in perm. table with this key in 
            * the cluster groups. Create a new virtual cluster entry.
            */

            if ( !found ) {
                cfips[0] = srchfip;
                ik = 0;
               /* Loop over rest of current clustered combo fips 
                * and store the codes temporarily.
                */
                for ( ij = 0; ij < tpc.clust[ii].npc;ij++ ) {
                    if ( tpc.clust[ii].pc[ij] != srchfip ) {
                       ik++;
                       cfips[ik] = tpc.clust[ii].pc[ij];
                    }
                }
               /* Set the number of virtual fips codes we have so far*/
                ivfips = ik+1;

               /* 
                * Check rest of perm clusters combox for srchfip.
                * Start with the next perm cluster combo.
                */
                inx = ii + 1;
                match = False;
                    /* loop over rest of combo clusters */
                    for ( kk= inx; kk < numclust; kk++ )  {
                        /* loop over number of counties in each cluster */
                        for ( ll = 0; ll < tpc.clust[kk].npc; ll++ )  {
                            /* look for a match in a cluster */
                            if ( tpc.clust[kk].pc[ll] == srchfip )  {
                                /* store all new codes in cfips array */
                                for ( nn = 0; nn < tpc.clust[kk].npc; nn++ )  {
                                    /* loop over current cluster array, store
                                       one's we don't have*/
                                    in = 0;
                                    while ( (in < ivfips ) && ( !match) ) {
                                        if ( tpc.clust[kk].pc[nn] == cfips[in] )  {
                                            match = True; 
                                        }
                                        in++;
                                    }
                                   /* didn't find fips in cfips array, keep it */
                                    if ( !match ) { 
                                        cfips[ivfips]  = tpc.clust[kk].pc[nn];
                                        ivfips++;
                                    }
                                    match = False;
                                }
                            }
                        }
                    }

               /*
                * Put temporary pcname, pcwfo, npc and fips array into 
                * virtual perm clust. combos.
                * Increment number of virtual fip cluster combos
                */

                 strcpy ( vpc.clust[inum].pcwfo, tpc.clust[ii].pcwfo );
             
	         vpc.clust[inum].pcname = 
		        (char *)malloc( (strlen(pcname)+1) * sizeof(char) );

                /*
                 * Store the number of fips codes and the code numbers
                 */
      
                  vpc.clust[inum].npc = ivfips;
                  vpc.clust[inum].pc = (int *)malloc( ivfips * sizeof(int) );
                  for ( ij= 0; ij < ivfips; ij++ )  {
                      vpc.clust[inum].pc[ij] = cfips[ij];
                  }
                  vpc.nclust++;
                  inum++;
            } /* (!found) loop */ 
        } /* for jj loop */
        ii++;
    } /* while ii loop */ 

   /*
    * Fill out output permanent cluster structure.
    * Allocate the structure elements.
    */

    itotal = numclust + vpc.nclust;
    pc->nclust = itotal;
    pc->clust = (PCinfo *) malloc( itotal * sizeof(PCinfo) );
    ii = 0;

   /*
    * Write out permanent table cluster combos first.
    */
    while ( ii < numclust )  {

        strcpy (pc->clust[ii].pcwfo, tpc.clust[ii].pcwfo);
        pc->clust[ii].pcname = 
                    (char *)malloc( (strlen(tpc.clust[ii].pcname)+1) * sizeof(char) );
        strcpy ( pc->clust[ii].pcname, tpc.clust[ii].pcname );

        pc->clust[ii].npc = tpc.clust[ii].npc;
        pc->clust[ii].pc = (int *)malloc( tpc.clust[ii].npc * sizeof(int) );
        for ( jj = 0; jj < pc->clust[ii].npc; jj++ )  {
            pc->clust[ii].pc[jj] =  tpc.clust[ii].pc[jj];
        }
        ii++;
    }
    
   /*
    * Write out virtual cluster combos next.
    */
    jj = 0;
    while ( ii < pc->nclust )  {

        strcpy (pc->clust[ii].pcwfo, vpc.clust[jj].pcwfo);
        pc->clust[ii].pcname =
                    (char *)malloc( 12 * sizeof(char) );
        sprintf ( pc->clust[ii].pcname, "VClust %d", jj+1 );

        pc->clust[ii].npc = vpc.clust[jj].npc;
        pc->clust[ii].pc = (int *)malloc( vpc.clust[jj].npc * sizeof(int) );
        for ( ij = 0; ij < pc->clust[ii].npc; ij++ )  {
            pc->clust[ii].pc[ij] =  vpc.clust[jj].pc[ij];
        }
        ii++;
        jj++;
    }

} 
void decode_strike(char *line, nldn_file ltgf)
{
static int isinit=!0;
int iret;
char result[256], *cpos;
int maxchar=sizeof(result)-1;
int year, month, day, hour, minute, second;
int mult;
float slat,slon,sgnl,emaj,emin;
nldn_flash flashdat;
time_t obsclock;
struct tm obstime;
int loglev, numerr,axisor;
static char errgrp[] = {"decode_strike"};
char errstr[LLMXLN];
int filver;

/* Split line into result (date string) and cpos (leftovers) */
cpos = cst_split(line,',',maxchar,result,&iret);

/* See if this look like a valid line (check if first char is 2[008] */
if ( ( iret != 0 ) || ( cpos == NULL ) || ( result[0] != '2' ) ) {
   printf("Not a strike line %s\n",line);
   return;
}

/* Check if file is old (filver = 4) or new (filver = 6)  */
filver = sscanf(cpos,"%f,%f,%f,%f,%f,%d", &slat, &slon, &sgnl, &emaj, &emin, &axisor);
switch ( filver ) {
   case 4:
      if ( (iret = sscanf(cpos,"%f,%f,%f,%d", &slat, &slon, &sgnl, &mult)) != 4 ) {
         sprintf(errstr,"Old: Not a strike line %s\0",line);
         loglev = 4;
         numerr = 1;
         dc_wclg(loglev, errgrp, numerr, errstr, &iret);
         return;
      }
   break;
   case 6:
      if ( (iret = sscanf(cpos,"%f,%f,%f,%f,%f,%d", &slat, &slon, &sgnl, &emaj, &emin, &axisor)) != 6 ) {
         sprintf(errstr,"New: Not a strike line %s\0",line);
         loglev = 4;
         numerr = 1;
         dc_wclg(loglev, errgrp, numerr, errstr, &iret);
         return;
      }
   break;
}

/* Check date string is formatted correctly */
if ( (iret = sscanf(result,"%d-%d-%dT%d:%d:%d", &year, &month, &day, &hour, &minute, &second )) != 6 ) {
   printf("Unexpected date string %s\n",result);
   return;
}

/* Initialize time zone information */
if(isinit) {
   isinit = 0;
   putenv("TZ=UTC0");
   tzset();
}

/* Convert time to seconds*/
obstime.tm_sec = second;
obstime.tm_min = minute;
obstime.tm_hour = hour;
obstime.tm_mday = day;
obstime.tm_mon = month - 1;
obstime.tm_year = year - 1900; /* year since 1900 */
obstime.tm_wday = 0;
obstime.tm_yday = 0;
obstime.tm_isdst = 0;
obsclock = mktime ( &obstime );

/* The following are present regardless of file version */
flashdat.sec = (int)obsclock;
flashdat.nsec = 0;
flashdat.lat = slat;
flashdat.lon = slon;
flashdat.sgnl = sgnl;

switch ( filver ) {
   case 4:
      flashdat.mult = mult;
      flashdat.semimaj = RMISSD;
      flashdat.eccent = RMISSD;
      flashdat.angle = RMISSD;
   break;
   case 6:
      flashdat.mult = 1;
      flashdat.semimaj = emaj;
      flashdat.eccent = emin;
      flashdat.angle = axisor;
   break;
}
flashdat.chisqr = RMISSD;

(void)write_point(ltgf, flashdat, &iret);
if ( iret != 0 )
   printf("%d look line %s %f %f %f %d [%d %d %d]\n",iret, result,slat,slon,sgnl,mult,
	obstime.tm_year, obstime.tm_mon, obstime.tm_mday);

}
Exemple #8
0
void clo_ddenc ( char *type, int format, float lat, float lon, char *str,
                 int *iret )
/************************************************************************
 * clo_ddenc                                                    	*
 *                                                                      *
 * This function returns gets the string for the seek and location      *
 * structure indicating which entry matches the input CLO name for the  *
 * given latitude and longitude. The format code is in a 4-5 digit      *
 * format (Eg. 5212 or 10212).  The columns are formatted as follows : 	*
 *					       				*
 *									*
 *   ROUNDING        UNITS        DIRECTION     DISPLAY			*
 *                                              			*
 *  5 - nearest 5    0 - omit     0 - omit      0 - degrees		*
 * 10 - nearest 10   1 - NM       1 - 16 point  1 - decimal/minutes   	*
 *                   2 - SM       2 - degrees   2 - 1st column		*
 *                   3 - KM             	4 - 3rd column		*
 *									*
 * For DISPLAY, the 1st column is usually the station id and the 3rd    *
 * column is the name of the station, city or county.			*
 *                                                                      *
 * clo_ddenc ( type, format, lat, lon, str, iret)                       *
 *                                                                      *
 * Input parameters:                                                    *
 *	*type		char		Name of CLO parameter		*
 *	format		int		Indicator of format to use      *
 *      lat            float            Latitude point                  *
 *      lon            float            Longitude point                 *
 *									*
 * Output parameters:                                                   *
 *	*str		char		Character string location       *
 *	*iret		int		Return value			*
 *					=  < 0 - String not created	*
 *									*
 **                                                                     *
 * Log:                                                                 *
 * A. Hardy/GSC		01/00	Create					*
 * A. Hardy/GSC		01/00	Added new format display option         *
 * A. Hardy/GSC		01/00	Added length chk of str;changed rounding*
 * A. Hardy/GSC		02/00	modified for all variations of formats  *
 * A. Hardy/GSC		02/00	reworked string display; city locations *
 * D.W.Plummer/NCEP	 8/00	changes for clo_ redesign		*
 * A. Hardy/GSC		 8/00   renamed from clo_format			*
 * T. Piper/GSC		 3/01	Fixed IRIX6 compiler warnings		*
 * D.W.Plummer/NCEP	 8/01	Repl clo_bqinfo w/ cst_gtag		*
 * D.W.Plummer/NCEP	 6/05	Tens digit sets # decimals for lat,lon	*
 ***********************************************************************/
{
    int		idist, icmp, nh, ier;
    int		ilat, ilon, imnt, imnn, isit, isin;
    char	stn[80], idx[80], *pidx, sdir[4];
    float	dist, dir;
    int         ione, itens, ihund, irnd, which, inlen;
    int         isln, iwidth, ilftovr;
    char        sdirc[5], sdist[5];
    char	info[128], fmt[20];
    /*---------------------------------------------------------------------*/
    *iret = 0;
    strcpy ( str, "NULL" );
    iwidth = 16;

    /*
     * Parse out format into it's components.
     */

    ione  = format % 10;
    itens = (int) (format/10) % 10;
    ihund = (int) (format/100) % 10;
    irnd  = format / 1000;

    /*
     * Check one's place for lat-lon or deg-min.
     */

    if ( ione == 0 ) {	/* show lat/lon */
        /*
         * Tens digit controls the number of decimal digits for the
         * lat,lon display. The default is 2 digits.
         */
        if ( itens == 0 )  itens = 2;
        sprintf(fmt,"%%.%df, %%.%df", itens, itens );
        sprintf(str, fmt, lat, lon);
    }
    else if ( ione == 1 ) {   /* show lat/lon as deg-min */
        isit = ( lat < 0.0F ) ? '-' : ' ';
        ilat = (int) G_ABS ( lat );
        imnt = G_NINT ( ( G_ABS(lat) - (float)ilat ) * 60.0F );
        if  ( imnt >= 60 )  {
            imnt = imnt % 60;
            ilat += 1;
        }

        isin = ( lon < 0.0F ) ? '-' : ' ';
        ilon = (int) G_ABS ( lon );
        imnn = G_NINT ( ( G_ABS(lon) - (float)ilon ) * 60.0F );
        if  ( imnn >= 60 )  {
            imnn = imnn % 60;
            ilon += 1;
        }

        sprintf ( str, "%c%3d:%02d, %c%3d:%02d",
                  isit, ilat, imnt, isin, ilon, imnn );
    }

    else {   /* show city/county/stn  */
        which = clo_which ( type );

        if ( clo.loc[which].format == 1 ) { 		/* show bound */

            clo_tqbnd ( type, lat, lon, idx, &ier);
            pidx = idx;

            /*
             *   Find and save the county FIPS id.
            */

            if ( ione == 2) {

                if (strcmp ( pidx,"-") != 0 ) {
                    clo_bginfo ( type, 0, info, &ier );
                    cst_gtag ( "FIPS", info, "?", str, &ier );
                }
                else {
                    cst_split (pidx, ' ', 14, str, &ier);
                }
            }
            if ( ione == 4) {  /* Save the bound name */
                cst_split (pidx, ' ', 14, str, &ier);
            }
        }


        else {
            if ( clo.loc[which].format == 0 ) { 	/* show station */

                /*
                 *  get station ID, distance and direction.
                 */
                clo_tdirect ( type, lat, lon, stn, &dist, &dir, &ier );

                if ( ione == 4 ) {
                    /*
                     *  Replace station ID w/ station name.
                     */
                    clo_tgnm ( type, 1, sizeof(stn), &nh, stn, &ier );
                }
            }

            if ( ihund == 0 ) {
                strcpy ( sdirc, "" );
            }
            else {
                if ( ihund == 1 ) {           /* get nautical miles */
                    dist *= M2NM;
                }
                else if ( ihund == 2 ) {      /* get statute miles */
                    dist *= M2SM;
                }
                else if ( ihund == 3 ) {      /* get kilometers */
                    dist /= 1000.0F;
                }

                if ( irnd > 0 ) {
                    idist = G_NINT ( dist / (float)irnd ) * irnd;
                    sprintf ( sdirc, "%i ", idist);
                }
                else if ( irnd < 0 ) {
                    irnd = 1;
                    idist = G_NINT ( dist / (float)irnd ) * irnd;
                    sprintf ( sdirc, "%i ", idist);
                }
                else if ( irnd == 0 ) {
                    strcpy ( sdirc, "" );
                }

            }

            if ( itens == 0 ) {  /* omit the direction */
                strcpy ( sdist, "" );
            }
            else {
                if ( itens == 1 ) {      /* use 16 point dir. */
                    clo_compass ( &dir, sdir, &icmp, &ier );
                    sprintf ( sdist, "%s", sdir );
                }
                else if  ( itens == 2 ) {      /* use degrees  */
                    sprintf ( sdist, "%.0f", dir );
                }
            }

            sprintf(str, "%s %s",sdirc, sdist);

            /*
             * If the stn name is longer than 4 chars, print
             */

            inlen = (int)strlen(stn);
            isln = (int)strlen(str);
            ilftovr = iwidth - isln;

            if (inlen > 4 )  {
                sprintf ( str, "%*s %.*s", isln, str, ilftovr, stn );
            }
            else {
                sprintf ( str, "%s %3s", str, stn );
            }

            if ( (ihund == 0 ) && ( itens == 0 ) ) {
                sprintf ( str, "%.*s", ilftovr, stn );
            }
        }
    }
    if ( strcmp ( str, "NULL") != 0 ) *iret = -1;
}
Exemple #9
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);
}
Exemple #10
0
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);
}