Beispiel #1
0
void boundry_segs(long int offset, int npts, char *bndtbl, int col1, int col2, 
			int ltype, int lwidth)
{
FILE *fp;
int iret;
int nsegs,i,j,k;
float mxlat,mnlat,mxlon,mnlon;
float *X,*Y;
float lt[4],ln[4];
char buf[256];
static char bounddir[]="bounds";

fp = (FILE *)cfl_tbop(bndtbl,bounddir,&iret);
if(iret == 0)
   cfl_seek(fp,offset,SEEK_SET,&iret);
else
   {
   printf("open failed %d\n",iret);
   return;
   }

if(iret == 0)
   {
   X = (float *)malloc(npts*sizeof(float));
   Y = (float *)malloc(npts*sizeof(float));
   cfl_rdln(fp,255,buf,&iret);
   /*printf("look cfl_rdln %d %s\n",iret,buf);*/
   i = 0;
   if(iret == 0)
      {
      sscanf(buf,"%d %f %f %f %f %f %f",&nsegs,&mxlat,&mnlat,&mxlon,&mnlon,X,Y);
      i++;
      while((i < nsegs/2)&&(iret == 0))
         {
         cfl_rdln(fp,255,buf,&iret);
         if(iret == 0)
            {
            j = sscanf(buf,"%f %f %f %f %f %f %f %f",
               lt,ln,lt+1,ln+1,lt+2,ln+2,lt+3,ln+3);
            for(k=0;k<j;k+=2)
               {
               X[i] = lt[k/2]; Y[i] = ln[k/2]; i++;
               } 
            }
         }
      }
   bounds_fill(X,Y,nsegs/2,col1);

   bounds_line(X, Y, nsegs/2, col2, ltype, lwidth);
   free(X); free(Y);
   }
cfl_clos(fp,&iret);

}
Beispiel #2
0
void vfasaw ( char *rcntsw, int *iwtnum, char *amdcde, int *iret )
/************************************************************************
 * vfasaw                                                               *
 *                                                                      *
 * This program opens, creates and closes the Weather Watch amended SAW	*
 * text product file having an extension in time.			*
 *                                                                      *
 * vfasaw ( rcntsw, iwtnum, amdcde, iret )	    			*
 *                                                                      *
 * Input parameters:                                                    *
 *	*rcntsw		char		Most recent SAW bulletin	*
 *	*iwtnum		int		watch number			*
 *	*amdcde		char		Amendment Code(AAx, x=A,B,C,...)*
 *                                                                      *
 * Output parameters:                                                   *
 *      *iret		int		Return Code                     *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * F. J. Yen/NCEP	 1/07	Created                                 *
 ***********************************************************************/
{
    FILE    *ifpsaw;
    char    ifname[256];
    int	    ier;
/*-------------------------------------------------------------------*/
    ier = 0;

   /*
    *  Create output file for amended SAW.
    */
    sprintf ( ifname, "WW%04d.SAW.AM%c", *iwtnum, amdcde[2] );
    ifpsaw = cfl_wopn ( ifname, &ier );

    fprintf ( ifpsaw, "%s", rcntsw );
    fprintf ( ifpsaw, "\n");
	
   /*
    *  Close output file.
    */

    cfl_clos ( ifpsaw, &ier );
}
Beispiel #3
0
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++;
    }

} 
Beispiel #4
0
void ctb_g2rdlvl ( char *tbname, G2lvls *lvltbl, int *iret ) 
/************************************************************************
 * ctb_g2rdlvl								*
 *									*
 * This routine will read a GRIB2 vertical coordinate level/layer       *
 * table into an array of structures.	                                *
 * The table is allocated locally and a pointer to the new table is     *
 * passed back to the user in argument lvltbl.  The user is responsible *
 * for freeing this memory, when the table is no longer needed, by      *
 * free(lvltbl.info)                                                    *
 *									*
 * ctb_g2rdlvl ( tbname, lvltbl, iret )				        *
 *									*
 * Input parameters:							*
 *	*tbname char    Filename of the table to read                   *
 *									*
 * Output parameters:							*
 *	*lvltbl G2lvls  Pointer to list of table entries                *
 *	*iret   int     Return code			                *
 *                          0 = Successful                              *
 *                         -1 = Could not open                          *
 *                         -2 = Could not get count of of table entries *
 *                        -52 = Memory allocation failure (G_NMEMRY)    *
 **									*
 * Log:									*
 * S. Gilbert/NCEP	 11/04	Modified from ctb_g2rdcntr to read a    *
 *                              GRIB2 level/layer Table.                *
 * S. Emmerson/Unidata   12/15  Added check for malloc() returning NULL *
 ***********************************************************************/
{
        FILE     *fp = NULL;
        int      n, blen, id1, id2, scale, nr, ier;
        char     buffer[256]; 
        char     name[34], abbrev[5], unit[21];

/*---------------------------------------------------------------------*/
	*iret = G_NORMAL;

        /*
         *  Open the table. If not found return an error.
         */

        fp = cfl_tbop( tbname, "grid", &ier);
        if ( fp == NULL  ||  ier != 0 )  {
            if (fp)
                fclose(fp);
            *iret = -1;
            return;
        }

        cfl_tbnr(fp, &nr, &ier);
        if ( ier != 0 || nr == 0 ) {
            *iret = -2;
            cfl_clos(fp, &ier);
            return;
        }

        lvltbl->info = (G2level *)malloc((size_t)nr*sizeof(G2level));
        if (lvltbl->info == NULL) {
            *iret = G_NMEMRY;
            cfl_clos(fp, &ier);
            return;
        }
        lvltbl->nlines = nr;

        n  = 0;
        while ( n < nr ) {

            cfl_trln( fp, 256, buffer, &ier );
            if ( ier != 0 ) {
                free(lvltbl->info);
                break;
            }

            cst_lstr (  buffer, &blen, &ier );

            sscanf( buffer, "%11d %11d %33c %20c %4s %11d",
                            &id1, &id2, name, unit, abbrev, &scale);

            name[33] = '\0';
            unit[20] = '\0';
            abbrev[4] = '\0';

            lvltbl->info[n].id1=id1;
            lvltbl->info[n].id2=id2;
            strcpy(lvltbl->info[n].name,    name);
            strcpy(lvltbl->info[n].unit,    unit);
            strcpy(lvltbl->info[n].abbrev,  abbrev);
            lvltbl->info[n].scale=scale;

            n++;
        }

        cfl_clos(fp, &ier);

}
Beispiel #5
0
void cvg_rdrec ( char *fname, int fpos, VG_DBStruct *el, int *iret )
/************************************************************************
 * cvg_rdrec								*
 *									*
 * This function reads a VG record from a VG file based upon the file	*
 * position.								*
 *									*
 * cvg_rdrec ( fname, fpos, el, iret )					*
 *									*
 * Input parameters:							*
 *	*fname		char		VG file name			*
 *	fpos		int		File position to read from 	*
 *									*
 * Output parameters:							*
 *	*el		VG_DBStruct	Pointer to VG record structure	*
 *	*iret		int		Return code			*
 *					 -1 = error opening VG file	*
 *					 -2 = error closing VG file	*
 *					-13 = error reading VG header	*
 *					-14 = error reading VG element	*
 *									*
 **									*
 * Log:									*
 * E. Wehner/EAi	11/96	Created					*
 * D. Keiser/GSC	 1/97	Clean up				*
 * E. Wehner/EAi	 8/97	Remove unneeded include 		*
 * E. Wehner/EAi	 9/97	Handle null file name			*
 * F. J. Yen/NCEP       11/97   Replace " " with NULL for       	*
 *                              default directory.              	*
 * G. Krueger/EAI	 1/98	Ignore non-fatal read warnings.		*
 * I. Durham/GSC	 5/98	Changed underscore decl. to an include	*
 * E. Safford/GSC	10/98	removed end from param list		*
 * J. Wu/SAIC		04/02	call cvg_rdrecnoc to read element	*
 * T. Lee/SAIC		11/03	used cvgcmn.h				*
 ***********************************************************************/
{
    int		ier;
    FILE 	*fp;
/*---------------------------------------------------------------------*/

    *iret = 0;

    if ( !fname ) {
	*iret = -47;
	return;
    }


    /*
     *  Open the file for READ only.
     */

    fp = (FILE *) cfl_ropn(fname, "", &ier);
    if ( ( ier != 0 ) || ( fp == NULL ) ) {
	*iret = -1;
        return;
    }


    /*
     *  Read the element.
     */
    cvg_rdrecnoc ( fname, fp, fpos, el, iret );


    /*
     *  Close the VG file.
     */
    cfl_clos ( fp, &ier );
    if ( ier != 0 )  *iret = -2;

}
void nexr_list_lev ( char *filnam, int *lenfnam,
		char *radparm, int *lenparm, int *ier)

{

int i, nbin, iret;
long    flen, lofset = 20;
char cfil[LLPATH], cprm[LLMXLN];
char stid[]="KFTG", callid[5];

Radar *radar=NULL;
FILE *fp;


*ier = 0;

strncpy(cfil, filnam, *lenfnam);
strncpy(cprm, radparm, *lenparm);
cfil[*lenfnam] = '\0';
cprm[*lenparm] = '\0';

/* get actual file name to use in rsl call */
cfl_inqr ( cfil, NULL, &flen, cfil, &iret);

RSL_select_fields(cprm, NULL);

/*
if ( cprm[0] == 'd' )
        VINDEX = DZ_INDEX;
else if ( cprm[0] == 's' )
        VINDEX = SW_INDEX;
else if ( cprm[0] == 'v' )
        VINDEX = VR_INDEX;
*/

/*
 * see if we can get the station ID from bytes 21-24, otherwise, just use any ID
 */

fp = cfl_ropn ( cfil, NULL, &iret );
if  ( iret != 0 )  {
    printf("failed to open %s\n",cfil);
    *ier = -1;
    return;
    }
else {
    cfl_seek ( fp, lofset, SEEK_SET, &iret );
    if  ( iret != 0 )  {
        *ier = -1;
        cfl_clos ( fp, &iret );
        return;
        }
    }

cfl_read ( fp, 4, (unsigned char *)callid, &nbin, &iret );
cfl_clos ( fp, &iret );

if (( nbin < 4 )||(callid[0] < 'A')||(callid[0] > 'Z')) /* use a safe station ID....we aren't plotting lat/lon anyhow */
   strcpy(callid,stid);
else
   callid[4] = '\0';


/*RSL_radar_verbose_on();*/
RSL_read_these_sweeps("all", NULL);
radar = RSL_wsr88d_to_radar(cfil, callid);
/*RSL_radar_verbose_off();*/

if ( radar == NULL )
   {
   printf("failed to open %s\n",cfil);
   *ier = -1;
   return;
   }

for (i=0; i<radar->h.nvolumes; i++) {
   if (radar->v[i]) {
        printf("Volume %s: Sweeps available %d\n", cprm, radar->v[i]->h.nsweeps);
        print_header_for_volume(radar->v[i]);
      }
   }

RSL_free_radar(radar);


}
Beispiel #7
0
void srchw_fosdScan ( srchinfo_t *srchinfo, int called_from, int *iret )
/************************************************************************
 * srchw_fosdScan							*
 *									*
 * This routine will scan a file given a search structure and return    *
 *    the appropriate report.                                           *
 *                                                                      *
 * srchw_fosdScan ( srchinfo, called_from, iret )  	               	*
 *                                                                      *
 * Input parameters:                                                    *
 *      *srchinfo       srchinfo_t      Search info structure           *
 *      called_from     int     	Indicate from where it is called*
 *                                	  1 - from user click           *
 *                                	  2 - from auto-update          *
 *                                                                      *
 * Output parameters:                                                   *
 *      *iret           int             Return code                     *
 *					-8 -- scandir failure		*
 *					-9 -- open file error		*
 *									*
 **									*
 * Log:									*
 * L. Williams/EAI       10/95						*
 * D.Plummer/NCEP        12/95		Reorganize for fosd type W      *
 * G. Krueger/EAI	  3/96		CFL_SOPN -> CFL_ROPN		*
 * L. Williams/EAI	  6/96		Check for duplicate reports	*
 * S. Jacobs/NCEP	 12/98		Changed fclose to cfl_clos	*
 * S. Danz/AWC		 12/00		Updated call to dttm_cpy	*
 * S. Danz/AWC		 12/00		Remove NULL chars from report	*
 * R. Tian/SAIC         04/02           Query file size before open it  *
 * T. Piper/SAIC	05/02	Close last file opened before returning	*
 * R. Tian/SAIC		11/03		Added called_from arg		*
 * T. Piper/SAIC	01/04	Added check for -8 from dir_getflist	*
 * T. Piper/SAIC	01/04	Added check on cfl_ropn			*
 * E. Safford/SAIC	12/07	rm direct access to textW widget	*
 ***********************************************************************/
{
char	*text, last_flg;
char	search_str[2];

static struct date_time_info _startd_save;
static struct date_time_info _endd_save;

int		i, j, duplicate, ier;
char            nofile_msg[80];
long            flen;
char            dumyname[133];

/* ------------------------------------------------------------------- */

	repnum=0;

/*
 * Scan the data directory for a list of valid files.
 */
        if ( (srchinfo->idtyp != _idtyp_save) ||
                (dttm_cmp(srchinfo->startd, _startd_save) != 0) ||
                (dttm_cmp(srchinfo->endd, _endd_save) != 0) )
        {
                _idtyp_save = srchinfo->idtyp;
                dttm_cpy(&_startd_save, srchinfo->startd);
                dttm_cpy(&_endd_save,   srchinfo->endd);

                dir_getflist( nwxTable->dtyp_info, srchinfo->idtyp, 
			srchinfo->startd, srchinfo->endd,
                        &srchinfo->dir_info, iret );
		if ( *iret == -8 ) {
		    return;
		}
		else if  ( *iret != 0 ) {
/*
 * no matching data file
 */
                    *iret = -1;
		    sprintf( nofile_msg, "No reports.\n\n" );
		    if ( called_from == 1 ) {
			pdata_setReportText( nofile_msg, &ier );
			txtw_dsplyReport( &ier );
		    }
		    stnList.nrptstn = 0;
                    return;
                }
	}

	last_flg = 0;
	search_str[0] = CHCTLA;
	search_str[1] = '\0';

	while ( !last_flg ) {

/*
 * Get the next data file.
 */
            dir_getnextf( &(srchinfo->dir_info), srchinfo->sflag,
                        &(srchinfo->file_info), iret);

            if (srchinfo->sflag == 0)
                srchinfo->sflag = -1;

            if ( *iret == 3 )
                last_flg = 1;

            if ( (*iret == 0) || (*iret == 3) ) { /* new file */

/*
 * Close the open file.
 */
                if  ( srchinfo->file_info.fptr != NULL ) {
                    cfl_clos ( srchinfo->file_info.fptr, iret );
		    srchinfo->file_info.fptr = NULL;
		}

/*
 * Get the size of the new file. If the size is 0, skip it.
 */
                cfl_inqr(srchinfo->file_info.filnam, NULL, &flen, dumyname,
                         iret);
                if  ( *iret != 0 || flen == 0) {
                    if ( last_flg ) {
                        break;
                    } else {
                        continue;
                    }
                }
                srchinfo->file_info.file_len = (int)flen;

/*
 * Open the new file.
 */
                srchinfo->file_info.fptr = cfl_ropn(
                                srchinfo->file_info.filnam,
                                NULL, iret );
                if  ( *iret != 0 ) {
		    *iret = -9;
		    return;
		}

/*
 * Allocate enough space to hold the entire contents of the file.
 */
                text = (char *) malloc((size_t)(srchinfo->file_info.file_len + 1) *
                                        sizeof(char) );

/*
 * Read the contents of the file into the TEXT string.
 */
                if ( fread( text, (size_t)srchinfo->file_info.file_len, 1,
                                srchinfo->file_info.fptr) != (size_t)1 ){
/*
 * reading error
 */
                    free ( text );
                    if ( last_flg ) {
                        break;
                    } else {
                        continue;
                    }
                }
                text[srchinfo->file_info.file_len] = '\0';

                for (i=0; i<srchinfo->file_info.file_len; i++) {
                    if (!text[i]) text[i] = ' ';
                }

/*
 * Search the TEXT for the search string and report's position.
 */

                srchw_fosdMarkrep( srchinfo, text, search_str, called_from, iret);

/*
 * Free the allocated space
 */
                free ( text );

            }
            else
                break;

	}   /*  end while  */

/*
 * Close the last open file.
 */
	if  ( srchinfo->file_info.fptr != NULL ) {
	    cfl_clos ( srchinfo->file_info.fptr, iret );
	    srchinfo->file_info.fptr = NULL;
	}

	stnList.nrptstn = 0;
	for( i = 0 ; i < stnList.nreports; i++ )  {
	    duplicate = G_FALSE;
	    for( j=0; j < i; j++ ) {
	        if( reportInfo[i].stnindex == reportInfo[j].stnindex ) {
		   duplicate = G_TRUE;
		   break;
	        }
	    }
	    if( ! duplicate ) {
	       stnList.rptstn[stnList.nrptstn] = reportInfo[i].stnindex;
	       stnList.rptstnlat[stnList.nrptstn] = stnList.lat[reportInfo[i].stnindex];
	       stnList.rptstnlon[stnList.nrptstn] = stnList.lon[reportInfo[i].stnindex];
	       stnList.nrptstn++;
	    }
	}
}
Beispiel #8
0
void shp_rdException ( int *iret )
/************************************************************************
 * shp_rdException							*
 *									*
 * This function reads the shape exception table.			*
 *									*
 * void shp_rdException ( iret )					*
 *									*
 * Input parameters:							*
 *									*
 * Output parameters:							*
 *	*iret	int		Return value				*
 *                               -1 - Unable to open table      	*
 *				 -2 - Information missing		*
 *									*
 **									*
 * Log:									*
 * H. Zeng/SAIC		07/07	created					*
 ***********************************************************************/
{
    int		num, ilat, ilon, idx, ier;
    char	tagstr1[128], tagstr2[128], tagstr3[128], tagstr4[128];
    char	tagstr5[128], tagstr6[128], tagstr7[128], buff[256];
    FILE    	*fp;
    /*---------------------------------------------------------------------*/

    *iret = 0;

    /*
     *  Open the shape exception table. If not found, return an error.
     */
    fp = cfl_tbop("shpexception.tbl", "stns", &ier);
    if ( fp == NULL  ||  ier != 0 )  {
        *iret = -1;
        return;
    }

    /*
     * Count # of records on the table.
     */
    cfl_tbnr (fp, &_numShpException, &ier);

    /*
     * Allocate space for _shpException.
     */
    _shpException = (ShpException_t*) malloc( sizeof(ShpException_t) *
                    _numShpException );

    /*
     *  Scan table line-by-line.
     */
    idx = 0;
    rewind (fp);
    while ( !feof(fp) )  {

        cfl_trln(fp, sizeof(buff), buff, &ier);
        if ( ier != 0 ) continue;

        num = sscanf (buff, "%s %s %s %s %s %s %s", tagstr1, tagstr2,
                      tagstr3, tagstr4, tagstr5, tagstr6, tagstr7);
        if ( num != 7 ) continue;

        if ( sscanf (tagstr6, "%d",  &ilat) == 1  &&
                sscanf (tagstr7, "%d",  &ilon) == 1     ) {

            strcpy ( _shpException[idx].id, tagstr1);
            _shpException[idx].fips = 0;
            sscanf (tagstr2, "%lu", &(_shpException[idx].fips));
            _shpException[idx].clat = ilat * 0.01;
            _shpException[idx].clon = ilon * 0.01;
            idx++;
        }
    } /* the end of while (... */

    cfl_clos(fp, &ier);

}
Beispiel #9
0
void cvg_scangfa ( char *fname, int layer, int subtype, int areatype,
		   char *tag, VG_DBStruct *el, int *selected, int *iret )
/************************************************************************
 * cvg_scangfa								*
 *									*
 * This function scans a vector graphics file looking for a GFA element	*
 * that matches the layer, subtype, area type (hazard) and tag input.	*
 * The first matching record is returned in "el". Also,			*
 * the element should match one of the active filters.			*
 *									*
 * cvg_scan ( fname, layer, subtype, areatype, tag, el, selected, iret )*
 *									*
 * Input parameters:							*
 *	*fname		char		Name of file to scan from	*
 *	layer		int		layer to test against		*
 *	subtype		int		subtype to test against		*
 *	areatype	int		area type to test against	*
 * 	tag		char		gfa tag to test against		*
 *									*
 * Output parameters:							*
 *	*el		VG_DBStruct	Pointer to VG record structure	*
 * 	*selected	int		Offset to selected element	*
 *	*iret		int		Return code			*
 *					 -1 = error opening VG file	*
 *					 -2 = error closing VG file	*
 *					 -6 = element not found		*
 *					-13 = error reading VG header	*
 *					-14 = error reading VG element	*
 *									*
 **									*
 * Log:									*
 * J. Wu/SAIC		08/04	initial coding (modified from cvg_scan)	*
 * J. Wu/SAIC		10/04	use cvg_getFld to access GFA attributes	*
 * E. Safford/SAIC	07/05	replace seqnum param with tag		*
 * J. Wu/SAIC		06/06	call cvg_matchfilter 			*
 * M. Li/SAIC           03/07   Updated cvg_matchfilter                 *
 ***********************************************************************/
{
    int		ii, ier, el_layer, location;
    float	llx,lly,urx,ury;
    long	size;
    char	newfil[133], reqfil[133], cclass, ctype, value[32];
    FILE	*fp;
    filter_t    el_filter, timeMatched;
    Boolean     filter_match, matchAny = False;
/*---------------------------------------------------------------------*/

    *iret = 0;
    *selected = -1;
    
    if ( !fname ) {
	strcpy ( reqfil, work_file );
    }
    else { 
	strcpy ( reqfil, fname );
    }

    /* 
     *  Inquire the size of the VG file and open the file for update.
     */
    cfl_inqr ( reqfil, NULL, &size, newfil, &ier );
    fp = (FILE *) cfl_uopn ( newfil, &ier );
    if ( (ier != 0) || (fp == NULL) ) {
	*iret = -1;
	return;
    }

    /* 
     *  Loop through all elements to find a match.
     */    
    for ( ii = 0; ii < MAX_EDITABLE_ELEMS; ii++ ) {

	crg_goffset ( ii, &location, &ier );
	if ( location < 0 ) {
	    continue;
	}

	crg_get ( ii, &el_layer, el_filter, &llx, &lly, &urx, &ury, &ier );
	if ( ier >= 0 ) {
	    crg_gtyp ( ii, &cclass, &ctype, &ier );
	}	
	
	if ( ier < 0 ) {
	    continue;
	}
	
	
	/*
	 *  Match layer, class, vg type first.
	 */
	if ( (el_layer == layer) && (cclass == CLASS_MET) &&
	     (ctype == GFA_ELM) ) {

	    
	    /*
	     *  Then check if the element matches one of the filters.
	     */
            cvg_matchfilter ( el_filter, matchAny, &filter_match, timeMatched, &ier );
	    
	    if ( !filter_match ) {
		continue;
	    }
            
	    
	    /*
             *  Read the element.
             */
            cvg_rdrecnoc ( newfil, fp, location, el, iret );	    
	    if ( *iret != 0 ) {
	        continue;
	    }
	    
	    
	    /*
             *  Match the subtype, area type, and tag.
             */
	    cvg_getFld ( el, TAG_GFA_SUBTYPE, value, &ier );
	    if ( subtype == atoi(value) ) {
	        cvg_getFld ( el, TAG_GFA_AREATYPE, value, &ier );
	        
  		if ( areatype == atoi(value) ) {
  	            cvg_getFld ( el, TAG_GFA_TAG, value, &ier ); 

		    if( strcmp( tag, value ) == 0 ) {	            
		        *selected = location;
		        break;
  		    } 
		}
	    }
	}	    
    }	


    /*
     *  Check if there is an matching record found.
     */
    if ( *selected < 0 ) {
        *iret = -6;
    }
    
    /*
     *  Close the VG file.
     */
    cfl_clos(fp, &ier);
    if ( ier != 0 )  *iret = -2;

}
Beispiel #10
0
void ctb_g2rdcntr ( char *tbname, G2wmocntrs *cntrtbl, int *iret ) 
/************************************************************************
 * ctb_g2rdcntr								*
 *									*
 * This routine will read a WMO originating Center table into an array  *
 * of structures.	                                                *
 * The table is allocated locally and a pointer to the new table is     *
 * passed back to the user in argument cntrtbl.  The user is resposible *
 * for freeing this memory, when the table is no longer needed, by      *
 * free(cntrtbl.info)                                                   *
 *									*
 * ctb_g2rdcntr ( tbname, cntrtbl, iret )				*
 *									*
 * Input parameters:							*
 *	*tbname		char		Filename of the table to read   *
 *									*
 * Output parameters:							*
 *	*cntrtbl	G2wmocenter	Pointer to list of table entries*
 *	*iret		int		Return code			*
 *                                        0 = Successful                *
 *                                       -1 = Could not open            *
 *                                       -1 = Could not get count of    *
 *                                            of teble entries.         *
 **									*
 * Log:									*
 * m.gamazaychikov/SAIC	 5/03						*
 * m.gamazaychikov/SAIC	 5/03	added parameter pdtnmbr to the table	*
 * M. Li/SAIC		 4/04	added hzremap, and direction		*
 * S. Gilbert/NCEP	 11/04	Modified from ctb_g2read to read a WMO  *
 *                              Originating Center Table.               *
 ***********************************************************************/
{
        FILE     *fp;
        int      n, blen, id, nr, ier;
        char     buffer[256]; 
        char     name[65], abbrev[9];

/*---------------------------------------------------------------------*/
	*iret = G_NORMAL;

        /*
         *  Open the table. If not found return an error.
         */

        fp = cfl_tbop( tbname, "grid", &ier);
        if ( fp == NULL  ||  ier != 0 )  {
            *iret = -1;
            return;
        }

        cfl_tbnr(fp, &nr, &ier);
        if ( ier != 0 || nr == 0 ) {
            *iret = -2;
            cfl_clos(fp, &ier);
            return;
        }

        cntrtbl->info = (G2wmocenter *)malloc((size_t)nr*sizeof(G2wmocenter));
        cntrtbl->nlines = nr;

        n  = 0;
        while ( n < nr ) {

            cfl_trln( fp, 256, buffer, &ier );
            if ( ier != 0 ) break;

	    cst_lstr (  buffer, &blen, &ier );

            sscanf( buffer, "%d %64c %s", 
                            &id, name, abbrev);

	    name[64] = '\0';
	    abbrev[8] = '\0';

            cntrtbl->info[n].id=id;
            strcpy(cntrtbl->info[n].name,    name);
            strcpy(cntrtbl->info[n].abbrev,  abbrev);

            n++;
        }

        cfl_clos(fp, &ier);

}
Beispiel #11
0
void vfwsaw ( int *iret )
/************************************************************************
 * vfwsaw                                                               *
 *                                                                      *
 * This program opens, creates and closes the Weather Watch SAW text    *
 * product file.							*
 *                                                                      *
 * vfwsaw ( iret )                                             		*
 *                                                                      *
 * Input parameters:                                                    *
 *                                                                      *
 * Output parameters:                                                   *
 *      *iret            int            Return Code                     *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * A. Hardy/GSC          8/99   Created                                 *
 * M. Li/GSC		10/99	Modified output format			*
 * A. Hardy/GSC         11/99   Added replacement watch information     *
 * A. Hardy/GSC		 2/00   Extracted from SPCTXT                   *
 * A. Hardy/GSC		 3/00   Add check for listing replacement states*
 * A. Hardy/GSC		 5/00   Changed cfl_aopn to cfl_wopn; Use       *
 *				AWIPS/WMO header ids.; removed 'NNNN'	*
 * A. Hardy/GSC		10/00   Added ck for '0' dist. anchor/vor points*
 * A. Hardy/GSC		12/00   Removed '&' from iret			*
 * A. Hardy/SAIC	10/01   Added check for old/new WMO header flag *
 * R. Tian/SAIC		06/02	Modified to meet the SPC requirement	*
 * R. Tian/SAIC		04/03	Corrected if(iret == 0) syntax error	*
 * A. Hardy/NCEP	 6/03	Change hail size to string for decimals *
 * A. Hardy/NCEP	10/03	Modified to use utl/wbc libraries and   *
 * 				added 'TEST' if a test watch		*
 * A. Hardy/NCEP	 3/04	Added wbc_mzrm				*
 * G. Grosshans/SPC	10/04	Added ADD_WATCH_APPROX check		*
 * G. Grosshans/SPC	11/05	Added LATLON_SAW_FORMAT tag to turn     *
 *				off lat-lon info at bottom of product.	*
 * S. Jacobs/NCEP	11/05	Fixed array indices for ilat and ilon	*
 * T. Piper/SAIC	12/05	Updated for cst_wrap CSC		*
 * J. Wu/SAIC		04/06	Added parameter in cst_wrap 		*
 ***********************************************************************/
{
    FILE    *ifpsaw;
    char    blank[2]={' '}, ifname[256], wtch_type[20];
    char    cname1[32], cname2[32], sep[5], cpstates[256], states[256];
    char    newname[132], tmpsaw[500], hwmstr[500];
    char    prefs_tag[] = "LATLON_SAW_FORMAT";
    float   xx, yy;
    int     ii, jj, ier, len, ilat[4], ilon[4];
    Boolean useln;
/*-------------------------------------------------------------------*/
    ier = 0;

   /*
    *  Create output file for appending.
    */

    utl_gname ( spcinfo.ancrpt.stn1, spcinfo.ancrpt.stnnam1, 
		spcinfo.ancrpt.stateid1, &ier );
    utl_gname ( spcinfo.ancrpt.stn2, spcinfo.ancrpt.stnnam2, 
		spcinfo.ancrpt.stateid2, &ier );

    sprintf ( ifname, "WW%04d.SAW", spcinfo.wnum );
    ifpsaw = cfl_wopn ( ifname, &ier );

   /*
    * Set up header information.
    */
    if ( strcmp(spcinfo.wtype,"SEVERE THUNDERSTORM" ) == 0 ) 
                strcpy ( wtch_type, "SEVERE TSTM");
    if ( strcmp(spcinfo.wtype,"TORNADO" ) == 0 ) 
                strcpy ( wtch_type, "TORNADO");

    spcinfo.sssnum = spcinfo.wnum % 10;
    fprintf ( ifpsaw, "WWUS30 KWNS %02d%s\n", 
                      spcinfo.itime.day,spcinfo.itime.hour);
    fprintf ( ifpsaw, "SAW%d \n", spcinfo.sssnum);
    fprintf ( ifpsaw, "%cSPC AWW %02d%s\n", CHRS, 
                      spcinfo.itime.day,spcinfo.itime.hour);

   /*
    * Replace underscores in the county names with a space.
    */

    cst_rnan (  spcinfo.ancrpt.stnnam1, cname1, &ier );
    cst_rnan (  spcinfo.ancrpt.stnnam2, cname2, &ier );

   /*
    * Check if watch has been issued as a 'TEST'.
    */ 

    if ( strcmp (spcinfo.status, "TEST") == 0 ) {
        fprintf ( ifpsaw, "WW %d TEST ", spcinfo.wnum); 
    }
    else {
        fprintf ( ifpsaw, "WW %d ", spcinfo.wnum); 
    }

   /*
    * Check for the marine zones which aren't the Great Lakes or
    * coastal water (CW). Remove them, if found.
    */

    strcpy (cpstates, spcinfo.states);
    wbc_mzrm ( cpstates, states, &len, &ier );

   /*
    * Set up rest of section.
    */

    fprintf ( ifpsaw, "%s %s %02d%sZ - %02d%sZ\n",
              wtch_type, states, spcinfo.vtime.day, 
	      spcinfo.vtime.hour, spcinfo.etime.day, spcinfo.etime.hour );
    fprintf ( ifpsaw, "AXIS..%d STATUTE MILES %s OF LINE..\n",
              spcinfo.ancatt.dist, spcinfo.ancatt.dirc );

   /*
    *  Check for zero distance for anchor points.
    */
    if ( (spcinfo.ancrpt.dist1 != 0 ) && ( spcinfo.ancrpt.dist2 != 0 ) ) {
        fprintf ( ifpsaw, "%d%s %s/%s %s/ - %d%s %s/%s %s/\n",
                  spcinfo.ancrpt.dist1, spcinfo.ancrpt.dirct1, spcinfo.ancrpt.stn1,
                  cname1, spcinfo.ancrpt.stateid1,
                  spcinfo.ancrpt.dist2, spcinfo.ancrpt.dirct2, spcinfo.ancrpt.stn2,
                  cname2, spcinfo.ancrpt.stateid2);
    }
    else if  ( ( spcinfo.ancrpt.dist1 == 0 ) && ( spcinfo.ancrpt.dist2 != 0 ) ) {
        fprintf ( ifpsaw, "%s/%s %s/ - %d%s %s/%s %s/\n",
                  spcinfo.ancrpt.stn1, cname1, spcinfo.ancrpt.stateid1,
                  spcinfo.ancrpt.dist2, spcinfo.ancrpt.dirct2, spcinfo.ancrpt.stn2,
                  cname2, spcinfo.ancrpt.stateid2);
    }
    else if  ( ( spcinfo.ancrpt.dist1 != 0 ) && ( spcinfo.ancrpt.dist2 == 0 ) ) {
        fprintf ( ifpsaw, "%d%s %s/%s %s/ - %s/%s %s/\n",
                  spcinfo.ancrpt.dist1, spcinfo.ancrpt.dirct1, spcinfo.ancrpt.stn1,
                  cname1, spcinfo.ancrpt.stateid1, spcinfo.ancrpt.stn2,
                  cname2, spcinfo.ancrpt.stateid2);
    }
    else if  ( ( spcinfo.ancrpt.dist1 == 0 ) && ( spcinfo.ancrpt.dist2 == 0 ) ) {
        fprintf ( ifpsaw, "%s/%s %s/ - %s/%s %s/\n",
                  spcinfo.ancrpt.stn1, cname1, spcinfo.ancrpt.stateid1, 
		  spcinfo.ancrpt.stn2, cname2, spcinfo.ancrpt.stateid2);
    }
   /*
    * Check for zero distance for the vor points.
    */
    if ( (spcinfo.vorrpt.dist1 != 0 ) && ( spcinfo.vorrpt.dist2 != 0 ) ) {
        fprintf ( ifpsaw, "..AVIATION COORDS.. %dNM %s /%d%s %s - %d%s %s/\n",
                  spcinfo.voratt.dist, spcinfo.voratt.dirc,
                  spcinfo.vorrpt.dist1, spcinfo.vorrpt.dirct1, spcinfo.vorrpt.stn1,
                  spcinfo.vorrpt.dist2, spcinfo.vorrpt.dirct2, spcinfo.vorrpt.stn2);
    }
    else if ( (spcinfo.vorrpt.dist1 == 0 ) && ( spcinfo.vorrpt.dist2 != 0 ) ) {
        fprintf ( ifpsaw, "..AVIATION COORDS.. %dNM %s /%s - %d%s %s/\n",
                  spcinfo.voratt.dist, spcinfo.voratt.dirc, spcinfo.vorrpt.stn1, 
		  spcinfo.vorrpt.dist2, spcinfo.vorrpt.dirct2, spcinfo.vorrpt.stn2);
    }
    else if ( (spcinfo.vorrpt.dist1 != 0 ) && ( spcinfo.vorrpt.dist2 == 0 ) ) {
        fprintf ( ifpsaw, "..AVIATION COORDS.. %dNM %s /%d%s %s - %s/\n",
                  spcinfo.voratt.dist, spcinfo.voratt.dirc, spcinfo.vorrpt.dist1, 
		  spcinfo.vorrpt.dirct1, spcinfo.vorrpt.stn1, spcinfo.vorrpt.stn2);
    }
    else if ( (spcinfo.vorrpt.dist1 == 0 ) && ( spcinfo.vorrpt.dist2 == 0 ) ) {
        fprintf ( ifpsaw, "..AVIATION COORDS.. %dNM %s /%s - %s/\n",
                  spcinfo.voratt.dist, spcinfo.voratt.dirc, 
		  spcinfo.vorrpt.stn1, spcinfo.vorrpt.stn2);
    }

   /*
    * Set up hail, wind gusts and lightning section.
    */

    tmpsaw[0] = '\0';
    cst_ncpy ( sep, "TO", 2, &ier );
    len = sizeof(hwmstr);
    wbc_dhwm ( sep, &(spcinfo.hailsz), &(spcinfo.maxgust), 
                &(spcinfo.maxtops), &(spcinfo.motion.deg), 
		&(spcinfo.motion.speed), len, hwmstr, &ier );
    tmpsaw[0] = '\0';
    strcat ( tmpsaw, hwmstr);
    strcat ( tmpsaw, EOL );
    cst_wrap ( tmpsaw, blank, &len, EOL, (char *)NULL, tmpsaw, &ier );
    fprintf ( ifpsaw, tmpsaw);

   /*
    *  If there are replacement watches listed, retrieve the lists of states
    *  for each replacement watch.
    */

    if ( strcmp ( spcinfo.replcnm[0], "NONE") != 0 ) {
	strcpy ( newname, "ww");
	strcat ( newname, spcinfo.replcnm[0] );
	strcat ( newname, ".txt" );
	strcpy ( newinfo.file_info.filnam,newname);
	vfrptxt (newname, iret); 
	if ( *iret == 0 ){
            wbc_mzrm ( newinfo.states, states, &len, &ier );
            fprintf ( ifpsaw, "\nREPLACES WW %d..%s \n",
	          atoi(spcinfo.replcnm[0]), states);
	}
	else {
	    fprintf ( ifpsaw, "         WW %d.. \n", 
	              atoi (spcinfo.replcnm[0]) );
        }
   /*
    *  If there are more that 1 replacement watches listed,
    *  proceed with the loop.
    */
        for(jj = 1; jj <= spcinfo.wwrepnm; jj++) {
	    strcpy ( newname, "ww");
	    strcat ( newname, spcinfo.replcnm[jj] );
	    strcat ( newname, ".txt" );
	    strcpy ( newinfo.file_info.filnam,newname);
  	    vfrptxt (newname, iret); 
	    if ( *iret == 0 ){
            wbc_mzrm ( newinfo.states, states, &len, &ier );
	    fprintf ( ifpsaw, "REPLACES WW %d..%s \n", 
	              atoi (spcinfo.replcnm[jj]), states);
	    }
	    else {
	      fprintf ( ifpsaw, "         WW %d.. \n", 
	              atoi (spcinfo.replcnm[jj]) );
	    }
        }
	fprintf ( ifpsaw, "\n");
    }
    else {
	    fprintf ( ifpsaw, "\n");
    }

    /*
     * Check if the LATLON_SAW_FORMAT flag is TRUE and then
     * add enhanced lat-lon data to the SAW text.
     * Make sure lats and lons are rounded to 
     * 100ths of deg.
     */

    tmpsaw[0] = '\0';
    ctb_pfbool (prefs_tag, &useln, &ier );
    if ( useln == TRUE ) {
	for ( ii = 0 ; ii < 4 ; ii++ ) {
            switch ( ii ) {
                case 0:
                    xx = ((int)(spcinfo.wcpnt1.lat*100.0F)) / 100.0F;
                    yy = ((int)(spcinfo.wcpnt1.lon*-100.0F)) / 100.0F;
                    break;
                case 1:
                    xx = ((int)(spcinfo.wcpnt2.lat*100.0F)) / 100.0F;
                    yy = ((int)(spcinfo.wcpnt2.lon*-100.0F)) / 100.0F;
                    break;
                case 2:
                    xx = ((int)(spcinfo.wcpnt3.lat*100.0F)) / 100.0F;
                    yy = ((int)(spcinfo.wcpnt3.lon*-100.0F)) / 100.0F;
                    break;
                case 3:
                    xx = ((int)(spcinfo.wcpnt4.lat*100.0F)) / 100.0F;
                    yy = ((int)(spcinfo.wcpnt4.lon*-100.0F)) / 100.0F;
                    break;
		default:
                    break;
            } 
            if ( yy >= 100.0F )  yy = yy - 100.0F;
            ilat[ii] = G_NINT(xx*100.0F);
	    ilon[ii] = G_NINT(yy*100.0F);
        }
        fprintf ( ifpsaw, "LAT...LON %4d%04d %4d%04d %4d%04d %4d%04d\n\n",
            ilat[0], ilon[0],
            ilat[1], ilon[1],
            ilat[2], ilon[2],
            ilat[3], ilon[3]);
    }

    /*
     * Check if the approximation verbage needs to be included
     * in the SAW text.
     */
    tmpsaw[0] = '\0';
    strcpy (prefs_tag, "ADD_WATCH_APPROX");
    ctb_pfbool (prefs_tag, &useln, &ier );

    if ( useln == TRUE ) {
       tmpsaw[0] = '\0';
       fprintf(ifpsaw, "THIS IS AN APPROXIMATION TO THE WATCH AREA.  FOR A\n");
       fprintf(ifpsaw, "COMPLETE DEPICTION OF THE WATCH SEE WOUS64 KWNS\n");
       fprintf(ifpsaw, "FOR WOU%d.\n", spcinfo.sssnum);
       fprintf(ifpsaw, "\n");
    }


   /*
    *  Close output file.
    */

    cfl_clos ( ifpsaw, &ier );
}
Beispiel #12
0
void vfwwcp ( int *iret )
/************************************************************************
 * vfwwcp                                                               *
 *                                                                      *
 * This program opens, creates and closes the WCP ( Watch Corner        *
 * Point - radar chart ) text product file.				*
 *                                                                      *
 * vfwwcp ( iret )                                             		*
 *                                                                      *
 * Input parameters:                                                    *
 *                                                                      *
 * Output parameters:                                                   *
 *      *iret            int            Return Code                     *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * A. Hardy/GSC		 5/00   Modified from VFWOUI			*
 * A. Hardy/GSC		12/00   Removed '&' from iret and ti_dayw	*
 * A. Hardy/GSC		 5/01   Removed parameter 'vmin' from vfgtod	*
 * A. Hardy/SAIC	10/01   Changed 'MKC' to 'SPC'			*
 * R. Tian/SAIC		06/02	Modified to meet the SPC requirement	*
 * A. Hardy/NCEP	 6/03	Added tmzn to CSS_DATE			*
 * B. Yin/SAIC          03/04   changed css_date calling sequences      *
 ***********************************************************************/
{
    FILE    *ifpwcp;
    char    ifname[256], vorstr[400], locnam[15], type[4];
    char    ampm[3], zone1[4], ampm1[3]; 
    char    chmon[4], chdwk[4], tmzn[4]; 
    float   vorlat1, vorlon1, vorlat2, vorlon2, hdiff;
    float   newlat1, newlon1, newlat2, newlon2;
    int     ier, etime[5], newtm, time;
    int     newtime, earr[5];
    int     itmarr[5], iarr[5], vtime[5], varr[5], datwk;
    int     istyp, isyr, ismon, isday, ishr, ismin, issec, ijulian;
/*-------------------------------------------------------------------*/
    ier = 0;
    newtm = 0;
    strcpy(locnam, "VOR");
    strcpy(type, "WCP");
    istyp =  1;

   /*
    *  Create output file for appending.
    */
    sprintf ( ifname, "WW%04d.WCP", spcinfo.wnum );
    ifpwcp = cfl_wopn ( ifname, &ier );

   /*
    * storing the issue, valid and ending time.
    */

    strcpy ( zone1, "UTC" );
    strcpy ( chmon, " " );
    time  = atoi(spcinfo.itime.hour);
    itmarr[0] = spcinfo.itime.year;
    itmarr[1] = spcinfo.itime.month;
    itmarr[2] = spcinfo.itime.day;
    itmarr[3] = time / 100;
    itmarr[4] = time % 100;

    ti_dayw( itmarr, &datwk, &ier );
    vfgdat ( itmarr[1], datwk, chmon, chdwk, &ier );
    ti_tzdf ( itmarr, zone1, spcinfo.timzone, iarr, &hdiff, &ier,
              strlen(zone1), strlen(spcinfo.timzone) );
    vfampm ( iarr[3], &newtime, ampm, &ier );

    if ( itmarr[2] != iarr[2] ) {
        ti_dayw( iarr, &datwk, &ier);
        vfgdat ( iarr[1], datwk, chmon, chdwk, &ier );
    }

    time     = atoi(spcinfo.vtime.hour);
    vtime[0] = spcinfo.vtime.year;
    vtime[1] = spcinfo.vtime.month;
    vtime[2] = spcinfo.vtime.day;
    vtime[3] = time / 100;
    vtime[4] = time % 100;

    ti_tzdf ( vtime, zone1, spcinfo.timzone, varr, &hdiff, &ier,
              strlen(zone1), strlen(spcinfo.timzone) );
    vfampm ( varr[3], &newtime, ampm, &ier );

    time     = atoi(spcinfo.etime.hour);
    etime[0] = spcinfo.etime.year;
    etime[1] = spcinfo.etime.month;
    etime[2] = spcinfo.etime.day;
    etime[3] = time / 100;
    etime[4] = time % 100;
    ti_tzdf ( etime, zone1, spcinfo.timzone, earr, &hdiff, &ier,
              strlen(zone1), strlen(spcinfo.timzone) );
    vfampm ( earr[3], &newtm, ampm1, &ier );
    vfgtod ( newtime, newtm, earr[4], ampm, ampm1, datwk,
             spcinfo.genday, &ier);

   /*
    * Set up top three lines of information.
    */

    css_date ( &istyp, &isyr, &ismon, &isday, &ishr, &ismin, &issec, 
               &ijulian, tmzn, &ier);

    fprintf ( ifpwcp, "WOUS50 KSPC %02d%s\n", spcinfo.itime.day,
                       spcinfo.itime.hour);
    fprintf ( ifpwcp, "SPCSEVSPC\n");
    fprintf ( ifpwcp, "FILE CREATED %02d-%s-%02d AT %02d:%02d:%02d UTC\n\n", 
                       isyr % 100 , chmon, isday, ishr, ismin, issec);

   /*
    * Set up effective time of day information section.
    */

    if ( strcmp(spcinfo.wtype,"TORNADO") == 0 ) {
        fprintf ( ifpwcp, "TORN %s WT0%d %s\n", spcinfo.itime.hour, spcinfo.wnum,
	          spcinfo.etime.hour);
    }
    if ( strcmp(spcinfo.wtype,"SEVERE THUNDERSTORM") == 0 ) {
        fprintf ( ifpwcp, "SEVR %02d%02d%02d %s WT%04d %s\n", (iarr[0] % 10),
	          spcinfo.itime.month, spcinfo.itime.day, spcinfo.itime.hour, 
		  spcinfo.wnum, spcinfo.etime.hour);
    }

   /*
    *  Locate the VOR corner points.
    */

    vfvors ( locnam, type, vorstr, &vorlat1, &vorlon1, &vorlat2, &vorlon2,
                 iret);

    /*
     * Converting hundreths into minutes.
     */

     vftomin ( spcinfo.wcpnt1.lat,  spcinfo.wcpnt1.lon,
                &(spcinfo.wcpnt1.newlat),  &(spcinfo.wcpnt1.newlon), iret );
     vftomin ( spcinfo.wcpnt2.lat,  spcinfo.wcpnt2.lon,
                &(spcinfo.wcpnt2.newlat),  &(spcinfo.wcpnt2.newlon), iret );
     vftomin ( vorlat2,  vorlon2, &newlat2,  &newlon2, iret );
     vftomin ( spcinfo.wcpnt3.lat,  spcinfo.wcpnt3.lon,
                &(spcinfo.wcpnt3.newlat),  &(spcinfo.wcpnt3.newlon), iret );
     vftomin ( spcinfo.wcpnt4.lat,  spcinfo.wcpnt4.lon,
                &(spcinfo.wcpnt4.newlat),  &(spcinfo.wcpnt4.newlon), iret );
     vftomin ( vorlat1,  vorlon1, &newlat1,  &newlon1, iret );

    /*  The statement below will truncate the minutes at the 100's position.
     *  No rounding takes place.
     */

     fprintf ( ifpwcp, "%05d.%05d %05d.%05d %05d.%05d %05d.%05d %05d.%05d %05d.%05d\n",
         (int)(spcinfo.wcpnt1.newlat * 100.0F), (int)(spcinfo.wcpnt1.newlon * -100.0F),
         (int)(spcinfo.wcpnt2.newlat * 100.0F), (int)(spcinfo.wcpnt2.newlon * -100.0F),
         (int)(newlat2 * 100.0F), (int)(newlon2 * -100.0F),
         (int)(spcinfo.wcpnt3.newlat * 100.0F), (int)(spcinfo.wcpnt3.newlon * -100.0F),
         (int)(spcinfo.wcpnt4.newlat * 100.0F), (int)(spcinfo.wcpnt4.newlon * -100.0F),
         (int)(newlat1 * 100.0F), (int)(newlon1 * -100.0F) );

    /*
     *  Close output file.
     */

     cfl_clos ( ifpwcp, &ier );
}
Beispiel #13
0
void pds_by10 ( const char *cvcrd, const char *wmotb, const char *nceptb,
                unsigned char *byte10, int *ibyt10, int *iscale, int *iret )
/************************************************************************
 * pds_by10								*
 *									*
 * This subroutine uses the GEMPAK GRIB vertical coordinate lookup	*
 * tables to determine the value of PDS octet 10.			*
 *									*
 * pds_by10 ( cvcrd, wmotb, nceptb, byte10, ibyt10, iscale, iret )	*
 *									*
 * Input parameters:							*
 *	*cvcrd		const char	GEMPAK VCORD name string	*
 *	*wmotb		const char	WMO GRIB VCORD LUT file name	*
 *	*nceptb		const char	NCEP GRIB VCORD LUT file name	*
 *									*
 * Output parameters:							*
 *	*byte10		unsigned char	Byte with GRIB VCORD # stored	*
 *	*ibyt10		int		Integer value of byte 10	*
 *	*iscale		int		Power of 10 scaling in GEMPAK	*
 *	*iret		int		Return code			*
 *					  0 = normal return		*
 *					-85 = VCORD not found		*
 *					-86 = VCORD # is invalid	*
 **									*
 * Log:									*
 * K. Brill/HPC		 7/99						*
 * R. Tian/SAIC		10/06	Recoded from Fortran			*
 ************************************************************************/
{
    char filnam[2][LLMXLN], record[LLMXLN], prmnam[17], chkprm[17];
    int found;
    int ifile, iprm, iscl, ier;
    FILE *fp;
/*----------------------------------------------------------------------*/
    *iret = 0;
    *byte10 = (unsigned char)( 255 );
    *ibyt10 = 255;
    *iscale = 0;

    /*
     * Check the tables.
     */
    cst_lcuc ( (char *)cvcrd, chkprm, &ier );
    strcpy ( filnam[0], wmotb );
    strcpy ( filnam[1], nceptb );
    found = G_FALSE;
    ifile = 0;
    while ( ifile < 2 && found == G_FALSE ) {
        fp = cfl_tbop ( filnam[ifile++], "grid", &ier );
	if ( ier != 0 ) continue;

	while ( ! feof(fp) && found == G_FALSE ) {
	    cfl_trln ( fp, sizeof(record), record, &ier );
	    if ( ier != 0 ) continue;

	    sscanf ( record, "%d", &iprm );
	    sscanf ( &record[59], "%s %d", prmnam, &iscl );

	    if ( strcmp ( prmnam, chkprm ) == 0 ) {
	        found = G_TRUE;
		*ibyt10 = iprm;
		*iscale = iscl;
	    }
	}
	cfl_clos ( fp, &ier );
    }
    if ( found == G_FALSE ) {
	*iret = -85;
    } else if ( *ibyt10 < 255 && *ibyt10 > 0 ) {
	*byte10 = (unsigned char)( *ibyt10 );
    } else {
	*iret = -86;
    }

    return;
}
Beispiel #14
0
void wclosp ( char *filnam, int *gfplot, int *iret )
/************************************************************************
 * wclosp								*
 *									*
 * This function closes the current gif image.				*
 *									*
 * void wclosp ( filnam, gfplot, iret )					*
 *									*
 * Input and output parameters:						*
 *  *filnam		char	file name				*
 *  *gfplot		int						*
 *									*
 * Output parameters:							*
 *  *iret		int	return value				*
 *									*
 **									*
 * Log:									*
 * D. Austin		 5/96						*
 * T. Lee/GSC		 7/00	Renamed from gdr_closp; Used cfl_wopn	*
 * T. Piper/SAIC	 1/02	Fixed memory leak; freed string		*
 * S. Jacobs/NCEP	 1/02	Moved free of string			*
 * S. Danz/AWC   	11/03	Check if *gfplot is set, not the ptr    *
 *				Only attempt to free if Current is set  *
 * S. Jacobs/NCEP	 7/13	Added file name to error output		*
 ***********************************************************************/
{
	char *space;
	char *string;
	int ier;
/*---------------------------------------------------------------------*/
	*iret = G_NORMAL;

	/* 
	 * Check the file.
	 */

	if  ( *gfplot && Current ) {

	    /*
	     * Make sure the new file's name is null terminated.
	     */

	    string = strdup ( filnam );
	    space = (char *) strchr( string, ' ' );
	    *space = '\0';

	    /*
	     * Set the filename in the struct.
	     */
	    Current->fname = string;

	    outfile =  cfl_wopn ( Current->fname, &ier );
	    if ( outfile == NULL ) {
		printf ( " Error: %d - Cannot open output file: %s\n",
		       	ier, Current->fname );
		exit (-1);
	    }

	    /*
	     * Free the temp string for the file name.
	     */
	    free ( string );

	    /* 
	     * Write the current imageout in GIF 89a format.
	     */

	    gdImageGif ( Current_Im, outfile );

	    /*
	     * Close the file.
	     */

	     cfl_clos ( outfile, &ier );
	}

	/*
	 * Free all resources.
	 */

        if ( Current ) {
	    free ( Current );
	    Current = NULL;
	    gdImageDestroy ( Current_Im );
	    Current_Im = NULL;
        }

	/*
	 * Reset the global pointers after closing the file.
	 */
	CurrentBGColorIndex = 0;
	CurrentColorIndex = 999;

}
Beispiel #15
0
void dc_dlog ( char *messag, int *lenm, int *iret )
/************************************************************************
 * dc_dlog								*
 *									*
 * This routine opens the decoder log file, writes the given message	*
 * and closes the file.							*
 *									*
 * dc_dlog  ( messag, lenm, iret )					*
 *									*
 * Input parameters:							*
 *	*messag		char		Message to write to the log	*
 *	*lenm		int		Number of chars in the message	*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *					   0 = normal return		*
 *					  -2 = error writing to log	*
 *									*
 **									*
 * Log:									*
 * S. Jacobs/NMC	 7/95						*
 * S. Jacobs/NCEP	 6/96	Updated documentation; Removed check	*
 *				for log file not opened; Changed to use	*
 *				a FILE stream with CFL_WRIT		*
 * S. Jacobs/NCEP	 7/96	Added open and close of log file	*
 * K. Tyle/GSC		 1/97	Remove prog. name and dattim; remove	*
 *				loglev variable				*
 * S. Jacobs/NCEP	 2/01	Removed all references to ulog		*
 ***********************************************************************/
{

	char	mesg[DCMXLN+8], tstr[12];
	int	lens, ier;

	FILE	*fplog;

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

/*
**	Start the output message with the process ID.
*/
	cst_inch ( ipid, tstr, &ier );
	strcpy ( mesg, "[" );
	strcat ( mesg, tstr );
	strcat ( mesg, "] " );

/*
**	Concatenate the input message to the output string.
*/
	strcat ( mesg, messag );
	cst_lstr ( mesg, &lens, &ier );

/*
**	Get the length of the message and add a Line Feed and
**	a NULL to the end.
*/
	if  ( lens > (DCMXLN+8) - 2 ) {
	    mesg [lens-1] = CHLF;
	    mesg [lens]   = CHNULL;
	}
	else {
	    mesg [lens]   = CHLF;
	    mesg [++lens] = CHNULL;
	}

/*
**	Open the decoder log file.
*/
	fplog = NULL;
	if  ( dcdlog[0] == '-' )
	{
/*
**	    If the file name is "-", open standard error for logging.
*/
	    fplog = stderr;
	}
	else
	{
/*
**	    Try to open the decoder log file.
*/
	    fplog = cfl_aopn ( dcdlog, &ier );
	    if  ( ier != 0 )
	    {
/*
**		If there is an error opening the file, open standard
**		error for real-time processing, otherwise write an
**		error message to the LDM log.
*/
		if  ( irltim )
		{
		    fplog = stderr;
		}
		else
		{
		    *iret = -3;
		    return;
		}
	    }
	}

/*
**	Write the message to the log file.
*/
	cfl_writ ( fplog, lens, (unsigned char *)mesg, &ier );
	if  ( ier != 0 ) {
	    *iret = -2;
	}

/*
**	Close the decoder log file.
*/
	if  ( fplog == stderr )
	{
/*
**	    If standard error is being used for logging, do nothing.
*/
	}
	else if ( fplog != NULL )
	{
/*
**	    Otherwise, close the log file.
*/
	    cfl_clos ( fplog, &ier );
	}

}
Beispiel #16
0
void cvg_rdfilter ( int *iret )
/************************************************************************
 * cvg_rdfilter								*
 *									*
 * This function reads in all valid entries in the filter table.	*
 *									*
 * cvg_rdfilter ( filter, iret )					*
 *									*
 * Input parameters:							*
 *	none								*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *					  0 = Normal  			*
 *					 -1 = unable to open table file	*
 **									*
 * Log:									*
 * J. Wu/SAIC		06/06   initial coding         			*
 ***********************************************************************/
{
    int		ier;
    char	buff[256], filtype[12], str[256], filstr[8];
    FILE	*fp;
/*---------------------------------------------------------------------*/
    
    *iret = 0;
    
    /*
     *  Read the table only once.
     */
    if ( filterLoaded )  return;
    
    
    /*
     *  Initialize.
     */
    nTblFilter = 0;
            
    
    /*
     *  Set the flag to True.
     */
    filterLoaded = True;


    /*
     *  Open the filter table. If not found, return an error.
     */
    fp = cfl_tbop ( FILTER_TBL, "pgen", &ier );
    if ( fp == NULL || ier != 0 ) {
        printf ( "not loaded ....\n" );
        *iret = -1;
        return;
    }
    
    /*
     *  Scan table line-by-line and load valid entries.
     */
    while ( !feof(fp) ) {

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

	if ( ier == 0 ) {

	    sscanf ( buff, "%s %s", filstr, filtype );

	    if ( strcmp ( filstr, "FILTER" ) != 0 ) {
		continue;	/* Skip invalid lines */
	    }
            
	    if ( ( strcmp ( filtype, "TIME") == 0 ) && 
	         ( nTblFilter < MAX_FILTER_NUM ) ) {
		sscanf ( buff, "%*s %*s %s", str );
		_fillStrArray ( MAX_FILTER_NUM, DSPLY_FILTER_SZ, str, 
				&nTblFilter, tblFilter );
	    }	    	    	    
	}
    }

    cfl_clos ( fp, &ier );

}
Beispiel #17
0
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;
}
Beispiel #18
0
void csctbl ( char *tblnam, int *iret )
/************************************************************************
 * csctbl								*
 *									*
 * This routine checks the GEMPAK graphic color table by searching the  *
 * local (current) dir and $GEMTBL/color directory then creates the 	*
 * structure for colors currently used in driver.  Default color table	*
 * is coltbl.xwp.							*
 *									*
 * csctbl (tblnam, iret)						*
 *									*
 * Input parameters:							*
 *	*tblnam		char	color table file			*
 *									*
 * Output parameters:							*
 *	*iret		int	return code				*
 *				  0 for successful			*
 *		 		 -1 for file error			*
 *		  		  2 for number of colors exceeded the 	*
 *					maximum				*
 *									*
 **									*
 * Log:									*
 * L. Williams		1/96						*
 * G. Krueger/EAI	8/96	Changed CFL_TOPN->TBOP			*
 * S. Wang/GSC		11/97	Change coltbl.xw to coltbl.xwp		*
 * S. Jacobs/NCEP	12/97	Fixed check for NULL table name		*
 * T. Piper/SAIC	1/02	Initialized iret 			*
 * T. Piper/SAIC	07/04	Used CLR_DIR and CLR_TBL		*
 ***********************************************************************/
{
    GmcColor	*gmc;
    FILE		*fp;
    char		*token, buf[BUF_SIZE], fname[256], tgcname[16];
    char		tmpabv[4], tmpname[40], txname[40], xcolr[50];
    int		ary_index, c_element, found, ier, ii, in_range;
    int		pos, rgbval, rc;

    /*---------------------------------------------------------------------*/

    rc = 0;
    ier = 0;
    *iret = 0;
    ary_index = 0;

    gmc = &gemCmap.color[0];

    /*
     * If table name is NULL use the default name.
     */
    if ( tblnam && tblnam[0] != '\0' ) {
        strcpy(fname, tblnam);
    }
    else {
        strcpy(fname, CLR_TBL);
    }

    /*
     * open color file
     */
    fp = cfl_tbop(fname, CLR_DIR, &ier);
    if (ier != 0) {
        *iret = -1;
        return;
    }

    /*
     * read and process each line
     */
    while (fgets(buf, BUF_SIZE, fp) != NULL) {

        if (ary_index > GRAPH_COLORS) {
            ngemC = GRAPH_COLORS; /* array overflow */
            fclose(fp);
            *iret = 2;
            return;
        }

        if ( (token=strtok(buf, TOKENDM)) == NULL )
            continue; /* empty line */

        if (*token == '#' || *token == ';' || *token == '!')
            continue; /* comments */

        c_element = 0;
        in_range = 0;
        rgbval = 1;
        found = 0;
        pos = 0;

        while (token) {

            switch ( c_element ) {

            case CNAME:	/* color name */

                strcpy( gemColrs[ary_index].name, token );
                break;

            case GMC:       /* abbreviated color name */

                break;

            case RED:       /* red color component */

                if ( (*token == 'N') || (*token == 'n') )
                    rgbval = 0;
                else
                    gemColrs[ary_index].red = atoi ( token );
                break;

            case GREEN:     /* green color component */

                if ( (*token == 'N') || (*token == 'n') )
                    rgbval = 0;
                else
                    gemColrs[ary_index].green = atoi ( token );
                break;

            case BLUE:      /* blue color component */

                if ( (*token == 'N') || (*token == 'n') )
                    rgbval = 0;
                else
                    gemColrs[ary_index].blue = atoi ( token );
                break;

            default:

                strncpy( &(xcolr[pos]), token, strlen(token));
                pos = pos + strlen(token);
                ++pos;
                xcolr[pos] = ' ';
                break;


            }

            token = strtok(NULL, TOKENDM);
            c_element++;
        }

        xcolr[pos-1] = '\0';

        /*
         * if RGB is avaliable check its range
         */
        if ( rgbval ) {
            if ( ( gemColrs[ary_index].red >= 0 &&
                    gemColrs[ary_index].red <= 255 ) &&
                    ( gemColrs[ary_index].green >= 0 &&
                      gemColrs[ary_index].green <= 255 ) &&
                    ( gemColrs[ary_index].blue >= 0 &&
                      gemColrs[ary_index].blue <= 255 ) ) {

                in_range = 1;
            }
        }

        /*
         * Check if xw color name is in Gempak color table
         */
        for (ii=0; ii < gemCmap.nc; ii++) {

            cst_lcuc( gemColrs[ary_index].name, tmpname, &rc );
            cst_lcuc( gmc[ii].gcname, tgcname, &rc);
            cst_lcuc( gmc[ii].abvname, tmpabv, &rc );
            cst_lcuc( gmc[ii].xname, txname, &rc );

            if ( (strcmp( tmpname, tgcname ) == 0) ||
                    (strcmp( tmpname, tmpabv ) == 0) ||
                    (strcmp( tmpname, txname ) == 0) ) {

                found = 1;

                if ( ( in_range ) &&
                        ( ( gemColrs[ary_index].red != gmc[ii].red ) ||
                          ( gemColrs[ary_index].green != gmc[ii].green ) ||
                          ( gemColrs[ary_index].blue != gmc[ii].blue ) ) ) {

                    gemColrs[ary_index].index = -1;
                }
                else {
                    gemColrs[ary_index].index = ii;
                    gemColrs[ary_index].red = -1;
                    gemColrs[ary_index].green = -1;
                    gemColrs[ary_index].blue = -1;
                }

                ary_index++;
                break;

            }

        } /* end for loop */

        /*
         * color name not found in Gempak table
         */
        if ( !found ) {

            /*
             * if range is ok set index
             */
            if (in_range) {

                gemColrs[ary_index].index = -1;
                ary_index++;

            }
        }


    } /* end while loop */

    ngemC = ary_index;

    if ( fp != NULL ) cfl_clos ( fp, &ier );

    return;

}
Beispiel #19
0
void crarea ( char *imgnam, int *iret )
/************************************************************************
 * crarea								*
 *									*
 * This subroutine reads the image data from a MCIDAS AREA file.	*
 * The full image is placed in memory pointed to by imgData.		*
 *									*
 * crarea ( imgnam, iret )						*
 *									*
 * Input parameters:							*
 *	*imgnam		char		Name of image file		*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *					G_NORMAL = normal return	*
 *					G_NIDSIZ = invalid image depth	*
 *					G_NIMGFL = cannot open/read img	*
 *					G_NMEMRY = memory alloc failure	*
 **									*
 * Log:									*
 * J. Cowie/COMET	 3/95						*
 * J. Cowie/COMET	 5/95	Modified to work with NAWIPS 5.2.1	*
 * S. Jacobs/NCEP	 1/97	Copied from XRAREA			*
 * J. Cowie/COMET	 1/97	Changed common variable names		*
 * J. Cowie/COMET	12/97	Added cfl_clos if error on cfl_seek	*
 * S. Chiswell/Unidata	 8/06	Added multibyte image check		*
 ***********************************************************************/
{
	FILE		*fp;
	char		defdir[12];
	long		lofset;
	unsigned int	iboff;
	int		lstrt, ii, jj, kk, nbin, ier;
	unsigned char	*rwdptr, *imdptr, buf[8];
	int		isPNG = 0;
/*---------------------------------------------------------------------*/

    if ( imdpth <= 0 ) {
	*iret = G_NIDSIZ;
	return;
    }
/*
 *  Open the file and seek to data offset.
 */
    defdir[0] = CHNULL;
    fp = cfl_ropn ( imgnam, defdir, &ier );
    if  ( ier != 0 )  {
	*iret = G_NIMGFL;
	return;
    }
    else {
	lofset = (long) imdoff;
	cfl_seek ( fp, lofset, SEEK_SET, &ier );
	if  ( ier != 0 )  {
	    cfl_clos ( fp, &ier );
	    *iret = G_NIMGFL;
	    return;
	}
	/* See if this is a png compressed AREA file */
	cfl_read ( fp, 8, buf, &nbin, &ier);
	if ( ( *iret == 0 ) && ( nbin == 8 ) ) {
            /*
            ** Check PNG magic word (8 first bytes):
            ** http://www.libpng.org/pub/png/spec/1.2/PNG-Rationale.html
            ** decimal     -  137 80 78 71 13 10   26 10
            ** hexadecimal -   89 50 4e 47 0d 0a   1a 0a
            ** ASCII       - \211  P  N  G \r \n \032 \n
            */

            if ( buf[0] == (unsigned char)137 && buf[1] == (unsigned char) 80 &&
                buf[2] == (unsigned char) 78 && buf[3] == (unsigned char) 71 &&
                buf[4] == (unsigned char) 13 && buf[5] == (unsigned char) 10 &&
                buf[6] == (unsigned char) 26 && buf[7] == (unsigned char) 10     ) {
		isPNG = 1;
	    }
	}
	cfl_seek ( fp, lofset, SEEK_SET, &ier );
    }
    *iret = G_NORMAL;
/*
 *  If this file contains only one channel (band) and no line
 *  prefix data, read the raw data directly into imgData and exit.
 */
    if ( imprsz == 0 && imnchl == 1 ) {
	if ( isPNG )
	   png_read ( fp, imnpix, imnlin, imgData, &ier );
	else
	   cfl_read ( fp, imldat, imgData, &nbin, &ier );
	cfl_clos ( fp, &ier );
	crarea_pixel ( imgData );
	return;
    }
    else {
/*
 *  Allocate space for the raw image data.
 */
	if  ( ( rawData == (unsigned char *) NULL ) ||
		( imldat > (int)last_rawsize) ) {
	    if  ( rawData != (unsigned char *) NULL) {
		free(rawData);
	    }
	    rawData = (unsigned char *) calloc ( imldat,
			sizeof(unsigned char) );
	    if  ( rawData == (unsigned char *) NULL ) {
		*iret = G_NMEMRY;
		return;
	    }
	    last_rawsize = imldat;
	}
/*
 *  Read the raw image data.
 */
	if ( isPNG )
	   png_read ( fp, imnpix, imnlin, imgData, &ier );
	else
	   cfl_read ( fp, imldat, rawData, &nbin, &ier );
	cfl_clos ( fp, &ier );

    }
/*
 *  Process the prefix bytes and move data for the
 *  image channel into the imgData array.
 *
 *  NOTE: This has been tested for images with prefix bytes.
 *	  Have not tested any image files with multiple channels
 *	  in the file.
 */
    imdptr = imgData;

    for ( ii = 0; ii < imnlin; ii++ ) {
/*
 *  Calculate the starting byte in rawData for this line.
 */
	lstrt = ii * (imnpix * imdpth * imnchl + imprsz);
	rwdptr = &rawData[lstrt];
/*
 *  Process prefix data to each line, if any.
 *  iboff = band offset in each element.
 */
	iboff = 0; 
	if  ( imprsz != 0 ) {
/*
 *  Skip 4 bytes of validity code.
 */
	    if  ( imvald != 0 )  rwdptr += 4;
/*
 *  Skip documentation and calibration code.
 */
	    rwdptr += imdcsz + imclsz;
/*
 *  Process level map to get the band for each element,
 *  if necessary.
 */
	    if  ( imnchl > 1) {
/*
 *  Get the band offset.
 */
		for ( kk = 0; kk < imlvsz; kk ++ ) {
		    if  ( *rawData == 8 ) {
			iboff = kk;
			rwdptr += imlvsz - kk;
			break;
		    }
		    else {
			rwdptr ++;
		    }
		}
	    }
	    else {
/*
 *  Skip the level map.
 */
		rwdptr += imlvsz;
	    }
	}  /* End of "if  ( imprsz != 0 )"  */
/*
 *  Get the image data.
 */
	for ( jj = 0; jj < imnpix; jj++ ) {
	    for ( kk = 0; kk < imdpth; kk++ ) {
		*imdptr++ = *(rwdptr + iboff);
		rwdptr ++;
	    }
	}
    }  /* End of loop over imnlin  */
    crarea_pixel ( imgData );
}
Beispiel #20
0
void vfcnsaw ( int *iret )
/************************************************************************
 * vfcnsaw                                                              *
 *                                                                      *
 * This program opens, creates and closes the Weather Watch cancel SAW  *
 * text product file.							*
 *                                                                      *
 * vfcnsaw ( iret )							*
 *                                                                      *
 * Input parameters:                                                    *
 *                                                                      *
 * Output parameters:                                                   *
 *      *iret            int            Return Code                     *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * A. Hardy/GSC         10/99   Created                                 *
 * A. Hardy/GSC		 2/00   Extracted from SPCTXT                   *
 * A. Hardy/GSC		 5/00   Changed cfl_aopn to cfl_wopn; Use	*
 *				AWIPS/WMO header ids.; removed 'NNNN'	*
 * A. Hardy/GSC		12/00   Added '&' to ier for vfgname,vfctim     *
 * A. Hardy/GSC		 5/01   Initialized iret to 0			*
 * A. Hardy/SAIC	10/01   Added check for old/new WMO header flag *
 * R. Tian/SAIC		06/02	Modified to meet the SPC requirement	*
 * A. Hardy/NCEP	 7/03   Added calls to UTL library		*
 * A. Hardy/NCEp	11/03	Added watch status check for 'TEST'	*
 ***********************************************************************/
{
    FILE    *ifpsaw;
    char    ifname[256];
    int     ier, leni;
/*-------------------------------------------------------------------*/
    *iret = 0;
    ier = 0;

   /*
    *  Create output file for appending.
    */

    utl_gname ( spcinfo.ancrpt.stn1, spcinfo.ancrpt.stnnam1, 
		spcinfo.ancrpt.stateid1, &ier );
    utl_gname ( spcinfo.ancrpt.stn2, spcinfo.ancrpt.stnnam2, 
		spcinfo.ancrpt.stateid2, &ier );

    sprintf ( ifname, "WW%04d.SAW.CNL", spcinfo.wnum );
    ifpsaw = cfl_wopn ( ifname, &ier );

   /*
    * Get current GEMPAK time for issue time of cancel product.
    */

    leni = sizeof(spcinfo.curtim);
    utl_ctim ( leni, spcinfo.curtim, &ier );

   /*
    * Set up header information.
    */
    spcinfo.sssnum = spcinfo.wnum % 10;
    fprintf ( ifpsaw, "WWUS30 KWNS %s\n", spcinfo.curtim);
    fprintf( ifpsaw, "SAW%d\n", spcinfo.sssnum);

    fprintf ( ifpsaw, "%cSPC AWW %s\n", CHRS, spcinfo.curtim);
   /*
    * Set up cancelled line.
    * Check if watch has been issued as a 'TEST'.
    */ 

    if ( strcmp (spcinfo.status, "TEST") == 0 ) {
        fprintf ( ifpsaw, "WW %d TEST %s CANCELLED\n\n", 
	          spcinfo.wnum, spcinfo.wtype); 
    }
    else {
        fprintf ( ifpsaw, "WW %d %s CANCELLED\n\n", 
	          spcinfo.wnum, spcinfo.wtype); 
    }

   /*
    *  Close output file.
    */

    cfl_clos ( ifpsaw, &ier );
}
Beispiel #21
0
void _getrpt ( srchinfo_t *srchinfo, char *report, int *iret )
/************************************************************************
 * _getrpt                                                            	*
 *                                                                      *
 * This routine will retrieve the report for the requested location.	*
 *									*
 * _getrpt ( srchinfo, report, iret )                                 	*
 *                                                                      *
 * Input parameters:                                                    *
 *      *srchinfo       srchinfo_t      Search info structure           *
 *                                                                      *
 * Output parameters:                                                   *
 *      *report         char            Report                          *
 *      *iret           int             Return code                     *
 *                                                                      *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * L. Williams/EAI       6/96	modified from srchb_fosdFndrepWW	*
 * S. Jacobs/NCEP	12/98	Changed fclose to cfl_clos		*
 * S. Chiswell/UCAR	04/01	Changed strchr to memchr		*
 * R.Tian/SAIC  	1/02	Avoid possible overflow report		*
 * R. Tian/SAIC         04/02   Query file size before open it 		*
 ***********************************************************************/
{
int     rep_len;
long    flen;
char    dumyname[133];
char	*iepos, *ispos, *text;
/*---------------------------------------------------------------------*/
/*
 * Get the size of the new file. If the size is 0, skip it.
 */
	cfl_inqr(srchinfo->file_info.filnam, NULL, &flen, dumyname, iret);
        if  ( *iret != 0 || flen == 0 ) {
               report[0] = '\0';
               *iret = -1;
               return; /* error in query file */
        }
        srchinfo->file_info.file_len = (int)flen;

/*
 * Open the new file.
 */
        srchinfo->file_info.fptr = cfl_ropn(
                srchinfo->file_info.filnam,
                NULL, iret );
        if  ( *iret != 0 ) {
               report[0] = '\0';
               *iret = -1;
               return; /* error in opening file */
        }

/*
 * Allocate enough space to hold the entire contents of the file.
 */
        text = (char *) malloc((size_t)(srchinfo->file_info.file_len + 1) *
                sizeof(char) );

/*
 * Read the contents of the file into the TEXT string.
 */
        if ( fread( text, (size_t)srchinfo->file_info.file_len, 1,
                srchinfo->file_info.fptr) != (size_t)1 ){
/*
 * reading error
 */
                report[0] = '\0';
                *iret = -1;
        	free( text );
                return;
        }

/*
 * Copy the report from string text to string report
 */

        ispos = &text[reportInfo[srchinfo->current].position];
        iepos = memchr( &text[reportInfo[srchinfo->current].position],
				CHCTLC, (size_t)(srchinfo->file_info.file_len - 
				reportInfo[srchinfo->current].position));
	if ( iepos != NULL )
	    rep_len = G_MIN((iepos - ispos), (REPMAX - 1));
	else
	    rep_len = 0;

        strncpy( report, &text[reportInfo[srchinfo->current].position], (size_t)rep_len
);
        report[rep_len] = '\0';

        free( text );

/*
 * Close the data file.
 */
        if  ( srchinfo->file_info.fptr != NULL )  {
		cfl_clos ( srchinfo->file_info.fptr, iret );
		srchinfo->file_info.fptr = NULL;
	}
}
Beispiel #22
0
void tb_nidsdb ( char *prdnam, char *res, int *iprod, int *iret )
/************************************************************************
 * tb_nidsdb								*
 *									*
 * This subroutine returns information about the radar image from the	*
 * NIDS product table file.						*
 *									*
 * void tb_nidsdb (  prdnam, res, iprod, iret )				*
 *									*
 * Input parameters:							*
 *	*prdnam		char		Product name			*
 *	*res		char		Data resolution in km		*
 *									*
 * Output parameters:							*
 *	*iprod		int		NIDS product ID                 *
 *	*iret		int		Return code			*
 *					  0 = normal return		*
 *					 +3 = No entry found for image	*
 *					 -7 = Could not open imtyp table*
 **									*
 * Log:									*
 * m.gamazaychikov/CWS	01/10	Created					*
 ***********************************************************************/
{
    int			found, ier, ier1, loglev=2;
    float               ares;
    char		*grp="TB", line[128];
    size_t		ii;
    static int		nr;
    static FILE		*fptr=NULL;
    static Radtbl_t	*radtbl=NULL;
/*---------------------------------------------------------------------*/
/*
 *  Initialize output variables.
 */
    *iprod = 0;
    *iret = 33;  /*  Not found  */
    cst_crnm ( res, &ares, &ier );

/*
 *  If table not yet read into memory; open the image type table file.
 */
    if ( fptr == NULL ) {
	fptr = cfl_tbop ( NIDPRD_TBL, "rad", &ier );
	if ( ier != 0 ) { 
	    *iret = -7;
	    er_lmsg (&loglev, grp, iret, NIDPRD_TBL, &ier1, strlen(grp), strlen(NIDPRD_TBL));
	    return;
	}

/*
 *  Load the structure.
 */
	cfl_tbnr (fptr, &nr, &ier );
	if ( ier != 0 || nr == 0 ) {
	    *iret = -7;
	    er_lmsg (&loglev, grp, iret, NIDPRD_TBL, &ier1, strlen(grp), strlen(NIDPRD_TBL));
	    cfl_clos(fptr, &ier);
	    return;
	}
	G_MALLOC(radtbl, Radtbl_t, nr, "tb_nidsdb:  radtbl");
	for (ii = 0; ii < (size_t)nr; ii++ ) {

/*
 *  Read the next record.
 */
	    cfl_trln ( fptr, 127, line, &ier );
	    if ( ier == 0 ) {
		sscanf(line,"%s %s %i %i %s %f %s",
			radtbl[ii].type, radtbl[ii].name, &radtbl[ii].prod,
			&radtbl[ii].lvls, radtbl[ii].units,
			&radtbl[ii].res, radtbl[ii].desc);
	    }
	}  /*  end of 'for (ii = 0; ii < nr; ii++ )'  */
	cfl_clos(fptr, &ier);
    }  /*  end of 'if ( *fptr == NULL )'  */

    ii = 0;
    found = G_FALSE;

/*
 *  Retrieve the product ID for the specified 
 *  product name and the resolution.
 */
    while ( !found && ii < (size_t)nr ) {
      //if ( strstr (radtbl[ii].name, prdnam) != NULL ) {
      if ( strcmp (prdnam, radtbl[ii].name) == 0 ) {
         if ( G_DIFF(ares, radtbl[ii].res) ) {
	    found = G_TRUE; 
	    *iprod = radtbl[ii].prod;
	    *iret = G_NORMAL;
         }
      }
      ii++;
    }
}
Beispiel #23
0
void ctb_g2rdvar ( char *tbname, G2vars_t *vartbl, int *iret ) 
/************************************************************************
 * ctb_g2rdvar								*
 *									*
 * This routine will read a GRIB2 Parameter                             *
 * table into an array of structures.	                                *
 * The table is allocated locally and a pointer to the new table is     *
 * passed back to the user in argument vartbl.  The user is resposible  *
 * for freeing this memory, when the table is no longer needed, by      *
 * free(vartbl.info)                                                    *
 *									*
 * ctb_g2rdvar ( tbname, vartbl, iret )				        *
 *									*
 * Input parameters:							*
 *	*tbname		char		Filename of the table to read   *
 *									*
 * Output parameters:							*
 *	*vartbl	G2vars_t	Pointer to list of table entries        *
 *	*iret		int		Return code			*
 *                                        0 = Successful                *
 *                                       -1 = Could not open            *
 *                                       -2 = Could not get count of    *
 *                                            of table entries.         *
 **									*
 * Log:									*
 * S. Gilbert/NCEP	 11/04	Modified from ctb_g2rdcntr to read a    *
 *                              GRIB2 Parameter Table.                  *
 ***********************************************************************/
{
        FILE     *fp = NULL;
        int      n, blen,  nr, ier;
        char     buffer[256]; 
        char     name[33], gname[13], unts[21];
        int      disc, cat, parm, pdtn, scl, ihzrmp, idrct;
        float    msng;

        const    int  ncoln=110;

/*---------------------------------------------------------------------*/
	*iret = G_NORMAL;

        /*
         *  Open the table. If not found return an error.
         */

        fp = cfl_tbop( tbname, "grid", &ier);
        if ( fp == NULL  ||  ier != 0 )  {
            if (fp)
                fclose(fp);
            *iret = -1;
            return;
        }

        cfl_tbnr(fp, &nr, &ier);
        if ( ier != 0 || nr == 0 ) {
            *iret = -2;
            cfl_clos(fp, &ier);
            return;
        }

        vartbl->info = malloc((size_t)nr*sizeof(G2Vinfo));
        if (vartbl->info == NULL) {
            *iret = -1;
            cfl_clos(fp, &ier);
            return;
        }
        vartbl->nlines = nr;

        n  = 0;
        while ( n < nr ) {

            cfl_trln( fp, 256, buffer, &ier );
            if ( ier != 0 ) {
                free(vartbl->info);
                break;
            }

	    cst_lstr (  buffer, &blen, &ier );

            if ( blen > ncoln ) {
                sscanf( buffer,
                        "%12d %12d %12d %12d %32c %20c %12s %12d %20f %12d %12d",
                            &disc, &cat, &parm, &pdtn,
                            name, unts, gname,
                            &scl, &msng, &ihzrmp, &idrct );
            }
            else {
                sscanf( buffer, "%12d %12d %12d %12d %32c %20c %12s %12d %20f",
                            &disc, &cat, &parm, &pdtn,
                            name, unts, gname,
                            &scl, &msng);
                ihzrmp = 0;
                idrct = 0;
            }


	    name[32] = '\0';
	    unts[20] = '\0';
	    gname[12] = '\0';

            vartbl->info[n].discpln=disc;
            vartbl->info[n].categry=cat;
            vartbl->info[n].paramtr=parm;
            vartbl->info[n].pdtnmbr=pdtn;
            strcpy(vartbl->info[n].name,    name);
            strcpy(vartbl->info[n].units,   unts);
            strcpy(vartbl->info[n].gemname, gname);
            vartbl->info[n].scale=scl;
            vartbl->info[n].missing=msng;
            vartbl->info[n].hzremap = ihzrmp;
            vartbl->info[n].direction = idrct;

            n++;
        }

        cfl_clos(fp, &ier);

}
Beispiel #24
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);

}
Beispiel #25
0
void na_gtbl ( const char *cpyfil, char *name, char *proj, int *nxgd,
               int *nygd, float *garea, float *rnvblk, float *anlblk,
	       int *iret )
/************************************************************************
 * na_gtbl								*
 *									*
 * This subroutine finds grid INNAME (a numerical or character          *
 * identifier prefaced by '#') in a grid navigation table, then makes 	*
 * the navigation and analysis blocks.  The grid navigation is set up	*
 * in GEMPLT in order to check its validity.				*
 *									*
 * na_gtbl ( cpyfil, name, proj, nxgd, nygd, garea, rnvblk, anlblk,	*
 *           iret )							*
 *									*
 * Input parameters:							*
 *	*cpyfil		const char	Input for CPYFIL		*
 *									*
 * Output parameters:							*
 *	*name		char		Name of selected grid		*
 *	*proj		char		Grid projection			*
 *	*nxgd		int		Number of points in x dir	*
 *	*nygd		int		Number of points in y dir	*
 *	*garea		float		Grid corners			*
 *	*rnvblk		float		Grid navigation block		*
 *	*anlblk		float		Grid analysis block		*
 *	*iret		int		Return code			*
 *					 +1 = EXIT entered		*
 *					  0 = normal return		*
 *					 -4 = invalid navigation	*
 *					 -9 = grid not found in table	*
 **									*
 * Log:									*
 * S. Jacobs/EAI	 7/93		Copied from GDCTBL		*
 * D. Keiser/GSC	12/95		Changed FL_TOPN to FL_TBOP	*
 * R. Tian/SAIC		 7/06		Recoded from Fortran		*
 * S. Gilbert/NCEP      10/06   Added call to GR_VNAV                   *
 ************************************************************************/
{
    char gntrec[81], namgd[5], c2name[9], buffer[LLMXLN];
    float angl1, angl2, angl3, dbnds[4], deln;
    int angflg, found, valid;
    int iebnds[4], ingrdn, numgd, extnd, ier, ier1, iernum, navsz, i;
    FILE *lungrd;
/*----------------------------------------------------------------------*/
    *iret = 0;
    name[0] = '\0';

    /*
     * Get the grid number (INGRDN) out of NAME; a conversion error
     * sets IERNUM .ne. 0 and it is assumed that NAME is a type.
     */
    cst_lcuc ( (char *)cpyfil, c2name, &ier );
    strcpy ( name, &c2name[1] );
    cst_numb ( name, &ingrdn, &iernum );

    /*
     * Open the table of valid grid types.
     */
    lungrd = cfl_tbop ( "grdnav.tbl", "grid", &ier );
    if ( ier != 0 ) {
	er_wmsg ( "CFL", &ier, "grdnav.tbl", &ier1,
	          strlen("CFL"), strlen("grdnav.tbl") );
	*iret = -9;
	return;
    }

    /*
     * List the table contents for the user, if requested.
     */
    if ( strcmp ( name, "LIST" ) == 0 ) {
	while ( ! feof ( lungrd) ) {
	    cfl_trln ( lungrd, sizeof(gntrec), gntrec, &ier );
	    if ( ier != 0 ) break;

	    printf ( "%-79.79s\n", gntrec );
	}

	/*
	 * Rewind the table file.
	 */
	cfl_seek ( lungrd, 0, SEEK_SET, &ier );

	/*
	 * Prompt user for grid choice.
	 */
	printf ( "Enter grid id or number or type EXIT: " );
	scanf ( " %s", name );
	if ( name[0] == 'e' || name[0] == 'E' ) {
	    *iret = +1;
	    return;
	}
	cst_lcuc ( name, name, &ier );
	cst_numb ( name, &ingrdn, &iernum );
    }

    /*
     * Read through the list of valid grid types/numbers to get 
     * navigation/analysis information.
     */
    found = G_FALSE;
    while ( ! feof ( lungrd ) ) {
    	cfl_trln ( lungrd, sizeof(buffer), buffer, &ier );
	if ( ier != 0 ) break;

	sscanf ( buffer, "%s %d %s %f %f %f %f %f %f %f %d %d %f %d",
                 namgd, &numgd, proj, &angl1, &angl2, &angl3,
		 &garea[0], &garea[1], &garea[2], &garea[3],
		 nxgd, nygd, &deln, &extnd );
	if ( strcmp ( name, namgd ) == 0 || ingrdn == numgd ) {
	    found = G_TRUE;
	    break;
	}
    }
    cfl_clos ( lungrd, &ier );

    /*
     * Bail out if NAME wasn't found in the table.
     */
    if ( found == G_FALSE ) {
	*iret = -9;
	return;
    }

    /*
     * Fill navigation block.
     */
    angflg = G_TRUE;
    gr_vnav  ( proj, nxgd, nygd, &garea[0], &garea[1],
                &garea[2], &garea[3], &angl1, &angl2, &angl3,
		&angflg, &valid, &ier, strlen(proj) );

    if ( ier == 0 )
       grc_mnav  ( proj, nxgd, nygd, &garea[0], &garea[1],
                   &garea[2], &garea[3], &angl1, &angl2, &angl3,
                   &angflg, rnvblk, &ier );
    else {
       *iret = -2;
       return;
    }

    /*
     * Set up navigation in GEMPLT to check validity.
     */
    navsz = 13;
    grc_snav  ( &navsz, rnvblk, &ier );
    if ( ier != 0 ) {
	*iret = -4;
	return;
    }

    /*
     * Make an analysis block.
     */
    for ( i = 0; i < 4; i++ ) {
	iebnds[i] = extnd;
	dbnds [i] = RMISSD;
    }
    grc_mbn2 ( &deln, iebnds, dbnds, rnvblk, anlblk, &ier );

    return;
}
Beispiel #26
0
int main ( void )
/************************************************************************
 * GDGRIB2                                                              *
 *                                                                      *
 * This program encodes a selected GEMPAK grid into a GRIB2 message.    *
 *                                                                      *
 *  Command line:                                                       *
 *  gdgrib2                                                             *
 **                                                                     *
 * Log:                                                                 *
 * S. Gilbert/NCEP           5/2005   Orig                              *
 * S. Gilbert/NCEP           3/2006   Replaced dg_clal with dg_nend     *
 * T. Piper/SAIC        01/08   Added GD_INIT; removed from IN_BDTA     *
 * B. Yin/ERT           09/15   Added bulk processing from table        *
 ***********************************************************************/
{

    int    respond, ret, ier, mode=1, done, skip, j;

    int    g2len;                     /* Length of GRIB2 message  */
    unsigned char  *g2msg;            /* GRIB2 message            */
    char  cur_gbfile[LLMXLN]="";
    char  chdr[22];          /* WMO Header               */
    FILE  *gbfptr=0;

    GDG2_input    input;                  /* user input variables */
    GDG2_gemgrid  gemgrid;                /* GEMPAK grid and info */
/*---------------------------------------------------------------------*/
/*
 *  Initialize TAE. 
 */
    ip_init ( &respond, &ret );
    if ( ret == 0 ) {
	ip_idnt ( "GDGRIB2", &done, 7 );

/*
 *  Initialize GEMPLT.
 */
	gg_init ( &mode, &ret );
	if ( ret == 0 ) {

/*
 *  Initialize grid library common area grdcmn.cmn
 */
	    gd_init ( &ier );

/*
 *  Initialize the DG library
 */
	    dg_intl ( &ret );
	    done = 0;
	    skip = 1;
	}
	else {
	    done = 1;
	}
    }
    else {
	done = 1;
    }

/*
 *  Process next request, if user has one.
 */
    while ( done == 0 ) {

/*
 *  Wait for user input, if not first time through this loop
 */
        if ( skip == 0 ) ip_dynm( &done, &ret );
        skip = 0;
        if ( done != 0 ) break;          /*  Exit out of interactive loop  */

/*
 *  Get user input info
 */
        gdg2in( &input, &ret );

        if ( ret != 0 ) {
            er_wmsg("GDGRIB2",&ret," ",&ier,7,1);
            continue;
        }
        else if ((strlen(input.g2conv) != (size_t)0) && (ret == 0)) {
/*
 *  Skip program prompt and get input from conversion table 
 */
           skip = 1;
        }

        if ( strlen(input.g2file) == (size_t)0 ) {
            ret=-28;
            er_wmsg("GDGRIB2",&ret," ",&ier,7,1);
            continue;
        }

/*
 *  Get requested grid
 */
        gdgetgrid( &input, &gemgrid, &ret );
        if ( ret != 0 ) {
            er_wmsg("GDGRIB2",&ret," ",&ier,7,1);
            continue;
        }

/*
 *  Make GRIB2 field
 */
        gdmakeg2( &input, &gemgrid, &g2msg, &g2len, &ret );
        if ( ret != 0 ) {
            er_wmsg("GDGRIB2",&ret," ",&ier,7,1);
            continue;
        }

/*
 *  Open GRIB2 file, if not already open.
 */
        if ( strncmp(input.g2file, cur_gbfile, LLMXLN) != 0 ) {

/*
 *  If output GRIB file is different, must close previous one first
 */
            if ( strlen(cur_gbfile) != (size_t)0 ) {
                cfl_clos( gbfptr, &ret);
                gbfptr=0;
            }

/*
 *  Open GRIB file
 */
            gbfptr = cfl_aopn( input.g2file, &ret);
            if ( ret == 0 ) {
                strncpy( cur_gbfile, input.g2file, LLMXLN);
            }
            else {
                er_wmsg("CFL",&ret,input.g2file,&ier,7,strlen(input.g2file));
                ret = -24;
                er_wmsg("GDGRIB2",&ret," ",&ier,7,1);
                gbfptr = 0;
                continue;
            }
        }

/*
 *  Write out WMO Header, if requested
 */
        gdmakewmo( &input, &gemgrid, chdr, &ret );
        if ( strlen(chdr) == (size_t)21 ) {
           cfl_writ( gbfptr, strlen(chdr), (unsigned char*)chdr, &ret );
        }

/*
 *  Write out GRIB2 message.
 */
        cfl_writ( gbfptr, g2len, g2msg, &ret );
        if ( ret != 0 ) {
            er_wmsg("CFL",&ret,input.g2file,&ier,7,strlen(input.g2file));
            ret = -25;
            er_wmsg("GDGRIB2",&ret," ",&ier,7,1);
            continue;
        }

/*
 *  Free no longer needed allocated space
 */
        if ( gemgrid.grid != 0 ) free(gemgrid.grid);
        if ( g2msg != 0 ) free(g2msg);

    }

/*
 *  Clean up files
 */
    dg_nend( &ret );
    if ( gbfptr != 0 ) cfl_clos( gbfptr, &ret);

/*
 *  Exit the GEMPAK user interface
 */
    ip_exit( &ret );
 
    return(0);
}
Beispiel #27
0
void ctb_g2read ( int *iret ) 
/************************************************************************
 * ctb_g2read								*
 *									*
 * This routine will read a grib2 table into an array of structures.	*
 *									*
 * ctb_g2read ( iret )							*
 *									*
 * Input parameters:							*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 **									*
 * Log:									*
 * m.gamazaychikov/SAIC	 5/03						*
 * m.gamazaychikov/SAIC	 5/03	added parameter pdtnmbr to the table	*
 * M. Li/SAIC		 4/04	added hzremap, and direction		*
 ***********************************************************************/
{
FILE     *fp = NULL;
int      n, nr, blen, ier;
char     buffer[256]; 
int      disc, cat, parm, pdtn, scl, ihzrmp, idrct;
char     name[33], unts[21], gname[13];
float    msng;

/*---------------------------------------------------------------------*/
	*iret = G_NORMAL;

        if ( Gr2Readin == 1 )  return;

        /*
         *  Open the table. If not found return an error.
         */

        fp = cfl_tbop( G2VARS_TBL, "grid", &ier);
        if ( fp == NULL  ||  ier != 0 )  {
            if (fp)
                fclose(fp);
            *iret = -1;
            return;
        }

        cfl_tbnr(fp, &nr, &ier);
        if ( ier != 0 || nr == 0 ) {
            *iret = -2;
            cfl_clos(fp, &ier);
            return;
        }

        Gr2Tbl.info = (G2Vinfo *)malloc((size_t)nr*sizeof(G2Vinfo));

        n  = 0;
        while ( n < nr ) {

            cfl_trln( fp, 256, buffer, &ier );
            if ( ier != 0 ) break;

	    cst_lstr (  buffer, &blen, &ier );

	    if ( blen > NCOLN ) { 
                sscanf( buffer, "%12d %12d %12d %12d %32c %20c %s %12d %f %12d %12d",
                            &disc, &cat, &parm, &pdtn,
                            name, unts, gname,
                            &scl, &msng, &ihzrmp, &idrct );
	    }
	    else {
		sscanf( buffer, "%12d %12d %12d %12d %32c %20c %s %12d %20f",
                            &disc, &cat, &parm, &pdtn,
                            name, unts, gname,
                            &scl, &msng);
		ihzrmp = 0;
		idrct = 0;
	    }

	    name[32] = '\0';
	    unts[20] = '\0';

            Gr2Tbl.info[n].discpln=disc;
            Gr2Tbl.info[n].categry=cat;
            Gr2Tbl.info[n].paramtr=parm;
            Gr2Tbl.info[n].pdtnmbr=pdtn;
            strcpy(Gr2Tbl.info[n].name,    name);
            strcpy(Gr2Tbl.info[n].units,   unts);
            strcpy(Gr2Tbl.info[n].gemname, gname);

            Gr2Tbl.info[n].scale=scl;
            Gr2Tbl.info[n].missing=msng;
	    Gr2Tbl.info[n].hzremap = ihzrmp;
	    Gr2Tbl.info[n].direction = idrct;

            n++;
        }


        cfl_clos(fp, &ier);

        Gr2Tbl.nlines = n;

        Gr2Readin = 1;

}
Beispiel #28
0
void gg_rtrk ( char *filtyp, char *filnam, char *stime, char *etime,
		int *itmclr, int *iskip, int *iret )
/************************************************************************
 * gg_rtrk								*
 *									*
 * This routine reads the data from a Altimeter Ground Track Prediction *
 * file and plots it.							*
 *									*
 * gg_rtrk ( filtyp, filnam, stime, etime, itmclr, iskip, iret )        *
 *									*
 *									*
 * Input parameters:							*
 *	*filtyp		char		Data type			*
 *	*filnam		char		Data file name			*
 *	*stime		char		Start time of data 		*
 *	*etime		char		End time of data 		*
 * 	*itmclr		int		Time stamp color		*
 *	*iskip		int		Skip value			*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 **									*
 * Log:									*
 * G. McFadden/SAIC	12/08	Modeled after gg_qsrd			*
 * S. Jacobs/NCEP	 6/10	Removed underscore on function name	*
 ***********************************************************************/
{
	int	ier, incr, itarr[5], iyoff = 0,
		ixoff = -10, ntime, np2, pcount, gyear, ymd, hm;
	FILE    *fptr;
	char    buffer[256], textstr[8], final_ts[9], ymd_string[7], hm_string[5];
        char    gempak_dt[12];
        char    *cp, underscore[2];
	float   lat, lon, rotat = 0.0F;
	double	dlat, dlon, dalt;
        size_t  two = 2;
/*---------------------------------------------------------------------*/
/*
 *  Open the data file.
 */
	fptr = cfl_ropn ( filnam, NULL, &ier );
	if ( fptr == NULL  ||  ier != 0 )  {
	    *iret = -1;
	    return;
	}
	*iret = 0;

        underscore[0] = '_';
        underscore[1] = '\0';

/*
 * Set the skip factor.
 */
        if  ( *iskip <= 0 ) {
            incr = 1;
        }
        else {
            incr = *iskip + 1;
        }

        pcount = incr;
        while  ( ier == 0 )  {

/*
 *  Read this prediction's data.
 */
	    cfl_trln( fptr, 256, buffer, &ier );
	    if ( ier != 0 ) {
/*
 *  Bad read...close the file and exit.
 */
     		cfl_clos ( fptr, &ier );
		return;
	    }
/*
 *  Extract this prediction's data.
 */
	    sscanf( buffer, "%d %d %d %d %d %lf %lf %lf",
			&itarr[0], &itarr[1], &itarr[2], &itarr[3],
			&itarr[4], &dlat, &dlon, &dalt );

	    lat = (float)dlat;
            lon = (float)dlon;
/*
 *  Get the gempak date/time of this prediction
 */
            gyear = itarr[0] - 2000;
            ymd  = gyear * 10000 + itarr[1] * 100 + itarr[2];
            sprintf(ymd_string, "%6.6d", ymd );

            hm = itarr[3] * 100 + itarr[4];
            sprintf(hm_string, "%4.4d", hm );

            gempak_dt[0] = '\0';
            strcat(gempak_dt,ymd_string);
            strcat(gempak_dt,"/");
            strcat(gempak_dt,hm_string);

/*
 *  The longitude is stored as 0 -> 360.  PRNLON will correct the longitude to
 *  the range -180 -> 180.
 */
            np2 = 1;
            prnlon( &np2, &lon, &ier );

/*
 *  Plot the prediction if it is not skipped and if it is within the valid
 *  time range...plot "DD_HHMM" on the screen.
 */
            ntime = itarr[2] * 10000 + itarr[3] * 100 + itarr[4];
	    sprintf(textstr, "%6.6d", ntime);
            final_ts[0] = '\0';
            strncpy(final_ts,textstr,two);
            final_ts[2] = '\0';
            strcat(final_ts,underscore);
            cp = textstr + 2;
            strcat(final_ts,cp);
                 
	    gscolr ( itmclr, &ier);
            if ( pcount % incr == 0 && PathTimeCheck( gempak_dt, stime, etime) ) {
	       gtext  ( sys_M, &lat, &lon, final_ts, &rotat, &ixoff, &iyoff,
	                &ier, strlen(sys_M), strlen(final_ts) );
            }

            pcount++;

	}
/*
 *  Close the file.
 */
	cfl_clos ( fptr, &ier );
}
Beispiel #29
0
void ces_rtbl ( int *iret )
/************************************************************************
 * ces_rtbl								*
 *									*
 * This function reads the setting table and loads the settings		*
 * structure.								*
 *									*
 * ces_rtbl ( iret )							*
 *									*
 * Input parameters:							*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *					  2 = Bad read.  Ignore record. *
 *					  1 = Setting array siz exceeded*
 *					 -1 = No setting table		*
 **									*
 * Log:									*
 * D. Keiser/GSC	 7/97	Rewrote using union structure		*
 * E. Wehner/EAi	 8/97	Adopted from cpg_rstng			*
 * C. Lin/EAi		 9/97	Change default table name		*
 * G. Krueger/EAI	10/97	CST_xLST: Removed RSPTB; Add str limit	*
 * C. Lin/EAi		10/97	modify to remove cst_clst(), cleanup	*
 * C. Lin/EAi	 	10/97	modify WBOX_ELM				*
 * M. Linda/GSC		10/97	Corrected the prologue format		*
 * C. Lin/EAi	 	11/97	use CLASS_WATCHES for WBOX_ELM		*
 * C. Lin/EAi	 	11/97	add front strength and wind line width	*
 * S. Law/GSC		03/98	Changed scanned values for CLASS_WINDS  *
 * F. J. Yen/NCEP	 4/98	Renamed from ces_rstng.  Cleaned up.	*
 * F. J. Yen/NCEP	 4/98	Set hdsiz for BARB_ELM to 1.		*
 * W. Li/EAI		04/98	Add darr and hash in CLASS_WINDS	*
 * S. Jacobs/NCEP	 6/98	Changed front pip size to type float	*
 * W. Li/EAI		07/98	Added txt_attrib's text value setting	*
 * C. Lin/EAI		09/98	Add smoothing level for line/front	*
 * A. Hardy/GSC		10/98	Added CMBSY_ELM                         *
 * S. Jacobs/NCEP	12/98	Fixed typo				*
 * A. Hardy/GSC		12/98	Added CIRCLE_ELM                        *
 * E. Safford/GSC	02/99	set default for wndtyp to 114 (cleared) *
 * W. Li/EAI		03/99	added latitude/longitude for symbols	*
 * S. Law/GSC		03/99	added filled/closed = 0			*
 * W. Li/EAI		04/99	added MARK_ELM, removed lat/long symbol *
 * S. Law/GSC		05/99	Added CLASS_TRACKS			*
 * S. Law/GSC		07/99	Added CLASS_SIGMETS			*
 * S. Law/GSC		08/99	added remaining SIGMETs			*
 * S. Law/GSC		02/00	added CCF				*
 * H. Zeng/EAI		02/01	added group type info.			*
 * E. Safford/SAIC	02/02	added initialization for new_subtyp	*
 * J. Wu/SAIC		11/02	add class LIST				*
 * M. Li/SAIC		01/03	delete vgstruct.h			*
 * H. Zeng/XTRIA	01/03	added marker info. for Watch		*
 * H. Zeng/XTRIA	03/03	added layer_flag			*
 * D.W.Plummer/NCEP	06/03	added ASHCLD_ELM and VOLC_ELM		*
 * J. Wu/SAIC		09/03	add CLASS_MET -> JET_ELM		*
 * J. Wu/SAIC		01/04	add CLASS_MET -> GFA_ELM		*
 * B. Yin/SAIC		02/04	added CLASS_MET -> TCA_ELM		*
 * J. Wu/SAIC		05/04	add barb/hash color into JET_ELM	*
 * J. Wu/SAIC		05/04	add initialization for "ppid"		*
 * H. Zeng/SAIC		07/04	added check for ialign value		*
 * J. Wu/SAIC		09/04	add text type for jet barb text		*
 * J. Wu/SAIC		10/04   remove line width from GFA_ELM		*
 * T. Piper/SAIC	12/05	redone with new Setting_t structure	*
 * B. Yin/SAIC		12/05	added line width for GFA		*
 * S. Jacobs		03/06	add initialization of special text (bug)*
 * S. Danz/AWC		04/06	initialized jet->barb[]spt.text		*
 * B. Yin/SAIC		07/06	added line type and line elem for GFA	*
 * L. Hinson/AWC        12/06   added text color, size, font, hw, width *
 *                              alignment, and text Layout for GFA      *
 * L. Hinson/AWC        06/07   added arrow size for GFA                *
 * L. Hinson/AWC        07/09   Add color, fills, linetype, szarrow,    *
 *                              text size, font, hw, width, alignment,  *
 *                              and text Layout to CCF                  *
 * L. Hinson/AWC        01/12   Add CLASS_MET -> SGWX_ELM               *
 ***********************************************************************/
{
    char	tstr[256], vg_classstr[64], vg_typestr[64], tmpstr[256];
    int		one=1, smooth, loglev, quit, ier1, ier, jj, align_val;
    int		ii, tmpwid[3], tmpclr[3], ityp, ifnt, ithw, ialign, nn;
    char	grp[4], *ptr;
    float	tmpsiz, tmpsz[3];
    FILE	*fp;
/*---------------------------------------------------------------------*/

    *iret = G_NORMAL;

    /*
     * Open the setting table.  If not found, return an error.
     */

    if ( (fp = (FILE * )cfl_tbop(SETTING_TBL, "pgen", &ier)) == NULL) {
        *iret = -1;
	loglev = 2;
	strcpy(grp, "CES");
	er_lmsg (&loglev, grp, iret, SETTING_TBL, &ier1, strlen(grp),
		 strlen(SETTING_TBL));
        return;
    }

    /* 
     * For every line in the setting table list, read in the record,
     * parse out the fields, and compare to input type.
     */
    jj = num_set = 0;
    quit = G_FALSE;
    while ( ( !quit ) && ( jj < MAX_SET ) ) {

	cfl_trln ( fp, sizeof(tstr), tstr, &ier );

	if ( ier == 4 ) {
	    /*
	     * Here for end of file.
	     */
	    quit = G_TRUE;
	}

	else if ( ier != 0 ) {
	    /*
	     * Here for a bad read; record is ignored.
	     */
	    loglev = 2;
	    strcpy(grp, "CES");
	    ier = 2;
	    er_lmsg ( &loglev, grp, &ier, SETTING_TBL, &ier1,
		      strlen(grp), strlen(SETTING_TBL) );
	}

	else {
	    /*
	     * Here to process a good record.
	     */
	    sscanf(tstr, "%s %s", vg_classstr, vg_typestr);
	    num_set++;
	    G_REALLOC(set, Setting_t, num_set, "set");
	    set[jj].smooth = 0;
	    set[jj].filled = 0;
	    set[jj].closed = 0;

    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE FRONTS CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */

	    if ( strcmp(vg_classstr, "CLASS_FRONTS" ) == 0 ) {
		set[jj].vg_class = CLASS_FRONTS;
		G_MALLOC(set[jj].info.frt, FrontInfo, one, "set[jj].info.frt");

		sscanf(tstr, "%*s %*s %d %d %d %d %f %d %d %s",
			 &(set[jj].subtyp), &(set[jj].maj_col),
			 &(set[jj].min_col), &smooth, &tmpsiz,
			 &(set[jj].info.frt->fpipdr),
			 &(set[jj].info.frt->fwidth),
			   set[jj].grp_typ );
		
		set[jj].info.frt->fpipsz = (int)(tmpsiz * 100.0F);
		set[jj].info.frt->fcode = set[jj].subtyp;
		set[jj].info.frt->fpipst = 1;
	
		if ( smooth < 0 || smooth > 2 )
		    smooth = 0;
		set[jj].smooth = smooth;

		if ( strcmp(vg_typestr, "FRONT_ELM" ) == 0 ) {
		    set[jj].vg_type = FRONT_ELM;
		}
		else if ( strcmp(vg_typestr, "-99" ) == 0 ) {
		    set[jj].vg_type = DEFLTSET;
		}

	    }
    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE CIRCLE CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_CIRCLE") == 0 ) {
		set[jj].vg_class = CLASS_CIRCLE;
		G_MALLOC(set[jj].info.cir, LineInfo, one, "set[jj].info.cir");

		if (strcmp(vg_typestr, "CIRCLE_ELM") == 0) {
		   set[jj].vg_type = CIRCLE_ELM;

		   sscanf(tstr, "%*s %*s %d %d %d %d %d %d %d %s", 
			 &(set[jj].subtyp), 
			 &(set[jj].maj_col), &(set[jj].min_col),
			 &(set[jj].info.cir->lintyp), 
			 &(set[jj].info.cir->lthw),
			 &(set[jj].info.cir->width), 
			 &(set[jj].info.cir->lwhw),
			   set[jj].grp_typ );

		}

	    }
    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE LINES CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_LINES") == 0 ) {
		set[jj].vg_class = CLASS_LINES;

		if (strcmp(vg_typestr, "LINE_ELM") == 0) {
		    set[jj].vg_type = LINE_ELM;
		    G_MALLOC(set[jj].info.lin, LineInfo, one, "set[jj].info.lin");
		    sscanf(tstr, "%*s %*s %d %d %d %d %d %d %d %d %s",
			 &(set[jj].subtyp),
			 &(set[jj].maj_col), &(set[jj].min_col),
			 &smooth,
			 &(set[jj].info.lin->lintyp),
			 &(set[jj].info.lin->lthw),
			 &(set[jj].info.lin->width),
			 &(set[jj].info.lin->lwhw),
			   set[jj].grp_typ );

	        }
		else if (strcmp(vg_typestr, "SPLN_ELM") == 0) {
		    set[jj].vg_type = SPLN_ELM;
		    G_MALLOC(set[jj].info.spl, SpLineInfo, one, "set[jj].info.spl");
		    set[jj].info.spl->splstr = 1;

			sscanf(tstr, "%*s %*s %d %d %d %d %d %d %f %d %s",
			&(set[jj].subtyp), 
			&(set[jj].maj_col), &(set[jj].min_col),
			&smooth,
			&(set[jj].info.spl->spltyp), 
			&(set[jj].info.spl->spldir),
			&(set[jj].info.spl->splsiz), 
			&(set[jj].info.spl->splwid),
			set[jj].grp_typ );

		}

		if (smooth < 0 || smooth > 2)
			smooth = 0;
		set[jj].smooth = smooth;

	    }
    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE SYMBOLS CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_SYMBOLS") == 0 ) {
		set[jj].vg_class = CLASS_SYMBOLS;
		G_MALLOC(set[jj].info.sym, SymType, one, "set[jj].info.sym");

		if ( strcmp(vg_typestr, "WXSYM_ELM") == 0) {
		    set[jj].vg_type = WXSYM_ELM;
		}
		else if ( strcmp(vg_typestr, "CTSYM_ELM") == 0) {
		    set[jj].vg_type = CTSYM_ELM;
		}
		else if ( strcmp(vg_typestr, "ICSYM_ELM") == 0) {
		    set[jj].vg_type = ICSYM_ELM;
		}
		else if ( strcmp(vg_typestr, "PTSYM_ELM") == 0) {
		    set[jj].vg_type = PTSYM_ELM;
		}
		else if ( strcmp(vg_typestr, "PWSYM_ELM") == 0) {
		    set[jj].vg_type = PWSYM_ELM;
		}
		else if ( strcmp(vg_typestr, "SKSYM_ELM") == 0) {
		    set[jj].vg_type = SKSYM_ELM;
		}
		else if ( strcmp(vg_typestr, "SPSYM_ELM") == 0) {
		    set[jj].vg_type = SPSYM_ELM;
		}
		else if ( strcmp(vg_typestr, "TBSYM_ELM") == 0) {
		    set[jj].vg_type = TBSYM_ELM;
		}
		else if ( strcmp(vg_typestr, "CMBSY_ELM") == 0) {
		    set[jj].vg_type = CMBSY_ELM;
		}
		else if ( strcmp(vg_typestr, "MARK_ELM" ) == 0 ) {
		    set[jj].vg_type = MARK_ELM;
		}
		else if (strcmp(vg_typestr, "-99" ) == 0 ) {
		    set[jj].vg_type = DEFLTSET;
		}
		sscanf(tstr, "%*s %*s %d %d %d %d %f %s", 
			&(set[jj].subtyp),
			&(set[jj].maj_col),
			&(set[jj].min_col),
			&(set[jj].info.sym->info.width),
			&(set[jj].info.sym->info.size),
			 set[jj].grp_typ );

	    }
    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE WINDS CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_WINDS") == 0 ) {
		set[jj].vg_class = CLASS_WINDS;
		G_MALLOC(set[jj].info.wnd, WindInfo, one, "set[jj].info.wnd");

		if ( strcmp(vg_typestr, "ARROW_ELM") == 0 ) {
		    set[jj].vg_type = ARROW_ELM;
		    sscanf(tstr, "%*s %*s %d %d %d %d %f %f %s",
			&(set[jj].subtyp),
			&(set[jj].maj_col), &(set[jj].min_col),
			&(set[jj].info.wnd->width),
			&(set[jj].info.wnd->size),
			&(set[jj].info.wnd->hdsiz), set[jj].grp_typ );
		    set[jj].info.wnd->wndtyp = 114;
		}
		else if ( strcmp(vg_typestr, "BARB_ELM") == 0 ) {
		    set[jj].vg_type = BARB_ELM;
		    sscanf(tstr, "%*s %*s %d %d %d %d %f %s",
			 &(set[jj].subtyp), &(set[jj].maj_col),
			 &(set[jj].min_col), &(set[jj].info.wnd->width),
			 &(set[jj].info.wnd->size), set[jj].grp_typ );
		    set[jj].info.wnd->hdsiz = 1.0F;
		    set[jj].info.wnd->wndtyp = 114;

		}
		else if ( strcmp(vg_typestr, "DARR_ELM") == 0 ) {
		    set[jj].vg_type = DARR_ELM;
		    sscanf(tstr, "%*s %*s %d %d %d %d %f %f %s",
			&(set[jj].subtyp),
			&(set[jj].maj_col), &(set[jj].min_col),
			&(set[jj].info.wnd->width),
			&(set[jj].info.wnd->size),
			&(set[jj].info.wnd->hdsiz), set[jj].grp_typ );
		    set[jj].info.wnd->wndtyp = 114;
		}
		else if ( strcmp(vg_typestr, "HASH_ELM") == 0 ) {
		    set[jj].vg_type = HASH_ELM;
		    sscanf(tstr, "%*s %*s %d %d %d %d %f %s",
			&(set[jj].subtyp),
			&(set[jj].maj_col), &(set[jj].min_col),
			&(set[jj].info.wnd->width),
			&(set[jj].info.wnd->size),
			  set[jj].grp_typ );
		    set[jj].info.wnd->hdsiz = 1.0F;
		    set[jj].info.wnd->wndtyp = 1;
		}

	    }
    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE WBOX CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_WATCHES") == 0 ) {
		set[jj].vg_class = CLASS_WATCHES;
		G_MALLOC(set[jj].info.wbx, WboxAttr, one, "set[jj].info.wbx");

		sscanf (tstr, "%*s %*s %d %d %d %d %d %f %d %s",
			&(set[jj].subtyp),
			&(set[jj].maj_col), &(set[jj].min_col),
			&(set[jj].info.wbx->w_type),
			&(set[jj].info.wbx->w_mrktyp),
			&(set[jj].info.wbx->w_mrksiz),
			&(set[jj].info.wbx->w_mrkwid), set[jj].grp_typ );

		set[jj].info.wbx->w_number = -9999;

		if (strcmp(vg_typestr, "WBOX_ELM") == 0) { 
		    set[jj].vg_type = WBOX_ELM;
		}
		else if (strcmp(vg_typestr, "-99") == 0) {
		    set[jj].vg_type = DEFLTSET;
		}

	    }
    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE TEXT CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_TEXT") == 0 ) {
		set[jj].vg_class = CLASS_TEXT;

		if (strcmp(vg_typestr, "TEXT_ELM") == 0) {
		    set[jj].vg_type = TEXT_ELM;
		    G_MALLOC(set[jj].info.txt, TextType, one, "set[jj].info.txt");

		    sscanf (tstr, "%*s %*s %d %d %d %f %f %d %d %d %s", 
			&(set[jj].subtyp),
			&(set[jj].maj_col), &(set[jj].min_col),
			&(set[jj].info.txt->info.rotn),
			&(set[jj].info.txt->info.sztext),
			&(set[jj].info.txt->info.itxfn),
			&(set[jj].info.txt->info.iwidth), 
			&(set[jj].info.txt->info.ialign),
			  set[jj].grp_typ );

		    set[jj].info.txt->info.ithw = set[jj].subtyp;
		    set[jj].info.txt->text[0] = CHNULL;

		    /*
		     * Make sure ialign value is among (-1, 0, 1).
		     */
		    align_val = set[jj].info.txt->info.ialign;

		    if ( align_val != -1 && align_val != 0 &&
			align_val !=  1			) {

			set[jj].info.txt->info.ialign = 0;
		    }

		}
		else if (strcmp(vg_typestr, "TEXTC_ELM") == 0) {
		    set[jj].vg_type = TEXTC_ELM;
		    G_MALLOC(set[jj].info.txt, TextType, one, "set[jj].info.txt");

		    sscanf (tstr, "%*s %*s %d %d %d %f %f %d %d %d %s",
			&(set[jj].subtyp),
			&(set[jj].maj_col), &(set[jj].min_col),
			&(set[jj].info.txt->info.rotn),
			&(set[jj].info.txt->info.sztext),
			&(set[jj].info.txt->info.itxfn),
			&(set[jj].info.txt->info.iwidth),
			&(set[jj].info.txt->info.ialign),
			  set[jj].grp_typ );
		    set[jj].info.txt->info.ithw = set[jj].subtyp;
		    set[jj].info.txt->text[0] = CHNULL;

		    /*
		     * Make sure ialign value is among (-1, 0, 1).
		     */
		    align_val = set[jj].info.txt->info.ialign;

		    if ( align_val != -1 && align_val != 0 &&
			align_val !=  1			) {

			set[jj].info.txt->info.ialign = 0;
		    }

		}
		else if (strcmp(vg_typestr, "SPTX_ELM") == 0) { 
		    set[jj].vg_type = SPTX_ELM;
		    G_MALLOC(set[jj].info.spt, SpTxtAttr, one, "set[jj].info.spt");

		    sscanf (tstr, "%*s %*s %d %d %d %f %f %d %d %d %d %d %s",
			&(set[jj].subtyp),
			&(set[jj].maj_col), &(set[jj].min_col),
			&(set[jj].info.spt->text.info.rotn),
			&(set[jj].info.spt->text.info.sztext), 
			&(set[jj].info.spt->text.info.turbsym),
			&(set[jj].info.spt->text.info.itxfn), 
			&(set[jj].info.spt->text.info.ithw),
			&(set[jj].info.spt->text.info.iwidth), 
			&(set[jj].info.spt->text.info.ialign),
			  set[jj].grp_typ );
		    set[jj].info.spt->text.info.sptxtyp = set[jj].subtyp;
		    strcpy ( set[jj].info.spt->ppid, DEFLTPPID );
		    set[jj].info.spt->text.text[0] = CHNULL;
		    /*
		     * Make sure ialign value is among (-1, 0, 1).
		     */
		    align_val = set[jj].info.spt->text.info.ialign;

		    if ( align_val != -1 && align_val != 0 &&
			 align_val !=  1			) {

		         set[jj].info.spt->text.info.ialign = 0;
		    }

		}

	    }
    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE TRACKS CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_TRACKS") == 0 ) {
		set[jj].vg_class = CLASS_TRACKS;
		G_MALLOC(set[jj].info.trk, TrackInfo, one, "set[jj].info.trk");

		if ( strcmp(vg_typestr, "TRKSTORM_ELM" ) == 0 ) {
		    set[jj].vg_type = TRKSTORM_ELM;
		}
		else if ( strcmp(vg_typestr, "-99" ) == 0 ) {
		    set[jj].vg_type = DEFLTSET;
		}

		sscanf(tstr, "%*s %*s %d %d %d %d %d %d %d %d %d %s",
		    &(set[jj].subtyp),
		    &(set[jj].maj_col), &(set[jj].min_col),
		    &(set[jj].info.trk->ltype1), &(set[jj].info.trk->ltype2),
		    &(set[jj].info.trk->mtype1), &(set[jj].info.trk->mtype2),
		    &(set[jj].info.trk->width), &(set[jj].info.trk->incr),
		    set[jj].grp_typ );
	    }
    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE SIGMETS CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_SIGMETS") == 0 ) {
		set[jj].vg_class = CLASS_SIGMETS;

		if ( strcmp(vg_typestr, "SIGAIRM_ELM" ) == 0 ) {
		    set[jj].vg_type = SIGAIRM_ELM;
		}
		else if ( strcmp(vg_typestr, "SIGCONV_ELM" ) == 0 ) {
		    set[jj].vg_type = SIGCONV_ELM;
		}
		else if ( strcmp(vg_typestr, "SIGINTL_ELM" ) == 0 ) {
		    set[jj].vg_type = SIGINTL_ELM;
		}
		else if ( strcmp(vg_typestr, "SIGNCON_ELM" ) == 0 ) {
		    set[jj].vg_type = SIGNCON_ELM;
		}
		else if ( strcmp(vg_typestr, "SIGOUTL_ELM" ) == 0 ) {
		    set[jj].vg_type = SIGOUTL_ELM;
		}
		else if ( strcmp(vg_typestr, "SIGCCF_ELM" ) == 0 ) {
		    set[jj].vg_type = SIGCCF_ELM;
		}
		else if ( strcmp(vg_typestr, "ASHCLD_ELM" ) == 0 ) {
		    set[jj].vg_type = ASHCLD_ELM;
		}
		else if ( strcmp(vg_typestr, "VOLC_ELM" ) == 0 ) {
		    set[jj].vg_type = VOLC_ELM;
		}
		else if ( strcmp(vg_typestr, "-99" ) == 0 ) {
		    set[jj].vg_type = DEFLTSET;
		}

		if (set[jj].vg_type == SIGCCF_ELM) {
                    G_MALLOC(set[jj].info.ccf, CcfAttr, one, "set[jj].info.ccf");		    
                    sscanf(tstr, "%*s %*s %d %d %d %d %d %d %d %d %f %f %d %d %d %d %s %s",
                      &(set[jj].subtyp), &(set[jj].smooth),
                      &(set[jj].maj_col), &(set[jj].min_col),
                      &(set[jj].info.ccf->fillhi),
                      &(set[jj].info.ccf->fillmed),
                      &(set[jj].info.ccf->filllow),
                      &(set[jj].info.ccf->linetype),
                      &(set[jj].info.ccf->szarrow),
                      &(set[jj].info.ccf->info.sztext),
                      &(set[jj].info.ccf->info.itxfn),
                      &(set[jj].info.ccf->info.ithw),
                      &(set[jj].info.ccf->info.iwidth),
                      &(set[jj].info.ccf->info.ialign),
                      set[jj].info.ccf->textLayout,
                      set[jj].grp_typ );
                    /* printf("subtyp = %d, smooth=%d, maj_col=%d, min_col=%d, fillhi=%d, fillmed=%d, filllow=%d\n", 
                      set[jj].subtyp, set[jj].smooth, set[jj].maj_col, set[jj].min_col, 
                      set[jj].info.ccf->fillhi, set[jj].info.ccf->fillmed, set[jj].info.ccf->filllow);
                    printf("linetype=%d, szarrow=%f, sztext=%f, itxfn=%d, ithw=%d, iwidth=%d ialign=%d\n",
                      set[jj].info.ccf->linetype, set[jj].info.ccf->szarrow, 
                      set[jj].info.ccf->info.sztext,
                      set[jj].info.ccf->info.itxfn, set[jj].info.ccf->info.ithw, set[jj].info.ccf->info.iwidth,
                      set[jj].info.ccf->info.ialign);
                    printf("tlayout=%s grptyp=%s\n",set[jj].info.ccf->textLayout, set[jj].grp_typ); */
                      
		}
		else if (set[jj].vg_type == ASHCLD_ELM) {
		    G_MALLOC(set[jj].info.ash, SigAttr, one, "set[jj].info.ash");
		    sscanf(tstr, "%*s %*s %d %d %d %d %s", 
			   &(set[jj].subtyp), &(set[jj].maj_col),
			   &(set[jj].min_col), &(set[jj].smooth),
			   set[jj].grp_typ );
		}
		else if (set[jj].vg_type == VOLC_ELM) {
		    G_MALLOC(set[jj].info.vol, VolAttr, one, "set[jj].info.vol");
		    sscanf(tstr, "%*s %*s %d %d %d %d %f %s",
			   &(set[jj].subtyp), &(set[jj].maj_col),
			   &(set[jj].min_col),&(set[jj].info.vol->width),
			   &(set[jj].info.vol->size), set[jj].grp_typ );
		}
		else {
		    G_MALLOC(set[jj].info.sig, SigAttr, one, "set[jj].info.sig");
		    sscanf(tstr, "%*s %*s %d %d %d %d %d %s",
			   &(set[jj].subtyp),
			   &(set[jj].maj_col), &(set[jj].min_col),
			   &(set[jj].info.sig->lintyp), 
			   &(set[jj].info.sig->linwid),
			     set[jj].grp_typ );
		}
	    }

    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE LIST CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_LIST") == 0 ) {
		set[jj].vg_class = CLASS_LIST;
		G_MALLOC(set[jj].info.lst, ListInfo, one, "set[jj].info.lst");

		if ( strcmp(vg_typestr, "LIST_ELM") == 0 ) {
		    set[jj].vg_type = LIST_ELM;
		    sscanf ( tstr, "%*s %*s %d %d %d %d %f %d %s",
			&(set[jj].subtyp),
			&(set[jj].maj_col),
			&(set[jj].min_col),
			&(set[jj].info.lst->mrktyp),
			&(set[jj].info.lst->mrksiz),
			&(set[jj].info.lst->mrkwid),
			  set[jj].grp_typ );

		     set[jj].info.lst->subtyp = set[jj].subtyp;
		}

	    }

    /*
     * +++++++++++++++++++++++++++++++++++++++++++
     *    HANDLE MET CLASS 
     * +++++++++++++++++++++++++++++++++++++++++++
     */
	    else if ( strcmp(vg_classstr, "CLASS_MET") == 0 ) {
		set[jj].vg_class = CLASS_MET;

		if ( strcmp(vg_typestr, "JET_ELM") == 0 ) {
		    set[jj].vg_type = JET_ELM;
 		    G_MALLOC(set[jj].info.jet, JetInfo, one, "set[jj].info.jet");
		    /*
		       *  Check the number of items in setting.tbl.
		       *  ( 22 - version 5.7.4 & later; 21 for earlier versions.
		       */
		    strcpy ( tmpstr, tstr );
		    cst_nocc ( tmpstr, '!', 1, 0, &nn, &ier );

		    if ( ier == 0 ) {
		        tmpstr[nn] = '\0';
		        cst_lstr ( tmpstr, &nn, &ier );
		        tmpstr[nn] = '\0';
		    }

		    nn = 0;
		    ptr = strtok ( tmpstr, " " );
		    while ( (ptr != (char *)NULL) ) {
			ptr = strtok ( NULL, " " );
			nn++;
		    }

		    if ( nn < 22 ) {  /* Version 5.7.3 & before */
			sscanf ( tstr, "%*s %*s %d %d %d %d %d %f %d %d %f %d %f %d %d %d %d %d %f %d %s",
			    &(set[jj].subtyp),
			    &(set[jj].maj_col), &(set[jj].min_col), &smooth,
			    &(set[jj].info.jet->line.spltyp),
			    &(set[jj].info.jet->line.splsiz),
			    &(set[jj].info.jet->line.splwid),
			    &tmpclr[0], &tmpsz[0], &tmpwid[0],			/* Barb */
			    &tmpsz[1], &ifnt, &ithw, &tmpwid[1], &ialign,	/* Text */
			    &tmpclr[1], &tmpsz[2], &tmpwid[2],			/* Hash */
			    set[jj].grp_typ );

			    ityp = 0;
		    }
		    else {  /* Version 5.7.4 and later */
		        sscanf ( tstr, "%*s %*s %d %d %d %d %d %f %d %d %f %d %d %f %d %d %d %d %d %f %d %s",
			    &(set[jj].subtyp),
			    &(set[jj].maj_col), &(set[jj].min_col), &smooth,
			    &(set[jj].info.jet->line.spltyp),
			    &(set[jj].info.jet->line.splsiz),
			    &(set[jj].info.jet->line.splwid),
			    &tmpclr[0], &tmpsz[0], &tmpwid[0],				/* Barb */
			    &ityp, &tmpsz[1], &ifnt, &ithw, &tmpwid[1], &ialign,	/* Text */
			    &tmpclr[1], &tmpsz[2], &tmpwid[2],				/* Hash */
			    set[jj].grp_typ );
		    }
		    
		    if (smooth < 0 || smooth > 2) smooth = 0;
		    set[jj].smooth = smooth;
		    set[jj].info.jet->splcol = set[jj].maj_col;
		    set[jj].info.jet->line.splstr = 1;
		    set[jj].info.jet->line.spldir = 0;


		    for ( ii = 0; ii < MAX_JETPTS; ii++ ) {
		        set[jj].info.jet->barb[ii].wndcol = tmpclr[0];
		        set[jj].info.jet->barb[ii].wnd.info.size = tmpsz[0];
		        set[jj].info.jet->barb[ii].wnd.info.width = tmpwid[0];
		        set[jj].info.jet->barb[ii].wnd.info.wndtyp = 114;
		        set[jj].info.jet->barb[ii].wnd.info.hdsiz = 1.0F;
		        set[jj].info.jet->barb[ii].sptcol = tmpclr[0];
			set[jj].info.jet->barb[ii].spt.info.sztext = tmpsz[1];
		        set[jj].info.jet->barb[ii].spt.info.itxfn = ifnt;
		        set[jj].info.jet->barb[ii].spt.info.ithw = ithw;
		        set[jj].info.jet->barb[ii].spt.info.iwidth = tmpwid[1];
		        set[jj].info.jet->barb[ii].spt.info.ialign = ialign;
		        set[jj].info.jet->barb[ii].spt.info.rotn = 0.0F;
		        set[jj].info.jet->barb[ii].spt.info.sptxtyp = ityp;
		        set[jj].info.jet->barb[ii].spt.info.turbsym = 0;
		        set[jj].info.jet->barb[ii].spt.info.txtcol = tmpclr[0];
		        set[jj].info.jet->barb[ii].spt.info.filcol = tmpclr[0];
		        set[jj].info.jet->barb[ii].spt.info.lincol = tmpclr[0];
			set[jj].info.jet->barb[ii].spt.text[0] = CHNULL;
		        set[jj].info.jet->hash[ii].wndcol = tmpclr[1];
		        set[jj].info.jet->hash[ii].wnd.info.size = tmpsz[2];
		        set[jj].info.jet->hash[ii].wnd.info.width = tmpwid[2];
		        set[jj].info.jet->hash[ii].wnd.info.wndtyp = 1;	
		        set[jj].info.jet->hash[ii].wnd.info.hdsiz = 1.0F;			
		    }

		}

		else if ( strcmp(vg_typestr, "GFA_ELM") == 0 ) {
		    set[jj].vg_type = GFA_ELM;
		    G_MALLOC(set[jj].info.gfa, GfaAttr, one, "set[jj].info.gfa");
          
		    sscanf(tstr, "%*s %*s %d %d %d %d %d %d %f %d %f %d %d %d %d %s %s", 
			   &(set[jj].subtyp), &(set[jj].maj_col), 
			   &(set[jj].min_col), &(set[jj].info.gfa->linelm), 
			   &(set[jj].info.gfa->lintyp),&(set[jj].info.gfa->linwid),
                           &(set[jj].info.gfa->szarrow),
                           &(set[jj].info.gfa->info.txtcol),
                           &(set[jj].info.gfa->info.sztext),
                           &(set[jj].info.gfa->info.itxfn),
                           &(set[jj].info.gfa->info.ithw),
                           &(set[jj].info.gfa->info.iwidth),
                           &(set[jj].info.gfa->info.ialign),
                           set[jj].info.gfa->textLayout,
			   set[jj].grp_typ );
		}
                else if ( strcmp(vg_typestr, "SGWX_ELM") == 0 ) {
                  set[jj].vg_type = SGWX_ELM;
                  G_MALLOC(set[jj].info.sgwx, SgwxAttr, one, "set[jj].info.sgwx");
                  sscanf(tstr, "%*s %*s %d %d %d %d %d %d %d %f %f %d %d %d %d %s",
                    &(set[jj].subtyp), &(set[jj].smooth),
                    &(set[jj].maj_col), &(set[jj].min_col),
                    &(set[jj].info.sgwx->lineelm),
                    &(set[jj].info.sgwx->linetype),
                    &(set[jj].info.sgwx->linewidth),
                    &(set[jj].info.sgwx->szarrow),
                    &(set[jj].info.sgwx->info.sztext),
                    &(set[jj].info.sgwx->info.itxfn),
                    &(set[jj].info.sgwx->info.ithw),
                    &(set[jj].info.sgwx->info.iwidth),
                    &(set[jj].info.sgwx->info.ialign),
                    set[jj].grp_typ );
                }
		else if ( strcmp(vg_typestr, "TCA_ELM") == 0 ) {
		    set[jj].vg_type = TCA_ELM;
		    G_MALLOC(set[jj].info.tca, TcaInfo, one, "set[jj].info.tca");

		    sscanf(tstr, "%*s %*s %d %d %d %d %s",
                           &set[jj].subtyp, &set[jj].maj_col, &set[jj].min_col,
                           &set[jj].info.tca->wwNum, set[jj].grp_typ );
	}

	    }

	    /*
	     * ++++++++++++++++++++++++++++++++++++++++++++++++++++++
	     *    DIDN'T RECOGNIZE THE CLASS; BAD READ, IGNORE RECORD 
	     * ++++++++++++++++++++++++++++++++++++++++++++++++++++++
	     */
	    else {
		*iret = 2;
	        loglev = 2;
		strcpy(grp, "CES");
		er_lmsg (&loglev, grp, iret, SETTING_TBL, &ier1, strlen(grp),
		         strlen(SETTING_TBL));
	    }

        /*
         * Set layer_flag according to set[jj].grp_typ
         */
            cst_lcuc(set[jj].grp_typ, set[jj].grp_typ, &ier1);
	    if ( strstr ( set[jj].grp_typ, "/LAYER" ) != NULL ) {
                 set[jj].cds_or_ces.layer_flag = TRUE;
	    }
	    else {
		set[jj].cds_or_ces.layer_flag = FALSE;
	    }

	    /*
	     * Increment jj
	     */
	    jj++;

	}

    }

    if ( !quit ) {
	/*
	 * Setting array (set) size exceeded.  MAX_SET should
	 * be increased.
	 */
	*iret = 1;
	loglev = 2;
	strcpy(grp, "CES");
	er_lmsg (&loglev, grp, iret, SETTING_TBL, &ier1, strlen(grp),
		 strlen(SETTING_TBL));
    }

    /* close the settings file */
    cfl_clos(fp, &ier);
}
Beispiel #30
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);
}