/* *********************************************************
 * *                                                       * 
 * *                TS Archive Library                     * 
 * *          Load Setup Information From file             * 
 * *                                                       * 
 * *********************************************************
 * File: ts/archlib/Load.c
 *
 *                   COPYRIGHT (c) 2003, 2004 BY 
 *          SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.  
 * 
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED. 
 */     

#define INCLUDE_STDIO_PROTOTYPES 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "sigtypes.h"
#include "headers.h"

#define LIM_DEFINITIONS
#define LIM_KERNEL tsarchlib_limits_kernel
#include "config_lib.h"
#include "user_lib.h"

#include "ericsson_ewis.h"

static MESSAGE LIM_KERNEL
( const char *sname_a,		/* Name of structure */
  void *item_a,			/* Pointer to structure */
  SINT4 ioper_a,		/* Operation to perform */
  const char *spath_a,		/* Full path name of fields */
  void *ioarg_a ) ;		/* Diagnostic messages, or NULL */

MESSAGE tsarchlib_limits
( const char *sname_a,		/* Name of structure */
  volatile void *item_a,	/* Pointer to structure */
  SINT4 ioper_a,		/* Operation to perform */
  void *file_a )		/* Diagnostic messages, or NULL */
{
  return( lim_toplevel( sname_a, item_a, ioper_a, file_a, LIM_KERNEL ) ) ;
}

/* ======================================================================
 * Internal routine to recursively descend the config structure.
 */
static MESSAGE LIM_KERNEL
( const char *sname_a,		/* Name of structure */
  void *item_a,			/* Pointer to structure */
  SINT4 ioper_a,		/* Operation to perform */
  const char *spath_a,		/* Full path name of fields */
  void *ioarg_a )		/* Diagnostic messages, or NULL */
{
  char *sItem ; struct lim_inLine **pLine ;
  char spath[PATHNAME_SIZE];
  SINT4 idim1=0, idim2=0 ; MESSAGE istatus = SS_NORMAL ;

  /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  if( 0 == strcmp( "convert_config", sname_a ) ) {
    struct convert_config *item = (struct convert_config*)item_a ;

    STRING( sVersion, "" ) ;
    SUBSTRUCTURE_1D( convert_site_table, Sites, MAX_PIPE_SITES ) ;
    SUBSTRUCTURE( sig_logging_spec, logging );
    SCALAR( lLatitudeFirst,      0,        1,     1 ) ;
    SCALAR( fPolarRangeRes,    0.0,      5.0,   0.0 ) ;
    SCALAR( iPolarBinCount,      0, MAX_BINS,     0 ) ;
    SCALAR( fDopPolarRangeRes, 0.0,      5.0,   0.0 ) ;
    SCALAR( iDopPolarBinCount,   0, MAX_BINS,     0 ) ;
  }

  else if( 0 == strcmp( "convert_site_table", sname_a ) ) {
    struct convert_site_table *item = (struct convert_site_table*)item_a ;

    STRING( sIrisSiteName16, "" ) ;
    STRING( sEwisPlace20, "" ) ;
  }

  else if( 0 == strcmp( "sig_logging_spec", sname_a ) ) {
    struct sig_logging_spec *item = (struct sig_logging_spec*)item_a ;

    SCALAR(  lLogToFile,       0,      1,     1 ) ;
    SCALAR(  lLogToTerm,       0,      1,     0 ) ;
    SCALAR(  lVerbose,         0,      1,     0 ) ;
    SCALAR(  lAppendToLog,     0,      1,     0 ) ;
  }

  /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  else
    istatus = iMessageMod_va( CONFIG_LIM_BADSTRUCT, 1, sname_a ) ;

  return( istatus ) ;
}

/* =================================================================== 
 * This subroutine reads the saved values from the setup file.
 */
MESSAGE LoadSetup
( const char *sRemoteHostname_a,
  struct convert_config *pCSetup_a )
{
  memset( (void *)pCSetup_a, 0, sizeof(struct convert_config) ) ;

  return( lim_loadFile( sRemoteHostname_a, "IrisToEwis.conf", "convert_config",
			pCSetup_a, tsarchlib_limits ) ) ;
}
