/*
** Do not change these include commands.
** All necessary header files are included in "geminc.h".
** All macros and constants are in "gemprm.h" and "bridge.h".
*/

#include "geminc.h"
#include "gemprm.h"
#include "bridge.h"

#include "decod_ut.h"

main ( argc, argv )
	int	argc;
	char	*argv[];

/************************************************************************
 * DCSYNP								*
 *									*
 * This program decodes bulletins containing WMO-migrated synoptic   	*
 * BUFR messages into NCEP BUFR format.  	                    	*
 *									*
 *	Command line:							*
 *	    dcsynp [options] [r40fil] [bufrt000] [bufrt001] [wgosid]	*
 *									*
 *	    r40fil	= file of WMO Resolution 40 bulletin headers	*
 *	    bufrt000	= NCEP BUFR tables file for type 000		*
 *	    bufrt001	= NCEP BUFR tables file for type 001		*
 *	    wgosid      = wigos ids test CWAO                           *
 *									*
 **									*
 * Log:									*
 * J. Ator/NCEP		08/12						*
 * J. Ator/NCEP		12/14	Add r40fil argument to command line	*
 * J. Ator/NCEP         01/19   Modify for Dell environment		*
 * M. Weiss/IMSG        10/19   Add wgosid wigos ids Canada (CWAO)      * 
 *                              test sites                              *
 * J. Ator/NCEP		11/19	Route CMAN rpts to new b001/xx104 tanks	*
 * J. Ator/NCEP         09/21   Modify for WCOSS2 environment           *
 ***********************************************************************/

{

#define NUMEXP	4

	int	nexp	= NUMEXP;
	char	*prgnam = "DCSYNP";

/*
**	Define the standard decoder parameters.
*/
	char	stntbl[DCMXLN], stntb2[DCMXLN];
	char	prmfil[DCMXLN];
	int	iadstn;
	int	maxtim;
	int	nhours;
	int	txtflg;
	int	iwndht;
        int     circflg;

/*
**	Define default values for the standard decoder parameters.
*/
	char	*defprm	= " ";
	char	*defstn	= " ";
	char	*dfstn2	= " ";
	int	idfadd	= 0;
	int	idfmax	= 0;
	int	ndfhr1	= 240;
	int	ndfhr2	= 240;
	int	idfwdh	= 0;

/*
**	Define the additional decoder parameters.
*/
	const char *dvstr = DVSTR;  /* DVSTR is a compile-time macro */
	char	r40fil[DCMXLN];
	char	bufrt000[DCMXLN];
	char	bufrt001[DCMXLN];
        char    wgosid[DCMXLN];

/*
**	Do not change these variables.  These variables are used by all
**	decoders for getting the command line parameters.
*/
	char	parms[NUMEXP][DCMXLN];
	char	curtim[DCMXLN];
	int	num;
	int	iret;
	int	ier;


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

/*
**	Initialize the output logs, set the time out, and 
**	parse the command line parameters.
*/
	dc_init ( prgnam, argc, argv, nexp, parms, &num, &iret );

/*
**	Check for an initialization error.
*/
	if  ( iret < 0 )  {
	    dc_exit ( &iret );
	}

/*
**	Set each standard decoder parameter to the value from the
**	command line options (if defined) or else to the default
**	value.
*/
        dc_gopt ( defprm, defstn, dfstn2, idfadd, idfmax, ndfhr1,
                  ndfhr2, idfwdh, prmfil, stntbl, stntb2, &iadstn,
                  &maxtim, curtim, &nhours, &txtflg, &circflg,
                  &iwndht, &iret );

/*
**	Set default values for the additional decoder parameters.
*/
	strcpy ( bufrt000, "bufrtab.000" );
	strcpy ( bufrt001, "bufrtab.001" );

/*
**	Now, for each additional decoder parameter, if a value was
**	defined on the command line, then use that value instead of
**	the default value.
*/
	if  ( num > 0 )  {
	    strcpy ( r40fil, parms[0] );
	}

	if  ( num > 1 )  {
	    strcpy ( bufrt000, parms[1] );
	}

	if  ( num > 2 )  {
	    strcpy ( bufrt001, parms[2] );
	}

	if  ( num > 3 )  {
	    strcpy ( wgosid, parms[3] );
	}

/*
** Call the decoding routine.
**
** Change this function call, define command and prototype for the
** specific decoder.
*/

#ifdef UNDERSCORE
#define sy_dcod sy_dcod_
#endif

	void sy_dcod ( char *, char *, char *, char *, char *, int *, int *,
                       size_t, size_t, size_t, size_t, size_t );


	ut_prvs ( dvstr, strlen(dvstr) );
	sy_dcod ( curtim, r40fil, bufrt000, bufrt001, wgosid, &nhours, &iret, 
		  strlen(curtim), strlen(r40fil),
		  strlen(bufrt000), strlen(bufrt001), strlen(wgosid) );

/*
**	Send shut down message and close the log files.
*/
	dc_exit ( &iret );

}