void decode_nldn (char *curtim, char *gemfil, char *prmfil, char *filetyp, int maxtim, int nhours, int *iret) { int maxfil=1, iflsrc=2; int ier,ichk,nexp,nret,loglev; nldn_file ltgf; char errmsg[80]; static char errgrp[] = {"decode_nldn"}; nldninit(); *iret = 0; ltgf.gemfil = (char *)malloc(strlen(gemfil) + 1); strcpy(ltgf.gemfil,gemfil); ltgf.curtim = (char *)malloc(strlen(curtim) + 1); cst_uclc(curtim, ltgf.curtim, &ier); ltgf.ifltyp = (char *)malloc(strlen(filetyp) + 1); cst_uclc(filetyp, ltgf.ifltyp, &ier); ltgf.maxtim = maxtim; ltgf.iflsrc = iflsrc; /* * File types can be hour, day, or month, for hourly, daily, or monthly files * OR can be minute stored in xx minute bins. */ ltgf.itype = 0; ltgf.ifactor = 0; if (strncmp(filetyp,"hour",4) == 0) ltgf.itype = 1; else if (strncmp(filetyp,"day",3) == 0) ltgf.itype = 2; else if (strncmp(filetyp,"month",5) == 0) ltgf.itype = 3; else if (strncmp(filetyp,"minute",6) == 0) { ltgf.itype = 4; nexp = 1; st_c2i ( filetyp+6, &nexp, <gf.ifactor, &nret, &ier, 2); if ( ier != 0 ) { sprintf(errmsg,"Can't decode bin size, use 10 min as default\0"); loglev = 0; dc_wclg ( loglev, errgrp, ier, errmsg, &ichk); ltgf.ifactor = 10; } } /* use the -b nhours to specify the output file frequency (60 min default)*/ ltgf.ibin = nhours; dc_fint(&maxfil, &iflsrc, prmfil, &ier, strlen(prmfil) ); while(*iret == 0) dcnldn_input(ltgf,iret); dc_fcls(&ier); }
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] ); } }
/* convenience routine to get grid number for grib2 */ int ced_num ( g2int *gdtmpl, g2int gdtlen) { int kx, ky, try_quick, loglev, numerr, ier; float angl[3], llt, lln, ult, uln, basic_angle; static char _proj[] = "CED"; char errgrp[20], errstr[81]; nav_list *q; static nav_list *lastmatch=NULL; if ( gdtlen < 18 ) return(255); /*for ( i=0;i<gdtlen;i++) printf("gdtmpl %d %d\n",i,gdtmpl[i]);*/ kx = gdtmpl[7]; ky = gdtmpl[8]; /* 1.0e6 assumes gdtmpl[9] = 0 or 1 for ratio of degree to 1.0e6 */ if ( ( gdtmpl[9] == 0 ) || ( gdtmpl[9] == 1 ) ) basic_angle = 1.0e6; else basic_angle = 1.0e6 * gdtmpl[9] / gdtmpl[10]; llt = gdtmpl[11] / basic_angle; lln = gdtmpl[12] / basic_angle; while ( lln > 180.0 ) lln = lln - 360.0; ult = gdtmpl[14] / basic_angle; uln = gdtmpl[15] / basic_angle; while ( uln > 180.0 ) uln = uln - 360.0; if ( lastmatch != NULL ) { q = lastmatch; try_quick = 1; } else { q = nav_head; try_quick = 0; } while ( q != NULL ) { if ( ( strcmp(_proj,q->proj ) == 0 ) && ( kx == q->kx ) && ( ky == q->ky ) && ( ( G_DIFFT( llt, q->llt, .001) && G_DIFFT( ult, q->ult, .001) ) || ( G_DIFFT( ult, q->llt, .001) && G_DIFFT( llt, q->ult, .001) ) ) && G_DIFFT( lln, q->lln, .001) && G_DIFFT( uln, q->uln, .001) ) { lastmatch = q; return(q->gnum); } if ( try_quick ) { q = nav_head; try_quick = 0; } else q = q->next; } loglev = 2; numerr = -1; sprintf(errgrp,"%s_GNUM\0",_proj); sprintf(errstr,"No GID KXKY [%d %d] LL [%f %f] UR [%f %f]\n",kx,ky,llt,lln, ult, uln); dc_wclg(loglev,errgrp,numerr,errstr,&ier); /*if ( ( gdtmpl[7] == 720 ) && ( gdtmpl[8] == 361 ) && ( gdtmpl[11] == 90000000 ) && ( gdtmpl[12] == 0 ) && ( gdtmpl[14] == -90000000 ) && ( gdtmpl[15] == 359500000 ) && ( gdtmpl[16] == 500000 ) && ( gdtmpl[17] == 500000 ) ) return ( 4 );*/ return ( 255 ); }
int str_num ( g2int *gdtmpl, g2int gdtlen) { int kx, ky, try_quick, loglev, numerr, ier; float angl[3], llt, lln, ult=RMISSD, uln=RMISSD; static char _proj[] = "STR"; char errgrp[20], errstr[81]; nav_list *q; static nav_list *lastmatch=NULL; if ( gdtlen < 18 ) return(255); kx = gdtmpl[7]; ky = gdtmpl[8]; llt = gdtmpl[9] / 1.0e6; lln = gdtmpl[10] / 1.0e6; while ( lln > 180.0 ) lln = lln - 360.0; if ( gdtmpl[16] & 64 ) angl[0] = -90.0; else angl[0] = 90.0; angl[1] = gdtmpl[13] / 1.0e6; while ( angl[1] > 180.0 ) angl[1] = angl[1] - 360.0; angl[2] = 0; /*for ( i=0;i<gdtlen;i++) printf("gdtmpl %d %d\n",i,gdtmpl[i]);*/ if ( lastmatch != NULL ) { q = lastmatch; try_quick = 1; } else { q = nav_head; try_quick = 0; } while ( q != NULL ) { if ( ( strcmp(_proj,q->proj ) == 0 ) && ( kx == q->kx ) && ( ky == q->ky ) && ( angl[0] == q->angle[0] ) && ( angl[1] == q->angle[1] ) && ( G_DIFFT( llt, q->llt, .001) ) && ( G_DIFFT( lln, q->lln, .001) ) ) { lastmatch = q; return(q->gnum); } if ( try_quick ) { q = nav_head; try_quick = 0; } else q = q->next; } loglev = 2; numerr = -1; sprintf(errgrp,"%s_GNUM\0",_proj); sprintf(errstr,"No GID KXKY [%d %d] LL [%f %f] ANGL [%f %f %f]\n",kx,ky,llt,lln, angl[0],angl[1], angl[2]); dc_wclg(loglev,errgrp,numerr,errstr,&ier); /* if ( ( gdtmpl[7] == 377 ) && ( gdtmpl[8] == 237 ) && ( gdtmpl[9] == 44196000 ) && ( gdtmpl[10] == 174759000 ) && ( gdtmpl[12] == 60000000 ) && ( gdtmpl[13] == 203000000 ) && ( gdtmpl[14] == 11945000 ) && ( gdtmpl[15] == 11945000 ) ) return ( 186 ); if ( ( gdtmpl[7] == 553 ) && ( gdtmpl[8] == 425 ) && ( gdtmpl[9] == 30000000 ) && ( gdtmpl[10] == 187000000 ) && ( gdtmpl[12] == 60000000 ) && ( gdtmpl[13] == 225000000 ) && ( gdtmpl[14] == 11250000 ) && ( gdtmpl[15] == 11250000 ) ) return ( 242 );*/ return ( 255 ); }
int lcc_num ( g2int *gdtmpl, g2int gdtlen) { int kx, ky, try_quick, loglev, numerr, ier; float angl[3], llt, lln, ult=RMISSD, uln=RMISSD; static char _proj[] = "LCC"; char errgrp[20], errstr[81]; nav_list *q; static nav_list *lastmatch=NULL; if ( gdtlen < 21 ) return(255); kx = gdtmpl[7]; ky = gdtmpl[8]; llt = gdtmpl[9] / 1.0e6; lln = gdtmpl[10] / 1.0e6; while ( lln > 180.0 ) lln = lln - 360.0; angl[0] = gdtmpl[18] / 1.0e6; angl[1] = gdtmpl[13] / 1.0e6; while ( angl[1] > 180.0 ) angl[1] = angl[1] - 360.0; angl[2] = gdtmpl[19] / 1.0e6; /*for ( i=0;i<gdtlen;i++) printf("gdtmpl %d %d\n",i,gdtmpl[i]);*/ if ( lastmatch != NULL ) { q = lastmatch; try_quick = 1; } else { q = nav_head; try_quick = 0; } while ( q != NULL ) { /* TODO: need to use either Dx and DY or ult, uln comparison */ if ( ( strcmp(_proj,q->proj ) == 0 ) && ( kx == q->kx ) && ( ky == q->ky ) && ( G_DIFFT( llt, q->llt, .001) ) && ( G_DIFFT( lln, q->lln, .001) ) ) { lastmatch = q; return(q->gnum); } if ( try_quick ) { q = nav_head; try_quick = 0; } else q = q->next; } /*if ( ( gdtmpl[7] == 491 ) && ( gdtmpl[8] == 303 ) && ( gdtmpl[9] == 19943000 ) && ( gdtmpl[10] == 234907000 ) && ( gdtmpl[12] == 40000000 ) && ( gdtmpl[13] == 262000000 ) && ( gdtmpl[14] == 12000000 ) && ( gdtmpl[15] == 12000000 ) ) return ( 185 ); if ( ( gdtmpl[7] == 185 ) && ( gdtmpl[8] == 129 ) && ( gdtmpl[9] == 12190000 ) && ( gdtmpl[10] == 226541000 ) && ( gdtmpl[12] == 25000000 ) && ( gdtmpl[13] == 265000000 ) && ( gdtmpl[14] == 12190000 ) && ( gdtmpl[15] == 12190000 ) ) return ( 212 ); if ( ( gdtmpl[7] == 614 ) && ( gdtmpl[8] == 428 ) && ( gdtmpl[9] == 12190000 ) && ( gdtmpl[10] == 226541000 ) && ( gdtmpl[12] == 25000000 ) && ( gdtmpl[13] == 265000000 ) && ( gdtmpl[14] == 12191000 ) && ( gdtmpl[15] == 12191000 ) ) return ( 218 );*/ loglev = 2; numerr = -1; sprintf(errgrp,"%s_GNUM\0",_proj); sprintf(errstr,"No GID KXKY [%d %d] LL [%f %f] ANGL [%f %f %f]\n",kx,ky,llt,lln, angl[0],angl[1], angl[2]); dc_wclg(loglev,errgrp,numerr,errstr,&ier); return ( 255 ); }
void decode_strike(char *line, nldn_file ltgf) { static int isinit=!0; int iret; char result[256], *cpos; int maxchar=sizeof(result)-1; int year, month, day, hour, minute, second; int mult; float slat,slon,sgnl,emaj,emin; nldn_flash flashdat; time_t obsclock; struct tm obstime; int loglev, numerr,axisor; static char errgrp[] = {"decode_strike"}; char errstr[LLMXLN]; int filver; /* Split line into result (date string) and cpos (leftovers) */ cpos = cst_split(line,',',maxchar,result,&iret); /* See if this look like a valid line (check if first char is 2[008] */ if ( ( iret != 0 ) || ( cpos == NULL ) || ( result[0] != '2' ) ) { printf("Not a strike line %s\n",line); return; } /* Check if file is old (filver = 4) or new (filver = 6) */ filver = sscanf(cpos,"%f,%f,%f,%f,%f,%d", &slat, &slon, &sgnl, &emaj, &emin, &axisor); switch ( filver ) { case 4: if ( (iret = sscanf(cpos,"%f,%f,%f,%d", &slat, &slon, &sgnl, &mult)) != 4 ) { sprintf(errstr,"Old: Not a strike line %s\0",line); loglev = 4; numerr = 1; dc_wclg(loglev, errgrp, numerr, errstr, &iret); return; } break; case 6: if ( (iret = sscanf(cpos,"%f,%f,%f,%f,%f,%d", &slat, &slon, &sgnl, &emaj, &emin, &axisor)) != 6 ) { sprintf(errstr,"New: Not a strike line %s\0",line); loglev = 4; numerr = 1; dc_wclg(loglev, errgrp, numerr, errstr, &iret); return; } break; } /* Check date string is formatted correctly */ if ( (iret = sscanf(result,"%d-%d-%dT%d:%d:%d", &year, &month, &day, &hour, &minute, &second )) != 6 ) { printf("Unexpected date string %s\n",result); return; } /* Initialize time zone information */ if(isinit) { isinit = 0; putenv("TZ=UTC0"); tzset(); } /* Convert time to seconds*/ obstime.tm_sec = second; obstime.tm_min = minute; obstime.tm_hour = hour; obstime.tm_mday = day; obstime.tm_mon = month - 1; obstime.tm_year = year - 1900; /* year since 1900 */ obstime.tm_wday = 0; obstime.tm_yday = 0; obstime.tm_isdst = 0; obsclock = mktime ( &obstime ); /* The following are present regardless of file version */ flashdat.sec = (int)obsclock; flashdat.nsec = 0; flashdat.lat = slat; flashdat.lon = slon; flashdat.sgnl = sgnl; switch ( filver ) { case 4: flashdat.mult = mult; flashdat.semimaj = RMISSD; flashdat.eccent = RMISSD; flashdat.angle = RMISSD; break; case 6: flashdat.mult = 1; flashdat.semimaj = emaj; flashdat.eccent = emin; flashdat.angle = axisor; break; } flashdat.chisqr = RMISSD; (void)write_point(ltgf, flashdat, &iret); if ( iret != 0 ) printf("%d look line %s %f %f %f %d [%d %d %d]\n",iret, result,slat,slon,sgnl,mult, obstime.tm_year, obstime.tm_mon, obstime.tm_mday); }
int main ( int argc, char *argv[] ) /************************************************************************ * DCREDBOOK * * * * This program decodes REDBOOK graphics files and outputs them as * * standard graphics format files from GEMPAK device drivers. * * * * Command line: * * dcgrib [options] device * * device output file device * ** * * Log: * * Chiz/Unidata 8/00 * ***********************************************************************/ { /* ** Change the values of these default variables for the ** specific decoder. ** ** These variables are the number of expected command line ** parameters; the program name; the packing and station tables; ** values for the the number of additional stations and the ** number of times; and the number of hours, prior to the ** "current" time, to decode. */ #define NUMEXP 1 int nexp = NUMEXP; char *prgnam = "DCREDBOOK"; char *defprm = " "; char *defstn = " "; char *dfstn2 = " "; int idfadd = 0; int idfmax = 1; int ndfhr1 = 0; int ndfhr2 = 0; int idfwdh = 0; /* ** Do not change these variables. These variables are used by all ** decoders for getting the command line parameters. */ char parms[NUMEXP][DCMXLN], curtim[DCMXLN]; int num, iret, ier; char gemdev[DCMXLN], stntbl[DCMXLN], stntb2[DCMXLN], prmfil[DCMXLN]; int iadstn, maxtim, nhours, txtflg, crcflg, iwndht; char errstr[DCMXLN]; /*---------------------------------------------------------------------*/ /* ** Initialize the output logs, set the time out and ** parse the command line parameters. dc_init calls in_bdta in 5.4.3+. */ dc_init ( prgnam, argc, argv, nexp, parms, &num, &iret ); /* ** Check for an initialization error. ** On an error, exit gracefully. */ if (( iret < 0 )&&(iret != -11)) { sprintf ( errstr, "Error initializing\0" ); dc_wclg ( 0, "DC", iret, errstr, &ier ); dc_exit ( &iret ); } /* ** Set the decoder parameters to the command line entries or ** default values. */ dc_gopt ( defprm, defstn, dfstn2, idfadd, idfmax, ndfhr1, ndfhr2, idfwdh, prmfil, stntbl, stntb2, &iadstn, &maxtim, curtim, &nhours, &txtflg, &crcflg, &iwndht, &iret ); /* ** The if the output file name is not present, use gribkey table ** ** Change this section for the specific decoder. */ strcpy ( gemdev, parms[0] ); /* ** Call the decoding routine. ** ** Change this function call, and the define command, ** for the specific decoder. */ decode_redbook (gemdev, stntbl, &iret); /* ** Send shut down message and close the log files. */ dc_exit ( &iret ); }
void dc_shnd ( int sig ) /************************************************************************ * dc_shnd * * * * This routine will process the given signal. * * * * dc_shnd ( sig ) * * * * Input parameters: * * sig int Signal to process * * * * Output parameters: * * * ** * * Log: * * A. Chang/EAi 5/95 * * S. Jacobs/NMC 7/95 Update and clean up * * S. Jacobs/NCEP 6/96 Updated documentation * * K. Tyle/GSC 1/97 Changed numerr = 0 to 2 in dc_wclg calls* * S. Jacobs/NCEP 2/01 Removed all references to ulog * ***********************************************************************/ { int ier; char errstr[DCMXLN]; /*---------------------------------------------------------------------*/ signal ( sig, SIG_IGN ); /* ** Process the trapped signal. */ switch ( sig ) { case SIGINT : /* ** Interrupt ** Send a message to the log files and exit. */ strcpy ( errstr, "Interrupt Signal" ); dc_wclg ( 0, "DC", 2, errstr, &ier ); dc_exit ( &ier ); case SIGTERM : /* ** Terminate ** Send a message to the log files and exit. */ strcpy ( errstr, "Terminate Signal" ); dc_wclg ( 0, "DC", 2, errstr, &ier ); dc_exit ( &ier ); case SIGPIPE : /* ** Broken pipe ** Send a message to the log files and exit. */ strcpy ( errstr, "Broken Pipe Signal" ); dc_wclg ( 0, "DC", 2, errstr, &ier ); dc_exit ( &ier ); } signal ( sig, dc_shnd ); }
int write_point(nldn_file ltgf, nldn_flash flashdat, int *iret) { int i,numerr,loglev,ier,isfull; char errstr[80],filnam[256]; static char tmplnam[256], oldnam[256]; static char errgrp[] = {"write_point"}; static int iflno=-1; char cparms[40][4],stid[5]; int nparms; float ndata[8]; static int jparms[40]; static char stnfil[] = {" "}; static int nadstn = 0; int year, month, day, hour, minute, seconds, isecoff; int idtarr[5],idate,itime,ihhmm; time_t obs_time; char timestr[81],gemtime[20]; struct tm *gmt_time=NULL,new_time; static int filseq=-1; /* printf("flashdat.angle = %f\n", flashdat.angle); */ if(iflno < 0) { tmplnam[0] = '\0'; oldnam[0] = '\0'; } obs_time = (time_t) flashdat.sec; gmt_time = gmtime(&obs_time); new_time = *gmt_time; /* copy the time since gmtime pointer is volotile */ timestr[0] = '\0'; strftime(timestr,80,"%Y %m %d %H %M %S",&new_time); sscanf(timestr,"%d %d %d %d %d %d",&year,&month,&day,&hour,&minute,&seconds); idtarr[0] = year; idtarr[1] = month; idtarr[2] = day; idtarr[3] = hour; /* if itype ==4 using minute bins, use bin for NN template */ if(ltgf.itype == 4) idtarr[4] = ltgf.ibin*(minute / ltgf.ibin); else idtarr[4] = minute; ti_itoc(idtarr,gemtime,&ier,sizeof(gemtime)); for(i=0;i<sizeof(gemtime);i++) if(gemtime[i] <= ' ') gemtime[i] = '\0'; /* get ihhmm idate and itime for data storage using sfnldn */ idate = (year % 100 ) * 10000 + month * 100 + day; ihhmm = hour * 100 + minute; /* do ifactor */ if(ltgf.itype == 4) itime = ltgf.ifactor*(minute / ltgf.ifactor); else itime = 0; itime = itime + (hour * 100); /* calculate seconds in the day */ isecoff = (new_time.tm_hour * 3600) + (new_time.tm_min * 60) + new_time.tm_sec; cfl_mnam(gemtime, ltgf.gemfil, filnam, &ier ); strcpy(tmplnam,filnam); if( oldnam[0] == '\0' ) { filseq = 0; templseq(tmplnam,filnam,filseq); dc_fcyl(filnam,<gf.iflsrc,stnfil,&nadstn,<gf.maxtim, &iflno, &nparms, cparms, &ier, strlen(filnam),strlen(stnfil),sizeof(cparms[0])); sprintf(errstr,"Opened output file %s\0",filnam); loglev = 1; numerr = ier; dc_wclg(loglev, errgrp, numerr, errstr, &ier); setcparm(cparms,&nparms,jparms,4); } else { if(strcmp(oldnam,tmplnam) != 0) { nldnflush(&iflno,&ier); dc_fcls(&ier); filseq = 0; templseq(tmplnam,filnam,filseq); dc_fcyl(filnam,<gf.iflsrc,stnfil,&nadstn,<gf.maxtim, &iflno, &nparms, cparms, &ier, strlen(filnam),strlen(stnfil),sizeof(cparms[0])); sprintf(errstr,"New output file %s\0",filnam); loglev = 1; numerr = ier; dc_wclg(loglev, errgrp, numerr, errstr, &ier); setcparm(cparms,&nparms,jparms,4); } } /* do the write */ memset(stid,0,5); if( flashdat.sgnl < 0 ) strcat(stid,"- "); else strcat(stid,"+ "); for(i=0;i<8;i++) ndata[i] = -9999.; if( jparms[SGNL] != 0 ) ndata[jparms[SGNL] - 1] = flashdat.sgnl; if( jparms[MULT] != 0 ) ndata[jparms[MULT] - 1] = flashdat.mult; if( jparms[TSEC] != 0 ) ndata[jparms[TSEC] - 1] = isecoff; if( jparms[MSEC] != 0 ) ndata[jparms[MSEC] - 1] = flashdat.nsec/1e6; if( jparms[SMAJ] != 0 ) ndata[jparms[SMAJ] - 1] = flashdat.semimaj; if( jparms[ECNT] != 0 ) ndata[jparms[ECNT] - 1] = flashdat.eccent; if( jparms[ANGL] != 0 ) ndata[jparms[ANGL] - 1] = flashdat.angle; if( jparms[CHI2] != 0 ) ndata[jparms[CHI2] - 1] = flashdat.chisqr; sprintf(errstr,"%s %6.2f %7.2f\0",gemtime,flashdat.lat,flashdat.lon); loglev = 3; numerr = 0; dc_wclg(loglev, errgrp, numerr, errstr, &ier); isfull = 0; sfnldn(&iflno,&idate,&itime,stid,&flashdat.lat,&flashdat.lon, &ihhmm, ndata, &ier, 4); if(ier != 0) { if(ier == -1) isfull = -1; sprintf(errstr,"%s %d\0",filnam,ier); loglev = 1; numerr = 0; dc_wclg(loglev, errgrp, numerr, errstr, &ier); } while((isfull == -1)&&(filseq < 100)) { nldnflush(&iflno,&ier); dc_fcls(&ier); filseq++; templseq(tmplnam,filnam,filseq); dc_fcyl(filnam,<gf.iflsrc,stnfil,&nadstn,<gf.maxtim, &iflno, &nparms, cparms, &ier, strlen(filnam),strlen(stnfil),sizeof(cparms[0])); setcparm(cparms,&nparms,jparms,4); printf("got here...need to reload ndata\n"); sfnldn(&iflno,&idate,&itime,stid,&flashdat.lat,&flashdat.lon, &ihhmm, ndata, &ier, 4); isfull = ier; loglev = 1; numerr = ier; sprintf(errstr,"New output file %s\0",filnam); dc_wclg(loglev, errgrp, numerr, errstr, &ier); } oldnam[0] = '\0'; strcat(oldnam,tmplnam); *iret = ier; return(iflno); }
void dcwwstore(int *iflno, char *gemtime, float rdata[], int *iret) { float slat=-9999.0,slon=-9999.0,selv=0; char state[]="--", country[]="US"; char stid[9],ostid[9]; int isnum,wnum; int hour; int ier; int exist; int ispri; int loglev,ilog; char logid[]="DCWATCH"; char errstr[81]; *iret = 0; wnum = (int)rdata[WNUM]; sprintf(stid,"WW%04d \0",wnum); sprintf(ostid," \0"); if(rdata[CANCEL] != 0) { loglev = 1; errstr[0] = '\0'; sprintf(errstr,"watch %d is cancelled\0",wnum); dc_wclg( loglev, logid, *iret, errstr, &ilog); sf_tstn(iflno,stid,&ier,sizeof(stid)-1); if(ier == 0) { sf_tnxt(iflno,gemtime,&ier,strlen(gemtime)); if(ier == 0) { sf_rdat(iflno,rdata,&hour,&ier); rdata[CANCEL] = 1; if(ier == 0) sf_wdat(iflno,&hour,rdata,&ier); } else { *iret = -10; loglev = 1; errstr[0] = '\0'; sprintf(errstr,"time not found to cancel %d\0",ier); dc_wclg( loglev, logid, *iret, errstr, &ilog); } } else { *iret = -10; loglev = 1; errstr[0] = '\0'; sprintf(errstr,"watch %d was not in file %d\0",wnum,ier); dc_wclg( loglev, logid, *iret, errstr, &ilog); } return; } hour = ((int)rdata[ISSUE]) % 10000; /* If time exists, and watch number exist, and this is not a correction- it is a duplicate....return */ sf_stim(iflno,gemtime,&ier,strlen(gemtime)); if(ier == 0) { sf_sstn(iflno,stid,ostid,&isnum,&slat,&slon,&selv,&ispri,&ier, sizeof(stid)-1,sizeof(ostid)-1); if((ier == 0)&&(rdata[CORR] == 0)) { loglev = 1; errstr[0] = '\0'; sprintf(errstr,"Duplicate report for %s\0",stid); dc_wclg( loglev, logid, ier, errstr, &ilog); return; } } if(rdata[CORR] == 0) /* not a correction, not a duplicate */ { loglev = 2; errstr[0] = '\0'; sprintf(errstr,"writing %s %s\0",gemtime,stid); dc_wclg( loglev, logid, *iret, errstr, &ilog); sf_wsdd(iflno,gemtime,stid,&wnum,&slat,&slon,&selv,state,country,&hour,rdata,&ier, strlen(gemtime),sizeof(stid)-1,strlen(state),strlen(country)); } else { /* Correct report */ loglev = 1; errstr[0] = '\0'; sprintf(errstr,"correction received: %s\0",stid); dc_wclg( loglev, logid, *iret, errstr, &ilog); sf_tstn(iflno,stid,&ier,sizeof(stid)-1); if(ier == 0) { sf_tnxt(iflno,gemtime,&ier,strlen(gemtime)); if(ier == 0) { sf_ddat(iflno,&ier); if(ier != 0) { loglev = 1; errstr[0] = '\0'; sprintf(errstr,"Error deleting old data: WW%04d\0",wnum); dc_wclg( loglev, logid, ier, errstr, &ilog); } sf_wdat(iflno,&hour,rdata,&ier); /* write corrected report */ } else { loglev = 1; errstr[0] = '\0'; sprintf(errstr,"time not found to correct %s %s\0", stid,gemtime); dc_wclg( loglev, logid, ier, errstr, &ilog); /* so lets still write this correction as a new entry */ sf_wsdd(iflno,gemtime,stid,&wnum,&slat,&slon,&selv,state,country, &hour,rdata,&ier,strlen(gemtime),sizeof(stid)-1,strlen(state),strlen(country)); } } else { loglev = 1; errstr[0] = '\0'; sprintf(errstr,"didn't find station in file WW%04d\0",wnum); dc_wclg( loglev, logid, ier, errstr, &ilog); /* so lets still write this correction as a new entry */ sf_wsdd(iflno,gemtime,stid,&wnum,&slat,&slon,&selv,state,country, &hour,rdata,&ier,strlen(gemtime),sizeof(stid)-1,strlen(state), strlen(country)); } } }
void decode_grib (char *gemfil, int maxgrd, int *iret) { /************************************************************************ * void decode_grib ( gemfil, maxgrd, iret) * * char *gemfile output gempak grid file name * * int maxgrd maximum number of grids in output file * * int *iret Error code return * * * * Error Codes * * -51 failed to read grib tables * * -52 grdnav.tbl error * * -53 file template not available * * -55 number of gridpoints too large * * Log: * * Chiz/Unidata 12/99 Created * *************************************************************************/ size_t griblen; char filnam[132]; int ier, gvers; int numerr, loglev; char errstr[80]; static char errgrp[] = "DCGRIB"; unsigned char *gribbul = NULL; *iret = 0; /* ** Initialize the nacmn.cmn common block for grid tables */ na_init (iret); /* ** Set the GBDIAG variable for verbose output if necessary */ if (ivrblv >= 3) { GBDIAG_GDS = TRUE; GBDIAG_PDS = TRUE; GBDIAG_BDS = TRUE; } while ((*iret == 0) || ( *iret < -10 ) ) { /* ** Get a single GRIB product from the input stream. ** If *iret != 0, keep looking for GRIB messages we can handle. */ gribbul = dc_ggrib (&griblen, &gvers, iret); if ( (*iret != 0) || ( gribbul == NULL ) ) continue; switch (gvers) { case 0: case 1: /* send grib1 bulletins to decode_grib1 */ decode_grib1 (gribbul, griblen, gemfil, filnam, maxgrd, iret); break; case 2: /* send grib2 bulletins to decode_grib2 */ decode_grib2 (gribbul, griblen, gemfil, filnam, maxgrd); break; default: loglev = 0; numerr = -70; sprintf (errstr, "Unknown GRIB version %d\0", gvers); dc_wclg (loglev, errgrp, numerr, errstr, &ier); } nbull++; } /* ** Close all open files */ dcgfcls (&ier); }
int main(int argc, char *argv[], char *envp[]) { char clength[4]; char *block = (char *)malloc(8192), *oblock = (char *)malloc(262144); unsigned isize = 8192, osize=262144, olength; int length, go; int compress = 0; char *logfname = ""; int bzip2 = 1; int filter = 0; int fd; char stid[5]={0}; #define NUMEXP 1 int nexp = NUMEXP; char *prgnam = "DCNEXR2"; char *defprm = " "; char *defstn = " "; char *dfstn2 = " "; int idfadd=0; int idfmax=0; int ndfhr1=0; int ndfhr2=0; int idfwdh = 0; /* ** Do not change these variables. These variables are used by all ** decoders for getting the command line parameters. */ char parms[NUMEXP][DCMXLN], newfil[DCMXLN], curtim[DCMXLN]; int i, j, num, iret, ier; char stntbl[DCMXLN], stntb2[DCMXLN], prmfil[DCMXLN]; int iadstn, maxtim, nhours, txtflg, crcflg, iwndht; char errstr[DCMXLN]; extern int optind, opterr; extern char *optarg; int ch; long flen; if(atexit(cleanup) != 0) { printf("could not register exit routine\n"); } /* ** Initialize the output logs, set the time out and ** parse the command line parameters. dc_init calls in_bdta in 5.4.3+. */ /* * process some extra arguments "fC:" for this routine */ num = argc; i = 1; while ( i < num ) { if ( strcmp(argv[i], "-f") == 0 ) { num--; filter = 1; for ( j = i+1; j < argc; j++ ) argv[j-1] = argv[j]; continue; } if ( strcmp(argv[i], "-C") == 0 ) { /* optional compression specification for future use */ num-=2; for ( j = i+2; j < argc; j++ ) argv[j-2] = argv[j]; continue; } i++; } argc = num; dc_init ( prgnam, argc, argv, nexp, parms, &num, &iret ); /* ** Check for an initialization error. ** On an error, exit gracefully. */ if ( iret == -11 ) { fd = 1; } else if ( iret < 0 ) { sprintf ( errstr, "Error initializing\0" ); dc_wclg ( 0, "DCNEXR2", iret, errstr, &ier ); dc_exit ( &iret ); } else { char *cpos = strrchr(parms[0],'/'); if ( cpos == NULL ) sprintf(filnam,".%s\0",parms[0]); else { strncpy(filnam,parms[0],cpos - parms[0]+1); strncat(filnam,".",1); strcat(filnam,cpos+1); } cfl_inqr ( parms[0], NULL, &flen, newfil, &iret ); if(iret != 0) { filptr = parms[0]; strcpy(newfil,filnam); sprintf ( errstr, "new output file %s\0",newfil); dc_wclg ( 0, "DCNEXR2", iret, errstr, &ier ); } if ((fd=mkdirs_open(newfil,O_WRONLY | O_CREAT, 0664)) == -1) { sprintf ( errstr, "Cannot open %s\0", newfil); iret = -10; dc_wclg ( 0, "DCNEXR2", iret, errstr, &ier ); dc_exit( &iret ); } lseek(fd, 0, SEEK_END); } /* ** Set the decoder parameters to the command line entries or ** default values. */ dc_gopt ( defprm, defstn, dfstn2, idfadd, idfmax, ndfhr1, ndfhr2, idfwdh, prmfil, stntbl, stntb2, &iadstn, &maxtim, curtim, &nhours, &txtflg, &crcflg, &iwndht, &iret ); if(stntbl[0] != '\0') { strncat(stid,stntbl,4); sprintf ( errstr, "STID set to %s\0", stid ); dc_wclg ( 2, "DCNEXR2", iret, errstr, &ier ); } /* * set up signal handlers */ go = 1; while (go) { /*bufread(0, (char *)(&length), 4, &i);*/ bufread(0, clength, 4, &i); if (i != 4) { if (i > 0) { sprintf ( errstr, "Short block length\0"); iret = -5; dc_wclg ( 0, "DCNEXR2", iret, errstr, &ier ); } else iret = 0; dc_exit(&iret); } if ( (memcmp(clength, "ARCH", 4)==0) || (memcmp(clength, "AR2V", 4)==0) ) { memcpy(block, clength, 4); bufread(0, block+4, 20, &i); if (i != 20) { sprintf ( errstr, "Missing header\0"); iret = -5; dc_wclg ( 0, "DCNEXR2", iret, errstr, &ier ); dc_exit( &iret); } if ( stid[0] != 0 ) memcpy(block+20,stid,4); lseek(fd, 0, SEEK_SET); write(fd, block, 24); continue; } length = 0; for(i=0;i<4;i++) length = ( length << 8 ) + (unsigned char)clength[i]; if(length < 0) { sprintf ( errstr, "EOF %ld\0",length); iret = -9; dc_wclg ( 2, "DCNEXR2", iret, errstr, &ier ); length = -length; go = 0; } if (length > isize) { isize = length; sprintf ( errstr, "Expanding input buffer to %d\0", isize); iret = -7; dc_wclg ( 2, "DCNEXR2", iret, errstr, &ier ); if ((block = (char *)realloc(block, isize)) == NULL) { sprintf ( errstr, "Cannot allocate input buffer\0"); iret = -4; dc_wclg ( 0, "DCNEXR2", iret, errstr, &ier ); dc_exit( &iret ); } } sprintf(errstr, "read block size %d\0",length); dc_wclg ( 4, "DCNEXR2", 0, errstr, &ier ); bufread(0, block, length, &i); if (i != length) { sprintf ( errstr, "Short block read\0"); iret = -5; dc_wclg ( 0, "DCNEXR2", iret, errstr, &ier ); dc_exit( &iret ); } if (length > 10) { int error; tryagain: olength = osize; if (bzip2 == 1) #ifdef BZ_CONFIG_ERROR error = BZ2_bzBuffToBuffDecompress(oblock, &olength, /*error = bzBuffToBuffDecompress(oblock, &olength,*/ #else error = bzBuffToBuffDecompress(oblock, &olength, #endif block, length, 0, 0); if (error) { if (error == BZ_OUTBUFF_FULL) { osize += 262144; sprintf(errstr, "Expanding output buffer to %d\0", osize); iret = -7; dc_wclg ( 2, "DCNEXR2", iret, errstr, &ier ); if ((oblock=(char*) realloc(oblock, osize)) == NULL) { sprintf(errstr, "Cannot allocate output buffer\0"); iret = -4; dc_wclg ( 0, "DCNEXR2", iret, errstr, &ier ); dc_exit(&iret); } goto tryagain; } sprintf(errstr, "decompress error - %d\0", error); iret = -5; dc_wclg ( 0, "DCNEXR2", iret, errstr, &ier ); dc_exit( &iret); } if (filter) { int i; for (i=0; i < olength; i += 2432) { struct packet *packet=(struct packet *) (oblock+i); if (packet->type != 2 || packet->rad_status != 28) write(fd, oblock+i, 2432); } } else write(fd, oblock, olength); } nbull++; }