Exemple #1
0
FILE *cfl_tbop ( char *table, char *type, int *iret )
/************************************************************************
 * cfl_tbop								*
 *									*
 * This function opens a GEMPAK table file for reading.			*
 *									*
 * The table is split into the path and filename, and the file is	*
 * located by searching in the following order:				*
 *									*
 *	1. filename (local)						*
 *	2. path/filename (table as given)				*
 *	3. $NCDESK/type/filename					*
 *	4. $NCSITE/type/filename					*
 *	5. $GEMTBL/type/filename					*
 *									*
 * FILE *cfl_tbop ( table, type, iret )					*
 *									*
 * Input parameters:							*
 *	*table		char		Table file name			*
 *	*type		char		File name type			*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *	*cfl_tbop	FILE		File pointer			*
 **									*
 * G. Krueger/EAI  3/96							*
 * G. Krueger/EAI  8/96	   CFL_TOPN->TBOP; Match with FL library	*
 * C. Lin/EAI	   8/97	   fix bug in while loop (cpos>=0)->(cpos>0)	*
 * S. Law/GSC		05/00	changed to use file size defines	*
 * A. Hardy/GSC		12/00   Added search paths NCDESK and NCSITE	*
 * S. Jacobs/NCEP        5/01   Changed to call CFL_TINQ                *
 ***********************************************************************/
{
    FILE	*fptr;
    int		ier;
    long	lfsize;
    char	actualpath[LLPATH];

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

    *iret = 0;

    cfl_tinq ( table, type, &lfsize, actualpath, &ier );

    fptr = cfl_ropn (actualpath, NULL, iret);
    return fptr;
}
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++;
	    }
	}
}
Exemple #3
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 );
}
Exemple #4
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;
}
Exemple #5
0
int main ( int argc, char **argv )
/************************************************************************
 * clipvgf								*
 *                                                                      *
 * This program clips elements in a VGF file based on a bounds 		*
 * specification.  By default, a simple clipping algorithm is used 	*
 * where element points either inside or outside the polygon are kept 	*
 * or thrown away based on an input flag.  Alternatively, an exact	*
 * algorithm may be requested which clips precisely at the borders.	*
 *                                                                      *
 * The bound definition must be in the format:				*
 * bound_name|<area_tag_name>area_tag_value				*
 * and must be enclosed w/ quotes so the shell will ignore directives.	*
 *									*
 * Examples:								*
 * clipvgf input.vgf "STATE_BNDS|<STATE>WY" keep output.vgf rough	*
 * clipvgf input.vgf "STATE_BNDS|<STATE>WY" keep output.vgf exact	*
 * Where "rough" uses the simple clipping algorithm and "exact" yields	*
 * precise clipping at the bounds borders.				*
 *                                                                      *
 * The following element classes are not processed:			*
 * CLASS_WATCHES, CLASS_TRACKS, CLASS_SIGMETS				*
 *                                                                      *
 * main(argc, argv)                                                     *
 *                                                                      *
 * Input parameters:                                                    *
 *  argc   int      number of parameters of command line                *
 *  argv   char**   parameter array of command line                     *
 *                                                                      *
 * Output parameters:                                                   *
 * Return parameters:                                                   *
 *                      NONE                                            *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * D.W.Plummer/NCEP	 2/02						*
 * D.W.Plummer/NCEP	 5/02	Added exact clipping and label moving	*
 * D.W.Plummer/NCEP	 8/02	Account for text grouped with symbol	*
 * D.W.Plummer/NCEP	 8/02	Create output VGF, even if it is empty	*
 * H. Zeng/XTRIA	02/03	converted CLASS_CIRCLE to CLASS LINES	*
 * D.W.Plummer/NCEP	 8/03	Bug fix - add pt to closed lines	*
 * R. Tian/SAIC		11/04	Added clip jet element			*
 * S. Danz/AWC		07/06	Update to new cvg_writef() parameter    *
 * T. Piper/SAIC	03/07	Added ninout-- for closed line case	*
 * L. Hinson/AWC        07/07   Added clip code for GFA elements        *
 * L. Hinson/AWC        07/07   Add recalcGFAtLblArwLoc function *
                                for GFA elements                        *
 * X.Guo/CWS		10/10   Bug fix - Low level graphic don't make  *
 *                              it all the way north in central US      *
 * L. Hinson/AWC        09/13   Fixed improperly clipped JET_ELM Barbs  *
 *                              and hashes                              *
 ***********************************************************************/
{
    int    	ii, jj, ip, ibeg, iend, loc, ne, found, found_txt, joffset, kept, ier;
    int    	wrtflg, pagflg;
    int	minpts, maxpts, npts, numpts, npoly;
    char	vg_class, vg_type;
    char	bnd[128], keep[32], bnd_name[64], bnd_tag[64];
    char    infile[128], ifname[128], outfile[128];
    char	*cptr;
    long	ifilesize;
    int	more, curpos;
    float	flat, flon, filt, px[LLMXPT], py[LLMXPT];
    float	plat[LLMXPT], plon[LLMXPT], *ptrlat, *ptrlon;
    float	tlat[LLMXPT], tlon[LLMXPT];
    float	fltmin, fltmax, flnmin, flnmax;
    int	inout[LLMXPT], tinout[LLMXPT];
    char	device[8], dfilnam[128], pro[32];
    float	xsize, ysize, lllat, lllon, urlat, urlon;
    float	prjang1, prjang2, prjang3;
    int	mode, istat, iunit, itype;
    char	errgrp[8];
    int	ninout;
    float	xinout[LLMXPT], yinout[LLMXPT];
    char	precision[8];
    int	tltpts, nbarb, nhash;
    int     tmaxpts, tnpts, tnclip;
    char    hazList[ STD_STRLEN ];

    VG_DBStruct     el, el_t, el_q, el_lin;

    FILE    *ifptr;

    int	ninxarr, inxarr[100];
    /*---------------------------------------------------------------------*/

    /*
     *  First check if number of input arguments is correct.
     */
    if ( argc < 5 )  {
        pagflg = G_FALSE;
        strcpy ( errgrp, "CLIPVGF" );
        ip_help ( errgrp, &pagflg, &ier,
                  strlen(errgrp) );
        exit (0);
    }

    /*
     *  First input on command line is input vgf file name.
     */
    strcpy ( infile, argv[1] );
    wrtflg = 0;
    cvg_open ( infile, wrtflg, &(ifptr), &ier );
    if ( ier != 0 )  {
        printf("Error opening VGF file %s\n", infile );
        exit (0);
    }
    cfl_inqr ( infile, NULL, &ifilesize, ifname, &ier );

    /*
     *  Second input on command line is bounds name.
     */
    clo_init ( &ier );
    strcpy ( bnd, argv[2] );
    cptr = cst_split( bnd, '|', sizeof(bnd_name), bnd_name, &ier );
    clo_bstype ( bnd_name, &ier );
    if ( ier != 0 ) {
        printf("Error finding bounds type %s\n", bnd_name );
        exit (0);
    }
    if ( cptr != (char *)NULL )  {
        strcpy ( bnd_tag, cptr );
        clo_bstag ( bnd_tag, &ier );
    }
    fltmin =  -90.0F;
    fltmax =  90.0F;
    flnmin = -180.0F;
    flnmax = 180.0F;
    clo_bsarea ( &fltmin, &flnmin, &fltmax, &flnmax, &ier );
    minpts = 3;
    maxpts = sizeof(px)/sizeof(float);
    filt = 0.0F;
    clo_bgnext ( &minpts, &maxpts, &filt, &npoly, px, py, &ier );
    if ( ier < 0 )  {
        printf("Error retrieving bound area %s|%s\n", bnd_name, bnd_tag );
        exit (0);
    }

    /*
     *  Third input on command line is keep flag.
     */
    strcpy ( keep, argv[3] );

    /*
     *  Fourth input on command line is output vgf file name; create it.
     */
    strcpy ( outfile, argv[4] );
    cvg_crvgf ( outfile, &ier );

    /*
     *  Fifth input on command line is clip precision = "rough" or "exact"
     */
    if ( argv[5] != (char *)NULL )
        strcpy ( precision, argv[5] );
    else
        strcpy ( precision, "ROUGH" );
    cst_lcuc ( precision, precision, &ier );

    /*
     *  All input checks out OK; set up GAREA and PROJ for inpoly.
     */
    mode = 1;
    ginitp ( &mode, &istat, &ier );

    strcpy ( device, "GN" );

    iunit = 1;
    strcpy ( dfilnam, "CLIPVGF" );
    itype = 1;
    xsize = 500.0F;
    ysize = 500.0F;

    gsdeva ( device, &iunit, dfilnam, &itype, &xsize, &ysize, &ier,
             strlen(device), strlen(dfilnam));

    /*
     *  Something more sophisticated may be needed here in the future
     *  to set up a proper proj and garea based on the clip area.
     *  For instance, the following definitions probably won't work
     *  on a clipping bound equivalent to Antartica.
     */
    lllat = 0.0F;
    lllon = -135.0F;
    urlat = 0.0F;
    urlon = 45.0F;
    strcpy ( pro, "str" );
    prjang1 = 90.0F;
    prjang2 = -105.0F;
    prjang3 = 0.0F;
    gsmprj ( pro, &prjang1, &prjang2, &prjang3,
             &lllat, &lllon, &urlat, &urlon, &ier, strlen(pro));

    /*
     *  Loop through all the elements to set the range records.
     */
    crg_init ( &ier );
    ne = 0;
    more = G_TRUE;
    curpos = 0;
    ifptr = (FILE *) cfl_ropn(ifname, "", &ier);
    while ( ne < MAX_EDITABLE_ELEMS && more == G_TRUE )  {
        cvg_rdrecnoc ( ifname, ifptr, curpos, &el, &ier );
        if ( ier < 0 )  {
            more = G_FALSE;
        }
        else  {
            crg_set ( &el, curpos, 1, &ier );
            curpos += el.hdr.recsz;
            ne++;
        }
    }
    cfl_clos ( ifptr, &ier );

    /*
     *  Loop through all the elements.
     */
    ne = 0;
    more = G_TRUE;
    curpos = 0;
    ifptr = (FILE *) cfl_ropn(ifname, "", &ier);
    while ( ne < MAX_EDITABLE_ELEMS && more == G_TRUE )  {

        cvg_rdrecnoc( ifname, ifptr, curpos, &el, &ier );

        if ( ier < 0 )  {
            more = G_FALSE;
        }
        else if ( el.hdr.recsz > 0 )  {

            crg_gginx( el.hdr.grptyp, el.hdr.grpnum,
                       sizeof(inxarr)/sizeof(inxarr[0]),
                       inxarr, &ninxarr, &ier );

            /*
             *  Increment file pointer now because element hdrsz may change.
             */
            curpos += el.hdr.recsz;

            vg_class = el.hdr.vg_class;
            vg_type  = el.hdr.vg_type;

            switch ( (int)vg_class )  {

            case	CLASS_SYMBOLS:
            case	CLASS_TEXT:
            case	CLASS_WINDS:
            case	CLASS_COMSYM:
            case	CLASS_MARKER:

                switch ( (int)vg_type )  {

                case	TEXT_ELM:
                case	TEXTC_ELM:
                    flat = el.elem.txt.info.lat;
                    flon = el.elem.txt.info.lon;
                    break;
                case	SPTX_ELM:
                    flat = el.elem.spt.info.lat;
                    flon = el.elem.spt.info.lon;
                    break;
                case	BARB_ELM:
                case	ARROW_ELM:
                case	DARR_ELM:
                case	HASH_ELM:
                    flat = el.elem.wnd.data.latlon[0];
                    flon = el.elem.wnd.data.latlon[1];
                    break;
                case	WXSYM_ELM:
                case	CTSYM_ELM:
                case	ICSYM_ELM:
                case	PTSYM_ELM:
                case	PWSYM_ELM:
                case	SKSYM_ELM:
                case	SPSYM_ELM:
                case	TBSYM_ELM:
                case	MARK_ELM:
                case	CMBSY_ELM:
                    flat = el.elem.sym.data.latlon[0];
                    flon = el.elem.sym.data.latlon[1];
                    break;
                }

                npts = 1;
                cgr_inpoly ( "M", &npts, &flat, &flon, "M", &npoly, px, py,
                             inout, &ier );

                if ( ( inout[0] == 1 && strcmp(keep,"keep") == 0 )  ||
                        ( inout[0] == 0 && strcmp(keep,"keep") != 0 ) )  {

                    /*
                     *  Check if element is TEXT grouped with a SYMBOL.  If this text was going
                     *  to be kept but it's symbol was going to be throw away, throw it away also.
                     */
                    if ( (int)vg_class == CLASS_TEXT &&
                            (int)el.hdr.grptyp != 0 && ninxarr > 1 )  {

                        found = G_FALSE;
                        ii = 0;
                        while ( ii < ninxarr && found == G_FALSE )  {
                            crg_goffset ( inxarr[ii], &joffset, &ier );
                            cvg_rdrecnoc( ifname, ifptr, joffset, &el_q, &ier );
                            if ( el_q.hdr.vg_class == CLASS_SYMBOLS )  {

                                found = G_TRUE;
                                flat = el_q.elem.sym.data.latlon[0];
                                flon = el_q.elem.sym.data.latlon[1];
                                npts = 1;
                                cgr_inpoly ( "M", &npts, &flat, &flon, "M",
                                             &npoly, px, py, inout, &ier );
                                if ((inout[0] == 1 && strcmp(keep,"keep") == 0) ||
                                        (inout[0] == 0 && strcmp(keep,"keep") != 0)) {
                                    cvg_writef( &el, -1, el.hdr.recsz, outfile,
                                                FALSE, &loc, &ier );
                                    kept = G_TRUE;
                                }
                                else  {
                                    kept = G_FALSE;
                                }
                            }

                            ii++;

                        }
                        if ( found == G_FALSE )  {
                            cvg_writef( &el, -1, el.hdr.recsz, outfile,
                                        FALSE, &loc, &ier );
                            kept = G_TRUE;
                        }
                    }
                    else  {
                        /*
                         *  non-TEXT -- keep it.
                         */
                        cvg_writef( &el, -1, el.hdr.recsz, outfile, FALSE, &loc, &ier );
                        kept = G_TRUE;
                    }

                }
                else  {
                    /*
                     *  Element is not to be kept.
                     */
                    kept = G_FALSE;
                }

                /*
                 *  Check if element was kept and is a SYMBOL element grouped with TEXT;
                 *  make sure any text elements are saved off they were going to be thrown away.
                 */
                if ( kept == G_TRUE && (int)vg_class == CLASS_SYMBOLS &&
                        (int)el.hdr.grptyp != 0 && ninxarr > 1 )  {

                    ii = 0;
                    while ( ii < ninxarr )  {
                        crg_goffset ( inxarr[ii], &joffset, &ier );
                        cvg_rdrecnoc( ifname, ifptr, joffset,
                                      &el_q, &ier );
                        if ( el_q.hdr.vg_class == CLASS_TEXT )  {

                            el_t = el_q;
                            switch ( (int)el_t.hdr.vg_type )  {
                            case	TEXT_ELM:
                            case	TEXTC_ELM:
                                flat = el_t.elem.txt.info.lat;
                                flon = el_t.elem.txt.info.lon;
                                break;
                            case	SPTX_ELM:
                                flat = el_t.elem.spt.info.lat;
                                flon = el_t.elem.spt.info.lon;
                                break;
                            }
                            npts = 1;
                            cgr_inpoly ( "M", &npts, &flat, &flon, "M",
                                         &npoly, px, py, inout, &ier );
                            if ( ( kept == G_TRUE )  &&
                                    ( ( inout[0] == 1 && strcmp(keep,"keep") == 0 )  ||
                                      ( inout[0] == 0 && strcmp(keep,"keep") != 0 ) ) ) {
                            }
                            else  {
                                cvg_writef ( &el_t, -1, el_t.hdr.recsz, outfile,
                                             FALSE, &loc, &ier );
                            }
                        }

                        ii++;

                    }

                }

                break;

            case	CLASS_CIRCLE:
            case	CLASS_LINES:
            case	CLASS_FRONTS:

                /*
                 * convert a circle element to a line element
                 */
                if ( vg_class == CLASS_CIRCLE ) {

                    cvg_cir2lin ( &el, 10, &el_lin, &ier );
                    el = el_lin;
                    vg_class = el.hdr.vg_class;
                    vg_type  = el.hdr.vg_type;
                }

                switch ( (int)vg_type )  {

                case    LINE_ELM:
                    npts = el.elem.lin.info.numpts;
                    ptrlat = &(el.elem.lin.latlon[   0]);
                    ptrlon = &(el.elem.lin.latlon[npts]);
                    break;

                case    SPLN_ELM:
                    npts = el.elem.spl.info.numpts;
                    ptrlat = &(el.elem.spl.latlon[   0]);
                    ptrlon = &(el.elem.spl.latlon[npts]);
                    break;

                case    FRONT_ELM:
                    npts = el.elem.frt.info.numpts;
                    ptrlat = &(el.elem.frt.latlon[   0]);
                    ptrlon = &(el.elem.frt.latlon[npts]);
                    break;

                }

                memcpy ( plat, ptrlat, (size_t)npts*sizeof(float) );
                memcpy ( plon, ptrlon, (size_t)npts*sizeof(float) );
                if ( el.hdr.closed == 1 )  {
                    plat[npts] = plat[0];
                    plon[npts] = plon[0];
                    npts++;
                }

                if ( strcmp(precision,"EXACT") == 0 )  {

                    clip_line ( npoly, px, py, npts, plat, plon,
                                (int)el.hdr.closed, sizeof(xinout)/sizeof(float),
                                &ninout, xinout, yinout, inout, &ier );
                }
                else if ( strcmp(precision,"ROUGH") == 0 )  {

                    cgr_inpoly ( "M", &npts, plat, plon, "M", &npoly, px, py,
                                 inout, &ier );
                    ninout = npts;
                    memcpy ( xinout, plat, (size_t)ninout*sizeof(float) );
                    memcpy ( yinout, plon, (size_t)ninout*sizeof(float) );

                }

                /*
                 *  If element is closed, and some points are to be kept and others are not,
                 *  then rotate the locations arrays such that a transition point is the first point.
                 */
                if ( el.hdr.closed == 1 )  {
                    ip = 0;
                    ninout--;
                    while ( inout[ip] == inout[0] && ip < ninout )  ip++;
                    if ( ip != ninout )  {
                        if (( inout[0] == 1 && strcmp(keep,"keep") == 0 )  ||
                                ( inout[0] == 0 && strcmp(keep,"keep") != 0 ) ) {
                            memcpy ( tlat, xinout, (size_t)ninout*sizeof(float) );
                            memcpy ( tlon, yinout, (size_t)ninout*sizeof(float) );
                            memcpy ( tinout, inout, (size_t)ninout*sizeof(float) );
                            for ( ii = 0; ii < ninout; ii++ )  {
                                xinout[ii] = tlat[(ii+ip) % ninout];
                                yinout[ii] = tlon[(ii+ip) % ninout];
                                inout[ii] = tinout[(ii+ip) % ninout];
                            }
                        }
                    }
                }

                ip = 0;
                while ( ip < ninout )  {

                    ibeg = ip;
                    iend = ip;
                    while ( inout[ip] == inout[ibeg] && ip < ninout )  ip++;
                    iend = ip - 1;
                    numpts = iend - ibeg + 1;

                    /*
                     *  If element is closed, and some points are to be kept and others are not,
                     *  then reset the closed flag.
                     */
                    if ( el.hdr.closed == 1 && numpts != ninout )
                        el.hdr.closed = 0;

                    if ( numpts > 1 )  {

                        if (( inout[ibeg] == 1 && strcmp(keep,"keep") == 0 )  ||
                                ( inout[ibeg] == 0 && strcmp(keep,"keep") != 0 ) ) {

                            switch ( (int)vg_type )  {

                            case    LINE_ELM:
                                el.elem.lin.info.numpts = numpts;
                                ptrlat = &(el.elem.lin.latlon[     0]);
                                ptrlon = &(el.elem.lin.latlon[numpts]);
                                el.hdr.recsz = ( (int)((sizeof(float) * 2 * (size_t)numpts) +
                                                       sizeof(VG_HdrStruct) +
                                                       sizeof(LineInfo) ));
                                break;

                            case    SPLN_ELM:
                                el.elem.spl.info.numpts = numpts;
                                ptrlat = &(el.elem.spl.latlon[     0]);
                                ptrlon = &(el.elem.spl.latlon[numpts]);
                                el.hdr.recsz = ( (int)((sizeof(float) * 2 * (size_t)numpts) +
                                                       sizeof(VG_HdrStruct) +
                                                       sizeof(SpLineInfo) ));
                                break;

                            case    FRONT_ELM:
                                el.elem.frt.info.numpts = numpts;
                                ptrlat = &(el.elem.frt.latlon[     0]);
                                ptrlon = &(el.elem.frt.latlon[numpts]);
                                el.hdr.recsz = ( (int)((sizeof(float) * 2 * (size_t)numpts) +
                                                       sizeof(VG_HdrStruct) +
                                                       sizeof(FrontInfo) ));
                                break;

                            }

                            memcpy(ptrlat, &(xinout[ibeg]), (size_t)numpts*sizeof(float));
                            memcpy(ptrlon, &(yinout[ibeg]), (size_t)numpts*sizeof(float));

                            cvg_writef ( &el, -1, el.hdr.recsz, outfile,
                                         FALSE, &loc, &ier );

                            if ( (int)el.hdr.grptyp != 0 && ninxarr > 1 )  {
                                found = G_FALSE;
                                found_txt = G_FALSE;
                                ii = 0;
                                while ( ii < ninxarr && found == G_FALSE )  {
                                    crg_goffset ( inxarr[ii], &joffset, &ier );
                                    cvg_rdrecnoc( ifname, ifptr, joffset,
                                                  &el_q, &ier );
                                    if ( el_q.hdr.vg_class == CLASS_TEXT )  {

                                        found_txt = G_TRUE;
                                        el_t = el_q;
                                        switch ( (int)el_t.hdr.vg_type )  {
                                        case	TEXT_ELM:
                                        case	TEXTC_ELM:
                                            flat = el_t.elem.txt.info.lat;
                                            flon = el_t.elem.txt.info.lon;
                                            break;
                                        case	SPTX_ELM:
                                            flat = el_t.elem.spt.info.lat;
                                            flon = el_t.elem.spt.info.lon;
                                            break;
                                        }
                                        npts = 1;
                                        cgr_inpoly ( "M", &npts, &flat, &flon, "M",
                                                     &npoly, px, py, inout, &ier );
                                        if ( ( inout[0] == 1 && strcmp(keep,"keep") == 0 )  ||
                                                ( inout[0] == 0 && strcmp(keep,"keep") != 0 ) )  {
                                            found = G_TRUE;
                                            break;
                                        }
                                    }
                                    ii++;

                                }
                                if ( found == G_FALSE && ii == ninxarr &&
                                        found_txt == G_TRUE )  {

                                    switch ( (int)vg_type )  {
                                    case    LINE_ELM:
                                        flat = ( el.elem.lin.latlon[0] +
                                                 el.elem.lin.latlon[1] ) / 2.0F;
                                        flon = ( el.elem.lin.latlon[numpts] +
                                                 el.elem.lin.latlon[numpts+1] ) / 2.0F;
                                        break;
                                    case    SPLN_ELM:
                                        flat = ( el.elem.spl.latlon[0] +
                                                 el.elem.spl.latlon[1] ) / 2.0F;
                                        flon = ( el.elem.spl.latlon[numpts] +
                                                 el.elem.spl.latlon[numpts+1] ) / 2.0F;
                                        break;
                                    case    FRONT_ELM:
                                        flat = ( el.elem.frt.latlon[0] +
                                                 el.elem.frt.latlon[1] ) / 2.0F;
                                        flon = ( el.elem.frt.latlon[numpts] +
                                                 el.elem.frt.latlon[numpts+1] ) / 2.0F;
                                        break;
                                    }

                                    switch ( (int)el_t.hdr.vg_type )  {
                                    case	TEXT_ELM:
                                    case	TEXTC_ELM:
                                        el_t.elem.txt.info.lat = flat;
                                        el_t.elem.txt.info.lon = flon;
                                        break;
                                    case	SPTX_ELM:
                                        el_t.elem.spt.info.lat = flat;
                                        el_t.elem.spt.info.lon = flon;
                                        break;
                                    }

                                    cvg_writef ( &el_t, -1, el_t.hdr.recsz, outfile,
                                                 FALSE, &loc, &ier );
                                }

                            }

                        }

                    }
                }
                break;

            case	CLASS_MET:
                switch ( (int)vg_type )  {
                case    JET_ELM:
                    npts = tltpts = el.elem.jet.line.spl.info.numpts;
                    ptrlat = &(el.elem.jet.line.spl.latlon[   0]);
                    ptrlon = &(el.elem.jet.line.spl.latlon[npts]);
                    memcpy ( plat, ptrlat, (size_t)npts*sizeof(float) );
                    memcpy ( plon, ptrlon, (size_t)npts*sizeof(float) );

                    if ( strcmp(precision,"EXACT") == 0 )  {

                        clip_line ( npoly, px, py, npts, plat, plon,
                                    (int)el.hdr.closed, sizeof(xinout)/sizeof(float),
                                    &ninout, xinout, yinout, inout, &ier );

                    }
                    else if ( strcmp(precision,"ROUGH") == 0 )  {

                        cgr_inpoly ( "M", &npts, plat, plon, "M", &npoly, px, py, inout, &ier );
                        ninout = npts;
                        memcpy ( xinout, plat, (size_t)ninout*sizeof(float) );
                        memcpy ( yinout, plon, (size_t)ninout*sizeof(float) );
                    }

                    ip = 0;
                    while ( ip < ninout )  {

                        ibeg = ip;
                        iend = ip;
                        while ( inout[ip] == inout[ibeg] && ip < ninout )
                            ip++;
                        iend = ip - 1;
                        numpts = iend - ibeg + 1;

                        if ( numpts > 1 )  {

                            if (( inout[ibeg] == 1 && strcmp(keep,"keep") == 0 )  ||
                                    ( inout[ibeg] == 0 && strcmp(keep,"keep") != 0 ) ) {
                                memcpy ( &(el_t.hdr), &(el.hdr), sizeof(VG_HdrStruct) );
                                el_t.elem.jet.line.splcol = el.elem.jet.line.splcol;
                                memcpy ( &(el_t.elem.jet.line.spl.info), &(el.elem.jet.line.spl.info), sizeof(SpLineInfo) );
                                el_t.elem.jet.line.spl.info.numpts = numpts;
                                ptrlat = &(el_t.elem.jet.line.spl.latlon[     0]);
                                ptrlon = &(el_t.elem.jet.line.spl.latlon[numpts]);
                                memcpy(ptrlat, &(xinout[ibeg]), (size_t)numpts*sizeof(float));
                                memcpy(ptrlon, &(yinout[ibeg]), (size_t)numpts*sizeof(float));
                                nbarb = 0;
                                for ( ii = 0; ii < el.elem.jet.nbarb; ii++ ) {
                                    flat = el.elem.jet.barb[ii].wnd.data.latlon[0];
                                    flon = el.elem.jet.barb[ii].wnd.data.latlon[1];
                                    npts = 1;
                                    cgr_inpoly ( "M", &npts, &flat, &flon, "M", &npoly, px, py, tinout, &ier );
                                    if (( tinout[0] == 1 && strcmp(keep,"keep") == 0 )  ||
                                            ( tinout[0] == 0 && strcmp(keep,"keep") != 0 ) ) {
                                        memcpy ( &(el_t.elem.jet.barb[nbarb]), &(el.elem.jet.barb[ii]), sizeof(BarbAttr) );
                                        nbarb++;
                                    }
                                }
                                el_t.elem.jet.nbarb = nbarb;

                                nhash = 0;
                                for ( ii = 0; ii < el.elem.jet.nhash; ii++ ) {
                                    flat = el.elem.jet.hash[ii].wnd.data.latlon[0];
                                    flon = el.elem.jet.hash[ii].wnd.data.latlon[1];
                                    npts = 1;
                                    cgr_inpoly ( "M", &npts, &flat, &flon, "M", &npoly, px, py, tinout, &ier );
                                    if (( tinout[0] == 1 && strcmp(keep,"keep") == 0 )  ||
                                            ( tinout[0] == 0 && strcmp(keep,"keep") != 0 ) ) {
                                        memcpy ( &(el_t.elem.jet.hash[nhash]), &(el.elem.jet.hash[ii]), sizeof(HashAttr) );
                                        nhash++;
                                    }
                                }
                                el_t.elem.jet.nhash = nhash;
                                cvg_writef ( &el_t, -1, el.hdr.recsz, outfile,
                                             FALSE, &loc, &ier );
                            }
                        }
                    }
                    break;
                case GFA_ELM:
                    /* Get the Hazard Type... */
                    cvg_getFld ( &el, TAG_GFA_AREATYPE, hazList, &ier );
                    npts = el.elem.gfa.info.npts;
                    ptrlat = &(el.elem.gfa.latlon[0]);
                    ptrlon = &(el.elem.gfa.latlon[npts]);
                    memcpy ( plat, ptrlat, (size_t)npts*sizeof(float) );
                    memcpy ( plon, ptrlon, (size_t)npts*sizeof(float) );
                    if ( el.hdr.closed == 1 )  {
                        plat[npts] = plat[0];
                        plon[npts] = plon[0];
                        npts++;
                    }
                    if(strcmp(hazList,"FZLVL")==0) {  /* Is this a Freezing Level? */
                        if ( strcmp(precision,"EXACT") == 0 ) {
                            clip_line ( npoly, px, py, npts, plat, plon,
                                        (int)el.hdr.closed,
                                        sizeof(xinout)/sizeof(float),
                                        &ninout, xinout, yinout, inout, &ier );
                        } else if (strcmp(precision,"ROUGH") == 0 ) {
                            cgr_inpoly ( "M", &npts, plat, plon, "M", &npoly, px, py,
                                         inout, &ier );
                            ninout = npts;
                            memcpy ( xinout, plat, (size_t)ninout*sizeof(float) );
                            memcpy ( yinout, plon, (size_t)ninout*sizeof(float) );
                        }

                        if ( el.hdr.closed == 1 )  {
                            ip = 0;
                            ninout--;
                            while ( inout[ip] == inout[0] && ip < ninout )  ip++;
                            if ( ip != ninout )  {
                                if (( inout[0] == 1 && strcmp(keep,"keep") == 0 )  ||
                                        ( inout[0] == 0 && strcmp(keep,"keep") != 0 ) ) {
                                    memcpy ( tlat, xinout, (size_t)ninout*sizeof(float) );
                                    memcpy ( tlon, yinout, (size_t)ninout*sizeof(float) );
                                    memcpy ( tinout, inout, (size_t)ninout*sizeof(float) );
                                    for ( ii = 0; ii < ninout; ii++ )  {
                                        xinout[ii] = tlat[(ii+ip) % ninout];
                                        yinout[ii] = tlon[(ii+ip) % ninout];
                                        inout[ii] = tinout[(ii+ip) % ninout];
                                    }
                                }
                            }
                        }
                        ip = 0;

                        while ( ip < ninout ) {
                            ibeg = ip;
                            iend = ip;
                            while ( inout[ip] == inout[ibeg] && ip < ninout ) ip++;
                            iend = ip - 1;
                            numpts = iend - ibeg + 1;
                            if (el.hdr.closed == 1 && numpts != ninout )
                                el.hdr.closed = 0;

                            if ( numpts > 1 )  {

                                if (( inout[ibeg] == 1 && strcmp(keep,"keep") == 0 )  ||
                                        ( inout[ibeg] == 0 && strcmp(keep,"keep") != 0 )) {
                                    el.elem.gfa.info.npts = numpts;
                                    ptrlat = &(el.elem.gfa.latlon[     0]);
                                    ptrlon = &(el.elem.gfa.latlon[numpts]);
                                    memcpy(ptrlat, &(xinout[ibeg]),
                                           (size_t)numpts*sizeof(float));
                                    memcpy(ptrlon, &(yinout[ibeg]),
                                           (size_t)numpts*sizeof(float));
                                    /* Recompute Default Text Label & Arrow location */
                                    recalcGFAtLblArwLoc( &el );
                                    el.hdr.recsz = (int) (sizeof(VG_HdrStruct) +
                                                          sizeof(int)*2 + sizeof(char)* STD_STRLEN *
                                                          el.elem.gfa.info.nblocks ) + sizeof(float)*numpts*2;
                                    cvg_writef ( &el, -1, el.hdr.recsz, outfile,
                                                 FALSE, &loc, &ier );
                                }
                            }
                        }
                    } else {
                        /* We have a GFA object (that's not a freezing level)
                                    to be clipped */
                        /* Use clo_clip to clip the GFA Polygon against the specified
                           bounds area. The resulting number of clipped areas (tnclips),
                           and max points (tmaxpts) is returned */
                        clo_clip(&npts, plat, plon, sys_M, bnd_name, bnd_tag, &tnclip,
                                 &tmaxpts, &ier);
                        /* Foreach of the clipped areas, get the clipped area, and write
                           it out to the VGF file */
                        for (ii = 0; ii < tnclip; ii++) {
                            clo_clipget(&ii, &tnpts, tlat, tlon, &ier);
                            el.elem.gfa.info.npts = tnpts;
                            ptrlat = &(el.elem.gfa.latlon[     0]);
                            ptrlon = &(el.elem.gfa.latlon[tnpts]);
                            /* Re-Initialize the latlon struct. */
                            for (jj =0; jj < MAXPTS*2; jj++) {
                                el.elem.gfa.latlon[jj] = 0.00;
                            }
                            memcpy(ptrlat, &(tlat[0]),
                                   (size_t)tnpts*sizeof(float));
                            memcpy(ptrlon, &(tlon[0]),
                                   (size_t)tnpts*sizeof(float));
                            /* Recompute Default Text Label & Arrow location */
                            recalcGFAtLblArwLoc( &el );
                            el.hdr.recsz = (int) (sizeof(VG_HdrStruct) +
                                                  sizeof(int)*2 + sizeof(char)* STD_STRLEN *
                                                  el.elem.gfa.info.nblocks ) + sizeof(float)*tnpts*2;
                            cvg_writef (&el, -1, el.hdr.recsz, outfile,
                                        FALSE, &loc, &ier );
                        }
                        /*  Free up memory left over from the clo routines */
                        clo_clipdone(&ier);
                    }
                    break;
                }
                break;
            }
        }
        ne++;
    }

    cfl_clos ( ifptr, &ier );
    return(0);
}
Exemple #6
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 );
}
Exemple #7
0
int main ( int argc, char **argv )
/************************************************************************
 * VGF2TAG								*
 *									*
 * This program converts a file of pgen elements in <tag>value format	*
 * into a standard VGF file.						*
 *									*
 **									*
 * Log: 								*
 * D.W.Plummer/NCEP	06/03						*
 * S. Jacobs/NCEP	 5/05	Increased the size of the buffer	*
 * S. Jacobs/NCEP	12/09	Changed cvg_rdrecnoc to cvg_rdjrecnoc	*
 * S. Jacobs/NCEP	 1/12	Changed cvg_jrdrecnoc to cvg_rdrecnoc	*
 ***********************************************************************/
{
int		ne, more, ier;
int		wrtflg, curpos;
VG_DBStruct	el;
char		asfn[32], vgfn[128];
char		comment[8]={"!\n"}, buffer[10000];
char		infile[128], ifname[128];
long		ifilesize;
int		nw;
FILE		*ifptr, *ofptr;
/*---------------------------------------------------------------------*/
    
    printf ( "Enter the VGF file name to convert from :\n" );
    scanf ( " %s", vgfn );
    printf ( "Enter the ASCII file name to write tags to :\n" );
    scanf ( " %s", asfn );

    wrtflg = 0;
    cvg_open ( vgfn, wrtflg, &(ifptr), &ier );
    if ( ier != 0 )  {
        printf("Error opening VGF file %s\n", infile );
        exit (0);
    }
    cfl_inqr ( vgfn, NULL, &ifilesize, ifname, &ier );

    ofptr = cfl_wopn ( asfn, &ier );

    nw = 0;
    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 )  {
	    curpos += el.hdr.recsz;
            cvg_v2t ( &el, buffer, &ier );
	    if ( ier == 0 )  {
	        cfl_writ ( ofptr, (int)strlen("!\n"), (unsigned char*)comment, &ier );
		strcat ( buffer, "\n" );
	        cfl_writ ( ofptr, (int)strlen(buffer), (unsigned char*)buffer, &ier );
		if ( ier == 0 )  nw++;
	    }
	}


    }
    printf("Number of elements encoded and written successfully = %d\n", nw );

    return ( 0 );

}
Exemple #8
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;

}
Exemple #9
0
void cvg_open ( char *filnam, int wrtflg, FILE **fptr, int *iret )
/************************************************************************
 * cvg_open								*
 *									*
 * This function opens a VG file.					*
 *									*
 * cvg_open ( filnam, wrtflg, fptr, iret )				*
 *									*
 * Input parameters:							*
 *	*filnam		char		VG filename			*
 *	wrtflg		int		Write flag			*
 *									*
 * Output parameters:							*
 *	**fptr		FILE		File pointer			*
 *	*iret		int		Return code			*
 *					   2 = created vg file		*
 *					   0 = normal 			*
 *					  -1 = error opening VG file	*
 *					 -13 = error verifying vg file  *
 *					 -25 = no filehead elm in file  *
 *					 -47 = no file name specified   *
 **									*
 * Log:									*
 * D. Keiser/GSC	 1/97	Copied from UTF_OPEN			*
 * E. Wehner/EAi	 6/97	Create VGF if does not exist		*
 * E. Wehner/EAi	 7/97	Produce error msg on bad hdr		*
 * E. Wehner/EAi	 9/97	Handle null file name			*
 * E. Safford/GSC	10/98	clean up & rework error mesgs		*
 * A. Hardy/GSC          1/01   changed fptr from int to FILE   	*
 * E. Safford/SAIC	04/02	avoid cvg_rdhdr if bad filehead 	*
 * T. Lee/SAIC		11/03	used cvgcmn.h				*
 * T. Piper/SAIC	09/06	Added wrtflg check after first cfl_inqr	*
 ***********************************************************************/
{
    int			ier, ier1, flag, curpos;
    long		maxbytes;
    int			err_log, dtl_log, dbg_log;
    VG_DBStruct		el;
    char		grp[4], newfil[256];
/*---------------------------------------------------------------------*/
    *fptr = NULL;

    strcpy(grp, "CVG");
    err_log  = 0;
    dtl_log  = 2;
    dbg_log  = 4; 

    *iret = 0;

    /*  Check to see if there is a file of the specified name, 
     *  open it if it is there.
     */    

    if ( !filnam) {
	*iret = ier1 = -47;
        er_lmsg ( &dbg_log, grp, &ier1, filnam, &ier, strlen(grp),
                        strlen(filnam) );
	return;
    }

    cfl_inqr(filnam, NULL, &maxbytes, newfil, &ier);
    
    if ( ier < 0 && wrtflg == G_TRUE ) {

	/*
	 *  Attempt to create a vg file if specified file doesn't exist
	 */
	cvg_crvgf(filnam, &ier);
	if (ier == 0) {

	    /* 
	     * Verify file was created
	     */ 
	    cfl_inqr(filnam, NULL, &maxbytes, newfil, &ier);

	}

	if (ier != 0) {
	    *iret = ier1 = -1;
            er_lmsg ( &err_log, grp, &ier1, filnam, &ier, strlen(grp),
                        strlen(filnam) );
	    return;
	}
	else {
	    /*
	     *  File was created successfully
	     */
	    *iret = ier1 = 2;
            er_lmsg ( &dtl_log, grp, &ier1, filnam, &ier, strlen(grp),
                        strlen(filnam) );
	}

    }

    /*  
     *  Open file with either read, or read-write permissions
     */
    if (wrtflg == G_TRUE) {
	*fptr = cfl_uopn(filnam, &ier);
    }
    else {
	*fptr = cfl_ropn(filnam, " ", &ier);
    }

    if (( ier != 0 ) || ( *fptr == NULL )) {		/* open failed */
	*iret = ier1 = -1;
        er_lmsg ( &err_log, grp, &ier1, filnam, &ier, strlen(grp),
                        strlen(filnam) );
    }
    else {

	if ( (size_t)maxbytes < (sizeof(FileHeadType) + sizeof(VG_HdrStruct)) ) {
	    *iret = -25;
	}
        else {
            /* 
	     * Check to see that the file is a valid VGF file...
	     */
	    curpos = 0;
            cvg_rdhdr(newfil, *fptr, curpos, (int)maxbytes, &el, &flag, &ier);
	    if (ier != 0) {
                *iret = ier1 = -13;
                er_lmsg ( &err_log, grp, &ier1, filnam, &ier, strlen(grp),
                        strlen(filnam) );
    	    }

	    if (el.hdr.vg_type != FILEHEAD_ELM) {
	        *iret = ier1 = -25;
                er_lmsg ( &err_log, grp, &ier1, filnam, &ier, strlen(grp),
                        strlen(filnam) );
	    }
	}
    }
}
Exemple #10
0
void cvg_valid ( char *filnam, int *iret )
/************************************************************************
 * cvg_valid								*
 *									*
 * This function checks validity of a VG file.				*
 *									*
 * cvg_valid ( filnam, iret )						*
 *									*
 * Input parameters:							*
 *	*filnam		char		VG filename			*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *					   1 = VG file does not exist	*
 *					   0 = normal 			*
 *					  -1 = error opening VG file	*
 *					 -13 = error verifying vg file  *
 *					 -25 = no filehead elm in file  *
 *					 -47 = no file name specified   *
 **									*
 * Log:									*
 * T. Lee/SAIC		05/02	created					*
 * T. Lee/SAIC		11/03	used cvgcmn.h				*
 ***********************************************************************/
{
    int			ier, flag, curpos;
    long		maxbytes;
    VG_DBStruct		el;
    char		newfil[256];
    FILE		*fptr;
/*---------------------------------------------------------------------*/
    *iret = 0;
    fptr = NULL;

    /*  	
     * Check to see if there is a file of the specified name.
     */    

    if ( strlen (filnam) <= (size_t)0 ) {
	*iret = -47;
	return;
    }

    cfl_inqr(filnam, NULL, &maxbytes, newfil, &ier);
    
    if (ier < 0) {

	/*
	 *  if file does not exist retrun error code 1.
	 */
	*iret = 1;
	return;
    }

    /*  
     *  Open the file. 
     */

    fptr = cfl_ropn (newfil, NULL, &ier);

    if ( ( ier != 0 ) || ( fptr == NULL ) ) {	   /* open failed */
	*iret = -1;
        return;
    }
    else {

	if ( maxbytes < (long)(sizeof(FileHeadType) + sizeof(VG_HdrStruct)) ) {
	    *iret = -25;
	}
        else {
            /* 
	     * Check to see that the file is a valid VGF file...
	     */
	    curpos = 0;
            cvg_rdhdr (newfil, fptr, curpos, (int)maxbytes, &el, &flag, &ier);
	    if (ier != 0) {
                *iret = -13;
    	    }

	    if (el.hdr.vg_type != FILEHEAD_ELM) {
	        *iret = -25;
	    }
	}
	cfl_clos ( fptr, &ier );
    }
}
Exemple #11
0
int main ( void )
/************************************************************************
 * TESTGPC								*
 *									*
 * This program tests the GPC contributed library public functions.	*
 *									*
 **									*
 * Log:									*
 * D.W.Plummer/NCEP	 2/04						*
 * D.W.Plummer/NCEP	10/06	Added GPC_SET_EPSILON			*
 ***********************************************************************/
{
int		ii, cont, numsub, which, ier;
int		operation, readholeflag, writeholeflag, hole;
int		nverts=0;
double		e;
char		select[8];
float		xv[LLMXPT], yv[LLMXPT];
char		filnam[256], buffer[80];
int		pagflg;
char    	errgrp[8];
FILE		*fpread, *fpwrite;
gpc_polygon	subject_polygon, clip_polygon, result_polygon;
gpc_vertex_list	contour;
/*---------------------------------------------------------------------*/
    cont = G_FALSE;

    /*
     * Structure initializations.
     */
    subject_polygon.num_contours = 0;
    subject_polygon.hole         = (int*)NULL;
    subject_polygon.contour      = (gpc_vertex_list*)NULL;
    clip_polygon.num_contours    = 0;
    result_polygon.num_contours  = 0;
    contour.vertex 		 = (gpc_vertex*)NULL;
    contour.num_vertices 	 = 0;

    while ( cont == G_FALSE ) {
        printf ( "\n\n" );
        printf ( "*** ORIGINAL GPC PUBLIC FUNCTIONS ***\n");
        printf ( "   1 = GPC_READ_POLYGON    2 = GPC_WRITE_POLYGON \n");
        printf ( "   3 = GPC_ADD_CONTOUR     4 = GPC_POLYGON_CLIP \n");
        printf ( "   5 = GPC_FREE_POLYGON     \n");
        printf ( "*** GPC PUBLIC FUNCTION ADD-ONS ***\n");
        printf ( "  11 = GPC_CREATE_VERTEX_LIST   \n");
	printf ( "  12 = GPC_GET_VERTEX_LIST      \n");
	printf ( "  13 = GPC_GET_VERTEX_AREA      \n");
	printf ( "  14 = GPC_SET_EPSILON      \n");
        printf ( "*** HELP ***\n");
	printf ( "  99 = HELP on INPUT FILE FORMATS \n");
        printf ( "\n" );
        printf ( "Select a subroutine number or type EXIT: " );
        scanf ( " %s", select );
        switch ( select[0] ) {
    	    case 'e':
    	    case 'E':
    		cont = G_TRUE;
    	    default:
    		numsub = atoi ( select );
    		break;
        }

/*---------------------------------------------------------------------*/
        if ( numsub == 1 ) {

	    printf("Make sure your polygon file is in the proper format:\n");

	    printf("<num-contours>\n");
	    printf("<num-vertices-in-first-contour>\n");
	    printf("[<first-contour-hole-flag>]\n");
	    printf("<vertex-list>\n");
	    printf("<num-vertices-in-second-contour>\n");
	    printf("[<second-contour-hole-flag>]\n");
	    printf("<vertex-list> \n");
	    printf("etc...\n");

	    printf ( "Enter filename to read polygon from : \n");
	    scanf ( " %s", filnam );

	    printf ( "Enter whether file format contains hole flags (%d-FALSE,%d-TRUE) :\n",
		  G_FALSE, G_TRUE );
	    scanf ( " %d", &readholeflag );

	    printf ( "Enter which polygon (%d-SUBJECT,%d-CLIP) :\n",
		  SUBJECT, CLIP );
	    scanf ( " %d", &which );

	    fpread = (FILE *)cfl_ropn ( filnam, "", &ier );
	    if ( ier == G_NORMAL )  {
	      if ( which == SUBJECT )
	        gpc_read_polygon ( fpread, readholeflag, &subject_polygon );
	      else if ( which == CLIP )
	        gpc_read_polygon ( fpread, readholeflag, &clip_polygon );
	      else
		printf("Invalid polygon type\n");
	      cfl_clos ( fpread, &ier );
	    }
	    else  {
	      printf("Unable to open file %s\n", filnam );
	    }

        }
/*---------------------------------------------------------------------*/
        if ( numsub == 2 ) {

	    printf ( "Enter filename to write polygon to : \n");
	    scanf ( " %s", filnam );

	    printf ( "Enter the write hole flag (%d-FALSE,%d-TRUE):\n",
		  G_FALSE, G_TRUE );
	    scanf ( " %d", &writeholeflag );

	    printf ( "Enter which polygon (%d-SUBJECT,%d-CLIP,%d-RESULT):\n",
		  SUBJECT, CLIP, RESULT );
	    scanf ( " %d", &which );

	    fpwrite = (FILE *)cfl_wopn ( filnam, &ier );
	    if ( ier == G_NORMAL )  {
	      if ( which == SUBJECT )
	        gpc_write_polygon ( fpwrite, writeholeflag, &subject_polygon );
	      else if ( which == CLIP )
	        gpc_write_polygon ( fpwrite, writeholeflag, &clip_polygon );
	      else if ( which == RESULT )
	        gpc_write_polygon ( fpwrite, writeholeflag, &result_polygon );
	      else
		printf("Invalid polygon type\n");
	      cfl_clos ( fpwrite, &ier );
	    }
	    else  {
	      printf("Unable to open file %s\n", filnam );
	    }


        }
/*---------------------------------------------------------------------*/
	if ( numsub == 3 ) {

	    if ( nverts == 0 )  {
		printf("Must first create a vertex list (option 11)\n");
	    }
	    else  {

	        printf ( "Enter which polygon (%d-SUBJECT,%d-CLIP,%d-RESULT) to add vertex list to:\n",
		      SUBJECT, CLIP, RESULT );
	        scanf ( " %d", &which );

	        printf ( "Enter the hole flag (%d-HOLE,%d-NOT A HOLE):\n",
		      G_TRUE, G_FALSE );
	        scanf ( " %d", &hole );

	        if ( which == SUBJECT )  {
		    gpc_add_contour ( &subject_polygon, &contour, hole );
		}
		else if ( which == CLIP )  {
		    gpc_add_contour ( &clip_polygon, &contour, hole );
		}
		else {
		    printf("Invalid polygon\n");
		}
	    }

	}
/*---------------------------------------------------------------------*/
	if ( numsub == 4 ) {

	    printf ( "Enter operation (%d-GPC_DIFF,%d-GPC_INT,%d-GPC_XOR,%d-GPC_UNION):\n",
		  GPC_DIFF, GPC_INT, GPC_XOR, GPC_UNION );
	    scanf ( " %d", &operation );

	    gpc_polygon_clip ( operation, &subject_polygon,
		    &clip_polygon, &result_polygon );

	}
/*---------------------------------------------------------------------*/
        if ( numsub == 5 ) {

	    printf ( "Enter which polygon (%d-SUBJECT,%d-CLIP,%d-RESULT,%d-ALL) to free contours:\n ",
		  SUBJECT, CLIP, RESULT, ALL );
	    scanf ( " %d", &which );

	    if ( which == SUBJECT || which == ALL )  {
    	        if ( subject_polygon.num_contours != 0 )
		    gpc_free_polygon ( &subject_polygon );
	    }
	    else if ( which == CLIP || which == ALL )  {
    	        if ( clip_polygon.num_contours != 0 )
        	    gpc_free_polygon ( &clip_polygon );
	    }
	    else if ( which == RESULT || which == ALL )  {
    	        if ( result_polygon.num_contours != 0 )
        	    gpc_free_polygon ( &result_polygon );
            }


        }
/*---------------------------------------------------------------------*/
        if ( numsub == 11 ) {

	    printf ( "Enter either the number of points in polygon (to be followed by entering the points), or a filename to read points from: \n");
	    scanf ( " %s", filnam );

	    cst_numb ( filnam, &nverts, &ier );

	    if ( ier == 0 )  {
	        for ( ii = 0; ii < nverts; ii++ )
		    scanf ( "%f %f", &(xv[ii]), &(yv[ii]) );
    	        if ( contour.vertex != (gpc_vertex*)NULL )
		    free ( contour.vertex );
	        gpc_cvlist ( nverts, xv, yv, &contour, &ier );
	    }
	    else  {
	        printf ( "Note that the file format is simply a list of coordinate pairs separated by whitespace.\nThe number of points will be counted automatically. For instance, a file containing:\n0 0\n0 1\n1 1\nyields a vertex list of three points.\n\n");
		nverts = 0;
	        fpread = (FILE *)cfl_tbop ( filnam, "", &ier );
	        if ( ier == G_NORMAL )  {
		    cfl_trln ( fpread, sizeof(buffer), buffer, &ier );
		    while ( ier == 0 )  {
			sscanf ( buffer, "%f %f", 
			    &(xv[nverts]), &(yv[nverts]) );
			    nverts += 1;
			cfl_trln ( fpread, sizeof(buffer), buffer, &ier );
		    }
		    printf("EOF reached in file %s, number of vertices = %d\n", 
			    filnam, nverts );
		    cfl_clos( fpread, &ier );
    	            if ( contour.vertex != (gpc_vertex*)NULL )
		    	free ( contour.vertex );
	            gpc_cvlist ( nverts, xv, yv, &contour, &ier );
		}
	    }

        }
/*---------------------------------------------------------------------*/
        if ( numsub == 12 ) {

	    gpc_gvlist ( &contour, &nverts, xv, yv, &ier );

	    printf("gpc_gvlist, ier = %d\n", ier );

	    printf("Number of vertices = %d\n", nverts );
	    for ( ii = 0; ii < nverts; ii++ )
		printf ( "%d - %f %f\n", ii, xv[ii], yv[ii] );

        }
/*---------------------------------------------------------------------*/
        if ( numsub == 13 ) {

	    printf ( "Area of contour is %f\n", gpc_gvarea(&contour) );

        }
/*---------------------------------------------------------------------*/
        if ( numsub == 14 ) {

	    scanf ( " %lf", &e );

	    gpc_set_epsilon ( e );

        }
/*---------------------------------------------------------------------*/
        if ( numsub == 99 ) {

	    pagflg = G_FALSE;
	    strcpy ( errgrp, "TESTGPC" );
	    ip_help ( errgrp, &pagflg, &ier, strlen(errgrp) );

        }
/*---------------------------------------------------------------------*/
    }

    if ( subject_polygon.num_contours != 0 )
	gpc_free_polygon ( &subject_polygon );
    if ( clip_polygon.num_contours != 0 )
        gpc_free_polygon ( &clip_polygon );
    if ( result_polygon.num_contours != 0 )
        gpc_free_polygon ( &result_polygon );
    if ( contour.vertex != (gpc_vertex*)NULL )
	free ( contour.vertex );

    return(0);

}
Exemple #12
0
int main ( int argc, char **argv )
/************************************************************************
 * TAGTOVGF								*
 *									*
 * This program converts a file of pgen elements in <tag>value format	*
 * into a standard VGF file.						*
 *									*
 **									*
 * Log: 								*
 * D.W.Plummer/NCEP	06/03						*
 * S. Jacobs/NCEP	 5/05	Increased size of the buffer		*
 * S. Danz/AWC		07/06	Switch to new cvg_writefD() function    *
 * Q. Zhou/Chu          06/12   Added converting head only file         *
 ***********************************************************************/
{
int		loc, ier;
VG_DBStruct	el;
char	fn[32], vgfn[128], buffer[10000], *str;
int		nw;
FILE	*fp;

/*---------------------------------------------------------------------*/
    
    printf ( "Enter the ASCII file name to read element from :\n" );
    scanf ( " %s", fn );
    printf ( "Enter the VGF file name to write element to :\n" );
    scanf ( " %s", vgfn );

    fp = cfl_ropn ( fn, "", &ier );
    nw = 0;
    while ( ier == 0 )  {

	str = fgets ( buffer, sizeof(buffer), fp );

	if ( str != (char *)NULL )  {
	    if ( buffer[0] != '!' )  {
               cvg_t2v ( buffer, &el, &ier );
 
		if ( ier == 0 )  {
		  if ( el.hdr.vg_type != FILEHEAD_ELM )  {
	            cvg_writefD ( &el, -1, el.hdr.recsz, vgfn, &loc, &ier );
 	            if ( ier != 0 )  {
		        printf("ERROR writing element to file %s\n", vgfn );
	            }
	            else  {
		        nw++;
	            }
	          }
	        }
		else  {
		    printf("ERROR processing buffer=\"%s\"\n", buffer );
		}
	    }
	}
	else  {
	    ier = -1;
	}
    }

    if ( nw==0) { 
    	cvg_crvgf(vgfn, &ier);
    }
    printf("Number of elements decoded and written successfully = %d\n", nw );

    return ( 0 );

}
Exemple #13
0
void msdatt ( int *iunit, char *filnam, int *lenf, int *itype, 
              float *xsize, float *ysize, int *ileft, int *ibot, 
	      int *iright, int *itop, int *iret )
/************************************************************************
 * msdatt								*
 *									*
 * This subroutine is called to initialize the metafile attributes.	*
 *									*
 * msdatt  ( iunit, filnam, lenf, itype, xsize, ysize,			*
 *           ileft, ibot, iright, itop, iret )                          *
 *									*
 * Input parameters:							*
 *	*iunit		int		Output type (Used for XW only)	*
 *	*filnam		char		Output metafile name		*
 *	*lenf		int		Length of file name		*
 *	*itype		int		Device color type		*
 *	*xsize		float		X size in pixels		*
 *	*ysize		float		Y size in pixels		*
 *									*
 * Output parameters:							*
 *      *ileft          int             Left device coordinate          *
 *      *ibot           int             Bottom device coordinate        *
 *      *iright         int             Right device coordinate         *
 *      *itop           int             Top device coordinate           *
 *	*iret		int		Return code			*
 **									*
 * Log:									*
 * S. Jacobs/NCEP	 2/96						*
 * S. Jacobs/NCEP	 5/96	Added new global variables for queries	*
 * S. Jacobs/NCEP	 2/97	Fixed check for same file name		*
 * R. Tian/SAIC          4/02   Added init of ileft, ibot, iright, itop *
 * M. Li/SAIC		 7/02	Added G_NINT				*
 ***********************************************************************/
{
	int	ier;
	char	tmpfil[MAX_FNLEN];
        int     tmpxz, tmpyz;
	long	flen;
	int	nbin;
	FILE	*fp;

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

/*
 *	If the input length is greater than the maximum allowed,
 *	return an error.
 */
	if  ( ( *lenf >= MAX_FNLEN ) || ( *lenf <= 0 ) )  {
	    *iret = G_NOMETA;
	    return;
	}

/*
 *	Copy the file name to a temporary variable and add a NULL.
 */
	strncpy ( tmpfil, filnam, (size_t)*lenf );
	tmpfil[*lenf] = CHNULL;

/*
 *	Compare the input file name to the current file name.  If the
 *	names are different, close the old file.  Otherwise, do nothing.
 */
	if  ( strcmp ( curfil, tmpfil ) != 0 )  {
 	    mclose ( &ier );

/*
 *	    Set the current file name.
 */
	    strcpy ( curfil, tmpfil );
	    *iret = G_NEWWIN;

/*
 *	    Set the global output and color scheme types.
 */
    	    kctype = *itype;
	    kunit  = *iunit;

/*
 *          Check for the existence of the metafile.
 */
	    cfl_inqr(curfil, NULL, &flen, tmpfil, &ier);
            if ( ( ier == 0 ) && ( strcmp ( curfil, "Nmeta" ) != 0 ) ) {
/*
 *          	Get frame size from the existing file
 */
		if ( ( fp = cfl_ropn(curfil, NULL, &ier) ) == NULL ) {
            	    *iret = G_NOMETA;
            	    return;
        	}
		
	        cfl_read(fp, sizeof(nc_file_header), (unsigned char *)&meta_head,
		         &nbin, &ier);
        	if ( ier ) {
            	    *iret = G_NOMETA;
		    cfl_clos(fp, &ier);
            	    return;
        	}
		cfl_clos(fp, &ier);

            	if ( meta_head.version == 2 ) {
/*
 *    	            Set the global CGM frame size
 */
        	    fxsize = meta_head.fxsize;
        	    fysize = meta_head.fysize;

/*
 *      	    ileft  = left device coordinate
 *      	    ibot   = bottom device coordinate
 *      	    iright = right device coordinate
 *      	    itop   = top device coordinate
 */
        	    *ileft  = 0;
        	    *ibot   = 0;
        	    *iright = (int)meta_head.fxsize;
        	    *itop   = (int)meta_head.fysize;
		}

            } else {
/*
 *              The valid range of xsize and ysize is 0.1 ~ 1.0.  If neither
 *              value is 1.0, then set the larger value to be 1.0, and set the
 *              smaller value to be the ratio of the smaller to the larger.
 */
        	tmpxz = G_NINT(*xsize * (float)XY_SCALE);
        	tmpyz = G_NINT(*ysize * (float)XY_SCALE);
        	tmpxz = (tmpxz < 0 || tmpxz > XY_SCALE) ? XY_SCALE : tmpxz;
        	tmpyz = (tmpyz < 0 || tmpyz > XY_SCALE) ? XY_SCALE : tmpyz;
        	if(tmpxz != XY_SCALE && tmpyz != XY_SCALE) {
            	    if(tmpxz > tmpyz) {
                    	tmpyz = G_NINT((((float)tmpyz)/(float)tmpxz)*(float)XY_SCALE);
                    	tmpxz = XY_SCALE;
            	    } else if(tmpxz < tmpyz) {
                    	tmpxz = G_NINT((((float)tmpxz)/(float)tmpyz)*(float)XY_SCALE);
                    	tmpyz = XY_SCALE;
            	    } else {
                    	tmpxz = XY_SCALE;
                    	tmpyz = XY_SCALE;
            	    }
        	}
        	tmpxz = (tmpxz < G_NINT(0.1F*(float)XY_SCALE)) ? G_NINT(0.1F*(float)XY_SCALE) 
						      : tmpxz;
        	tmpyz = (tmpyz < G_NINT(0.1F*(float)XY_SCALE)) ? G_NINT(0.1F*(float)XY_SCALE) 
						      : tmpyz;

/*
 *    	        Set the global CGM frame size
 */
        	fxsize = (unsigned short)tmpxz;
        	fysize = (unsigned short)tmpyz;;

/*
 *      	ileft  = left device coordinate
 *      	ibot   = bottom device coordinate
 *      	iright = right device coordinate
 *      	itop   = top device coordinate
 */
        	*ileft  = 0;
        	*ibot   = 0;
        	*iright = tmpxz;
        	*itop   = tmpyz;
	    }
	}
}
Exemple #14
0
void cvg_redraw ( char *fname, int *iret )
/************************************************************************
 * cvg_redraw								*
 *									*
 * This function re-displays all records in a given VG file. If no file	*
 * name is given, records in WORK_FILE will be redrawn.			*
 *									*
 * cvg_redraw  ( fname, iret )						*
 *									*
 * Input parameters:							*
 *	*fname		char		File name to redraw from	*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *					 -1 = error opening VG file	*
 *					 -2 = error closing VG file	*
 **									*
 * Log:									*
 * J. Wu/SAIC           12/01   modify from cvg_rfrsh()			*
 * J. Wu/SAIC           02/02   add layering with cvg_drawLayer()	*
 * J. Wu/SAIC           03/02   change loop max. from 2 to MAX_LAYERS	*
 * J. Wu/SAIC           03/02   set proper color/fill mode for redraw	*
 * E. Safford/SAIC	03/02	rm the display-on check for cur layer	*
 * T. Lee/SAIC          11/03   added user directory to work_file       *
 * T. Lee/SAIC		11/03	used cvgcmn.h				*
 * S. Danz/AWC		08/06	Call cvg_rebuildplace to update placement	*
 *							before the redraw in case the device changed*
 ***********************************************************************/
{
    int 		ii, ier, icol, ifill, cur_layer;
    long		maxbytes;
    char		newfil[256], reqfil[256];
    FILE		*fp;
/*---------------------------------------------------------------------*/
    
    *iret = 0;

    cur_layer = pglayer_getCurLayer ();
    
    if (!fname)
	strcpy( reqfil, work_file );
    else
 	strcpy( reqfil, fname );

    /*
     * Update the placement info
     */
    cvg_rebuildplace(fname, &ier);

    /* 
     *  Open the specified file or WORK_FILE if it exists.
     */
    cfl_inqr( reqfil, NULL, &maxbytes, newfil, &ier );

    /*
     *  If empty file just return, otherwise, attempt to open the file.
     *  Report an error if applicable.
     */
    if (maxbytes == 0) {
        return;
    }
    else {
	fp = (FILE *) cfl_ropn( newfil, NULL, &ier );
	if ( ( ier != 0 ) || ( fp == NULL ) ) {
	    *iret = -1;
	    return;
	}
    }

    /*
     *  Draw elements layer by layer except those on the current layer.       
     */
    for ( ii = 0; ii < MAX_LAYERS; ii++ ) {
        			
        icol = 0;
        ifill = G_TRUE;

	/*
	 *  skip current layer, layers not in use or dsply_on is off.
	 */ 	
	if ( ii == cur_layer || ( !pglayer_getInUse(ii) ) || 
	                        ( !pglayer_getDsplOn(ii) ) ) {
	    continue;
	}
	
	/*
	 *  Set required color & fill mode.
	 */ 	
	if ( !pglayer_getDsplClr(ii) )  icol = pglayer_getMonoClr ( ii );
	
	if ( !pglayer_getFill(ii) )  ifill = G_FALSE;

	cds_scol ( icol, iret );
	cds_sfill ( &ifill, &ier );
	
	/*
	 *  Draw elements.
	 */
	cvg_drawLayer ( fp, newfil, ii, (int)maxbytes, &ier );
		 
    }


    /*
     *  Always draw elements on the current layer in full color &
     *  fill mode if its dspl_on flag is on.       
     */
    icol = 0;
    ifill = G_TRUE;
    cds_scol ( icol, iret );
    cds_sfill ( &ifill, &ier );
    cvg_drawLayer ( fp, newfil, cur_layer, (int)maxbytes, &ier ); 


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

    geplot(&ier);

}
Exemple #15
0
void vfgttxt ( char fname[], int *iret )
/************************************************************************
 * vfgttxt                                                              *
 *                                                                      *
 * This function gets and reads the ww----.txt file information which   *
 * is used to create SEL, SAW, SEV and the cancel text products for     *
 * SAW and SEL.                                                         *
 *                                                                      *
 * vfgttxt ( fname, iret )						*
 *                                                                      *
 * Input parameters:                                                    *
 *      fname[]		char		Input File Name                 *
 *									*
 * Output parameters:                                                   *
 *      *iret            int            Return Code                     *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * A. Hardy/GSC          2/00	Created					*
 * A. Hardy/GSC          5/00	Removed 'file not found' statement      *
 * A. Hardy/GSC         12/00	Removed '&' from iret			*
 ***********************************************************************/
{
    int          ierr;
/*---------------------------------------------------------------------*/
    *iret = 0;

   /*
    * Store the text filename.
    */

    strcpy ( spcinfo.file_info.filnam, fname );

   /*
    * Open text file to be read.
    */
    spcinfo.file_info.ifp = cfl_ropn(
	                  spcinfo.file_info.filnam, NULL, &ierr);
			  
    *iret = ierr;
    if ( *iret == 0 ) {
       /*
        * Read in verification file.
        */

        vfread ( iret );

       /*
        * Close text file.
        */

         cfl_clos ( spcinfo.file_info.ifp, iret );
         spcinfo.file_info.ifp = NULL;
    }
    /*
     * If the WW filename is incorrect, send an error.
     */
    else {
	 *iret = -1;
    }
}
Exemple #16
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;
	}
}
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);


}
Exemple #18
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);

}
Exemple #19
0
void spf_open ( char *filnam, Boolean crt, FILE **fptr, int *flen, int *iret )
/************************************************************************
 * spf_open								*
 *									*
 * This function opens an SPF file for update. If the file doesn't 	*
 * exist and flag "crt" is TRUE, then it will be created. If the file   *
 * suffix is not ".spf", it will be added. If the user has only read    *
 * permission to the SPF file, it will be opened as "read-only".	*
 *									*
 * spf_open ( filnam, crt, fptr, flen, iret )				*
 *									*
 * Input parameters:							*
 *      *filnam		char		File name with full path	*
 *      crt		Boolean		Flag, create a new file or not	*
 *									*
 * Output parameters:							*
 *      **fptr		FILE		Pointer to a file pointer	*
 *      *flen		int		File size			*
 *	*iret		int		Return code			*
 *					1 - File opened as READ_ONLY	*
 *					0 - Normal 			*
 *				       -1 - File does not exist		*
 *				       -2 - File cannot be opened	*
 *				       -3 - Failure to create SPF file	*
 *									*
 **									*
 * Log:									*
 * J. Wu/GSC		6/01	create					*
 * J. Wu/GSC		6/01	use cst_srch()				*
 * J. Wu/GSC		7/01	allow access to read-only SPF files	*
 * E. Safford/SAIC	02/06	fix cfl_inqr call, make 3rd param long  *
 ***********************************************************************/
{
    int	    ipos, ier, ierr;
    char    newfil[FILE_FULLSZ];
    char    filepart[MXFLSZ], pathpart[LLPATH];
    long    localFlen; 
/*---------------------------------------------------------------------*/

    *iret = G_NORMAL;
    *flen = 0;
       
    /*
     *  Check if the file suffix is ".spf". If not, add it. 
     */
    cfl_path ( filnam, pathpart, filepart, &ier ) ;   
    cst_srch ( 0, strlen(filepart), ".spf", filepart, &ipos, &ier );
    if ( ier == -4 ) {
        strcat (filnam, ".spf");
    }
    
    /*
     *  Check the file status, if it exists, open it; otherwise, create
     *  it if authorized. 
     */ 
    cfl_inqr( filnam, NULL, &localFlen, newfil, &ier ); 
    *flen = ( int ) localFlen;

    if ( ier == 0 ) { 

        *fptr = cfl_aopn( filnam, &ierr );
            
	if ( *fptr == NULL ) {
                
            *fptr = cfl_ropn( filnam, NULL, &ierr );
	    
	    if ( *fptr == NULL ) {
	        *iret = -2;
	        er_wmsg ( "CFL", &ierr, filnam, &ier, 3, strlen( filnam ) );
	    }
	    else {
	       *iret = 1; 
	    }
	
	}    

    }
    else {
    
        *iret = -1;
	
	if ( crt == TRUE ) {
       
            *fptr = ( FILE *) spf_create( filnam, flen, iret ); 
	     	
	}
	         
    }
               
}
Exemple #20
0
int main ( int argc, char **argv )
/************************************************************************
 * mdp									*
 *                                                                      *
 * This program generates the mesoscale discussion latlon pairings.	*
 * Pairings will be written to a file whose filename is based on the	*
 * input filename (filename extension, if exists, is replaced w/ "mdp").*
 *                                                                      *
 * Example:								*
 * mdp input_vgf_file.vgf						*
 * Produces latlon pairings in the ASCII file				*
 * output_vgf_file.mdp							*
 *                                                                      *
 * main(argc, argv)                                                     *
 *                                                                      *
 * Input parameters:                                                    *
 *  argc   int      number of parameters of command line                *
 *  argv   char**   parameter array of command line                     *
 *                                                                      *
 * Output parameters:                                                   *
 * Return parameters:                                                   *
 *                      NONE                                            *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * D.W.Plummer/NCEP	 6/02						*
 * D.W.Plummer/NCEP	 8/02	Bug fix for lons > 99.995 and < 100.0	*
 * G. Grosshans/SPC	11/02	Updated to decode multi-scalloped lines *
 * G. Grosshans/SPC	12/02	Updated to compute WFO/State		*
 * S. Jacobs/NCEP	 5/03	Clean up unused variables and headers	*
 * G. Grosshans/SPC     10/03   Updated for precision                   *
 * T. Piper/SAIC	12/05	Updated cst_wrap for CSC		*
 * J. Wu/SAIC		04/06	Added parameter in cst_wrap 		*
 * G. Grosshans/SPC	08/08	Updated for SCN 08-45 to add LAT...LON  *
 * 				and list first point as last point      *
 * 				to indicate a closed polygon.  Add      *
 *				word wrapping for ATTN...WFO...		*
 ***********************************************************************/
{
int		ii, ix, iy, ixfirst, iyfirst, pagflg, ne, ilen,
	        npts, ier, iret, nitems, more, curpos;

long		ifilesize;

float		x, y, flat[MAXLISTITEMS], flon[MAXLISTITEMS];

char		vg_class, vg_type, buffer[2048], bufferfinal[2048],
		bufferfinalwfo[2048],str[20], *cptr, errgrp[12], infile[128],
		ifname[128], outfile[128], info[2048], stpo[4],
		cstl_list[1000], cstl_liststate[1000],
		newLineStr[13]="            "; /* 13 spaces */

char		blank[2]={' '}, device[13], dfilnam[73], pro[80];
int		mode, istat, iunit, itype;
float		xsize, ysize, lllat, lllon, urlat, urlon,
		prjang1, prjang2, prjang3;

VG_DBStruct	el;

FILE		*ifptr, *ofptr;

const int line_len = 66;

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

    /* 
     * Set defaults for gsdeva and gsmprj
     */
    mode = 1;
    strcpy ( device, "GN" );
    iunit = 1;
    strcpy ( dfilnam, "MDPSPC" );
    itype = 1;
    xsize = 500.0F;
    ysize = 500.0F;
    lllat = 10.0F;
    lllon = -120.0F;
    urlat = 50.0F;
    urlon = -50.0F;
    strcpy ( pro, "str" );
    prjang1 =   90.0F;
    prjang2 = -105.0F;
    prjang3 =    0.0F;
    cstl_list[0] = '\0';
    cstl_liststate[0] = '\0';

    in_bdta ( &ier );
    ginitp ( &mode, &istat, &ier);
    gsdeva (device, &iunit, dfilnam, &itype, &xsize, &ysize, &iret,
	    strlen(device), strlen(dfilnam));
    gsmprj ( pro, &prjang1, &prjang2, &prjang3, 
	     &lllat, &lllon, &urlat, &urlon, &iret, strlen(pro));
    clo_init ( &ier );

    /*
     *  Check if number of input arguments is correct.
     */
    if ( argc < 2 )  {
	pagflg = G_FALSE;
	strcpy ( errgrp, "MDPSPC" );
        ip_help ( errgrp, &pagflg, &ier,
                  strlen(errgrp) );
	gendp (&mode, &ier);
	exit (0);
    }

    /*
     *  First input on command line is input vgf file name.
     */
    strcpy ( infile, argv[1] );
    cfl_inqr ( infile, NULL, &ifilesize, ifname, &ier );
    ifptr = (FILE *) cfl_ropn(ifname, "", &ier);
    if ( ier != 0 )  {
	printf("Error opening VGF file %s\n", infile );
	gendp (&mode, &ier);
	exit (0);
    }

    /*
     *  Output filename is input filename w/ "mdp" filename extension.
     */
    strcpy ( outfile, infile );
    cptr = strrchr( outfile, '.' );
    if ( cptr != (char *)NULL )  {
	cptr[0] = '\0';
    }
    strcat( outfile, ".mdp" );
    
    /*
     *  Loop through all the elements until a line is found.
     */
    ne = 0;
    more = G_TRUE;
    curpos = 0;
    buffer[0] = '\0';
    bufferfinal[0] = '\0';
    bufferfinalwfo[0] = '\0';
    strcat ( buffer, "LAT...LON   " );
    while ( ne < MAX_EDITABLE_ELEMS && more == G_TRUE )  {
	cvg_rdrecnoc( ifname, ifptr, curpos, &el, &ier );

	if ( ier < 0 )  {
	    more = G_FALSE;
	}
	else  {

	    curpos += el.hdr.recsz;

	    vg_class = el.hdr.vg_class;
	    vg_type  = el.hdr.vg_type;

            if ( ( (int)vg_class == CLASS_LINES ) &&
	    	 ( el.hdr.vg_type == SPLN_ELM ) &&
		 ( (int)el.elem.spl.info.spltyp == 3 ) )  {

		/*
		 *  Open output file.
		 */
		ofptr = (FILE *)cfl_wopn ( outfile, &ier );
		if ( ier != 0 )  {
		    printf("Error opening/creating output file %s\n",
		    	    outfile );
	            gendp (&mode, &ier);
		    exit (0);
    		}

	       /*
		* Find FIPS bounded by the closed line
		*/

		npts = el.elem.spl.info.numpts;

		/*  FIND WHAT STATES ARE IN MD AREA */

		clo_binpoly ( "CNTY_BNDS", npts, el.elem.spl.latlon,
                              &(el.elem.spl.latlon[npts]), &ier );
		clo_tgltln ( "CNTY_BNDS", MAXLISTITEMS, &nitems,
			      flat, flon, &ier);

		for ( ii = 0; ii < nitems; ii++ )  {
		  clo_bginfo( "CNTY_BNDS", ii, info, &ier );
		  cst_gtag( "STATE", info, "?", stpo, &ier);
		  
		  if (strstr(cstl_liststate, stpo)==NULL) {
		    strcat(cstl_liststate, stpo);
		    strcat(cstl_liststate, " ");		  
		  }
		}


		/*  FIND WHAT WFOs ARE IN MD AREA */
		clo_binpoly ( "CWA_BNDS", npts, el.elem.spl.latlon,
                              &(el.elem.spl.latlon[el.elem.spl.info.numpts]),
			      &ier );
		clo_tgltln ( "CWA_BNDS", MAXLISTITEMS, &nitems,
			      flat, flon, &ier);

		for ( ii = 0; ii < nitems; ii++ )  {
		  clo_bginfo( "CWA_BNDS", ii, info, &ier );
		  cst_gtag( "WFO", info, "?", stpo, &ier);
		  strcat(cstl_list, stpo);
		  strcat(cstl_list, "...");		  
		}

		/*
		 *  Format lats and lons into buffer.
		 */
		if ( (int)vg_type == LINE_ELM )  {
		    npts = el.elem.lin.info.numpts;
		}
		else if ( (int)vg_type == SPLN_ELM )  {
		    npts = el.elem.spl.info.numpts;
		}
		for ( ii = 0; ii < npts; ii++ )  {
		    if ( (int)vg_type == LINE_ELM )  {
		        x = el.elem.lin.latlon[ii];
		        y = -el.elem.lin.latlon[ii+npts];
		    }
		    else if ( (int)vg_type == SPLN_ELM )  {
		        x = el.elem.spl.latlon[ii];
		        y = -el.elem.spl.latlon[ii+npts];
		    }
		    /*
		     * Make sure lats and lons are rounded
		     * to 100ths of deg.
		     */
		    x = ((int)(x*100.0F)) / 100.0F;
		    y = ((int)(y*100.0F)) / 100.0F;
		    if ( y >= 100.0F )  y -= 100.0F;
		    ix = G_NINT(x*100.0F);
		    iy = G_NINT(y*100.0F);
		    sprintf( str, "%04d%04d ", ix, iy );
		    strcat ( buffer, str );
		    if ( ii == 0 ) {
                        ixfirst = ix;
			iyfirst = iy;
                    }
		}
		/*
		 *   Repeat first lat/lon point as last lat/lon point 
		 *   to indicate a closed polygon.
		 */


		sprintf( str, "%04d%04d ", ixfirst, iyfirst);
		strcat ( buffer, str );

		sprintf( str, "\n\n" );
		strcat ( buffer, str );

		/*
		 *  Wrap buffer such that only 6 pairs of lat,lons 
		 *  on one line.
		 *  ilen = 55;
		 *  cst_wrap( buffer, blank, &ilen, "\n", (char *)NULL, buffer, &ier );
		 */
		ilen = 66;
		cst_wrap( buffer, blank, &ilen, "\n", newLineStr, buffer, &ier );

	    }

	}
	ne++;
    }

    /*
     * wrap the ATTN...WFO... line
     */
    strcat ( bufferfinalwfo, "ATTN...WFO..." );
    strcat ( bufferfinalwfo, cstl_list );
    cst_wrap( bufferfinalwfo, "...", &line_len, "\n", (char *)NULL, bufferfinalwfo, &ier );

    /*
     * build the output file string and add the ATTN...WFO... string
     */
    strcat ( bufferfinal,"STATES=" );
    strcat ( bufferfinal, cstl_liststate );
    strcat ( bufferfinal, "\n\n" );
    strcat ( bufferfinal, bufferfinalwfo );
/*
    strcat ( bufferfinal,"ATTN...WFO..." );
    strcat ( bufferfinal, cstl_list );
*/
    strcat ( bufferfinal, "\n\n" );
    strcat ( bufferfinal, buffer );

    /*
     *  Write to output file.
     */
    cfl_writ ( ofptr, (int)strlen(bufferfinal),
    	       (unsigned char *)bufferfinal, &ier );

    /*
     *  close files and exit.
     */
    cfl_clos ( ifptr, &ier );
    cfl_clos ( ofptr, &ier );
    gendp (&mode, &ier);
    return(0);

}