int main ( void ) /************************************************************************ * TESTCVQ * * * * This program tests the CGEMLIB "CVQ" functions. * * * ** * * Log: * * E. Wehner/EAi 6/97 Created * * E. Wehner/EAi 7/97 Fixed typecasting of group type * * E. Wehner/EAi 7/97 Added cvq_higrp. * * I. Durham/GSC 5/98 Changed underscore decl. to an include * * A. Hardy/SAIC 11/01 Added maxoff to cvq_scangrp * ***********************************************************************/ { int cont, iret, numsub, i, ier; int flag, level, elevel, ebuff; int eflag; int ingrp, maxoff; long size; char select[LLSCRN], filnam[LLSCRN]; char grp[4], path[133]; VG_DBStruct el; int vgstart; char gptyp; /* group type */ int gpnum; /* group number */ int members[10]; int fpos; int tgtyp; /* temporary group type */ /*---------------------------------------------------------------------*/ iret = 0; size = 0; cont = G_FALSE; flag = G_FALSE; eflag = G_FALSE; strcpy(grp, "CVQ"); level = 0; elevel = 2; ebuff = 0; in_bdta(&ier); er_stat(&elevel, &ebuff, &eflag, &ier); vgstart = 0; cvg_rdrec ( filnam, vgstart, &el, &iret ); while ( cont == G_FALSE ) { numsub = 0; printf ( "\n\n" ); printf (" 1 = CVQ_SCANGRP 2 = CVQ_GETGINF 3 = CVQ_NXTGNM\n"); printf (" 4 = CVQ_HIGP \n"); printf ( "\n" ); printf ( "Select a function number or type EXIT: " ); scanf ( " %s", select ); switch ( select[0] ) { case 'e': case 'E': cont = G_TRUE; break; default: numsub = atoi ( select ); break; } /*---------------------------------------------------------------------*/ switch (numsub) { /* * ---------------------------------------------------------- * CVQ_SCANGRP - retrieve the members of a group * ---------------------------------------------------------- */ case 1: printf ( "Enter the VG file name to scan:\n" ); scanf ( " %s", filnam ); printf( "Enter Group type to retrieve:\n"); scanf( " %i", &tgtyp); printf( "Enter Group number to retrieve: \n"); scanf( " %i", &gpnum); printf( "Enter maximum number of offsets to find: \n"); scanf( " %i", &maxoff); gptyp = (char)tgtyp; cvq_scangrp( filnam, gptyp, gpnum, maxoff, members, &ingrp, &iret); printf ( "\nCVQ_SCANGRP: iret = %d\n\n", iret ); printf(" Extracted %i elements in group: %i/%i \n", ingrp, gptyp, gpnum); for (i = 0; i< ingrp; i++) { /* read header */ cfl_inqr ( filnam, " ", &size, path, &ier ); if (members[i] < size) { cvg_rdrec ( filnam, members[i], &el, &iret ); cvg_dump ( el, el.hdr.recsz, el.hdr.recsz, flag, &iret ); } } er_lmsg ( &level, grp, &iret, filnam, &ier, strlen(grp), strlen(filnam) ); break; /* * ---------------------------------------------------------- * CVQ_GETGINF - Return group type and number from elem. * ---------------------------------------------------------- */ case 2: printf ( "Enter the VG file name to examine:\n" ); scanf ( " %s", filnam ); printf( "Enter file location of element in question:\n"); scanf( " %i", &fpos); cvq_getginf( filnam, fpos, &gptyp, &gpnum, &iret); printf ( "\nCVQ_GETGINF: iret = %d\n\n", iret ); printf(" Element is in group %c %i \n", gptyp, gpnum); er_lmsg ( &level, grp, &iret, filnam, &ier, strlen(grp), strlen(filnam) ); break; /* * ---------------------------------------------------------- * CVQ_NXTGNM - Get next group number used in file * ---------------------------------------------------------- */ case 3: printf ( "Enter the VG file name to examine:\n" ); scanf ( " %s", filnam ); printf( "Enter the group type to retrieve from:\n"); scanf( " %i", &tgtyp); gptyp = (char)tgtyp; printf( "Locate the next group number above: \n"); scanf( " %i", &gpnum); cvq_nxtgnm( filnam, gptyp, &gpnum, &iret); printf ( "\nCVQ_NXTGNM: iret = %d\n\n", iret ); printf(" The next group number of group type %c is %i \n", gptyp, gpnum); er_lmsg ( &level, grp, &iret, filnam, &ier, strlen(grp), strlen(filnam) ); break; /* * ---------------------------------------------------------- * CVQ_HIGP - Get highest group number used in file * ---------------------------------------------------------- */ case 4: printf ( "Enter the VG file name to examine:\n" ); scanf ( " %s", filnam ); cvq_higp( filnam, &gpnum, &iret); printf ( "\nCVQ_HIGP: iret = %d\n\n", iret ); printf(" The highest group number is %i \n", gpnum); er_lmsg ( &level, grp, &iret, filnam, &ier, strlen(grp), strlen(filnam) ); break; } } return 0; }
void dc_init ( char *prgnam, int argc, char **argv, int numexp, char parms[][DCMXLN], int *num, int *iret ) /************************************************************************ * dc_init * * * * This routine initializes the bridge and decoder parameters and * * processes the command line options. * * * * dc_init ( prgnam, argc, argv, numexp, parms, num, iret ) * * * * Input parameters: * * *prgnam char Program name * * argc int Number of command line args * * **argv char Command line arguments * * numexp int Number of expected parameters * * * * Output parameters: * * parms[][DCMXLN] char Parameters found on command line* * *num int Number of parameters found * * *iret int Return code * * 0 = normal return * * -11 = no command line args * * * ** * * Log: * * A. Chang/EAi 5/95 * * S. Jacobs/NMC 7/95 Update and clean up * * S. Jacobs/NCEP 6/96 Updated documentation; Changed atoi to * * cst_numb; Removed the +3 return code; * * Changed ldfd to a FILE stream - fplog * * S. Jacobs/NCEP 7/96 Reorganized the source code * * K. Tyle/GSC 7/96 NT_HELP --> IP_HELP * * S. Jacobs/NCEP 7/96 Removed log file open * * K. Tyle/GSC 1/97 Added calls to IN_BDTA and ER_STAT; * * changed numerr in startup dc_wclg call * * K. Tyle/GSC 1/97 Use iflg in call to ER_STAT * * D. Kidwell/NCEP 9/97 Added version number to help option * * I. Durham/GSC 5/98 Changed underscore decl. to an include * * S. Jacobs/NCEP 1/00 Added command line input of env vars * * S. Jacobs/NCEP 2/01 Removed all references to ulog * * R. Tian/SAIC 8/02 Added version to log file * * m.gamazaychikov/SAIC 07/05 Added -w input parameter * * H. Zeng/SAIC 08/05 Added second station table * * L. Hinson/AWC 06/08 Add -r circular flag switch * * S. Jacobs/NCEP 3/12 Add $HOME to the logs directory * * S. Jacobs/NCEP 12/13 Added more options for log location * ***********************************************************************/ { int ch, i, errflg, ier; int pagflg = G_FALSE; int iflg = G_TRUE; /* ** These variables are used for logging errors and notices. */ char tdclog[DCMXLN]; int logflg, ibuf; char errstr[DCMXLN]; char version[128]; /* ** These variables are used by getopt. Unset the error reporting. */ char optver[20]; /*---------------------------------------------------------------------*/ *iret = 0; /* ** Set the process ID for log messages. */ ipid = (int) getpid (); /* ** Initialize the bulletin counter. */ nbull = 0; /* ** Save the program name as a global variable. */ strcpy ( cprgnm, prgnam ); /* ** Set up the signal handlers. */ dc_sgnl ( ); /* ** Get and process the command line options. ** ** Set the default values for parsing the command line. */ strcpy ( curtim, "SYSTEM" ); cst_uclc ( cprgnm, tdclog, &ier ); strcat ( tdclog, ".log" ); logflg = G_FALSE; itmout = DCDFTM; irltim = G_TRUE; txtflg = G_TRUE; circflg = G_FALSE; ivrblv = 0; prmfil[0] = CHNULL; stntbl[0] = CHNULL; iadstn = IMISSD; maxtim = IMISSD; nhours = IMISSD; iwndht = IMISSD; /* ** Get the valid options from the command line. ** The valid options are: ** -v Set the level of verbosity for the logs ** -c Set the "current" time ** -b Number of hours to decode prior to "current" time ** -d Set the decoder log file name ** -t Set the interval for the time out ** -p Set the parameter packing table ** -s Set the station table ** -S Set the second station table ** -a Set the number of additional stations ** -m Set the max number of times ** -e Set an environment variable=value ** -n Set a flag to NOT save the text data ** -r Set a flag to force circular files ** -w Set the cutoff "close-to-the-surface" height ** -h Print the help file, then exit the program */ opterr = 1; errflg = 0; while ( ( ch = getopt ( argc, argv, "v:c:b:d:t:p:s:S:a:m:e:w:nhr" ) ) != EOF ) { switch ( ch ) { case 'v': cst_numb ( optarg, &ivrblv, &ier ); if ( ivrblv < 0 ) ivrblv = 0; break; case 'c': strcpy ( curtim, optarg ); irltim = G_FALSE; break; case 'b': cst_numb ( optarg, &nhours, &ier ); break; case 'd': strcpy ( tdclog, optarg ); logflg = G_TRUE; break; case 't': cst_numb ( optarg, &itmout, &ier ); if ( itmout < 1 ) itmout = DCDFTM; break; case 'p': strcpy ( prmfil, optarg ); break; case 's': strcpy ( stntbl, optarg ); break; case 'S': strcpy ( stntb2, optarg ); break; case 'a': cst_numb ( optarg, &iadstn, &ier ); break; case 'm': cst_numb ( optarg, &maxtim, &ier ); break; case 'e': envobj = (envlist *) malloc ( sizeof(envlist) ); envobj->env = malloc ( strlen(optarg)+1 ); strcpy ( envobj->env, optarg ); envobj->env[strlen(optarg)] = '\0'; envobj->next = envhead; envhead = envobj; break; case 'n': txtflg = G_FALSE; break; case 'w': cst_numb ( optarg, &iwndht, &ier ); break; case 'r': circflg = G_TRUE; break; case 'h': ip_help ( cprgnm, &pagflg, &ier, strlen(cprgnm) ); strcpy ( cprgnm, "DECODE" ); ip_help ( cprgnm, &pagflg, &ier, strlen(cprgnm) ); ss_vers ( optver, &ier, sizeof (optver) ); printf ( ">%s<\n", optver ); exit ( 0 ); break; case '?': errflg++; break; } } /* ** Initialize GEMPAK and set error reporting parameters. */ in_bdta ( &ier ); ibuf = 1; er_stat ( &ivrblv, &ibuf, &iflg, &ier ); /* ** Open the decoder log. ** ** If the processing is in real-time add the directory to the ** file name. */ if ( !logflg && irltim ) { if ( tdclog[0] == '/' ) { strcpy ( dcdlog, tdclog ); } else if ( getenv("GEMPAK_DECODER_LOGS") ) { strcpy ( dcdlog, "$GEMPAK_DECODER_LOGS/" ); strcat ( dcdlog, tdclog ); } else { strcpy ( dcdlog, "$HOME/" ); strcat ( dcdlog, tdclog ); } } else { strcpy ( dcdlog, tdclog ); } /* ** Send a start up message to the decoder log. */ ss_vers ( version, &ier, sizeof(version) ); dc_wclg ( 0, "DCINIT", 3, version, &ier ); /* ** Set all of the environment variables. */ envobj = envhead; while ( envobj != NULL ) { if ( putenv ( envobj->env ) != 0 ) { strcpy ( errstr, envobj->env ); dc_wclg ( 0, "DCINIT", -17, errstr, &ier ); } envobj = envobj->next; } /* ** Adjust argc and argv by the option index. */ argc -= optind; argv += optind; /* ** Initialize the output string array. */ for ( i = 0; i < numexp; i++ ) strcpy ( parms[i], " " ); /* ** Get the decoder specific parameters. */ *num = argc; if ( *num == 0 ) { /* ** If there are no parameters write a message and return ** with an error. */ *iret = -11; dc_wclg ( 0, "DCINIT", *iret, " ", &ier ); } else { /* ** Otherwise, set the parameters to be returned. */ for ( i = 0; i < *num; i++ ) if ( i < numexp ) strcpy ( parms[i], argv[i] ); } }
void gmpk_init ( int *iret ) /************************************************************************ * gmpk_init * * * * This function initializes GEMPAK variables. * * * * void gmpk_init ( iret ) * * * * Input parameters: NONE * * * * Output parameters: * * *iret int return code * * * ** * * Log: * * C. Lin/EAI 02/93 * * C. Lin/EAI 03/94 * * C. Lin/EAI 1/95 add comments, clean up * * add GetColorDefs() * * C. Lin/EAI 12/95 clean up * * C. Lin/EAI 1/97 add er_stat() * * C. Lin/EAI 1/97 add initialization of gdpltb common block * * C. Lin/EAI 2/98 set allocflag[] in xwcmn.h for graphics * * I. Durham/GSC 5/98 changed underscore decl. to an include * * S. Jacobs/NCEP 7/01 Added call to gmpk_initTxt * * S. Chiswell/UPC 9/02 Added call to xscint for 24 bit support * * K. Brill/HPC 4/03 Use dg_intl to initialize the DG library * * T. Piper/SAIC 05/03 removed items common w/NxmGmpkInit * * R. Tian/SAIC 01/04 added nuflg to dg_intl call * * R. Tian/SAIC 02/04 removed nuflg from dg_intl call * ***********************************************************************/ { int level, bufflg, dttmflg, lflag; char pname[30]; /*---------------------------------------------------------------------*/ *iret = 0; /* * set the error buffering scheme * different level may be set by the application */ level = 0; bufflg = 1; dttmflg = 1; er_stat( &level, &bufflg, &dttmflg, iret); /* iret always 0! */ /* * initialize the GEMPAK Grid Diagnostics (DG) library */ dg_intl ( iret ); /* iret always 0! */ /* * initialize GEMPAK gdpltb common block */ strcpy(pname, "CLEAR"); lflag = 1; gdpstt(pname, &lflag, iret, strlen(pname)); if ( *iret != 0 ) return; strcpy(pname, "SHORT_TITLE"); lflag = 0; gdpstt(pname, &lflag, iret, strlen(pname)); if ( *iret != 0 ) return; strcpy(pname, "PLOT_MAP"); lflag = 1; gdpstt(pname, &lflag, iret, strlen(pname)); if ( *iret != 0 ) return; /* * Initialize the text font info. */ gmpk_initTxt( ); return; }