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

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

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

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

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

    rewind ( ftbl );

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

    ii = 0;
    while ( ii < numclust )  {

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

	if ( ier == 0 )  {

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

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

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

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

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

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

	}

    }

    cfl_clos ( ftbl, &ier );

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}
Exemple #4
0
void shp_rdException ( int *iret )
/************************************************************************
 * shp_rdException							*
 *									*
 * This function reads the shape exception table.			*
 *									*
 * void shp_rdException ( iret )					*
 *									*
 * Input parameters:							*
 *									*
 * Output parameters:							*
 *	*iret	int		Return value				*
 *                               -1 - Unable to open table      	*
 *				 -2 - Information missing		*
 *									*
 **									*
 * Log:									*
 * H. Zeng/SAIC		07/07	created					*
 ***********************************************************************/
{
    int		num, ilat, ilon, idx, ier;
    char	tagstr1[128], tagstr2[128], tagstr3[128], tagstr4[128];
    char	tagstr5[128], tagstr6[128], tagstr7[128], buff[256];
    FILE    	*fp;
    /*---------------------------------------------------------------------*/

    *iret = 0;

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

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

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

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

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

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

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

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

    cfl_clos(fp, &ier);

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

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

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

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

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

    ii = 0;
    found = G_FALSE;

/*
 *  Retrieve the product ID for the specified 
 *  product name and the resolution.
 */
    while ( !found && ii < (size_t)nr ) {
      //if ( strstr (radtbl[ii].name, prdnam) != NULL ) {
      if ( strcmp (prdnam, radtbl[ii].name) == 0 ) {
         if ( G_DIFF(ares, radtbl[ii].res) ) {
	    found = G_TRUE; 
	    *iprod = radtbl[ii].prod;
	    *iret = G_NORMAL;
         }
      }
      ii++;
    }
}
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);

}
Exemple #8
0
void NxmCursor_rdTbls ( void )
/************************************************************************
 * NxmCursor_rdTbls                                             	*
 *                                                                      *
 * This function reads the cursor type table and cursor reference table *
 *                                                                      *
 * void NxmCursor_rdTbls()                                            	*
 *                                                                      *
 * Input parameters:                                                    *
 * Output parameters:                                                   *
 * Return parameters:                                                   *
 *                      NONE                                            *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * H. Zeng/EAI          04/00     initial coding                        *
 ***********************************************************************/
{
int  ii, jj, nr = 0, ignore, iret;
char buffer[256];
FILE *fp;

/*---------------------------------------------------------------------*/
/*
 * Read cursorsymb.tbl
 */
	_cursymbTbl.nsymb = 0;

        fp = cfl_tbop( CURSORSYMB_TBL, "config", &iret );
	if ( iret == 0 ) { 
	    cfl_tbnr( fp, &nr, &iret);
	}
	    
	if ( nr == 0 ) {
	    fclose(fp);
        }
        else {
           _cursymbTbl.nsymb = nr;
           _cursymbTbl.cursymbs = (cursorsymb_t*)
                           malloc((size_t)_cursymbTbl.nsymb*sizeof(cursorsymb_t));

           ii = 0;
           while (ii < _cursymbTbl.nsymb) {
               cfl_trln(fp, 256, buffer, &iret);

               if ( iret == 0 ) {
                   sscanf(buffer, "%s %d", _cursymbTbl.cursymbs[ii].X_name, 
				  &(_cursymbTbl.cursymbs[ii].id) );
         
	       }

               ii++;
	   }      

           fclose(fp);
	}   

/*
 * Read cursortyp.tbl
 */
	_curtypTbl.ntyp = 0;

        fp = cfl_tbop( CURSORTYPE_TBL, "config", &iret );
	if ( iret == 0 ) { 
	    cfl_tbnr( fp, &nr, &iret);
	}
	    
	if ( nr == 0 ) {
	    fclose(fp);
        }
        else {
           _curtypTbl.ntyp = nr;
           _curtypTbl.curtyps = (cursortyp_t*)
                             malloc((size_t)_curtypTbl.ntyp*sizeof(cursortyp_t));

           ii = 0;
           while (ii <  _curtypTbl.ntyp) {
               cfl_trln(fp, 256, buffer, &iret);

               if ( iret == 0 ) {
                   sscanf(buffer, "%s %s", 
                          _curtypTbl.curtyps[ii].ext_name, 
			  _curtypTbl.curtyps[ii].int_name  );
                   
/*
 * By default id value is -1 which means it is a pixmap cursor.
 */
                   _curtypTbl.curtyps[ii].id = -1;

                   if( strstr(_curtypTbl.curtyps[ii].int_name, 
                              "XC_") != NULL ) {

                     for(jj=0; jj<_cursymbTbl.nsymb; jj++) {
                        if(strcmp(_curtypTbl.curtyps[ii].int_name,
                           _cursymbTbl.cursymbs[jj].X_name)==0 ) {

                           _curtypTbl.curtyps[ii].id = 
                                       _cursymbTbl.cursymbs[jj].id;
                            break; 
                        }

                     } /* the end of for() */

		   } /* the end of if(strstr...) */

	       }

               ii++;
	   }      

           fclose(fp);
	}   

/*
 * Read cursorref.tbl
 */
	_currefTbl.nref = 0;

        fp = cfl_tbop( CURSORREF_TBL, "config", &iret );
	if ( iret == 0 ) { 
	    cfl_tbnr( fp, &nr, &iret);
	}
	    
	if ( nr == 0 ) {
	    fclose(fp);
        }
        else {
           _currefTbl.nref = nr;
           _currefTbl.currefs = (cursorref_t*)
                             malloc((size_t)_currefTbl.nref*sizeof(cursorref_t));

           ii = 0;
           while (ii < _currefTbl.nref) {
               cfl_trln(fp, 256, buffer, &iret);

               if ( iret == 0 ) {
                   sscanf(buffer, "%d %s %s %s", &ignore, 
                                  _currefTbl.currefs[ii].ref_name, 
				  _currefTbl.currefs[ii].typ_name,
                                  _currefTbl.currefs[ii].color    );
         
	       }

               ii++;
	   }      

           fclose(fp);
	}   

        free(_cursymbTbl.cursymbs);

}
Exemple #9
0
void ctb_hfread ( int *iret )
/************************************************************************
 * ctb_pfread								*
 *									*
 * This function reads the info from the Hershey Fonts tables.		*
 * 									*
 * The Hershey Font coordinates are encoded using the ASCII characters.	*
 * Each character pair represents a coordinate in the drawing system	*
 * with 'R,R' as the origin. To get the coordinate values, subtract	*
 * 'R' from the given character. For example, the pair 'SB' corresponds	*
 * to (+1,-16).								*
 *									*
 * ctb_hfread ( iret )							*
 *									*
 * Input parameters:							*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *				  	  -1 = cannot open or read table*
 *				  	 -12 = cannot allocate memory	*
 **									*
 * Log:									*
 * S. Jacobs/NCEP	10/07	Created					*
 * T. Piper/SAIC	03/08	Replaced cmm functions with Macros	*
 ***********************************************************************/
{
    FILE	*fp;
    char	buffer[256], av[6];
    int		ii, nr, ier, ifont, ier2, jj, kk, nf, one = 1;

    font_tbl_name_t   tbl[] = {	{"hfont03.tbl",  3},
				{"hfont23.tbl", 23},
				{"hfont04.tbl",  4},
				{"hfont14.tbl", 14},
				{"hfont24.tbl", 24},
				{"hfont34.tbl", 34} };
/*---------------------------------------------------------------------*/

  *iret = G_NORMAL;

/*
 * Allocate space for all of the font structures.
 */
  nf = sizeof(tbl)/sizeof(tbl[0]);
  G_MALLOC ( _hfontTbl, HF_font_t, nf, "ctb_hfread - _hfontTbl");
  if ( _hfontTbl == NULL ) {
    *iret = -12;
    return;
  }

  _nhfont = 0;
  for ( ifont = 0; ifont < nf; ifont++ )  {
/*
 *  Read the font table and add entries into the structure. 
 */
    nr = 0;
    fp = cfl_tbop ( tbl[ifont].table_name, "hershey", &ier );
    if ( ier == 0 ) { 
	cfl_tbnr ( fp, &nr, &ier);
    }
	    
    if ( nr == 0 ) {
	cfl_clos ( fp, &ier );
        *iret = -1;
        return;
    }
    _hfontTbl[ifont].font_code = tbl[ifont].font_num;

/*
 *  Allocate space for the characters.
 */
    G_MALLOC ( _hfontTbl[ifont].character, HF_char_t, nr, "ctb_hfread - _hfontTbl[ifont].character");
    if ( _hfontTbl[ifont].character == NULL ) {
	cfl_clos ( fp, &ier );
	*iret = -12;
	return;
    }
  
/*
 * Read table entries into the structure.
 */
    ii = 0;

/* Read the next line from the file */
    cfl_trln ( fp, 256, buffer, &ier );

/*
 * Process the file while there is no error and
 * the end of the file has not been reached.
 */
    while ( ier >= 0 && ier != 4 ) {

        if ( ier == 0 ) {

	    G_MALLOC ( _hfontTbl[ifont].character[ii].point_code, char,  
		    strlen(buffer)+1, " ctb_hfread - _hfontTbl[ifont].character[ii].point_code");
	    if ( _hfontTbl[ifont].character[ii].point_code == NULL ) {
		cfl_clos ( fp, &ier );
		*iret = -12;
		return;
	    }
	    strcpy ( _hfontTbl[ifont].character[ii].point_code, buffer );

/* Get the character ASCII code */
	    cst_ncpy ( av, &(buffer[0]), 5, &ier2 );
	    cst_numb ( av, &(_hfontTbl[ifont].character[ii].ascii_val),
		       &ier2 );

/*
 * Get the number of points for the character
 * (The number in the file includes the X min and max,
 *  so subtract one)
 */
	    cst_ncpy ( av, &(buffer[5]), 3, &ier2 );
	    cst_numb ( av, &(_hfontTbl[ifont].character[ii].npts),
			&ier2 );
	    (_hfontTbl[ifont].character[ii].npts)--;

/* Get the X min and max */
	    _hfontTbl[ifont].character[ii].xmin = buffer[8] - 'R';
	    _hfontTbl[ifont].character[ii].xmax = buffer[9] - 'R';

/* Get the coordinates, if the number of points is > 0 */
	    if ( _hfontTbl[ifont].character[ii].npts > 0 ) {
		G_MALLOC ( _hfontTbl[ifont].character[ii].point, HF_point_t,
			_hfontTbl[ifont].character[ii].npts, 
			" ctb_hfread - _hfontTbl[ifont].character[ii].point");
                if ( _hfontTbl[ifont].character[ii].point == NULL ) {
		    cfl_clos ( fp, &ier );
		    *iret = -12;
		    return;
		}

/*
 * Check for " R", which denotes a "pen up".
 * If there is a pen up code, set the points to missing.
 * Otherwise, decode the coordinate values.
 */
		kk = 10;
		for ( jj = 0;
		      jj < _hfontTbl[ifont].character[ii].npts;
		      jj++ ) {
		    if ( strncmp ( &(buffer[kk]), " R", 2 ) == 0 ) {
			_hfontTbl[ifont].character[ii].point[jj].x = -99;
			_hfontTbl[ifont].character[ii].point[jj].y = -99;
			kk += 2;
		    }
		    else {
			_hfontTbl[ifont].character[ii].point[jj].x =
						buffer[kk] - 'R'; kk++;
			_hfontTbl[ifont].character[ii].point[jj].y =
						buffer[kk] - 'R'; kk++;
		    }
		}

	    }
/*
 * If there are no character codes,
 * set one point at the origin
 */
	    else {
		G_MALLOC ( _hfontTbl[ifont].character[ii].point, HF_point_t,
				one, " ctb_hfread - _hfontTbl[ifont].character[ii].point");
		if ( _hfontTbl[ifont].character[ii].point == NULL ) {
		    cfl_clos ( fp, &ier );
		    *iret = -12;
		    return;
		}
		_hfontTbl[ifont].character[ii].point[0].x = 0;
		_hfontTbl[ifont].character[ii].point[0].y = 0;
	    }
	    ii++;
        }

/* Read the next line from the file */
	cfl_trln ( fp, 256, buffer, &ier );

    }

/* Set the number of characters for the font */
    _hfontTbl[ifont].numchr = ii;

/* Close the font table */
    cfl_clos ( fp, &ier );

/* Increase the count for the number of fonts */
    _nhfont++;
  }  
Exemple #10
0
void clo_rdstn ( Stn_t *stn, char *fnm, char *alias, int *iret )
/************************************************************************
 * clo_rdstn								*
 *									*
 * This function loads station table information into the standard	*
 * station information structure.					*
 *									*
 * clo_rdstn ( stn, fnm, alias, iret )					*
 *									*
 * Input parameters:							*
 * *stn		Stn_t		station structure to fill		*
 * *fnm		char		station file name to use		*
 * *alias	char		alias of table name			*
 *									*
 * Output parameters:							*
 * *iret	int		Return code				*
 *				  -1 - Unable to open table		*
 *				  -2 - No records in table		*
 *				  -3 - Invalid type of point		*
 **									*
 * Log:									*
 * D.W.Plummer/NCEP	 1/99	From (now replaced) cloancrd.c		*
 * D.W.Plummer/NCEP	 3/99	Add sorting index			*
 * T. Piper/GSC		 3/99	Corrected prolog			*
 * D.W.Plummer/NCEP	 4/99	Updated for MARINE & COASTAL types	*
 * D.W.Plummer/NCEP	 7/00	Updated for consolidated CLO structures	*
 * D.W.Plummer/NCEP	 8/00	Added conversion to upper case of desc	*
 * T. Piper/GSC		 6/01	Initialized c10 			*
 * R. Tian/SAIC		 8/03	Increased c10 size.			*
 * B. Yin/SAIC		 5/04	Modified code to handle blank id.	*
 * B. Yin/SAIC		 7/04	Modified for various break point types	*
 * m.gamazaychikov	01/05	Corrected for proper column reading	*
 ***********************************************************************/
{
int	counter, ier;
char 	buff[120];
FILE	*fp;
char	id[9], desc[64], state[8], cntry[8], c10[21]="\0", tmpstr[128];
int	stnm, lat, lon, numstn, elv, pri;

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

    /*
     *  Open the table. If not found return an error.
     */
    fp = (FILE *)cfl_tbop(fnm, "stns", &ier);
    if ( fp == NULL  ||  ier != 0 )  {
	stn->nstn = 0;
        *iret = -1;
        return;
    }

    cfl_tbnr( fp, &numstn, &ier );

    if ( numstn != 0 )  {

        /* 
         *  Allocate the structure elements.
         */
        stn->nstn = numstn; 
        stn->station = (SInfo_t *) malloc( (size_t)numstn * sizeof(SInfo_t) );

    }
    else  {
	cfl_clos(fp, &ier);
        *iret = -2;
        return;
    }

    rewind(fp);

    if ( strncmp( alias, "TCA_BKPTS_", 10 ) == 0 ) {
       clo_rdtcabkpts( stn, fp, alias, numstn, iret );
       cfl_clos(fp, &ier);
       return;
    }

    /* 
     *  For every line in the station table list, read in the record,
     *  parse out the fields, and add to the structure.
     */

    counter = 0;
    while ( counter < numstn ) {
    
	cfl_trln(fp, sizeof(buff), buff, &ier);

	if ( ier == 0 )  {

	    id[ 0 ]	= '\0';
	    desc[ 0 ]	= '\0';
	    state[ 0 ]	= '\0';
	    cntry[ 0 ]	= '\0';
	    c10[ 0 ]	= '\0';
	    stnm 	= 0;
	    lat 	= 9999;
	    lon 	= 9999;
	    elv 	= 9999;
	    pri 	= 9999;

	    strncpy( tmpstr, buff, 8 );
	    tmpstr[8]='\0';
	    sscanf( tmpstr, "%s", id );
	    stn->station[counter].id = (char *)malloc(sizeof(char)*strlen(id)+1);
	    strcpy( stn->station[counter].id, id );

	    strncpy( tmpstr, &buff[9], 6 );
	    tmpstr[6]='\0';
	    sscanf( tmpstr, "%d", &stnm );
	    stn->station[counter].nm = stnm;

	    strncpy( tmpstr, &buff[16], 32 );
	    tmpstr[32]='\0';
	    sscanf( tmpstr, "%s", desc );
	    stn->station[counter].desc = (char *)malloc(sizeof(char)*strlen(desc)+1);
	    cst_lcuc ( desc, stn->station[counter].desc, &ier );

	    strncpy( tmpstr, &buff[49], 2 );
	    tmpstr[2]='\0';
	    sscanf( tmpstr, "%s", state );
	    stn->station[counter].state=(char *)malloc(sizeof(char)*strlen(state)+1);
	    strcpy( stn->station[counter].state, state );

	    strncpy( tmpstr, &buff[52], 2 );
	    tmpstr[2]='\0';
	    sscanf( tmpstr, "%s", cntry );
	    stn->station[counter].cntry=(char *)malloc(sizeof(char)*strlen(cntry)+1);
	    strcpy( stn->station[counter].cntry, cntry );

	    strncpy( tmpstr, &buff[55], 21 );
	    tmpstr[21]='\0';
	    sscanf( tmpstr, "%d %d %d %d", &lat, &lon, &elv, &pri );
	    stn->station[counter].lat = (float)lat / 100.0F;

	    stn->station[counter].lon = (float)lon / 100.0F;

	    stn->station[counter].elv = elv;

	    stn->station[counter].pri = pri;

	    strncpy( tmpstr, &buff[76], 20 );
	    tmpstr[20]='\0';
	    sscanf( tmpstr, "%s", c10 );
	    stn->station[counter].col10 = (char *)malloc(sizeof(char)*strlen(c10)+1);
	    strcpy( stn->station[counter].col10, c10 );

	    counter++;

    	}

    }

    cfl_clos(fp, &ier);

}