Exemplo n.º 1
0
void init_driver(int *iret) {

   int ier, mode = 0;

   *iret = 0;

   in_bdta(&ier);
   if ( ier != 0 ) {
      *iret = -11;
      return;
   }

   gd_init(&ier);
   if ( ier != 0 ) {
      *iret = -12;
      return;
   }

   gg_init(&mode, &ier);
   if ( ier != 0 ) {
      *iret = -13;
      return;
   }

   dg_intl(&ier);
   if ( ier != 0 ) {
      *iret = -14;
      return;
   }

   db_init(&ier);
   if ( ier != 0 ) {
      *iret = -15;
      return;
   }

}
Exemplo n.º 2
0
int main ( void )
/************************************************************************
 * TESTNSN								*
 *									*
 * This program test the NSN library of routines.			*
 *									*
 **									*
 * Log:									*
 * S. Jacobs/NCEP	 6/99	Created					*
 * M. Li/GSC		 7/00	Added nsn_save and nsn_rest		*
 * T. Lee/SAIC		 8/03	Add time interval to nsn_gtim, nsn_dspl	*
 * T. Lee/SAIC		 2/04	Add reference time flag to nsn_gtim	*
 * T. Lee/SAIC		 4/04	Added delta reference time to nsn_gtim	*
 * T. Lee/SAIC		10/04	Added bin hours				*
 * T. Piper/SAIC        01/08   Added GD_INIT; removed from IN_BDTA     *
 * F. J. Yen/NCEP	04/08   Insert new parms for nsn_dspl (CSC).	*
 *				Request input for bin hours.		*
 ***********************************************************************/
{
	int	cont, ier, iret, numsub, id;
	char	ergrp[4], erstr[81], select[LLSCRN];

	int	iindex, jindex, knt, ntime, match, ititl, idelta,
		mode, istat, minute, isbcat, mrange, intrvl,
		ibfr, iaftr, mbfr, maftr, mstrct;
	char	alias[81], cycle[81], parms[81], color[81],
		level[81], vcord[81], filter[81], txtatt[81],
		garea[81], proj[5], panel[81], dattim[21], device[81],
		map[21], ltln[21], ans[9];
	unsigned int	jflag;
	Boolean	iflag;
	dttms_t	endtim, timarr[2000];

	char	blank[] = " ";

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

	in_bdta ( &ier );
	gd_init ( &ier );

	mode = 1;
	ginitp ( &mode, &istat, &ier );

	printf ( "Enter full DEVICE string:\n" );
	scanf ( " %s", device );

	gg_sdev ( device, &ier, strlen ( device ) );

	strcpy ( ergrp, "NSN" );

	cont = G_TRUE;

	while ( cont ) {
	    printf ( "\n\n" );
	    printf ( "   1 = NSN_INIT   2 = NSN_SATT   3 = NSN_QATT\n" );
	    printf ( "   4 = NSN_GTIM   5 = NSN_DSPL   6 = NSN_SAVE\n" );
	    printf ( "   7 = NSN_REST\n\n" );
	    printf ( "  20 = Change device\n\n" );
	    printf ( "\n" );
	    printf ( "Select a subroutine number or type EXIT: " );
	    scanf ( " %s", select );
	    switch ( select[0] ) {
		case 'e':
		case 'E':
			cont = G_FALSE;
		default:
			numsub = atoi ( select );
			break;
	    }

/*---------------------------------------------------------------------*/
	    if  ( numsub == 1 )  {
		nsn_init ( &iret );

		printf ( "iret = %d\n", iret );

		if  ( iret != 0 )  {
		    strcpy ( erstr, " " );
		    er_wmsg ( ergrp, &iret, erstr, &ier,
			      strlen ( ergrp ), strlen ( erstr ) );
		}
	    }

/*---------------------------------------------------------------------*/
	    if  ( numsub == 2 )  {
		printf ( "Enter index number:\n" );
		scanf  ( " %d", &iindex );
		printf ( "Enter the data alias (e.g., UAIR):\n" );
		scanf  ( " %s", alias );
		printf ( "Enter data subcategory number:\n" );
		scanf  ( " %d", &isbcat );
		printf ( "Enter the cycle date/time or NONE:\n" );
		scanf  ( " %s", cycle );
		printf ( "Enter the parm list:\n" );
		scanf  ( " %s", parms );
		printf ( "Enter the color list:\n" );
		scanf  ( " %s", color );
		printf ( "Enter the level:\n" );
		scanf  ( " %s", level );
		printf ( "Enter the vertical coordinate:\n" );
		scanf  ( " %s", vcord );
		printf ( "Enter the filter:\n" );
		scanf  ( " %s", filter );
		printf ( "Enter the text attributes string:\n" );
		scanf  ( " %s", txtatt );

		nsn_satt ( iindex, alias, isbcat, cycle, parms, color,
			   level, vcord, filter, txtatt, &jindex,
			   &iret );

		printf ( "iret   = %d\n", iret );
		printf ( "jindex = %d\n", jindex );

		if  ( iret != 0 )  {
		    strcpy ( erstr, " " );
		    er_wmsg ( ergrp, &iret, erstr, &ier,
			      strlen ( ergrp ), strlen ( erstr ) );
		}
	    }

/*---------------------------------------------------------------------*/
	    if  ( numsub == 3 )  {
		printf ( "Enter index number:\n" );
		scanf  ( " %d", &iindex );

		nsn_qatt ( iindex, alias, &isbcat, cycle, parms, color,
			   level, vcord, filter, txtatt, &iret );

		printf ( "iret   = %d\n", iret );
		printf ( "alias  = %s\n", alias );
		printf ( "isbcat = %d\n", isbcat );
		printf ( "cycle  = %s\n", cycle );
		printf ( "parms  = %s\n", parms );
		printf ( "color  = %s\n", color );
		printf ( "level  = %s\n", level );
		printf ( "vcord  = %s\n", vcord );
		printf ( "filter = %s\n", filter );
		printf ( "txtatt = %s\n", txtatt );

		if  ( iret != 0 )  {
		    strcpy ( erstr, " " );
		    er_wmsg ( ergrp, &iret, erstr, &ier,
			      strlen ( ergrp ), strlen ( erstr ) );
		}
	    }

/*---------------------------------------------------------------------*/
	    if  ( numsub == 4 )  {
		printf ( "Enter index number:\n" );
		scanf  ( " %d", &iindex );
                printf ( "Enter end time for range:\n" );
		scanf  ( " %s", endtim );
		printf ( "Enter time range in minutes:\n" );
		scanf  ( " %d", &mrange );
		printf ( "Enter time interval in minutes:\n" );
		scanf  ( " %d", &intrvl );
		printf ( "Enter reference time flag:\n" );
		scanf  ( " %u", &jflag );
		iflag = (Boolean) jflag;
		printf ( "Enter delta reference time in minutes:\n" );
		scanf  ( " %d", &idelta );


		nsn_gtim ( iindex, endtim, mrange, intrvl, iflag, 
			   &idelta, &ntime, timarr, &iret );

		printf ( "idelta = %d\n", idelta );
		printf ( "iret   = %d\n", iret );
		printf ( "ntime  = %d\n", ntime );
		if  ( ntime > 0 )  {
		    for ( knt = 0; knt < ntime; knt++ ) {
			printf ( "Times: timarr[%d] = %s\n",
				 knt, timarr[knt] );
		    }
		}

		if  ( iret != 0 )  {
		    strcpy ( erstr, " " );
		    er_wmsg ( ergrp, &iret, erstr, &ier,
			      strlen ( ergrp ), strlen ( erstr ) );
		}
	    }

/*---------------------------------------------------------------------*/
	    if  ( numsub == 5 )  {
		printf ( "Enter index number:\n" );
		scanf  ( " %d", &iindex );

		nsn_qatt ( iindex, alias, &isbcat, cycle, parms, color,
			   level, vcord, filter, txtatt, &iret );

		printf ( "Enter GAREA:\n" );
		scanf  ( " %s", garea );

		printf ( "Default projection? (y/n)\n" );
		scanf  ( " %s", ans );
		if  ( ans[0] == 'N' || ans[0] == 'n' )  {
		    printf ( "Enter PROJ:\n" );
		    scanf  ( " %s", proj );
		}
		else {
		    strcpy ( proj, blank );
		}

		printf ( "Enter PANEL:\n" );
		scanf  ( " %s", panel );
		printf ( "Enter DATTIM:\n" );
		scanf  ( " %s", dattim );

                printf ( "Enter end time for range:\n" );
		scanf  ( " %s", endtim );
		printf ( "Enter the time range in minutes:\n" );
		scanf  ( " %d", &mrange );
		printf ( "Enter the time interval in minutes:\n" );
		scanf  ( " %d", &intrvl );

		printf ( "Enter time match type:\n" );
		scanf  ( " %d", &match );
		printf ( "Enter minutes for difference match:\n" );
		scanf  ( " %d", &minute );
		printf ( "Enter title line:\n" );
		scanf  ( " %d", &ititl );
                printf ( "Enter binning time before current time: hh mm:\n" );
                scanf  ( " %d %d", &ibfr, &mbfr );
                printf ( "Enter binning time after current time: hh mm:\n" );
                scanf  ( " %d %d", &iaftr, &maftr );
                printf ( "Enter most recent only flag (0 for no; 1 for yes)\n" );
                scanf  ( " %d", &mstrct );

		gg_maps ( proj, garea, blank, &id, &ier,
			  strlen ( proj ), strlen ( garea ),
			  strlen ( blank ) );

		gclear ( &ier );

		strcpy ( map, "1" );
		gg_map ( map, &ier, strlen ( map ) );

		strcpy ( ltln, "2" );
		gg_ltln ( ltln, &ier, strlen ( ltln ) );

		nsn_dspl ( panel, dattim, alias, &isbcat, cycle, parms,
			   color, level, vcord, filter, txtatt,       
			   endtim, &mrange, &intrvl, &match, &minute, 
			   &ititl, &ibfr, &mbfr, &iaftr, &maftr,
			   &mstrct, &iret,
			   strlen ( panel ), strlen ( dattim ),
			   strlen ( alias ), strlen ( cycle ),
			   strlen ( parms ), strlen ( color ),
			   strlen ( level ), strlen ( vcord ),
			   strlen ( filter ), strlen ( txtatt ),
			   strlen ( endtim ) );

		geplot ( &ier );

		if  ( iret != 0 )  {
		    strcpy ( erstr, " " );
		    er_wmsg ( ergrp, &iret, erstr, &ier,
			      strlen ( ergrp ), strlen ( erstr ) );
		}
	    }

/*---------------------------------------------------------------------*/
            if  ( numsub == 6 )  {
                nsn_save ( &iret );

                printf ( "iret = %d\n", iret );

                if  ( iret != 0 )  {
                    strcpy ( erstr, " " );
                    er_wmsg ( ergrp, &iret, erstr, &ier,
                              strlen ( ergrp ), strlen ( erstr ) );
                }
            }

/*---------------------------------------------------------------------*/
            if  ( numsub == 7 )  {
                nsn_rest ( &iret );

                printf ( "iret = %d\n", iret );

                if  ( iret != 0 )  {
                    strcpy ( erstr, " " );
                    er_wmsg ( ergrp, &iret, erstr, &ier,
                              strlen ( ergrp ), strlen ( erstr ) );
                }
            }

/*---------------------------------------------------------------------*/
	    if  ( numsub == 10 )  {
		dumpcmn ( &iret );
	    }

/*---------------------------------------------------------------------*/
	    if  ( numsub == 20 )  {
		printf ( "Enter full DEVICE string:\n" );
		scanf ( " %s", device );

		gg_sdev ( device, &ier, strlen ( device ) );
	    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    }

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

/*
 *  Exit the GEMPAK user interface
 */
    ip_exit( &ret );
 
    return(0);
}
Exemplo n.º 4
0
int main ( void )
/************************************************************************
 * GRPHGD								*
 *									*
 * This program runs the graph-to-grid algorithm.			*
 *									*
 **									*
 * Log:									*
 * D.W.Plummer/NCEP	 2/05	Re-write in C based on grphgd.f		*
 * R. Tian/SAIC		 3/05	Added dg_intl				*
 * M. Li/SAIC		 4/05	Modified ggdriv				*
 * D.W.Plummer/NCEP	 5/05	Move dg_intl into gg_driv driver	*
 * m.gamazaychikov/SAIC	12/05	Add ces_gtrtbl				*
 * T. Piper/SAIC        01/08   Added GD_INIT; removed from IN_BDTA     *
 ***********************************************************************/
{
int	respnd, iperr, done, one=1, ier, iret, rspflg=G_TRUE;
int	kx=0, ky=0, npoints;
float	*grid, *grid1, *hist, *work1, *work2, *work3, *buffer;
/*---------------------------------------------------------------------*/
/*
 *  Initialize TAE.
 */
    ip_init ( &respnd, &iperr );
    if ( iperr == G_NORMAL )  {
	ip_idnt ( "GRPHGD", &ier, strlen("GRPHGD") );

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

    }
    else  {

	iperr = -1;
	done = G_TRUE;

    }

/*
 *  Initialize GEMPLT in order to set grid navigation later.
 */
    if ( done == G_FALSE )  {

	gg_init ( &one, &iret );

	if ( iret != G_NORMAL )  {
	    iperr = -3;
	    done = G_TRUE;
	}
    }

/*
 *  Initialize device.
 */
    if ( done == G_FALSE )  {

	gg_sdev ( "GN", &ier, strlen("GN") );

	if ( ier != G_NORMAL )  {
	    done = G_TRUE;
	}
    }

/*
 *  Initialize the _grpTbl structure.
 */
    if ( done == G_FALSE )  {
                                                                                                        
        ces_gtrtbl( &ier );
                                                                                                        
        if ( ier != G_NORMAL )  {
            done = G_TRUE;
        }
    }
    
/*
 * Main loop.
 */
    while ( done == G_FALSE ) {

	npoints = LLMXTG;
	G_MALLOC ( grid,	float, npoints, "Error allocating grid" );
	G_MALLOC ( grid1,	float, npoints, "Error allocating grid1" );
	G_MALLOC ( hist,	float, npoints, "Error allocating hist" );
	G_MALLOC ( work1,	float, npoints, "Error allocating work1" );
	G_MALLOC ( work2,	float, npoints, "Error allocating work2" );
	G_MALLOC ( work3,	float, npoints, "Error allocating work3" );
	G_MALLOC ( buffer,	float, npoints, "Error allocating buffer" );

	ggdriv ( grid, grid1, &kx, &ky, hist, work1, work2, work3, 
		 buffer, &rspflg, &ier );

	G_FREE ( hist, float );
	G_FREE ( grid, float );
	G_FREE ( grid1, float );
	G_FREE ( work1, float );
	G_FREE ( work2, float );
	G_FREE ( work3, float );
	G_FREE ( buffer, float );

/*
 * Call dynamic tutor.
 */
	ip_dynm ( &done, &ier );

    }

/*
 * Final error messages.
 */
    if ( iperr != G_NORMAL )  {
	er_wmsg ( "GRPHGD", &iperr, " ", &ier, strlen("GRPHGD"), strlen(" ") );
    }

    ip_exit ( &iret );

    return 0;

}