Example #1
0
void dg_clos ( const int *idgfln, int *iret )
/************************************************************************
 * dg_clos								*
 *									*
 * This subroutine closes a grid file opened by the DG library.		*
 *									*
 *									*
 * dg_clos ( idgfln, iret )						*
 *									*
 * Input parameters:							*
 *	*idgfln		const int	DGFILE entry number		*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *					  0 = normal return		*
 **									*
 * Log:									*
 * D.W.Plummer/NCEP	10/96						*
 * D.W.Plummer/NCEP	 1/98	Bug fix-add internal grid check & reset	*
 * D.W.Plummer/NCEP	 1/98	Added reset for template processing	*
 * D.W.Plummer/NCEP	 4/98	Bug fix - idgfln refers to file number	*
 *				also, remove dgset=false		*
 * K. Brill/HPC		 2/04	Check nucode flag; update documentation	*
 *                              Do only initialization in nucode case	*
 * R. Tian/SAIC		 2/06	Recoded from Fortran			*
 ************************************************************************/
{
    int idg, k, ier;
/*----------------------------------------------------------------------*/
    *iret   = 0;
    idg = *idgfln;

    if ( _nfile.nucode == G_FALSE ) gd_clos ( &idg, &ier );
    _dgfile.idflnm[idg-1] = 0;
    _dgfile.tfirst[idg-1][0] = '\0';
    _dgfile.tlast[idg-1][0] = '\0';
    _dgfile.gdcur[idg-1][0] = '\0';
    _dgfile.tmpflg[idg-1] = G_FALSE;
    _dgfile.templt[idg-1][0] = '\0';
    _dgfile.tdattm[idg-1][0] = '\0';
    for ( k = 0; k < _dggrid.maxdgg; k++ ) {
	if ( _dggrid.ifiled[k] == idg ) _dggrid.ifiled[k] = 0;
    }

    return;
}
Example #2
0
void gdsetnav ( GDG2_input *input, float *rnvblk, int *iret )
/************************************************************************
 * gdsetnav                                                             *
 *                                                                      *
 * This routine creates a gempak grid navigation block based on user    *
 * input variables CPYFIL, KXKY, PROJ, and GRDAREA.                     *
 * If CPYFIL is set, the navigation block will be set according to its  *
 * value.  Otherwise, the nav block will be constructed with info from  *
 * KXKY, PROJ, and GRDAREA.  Then the new navigation is set in the DG   *
 * library for future grid requests.                                    *
 * If none of the parameters are set, we default to the current input   *
 * grid file's navigation.                                              *
 *                                                                      *
 *  Usage:                                                              *
 *      gdsetnav( input, rnvblk, iret );                                *
 *                                                                      *
 *  Input Arguments:                                                    *
 *      *input            GDG2_input       input structure for GDGRIB2  *
 *                                                                      *
 *  Output Arguments:                                                   *
 *      *rnvblk            float           grid navigation block        *
 *      *iret              int              Error return code.          *
 *                                           0 = Normal                 *
 *                                         -30 = could not find grid    *
 *                                               number in grdnav.tbl   *
 *                                         -31 = could not open CPYFIL  *
 *                                               grid file              *
 *                                         -33 = could not process      *
 *                                               PROJ, KXKY, GRDAREA    *
 **                                                                     *
 * Log:                                                                 *
 * S. Gilbert/NCEP           6/2005   Orig                              *
 ***********************************************************************/
{

    int    ret;
    int    nxgd, nygd, nowrit, igdfln, maxgrd;
    int    mxanl, mxnav, iacss;
    char   cname[TMPLEN], cproj[TMPLEN];
    float  anlblk[LLNANL], garea[4];

    *iret=0;

    if ( strlen(input->cpyfil) != (size_t)0 ) {
        /*
         *  CPYFIL set
         */
        if ( input->cpyfil[0] == '#' ) {
           /*
            * get navigation from grdnav.tbl
            */ 
           na_gtbl( input->cpyfil, cname, cproj, &nxgd, &nygd, garea,
                    rnvblk, anlblk, &ret );
           if ( ret != 0 ) {
               *iret = -30;
               return;
           }
        }
        else {
           /*
            * get navigation from grid file specified by CPYFIL.
            */ 
           nowrit = 0;
           mxanl=0;
           mxnav=13;
           gd_open( input->cpyfil, &nowrit, &mxanl, &mxnav, &iacss,
                    anlblk, rnvblk, &maxgrd, &ret, LLMXLN );
           if ( ret != 0 ) {
               *iret = -31;
               return;
           }
           gd_clos( &igdfln, &ret);
        }
        /*
         *  Set output grid navigation in DG library
         */
        dg_onav( rnvblk, &ret );
    }
    else {
        /*
         *  CPYFIL not set
         */
        if ( strlen( input->proj ) == (size_t)0 &&
             strlen( input->kxky ) == (size_t)0 &&
             strlen( input->grdarea ) == (size_t)0 ) {
           /*
            *  Keep navigation from input grid file
            */ 
           nowrit = 0;
           mxanl=0;
           mxnav=13;
           gd_open( input->gdfile, &nowrit, &mxanl, &mxnav, &iacss,
                    anlblk, rnvblk, &maxgrd, &ret, strlen(input->gdfile) );
        }
        else {
           /*
            *  Construct navigation block from KXKY, PROJ, GRDAREA
            */
           na_gnav( input->proj, input->kxky, input->grdarea, cproj, 
                    &nxgd, &nygd, garea, rnvblk, &ret );
           if ( ret != 0 ) {
               *iret = -33;
               return;
           }
           /*
            *  Set output grid navigation in DG library
            */
           dg_onav( rnvblk, &ret );
        }
    }
 
}
Example #3
0
GridInfoObjectType *CreateGridInfoObject( char *fileName )
{
	int			numberGrids;
	int			maxPossibleGrids;
	int			gridFileID;
	int			iret;
	int			gridCounter;
	GridInfoObjectType	*gio;
	GridType		*gt;

/*
 *	Character Strings passed to GEMPAK fortran subroutines.  When passing
 *	the length of the string to GEMPAK, subtract out one for the NULL.
 *
 */
	char	lastTime[GEMPAKSTRING];
	char	time1[GEMPAKSTRING];
	char	time2[GEMPAKSTRING];
	char	gridField[GEMPAKSTRING];

	int	levels[2];
	int	jvcoordinate;  /* may not be right declaration - check common */
	int	verbose;

	verbose = GetVerboseLevel();
	if ( verbose > VERBOSE_0 )
	    printf ("CreateGridInfoObject\n" );

	memset( lastTime,  0, sizeof( lastTime ) );
	memset( time1,     0, sizeof( time1 ) );
	memset( time2,     0, sizeof( time2 ) );
	memset( gridField, 0, sizeof( gridField) ); 


	gdinfo( fileName, lastTime, &numberGrids, &maxPossibleGrids, 
			&gridFileID, &iret, strlen( fileName ), 
			sizeof( lastTime ) - 1);

	if( iret )
		return( NULL );

/*
 *	Allocate all the memory...
 */
	gio = (GridInfoObjectType *) malloc( sizeof(GridInfoObjectType) );
	gio->gridList = (GridType *) malloc( numberGrids * 
				sizeof( GridType) );

/*
 *	....and then check for errors.
 */
	if( ! gio || ! gio->gridList ) {
		printf("*** CreateGridInfoObject: malloc failure.\n");
		return( NULL );
	}

/*
 *	Intialize the object.
 */
	gt = gio->gridList;
	memset( gt, 0, numberGrids * sizeof( GridType) ); 

	gio->fileName                   = strdup( fileName );
	gio->lastTime                   = strdup( lastTime );
	gio->numberOfGrids              = numberGrids;
	gio->maxPossibleGrids           = maxPossibleGrids;
	gio->destroyFunc                = GridInfoObjectDestroy;
	gio->printfFunc                 = GridInfoObjectPrintf;
	gio->textFunc                   = GridInfoObjectToText;

	gio->numLevels                  = 0;
	gio->levels                     = NULL;

	gio->numTimes                   = 0;
	gio->times                      = NULL;

	gio->numVerticalCoordinates	= 0;
	gio->verticalCoordinates	= NULL;

	gio->numGridFields	        = 0;
	gio->gridFields	                = NULL;

	gio->numForecastIntervals	= 0;
	gio->forecastIntervals	        = NULL;
	
	if ( verbose > VERBOSE_1 ) {
		printf("  file is %s\n", fileName );
		printf("  numberGrids %d,", numberGrids );
		printf(" maxPossibleGrids %d,", maxPossibleGrids );
		printf(" iret %d\n", iret );
	}

	iret = 0;
	for( gridCounter = 1; gridCounter <= numberGrids; gridCounter++, gt++ ){

		getnxtgrd( &gridFileID, &gridCounter, gt->time1, gt->time2, 
				gt->levels, gt->verticalCoordinate, 
				gt->gridField, &iret, sizeof(gt->time1) - 1, 
				sizeof(gt->time2) - 1,
				sizeof(gt->verticalCoordinate) - 1,
				sizeof(gt->gridField) - 1 );

		if( iret  ) {
			printf("  CreateGridInfoObject: getnxtgrd ret %d\n", 
					iret );
			break;
		}
		
		StringClean( gt->time1 );
		StringClean( gt->time2 );
		StringClean( gt->gridField ); 
		StringClean( gt->verticalCoordinate ); 
		
		if ( verbose > VERBOSE_3 ) {
			printf("  Grid # %d:\n", gridCounter );
			printf("  time1 %s,", gt->time1 );
			printf(" time2 %s,", gt->time2 );
			printf(" lev1 %d,", gt->levels[0] );
			printf(" lev2 %d,", gt->levels[1] );
			printf(" jv %s,", gt->verticalCoordinate );
			printf(" gridField %s\n", gt->gridField );
		}

		AddString( gio->numberOfGrids, &gio->numForecastIntervals, 
				&gio->forecastIntervals, 
				ParseOffForecast(gt->time1) );

		AddString( gio->numberOfGrids, &gio->numTimes, 
				&gio->times, gt->time1 );

		AddString( gio->numberOfGrids, &gio->numGridFields, 
				&gio->gridFields, 
				gt->gridField );

		AddString( gio->numberOfGrids, 
				&gio->numVerticalCoordinates, 
				&gio->verticalCoordinates, 
				gt->verticalCoordinate );

		AddInteger( gio->numberOfGrids, &gio->numLevels, 
				&gio->levels, gt->levels[0] );

	} /* for(;;) */

/*
 *	Cleanup and go home if there was an error.
 */
	if( iret ) {
		(*gio->destroyFunc)( gio );
		gio = NULL;
	}

/*
 *	Close the gridfile for next time...
 */
	gd_clos( &gridFileID, &iret );

	return( gio );

}