Пример #1
0
static void tbl_usst ( shp_record *shprec, int numrec, int *iret )
/************************************************************************
 * tbl_usst                                                             *
 *                                                                      *
 * This function creates the us state and territories table files.	*
 *                                                                      *
 * tbl_usst ( shprec, numrec, iret )                            	*
 *                                                                      *
 * Input parameters:                                                    *
 *      *shprec         shp_record  	Shape record list		*
 *	numrec		int		Total number of records		*
 *                                                                      *
 * Output parameters:                                                   *
 *      *iret           int             Return code                     *
 *                                        0 = Normal                    *
 **                                                                     *
 * Log:                                                                 *
 * R. Tian/SAIC          6/04   	Initial coding                  *
 ***********************************************************************/
{
    shp_record *currec;
    /*
     * The array size is from the US State and Territories
     * specification.
     */
    char stabbr[3], stname[25];
    int rec, ifld, len, ier;
    char *tblnam = STATETBL;
    FILE *tblfp;
/*---------------------------------------------------------------------*/
    *iret = 0;

    tblfp = cfl_wopn ( tblnam, &ier );
    if ( ier != 0 ) {
        fprintf ( stderr, "File %s open failed.\n", tblnam );
        exit ( -1 );
    }

    for ( currec = shprec, rec = 0; rec < numrec;
        rec++, currec = currec->nxtrec ) {

        for ( ifld = 0; ifld < currec->numfld; ifld++ ) {
            if ( strncmp ( currec->fields[ifld].name, "STATE",
	        strlen("STATE") ) == 0 ) {
		strncpy ( stabbr, currec->fields[ifld].data, 2 );
		stabbr[2] = '\0';
            } else if ( strncmp ( currec->fields[ifld].name, "NAME",
	        strlen("NAME") ) == 0 ) {
		strcpy ( stname, currec->fields[ifld].data );
		cst_lstr ( stname, &len, &ier );
		stname[len] = '\0';
	    }
	}

        fprintf ( tblfp, "%2.2s %s\n", stabbr, stname );
    }

    cfl_clos ( tblfp, &ier );
}
Пример #2
0
static void bnd_iedg ( shp_record *onerec, char *header, char *subhdr,
                  char *hdrnam, float *cenlat, float *cenlon, int *iret )
/************************************************************************
 * bnd_iedg                                                             *
 *                                                                      *
 * This function generates the ice edge bound header and sub-header	*
 * lines 								*
 *                                                                      *
 * bnd_iedg ( onerec, header, subhdr, hdrnam, cenlat, cenlon, iret )    *
 *                                                                      *
 * Input parameters:                                                    *
 *      *onerec         shp_record      One shape record               	*
 *                                                                      *
 * Output parameters:                                                   *
 *	*header		char		Bound header line		*
 *	*subhdr		char		Bound sub-header line		*
 *	*hdrnam		char		Bound header name    		*
 *	*cenlat		float		Center latitude			*
 *	*cenlon		float 		Center longitude		*
 *      *iret           int             Return code                     *
 *                                        0 = Normal                    *
 *                                        1 = Incomplete record         *
 **                                                                     *
 * Log:                                                                 *
 * R. Tian/SAIC          3/04           Initial coding                  *
 ***********************************************************************/
{
    /*
     * The array size is from the Ice Edge attributes specification.
     */
    char icecod[120], icenam[15];
    int iclat, iclon, nparts, ifld, len, ier;
    static int seqnum = 0;
/*---------------------------------------------------------------------*/
    *iret = 0;

    seqnum++;
    nparts = onerec->numprt;
    for ( ifld = 0; ifld < onerec->numfld; ifld++ ) {
        if ( strncmp ( onerec->fields[ifld].name, "ICECODE",
	    strlen("ICECODE") ) == 0 ) {
	    strcpy ( icecod, onerec->fields[ifld].data );
	    cst_lstr ( icecod, &len, &ier );
	    icecod[len] = '\0';
        }
    }

    sprintf ( icenam, "ICE_EDGE_%5.5d", seqnum );
    iclat = (int)(ROUNDUP(onerec->cenlat)*100.);
    iclon = (int)(ROUNDUP(onerec->cenlon)*100.);
    *cenlat = onerec->cenlat;
    *cenlon = onerec->cenlon;

    sprintf ( header, "B%5.5d %-32.32s %5d %6d %3d %s",
              seqnum, icenam, iclat, iclon, nparts, icenam );
    sprintf ( subhdr, "<NUM>%d<ICECODE>%s", seqnum, icecod );
    sprintf ( hdrnam, "%s", icenam );
}
Пример #3
0
void wbc_mzrm ( char *states, char *ststr, int *len1, int *iret )
/************************************************************************
 * wbc_mzrm								*
 *                                                                      *
 * This function removes the specific marine zones listed above from	*
 * the state id string. 						*
 *                                                                      *
 * wbc_mzrm ( states, len1, len2, stzstr, sttstr, iret )		*
 *                                                                      *
 * Input parameters:                                                    *
 *	*states		char		String of state ids		*
 *                                                                      *
 * Output parameters:                                                   *
 *	*ststr		char		States id string; no Mar. Zones *
 *	*len1		int		Length of ststr			*
 *      *iret           int		Return Code                     *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * A. Hardy/NCEP          5/03						*
 * A. Hardy/NCEP          9/04		Added "SL"			*
 * T. Piper/SAIC	02/05	Removed unused variable 'stnam'		*
 ***********************************************************************/
{
    int     ii, ier, ilen, ipos;
/*-------------------------------------------------------------------*/
    *iret = 0;
    ier   = 0;
    ststr[0] = '\0';

   /*
    * Remove unwanted marine zones listed above from state strings.
    */

    ii = 0;

    while ( ( ii <  NUM_ZNS ) ) {
	cst_rmst ( states, _mzones[ii], &ipos, states, &ier);
	if ( ipos > 0 ) {
            cst_rxbl ( states, states, &ilen, &ier);
	}
	ii++;
    }

    cst_lstr ( states, &ilen, &ier );
    cst_ncpy ( ststr, states, ilen, &ier );
}
Пример #4
0
void bfr_make ( char *ofname, int nfxy, int *fxy_i, float *values,
               int num_vals, int jtime[], Data_MixVal_t *values_mx,
               int idcent, int info_bufr[], char *section2, int *iret ) 
/************************************************************************
 * bfr_make                                                             *
 *                                                                      *
 * This subroutine uses input values and associated descriptors to      *
 * create and output a BUFR message.  It can handle data of type float  *
 * or mixed type data.                                                  *
 *                                                                      *
 * bfr_make ( ofname, nfxy, fxy_i, values, num_vals, jtime, values_mx,  *
 *           idcent, info_bufr, section2, iret )			*
 *                                                                      *
 * Input parameters:                                                    *
 *	*ofname		char	   Output BUFR file name.               *
 *      nfxy		int	   Number of FXYs (descriptors)         *
 *	*fxy_i		int	   Array of decimal FXYs                *
 *	*values		float	   Array of data values (of type float) *
 *	num_vals	int	   Number of data values                *
 *      jtime[]		int	   Forecasted date/time 		*
 *	*values_mx   Data_MixVal_t Array of data values (of mixed type) *
 *	idcent		int	   Originating center id		*
 *	info_bufr[]	int	   BUFR initialization values		*
 *	*section2	char	   Section2 SWM area string		*
 *                                                                      *
 * Output parameters:                                                   *
 *      *iret           int        Return code                      	*
 *				     1 = BUFR message not output        *
 *				     0 = normal return                  *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * D. Kidwell/NCEP   9/03	Extracted from SIGBENC sige routines    *
 * M. Li/SAIC	    10/04	Added idcent, info_bufr and section2	*
 * S. Jacobs/NCEP   10/04	Updated for new verion of MELBUFR	*
 * M. Li/SAIC	    03/05	Added a check for idcent		*
 ***********************************************************************/
{
    BUFR_Info_t bufr_info;  	/* Largely Section 1 information. */
    FXY_t 	*fxy;     	/* array of packed FXYs */


    int   	ii, nc, lpend, lens, ier;

    int		numerr, leverr; 
    char 	errgrp[8], cc[50];
/*---------------------------------------------------------------------*/
     *iret   = 0;
     leverr  = 0;
     strcpy ( errgrp, "BFR" );
     strcpy ( cc, " " );

    /* 
     * Initialize the BUFR information structure. 
     * This function sets all of the default values for using
     * the MELBUFR library.
     */

     if( BUFR_Info_Init( &bufr_info ) ) {
	 numerr = -4;
	 er_lmsg ( &leverr, errgrp, &numerr, cc, &ier,
	           strlen(errgrp), strlen(cc) );
         *iret = 1;
         return;
     }
    
    /* 
     * Allocate memory for packed FXYs.
     */

     fxy = (FXY_t *) malloc(sizeof(FXY_t ) * (uint_t)nfxy);
    
    /*
     * Initialize the section one data.
     */

     if ( idcent == IMISSD ) {
	 bufr_info.OriginatingCenter       =  7;
     }
     else {
         bufr_info.OriginatingCenter	   =  idcent;
     }
     bufr_info.MinorLocalVersion           =  0;
     bufr_info.BUFR_MasterTable            =  info_bufr[0]; 
     bufr_info.BUFR_Edition                =  info_bufr[1];  
     bufr_info.UpdateSequenceNumber        =  info_bufr[2]; 
     bufr_info.DataCategory                =  info_bufr[3];
     bufr_info.DataSubCategory             =  info_bufr[4];
     bufr_info.VersionNumberOfMasterTables =  info_bufr[5];
     bufr_info.VersionNumberOfLocalTables  =  info_bufr[6];
     bufr_info.ObservedData                =  info_bufr[7];;

     bufr_info.Year                        =  jtime[0]%100;
     bufr_info.Month                       =  jtime[1];
     bufr_info.Day                         =  jtime[2];
     bufr_info.Hour                        =  jtime[3];
     bufr_info.Minute                      =  jtime[4];

    /*
     * Set trace and debug levels.
     BUFR_Trace( 10 );
     BUFR_Debug( 10 );
     */

    /* 
     * Initialize BUFR message.  Read standard tables. 
     */

     if( BUFR_Init(&bufr_info, ofname, ENCODING) ) {
         *iret = 1;
	 BUFR_perror( "main" );
	 numerr = -8;
	 er_lmsg ( &leverr, errgrp, &numerr, ofname, &ier,
		   strlen(errgrp), strlen(ofname) );
     }

    /*
     * Write out section2.
     */

     cst_lstr ( section2, &nc, &ier );
     if ( nc > 0 ) {
	 lens = strlen (section2);
	 if ( (lens % 60) != 0 ) { 
	     lpend = ( ( lens / 60 ) + 1 ) * 60;
	     cst_padString ( section2, ' ', 1, lpend, section2 );
	 }

     	 if ( BUFR_Put_OptionalData ( section2, strlen(section2) ) ){
	     numerr = -13;
	     er_lmsg ( &leverr, errgrp, &numerr, cc, &ier,
                   strlen(errgrp), strlen(cc) );
	 } 
     }

    /* 
     * Pack FXYs for data. 
     *
     * Pack replication FXY using delayed replication, therefore the 
     * replication count is in the data array.  The FXY for delayed 
     * replication of, for instance, 4 FXYs is 1-04-000.  The 000 
     * indicates delayed replication.  The delayed replication FXY 
     * must be followed by a count descriptor (0-31-001 or 0-31-002).  
     *
     */

     for ( ii = 0; ii < nfxy; ii++) {
         fxy[ii] = FXY_Pack_Dec( fxy_i[ii]);
     }

    /* 
     * Enter data array into bufr message. 
     */

     if ( !G_DIFF(values[0], (float)BUFR_MISSING_VALUE) ) {

        /*
         * Data is not of mixed type.
         */

         if ( BUFR_Put_Array( values, num_vals, DT_FLOAT, fxy, nfxy) ) {
	     numerr = -5;
             *iret = 1;
         }
     }
     else {     

        /*
         * Data is of mixed type - e.g., storm, volcano and radiation 
	 * event data for high level sig weather.
         */

         if ( BUFR_Put_MixArray( values_mx, num_vals, fxy, nfxy) ) {
             numerr = -11;
             *iret = 1;
         }
     }

    /* 
     * Create BUFR message. 
     */

     if ( *iret != 1 ) {
         if ( BUFR_Encode( &bufr_info ) ) {
	     BUFR_perror( "main" );
	     numerr = -9;
	     er_lmsg ( &leverr, errgrp, &numerr, ofname, &ier,
		       strlen(errgrp), strlen(ofname) );
             *iret = 1;
         }
     }
     else {
         er_lmsg ( &leverr, errgrp, &numerr, cc, &ier,
		   strlen(errgrp), strlen(cc) );
     }

     free (fxy);
     BUFR_Destroy(1);

     return;
}
Пример #5
0
void dg_pfun ( const char *func, int *iret )
/************************************************************************
 * dg_pfun								*
 *									*
 * This subroutine parses a diagnostic function entered by the user.	*
 * The output is returned in the diagnostic function tables.  In-line	*
 * parameters may be appended to an operand in any combination.  The	*
 * flags are:								*
 *									*
 *     Parameter:   time   level   ivcord				*
 *     Flag:         ^       @       %					*
 *									*
 * dg_pfun ( func, iret )						*
 *									*
 * Input parameters:							*
 *	*func		const char	Input function			*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *				  	  0 = normal return		*
 **									*
 * Log:									*
 * M. desJardins/GSFC	10/85						*
 * J. Nielsen/MIT	 4/88	Added ^ and & 				*
 * M. desJardins/GSFC	 7/88	Added %; changed & to @ for TAE		*
 * K. Brill/GSC 	 9/89   Addd +					*
 * K. Brill/NMC		 5/93	Assume FUNC is already upper case	*
 * M. desJardins/NMC	 8/93	Use MMFILE as maximum number of files	*
 * S. Jacobs/EAI	 9/93	Fixed typo				*
 * P. Bruehl/Unidata     8/94   Increased dimension on f from 20 to 36	*
 *				to allow for grids w/ 2 times after "^"	*
 * T. Piper/GSC		 7/01	Fixed typo f*30 -> f*36			*
 * m.gamazaychikov/SAIC	09/05	Added call to ST_NARG			*
 * R. Tian/SAIC		 2/06	Recoded from Fortran			*
 ************************************************************************/
{
    char f[37], c, dfunc[133];
    int dtm, lev, vcr, fil;
    int nf, iend, ival, ier, i;
/*----------------------------------------------------------------------*/
    /*
     * Initialize variables.
     */
    *iret  = 0;
    _dgtabl.ltabl = -1;
    memset ( f, 0, sizeof(f) );
    nf = 0;
    strcpy ( dfunc, func );
    cst_lstr ( dfunc, &iend, &ier );

    /*
     * First replace brackets with parentheses and semicolons with commas.
     * Brackets and semicolons may be used to make the function easier to
     * enter in the TAE tutor.
     */
    for ( i = 0;  i < iend; i++ ) {
	c  =  dfunc[i];
	if ( c == '[' ) dfunc[i] = '(';
	if ( c == ']' ) dfunc[i] = ')';
	if ( c == ';' ) dfunc[i] = ',';
    }

    /*
     * Loop through input string checking each character.
     */
    dtm = G_FALSE;
    lev = G_FALSE;
    vcr = G_FALSE;
    fil = G_FALSE;

    for ( i = 0; i < iend; i++ ) {
	c = dfunc[i];

	if ( c == ' ' ) {
	    /*
	     * Do nothing for blanks.
	     */
	} else if ( c == '(' ) {
	    /*
	     * Left parentheses, (, indicate the end of a function.
	     */
	    if ( nf != 0 ) {
		_dgtabl.ltabl++;
	        strcpy ( _dgtabl.ctabl[_dgtabl.ltabl], "*" );
		strcat ( _dgtabl.ctabl[_dgtabl.ltabl], f );
		cst_narg ( dfunc, i, ',', &_dgtabl.nfargs[_dgtabl.ltabl], &ier );
    		memset ( f, 0, sizeof(f) );
		nf = 0;
	    }


	} else if ( ( c == ')' ) || ( c == ',' ) || ( c == '%' ) ||
	            ( c == '^' ) || ( c == '@' ) || ( c == '+' ) ) {
	    /*
	     * Right parentheses, ), or commas indicate end of a parm.
	     * %, ^, @, + flag end of parm and beginning of vcord, time
	     * level or file number.
	     */
	    if ( nf != 0 ) {
		if ( dtm == G_TRUE ) {
		    if ( _dgtabl.ltabl > -1 ) {
		        strcpy ( _dgtabl.cgdttm[_dgtabl.ltabl], f );
		    }
		    dtm = G_FALSE;
		} else if ( lev == G_TRUE ) {
		    if ( _dgtabl.ltabl > -1 ) {
		        strcpy ( _dgtabl.clevel[_dgtabl.ltabl], f );
		    }
		    lev = G_FALSE;
		} else if ( vcr == G_TRUE ) {
		    if ( _dgtabl.ltabl > -1 ) {
		        strcpy ( _dgtabl.cvcord[_dgtabl.ltabl], f );
		    }
		    vcr = G_FALSE;
		} else if ( fil == G_TRUE ) {
		    if ( _dgtabl.ltabl >= 0 ) {
			cst_numb ( f, &ival, &ier );
			if ( ( ival > 0 ) && ( ival <= MMFILE ) ) {
			    _dgtabl.icflnm[_dgtabl.ltabl] = ival;
			}
		    }
		    fil = G_FALSE;
		} else {
		    _dgtabl.ltabl++;
		    strcpy ( _dgtabl.ctabl[_dgtabl.ltabl], f );
		    _dgtabl.nfargs[_dgtabl.ltabl] = 0;
		    _dgtabl.clevel[_dgtabl.ltabl][0] = '\0';
		    _dgtabl.cvcord[_dgtabl.ltabl][0] = '\0';
		    strcpy ( _dgtabl.cgdttm[_dgtabl.ltabl], _dginpt.ingdtm );
		    _dgtabl.icflnm[_dgtabl.ltabl] = 1;
		}
    		memset ( f, 0, sizeof(f) );
		nf = 0;
		if ( c == '%' )  vcr = G_TRUE;
		if ( c == '^' )  dtm = G_TRUE;
		if ( c == '@' )  lev = G_TRUE;
		if ( c == '+' )  fil = G_TRUE;
	    }
	} else if ( i == iend - 1) {
	    /*
	     * At end of function, check for single parameter.
	     */
	    f[nf++] = c;
	    if ( dtm == G_TRUE ) {
		if ( _dgtabl.ltabl > -1 ) {
		    strcpy ( _dgtabl.cgdttm[_dgtabl.ltabl], f );
		}
		dtm = G_FALSE;
	    } else if ( lev == G_TRUE ) {
		if ( _dgtabl.ltabl > -1 ) {
		    strcpy ( _dgtabl.clevel[_dgtabl.ltabl], f );
		}
		lev = G_FALSE;
	    } else if ( vcr == G_TRUE ) {
		if ( _dgtabl.ltabl > -1 ) {
		    strcpy ( _dgtabl.cvcord[_dgtabl.ltabl], f );
		}
		vcr = G_FALSE;
	    } else if ( fil == G_TRUE ) {
		if ( _dgtabl.ltabl > -1 ) {
		    cst_numb ( f, &ival, &ier );
		    if ( ( ival > 0 ) && ( ival <= MMFILE ) ) {
			_dgtabl.icflnm[_dgtabl.ltabl] = ival;
		    }
		}
		fil = G_FALSE;
	    } else {
		_dgtabl.ltabl++;
		strcpy ( _dgtabl.ctabl[_dgtabl.ltabl], f );
		_dgtabl.nfargs[_dgtabl.ltabl] = 0;
		_dgtabl.clevel[_dgtabl.ltabl][0] = '\0';
		_dgtabl.cvcord[_dgtabl.ltabl][0] = '\0';
		strcpy ( _dgtabl.cgdttm[_dgtabl.ltabl], _dginpt.ingdtm );
		_dgtabl.icflnm[_dgtabl.ltabl] = 1;
	    }
	} else {
	    /*
	     * Otherwise, add this character to the function name.
	     */
	    f[nf++] = c;
	}
    }

    /*
     * Compute the area to include.
     */
    dg_sare ( &ier );

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

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

        if ( Gr2Readin == 1 )  return;

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

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

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

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

        n  = 0;
        while ( n < nr ) {

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

	    cst_lstr (  buffer, &blen, &ier );

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

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

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

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

            n++;
        }


        cfl_clos(fp, &ier);

        Gr2Tbl.nlines = n;

        Gr2Readin = 1;

}
Пример #7
0
static void tbl_cnty ( shp_record *shprec, int numrec, int *iret )
/************************************************************************
 * tbl_cnty                                                             *
 *                                                                      *
 * This function creates the county station table files.               	*
 *                                                                      *
 * tbl_cnty ( shprec, numrec, iret )                            	*
 *                                                                      *
 * Input parameters:                                                    *
 *      *shprec         shp_record  	Shape record list		*
 *	numrec		int		Total number of records		*
 *                                                                      *
 * Output parameters:                                                   *
 *      *iret           int             Return code                     *
 *                                        0 = Normal                    *
 **                                                                     *
 * Log:                                                                 *
 * R. Tian/SAIC          3/04   	Initial coding                  *
 ***********************************************************************/
{
    shp_record *currec;
    char ctynam[25], shrnam[33], cwanam[10], stabbr[3];
    int ifips, ilat, ilon;
    int irec, jfld, pos, len, ier;
    float shplat, shplon;
    char *ctytbl = COUNTYTBL, *namtbl = COUNTYNAMTBL;
    FILE *tblfp, *namfp;
/*---------------------------------------------------------------------*/
    *iret = 0;

    tblfp = cfl_wopn ( ctytbl, &ier );
    if ( ier != 0 ) {
        fprintf ( stderr, "File %s open failed.\n", ctytbl );
        exit ( -1 );
    }
    namfp = cfl_wopn ( namtbl, &ier );
    if ( ier != 0 ) {
        fprintf ( stderr, "File %s open failed.\n", namtbl );
        exit ( -1 );
    }

    for ( currec = shprec, irec = 0; irec < numrec;
        irec++, currec = currec->nxtrec ) {
        for ( jfld = 0; jfld < currec->numfld; jfld++ ) {
            if ( strncmp ( currec->fields[jfld].name, "COUNTYNAME",
                strlen("COUNTYNAME") ) == 0 ) {
                strcpy ( ctynam, currec->fields[jfld].data );
		cst_lstr ( ctynam, &len, &ier );
		ctynam[len] = '\0';
		cst_rspc ( ctynam, &ier );
		abbreviate ( ctynam, 32, shrnam, &ier );

		/*
		 * Remove "City_of_" from county name
		 */
	        cst_rmst ( shrnam, "City_of_", &pos, shrnam, &ier );

		/*
		 * Remove "Lower_Keys_in_" from county name
		 */
	        cst_rmst ( shrnam, "Lower_Keys_in_", &pos, shrnam, &ier );

		/*
		 * Remove "Outer_Banks_" from county name
		 */
	        cst_rmst ( shrnam, "Outer_Banks_", &pos, shrnam, &ier );

		/*
		 * Remove "Mainland_" from county name
		 */
	        cst_rmst ( shrnam, "Mainland_", &pos, shrnam, &ier );
            } else if ( strncmp ( currec->fields[jfld].name, "STATE",
	        strlen ( "STATE" ) ) == 0 ) {
	        strcpy ( stabbr, currec->fields[jfld].data );
	    } else if ( strncmp ( currec->fields[jfld].name, "CWA",
	        strlen ( "CWA" ) ) == 0 ) {
	        strcpy ( cwanam, currec->fields[jfld].data );
		cst_lstr ( cwanam, &len, &ier );
		cwanam[len] = '\0';
	    } else if ( strncmp ( currec->fields[jfld].name, "FIPS",
                strlen("FIPS") ) == 0 ) {
                ifips = atoi ( currec->fields[jfld].data );
	    } else if ( strncmp ( currec->fields[jfld].name, "LAT",
                strlen("LAT") ) == 0 ) {
                shplat = atof ( currec->fields[jfld].data );
	    } else if ( strncmp ( currec->fields[jfld].name, "LON",
                strlen("LON") ) == 0 ) {
                shplon = atof ( currec->fields[jfld].data );
            }
	}
	if ( strlen ( shrnam ) == (size_t)0 || strlen ( stabbr ) == (size_t)0 ) {
	    continue;
	}

	if ( ERMISS ( currec->cenlat ) || ERMISS ( currec->cenlon ) ) {
	    ilat = (int)(ROUNDUP(shplat)*100.);
	    ilon = (int)(ROUNDUP(shplon)*100.);
	} else {
	    ilat = (int)(ROUNDUP(currec->cenlat)*100.);
	    ilon = (int)(ROUNDUP(currec->cenlon)*100.);
	}

        fprintf ( tblfp, 
          "%2.2sC%3.3d   %6d %-32.32s %2.2s US %5d %6d %5d %2d %-3.3s\n",
          stabbr, ifips%1000, ifips, shrnam, stabbr,
          ilat, ilon, 0, 0, cwanam );
        fprintf ( namfp, 
	  "%-8.8s %6d %-32.32s %2.2s US %5d %6d %5d %2d %-3.3s\n",
	  shrnam, ifips, shrnam, stabbr, ilat, ilon, 0, 0, cwanam );
    }

    cfl_clos ( tblfp, &ier );
    cfl_clos ( namfp, &ier );
}
Пример #8
0
void cst_ilst ( char *str, char sep, int def, int nexp, int *intptr, 
						int *num, int *iret )
/************************************************************************
 * cst_ilst								*
 *									*
 * This subroutine breaks a string containing a list of integers into 	*
 * an array of integers.  The separator for the integers is input as	*
 * SEP.  If the seperator is a blank, multiple blanks will be treated	*
 * as one.  If null strings are	encounteded or fewer than NEXP strings	*
 * are found in the string, the appropriate intptr locations are set to	*
 * DEF.									*
 *									*
 * Range strings (with optional increments) are indicated with a hyphen	*
 * (i.e., 3-9 or 3-12-3) and are processed into the INTPTR array.	*
 *									*
 * cst_ilst ( str, sep, def, nexp, intptr, num, iret )			*
 *									*
 * Input parameters:							*
 *	*str		char		Input string			*
 *	sep		char		Separator			*
 *	def		int	 	Default value			*
 *	nexp		int		Number of expected values	*
 *									*
 * Output parameters:							*
 *	*intptr		int		Pointer to integer values	*
 *	*num		int		Number of integers returned	*
 *	*iret		int		Return code			*
 *					  1 = more than nexp values	*
 *					  0 = normal			*
 *					 -1 = invalid nexp		*
 *					 -3 = invalid substring		*
 **									*
 * Log:									*
 * L. Williams/EAI	 4/96						*
 * L. Williams/EAI	 6/96	check for missing data			*
 * S. Jacobs/NCEP	 8/96	Updated header format			*
 * G. Krueger/EAI	10/97	Removed MALLOC, RSPTB			*
 ***********************************************************************/
{
char	strbuf[160], alpha[10], omega[10], rinc[10];
int	ielt, ichar, jchar, len, lenss;
int	begin, end, inc, tp, ival, intgr, ier, err;

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

	/*
	 * check the number of expected values
	 */
	if( nexp <= 0 ) {
	   intptr = 0;
	   *iret = -1;
	   return;
	}

	/*
	 * initialize output array to default value
	 */
	for( ielt=0; ielt < nexp; ielt++ )
	     intptr[ielt] = def;

	/*
	 * process the input string into an array of integer numbers
	 */
	jchar = 0;
	ielt = 0;
	*strbuf = '\0';
	len = strlen (str);
	for ( ichar = 0; ichar < len; ichar++ )
	{
	    if (str[ichar] == '\t' || str[ichar] == ' ') {
		if (sep != ' ') {
		    continue;
		} else if ( (sep == ' ') &&
			    (str[ichar+1] == '\t' && str[ichar+1] == ' ') ) {
		    continue;
		}
	    }
	    if ( str[ichar] == sep ) {
		/*
		 * character is a separator, finish the current array
		 * element
		 */
		strbuf[jchar] = '\0';
		cst_lstr( strbuf, &lenss, &ier );
		if ( lenss != 0 ) {
		    cst_rang( strbuf, alpha, omega, rinc, &tp, &ier );
		    if ( tp ) {
			/*
			 * this is a range
			 */
			cst_numb( alpha, &begin, &ier );
			cst_numb( omega, &end, &err );
			if ( ( ier == -2 ) || ( err == -2 ) ) {
			    *iret = -3;
			} else {
			    inc = 1;
			    if ( tp != 1 ) inc = atoi( rinc );
			    for ( ival=begin; ival <= end; ival += inc ) 
				if ( ielt < nexp ) {
				    intptr[ielt] = ival;
				    ielt++;
				}
				ielt--;
			}
		    } else {
			/*
			 * this is a simple integer
			 */
			cst_numb( strbuf, &intgr, &ier );
			if ( ier == -2 ) {
			    *iret = -3;
			} else {
			    intptr[ielt] = intgr;
			}
		    }
		}
		ielt++;
		/*
		 * work on the next array element
		 */
		jchar = 0;
		*strbuf = '\0';
		if ( ielt >= nexp ) {
		    *iret = 1;
		    break;
		}
	    } else {
		/*
		 * otherwise, append the character to the buffer
		 */
		strbuf[jchar] = str[ichar];
		jchar++;
	    }
	}
	/*
	 * finish the last array element
	 */
	strbuf[jchar] = '\0';
	cst_lstr( strbuf, &lenss, &ier );
	if ( lenss != 0 ) {
	    cst_rang( strbuf, alpha, omega, rinc, &tp, &ier );
	    if ( tp ) {
		/*
		 * this is a range
		 */
		cst_numb( alpha, &begin, &ier );
		cst_numb( omega, &end, &err );
		if ( ( ier == -2 ) || ( err == -2 ) ) {
		    *iret = -3;
		} else {
		    inc = 1;
		    if ( tp != 1 ) inc = atoi( rinc );
		    for ( ival=begin; ival <= end; ival += inc ) 
			if ( ielt < nexp ) {
			    intptr[ielt] = ival;
			    ielt++;
			}
			ielt--;
		}
	    } else {
		/*
		 * this is a simple integer
		 */
		cst_numb( strbuf, &intgr, &ier );
		if ( ier == -2 ) {
		    *iret = -3;
		} else {
		    intptr[ielt] = intgr;
		}
	    }
	}
	ielt++;
	*num = ielt;
	if ( *num > nexp ) *num = nexp;
}
Пример #9
0
void nim_flnm ( const char *imgtyp, const char *imginf,
                char *basetm, char *endtim, int mrange,
                int intrvl, Boolean bflag, Boolean bauto, char *path,
                char ***namarr, char ***timarr, int *ntimes, int *iret )
/************************************************************************
 * nim_flnm								*
 *									*
 * This routine returns an array of file names given the image info.	*
 * The type of image, SAT or RAD, and the image info, which is the	*
 * directory of the data, are used to locate the image data files on 	*
 * disk. For satellite images, the info is the part of the directory	*
 * path that defines the source/geog_area/channel. For radar images,	*
 * the info is lcl_or_natl/area/type.					*
 *									*
 * void nim_flnm ( imgtyp, imginf, basetm, endtim, mrange, intrvl,	*
 *		   bflag, bauto, path, namarr, timarr, nfound, iret )	*
 *									*
 * Input parameters:							*
 *      *imgtyp         const char      Type of image                   *
 *      *imginf         const char      Directory information           *
 *	*basetm		char		Base time			*
 *	*endtim		char		End time of range		*
 *	mrange		int		Minutes in time range		*
 *	intrvl		int		Minutes in time interval	*
 *	bflag		Boolean		Reference time flag		*
 *	bauto		Boolean		Auto update flag		*
 *									*
 * Output parameters:							*
 *	*path		char		Full directory path		*
 *	***namarr	char		Array of all file names		*
 *	***timarr	char		Array of all file times		*
 *	*ntimes		int		Number of files/times returned	*
 *	*iret		int		Return code			*
 *					  -3 = no files found		*
 **									*
 * Log:									*
 * S. Jacobs/NCEP	 8/99	Created					*
 * S. Jacobs/NCEP	 2/00	Use the path and templ from datatype.tbl*
 * S. Jacobs/NCEP	 7/00	Moved error check to after FL_SCND call	*
 * S. Jacobs/NCEP	 8/00	Added check: len of tmpl = len of file	*
 * S. Jacobs/NCEP	 3/01	Increased file template to 48 chars	*
 * S. Jacobs/NCEP	 9/01	Ignore the non-date part of the template*
 * A. Hardy/SAIC         2/02   Changed call FL_SCND			*
 * T. Lee/SAIC		 6/02	Handled wild card template; return ipos	*
 * T. Lee/SAIC		 9/04	Replaced FL_TMPL with CTB_DTGET		*
 * A. Hardy/NCEP	11/04   Added calls to ST_RNUL			*
 * m.gamazaychikov/SAIC 12/04   Added ion flag to CTB_DTGET CS          *
 * m.gamazaychikov/SAIC 01/06   Changed ctmpl string length to MXTMPL   *
 * m.gamazaychikov/SAIC 04/06   Added idtmch flag to CTB_DTGET CS       *
 * T. Piper/SAIC	04/07	Re-wrote in 'C'; dynamic arrays		*
 * T. Piper/SAIC	10/07	Check value of nt before cti_tmln	*
 * F. J. Yen/NCEP	 4/08	Add bin mins and mstrct to CTB_DTGET CSC*
 ***********************************************************************/
{
    long istar;
    int ic, is, nf, ir, ii, kk, ion, ihb, iha, idtmch, iorder, lens;
    int imb, ima, mstrct;
    int ier, ier1, ier2, itarr[5], jtarr[5], lenf, lent, mdif, ndif, nt;
    int idir=-1, idelrt=-1, nfiles;
    size_t timlen=DTTMS_SIZE;
    /*
     *  The following dimensions are based upon the sizes in the datatype.tbl
     *  plus one for the null character; then rounded up to the neartest
     *  multiple of four.
     */
    char *pstar, **t_names=NULL, **t_times=NULL, **tarr=NULL;
    char cpath[28], ctmpl[MXTMPL], tmplt[MXTMPL];
    dattm_t strtim;
    nmlst_t tfil;
    struct dirent **dnlist=NULL;
    /*---------------------------------------------------------------------*/
    /*
     *  Construct the directory name from the image data attributes.
     */
    ctb_dtget ( (char*)imgtyp, cpath, ctmpl, &ic, &is, &nf, &ir, &ii,
                &ion, &ihb, &imb, &iha, &ima, &mstrct, &idtmch, &ier );
    strcpy ( path,  cpath );
    strcat ( path,   "/"  );
    strcat ( path, imginf );
    /*
     *  Scan the directory.
     */
    iorder = 1;
    cfl_scnt ( path, ctmpl, iorder, &dnlist, &nfiles, &ier );
    /*
     *  If there are no files, there is an error.
     */
    if ( nfiles > 0 ) {
        /*
         *  Construct the full file name template for this directory.
         */
        pstar = strchr(ctmpl, '*' );
        if ( pstar == NULL ) {
            /*  No '*' was found in the template.   */
            strcpy(tmplt, ctmpl);
        }
        else {
            /*  An '*' was found in the template.  */
            istar = ( pstar - ctmpl );
            if ( istar == 0 ) {
                /*  An '*' was found at the beginning of the template.  */
                strcpy(tmplt, (ctmpl+2));
            }
            else {
                cst_ncpy(tmplt, ctmpl, istar, &ier);
            }
        }
        /*
         *  Convert each file name to a time.
         */
        cst_lstr(tmplt, &lent, &ier );
        cst_lstr(dnlist[0]->d_name, &lenf, &ier );
        G_MALLOC(tarr, char*, nfiles, "nim_flnm:  tarr");
        for ( ii = 0; ii < nfiles; ii++ ) {
            G_CALLOC(tarr[ii], char, timlen, "nim_flnm:  tarr[ii]");
            if ( pstar == NULL ) {
                cfl_mdat(dnlist[ii]->d_name, tmplt, "YYMMDD/HHNN",
                         tarr[ii], &ier );
            }
            else {
                if ( istar == 0 ) {
                    strcpy(tfil, dnlist[ii]->d_name+(lenf-lent));
                }
                else {
                    cst_ncpy(tfil, dnlist[ii]->d_name, lent, &ier);
                }
                cfl_mdat(tfil, tmplt, "YYMMDD/HHNN", tarr[ii], &ier );
            }
        }

        /*
         *   Sort the times.
         */
        qsort( (void*)tarr, (size_t)nfiles, sizeof(char*), compare );
        cti_yyyy(nfiles, tarr, tarr, &ier);

        /*
         *  Compute the start time of the range from the end time
         *  and the number of minutes.
         */
        ti_ctoi ( endtim, itarr, &ier, strlen(endtim) );
        ti_subm ( itarr, &mrange, jtarr, &ier );
        ti_itoc ( jtarr, strtim, &ier, sizeof(strtim) );
        st_null ( strtim, strtim, &lens, &ier, sizeof(strtim), sizeof(strtim) );
        /*
         *  Find the number of times to return.
         */
        nt = 0;
        for ( ii = 0; ii < nfiles; ii++ ) {
            ti_diff ( strtim, tarr[ii], &mdif, &ier1, strlen(strtim), timlen-1 );
            ti_diff ( tarr[ii], endtim, &ndif, &ier2, timlen-1, strlen(endtim));
            if ( ( ier1 == 0 ) && ( ier2 == 0 ) ) {
                if ( ( mdif <= 0 ) && ( ndif <= 0 ) ) {
                    G_REALLOC(t_names, char*, nt+1, "nim_flnm:  t_names");
                    G_MALLOC(t_names[nt], char, (strlen(dnlist[ii]->d_name)+1),
                             "nim_flnm:  t_names[nt]");
                    strcpy(t_names[nt], dnlist[ii]->d_name);
                    G_REALLOC(t_times, char*, nt+1, "nim_flnm:  t_times");
                    G_MALLOC(t_times[nt], char, (strlen(tarr[ii])+1),
                             "nim_flnm:  t_times[nt]");
                    strcpy(t_times[nt], tarr[ii]);
                    nt++;
                }
            }
            G_FREE(tarr[ii], char);
            free (dnlist[ii]);
        }
Пример #10
0
void dg_gtmp ( const char *time1, const char *time2, const int *level1,
               const int *level2, const int *ivcord, const char *parm,
	       int *num, int *iret )
/************************************************************************
 * dg_gtmp								*
 *									*
 * This subroutine checks for temperature parameters in units other	*
 * than those requested.  The grid will be found in the grid location	*
 * pointed to by NUM.  If NUM = 0 on input, the next grid location	*
 * will be used and returned.  If NUM > 0, the grid will be found	*
 * at NUM.  Temperatures include temperature (TMP), dewpoint (DWP),	*
 * maximum temperature (TMX), minimum temperature (TMN), sea surface	*
 * temperature (SST), and virtual temperature (TVR). 			*
 *									*
 * dg_gtmp ( time1, time2, level1, level2, ivcord, parm, num, iret )	*
 *									*
 * Input parameters:							*
 *      *time1          const char      Date/time                       *
 *      *time2          const char      Date/time                       *
 *      *level1         const int       Level                           *
 *      *level2         const int       Level                           *
 *      *ivcord         const int       Vertical coordinate             *
 *      *parm           const char      Parameter name                  *
 *									*
 * Input and output parameters:						*
 *	*num		int		Location of grid		*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *					  0 = normal return		*
 *					 -7 = grid cannot be found	*
 *					 -8 = grid is the wrong size	*
 **									*
 * Log:									*
 * M. desJardins/GSFC	10/85						*
 * M. desJardins/GSFC	 4/89	Fixed truncation to 4 chars		*
 * M. desJardins/GSFC	 7/89	Replaced PR calls with PA		*
 * M. desJardins/GSFC	 8/89	PA to PD subroutines			*
 * K. Brill/GSC		 9/89   IFILED					*
 * M. desJardins/GSFC	 2/90	Renamed from DG_TEMP			*
 * M. desJardins/NMC	 3/92	Generalize to translate units for temps	*
 * M. desJardins/NMC	 7/93	DG_UHDR --> DG_UPSG			*
 * L. Williams/EAI	 8/94	Added 'TMW' to temperature field check	*
 * T. Lee/GSC		 4/96	Single dimension for dgg		*
 * T. Piper/SAIC	 2/02	Increased c3 to 4 due to UMR error	*
 * K. Brill/HPC		11/02	Eliminate use of the SUBA logical array	*
 * R. Tian/SAIC		 2/06	Recoded from Fortran			*
 * S. Gilbert/NCEP	 2/07	Replaced dg_grdr with dg_vcrd           *
 ************************************************************************/
{
    char ppp[5], c1, c3[4], f[3][2] = { "K", "C", "F" };
    int lenp, knt, itin, itout, ier;
/*----------------------------------------------------------------------*/
    *iret = -7;

    /*
     * Check that the input string length is 4.
     */
    cst_lstr ( (char *)parm, &lenp, &ier );
    if ( lenp != 4 ) return;

    /*
     * Translate special names into names with K, C, or F.
     */
    if ( strcmp ( parm, "TEMP" ) == 0 ) {
	strcpy ( ppp, "TMPC" );
    } else if ( strcmp ( parm, "DWPT" ) == 0 ) {
	strcpy ( ppp, "DWPC" );
    } else if ( strcmp ( parm, "THTA" ) == 0 ) {
	strcpy ( ppp, "THTK" );
    } else if ( strcmp ( parm, "STHA" ) == 0 ) {
	strcpy ( ppp, "STHK" );
    } else if ( strcmp ( parm, "TMAX" ) == 0 ) {
	strcpy ( ppp, "TMXC" );
    } else if ( strcmp ( parm, "TMIN" ) == 0 ) {
	strcpy ( ppp, "TMNC" );
    } else {
	strcpy ( ppp, parm );
    }

    /*
     *Check that this is a temperature field.
     */
    strncpy ( c3, ppp, 3 );
    c3[3] = '\0';
    c1 = ppp[3];
    if ( ( strcmp ( c3, "TMP" ) != 0 ) && ( strcmp ( c3, "DWP" ) != 0 ) &&
	 ( strcmp ( c3, "THT" ) != 0 ) && ( strcmp ( c3, "STH" ) != 0 ) &&
	 ( strcmp ( c3, "SST" ) != 0 ) && ( strcmp ( c3, "TMX" ) != 0 ) &&
	 ( strcmp ( c3, "TMN" ) != 0 ) && ( strcmp ( c3, "TVR" ) != 0 ) &&
	 ( strcmp ( c3, "TMW" ) ) ) return;

    /*
     * Check for valid temperature units requested.
     */
    if ( c1 == 'K' ) {
	itout = 1;
    } else if ( c1 == 'C' ) {
	itout = 2;
    } else if  ( c1 == 'F' ) {
	itout = 3;
    } else {
	return;
    }

    /*
     * Check file for grid stored in K, C or F.
     */
    knt = 1;
    while ( ( *iret != 0 ) && ( knt <= 4 ) ) {
	/*
	 * Get name of parameter to check.
	 */
	if ( knt <= 3 ) {
	    strcpy ( ppp, c3 );
	    strcat ( ppp, f[knt-1] );
	} else if ( strcmp ( c3, "TMP" ) == 0 ) {
	    strcpy ( ppp, "TEMP" );
	    itin = 2;
	} else if  ( strcmp ( c3, "DWP" ) == 0 ) {
	    strcpy ( ppp, "DWPT" );
	    itin = 2;
	} else if  ( strcmp ( c3, "THT" ) == 0 ) {
	    strcpy ( ppp, "THTA" );
	    itin = 1;
	} else if  ( strcmp ( c3, "STH" ) == 0 ) {
	    strcpy ( ppp, "STHA" );
	    itin = 1;
	} else if  ( strcmp ( c3, "TMX" ) == 0 ) {
	    strcpy ( ppp, "TMAX" );
	    itin = 2;
	} else if  ( strcmp ( c3, "TMN" ) == 0 ) {
	    strcpy ( ppp, "TMIN" );
	    itin = 2;
	}

	/*
	 * Check for parameter in file.
	 */
	dg_vcrd ( time1, time2, level1, level2, ivcord, ppp, num, iret );

	/*
	 * Save information on type.
	 */
	if ( ( *iret == 0 ) && ( knt <= 3 ) ) itin = knt;

	/*
	 * Increment knt.
	 */
	knt++;
    }

    /*
     * Exit if thermodynamic field was not found.
     */
    if ( *iret != 0 ) {
	return;
    /*
     * If input and output types are the same, return.
     */
    } else if  ( itout == itin ) {
	return;
    /*
     * Otherwise, compute correct units.
     */
    } else if ( ( itin == 1 ) && ( itout == 2 ) ) {
	pd_tmkc ( _dggrid.dgg[(*num)-1].grid, &_dgfile.kxyd,
		  _dggrid.dgg[(*num)-1].grid, &ier);
    } else if ( ( itin == 1 ) && ( itout == 3 ) ) {
	pd_tmkf ( _dggrid.dgg[(*num)-1].grid, &_dgfile.kxyd,
		  _dggrid.dgg[(*num)-1].grid, &ier);
    } else if ( ( itin == 2 ) && ( itout == 1 ) ) {
	pd_tmck ( _dggrid.dgg[(*num)-1].grid, &_dgfile.kxyd,
	          _dggrid.dgg[(*num)-1].grid, &ier);
    } else if ( ( itin == 2 ) && ( itout == 3 ) ) {
	pd_tmcf ( _dggrid.dgg[(*num)-1].grid, &_dgfile.kxyd,
		  _dggrid.dgg[(*num)-1].grid, &ier);
    } else if ( ( itin == 3 ) && ( itout == 1 ) ) {
	pd_tmfk ( _dggrid.dgg[(*num)-1].grid, &_dgfile.kxyd,
		  _dggrid.dgg[(*num)-1].grid, &ier);
    } else if ( ( itin == 3 ) && ( itout == 2 ) ) {
	pd_tmfc ( _dggrid.dgg[(*num)-1].grid, &_dgfile.kxyd,
	 	  _dggrid.dgg[(*num)-1].grid, &ier);
    }

    /*
     * Put correct name in label.
     */
    dg_upsg ( time1, time2, level1, level2, ivcord, &_dgfile.idlun,
              parm, num, &ier );

    return;
}
Пример #11
0
static void tbl_zone ( shp_record *shprec, int numrec, int *iret )
/************************************************************************
 * tbl_zone                                                             *
 *                                                                      *
 * This function creates the public forecast zone and fire weather zone	*
 * station table files.							*
 *                                                                      *
 * tbl_zone ( shprec, numrec, iret )                            	*
 *                                                                      *
 * Input parameters:                                                    *
 *      *shprec         shp_record  	Shape record list		*
 *	numrec		int		Total number of records		*
 *                                                                      *
 * Output parameters:                                                   *
 *      *iret           int             Return code                     *
 *                                        0 = Normal                    *
 **                                                                     *
 * Log:                                                                 *
 * R. Tian/SAIC          3/04   	Initial coding                  *
 ***********************************************************************/
{
    shp_record *currec;
    /*
     * The array size is from the Public Forecast Zones attributes 
     * specification.
     */
    char zonenm[255], shrnam[33], cwanam[4], stabbr[3];
    int ifips, izone, istno, iclat, iclon;
    int rec, ifld, len, ier;
    float shplat, shplon;
    char *tblnam = PFZTBL;
    FILE *tblfp;
/*---------------------------------------------------------------------*/
    *iret = 0;

    tblfp = cfl_wopn ( tblnam, &ier );
    if ( ier != 0 ) {
        fprintf ( stderr, "File %s open failed.\n", tblnam );
        exit ( -1 );
    }

    for ( currec = shprec, rec = 0; rec < numrec;
        rec++, currec = currec->nxtrec ) {

        for ( ifld = 0; ifld < currec->numfld; ifld++ ) {
            if ( strcmp ( currec->fields[ifld].name, "STATE" ) == 0 ) {
	        strcpy ( stabbr, currec->fields[ifld].data );
            } else if ( strncmp ( currec->fields[ifld].name, "ZONE",
	        strlen ( "ZONE" ) ) == 0 ) {
		izone = strtol ( currec->fields[ifld].data, NULL, 10 );
	    } else if ( strncmp ( currec->fields[ifld].name, "CWA",
	        strlen ( "CWA" ) ) == 0 ) {
	        strncpy ( cwanam, currec->fields[ifld].data, 3 );
	        cwanam[3] = '\0';
	    } else if ( strncmp ( currec->fields[ifld].name, "LAT",
                strlen("LAT") ) == 0 ) {
                shplat = atof ( currec->fields[ifld].data );
	    } else if ( strncmp ( currec->fields[ifld].name, "LON",
                strlen("LON") ) == 0 ) {
                shplon = atof ( currec->fields[ifld].data );
            } else if ( strncmp ( currec->fields[ifld].name, "NAME",
	        strlen("NAME") ) == 0 ) {
		strcpy ( zonenm, currec->fields[ifld].data );
		cst_lstr ( zonenm, &len, &ier );
		zonenm[len] = '\0';
		cst_rspc ( zonenm, &ier );
		abbreviate ( zonenm, 32, shrnam, &ier );
	    }
	}

        for ( istno = 0; istno < NUMSTNO; istno++ ) {
            if ( strncmp ( stateno[istno], stabbr, 2 ) == 0 ) {
                break;
            }
        }
        ifips = istno * 10000 + izone * 10;
        iclat = (int)(ROUNDUP(shplat)*100.);
        iclon = (int)(ROUNDUP(shplon)*100.);
        if ( iclat == 0 && iclon == 0 ) {
            iclat = (int)(ROUNDUP(currec->cenlat)*100.);
            iclon = (int)(ROUNDUP(currec->cenlon)*100.);
        }

        fprintf ( tblfp, 
          "%2.2sZ%3.3d   %6d %-32.32s %2.2s US %5d %6d %5d %2d %-3.3s\n",
          stabbr, izone, ifips, shrnam, stabbr, iclat, iclon, 0, 0, cwanam );
    }

    cfl_clos ( tblfp, &ier );
}
Пример #12
0
static void bnd_cnty ( shp_record *onerec, char *header, char *subhdr,
                  char *hdrnam, float *cenlat, float *cenlon, int *iret )
/************************************************************************
 * bnd_cnty                                                             *
 *                                                                      *
 * This function generates the county bound header and sub-header lines *
 *                                                                      *
 * bnd_cnty ( onerec, header, subhdr, hdrnam, cenlat, cenlon, iret )    *
 *                                                                      *
 * Input parameters:                                                    *
 *      *onerec         shp_record      One shape record               	*
 *                                                                      *
 * Output parameters:                                                   *
 *	*header		char		Bound header line		*
 *	*subhdr		char		Bound sub-header line		*
 *	*hdrnam		char		Bound header name    		*
 *	*cenlat		float		Center latitude			*
 *	*cenlon		float 		Center longitude		*
 *      *iret           int             Return code                     *
 *                                        0 = Normal                    *
 *                                        1 = Incomplete record         *
 **                                                                     *
 * Log:                                                                 *
 * R. Tian/SAIC          3/04           Initial coding                  *
 ***********************************************************************/
{
    char ctynam[25], cwanam[10], fearea[3], tmzone[3], stabbr[3];
    int ifips, iclat, iclon, nparts;
    float shplat, shplon;
    int ifld, pos, len, ier;
/*---------------------------------------------------------------------*/
    *iret = 0;

    nparts = onerec->numprt;
    for ( ifld = 0; ifld < onerec->numfld; ifld++ ) {
        if ( strncmp ( onerec->fields[ifld].name, "COUNTYNAME", 
	    strlen("COUNTYNAME") ) == 0 ) {
	    strcpy ( ctynam, onerec->fields[ifld].data );
	    cst_lstr ( ctynam, &len, &ier );
	    ctynam[len] = '\0';
            cst_rspc ( ctynam, &ier );

            /*
             * Remove "Lower_Keys_in_" from county name
             */
            cst_rmst ( ctynam, "Lower_Keys_in_", &pos, ctynam, &ier );
                                                                                
            /*
             * Remove "Outer_Banks_" from county name
             */
            cst_rmst ( ctynam, "Outer_Banks_", &pos, ctynam, &ier );
                                                                                
            /*
             * Remove "Mainland_" from county name
             */
            cst_rmst ( ctynam, "Mainland_", &pos, ctynam, &ier );

	} else if ( strncmp ( onerec->fields[ifld].name, "FIPS", 
            strlen("FIPS") ) == 0 ) {
	    ifips = atoi ( onerec->fields[ifld].data );
        } else if ( strncmp ( onerec->fields[ifld].name, "CWA",
	    strlen ( "CWA" ) ) == 0 ) {
	    strcpy ( cwanam, onerec->fields[ifld].data );
	    cst_lstr ( cwanam, &len, &ier );
	    cwanam[len] = '\0';
        } else if ( strncmp ( onerec->fields[ifld].name, "FE_AREA",
	    strlen ( "FE_AREA" ) ) == 0 ) {
	    strcpy ( fearea, onerec->fields[ifld].data );
        } else if ( strncmp ( onerec->fields[ifld].name, "TIME_ZONE",
	    strlen ( "TIME_ZONE" ) ) == 0 ) {
	    strcpy ( tmzone, onerec->fields[ifld].data );
        } else if ( strncmp ( onerec->fields[ifld].name, "STATE",
	    strlen ( "STATE" ) ) == 0 ) {
	    strcpy ( stabbr, onerec->fields[ifld].data );
        } else if ( strncmp ( onerec->fields[ifld].name, "LAT",
            strlen("LAT") ) == 0 ) {
            shplat = atof ( onerec->fields[ifld].data );
        } else if ( strncmp ( onerec->fields[ifld].name, "LON",
            strlen("LON") ) == 0 ) {
            shplon = atof ( onerec->fields[ifld].data );
        }
    }

    if ( strlen ( ctynam ) == (size_t)0 || strlen ( stabbr ) == (size_t)0 ) {
        *iret = 1;
        return;
    }
	    
    if ( ERMISS ( onerec->cenlat ) || ERMISS ( onerec->cenlon ) ) {
        iclat = (int)(ROUNDUP(shplat)*100.);
        iclon = (int)(ROUNDUP(shplon)*100.);
        *cenlat = shplat;
        *cenlon = shplon;
    } else {
        iclat = (int)(ROUNDUP(onerec->cenlat)*100.);
        iclon = (int)(ROUNDUP(onerec->cenlon)*100.);
        *cenlat = onerec->cenlat;
        *cenlon = onerec->cenlon;
    }

    sprintf ( header, "B%5.5d %-32.32s %5d %6d %3d %s",
              ifips, ctynam, iclat, iclon, nparts, cwanam );
    sprintf ( subhdr, "<FIPS>%d<STATE>%s<TIME_ZONE>%s<FE_AREA>%s",
              ifips, stabbr, tmzone, fearea );
    sprintf ( hdrnam, "%s", ctynam );
}
Пример #13
0
static void bnd_mzcn ( shp_record *onerec, char *header, char *subhdr,
                  char *hdrnam, float *cenlat, float *cenlon, int *iret )
/************************************************************************
 * bnd_mzcn                                                             *
 *                                                                      *
 * This function generates the marine bound header and sub-header lines *
 *                                                                      *
 * bnd_mzcn ( onerec, header, subhdr, hdrnam, cenlat, cenlon, iret )    *
 *                                                                      *
 * Input parameters:                                                    *
 *      *onerec         shp_record      One shape record               	*
 *                                                                      *
 * Output parameters:                                                   *
 *	*header		char		Bound header line		*
 *	*subhdr		char		Bound sub-header line		*
 *	*hdrnam		char		Bound header name    		*
 *	*cenlat		float		Center latitude			*
 *	*cenlon		float 		Center longitude		*
 *      *iret           int             Return code                     *
 *                                        0 = Normal                    *
 *                                        1 = Incomplete record         *
 **                                                                     *
 * Log:                                                                 *
 * R. Tian/SAIC          3/04           Initial coding                  *
 ***********************************************************************/
{
    char ctynam[25], cwanam[10], stabbr[3];
    int ifips, izone, istno, iclat, iclon, nparts;
    float shplat, shplon;
    int i, pos, len, ier;
/*---------------------------------------------------------------------*/
    *iret = 0;

    nparts = onerec->numprt;
    for ( i = 0; i < onerec->numfld; i++ ) {
        if ( strncmp ( onerec->fields[i].name, "COUNTYNAME", 
	    strlen("COUNTYNAME") ) == 0 ) {
	    strcpy ( ctynam, onerec->fields[i].data );
	    cst_lstr ( ctynam, &len, &ier );
	    ctynam[len] = '\0';
            cst_rspc ( ctynam, &ier );

            /*
             * Remove "Lower_Keys_in_" from county name
             */
            cst_rmst ( ctynam, "Lower_Keys_in_", &pos, ctynam, &ier );
                                                                                
            /*
             * Remove "Outer_Banks_" from county name
             */
            cst_rmst ( ctynam, "Outer_Banks_", &pos, ctynam, &ier );
                                                                                
            /*
             * Remove "Mainland_" from county name
             */
            cst_rmst ( ctynam, "Mainland_", &pos, ctynam, &ier );

	} else if ( strncmp ( onerec->fields[i].name, "FIPS", 
            strlen("FIPS") ) == 0 ) {
	    izone = ifips = atoi ( onerec->fields[i].data );
        } else if ( strncmp ( onerec->fields[i].name, "CWA",
	    strlen ( "CWA" ) ) == 0 ) {
	    strcpy ( cwanam, onerec->fields[i].data );
	    cst_lstr ( cwanam, &len, &ier );
	    cwanam[len] = '\0';
        } else if ( strncmp ( onerec->fields[i].name, "ID", 
	    strlen("ID") ) == 0 ) {
	    strcpy ( ctynam, onerec->fields[i].data );
	    strncpy ( stabbr, onerec->fields[i].data, 2 );
	    stabbr[2] = '\0';
	    izone = atoi ( onerec->fields[i].data + 3 );
	    for ( istno = 0; istno < NUMSTNO; istno++ ) {
	        if ( strncmp ( stateno[istno], stabbr, 2 ) == 0 ) {
		    break;
		}
	    }
            ifips = istno * 10000 + izone * 10;
        } else if ( strncmp ( onerec->fields[i].name, "WFO",
	    strlen ( "WFO" ) ) == 0 ) {
	    strcpy ( cwanam, onerec->fields[i].data );
        } else if ( strncmp ( onerec->fields[i].name, "LAT",
            strlen("LAT") ) == 0 ) {
            shplat = atof ( onerec->fields[i].data );
        } else if ( strncmp ( onerec->fields[i].name, "LON",
            strlen("LON") ) == 0 ) {
            shplon = atof ( onerec->fields[i].data );
        }
    }

    if ( ERMISS ( onerec->cenlat ) || ERMISS ( onerec->cenlon ) ) {
        iclat = (int)(ROUNDUP(shplat)*100.);
        iclon = (int)(ROUNDUP(shplon)*100.);
        *cenlat = shplat;
        *cenlon = shplon;
    } else {
        iclat = (int)(ROUNDUP(onerec->cenlat)*100.);
        iclon = (int)(ROUNDUP(onerec->cenlon)*100.);
        *cenlat = onerec->cenlat;
        *cenlon = onerec->cenlon;
    }

    sprintf ( header, "B%5.5d %-32.32s %5d %6d %3d %s",
              izone, ctynam, iclat, iclon, nparts, cwanam );
    sprintf ( subhdr, "<FIPS>%d", ifips );
    sprintf ( hdrnam, "%s", ctynam );
}
Пример #14
0
static void tbl_npsa ( shp_record *shprec, int numrec, int *iret )
/************************************************************************
 * tbl_npsa                                                             *
 *                                                                      *
 * This function creates the Predictive Service Areas table files.	*
 *                                                                      *
 * tbl_npsa ( shprec, numrec, iret )                            	*
 *                                                                      *
 * Input parameters:                                                    *
 *      *shprec         shp_record  	Shape record list		*
 *	numrec		int		Total number of records		*
 *                                                                      *
 * Output parameters:                                                   *
 *      *iret           int             Return code                     *
 *                                        0 = Normal                    *
 **                                                                     *
 * Log:                                                                 *
 * S. Jacobs/NCEP	 4/10   	Initial coding                  *
 * X. Guo/CWS            4/12           Increase variables(code,shrnam) *
 *                                      size                            *
 ***********************************************************************/
{
    shp_record *currec;
    /*
     * The array size is from the specification.
     */
    char code[20], name[81], shrnam[52];
    int rec, ifld, len, ier;
    float clat, clon;
    int iclat, iclon;
    char *tblnam = NPSATBL;
    FILE *tblfp;
/*---------------------------------------------------------------------*/
    *iret = 0;

    tblfp = cfl_wopn ( tblnam, &ier );
    if ( ier != 0 ) {
        fprintf ( stderr, "File %s open failed.\n", tblnam );
        exit ( -1 );
    }

    for ( currec = shprec, rec = 0; rec < numrec;
        rec++, currec = currec->nxtrec ) {

        for ( ifld = 0; ifld < currec->numfld; ifld++ ) {
            if ( strncmp ( currec->fields[ifld].name, "NAT_CODE",
	        strlen("NAT_CODE") ) == 0 ) {
		strcpy ( code, currec->fields[ifld].data );
		cst_lstr ( code, &len, &ier );
		code[len] = '\0';
            } else if ( strncmp ( currec->fields[ifld].name, "PSA_NAME",
	        strlen("PSA_NAME") ) == 0 ) {
		strcpy ( name, currec->fields[ifld].data );
		cst_lstr ( name, &len, &ier );
		name[len] = '\0';
		cst_rspc ( name, &ier );
		abbreviate ( name, 50, shrnam, &ier );
	    }
	}

	if ( strlen(shrnam) == 0 ) {
	    strcpy ( shrnam, code );
	}

	shp_gctr ( currec, &clon, &clat, &ier );
        iclat = (int)(ROUNDUP(clat)*100.);
        iclon = (int)(ROUNDUP(clon)*100.);

        fprintf ( tblfp, 
          "%-8.8s %6.6d %-32.32s -- US %5d %6d %5d %2d\n",
          code, 999999, shrnam, iclat, iclon, 0, 0 );
    }

    cfl_clos ( tblfp, &ier );
}
Пример #15
0
static void tbl_mari ( shp_record *shprec, int numrec, int *iret )
/************************************************************************
 * tbl_mari                                                             *
 *                                                                      *
 * This function creates the marine station table files.               	*
 *                                                                      *
 * tbl_mari ( shprec, numrec, iret )                            	*
 *                                                                      *
 * Input parameters:                                                    *
 *      *shprec         shp_record  	Shape record list		*
 *	numrec		int		Total number of records		*
 *                                                                      *
 * Output parameters:                                                   *
 *      *iret           int             Return code                     *
 *                                        0 = Normal                    *
 **                                                                     *
 * Log:                                                                 *
 * R. Tian/SAIC          3/04   	Initial coding                  *
 ***********************************************************************/
{
    shp_record *currec;
    /*
     * The array size is from the Costal Marine Zones attributes
     * specification.
     */
    char id[7], fulnam[251], shrnam[33], wfonam[4], stabbr[3];
    int ifips, istno, izone, ilat, ilon;
    int irec, jfld, len, ier;
    char *tblnam = MARINETBL;
    float shplat, shplon;
    FILE *tblfp;
/*---------------------------------------------------------------------*/
    *iret = 0;

    tblfp = cfl_wopn ( tblnam, &ier );
    if ( ier != 0 ) {
        fprintf ( stderr, "File %s open failed.\n", tblnam );
        exit ( -1 );
    }

    for ( currec = shprec, irec = 0; irec < numrec;
        irec++, currec = currec->nxtrec ) {
        for ( jfld = 0; jfld < currec->numfld; jfld++ ) {
            if ( strncmp ( currec->fields[jfld].name, "ID",
                strlen("ID") ) == 0 ) {
		strncpy ( id, currec->fields[jfld].data, 6 );
		id[6] = '\0';
                strncpy ( stabbr, currec->fields[jfld].data, 2 );
                stabbr[2] = '\0';
                izone = atoi ( currec->fields[jfld].data + 3 );
                for ( istno = 0; istno < NUMSTNO; istno++ ) {
                    if ( strncmp ( stateno[istno], stabbr, 2 ) == 0 ) {
                        break;
                    }
                }
                ifips = istno * 10000 + izone * 10;
            } else if ( strncmp ( currec->fields[jfld].name, "WFO",
                strlen ( "WFO" ) ) == 0 ) {
                strncpy ( wfonam, currec->fields[jfld].data, 3 );
		wfonam[3] = '\0';
            } else if ( strncmp ( currec->fields[jfld].name, "NAME",
                strlen ( "NAME" ) ) == 0 ) {
                strcpy ( fulnam, currec->fields[jfld].data );
		cst_lstr ( fulnam, &len, &ier );
		fulnam[len] = '\0';
                cst_rspc ( fulnam, &ier );
		abbreviate ( fulnam, 32, shrnam, &ier );
	    } else if ( strncmp ( currec->fields[jfld].name, "LAT",
                strlen("LAT") ) == 0 ) {
                shplat = atof ( currec->fields[jfld].data );
	    } else if ( strncmp ( currec->fields[jfld].name, "LON",
                strlen("LON") ) == 0 ) {
                shplon = atof ( currec->fields[jfld].data );
            }
        }

	if ( ERMISS ( currec->cenlat ) || 
	    ERMISS ( currec->cenlon ) ) {
	    ilat = (int)(ROUNDUP(shplat)*100.);
	    ilon = (int)(ROUNDUP(shplon)*100.);
	} else {
	    ilat = (int)(ROUNDUP(currec->cenlat)*100.);
	    ilon = (int)(ROUNDUP(currec->cenlon)*100.);
	}

        fprintf ( tblfp,
            "%6.6s   %6d %-32.32s -- US %5d %6d %5d %2d %-3.3s\n",
            id, ifips, shrnam, ilat, ilon, 0, 0, wfonam );
    }

    cfl_clos ( tblfp, &ier );
}
Пример #16
0
static void tbl_rfcb ( shp_record *shprec, int numrec, int *iret )
/************************************************************************
 * tbl_rfcb                                                             *
 *                                                                      *
 * This function creates the river forecast center basin table file.	* 
 *                                                                      *
 * tbl_rfcb ( shprec, numrec, iret )                            	*
 *                                                                      *
 * Input parameters:                                                    *
 *      *shprec         shp_record  	Shape record list		*
 *	numrec		int		Total number of records		*
 *                                                                      *
 * Output parameters:                                                   *
 *      *iret           int             Return code                     *
 *                                        0 = Normal                    *
 **                                                                     *
 * Log:                                                                 *
 * R. Tian/SAIC          4/04   	Initial coding                  *
 ***********************************************************************/
{
    shp_record *currec;
    /*
     * The array size is from the River Forecast Center Basin
     * specification.
     */
    char basid[9], basnam[65], shrnam[33], cwanam[13], rfcid[6];
    int iclat, iclon;
    int rec, ifld, len, ier;
    float shplat, shplon;
    char *tblnam = RIVERBASINTBL;
    FILE *tblfp;
/*---------------------------------------------------------------------*/
    *iret = 0;

    tblfp = cfl_wopn ( tblnam, &ier );
    if ( ier != 0 ) {
        fprintf ( stderr, "File %s open failed.\n", tblnam );
        exit ( -1 );
    }

    for ( currec = shprec, rec = 0; rec < numrec;
        rec++, currec = currec->nxtrec ) {

        for ( ifld = 0; ifld < currec->numfld; ifld++ ) {
            if ( strncmp ( currec->fields[ifld].name, "ID",
	        strlen ( "ID" ) ) == 0 ) {
	        strcpy ( basid, currec->fields[ifld].data );
		cst_lstr ( basid, &len, &ier );
		basid[len] = '\0';
            } else if ( strncmp ( currec->fields[ifld].name, "NAME",
	        strlen ( "NAME" ) ) == 0 ) {
		strcpy ( basnam, currec->fields[ifld].data );
		cst_lstr ( basnam, &len, &ier );
		basnam[len] = '\0';
		cst_rspc ( basnam, &ier );
		abbreviate ( basnam, 32, shrnam, &ier );
	    } else if ( strncmp ( currec->fields[ifld].name, "CWA",
	        strlen ( "CWA" ) ) == 0 ) {
	        strcpy ( cwanam, currec->fields[ifld].data );
		cst_lstr ( cwanam, &len, &ier );
	        cwanam[len] = '\0';
	    } else if ( strncmp ( currec->fields[ifld].name, "LAT",
                strlen("LAT") ) == 0 ) {
                shplat = atof ( currec->fields[ifld].data );
	    } else if ( strncmp ( currec->fields[ifld].name, "LON",
                strlen("LON") ) == 0 ) {
                shplon = atof ( currec->fields[ifld].data );
            } else if ( strncmp ( currec->fields[ifld].name, "RFC",
	        strlen("RFC") ) == 0 ) {
		strcpy ( rfcid, currec->fields[ifld].data );
		cst_lstr ( rfcid, &len, &ier );
		rfcid[len] = '\0';
	    }
	}

        iclat = (int)(ROUNDUP(shplat)*100.);
        iclon = (int)(ROUNDUP(shplon)*100.);
        if ( iclat == 0 && iclon == 0 ) {
            iclat = (int)(ROUNDUP(currec->cenlat)*100.);
            iclon = (int)(ROUNDUP(currec->cenlon)*100.);
        }

        fprintf ( tblfp, 
          "%-6.6s   %6s %-32.32s -- US %5d %6d %5d %2d %-3.3s\n",
          basid, rfcid, shrnam, iclat, iclon, 0, 0, cwanam );
    }

    cfl_clos ( tblfp, &ier );
}
Пример #17
0
void utf_ptext ( int offflg, int shift_x, int shift_y,
		 unsigned char *endof, int zm, unsigned char *ptr,
		 int *add, int *iret )
/************************************************************************
 * utf_ptext								*
 *									*
 * This function plots both regular and offset text records C5 and C8	*
 * from a UTF file.							*
 *									*
 * utf_ptext ( offflg, shift_x, shift_y, endof, zm, ptr, add, iret )	*
 *									*
 * Input parameters:							*
 *	offflg		int		Offset vs regular text flag	*
 *	shift_x		int		X shift factor			*
 *	shift_y		int		Y shift factor			*
 *	*endof		unsigned char	End of buffer			*
 *	zm		int		Zoom threshold (from user)	*
 *	*ptr		unsigned char	Position in buffer		*
 *									*
 * Output parameters:							*
 *	*add		int		Total number of bytes in record	*
 *	*iret		int		Return code			*
 *									*
 **									*
 * Log:									*
 * D. Keiser/GSC	12/96	Copied from utf_text			*
 * D. Keiser/GSC	 4/97	Corrected turbulence plot		*
 * S. Jacobs/NCEP	 4/97	Removed value from turb sym		*
 * D. Keiser/GSC	 6/97	Initialized txtwid			*
 * S. Jacobs/NCEP	 7/97	Changed font size calculation		*
 * D. Keiser/GSC	 7/97	Increased string sizes			*
 * S. Jacobs/NCEP	 8/97	Corrected PTND symbol numbers		*
 * M. Linda/GSC		10/97	Corrected the prologue format		*
 * S. Jacobs/NCEP	10/97	Changed the calling seq for gstext	*
 * I. Durham/GSC	 5/98	Changed underscore decl. to an include	*
 * S. Jacobs/NCEP	 7/98	Changed the font type and size		*
 * A. Hardy/GSC         11/00   renamed coordinate system declarations	*
 ***********************************************************************/
{
    int 		len, offset, sign, i, j, delx, dely, ixoff, g, b;
    int			iyoff, spcflg, np, ier, rb, ipnt, pltfil, bytadd;
    int			jpnt, zt, zf, chrsiz, txtwid, fntnum, txtflg, nc;
    int 		ipwwid, isktyp, iskwid, iptwid, iwtwid, ictwid;
    int			ispwid, icewid, nchr, textfg, ituwid, numpnt;
    int			idum;
    float 		sf, txtsiz, temp, rotat, rx, ry, szsky, szpwth;
    float		rcode, xl, yb, xr, yt, xl2, yb2, xr2;
    float		yt2, xrat, yrat, rdelx, rdely, szptnd, szwthr;
    float		szctyp, szspcl, szicng, szturb, xin[2], yin[2];
    float 		xout[2], yout[2];
    unsigned char 	string[200], *tmpbuf=NULL, outstr[200];
    char 		newstr[200];

    int gfunc[] = { 0000, GSKY, GSKY, GSKY, GSKY, GSKY, GSPC, GSPC,
   		    0000, 0000, 0000, 0000, 0000, 0000, GSKY, GSKY,
		    GSKY, 0000, 0000, GSKY, GSKY, GSKY, GPTN, GPTN, 
		    GPTN, GPTN, GPTN, GPTN, GWTH, GWTH, GWTH, GWTH,
		    GWTH, GWTH, GWTH, GWTH, GWTH, GWTH, GWTH, GWTH,
		    GWTH, GPWX, GWTH, GWTH, GWTH, GWTH, GWTH, GWTH,
		    GSPC, GSPC, GSPC, GSPC, GSPC, GWTH, GPWX, GWTH,
		    GSPC, GSPC, GWTH, GWTH, GWTH, GWTH, GWTH, GWTH,
		    GWTH, GWTH, GWTH, GWTH, GWTH, GWTH, GWTH, GWTH,
		    GWTH, GWTH, GWTH, GWTH, GWTH, GWTH, GWTH, GWTH,
		    GSPC, GSPC, GSPC, GWTH, GSPC, GSPC, GSPC, GSPC,
		    GWTH, GWTH, GSPC, GSPC, GSPC, GCTP, GCTP, GCTP,
		    GCTP, GCTP, GCTP, GCTP, GCTP, GCTP, GCTP, GCTP, 
		    GCTP, GCTP, GCTP, GCTP, GCTP, GCTP, GCTP, GCTP, 
		    GCTP, GCTP, GCTP, GCTP, GCTP, GCTP, GCTP, GCTP,
		    GSPC, GSPC, GTRB, GTRB, GTRB, GICE, GICE, GICE };

    int gsym[] = { 0, 6, 7, 8, 9, 10, 0, 8,
    		   0, 0, 0, 0, 0, 0, 0, 1,
		   2, 0, 0, 3, 4, 5, 999, 1999,
		   5999, 6999, 3999, 8999, 4, 5, 6, 7,
		   8, 9, 10, 11, 12, 13, 14, 15,
		   16, 9, 18, 19, 50, 60, 70, 68,
		   30, 14, 16, 15, 4, 45, 8, 31,
		   18, 17, 34, 36, 37, 38, 39, 41,
		   44, 48, 49, 52, 56, 57, 66, 67,
		   47, 58, 76, 77, 78, 79, 81, 62,
		   4, 19, 20, 43, 21, 23, 22, 24,
		   97, 72, 12, 13, 29, 11, 12, 13, 
		   14, 15, 16, 17, 18, 19, 1, 2,
		   3, 4, 5, 6, 7, 8, 9, 21,
		   22, 23, 24, 25, 26, 27, 28, 29,
		   25, 26, 2, 4, 6, 3, 5, 8 };

/*---------------------------------------------------------------------*/
    *iret = 0;
    sf = 0.25F;
    temp = 0.8F;
    fntnum = 21;
    txtflg = 2;
    ixoff = 0;
    iyoff = 0;
    rotat = 0.0F;
    delx = 0;
    dely = 0;
    txtwid = 1;

/*
**  Decode the header of the C5 or C8 record.
*/
    utf_dtext( offflg, shift_x, shift_y, zm, endof, ptr, &g, &b, &rb,
	       &zt, &pltfil, &zf, &chrsiz, &ipnt, &jpnt, &len, &bytadd,
	       &ier );
    *add = bytadd;
    ptr += 6;

/*
**  If offset text record C8, decode delta X and delta Y.
*/
    if ( offflg ) {
     	for ( i = 0; i < 2; i++, ptr++ ) {
    	    sign = *ptr & 0x80;
      	    offset = *ptr & 0x7f;
      	    if ( sign != 0 )
            	offset -= 0x80;
      	    if ( i == 0 )
	    	delx = offset << shift_x;
      	    else
	     	dely = offset << shift_y;
    	}
    }

/*
**  Query MAP and DEVICE bounds and compute X and Y ratios that
**  will adjust delta X and delta Y for zooming. Add delta X and 
**  delta Y to I, J.
*/
    gqbnd( sys_M, &xl, &yb, &xr, &yt, &ier, strlen(sys_M) );
    xin[0] = xl;
    xin[1] = xr;
    yin[0] = yb;
    yin[1] = yt;
    numpnt = 2;
    gtrans( sys_M, sys_G, &numpnt, xin, yin, xout, yout, &ier, 
					strlen(sys_M),	strlen(sys_G) );
    gqbnd( sys_D, &xl2, &yb2, &xr2, &yt2, &ier, strlen(sys_D) );
    xrat = (xout[1] - xout[0]) / (xr2 - xl2) / 2.0F;
    yrat = (yout[1] - yout[0]) / (yb2 - yt2) / 2.0F;
    rx = (float) ipnt;
    ry = (float) jpnt; 
    rdelx = (float) delx;
    rdely = (float) dely;
    rx = rx + (rdelx + 3.0F) * xrat;
    ry = ry + (rdely + 15.0F) * yrat;

    spcflg = G_FALSE;
    textfg = G_FALSE;
    nchr = 0;

/*
**  Traverse string of characters, plotting only if plot filter is true.
*/
    while ( (*ptr < 128) && (ptr < endof) ) {
	if ( pltfil ) {

/*
**	    If a cursor moving character is encountered and textfg is
**	    TRUE, build string from buffer and pass into GTEXT to be
**	    plotted.
*/
	    if ( ( *ptr == 18 ) || (( *ptr >= 8 ) && ( *ptr <= 13 ) ) ) {
		if ( textfg ) {
		    j = 0;
		    for ( i = 0; i < nchr; i++, tmpbuf++) {
		    	if ( ( *tmpbuf >= 32 ) && ( *tmpbuf < 127 ) ) {
			    string[j] = *tmpbuf;
			    j++;
			}
		    }
		    string[j] = CHNULL;
		    if  ( chrsiz < 3 )  {
			txtsiz = 1.000F;
		    }
		    else  {
			txtsiz = 1.714F;
		    }
		    idum = 0;
		    gstext( &fntnum, &txtflg, &txtsiz, &txtwid,
			    &idum, &idum, &idum, &ier );
		    cst_unpr( (char *)string, (char *)outstr, &ier );
		    strcpy(newstr, (char *) outstr);
		    cst_lstr( newstr, &nc, &ier );
		    if ( nc > 0 ) {
			gtext( sys_G, &rx, &ry, newstr, &rotat, &ixoff,
			       &iyoff, &ier, strlen(sys_G), 
			       strlen(newstr) );
			ixoff = nc * 3;
		    }
		    textfg = G_FALSE;
		    nchr = 0;
		}

/*
**		Check for special characters and set appropriate GEMPAK
**		offsets.
*/
		switch(*ptr) {

/*
**		    Back space.
*/
		    case 8:
			ixoff -= 2;
			break;

/*
**		    Forward space. 
*/
		    case 9:
			ixoff += 2;
			break;

/*
**		    Down space. 
*/
		    case 10:
			iyoff -= 2;
			break;

/*
**		    Up space. 
*/
		    case 11:
			iyoff += 2; 
			break;

/*
**		    New Line (1.5). 
*/
		    case 12:
			ixoff = 0;
			iyoff -= 3;
			break;

/*
**		    New Line (1.0). 
*/
		    case 13:
			ixoff = 0;
			iyoff -= 2;
			break;

/*
**		    Set special character flag. 
*/
		    case 18:
			spcflg = G_TRUE;	
			break;
		}
	    }

/*
**	    If a reset to regular character mode character is
**	    encountered, set the special character flag back to FALSE.
*/
	    else if ( *ptr == 17 ) {
		spcflg = G_FALSE;
	    }

/*
**	    If a special character is encountered, check it against the
**	    symbol array, and plot it according to which symbol code it
** 	    represents.
*/
	    else {
		if ( spcflg ) {
		    np = 1;
		    switch (gfunc[*ptr]) {
/*
**			Sky cover. 
*/
			case GSKY:
			    isktyp = 0;
			    iskwid = 0;
			    szsky = temp + ((float) chrsiz*sf) - 0.05F;
			    rcode = (float) gsym[*ptr];
			    gssky( &szsky, &isktyp, &iskwid, &ier );
			    gsky( sys_G, &np, &rcode, &rx, &ry, &ixoff,
				  &iyoff, &ier, strlen(sys_G) );
			    break;

/*
**			Past weather. 
*/
			case GPWX:
			    ipwwid = 0;
			    szpwth = temp + ((float) chrsiz*sf);
		    	    rcode = (float) gsym[*ptr];
		    	    gspwth( &szpwth, &ipwwid, &ier );
		    	    gpwth( sys_G, &np, &rcode, &rx, &ry, &ixoff,
				   &iyoff, &ier, strlen(sys_G) );
		    	    break;

/*
**			Pressure tendency. 
*/
			case GPTN:
			    iptwid = 0;
			    szptnd = temp + ((float) chrsiz*sf);
		    	    rcode = (float) gsym[*ptr];
			    gsptnd( &szptnd, &iptwid, &ier );
			    gptnd( sys_G, &np, &rcode, &rx, &ry, &ixoff,
				   &iyoff, &ier, strlen(sys_G) );
			    break;

/*
**			WMO weather symbols. 
*/
			case GWTH:
			    iwtwid = 0;
			    if ( gsym[*ptr] == 70 || gsym[*ptr] == 72 ) 
				szwthr = temp + ((float) chrsiz*sf) +
								0.5F;
			    else
				szwthr = temp + ((float) chrsiz*sf);
		    	    rcode = (float) gsym[*ptr];
			    gswthr( &szwthr, &iwtwid, &ier );
			    gwthr( sys_G, &np, &rcode, &rx, &ry, &ixoff,
				   &iyoff, &ier, strlen(sys_G) );
			    break;

/*
**			Cloud type. 
*/
			case GCTP:
			    ictwid = 0;
			    szctyp = temp + ((float) chrsiz*sf);
		    	    rcode = (float) gsym[*ptr];
			    gsctyp( &szctyp, &ictwid, &ier );
			    gctyp( sys_G, &np, &rcode, &rx, &ry, &ixoff,
				   &iyoff, &ier, strlen(sys_G) );
			    break;

/*
**			Special symbols. 
*/
			case GSPC:
			    ispwid = 0;
			    if ( gsym[*ptr] == 12 || gsym[*ptr] == 13 )
				szspcl = temp + ((float) chrsiz*sf) -
								0.3F;
			    else if ( gsym[*ptr] == 0 ) 
				szspcl = temp + ((float) chrsiz*sf) -
								0.4F;
			    else
				szspcl = temp + ((float) chrsiz*sf);
			    rcode = (float) gsym[*ptr];
			    gsspcl( &szspcl, &ispwid, &ier );
			    gspcl( sys_G, &np, &rcode, &rx, &ry, &ixoff,
				   &iyoff, &ier, strlen(sys_G) );
			    break;

/*
**			Turbulence. 
*/
			case GTRB:
			    ituwid = 0;
			    szturb = temp + ((float) chrsiz*sf) - 0.5F;
		    	    rcode = (float) gsym[*ptr];
			    gsturb( &szturb, &ituwid, &ier );
			    gturb( sys_G, &np, &rcode, &rx, &ry, &ixoff,
				   &iyoff, &ier, strlen(sys_G) );
			    break;

/*
**			Icing. 
*/
			case GICE:
			    icewid = 0;
			    szicng = temp + ((float) chrsiz*sf) - 0.5F;
		    	    rcode = (float) gsym[*ptr];
			    gsicng( &szicng, &icewid, &ier );
			    gicng( sys_G, &np, &rcode, &rx, &ry, &ixoff,
				   &iyoff, &ier, strlen(sys_G) );
			    break;

		    }
		    ixoff += 2;
		}

/*
**		If textfg is FALSE, place character in buffer to be used
**		in later building the string to plot.
*/
		else {
		    if ( !textfg ) {
			tmpbuf = ptr;
			textfg = G_TRUE;
		    }
		    nchr++;
		}
	    }
	}
    ptr++;
    }

/*
**  Build string from buffer and pass into GTEXT to be plotted.
*/
    if ( textfg ) {
	if ( pltfil ) {
	j = 0;
	for ( i = 0; i < nchr; i++, tmpbuf++) {
	    if ( ( *tmpbuf >= 32 ) && ( *tmpbuf < 127 ) ) {
		string[j] = *tmpbuf;
		j++;
	    }
	}
	string[j] = CHNULL;
	if  ( chrsiz < 3 )  {
	    txtsiz = 1.000F;
	}
	else  {
	    txtsiz = 1.714F;
	}
	idum = 0;
       	gstext( &fntnum, &txtflg, &txtsiz, &txtwid, 
		&idum, &idum, &idum, &ier );
	    cst_unpr( (char *)string, (char *)outstr, &ier );
	    strcpy(newstr, (char *) outstr);
	    cst_lstr( newstr, &nc, &ier );
	    if  ( nc > 0 ) {
		gtext( sys_G, &rx, &ry, newstr, &rotat, &ixoff,
		       &iyoff, &ier, strlen(sys_G), strlen(newstr) );
		ixoff = nc * 3;
	    }
	    textfg = G_FALSE;
	    nchr = 0;
	}
    }
}
Пример #18
0
void dgc_subg ( const char *ijskip, int *maxgrid, int *imll, int *jmll, 
                int *imur, int *jmur, int *iret )
/************************************************************************
 * dgc_subg								*
 *									*
 * This subroutine sets the internal subset grid given the reference	*
 * grid navigation set in GPLT and the map projection set in GPLT.	*
 * If the reference grid is globe wrapping with the addition of an	*
 * extra grid column, then the navigation set in GPLT must be that for	*
 * the grid with the extra column.					*
 * 									*
 * The subset grid is larger by five grid points than that strictly	*
 * needed to cover the map projection area.  This extension permits	*
 * more accurate computation of derivatives.  The subset grid relative	*
 * coordinates of the region strictly needed for the map are returned.	*
 * 									*
 *									*
 * IJSKIP is parsed by IN_GSKP.  IJSKIP information is entered using	*
 * the following format, where items in square brackets are optional:	*
 *									*
 *	IJSKIP = Iskip[;Istart][;Iend][/Jskip[;Jstart][;Jend]],		*
 *									*
 *	IJSKIP=Y[ES], or IJSKIP=N[O]					*
 *									*
 * The following rules apply in using IJSKIP input:			*
 *									*
 * 1.  If only Iskip is entered, then I and J skips are Iskip.  The	*
 *     beginning points and ending points are determined by querying	*
 *     the display projection to find the area on the reference grid	*
 *     needed to cover it.						*
 *									*
 * 2.  If any bounding value is omitted, it is determined automatically *
 *     by querying the display projection as in 1 above.		*
 *									*
 * 3.  If IJSKIP is blank or NO, skipping is not used to determine the	*
 *     internal grid navigation.					*
 * 									*
 * 4.  If IJSKIP is YES, all skip parameters are determined		*
 *     automatically.							*
 * 									*
 * dgc_subg ( ijskip, maxgrid, imll, jmll, imur, jmru, iret )		*
 *									*
 * Input parameters:							*
 *	*ijskip		const char	User input for skip subsetting	*
 *	*maxgrid	int		Maximum grid size               *
 *									*
 * Output parameters:							*
 *	*IMLL		int		Lower left map I bound		*
 *	*JMLL		int		Lower left map J bound		*
 *	*IMUR		int		Upper right map I bound		*
 *	*JMUR		int		Upper right map J bound		*
 * 	*IRET		int		Return code			*
 *					  0 = normal return		*
 *					-37 = no ref grid navigation set*
 *					-38 = glb wrap grd inconsistency*
 *					-39 = map projection is not set *
 *					-40 = subset grd bound error	*
 *					-41 = subset grid is too big	*
 *					-43 = cannot rearrange grid	*
 *					-44 = error set subset grid nav	*
 *					-48 = both I bounds required	*
 **									*
 * Log:									*
 * K. Brill/HPC		08/02						*
 * K. Brill/HPC		 9/02	Also initialize gparmd () to blank	*
 * S. Jacobs/NCEP	11/02	Added check for current nav vs saved nav*
 * K. Brill/HPC		11/02	Eliminate use of the SUBA logical array	*
 * K. Brill/HPC		12/02	Use IJSKIP input for subset by skipping *
 * R. Tian/SAIC		 3/04	Add check for outflg			*
 * R. Tian/SAIC		 5/04	Added call to DG_CONE			*
 * R. Tian/SAIC		 2/06	Recoded from Fortran			*
 * S. Gilbert/NCEP	 5/07	Added maxgrid argument                  *
 ************************************************************************/
{
    char gprj[5], cnum[5];
    float aglt1, agln1, aglt2, agln2, ag1, ag2, ag3, rimn, rjmn, rimx,
        rjmx, rglt[2], rgln[2], tnav[LLNNAV];
    double a, b, c;
    int lmx, mx, my, imn, jmn, imx, jmx, nx, ny, ix1, ix2, nsx, iy1, iy2,
        nsy, n, idx, idy, ichk, iadlx, iadly, iadrx, iadry, kxsg, kysg,
	kxysg, nu, mxnu, imn2, jmn2, imx2, jmx2, iadd, navsz;
    int nc, tobig, autos, angflg, navflg, done, ishf, ier, ierr, iir, i, k;

   /*
    * timing vars
    */
    struct   timeb t_gsgprj1, t_gsgprj2, t_gsgprj3, t_gqgprj1, t_gqgprj2, 
             t_gsgprj4, t_setr, t_gqbnd, t_gskp, t_gtrans1, t_mnav, t_cnav, 
             t_cone, t_current;
/*----------------------------------------------------------------------*/
    *iret = 0;
    _dgsubg.dgsubg = G_TRUE;

    for ( i = 0; i < NGDFLS; i++ ) {
	if ( _nfile.outflg[i] == G_TRUE ) {
	    *iret = -63;
	    return;
	}
    }

    /*
     * Set LMX to maximum allowed threshold for ijskip=yes
     */
    lmx = LLMXTH;

    /*
     * Set the reference grid navigation in GPLT.
     */
    cst_itos ( (int *)(&_dgsubg.refnav[1]), 1, &nc, gprj, &ier );
    cst_rmbl ( gprj, gprj, &nc, &ier );
    mx = G_NINT ( _dgsubg.refnav[4] );
    my = G_NINT ( _dgsubg.refnav[5] );
    agln1 = _dgsubg.refnav[7];
    if ( _dgfile.addcol == G_TRUE ) {
	mx += 1;
	agln2 = _dgsubg.refnav[7];
    } else {
	agln2 = _dgsubg.refnav[9];
    }
    ftime(&t_gsgprj1);
    gsgprj ( gprj, &_dgsubg.refnav[10], &_dgsubg.refnav[11], 
             &_dgsubg.refnav[12], &mx, &my, &_dgsubg.refnav[6],
	     &_dgsubg.refnav[7], &_dgsubg.refnav[8], &agln2, &ier,
	     strlen(gprj) );
    ftime(&t_current);
    if ( ier != 0 ) {
	er_wmsg ( "GEMPLT", &ier, " ", &ierr, strlen("GEMPLT"), strlen(" ") );
	*iret = -37;
	return;
    } else if ( _dgsubg.gwrapg == G_TRUE &&
        ( ! COMPAR ( agln1, agln2 ) && ! COMPAR ( (agln1+360.), agln2 ) ) ) {
	*iret = -38;
	return;
    }

    /*
     * Get the shift for re-arranging any globe wrapping grid.
     * ISHIFT is stored in DGCMN.CMN.
     */
    ftime(&t_setr);
    grc_setr ( &mx, &my, &_dgsubg.ishift, &ier );
    ftime(&t_current);
    if ( ier == -22 ) {
	*iret = -39;
	return;
    } else if ( ier != 0 ) {
	*iret = -43;
	return;
    }
    ftime(&t_gqgprj1);
    gqgprj ( gprj, &ag1, &ag2, &ag3, &mx, &my, &aglt1, &agln1, &aglt2,
             &agln2, &ier, sizeof(gprj) );
    ftime(&t_current);
    gprj[4] = '\0';
    cst_lstr ( gprj, &nc, &ier );
    gprj[nc] = '\0';

    /*
     * Get the grid index bounds for the subset grid.
     */
    ftime(&t_gqbnd);
    gqbnd ( sys_G, &rimn, &rjmn, &rimx, &rjmx, &ier, strlen(sys_D) );
    ftime(&t_current);
    if ( ier != 0 ) {
	er_wmsg ( "GEMPLT", &ier, " ", &ierr, strlen("GEMPLT"), strlen(" ") );
	*iret = -40;
	return;
    }
    imn = (int)rimn;
    jmn = (int)rjmn;
    imx = G_NINT ( rimx + .5 );
    if ( G_DIFFT((float)((int)rimx), rimx, GDIFFD) ) imx = (int)rimx;
    jmx = G_NINT ( rjmx + .5 );
    if ( G_DIFFT((float)((int)rjmx), rjmx, GDIFFD) ) jmx = (int)rjmx;
    if ( imn < 1 ) imn = 1;
    if ( jmn < 1 ) jmn = 1;
    if ( imx > mx ) imx = mx;
    if ( jmx > my ) jmx = my;
    nx = imx - imn + 1;
    ny = jmx - jmn + 1;
    if ( nx * ny > lmx ) {
        tobig = G_TRUE;
    } else {
        tobig = G_FALSE;
    }

    /*
     * Check for subsetting by skipping.
     *
     * The bounds are returned from IN_GSKP as IMISSD if
     * not provided.  The skip value returned is converted
     * to a stride value by adding one, i.e. IDX=1 means
     * no skipping, IDX=2 means skip one point.
     *
     * The mathematical relationship stating that the
     * original number of grid points from IMN to IMX must
     * equal the number of points skipped plus the number
     * kept is this:
     *
     *	    (IMX - IMN + 1) = N + (N - 1) * nskip
     *
     * where N is the number of points remaining after
     * skipping and nskip is the number of points skipped
     * between the points that are kept.
     *
     * This equation appears a number of times in various
     * forms below.
     */
    ftime(&t_gskp);
    in_gskp ( ijskip, &ix1, &ix2, &nsx, &iy1, &iy2, &nsy, &autos, &ier );
    ftime(&t_current);
    if ( ier != 0 ) {
	er_wmsg ( "IN", &ier, " ", &iir, strlen("IN"), strlen(" ") );
	*iret = -40;
	return;
    }
    if ( ix2 > mx ) {
	ier = -49;
	er_wmsg ( "DG", &ier, "I", &iir, strlen("DG"), strlen("I") );
	*iret = -40;
	return;
    } else if ( iy2 > my ) {
	ier = -49;
	er_wmsg ( "DG", &ier, "J", &iir, strlen("DG"), strlen("J") );
	*iret = -40;
	return;
    }
    if ( autos == G_TRUE && tobig == G_TRUE ) {
	a = (double)( lmx - 1 );
	b = (double)( nx + ny - 2 * lmx );
	c = (double)( lmx - nx * ny );
	n = (int)( ( b + sqrt ( b * b - 4. * a * c ) ) / ( 2. * a ) );
	nsx = n + 1;
	nsy = nsx;
	cst_inch ( nsx, cnum, &ier );
	ier = 7;
	er_wmsg ( "DG", &ier, cnum, &iir, strlen("DG"), strlen(cnum) );
    }
    idx = nsx + 1;
    idy = nsy + 1;
    if ( nsx > 0 ) {
	ichk = nx / nsx;
	if ( ichk <= 4 ) {
	    ier = 6;
	    er_wmsg ( "DG", &ier, "I", &iir, strlen("DG"), strlen("I") );
	}
    }
    if ( nsy > 0 ) {
	ichk = ny / nsy;
	if ( ichk <= 4 ) {
	    ier = 6;
	    er_wmsg ( "DG", &ier, "J", &iir, strlen("DG"), strlen("J") );
	}
    }

    /*
     * Extend the grid bounds if possible.
     */
    iadlx = 0;
    iadly = 0;
    iadrx = 0;
    iadry = 0;
    imn2 = imn;
    jmn2 = jmn;
    imx2 = imx;
    jmx2 = jmx;
    iadd = 0;
    done = G_FALSE;
    while ( done == G_FALSE && iadd < 5 ) {
	iadd += 1;
	if ( imn2 > idx ) {
	    imn2 -= idx;
	    iadlx += idx;
	}
	if ( jmn2 > idy ) {
	    jmn2 -= idy;
	    iadly += idy;
	}
	if ( imx2 < ( mx - idx ) ) {
	    imx2 += idx;
	    iadrx += idx;
	}
	if ( jmx2 < ( my - idy ) ) {
	    jmx2 += idy;
	    iadry += idy;
	}
	kxsg = G_NINT ( (float)( imx2 - imn2 + 1 + nsx ) / (float)( 1 + nsx ) );
	kysg = G_NINT ( (float)( jmx2 - jmn2 + 1 + nsy ) / (float)( 1 + nsy ) );
	kxysg = kxsg * kysg;
	if ( (kxysg > *maxgrid) && (*maxgrid != IMISSD) ) {
	    done = G_TRUE;
	    if ( imn != imn2 ) {
		imn = imn2 + idx;
		iadlx -= idx;
	    }
	    if ( jmn != jmn2 ) {
		jmn = jmn2 + idy;
		iadly -= idy;
	    }
	    if ( imx != imx2 ) {
		imx = imx2 - idx;
		iadrx -= idx;
	    }
	    if ( jmx != jmx2 ) {
		jmx = jmx2 - idy;
		iadry -= idy;
	    }
	} else {
	    imn = imn2;
	    jmn = jmn2;
	    imx = imx2;
	    jmx = jmx2;
	}
    }

    /*
     * Adjust extend margins using the stride values.
     */
    iadlx = iadlx / idx;
    iadrx = iadrx / idx;
    iadly = iadly / idy;
    iadry = iadry / idy;

    /*
     * Set the I dimension extraction bounds.  No shifting
     * is done if the user provides these bounds.  No
     * extend region is allowed if user provides bounds.
     */
    ishf = _dgsubg.ishift;
    if ( ix1 > 0 ) {
	_dgsubg.ishift = 0;
	iadlx = 0;
	imn = ix1;
    }
    if ( ix2 > 0 ) {
	_dgsubg.ishift = 0;
	iadrx = 0;
	imx = ix2;
    }
    if ( ishf != _dgsubg.ishift ) {
	if ( ix1 < 0 || ix2 < 0 ) {
	    *iret = -48;
	    return;
	}

	/*
	 * Reset the grid projection in GPLT.
	 */
	mx = G_NINT ( _dgsubg.refnav[4] );
	my = G_NINT ( _dgsubg.refnav[5] );
	agln1 = _dgsubg.refnav[7];
	if ( _dgfile.addcol == G_TRUE ) {
	    mx += 1;
	    agln2 = _dgsubg.refnav[7];
	} else {
	    agln2 = _dgsubg.refnav[9];
	}
    ftime(&t_gsgprj2);
	gsgprj ( gprj, &_dgsubg.refnav[10], &_dgsubg.refnav[11], 
	    &_dgsubg.refnav[12], &mx, &my, &_dgsubg.refnav[6],
	    &_dgsubg.refnav[7], &_dgsubg.refnav[8], &agln2, &ier,
	    strlen(gprj) );
    ftime(&t_current);
    ftime(&t_gqgprj2);
	gqgprj ( gprj, &ag1, &ag2, &ag3, &mx, &my, &aglt1, &agln1, 
	    &aglt2, &agln2, &ier, sizeof(gprj) );
    ftime(&t_current);
    if ( diagClbkPtr != NULL )
	gprj[4] = '\0';
	cst_lstr ( gprj, &nc, &ier );
	gprj[nc] = '\0';
	ierr = 5;
	er_wmsg ( "DG", &ierr, " ", &ier, strlen("DG"), strlen(" ") );
    }

    /*
     * Adjust IMX and IMN for skipping.
     */
    if ( idx > 1 ) {
	nu = G_NINT ( (float)( imx - imn + 1 + nsx ) / (float)( 1 + nsx ) );
	mxnu = nu * ( 1 + nsx ) + imn - 1 - nsx;
	if ( mxnu > ( mx - idx ) && mxnu != ix2 ) {
	    mxnu = mx;
	    imn = mxnu - nu * ( 1 + nsx ) + 1 + nsx;
	    if ( imn < 1 ) {
		/*
		 * Start at 1 when full range is needed.
		 */
		imn = 1;
		nu = ( mxnu - imn + 1 + nsx ) / ( 1 + nsx );
		mxnu = nu * ( 1 + nsx ) + imn - 1 - nsx;
	    }
	}
	imx = mxnu;
	if ( ( ix2 > 0 && imx != ix2 ) || 
	     ( ix1 > 0 && imn != ix1 ) ) {
	    ierr = 4;
	    er_wmsg ( "DG", &ierr, "I", &ier, strlen("DG"), strlen("I") );
	}
    }

    /*
     * Set the J dimension extraction bounds. No extend
     * region is allowed if user provides bounds.
     */
    if ( iy1 > 0 ) {
	iadly = 0;
	jmn = iy1;
    }
    if ( iy2 > 0 ) {
	iadry = 0;
	jmx = iy2;
    }

    /*
     * Adjust JMX and JMN for skipping.
     */
    if ( idy > 1 ) { 
	nu = G_NINT ( (float)( jmx - jmn + 1 + nsy ) / (float)( 1 + nsy ) );
	mxnu = nu * ( 1 + nsy ) + jmn - 1 - nsy;
	if ( mxnu > ( my - idy ) && mxnu != iy2 ) {
	    mxnu = my;
	    jmn = mxnu - nu * ( 1 + nsy ) + 1 + nsy;
	    if ( jmn < 1 ) {
		/*
		 * Start at 1 when full range is needed.
		 */
		jmn = 1;
		nu = ( mxnu - jmn + 1 + nsy ) / ( 1 + nsy );
		mxnu = nu * ( 1 + nsy ) + jmn - 1 - nsy;
	    }
	}
	jmx = mxnu;
	if ( ( iy2 > 0 && jmx != iy2 ) || ( iy1 > 0 && jmn != iy1 ) ) {
	    ierr = 4;
	    er_wmsg ( "DG", &ierr, "J", &ier, strlen("DG"), strlen("J") );
	}
    }

    /*
     * Compute subset grid final dimensions.
     */
    kxsg = ( imx - imn + 1 + nsx ) / ( 1 + nsx );
    kysg = ( jmx - jmn + 1 + nsy ) / ( 1 + nsy );
    if ( kxsg <= 0 || kysg <= 0 ) {
	*iret = -40;
	return;
    }
    kxysg = kxsg * kysg;
	

    /*
     * Set common block subset coordinates on reference grid.
     */
    _dgsubg.jsgxmn = imn;
    _dgsubg.jsgymn = jmn;
    _dgsubg.jsgxmx = imx;
    _dgsubg.jsgymx = jmx;
    _dgsubg.jsgxsk = idx;
    _dgsubg.jsgysk = idy;

    /*
     * Set DG_HILO area bounds on subset grid.
     */
    _dgarea.kgxmin = iadlx + 1;
    _dgarea.kgymin = iadly + 1;
    _dgarea.kgxmax = kxsg - iadrx;
    _dgarea.kgymax = kysg - iadry;

    /*
     * Strict map bounds are same as above.
     */
    *imll = _dgarea.kgxmin;
    *jmll = _dgarea.kgymin;
    *imur = _dgarea.kgxmax;
    *jmur = _dgarea.kgymax;

    /*
     * Set the DGAREA common grid bounds calculation flag.
     */
    _dgarea.jgxmin = 1;
    _dgarea.jgxmax = kxsg;
    _dgarea.jgymin = 1;
    _dgarea.jgymax = kysg;
    _dgarea.ksub1 = 1;
    _dgarea.ksub2 = kxysg;

    /*
     * Compute grid size and maximum number of internal grids
     * for the common block.
     */
    if ( (kxysg > *maxgrid) && (*maxgrid != IMISSD) ) {
	/*
	 * Here is the future location to set up some other
	 * remapping.
	 */
	*iret = -41;
	return;
    }

    _dgfile.kxd = kxsg;
    _dgfile.kyd = kysg;
    _dgfile.kxyd = kxysg;
    _dggrid.maxdgg = NDGRD;

    /*
     * Compute the navigation of the internal (subset) grid.
     */
    strcpy ( _dgfile.cprj, gprj );
    rglt[0] = _dgsubg.jsgxmn;
    rgln[0] = _dgsubg.jsgymn;
    rglt[1] = _dgsubg.jsgxmx;
    rgln[1] = _dgsubg.jsgymx;
    nc = 2;
    ftime(&t_gtrans1);
    gtrans ( sys_G, sys_M, &nc, rglt, rgln, rglt, rgln, &ier,
        strlen(sys_G), strlen(sys_M) );
    ftime(&t_current);
    if ( G_ABS ( rgln[0] - 180. ) < .01 || G_ABS ( rgln[0] + 180. ) < .01 )
        rgln[0] = -180.;
    if ( G_ABS ( rgln[1] - 180. ) < .01 || G_ABS ( rgln[1] + 180. ) < .01 )
        rgln[0] = 180.;
    if ( G_ABS ( rgln[0] - rgln[1]) < 0.01 )
        rgln[1] = rgln[0];
    ftime(&t_gsgprj3);
    gsgprj ( _dgfile.cprj, &ag1, &ag2, &ag3, &_dgfile.kxd, &_dgfile.kyd, 
        &rglt[0], &rgln[0], &rglt[1], &rgln[1], &ier, strlen(_dgfile.cprj) );
    ftime(&t_current);
    if ( ier != 0 ) {
	if ( _dgsubg.gwrapg == G_TRUE) {
	    ag2 += 180.;
	    if ( ag2 >= 360. ) ag2 -= 360.;
    ftime(&t_gsgprj4);
	    gsgprj ( _dgfile.cprj, &ag1, &ag2, &ag3, &_dgfile.kxd, &_dgfile.kyd,
		&rglt[0], &rgln[0], &rglt[1], &rgln[1], &ier,
		strlen(_dgfile.cprj) ) ;
    ftime(&t_current);
	if ( ier != 0 ) {
		*iret = -44;
		return;
	    }
	} else {
	    *iret = -44;
	    return;
	}
    }
    angflg = G_TRUE;
    ftime(&t_mnav);
    grc_mnav ( _dgfile.cprj, &_dgfile.kxd, &_dgfile.kyd, &rglt[0], &rgln[0],
	&rglt[1], &rgln[1], &ag1, &ag2, &ag3, &angflg, tnav, &ier );
    ftime(&t_current);

    /*
     * Check the current navigation against the saved navigation.
     * If they are different, then set the navigation flag to False.
     */
    navsz = LLNNAV;
    ftime(&t_cnav);
    grc_cnav ( tnav, _dgfile.snav, &navsz, &navflg, &ier );
    ftime(&t_current);

    /*
     * Save the current navigation.
     */
    for ( k = 0; k < LLNNAV; k++ ) {
	_dgfile.snav[k] = tnav[k];
    }

    db_retsubgcrs (_dgfile.cprj, _dgfile.kxd, _dgfile.kyd, rglt[0], rgln[0],
                       rglt[1], rgln[1],ag1, ag2, ag3,&ier); 
    /*
     * Set the constant of the cone for various projections (code
     * duplicated from UPDCON.FOR in GEMPLT).
     */
    _dgfile.anglr1 = ag1 * DTR;
    _dgfile.anglr2 = ag2 * DTR;
    _dgfile.anglr3 = ag3 * DTR;
    ftime(&t_cone);
    dg_cone ( _dgfile.cprj, &_dgfile.anglr1, &_dgfile.anglr3,
    	      &_dgfile.concon, iret );
    ftime(&t_current);

    /*
     * Set lat/lon,  map scale factor, and rotation matrix
     * internal grid pointers to zero.
     */
    _dgfile.idglat = 0;
    _dgfile.idglon = 0;
    _mapscl.ixmscl = 0;
    _mapscl.iymscl = 0;
    _mapscl.ixmsdy = 0;
    _mapscl.iymsdx = 0;
    _dgrtwd.irtcos = 0;
    _dgrtwd.irtsin = 0;
    _dglndc.lndsea = 0;

    /*
     * Initialize orientation angle.
     */
    _dgovec.ornang = RMISSD;

    /*
     * Free all existing grids since navigation is changed.
     */
    if ( navflg == G_FALSE ) {
        dg_fall ( &ier );
    }

    /*
     * Initialize the origin for M calculation.
     */
    _dgorig.orglat = RMISSD;
    _dgorig.orglon = RMISSD;
    _dgorig.orgxpt = RMISSD;
    _dgorig.orgypt = RMISSD;

    /*
     * Since there were no errors, set flag saying dg package has
     * been initialized.
     */
    _dgfile.dgset = G_TRUE;

    /*
     * Initialize the pointer in the internal grid arrays.
     */
    _dggrid.idglst = 0;

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

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

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

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

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

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

        n  = 0;
        while ( n < nr ) {

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

	    cst_lstr (  buffer, &blen, &ier );

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

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

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

            n++;
        }

        cfl_clos(fp, &ier);

}
Пример #20
0
static void tbl_mzcn ( shp_record *shprec, int numrec, int *iret )
/************************************************************************
 * tbl_mzcn                                                             *
 *                                                                      *
 * This function creates the combined county and marine station tables.	*
 *                                                                      *
 * tbl_mzcn ( shprec, numrec, iret )                            	*
 *                                                                      *
 * Input parameters:                                                    *
 *      *shprec         shp_record  	Shape record list		*
 *	numrec		int		Total number of records		*
 *                                                                      *
 * Output parameters:                                                   *
 *      *iret           int             Return code                     *
 *                                        0 = Normal                    *
 **                                                                     *
 * Log:                                                                 *
 * R. Tian/SAIC          3/04   Initial coding                  	*
 * S. Jacobs/NCEP	 3/11	Changed header keys for determining	*
 * 				the type of file - county or marine	*
 * X.Guo/CWS             9/11   Increased fulname size and chnaged      *
 *                              SHAPE_LENG to COUNTYNAME                *
 ***********************************************************************/
{
    shp_record *currec;
    /*
     * The array size is from the Costal Marine Zones and AWIPS Counties
     * attributes specification.
     */
    char fulnam[500], shrnam[33], cwanam[10], stabbr[3];
    int ifips, istno, izone, ilat, ilon;
    int irec, jfld, kfld, pos, len, ier;
    char *stntbl = MZCNTYTBL, *namtbl = MZCNTYNAMTBL; 
    float shplat, shplon;
    FILE *tblfp, *namfp;
/*---------------------------------------------------------------------*/
    *iret = 0;

    tblfp = cfl_wopn ( stntbl, &ier );
    if ( ier != 0 ) {
        fprintf ( stderr, "File %s open failed.\n", stntbl );
        exit ( -1 );
    }
    namfp = cfl_wopn ( namtbl, &ier );
    if ( ier != 0 ) {
        fprintf ( stderr, "File %s open failed.\n", namtbl );
        exit ( -1 );
    }

    for ( currec = shprec, irec = 0; irec < numrec;
        irec++, currec = currec->nxtrec ) {

        for ( jfld = 0; jfld < currec->numfld; jfld++ ) {
            if ( strncmp ( currec->fields[jfld].name, "COUNTYNAME",
                strlen("COUNTYNAME") ) == 0 ) {
                /*
                 * County.
                 */
                for ( kfld = 0; kfld < currec->numfld; kfld++ ) {
                    if ( strncmp ( currec->fields[kfld].name, 
		        "COUNTYNAME", strlen("COUNTYNAME") ) == 0 ) {
                        strcpy ( fulnam, currec->fields[kfld].data );
			cst_lstr ( fulnam, &len, &ier );
			fulnam[len] = '\0';
                        cst_rspc ( fulnam, &ier );
                        abbreviate ( fulnam, 32, shrnam, &ier );

                        /*
                         * Remove "City_of_" from county name
                         */
                        cst_rmst ( shrnam, "City_of_", &pos,
                                   shrnam, &ier );

                        /*
                         * Remove "Lower_Keys_in_" from county name
                         */
                        cst_rmst ( shrnam, "Lower_Keys_in_", &pos,
                                   shrnam, &ier );

                        /*
                         * Remove "Outer_Banks_" from county name
                         */
                        cst_rmst ( shrnam, "Outer_Banks_", &pos,
                                   shrnam, &ier );

                        /*
                         * Remove "Mainland_" from county name
                         */
                        cst_rmst ( shrnam, "Mainland_", &pos,
                                   shrnam, &ier );
                    } else if ( strncmp ( currec->fields[kfld].name, 
		        "STATE", strlen ( "STATE" ) ) == 0 ) {
                        strcpy ( stabbr, currec->fields[kfld].data );
                    } else if ( strncmp ( currec->fields[kfld].name, 
		        "CWA", strlen ( "CWA" ) ) == 0 ) {
                        strcpy ( cwanam, currec->fields[kfld].data );
			cst_lstr ( cwanam, &len, &ier );
			cwanam[len] = '\0';
                    } else if ( strncmp ( currec->fields[kfld].name, 
		        "FIPS", strlen("FIPS") ) == 0 ) {
                        ifips = atoi ( currec->fields[kfld].data );
	            } else if ( strncmp ( currec->fields[kfld].name, 
		        "LAT", strlen("LAT") ) == 0 ) {
                        shplat = atof ( currec->fields[kfld].data );
	            } else if ( strncmp ( currec->fields[kfld].name, 
		        "LON", strlen("LON") ) == 0 ) {
                        shplon = atof ( currec->fields[kfld].data );
                    }
                }
                if ( strlen ( shrnam ) == (size_t)0 || strlen ( stabbr ) == (size_t)0 ) {
                    continue;
                }
	        if ( ERMISS ( currec->cenlat ) || 
		     ERMISS ( currec->cenlon ) ) {
	            ilat = (int)(ROUNDUP(shplat)*100.);
	            ilon = (int)(ROUNDUP(shplon)*100.);
	        } else {
	            ilat = (int)(ROUNDUP(currec->cenlat)*100.);
	            ilon = (int)(ROUNDUP(currec->cenlon)*100.);
	        }

                fprintf ( tblfp,
            "%2.2sC%3.3d   %6d %-32.32s %2.2s US %5d %6d %5d %2d %-3.3s\n",
                stabbr, ifips%1000, ifips, shrnam, stabbr,
                 ilat, ilon, 0, 0, cwanam );
            } else if ( strncmp ( currec->fields[jfld].name, "NAME",
                strlen("NAME") ) == 0 ) {
                /*
                 * Marine.
                 */
                for ( kfld = 0; kfld < currec->numfld; kfld++ ) {
                    if ( strncmp ( currec->fields[kfld].name, "ID",
                        strlen("ID") ) == 0 ) {
                        strcpy ( shrnam, currec->fields[kfld].data );
                        strncpy ( stabbr, currec->fields[kfld].data, 2 );
                        stabbr[2] = '\0';
                        izone = atoi ( currec->fields[kfld].data + 3 );
                        for ( istno = 0; istno < NUMSTNO; istno++ ) {
                            if ( strncmp ( stateno[istno], stabbr, 2 ) 
			        == 0 ) {
                                break;
                            }
                        }
                        ifips = istno * 10000 + izone * 10;
                    } else if ( strncmp ( currec->fields[kfld].name, 
		        "WFO", strlen ( "WFO" ) ) == 0 ) {
                        strcpy ( cwanam, currec->fields[kfld].data );
                    } else if ( strncmp ( currec->fields[kfld].name, 
		        "NAME", strlen ( "NAME" ) ) == 0 ) {
                        strcpy ( fulnam, currec->fields[kfld].data );
			cst_lstr ( fulnam, &len, &ier );
			fulnam[len] = '\0';
                        cst_rspc ( fulnam, &ier );
	            } else if ( strncmp ( currec->fields[kfld].name, 
		        "LAT", strlen("LAT") ) == 0 ) {
                        shplat = atof ( currec->fields[kfld].data );
	            } else if ( strncmp ( currec->fields[kfld].name, 
		        "LON", strlen("LON") ) == 0 ) {
                        shplon = atof ( currec->fields[kfld].data );
                    }
                } 

	        if ( ERMISS ( currec->cenlat ) || 
		     ERMISS ( currec->cenlon ) ) {
	            ilat = (int)(ROUNDUP(shplat)*100.);
	            ilon = (int)(ROUNDUP(shplon)*100.);
	        } else {
	            ilat = (int)(ROUNDUP(currec->cenlat)*100.);
	            ilon = (int)(ROUNDUP(currec->cenlon)*100.);
	        }

                fprintf ( tblfp,
                 "%6.6s   %6d %-32.32s %2.2s US %5d %6d %5d %2d %-3.3s\n",
                 shrnam, ifips, shrnam, stabbr, ilat, ilon, 0, 0, cwanam );
                fprintf (namfp, "%s %s\n", shrnam, fulnam );
            }
        }
    }

    cfl_clos ( tblfp, &ier );
    cfl_clos ( namfp, &ier );
}
Пример #21
0
void na_gnav ( const char *proj, const char *kxky, const char *gdarea,
               char *cprj, int *kx, int *ky,  float *grdout,
	       float *rnvblk, int *iret )
/************************************************************************
 * na_gnav								*
 *									*
 * This subroutine takes the user input for PROJ and KXKY and 		*
 * makes a grid navigation block.    					*
 *									*
 * na_gnav ( proj, kxky, gdarea, cprj, kx, ky, grdout, rnvblk, iret )	*
 *									*
 * Input parameters:							*
 *	*proj		const char	User input for PROJ		*
 *	*kxky		const char	User input for KXKY		*
 *	*gdarea		const char	User input for GDAREA		*
 *									*
 * Output parameters:							*
 *	*cprj		char		Grid projection			*
 *	*kx		int		Number of points in x dir	*
 *	*ky		int		Number of points in y dir	*
 *	*grdout		float		Grid corners			*
 *	*rnvblk		float		Grid navigation block		*
 *	*iret		int		Return code			*
 *					  0 = normal return		*
 *					 -4 = invalid navigation	*
 *					 -5 = invalid grid area		*
 *					 -6 = invalid grid size		*
 **									*
 * Log:									*
 * S. Jacobs/EAI	 7/93	Copied from GDCNAV			*
 * G. Krueger/EAI	 6/96	Add default projection			*
 * R. Tian/SAIC		 7/06	Recoded from Fortran			*
 * S. Gilbert/NCEP      10/06   Added call to GR_VNAV                   *
 ************************************************************************/
{
    char cdproj[31], tprj[31];
    float zmarg[4], rarr[2], rltln[4], angle[3], centrd[2],
          angle1, angle2, angle3, xspace, yspace;
    int angflg, space, valid;
    int iarr[2], len, num, ier, ier1, i;
/*----------------------------------------------------------------------*/
    *iret = 0;

    /*
     * Translate grid projection information.
     */
    gg_proj ( proj, tprj, angle, zmarg, &angflg, &ier,
              strlen(proj), sizeof(tprj) );
    tprj[30] = '\0';
    cst_lstr ( tprj, &len, &ier1 );
    tprj[len] = '\0';
    strcpy ( cprj, tprj );
    angle1 = angle[0];
    angle2 = angle[1];
    angle3 = angle[2];

    /*
     * Check for error.
     */
    if ( ier != 0 ) {
	er_wmsg ( "GG", &ier, (char *)proj, &ier1,
	          strlen("GG"), strlen(proj) );
	*iret = -4;
	return;
    }

    /*
     * Translate grid area.
     */
    lc_gare ( (char *)gdarea, rltln, tprj, centrd, &ier,
              strlen(gdarea), sizeof(tprj) );
    tprj[30] = '\0';
    cst_lstr ( tprj, &len, &ier1 );
    tprj[len] = '\0';
    strcpy ( cdproj, tprj );
    if ( ier != 0 ) {
	*iret = -5;
	er_wmsg ( "NAGRIB", iret, (char *)gdarea, &ier,
	          strlen("NAGRIB"), strlen(gdarea) );
	return;
    }

    /*
     * Translate the input for KXKY.
     */
    if ( ( strcmp ( cprj, "CED" ) == 0 ) && ( kxky[0] == '#' ) ) {
	space = G_TRUE;
    } else {
	space = G_FALSE;
    }

    /*
     * Check for input as grid spacing.
     */
    if ( space == G_TRUE ) {
	/*
	 * Get x- and y- spacing and check that there are two numbers.
	 */
	cst_rlst  ( (char *)&kxky[1], ';', 0., 2, rarr, &num, &ier );
	if ( ( rarr[0] <= 0. ) || ( rarr[1] <= 0. ) ) {
	    *iret = -6;
	    er_wmsg ( "NAGRIB", iret, " ", &ier,
	              strlen("NAGRIB"), strlen(" ") );
	    return;
	} else {
	    xspace = rarr[0];
	    yspace = rarr[1];
	}

	/*
	 * Align on grid points and exit for error.
	 */
	grc_algn ( rltln, &xspace, &yspace, grdout, kx, ky, iret );
	if ( *iret != 0 ) {
	    er_wmsg ( "GR", iret, " ", &ier, strlen("GR"), strlen(" ") );
	    *iret = -4;
	    return;
	}

    /*
     * Otherwise, find kx, ky.
     */
    } else {
	for ( i = 0; i < 4; i++ ) {
	    grdout[i] = rltln[i];
	}

	/*
	 * Get two numbers and check for error.
	 */
	cst_ilst ( (char *)kxky, ';', 0, 2, iarr, &num, &ier );
	*kx = iarr[0];
	*ky = iarr[1];
	if ( ( *kx < 2 ) || ( *ky < 2 ) ) {
	    *iret = -6;
	    er_wmsg ( "NAGRIB", iret, " ", &ier,
	              strlen("NAGRIB"), strlen(" ") );
	    return;
	}
    }

    /*
     * Fill navigation block.
     */
    gr_vnav  ( cprj, kx, ky, &grdout[0], &grdout[1], &grdout[2], &grdout[3],
               &angle1, &angle2, &angle3, &angflg, &valid, &ier, strlen(cprj) );

    if ( ier == 0 )
       grc_mnav  ( cprj, kx, ky, &grdout[0], &grdout[1], &grdout[2], &grdout[3],
                   &angle1, &angle2, &angle3, &angflg, rnvblk, &ier );
    else
       *iret = -2;

    return;
}
Пример #22
0
static void bnd_rfcr ( shp_record *onerec, char *header, char *subhdr,
                  char *hdrnam, float *cenlat, float *cenlon, int *iret )
/************************************************************************
 * bnd_rfcr                                                             *
 *                                                                      *
 * This function generates the river forecast center regions bound	*
 * header and sub-header lines.						*
 *                                                                      *
 * bnd_rfcr ( onerec, header, subhdr, hdrnam, cenlat, cenlon, iret )    *
 *                                                                      *
 * Input parameters:                                                    *
 *      *onerec         shp_record      One shape record               	*
 *                                                                      *
 * Output parameters:                                                   *
 *	*header		char		Bound header line		*
 *	*subhdr		char		Bound sub-header line		*
 *	*hdrnam		char		Bound header name    		*
 *	*cenlat		float		Center latitude			*
 *	*cenlon		float 		Center longitude		*
 *      *iret           int             Return code                     *
 *                                        0 = Normal                    *
 *                                        1 = Incomplete record         *
 **                                                                     *
 * Log:                                                                 *
 * R. Tian/SAIC          2/05           Initial coding                  *
 ***********************************************************************/
{
    /*
     * The array size is from the river forecast center regions
     * attributes specification.
     */
    char basnid[6], rfcnam[19];
    int iclat, iclon, nparts, ifld, len, ier;
    static int seqnum = 0;
/*---------------------------------------------------------------------*/
    *iret = 0;

    seqnum++;
    nparts = onerec->numprt;
    for ( ifld = 0; ifld < onerec->numfld; ifld++ ) {
        if ( strncmp ( onerec->fields[ifld].name, "BASIN_ID",
	    strlen("BASIN_ID") ) == 0 ) {
	    strncpy ( basnid, onerec->fields[ifld].data, 5 );
	    basnid[5] = '\0';
	    cst_lstr ( basnid, &len, &ier );
	    basnid[len] = '\0';
        } else if ( strncmp ( onerec->fields[ifld].name, "RFC_NAME",
	    strlen("RFC_NAME") ) == 0 ) {
	    strncpy ( rfcnam, onerec->fields[ifld].data, 18 );
	    rfcnam[18] = '\0';
	    cst_lstr ( rfcnam, &len, &ier );
	    rfcnam[len] = '\0';
	    cst_rspc ( rfcnam, &ier );
        }
    }

    iclat = (int)(ROUNDUP(onerec->cenlat)*100.);
    iclon = (int)(ROUNDUP(onerec->cenlon)*100.);
    *cenlat = onerec->cenlat;
    *cenlon = onerec->cenlon;

    sprintf ( header, "B%5.5d %-32.32s %5d %6d %3d %s",
              seqnum, basnid, iclat, iclon, nparts, basnid );
    sprintf ( subhdr, "<RFC>%s<RFC_NAME>%s", basnid, rfcnam );
    sprintf ( hdrnam, "%s", basnid );
}
Пример #23
0
void dg_prft ( const char *time1, const char *time2, const int *level1,
               const int *level2, const int *ivcord, const char *parm,
	       int *num, int *iret )
/************************************************************************
 * dg_prft								*
 *									*
 * This subroutine accumulates precipitation over a given time period.	*
 * The time period is hh hours given in the parameter name which has	*
 * the form PhhM or PhhI.  Conversions to inches or millimeters will	*
 * be automatic.							*
 *									*
 * The following assumptions are made:					*
 *									*
 *	1.  The precipitation totals exist at forecast times		*
 *	    at regular intervals in whole hours.			*
 *									*
 *	2.  At regular intervals the precipitation is given for		*
 *	    the entire interval.  This is a major interval.		*
 *									*
 *	3.  At regular subintervals within the major intervals,		*
 *	    the precipitation is accumulated since the start of		*
 *	    the major interval.						*
 *									*
 * dg_prft ( time1, time2, level1, level2, ivcord, parm, num, iret )    *
 *									*
 * Input parameters:							*
 *      *time1          const char      Date/time                       *
 *      *time2          const char      Date/time                       *
 *      *level1         const int       Level                           *
 *      *level2         const int       Level                           *
 *      *ivcord         const int       Vertical coordinate             *
 *      *parm           const char      Parameter name                  *
 *									*
 * Input and output parameters:						*
 *      *num            int             Location of grid                *
 *									*
 * Output parameters:							*
 *      *iret           int             Return code                     *
 *					  0 = normal return		*
 *					 -7 = grid cannot be found	*
 **									*
 * Log:									*
 * K. Brill/NMC		10/92						*
 * K. Brill/NMC		 2/93	Use first character of parm 		*
 * M. desJardins/NMC	 7/92	DG_UHDR --> DG_UPSG			*
 * K. Brill/NMC		11/93	Take care of negative precip		*
 * M. desJardins/NMC	 3/94	Reorganize				*
 * S. Jacobs/NMC	10/94	Check for parms w/ PR which aren't rates*
 * K. Brill/NMC		 5/95	Add 3-h major interval			*
 * T. Lee/GSC		 4/96	Single dimension for dgg		*
 * K. Brill/HPC		11/02	Eliminate use of the SUBA logical array	*
 * K. Brill/HPC		 2/03	Call DG_FRIG to free internal grids	*
 * T. Lee/SAIC		10/03	Increased temporal resolution for hrly	*
 * T. Lee/SAIC		 1/04	Handled Canadian precip. grids		*
 * R. Tian/SAIC		 1/05	Fixed bug for GFS data			*
 * S. Jacobs/NCEP	 9/05	Fixed counter when in CANADIAN mode	*
 * R. Tian/SAIC          2/06   Recoded from Fortran                 	*
 * S. Jacobs/NCEP	 8/09	Added 1hr to major interval list	*
 ************************************************************************/
{
    /*
     * Set possible subinterval accumulation periods.
     */
    char cdt[NDT][3] = { "03", "06", "09", "12", "01", "02",
			 "04", "05", "07", "08", "10", "11", 
			 "24", "48" };
    int idt[NDT]     = {  3,    6,    9,    12,   1,    2,
    			  4,    5,    7,    8,    10,   11,
			  24,   48 };
    /*
     * Set possible major interval lengths (hours).
     */
    char cdtm[NDTM][4] = { "01", "03", "06", "12", "24" };
    int idtm[NDTM]     = {   1,    3,    6,   12,   24 };

    char thold[5], pnum[14], fstchr, lstchr, accum[73], ftype, ftime[4],
        time21[21], time22[21];
    float rmult, signp;
    int intdtf[3], jvcord, iacc, lenstr, ihrs, ihhlst, iptime, lenst,
        numsub, nummaj, majts, iz, itet, i, ier, ierr;
    int done;
/*----------------------------------------------------------------------*/
    *iret = -7;

    /*
     * Set the vertical coordinate to missing since it can be ignored.
     */
    jvcord = -1;

    /*
     * Check to see if precipitation rate is requested.  If so,
     * check for the data immediately.
     */
    if ( strncmp ( parm, "PR", 2 ) == 0 ) {
	strcpy ( accum, &parm[2] );
	cst_numb ( accum, &iacc, &ierr );
	if ( ierr == 0 ) {
	    dg_grdr ( time1, time2, level1, level2, &jvcord, parm, num, iret );
	}
	return;
    }

    /*
     * Check that precipitation in form P|S|C nnn I|M has been requested.
     */
    cst_lstr ( (char *)parm, &lenstr, &ier );
    if ( lenstr <= 2 ) return;
    fstchr = parm[0];
    if ( ( fstchr != 'P' ) && ( fstchr != 'S' ) && ( fstchr != 'C' ) ) return;
    lstchr = parm[lenstr-1];
    if ( ( lstchr != 'I' ) && ( lstchr != 'M' ) ) return;

    /*
     * Get number of hours for the precipitation accumulation.
     */
    strncpy ( pnum, &parm[1], lenstr - 2 );
    pnum[lenstr-2] = '\0';
    cst_numb ( pnum, &ihrs, &ier );
    if ( ier != 0 ) return;

    /*
     * Check to see if precipitation can be found as a rate or as a
     * combination of P, S, C precipitation values.
     */
    dg_prcp ( time1, time2, level1, level2, &jvcord, parm, num, iret );
    if ( *iret == 0 ) return;

    /*
     * Get the forecast time for this grid.
     */
    tg_ctoi ( (char *)time1, intdtf, &ier, strlen(time1) );
    if ( intdtf[2] == 0 ) return;

    /*
     * Read data based on forecast hours (for Canadian data)
     */
    ctg_cftm ( intdtf[2], &ftype, ftime, &ier );
    if ( ftime[0] == '0' ) { 
	pnum[0] = fstchr;
	strcpy ( &pnum[1], &ftime[1] );
	lenstr = strlen ( pnum );
	pnum[lenstr] = lstchr;
	pnum[lenstr+1] = '\0';
    } else {
	pnum[0] = fstchr;
	strcpy ( &pnum[1], ftime );
	lenstr = strlen ( pnum );
	pnum[lenstr] = lstchr;
	pnum[lenstr+1] = '\0';
    }
    dg_prcp ( time1, time2, level1, level2, &jvcord, pnum, num, &ier );

    /*
     * Get the accumulation at present time, over x hours, where
     * x is to be determined by looping over the possiblities.
     */
    if ( ier != 0 ) {
	i = -1;
	while ( ( ier != 0 ) && ( i < NDT - 1 ) ) {
	    i++;
	    if ( idt[i] != ihrs ) {
		pnum[0] = fstchr;
		strcpy ( &pnum[1], cdt[i] );
		lenstr = strlen ( pnum );
		pnum[lenstr] = lstchr;
		pnum[lenstr+1] = '\0';
		dg_prcp ( time1, time2, level1, level2, &jvcord, pnum,
		          num, &ier );
	    }
	}

	/*
	 * If some value for precipitation was found, check the number 
	 * of hours accumulated.
	 */
	if ( ier == 0 ) {
	    ihhlst = idt[i];
	} else {
	    return;
	}
    } else {
	cst_numb ( ftime, &ihhlst, iret );
    }

    strcpy ( time22, time2 );
    if ( ihhlst > ihrs ) {
	/*
	 * Go back IHRS hours, get the accumulation at that
	 * forecast time and subtract.
	 */
	intdtf[2] = intdtf[2] - ihrs * 100;
	ctg_itoc ( intdtf, time21, &ier );
	iptime = ihhlst - ihrs;
	cst_inch ( iptime, thold, &ier );
	cst_lstr ( thold, &lenst, &ier );
	if ( lenst == 1 ) {
	    pnum[0] = fstchr;
	    pnum[1] = '0';
	    pnum[2] = thold[0];
	    pnum[3] = lstchr;
	    pnum[4] = '\0';
	} else {
	    pnum[0] = fstchr;
	    strcpy ( &pnum[1], thold );
	    lenstr = strlen ( pnum );
	    pnum[lenstr] = lstchr;
	    pnum[lenstr+1] = '\0';
	}
	dg_nxts ( &numsub, &ier );
	dg_prcp ( time21, time22, level1, level2, &jvcord, pnum,
	          &numsub, iret );
	if ( *iret == 0 ) {
	    rmult = -1.;
	    pd_prcp ( _dggrid.dgg[(*num)-1].grid, _dggrid.dgg[numsub-1].grid,
		&rmult, &_dgfile.kxyd, _dggrid.dgg[(*num)-1].grid, &ier );
	}
	dg_frig ( &numsub, &ier );
    } else {
	/*
	 * Accumulate the precipitation.  Total elapsed time is itet.
	 */
	itet = ihhlst;
	dg_nxts ( &nummaj, &ier );
	done = G_FALSE;
	while ( done == G_FALSE ) {
	    /*
	     * Go back IHHLST hours, get accum. and sum it in.
	     */
	    intdtf[2] = intdtf[2] - ihhlst * 100;
	    ctg_itoc ( intdtf, time21, &ier );

	    /*
	     * Determine the major time step.
	     */
	    ier = 999;
	    i = -1;
	    while ( ( ier != 0 ) && ( i < NDTM - 1 ) ) {
		i++;
		pnum[0] = fstchr;
		strcpy ( &pnum[1], cdtm[i] );
		lenstr = strlen ( pnum );
		pnum[lenstr] = lstchr;
		pnum[lenstr+1] = '\0';
		dg_prcp ( time21, time22, level1, level2, &jvcord,
		          pnum, &nummaj, &ier );
	    }
	    if ( ier != 0 ) {
		*iret = -7;
		dg_frig ( &nummaj, &ier );
		return;
	    }
	    majts = idtm[i];

	    /*
	     * Add in the accumulation.
	     */
	    signp = 1.;
	    pd_prcp ( _dggrid.dgg[(*num)-1].grid, _dggrid.dgg[nummaj-1].grid,
		&signp, &_dgfile.kxyd, _dggrid.dgg[(*num)-1].grid, &ier );

	    /*
	     * Increment elapsed time.
	     */
	    itet += majts;
	    if ( itet == ihrs ) {
		done = G_TRUE;
		*iret = 0;
	    } else if ( itet < ihrs ) {
		ihhlst = majts;
	    } else {
		/*
		 * Subtract out over accumulation.
		 */
		iz = ( ihrs - itet ) + majts;
		intdtf[2] = intdtf[2] - iz * 100;
		ctg_itoc ( intdtf, time21, &ier );
		iptime = majts - iz;
		cst_inch ( iptime, thold, &ier );
		cst_lstr ( thold, &lenst, &ier );
		if ( lenst == 1 ) {
	    	    pnum[0] = fstchr;
	    	    pnum[1] = '0';
	    	    pnum[2] = thold[0];
	    	    pnum[3] = lstchr;
	    	    pnum[4] = '\0';
		} else {
	    	    pnum[0] = fstchr;
	    	    strcpy ( &pnum[1], thold );
	    	    lenstr = strlen ( pnum );
	    	    pnum[lenstr] = lstchr;
	    	    pnum[lenstr+1] = '\0';
		}
		dg_prcp ( time21, time22, level1, level2, &jvcord, pnum,
		          &nummaj, &ier );
		if ( ier == 0 ) {
		    signp = -1.;
		    pd_prcp ( _dggrid.dgg[(*num)-1].grid,
		              _dggrid.dgg[nummaj-1].grid, &signp, &_dgfile.kxyd,
			      _dggrid.dgg[(*num)-1].grid, &ier );
		    *iret = 0;
		} else {
		    *iret = -7;
		    dg_frig ( &nummaj, &ier );
		    return;
		}
		done = G_TRUE;
	    }
	}
	dg_frig ( &nummaj, &ier );
    }

    return;
}
Пример #24
0
static void bnd_usst ( shp_record *onerec, char *header, char *subhdr,
                  char *hdrnam, float *cenlat, float *cenlon, int *iret )
/************************************************************************
 * bnd_usst                                                             *
 *                                                                      *
 * This function generates the us state boundaries bound header and	*
 * sub-header lines.							*
 *                                                                      *
 * bnd_usst ( onerec, header, subhdr, hdrnam, cenlat, cenlon, iret )    *
 *                                                                      *
 * Input parameters:                                                    *
 *      *onerec         shp_record      One shape record               	*
 *                                                                      *
 * Output parameters:                                                   *
 *	*header		char		Bound header line		*
 *	*subhdr		char		Bound sub-header line		*
 *	*hdrnam		char		Bound header name    		*
 *	*cenlat		float		Center latitude			*
 *	*cenlon		float 		Center longitude		*
 *      *iret           int             Return code                     *
 *                                        0 = Normal                    *
 *                                        1 = Incomplete record         *
 **                                                                     *
 * Log:                                                                 *
 * R. Tian/SAIC          6/05           Initial coding                  *
 ***********************************************************************/
{
    /*
     * The array size is from the us state and territories
     * attributes specification.
     */
    char stabbr[3], stname[25];
    int ifips, iclat, iclon, nparts, ifld;
    float shplat, shplon;
    int len, ier;
/*---------------------------------------------------------------------*/
    *iret = 0;

    nparts = onerec->numprt;
    for ( ifld = 0; ifld < onerec->numfld; ifld++ ) {
        if ( strncmp ( onerec->fields[ifld].name, "STATE",
	    strlen("STATE") ) == 0 ) {
	    strncpy ( stabbr, onerec->fields[ifld].data, 2 );
	    stabbr[2] = '\0';
        } else if ( strncmp ( onerec->fields[ifld].name, "NAME",
	    strlen("NAME") ) == 0 ) {
	    strcpy ( stname, onerec->fields[ifld].data );
	    cst_lstr ( stname, &len, &ier );
	    stname[len] = '\0';
            cst_rspc ( stname, &ier );
        } else if ( strncmp ( onerec->fields[ifld].name, "FIPS",
	    strlen("FIPS") ) == 0 ) {
	    ifips = atoi ( onerec->fields[ifld].data );
        } else if ( strncmp ( onerec->fields[ifld].name, "LAT",
            strlen("LAT") ) == 0 ) {
            shplat = atof ( onerec->fields[ifld].data );
        } else if ( strncmp ( onerec->fields[ifld].name, "LON",
            strlen("LON") ) == 0 ) {
            shplon = atof ( onerec->fields[ifld].data );
        }
    }

    if ( ERMISS ( onerec->cenlat ) || ERMISS ( onerec->cenlon ) ) {
        iclat = (int)(ROUNDUP(shplat)*100.);
        iclon = (int)(ROUNDUP(shplon)*100.);
        *cenlat = shplat;
        *cenlon = shplon;
    } else {
        iclat = (int)(ROUNDUP(onerec->cenlat)*100.);
        iclon = (int)(ROUNDUP(onerec->cenlon)*100.);
        *cenlat = onerec->cenlat;
        *cenlon = onerec->cenlon;
    }

    sprintf ( header, "B%5.5d %-32.32s %5d %6d %3d",
              ifips, stname, iclat, iclon, nparts );
    sprintf ( subhdr, "<FIPS>%d<STATE>%s", ifips, stabbr );
    sprintf ( hdrnam, "%s", stname );
}
Пример #25
0
void ctb_g2rdvar ( char *tbname, G2vars_t *vartbl, int *iret ) 
/************************************************************************
 * ctb_g2rdvar								*
 *									*
 * This routine will read a GRIB2 Parameter                             *
 * table into an array of structures.	                                *
 * The table is allocated locally and a pointer to the new table is     *
 * passed back to the user in argument vartbl.  The user is resposible  *
 * for freeing this memory, when the table is no longer needed, by      *
 * free(vartbl.info)                                                    *
 *									*
 * ctb_g2rdvar ( tbname, vartbl, iret )				        *
 *									*
 * Input parameters:							*
 *	*tbname		char		Filename of the table to read   *
 *									*
 * Output parameters:							*
 *	*vartbl	G2vars_t	Pointer to list of table entries        *
 *	*iret		int		Return code			*
 *                                        0 = Successful                *
 *                                       -1 = Could not open            *
 *                                       -2 = Could not get count of    *
 *                                            of table entries.         *
 **									*
 * Log:									*
 * S. Gilbert/NCEP	 11/04	Modified from ctb_g2rdcntr to read a    *
 *                              GRIB2 Parameter Table.                  *
 ***********************************************************************/
{
        FILE     *fp = NULL;
        int      n, blen,  nr, ier;
        char     buffer[256]; 
        char     name[33], gname[13], unts[21];
        int      disc, cat, parm, pdtn, scl, ihzrmp, idrct;
        float    msng;

        const    int  ncoln=110;

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

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

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

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

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

        n  = 0;
        while ( n < nr ) {

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

	    cst_lstr (  buffer, &blen, &ier );

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


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

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

            n++;
        }

        cfl_clos(fp, &ier);

}
Пример #26
0
static void bnd_npsa ( shp_record *onerec, char *header, char *subhdr,
                  char *hdrnam, float *cenlat, float *cenlon, int *iret )
/************************************************************************
 * bnd_npsa                                                             *
 *                                                                      *
 * This function generates the predictive service areas boundaries	*
 * bound header and sub-header lines.					*
 *                                                                      *
 * bnd_npsa ( onerec, header, subhdr, hdrnam, cenlat, cenlon, iret )    *
 *                                                                      *
 * Input parameters:                                                    *
 *      *onerec         shp_record      One shape record               	*
 *                                                                      *
 * Output parameters:                                                   *
 *	*header		char		Bound header line		*
 *	*subhdr		char		Bound sub-header line		*
 *	*hdrnam		char		Bound header name    		*
 *	*cenlat		float		Center latitude			*
 *	*cenlon		float 		Center longitude		*
 *      *iret           int             Return code                     *
 *                                        0 = Normal                    *
 *                                        1 = Incomplete record         *
 **                                                                     *
 * Log:                                                                 *
 * S. Jacobs/NCEP          4/10           Initial coding                *
 * X. Guo/CWS              4/12           Increase variables(code) size *
 ***********************************************************************/
{
    /*
     * The array size is from the us state and territories
     * attributes specification.
     */
    char code[20], name[81], gacc[81];
    int iclat, iclon, nparts, ifld;
    float shplat, shplon;
    int len, ier;
/*---------------------------------------------------------------------*/
    *iret = 0;

    nparts = onerec->numprt;
    for ( ifld = 0; ifld < onerec->numfld; ifld++ ) {
        if ( strncmp ( onerec->fields[ifld].name, "NAT_CODE",
	    strlen("NAT_CODE") ) == 0 ) {
	    strcpy ( code, onerec->fields[ifld].data );
	    cst_lstr ( code, &len, &ier );
	    code[len] = '\0';
        } else if ( strncmp ( onerec->fields[ifld].name, "PSA_NAME",
	    strlen("PSA_NAME") ) == 0 ) {
	    strcpy ( name, onerec->fields[ifld].data );
	    cst_lstr ( name, &len, &ier );
	    name[len] = '\0';
            cst_rspc ( name, &ier );
        } else if ( strncmp ( onerec->fields[ifld].name, "GACC",
	    strlen("GACC") ) == 0 ) {
	    strcpy ( gacc, onerec->fields[ifld].data );
	    cst_lstr ( gacc, &len, &ier );
	    gacc[len] = '\0';
            cst_rspc ( gacc, &ier );
        }
    }

    shp_gctr ( onerec, &shplon, &shplat, &ier );
    iclat = (int)(ROUNDUP(shplat)*100.);
    iclon = (int)(ROUNDUP(shplon)*100.);
    *cenlat = shplat;
    *cenlon = shplon;

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

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

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

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

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

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

        n  = 0;
        while ( n < nr ) {

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

            cst_lstr (  buffer, &blen, &ier );

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

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

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

            n++;
        }

        cfl_clos(fp, &ier);

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

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

	FILE	*fplog;

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

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

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

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

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

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

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

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

    *iret = G_NORMAL;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		}

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

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

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

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

		}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

		}

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

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

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

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

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

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

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

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

	    }

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

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

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

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

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

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


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

		}

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

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

	    }

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

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

	    /*
	     * Increment jj
	     */
	    jj++;

	}

    }

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

    /* close the settings file */
    cfl_clos(fp, &ier);
}
Пример #30
0
void cfl_tinq ( char *table, char *type, long *flen, char *newfil, 
								int *iret )
/************************************************************************
 * cfl_tinq								*
 *									*
 * This function returns the path to a GEMPAK table file, if the table	*
 * exists.								*
 *									*
 * 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						*
 *									*
 * void cfl_tinq ( table, type, flen, newfil, iret )			*
 *									*
 * Input parameters:							*
 *	*table		char		Table file name			*
 *	*type		char		File name type				*
 *									*
 * Output parameters:							*
 *	*flen 		long		File size				*
 *	*newfil		char		Expanded file name			*
 *	*iret		int		Return code				*
 **									*
 * S. Jacobs/NCEP	 5/01	Copied from cfl_tbop			*
 * S. Chiswell/Unidata	 3/06	Modified for $LDM/etc			*
 ***********************************************************************/
{
    int		found;
    int		lenp, lenf, lent, ier;
    long	lfsize;
    char	filepart[FILE_NAMESZ], pathpart[LLPATH];
    char	actualpath[LLPATH], pathfile[FILE_FULLSZ];

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

    *iret = 0;
    found = G_FALSE;
    newfil[0] = CHNULL;
    actualpath[0] = CHNULL;
    lfsize = 0;

    /*
     *	Strip GEMTBL from beginning of the table file name if present.
     */
    if ( strstr (table, "$GEMTBL/") == table ) {
	strcpy (pathfile, &table[8]);
    } else if ( strstr (table, "GEMTBL:") == table ) {
	strcpy (pathfile, &table[7]);
    } else {
	strcpy (pathfile, table);
    }

    /*
     *	Extract the filename from the end of the path.
     */
    cfl_path ( pathfile, pathpart, filepart, &ier );
    cst_lstr ( pathpart, &lenp, &ier );
    cst_lstr ( filepart, &lenf, &ier );
    cst_lstr ( type, &lent, &ier );

    /*
     *	Check to see if the file is local.
     */
    cfl_inqr (filepart, NULL, &lfsize, actualpath, iret );
    if ( *iret == 0 ) {
	found = G_TRUE;
    }

    /*
     *	Check to see if the file is in LDMHOME/etc.
     */
    if ( found == G_FALSE) {
	cfl_inqr (filepart, LDM_ETC_PATH, &lfsize, actualpath, iret );
	if ( *iret == 0 ) {
	    found = G_TRUE;
	}
    }

    /*
     *	Check to see if the file is down a path.
     */
    if ( (found == G_FALSE) && ( lenp != 0 ) ) {
	cfl_inqr (filepart, pathpart, &lfsize, actualpath, iret );
	if ( *iret == 0 ) {
	    found = G_TRUE;
	}
    }

    /*
     *	Check to see if the file exists in terms of type in NCDESK.
     */
    if ( (found == G_FALSE) && (lent != 0) ) {
	strcpy (pathfile, "$NCDESK/");
	strcat (pathfile, type);
	strcat (pathfile, "/");
	strcat (pathfile, filepart);
	cfl_inqr (pathfile, type, &lfsize, actualpath, iret );
	if ( *iret == 0 ) {
	    found = G_TRUE;
	}
    }

    /*
     *	Check to see if the file exists in terms of type in NCSITE.
     */
    if ( (found == G_FALSE) && (lent != 0) ) {
	strcpy (pathfile, "$NCSITE/");
	strcat (pathfile, type);
	strcat (pathfile, "/");
	strcat (pathfile, filepart);
	cfl_inqr (pathfile, type, &lfsize, actualpath, iret );
	if ( *iret == 0 ) {
	    found = G_TRUE;
	}
    }

    /*
     *	Check to see if the file exists in terms of type in GEMTBL.
     */
    if ( (found == G_FALSE) && (lent != 0) ) {
	strcpy (pathfile, "$GEMTBL/");
	strcat (pathfile, type);
	strcat (pathfile, "/");
	strcat (pathfile, filepart);
	cfl_inqr (pathfile, type, &lfsize, actualpath, iret );
	if ( *iret == 0 ) {
	    found = G_TRUE;
	}
    }

    strcpy ( newfil, actualpath );
    *flen = lfsize;

}