static char szModuleName__[] = "c:/nordrad/unix/nrd_un~1.c";
static char szLastVersion[] = "Version 0.14";
static char szLastSave[] = "1997-02-09*22:05";

/************************************************************
Abstract
nrd_unix_apitst.c - Test pgm for NORDRAD C-API

Start pgm by typing : nrd_unix_apitst

(C) Copyright AU-System Communication AB 1994.

Change activity
1997-09-08      ARg  Modified time type
1997-02-09      ARg  Modified for 8 bit BUFR
1993-06-22 1.00 BBN  Initial version by Bj”rn Brodin.

Part of  Nordrad.

Description
************************************************************                */

#ifdef   VMS
#include <types.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stat.h>
#include <socket.h>
#include <in.h>
#include "netdef.h"
#include "api.h"
#include "net.h"
#include "utl.h"
#include "comp.h"
#include "ewiscomp.h"
#include "nradutil.h"
#else
#ifdef   __MSDOS__
#include "netdef.h"
#include "api.h"
#include "net.h"
#include "utl.h"
#include "comp.h"
#include "nradutil.h"
#endif
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/socket.h>

/* #include <sys/socketvar.h>                                               */

#include <netinet/in.h>
#ifndef  __MSDOS__
#include "netdef.h"
#include "api.h"
#include "net.h"
#include "utl.h"
#include "comp.h"
#include "nradutil.h"
#endif
#endif

/*----------------------------------------------------------
*       Macros
*---------------------------------------------------------                  */

#define  CMD_MOD_DEFAULT 10
#define  CMD_STORE_PROD 11
#define  CMD_GET_PROD  12
#define  CMD_SEARCH_PROD 13
#define  CMD_SUBSCR_AVI 14
#define  CMD_RECEIVE_AVI 15
#define  CMD_CANCEL_AVI 16
#define  CMD_PACK      17
#define  CMD_UNPACK    18
#define  CMD_FILE_DEFAULT 19
#define  CMD_RESET     20
#define  CMD_SET_LOG   21
#define  CMD_STOP_LOG  22
#define  CMD_RUN       23
#define  CMD_MESSAGE   24
#define  CMD_WAIT      25
#define  CMD_CONTINUE_SCRIPT 26
#define  CMD_BREAK_SCRIPT 27
#define  CMD_SET_TIMER 28
#define  CMD_SET_SEARCH_CRIT 29
#define  CMD_SHOW_DATA 30
#define  CMD_GET_SEARCH_AVI 31
#define  CMD_SET_SUBSCR_HANDLE 32
#define  CMD_IMPORT      33
#define  CMD_EXPORT      34
#define  CMD_CONV_TO_SRI 35
#define  CMD_PACK_EWIS   36
#define  CMD_UNPACK_EWIS 37
#define  CMD_HELP      50
#define  CMD_QUIT      51
#define  SHOW_ALL      1               /* used in ShowData                  */
#define  SHOW_PD       2
#define  SHOW_AVI      3
#define  SIZE_STR_SIZE 10
#define  TSTSPACE      0

/*----------------------------------------------------------
*       Function prototypes
*----------------------------------------------------------                 */

void SetAllVars(void);

int FetchAdaStr(char *pGuideText,char *pAdaStr,char *pDefStr,int iMaxLen);
void HelpAction(void);
void ClearAllVars(void);
void ParseCmdLine(char *pLine,char *pDataType,int *piDataTypeLen,char 
                  *pData,INT32 *piDataLen);

void ShowData(INT32 iType,struct ApiProdDescrStruc *pApiProdDescr);
void ShowPd(struct ApiProdDescrStruc *pShowProdDescr);
void StrOutput(char *pOutStr);
void GetSearchAvi(void);
INT32 GetCritVal(char *pNxtValue,struct SearchCritStruc *pSearchCrit);
char *GetCritValStr(struct SearchCritStruc *pSearchCrit,char *pCritStr);
unsigned char GetProdTypeVal(char *pProdTypeStr,unsigned char *pbVal);
char *GetProdTypeStr(unsigned char bVal,char *pProdTypeStr);
void FetchProdDescr(struct ApiProdDescrStruc *pProdDescr);
void BuildCurrTime(char *pTimeStr);
INT32 IdentifyCmd(char *pCmdStr);
int CommandAction(INT32 iCmd,char *pCmdData);
INT32 SetFileDefault(char *pFileStr,struct ApiProdDescrStruc *pProdDescr);
struct CommonAdaStrStruc
      {
        INT32 iMaxLen;
        INT32 iLen;
        char Text[1];                  /* Uses variable length depending    */
      } ;
                                       /* on witch struct it is mapped on   */

/*----------------------------------------------------------
*       Global variables / structures
*----------------------------------------------------------                 */

char AccessCtrlStr[MAX_ACCESSCTRL_SIZE+TSTSPACE];
struct ApiAviStruc ApiAvi;
char NodeNameStr[MAX_NODENAME_SIZE+TSTSPACE];
struct ApiProdDescrStruc ApiProdDescr;
char DestFileNameStr[MAX_FILE_NAME_SIZE+TSTSPACE];
char SearchDataFileStr[MAX_FILE_NAME_SIZE+TSTSPACE];
char SourceFileNameStr[MAX_FILE_NAME_SIZE+TSTSPACE];
char SearchLimFileStr[MAX_FILE_NAME_SIZE+TSTSPACE];
struct SearchCritStruc SearchCrit;
char HostNameStr[60];
char ReceiverIdStr[MAX_RECEIVERID_SIZE+TSTSPACE];
char ParamFileStr[60];
char OutParamFileStr[60];
unsigned char bPackAlg = 0;
unsigned char BufrMode = 0;
INT32 iSubscrSock = 0;
int iWaitTime = 120;
INT32 iCmdFile = FALSE;
FILE *fCmdFile = NULL;
INT32 iLogFile = FALSE;
FILE *fLogFile;
char OutLine[200];
struct ErrorDataStruc ErrMsg;
#ifdef   __BORLANDC__
extern unsigned _stklen = 10*1024;
#endif

/*---------------------------------------------------------
*       Global variables
*---------------------------------------------------------                  */
/* extern       int     errno;                                              */


/*----------------------------------------------------------
*  Init Net Activity on Socket.
*---------------------------------------------------------                  */

main(int argc,char *argv[])
{
  char *pCmdStr;
  char CmdFileStr[60];
  int Continue = TRUE;
  time_t lTime;
  char Line[100];
  char *pLine;
  char DataType[50];
  int iDataTypeLen = 0;
  char Data[100];
  INT32 iDataLen = 0;
  struct tm *pTime;
  INT32 iCmd = 0;
  char *pNextToken;
  struct ApiProdDescrStruc *pApiProdDescr;

  UtlInitErrMsgTab();
  pApiProdDescr = &ApiProdDescr;
  memset(SearchDataFileStr, 
         0, 
         sizeof(SearchDataFileStr));
  memset(pApiProdDescr, 
         0, 
         sizeof(ApiProdDescr));
  ClearAllVars();
  if (argc > 1)
    {
      iCmdFile = TRUE;
      strcpy(CmdFileStr, 
             argv[1]);
      fCmdFile = fopen(CmdFileStr, 
                       "rb");
    } 
  else
    SetAllVars();
  time(&lTime);
  pTime = localtime(&lTime);
  printf("\n***************************\n");
  printf("%s\n", 
         asctime(pTime));
  printf("***************************\n");
  if (iCmdFile == FALSE)
    printf("\nApiTst>");
  while (Continue == TRUE)
    {
      if (iCmdFile == FALSE)
        {
          pLine = gets(Line);
          pCmdStr = strtok(pLine, 
                           " =\r\f\n");
          pNextToken = strtok(NULL, 
                              " =\r\f\n");
          if (pNextToken != NULL)
            strcpy(Data, 
                   pNextToken);
        } 
      else
        {
          memset(Line, 
                 0, 
                 sizeof(Line));
          pCmdStr = NULL;
          if (feof(fCmdFile) == 0)
            {
              fgets(Line, 
                    sizeof(Line), 
                    fCmdFile);
              UtlStripStr(Line, 
                          strlen(Line), 
                          UNCHANGED, 
                          UNCHANGED);
              if (strlen(Line) > 0)
                {
                  ParseCmdLine(Line, 
                               DataType, 
                               &iDataTypeLen, 
                               Data, 
                               &iDataLen);
                  pCmdStr = DataType;
                } 
            } 
          else
            {
              fclose(fCmdFile);
              fCmdFile = NULL;
              iCmdFile = FALSE;
            } 
        } 
      if ((pCmdStr != NULL) && (strlen(pCmdStr) > 0))
        {
          iCmd = IdentifyCmd(pCmdStr);
          Continue = CommandAction(iCmd, 
                                   Data);
        } 
      if (iCmdFile == FALSE)
        printf("\nApiTst>");
    } 
  if (iCmdFile == TRUE)
    {
      fclose(fCmdFile);
      iCmdFile = FALSE;
      fCmdFile = NULL;
    } 
  if (iLogFile == TRUE)
    fclose(fLogFile);
  return (0);
} 


/*----------------------------------------------------------
*  CommandAction - Perform the Test pgm command according to
*                  command code given as in parameter iCmd.
*                  Additional info is passed on from command
*                  file or pgm start parameters in pCmdData.
*---------------------------------------------------------                  */

int CommandAction(INT32 iCmd,char *pCmdData)
{
  INT32 iRc = OK;
  long lStartTime;
  long lEndTime;
  struct ApiAviStruc *pApiAvi;
  struct SearchCritStruc *pSearchCrit;
  struct ApiProdDescrStruc *pApiProdDescr;
  char CmdStr[40];
  char TmpStr[80];
  char LoggFileStr[60];
  char OutPut[200];
  INT32 iErrInd = 0;

  pApiAvi = &ApiAvi;
  pSearchCrit = &SearchCrit;
  pApiProdDescr = &ApiProdDescr;
  switch (iCmd)
    {
      case  CMD_MOD_DEFAULT :
        SetAllVars();
        break;
      case  CMD_FILE_DEFAULT :
        if (strlen(pCmdData) == 0)
          {
            printf("Indata File/%s/:", 
                   TmpStr);
            pCmdData = gets(TmpStr);
          } 
        iRc = SetFileDefault(pCmdData, 
                             pApiProdDescr);
        if (iRc != OK)
          {
            sprintf(OutLine, 
                    "Filedata error for file=%s\n", 
                    pCmdData);
            StrOutput(OutLine);
            iCmdFile = FALSE;
          } 
        break;
      case  CMD_GET_PROD :
        strcpy(CmdStr, 
               "GetProd");
        time(&lStartTime);
        strcpy(pApiAvi->cNodeName, 
               NodeNameStr);
        memcpy(&pApiAvi->ApiProdDescr, 
               (char *)pApiProdDescr, 
               sizeof(struct ApiProdDescrStruc));
        GetProduct(AccessCtrlStr, 
                   HostNameStr, 
                   pApiAvi, 
                   DestFileNameStr, 
                   iWaitTime, 
                   &iRc);
        time(&lEndTime);
        break;
      case  CMD_STORE_PROD :
        strcpy(CmdStr, 
               "StoreProd");
        time(&lStartTime);
        StoreProduct(AccessCtrlStr, 
                     HostNameStr, 
                     pApiProdDescr, 
                     SourceFileNameStr, 
                     iWaitTime, 
                     &iRc);
        time(&lEndTime);
        break;
      case  CMD_SEARCH_PROD :
        strcpy(CmdStr, 
               "SearchProd");
        time(&lStartTime);
        SearchProduct(AccessCtrlStr, 
                      HostNameStr, 
                      pApiProdDescr, 
                      pSearchCrit, 
                      SearchLimFileStr, 
                      SearchDataFileStr,
                      iWaitTime, 
                      &iRc);
        time(&lEndTime);
        break;
      case  CMD_SUBSCR_AVI :
        strcpy(CmdStr, 
               "SubscrAvi");
        time(&lStartTime);
        SubscribeAvi(AccessCtrlStr, 
                     HostNameStr, 
                     ReceiverIdStr, 
                     iWaitTime, 
                     &iSubscrSock, 
                     &iRc);
        time(&lEndTime);
        break;
      case  CMD_RECEIVE_AVI :
        strcpy(CmdStr, 
               "ReceiveAvi");
        time(&lStartTime);
        ReceiveAvi(iSubscrSock, 
                   pApiAvi, 
                   iWaitTime, 
                   &iRc);
        if (iRc == APIOK)
          {
            strcpy(NodeNameStr,
		   pApiAvi->cNodeName);
	    memcpy((char *)pApiProdDescr, 
		   &pApiAvi->ApiProdDescr, 
		   sizeof(struct ApiProdDescrStruc));
	    ShowPd(&pApiAvi->ApiProdDescr);
          } 
        time(&lEndTime);
        break;
      case  CMD_CANCEL_AVI :
        strcpy(CmdStr, 
               "CancelAvi");
        time(&lStartTime);
        CancelAvi(iSubscrSock);
        iRc = APIOK;
        time(&lEndTime);
        break;
      case  CMD_PACK :
        strcpy(CmdStr, 
               "Pack");
        time(&lStartTime);
        Pack(SourceFileNameStr, 
             DestFileNameStr, 
             RLE, 
             &iRc);
        time(&lEndTime);
        break;
      case  CMD_UNPACK :
        strcpy(CmdStr, 
               "UnPack");
        time(&lStartTime);
        UnPack(SourceFileNameStr, 
               DestFileNameStr, 
               RLE, 
               &iRc);
        time(&lEndTime);
        break;
      case  CMD_IMPORT :
        strcpy(CmdStr, 
               "Import");
        time(&lStartTime);
        Import_BUFR(SourceFileNameStr, 
                    DestFileNameStr, 
                    ParamFileStr, 
                    OutParamFileStr, 
                    bPackAlg, 
                    pApiProdDescr, 
                    &iRc);
        time(&lEndTime);
        break;
      case  CMD_EXPORT :
        strcpy(CmdStr, 
               "Export");
        time(&lStartTime);
        Export_BUFR(SourceFileNameStr, 
                    DestFileNameStr, 
                    ParamFileStr, 
		    BufrMode,
		    &iRc);
        time(&lEndTime);
        break;
      case  CMD_CONV_TO_SRI :
        strcpy(CmdStr, 
               "Convert");
        time(&lStartTime);
        Convert_Dbz_To_SRI(SourceFileNameStr, 
                           DestFileNameStr, 
                           ParamFileStr, 
                           bPackAlg, 
                           pApiProdDescr, 
                           &iRc);
        time(&lEndTime);
        break;
      case  CMD_RESET :
        ClearAllVars();
        break;
      case  CMD_SET_LOG :
        if (iLogFile == FALSE)
          {
            if (iCmdFile == FALSE)
              {
                strcpy(TmpStr, 
                       "Netcom.log");
                printf("Logg File/%s/:", 
                       TmpStr);
                pCmdData = gets(TmpStr);
              } 
            else
              memset(TmpStr, 
                     0, 
                     sizeof(TmpStr));
            if (strlen(TmpStr) > 0)
              strcpy(LoggFileStr, 
                     TmpStr);
            fLogFile = fopen(pCmdData, 
                             "w");
            iLogFile = TRUE;
          } 
        else
        if (iCmdFile == FALSE)
          printf("Loggfile already specified\n");
        break;
      case  CMD_STOP_LOG :
        if (iLogFile == TRUE)
          {
            fclose(fLogFile);
            iLogFile = FALSE;
          } 
        break;
      case  CMD_RUN :
        if (iCmdFile == FALSE)
          {
            if (strlen(pCmdData) == 0) /* no commandfile                    */
              {                        /* specified yet                     */
                printf("Command File/%s/:", 
                       TmpStr);
                pCmdData = gets(TmpStr);
              } 
          } 
        else
          {
            if (strlen(pCmdData) > 0)
              {
                fclose(fCmdFile);
                iCmdFile = FALSE;
                fCmdFile = NULL;
              } 
          } 
        if (strlen(pCmdData) > 0)
          {
            fCmdFile = fopen(pCmdData, 
                             "rb");
            if (fCmdFile == NULL)
              {
                printf("Illegal command file name '%s'\n", 
                       pCmdData);
                return  FALSE;
              } 

            iCmdFile = TRUE;
          } 
        break;
      case  CMD_MESSAGE :
        printf(pCmdData);
        printf("\n");
        if (iLogFile == TRUE)
          fwrite(pCmdData, 
                 sizeof(char), 
                 strlen(pCmdData), 
                 fLogFile);
        fwrite("\n", 
               sizeof(char), 
               1, 
               fLogFile);
        break;
      case  CMD_WAIT :
        printf(pCmdData);
        pCmdData = gets(TmpStr);
        break;
      case  CMD_SET_TIMER :
        if (iCmdFile == FALSE)
          {
            BuildCurrTime(TmpStr);
            printf("Timer/%s/:", 
                   TmpStr);
            pCmdData = gets(TmpStr);
          } 
        iWaitTime = atoi(pCmdData);
        break;
      case  CMD_CONTINUE_SCRIPT :
        if (fCmdFile != NULL)
          iCmdFile = TRUE;
        else
          printf("No commandfile active\n");
        break;
      case  CMD_SHOW_DATA :
        ShowData(SHOW_ALL, 
                 pApiProdDescr);
        break;
      case  CMD_SET_SUBSCR_HANDLE :
        iSubscrSock = atoi(pCmdData);
        break;
      case  CMD_GET_SEARCH_AVI :
        GetSearchAvi();
        break;
      case  CMD_BREAK_SCRIPT :
        printf("\nCMD BREAK!!:%s\n<To continue use 'CS' command>\n", 
               pCmdData);
        iCmdFile = FALSE;
        break;
      case  CMD_PACK_EWIS :
        strcpy(CmdStr, 
               "PackE");
        time(&lStartTime);
	iRc = pckCompressEwisFile (SourceFileNameStr, 
				   DestFileNameStr);
        time(&lEndTime);
        break;
      case  CMD_UNPACK_EWIS :
        strcpy(CmdStr, 
               "UnPackE");
        time(&lStartTime);

	iRc = pckExpandEwisFile (SourceFileNameStr, 
             			 DestFileNameStr); 
        time(&lEndTime);
        break;


      case  CMD_QUIT :
        return  FALSE;
        break;
      default  :

        iCmd = CMD_HELP;
        HelpAction();
        break;
    } 
  if ((iCmd != CMD_QUIT) && (iCmd != CMD_HELP) && (iCmd != CMD_MOD_DEFAULT) 
     && (iCmd != CMD_FILE_DEFAULT) && (iCmd != CMD_RESET) && (iCmd != 
     CMD_SET_LOG) && (iCmd != CMD_WAIT) && (iCmd != CMD_SET_TIMER) && (iCmd 
     != CMD_SET_SEARCH_CRIT) && (iCmd != CMD_MESSAGE) && (iCmd != 
     CMD_CONTINUE_SCRIPT) && (iCmd != CMD_BREAK_SCRIPT) && (iCmd != CMD_RUN)
     && (iCmd != CMD_SHOW_DATA) && (iCmd != CMD_GET_SEARCH_AVI) && (iCmd != 
     CMD_STOP_LOG))
    {
      iErrInd = UtlSearchErrMsgTab(iRc, 
                                   ErrMsg.ConstName, 
                                   ErrMsg.ErrTxt);
      if (iErrInd >= 0)
        sprintf(OutPut, 
                "Result for=%s\n  Time used=%d sec\n  Status(hex)=%lx, Statu\
s(dec)=%ld,Const=%s\n  Msg=%s \n\n", 
                CmdStr, 
                (INT16)(lEndTime-lStartTime), 
                (INT32)iRc, 
                (INT32)iRc, 
                ErrMsg.ConstName, 
                ErrMsg.ErrTxt);
      else
        sprintf(OutPut, 
                "Result for=%s\n  Time used=%d sec\n  Status(hex)=%lx, Statu\
s(dec)=%ld,Const=%s\n  Msg=%s \n\n", 
                CmdStr, 
                (INT16)(lEndTime-lStartTime), 
                (INT32)iRc, 
                (INT32)iRc, 
                "-----", 
                "No error msg for this error code");
      if (iLogFile == TRUE)
        fwrite(OutPut, 
               sizeof(char), 
               strlen(OutPut), 
               fLogFile);
      printf(OutPut);
    } 
  return  TRUE;
} 


/*----------------------------------------------------------
*  IdentifyCmd - First word in inparameter pCmdStr consists
*                of a command string. All commands are matched
*                against it and if none is matching help command
*                is used. 
*---------------------------------------------------------                  */

INT32 IdentifyCmd(char *pCmdStr)
{
  UtlStrToUpper(pCmdStr, 
                strlen(pCmdStr));
  if ((strncmp(pCmdStr, 
               "MODIFYDEFAULT", 
               13) == 0) || strncmp(pCmdStr, 
                                    "MDEF", 
                                    4) == 0)
    return  CMD_MOD_DEFAULT;
  else

  if ((strncmp(pCmdStr, 
               "FILEDEFAULT", 
               11) == 0) || strncmp(pCmdStr, 
                                    "FDEF", 
                                    4) == 0)
    return  CMD_FILE_DEFAULT;
  else

  if ((strncmp(pCmdStr, 
               "STOREPRODUCT", 
               12) == 0) || strncmp(pCmdStr, 
                                    "STP", 
                                    3) == 0)
    return  CMD_STORE_PROD;
  else

  if ((strncmp(pCmdStr, 
               "GETPRODUCT", 
               10) == 0) || strncmp(pCmdStr, 
                                    "GP", 
                                    2) == 0)
    return  CMD_GET_PROD;
  else

  if ((strncmp(pCmdStr, 
               "SEARCHPRODUCT", 
               10) == 0) || strncmp(pCmdStr, 
                                    "SEAP", 
                                    4) == 0)
    return  CMD_SEARCH_PROD;
  else

  if ((strncmp(pCmdStr, 
               "SUBSCRIBEAVI", 
               12) == 0) || strncmp(pCmdStr, 
                                    "SUBA", 
                                    4) == 0)
    return  CMD_SUBSCR_AVI;
  else

  if ((strncmp(pCmdStr, 
               "RECEIVEAVI", 
               10) == 0) || strncmp(pCmdStr, 
                                    "RA", 
                                    2) == 0)
    return  CMD_RECEIVE_AVI;
  else

  if ((strncmp(pCmdStr, 
               "CANCELAVI", 
               10) == 0) || strncmp(pCmdStr, 
                                    "CA", 
                                    2) == 0)
    return  CMD_CANCEL_AVI;

  else
  if ((strncmp(pCmdStr, 
               "PACKE", 
               5) == 0) || strncmp(pCmdStr, 
                                   "PE", 
                                   2) == 0)
    return  CMD_PACK_EWIS;
  else

  if ((strncmp(pCmdStr, 
               "PACK", 
               4) == 0) || strncmp(pCmdStr, 
                                   "P", 
                                   1) == 0)
    return  CMD_PACK;
  else
  if ((strncmp(pCmdStr, 
               "UNPACKE", 
               7) == 0) || strncmp(pCmdStr, 
                                   "UPE", 
                                   3) == 0)
    return  CMD_UNPACK_EWIS;
  else

  if ((strncmp(pCmdStr, 
               "UNPACK", 
               6) == 0) || strncmp(pCmdStr, 
                                   "UP", 
                                   2) == 0)
    return  CMD_UNPACK;
  else

  if ((strncmp(pCmdStr, 
               "RESET", 
               5) == 0) || strncmp(pCmdStr, 
                                   "RES", 
                                   3) == 0)
    return  CMD_RESET;
  else

  if (strncmp(pCmdStr, 
               "RUN", 
               3) == 0)
    return  CMD_RUN;
  else

  if ((strncmp(pCmdStr, 
               "LOG", 
               3) == 0) || strncmp(pCmdStr, 
                                   "LG", 
                                   2) == 0)
    return  CMD_SET_LOG;
  else

  if ((strncmp(pCmdStr, 
               "NOLOG", 
               5) == 0) || strncmp(pCmdStr, 
                                   "NLG", 
                                   3) == 0)
    return  CMD_STOP_LOG;
  else

  if ((strncmp(pCmdStr, 
               "MESSAGE", 
               7) == 0) || strncmp(pCmdStr, 
                                   "MSG", 
                                   3) == 0)
    return  CMD_MESSAGE;
  else

  if ((strncmp(pCmdStr, 
               "WAIT", 
               4) == 0) || strncmp(pCmdStr, 
                                   "WA", 
                                   2) == 0)
    return  CMD_WAIT;
  else

  if ((strncmp(pCmdStr, 
               "SETTIMER", 
               8) == 0) || strncmp(pCmdStr, 
                                   "ST", 
                                   2) == 0)
    return  CMD_SET_TIMER;
  else

  if ((strncmp(pCmdStr, 
               "SETSEACRIT", 
               10) == 0) || strncmp(pCmdStr, 
                                    "CRIT", 
                                    4) == 0)
    return  CMD_SET_SEARCH_CRIT;
  else

  if ((strncmp(pCmdStr, 
               "BREAKSCRIPT", 
               11) == 0) || strncmp(pCmdStr, 
                                    "BS", 
                                    2) == 0)
    return  CMD_BREAK_SCRIPT;
  else

  if ((strncmp(pCmdStr, 
               "CONTINUESCRIPT", 
               14) == 0) || strncmp(pCmdStr, 
                                    "CS", 
                                    2) == 0)
    return  CMD_CONTINUE_SCRIPT;
  else

  if ((strncmp(pCmdStr, 
               "QUIT", 
               4) == 0) || strncmp(pCmdStr, 
                                   "Q", 
                                   1) == 0)
    return  CMD_QUIT;
  else

  if ((strncmp(pCmdStr, 
               "SHOWDATA", 
               8) == 0) || strncmp(pCmdStr, 
                                   "SD", 
                                   2) == 0)
    return  CMD_SHOW_DATA;
  else

  if ((strncmp(pCmdStr, 
               "GETSEARCHAVI", 
               12) == 0) || strncmp(pCmdStr, 
                                    "GSA", 
                                    3) == 0)
    return  CMD_GET_SEARCH_AVI;
  else

  if ((strncmp(pCmdStr, 
               "SETSUBSCRHANDLE", 
               15) == 0) || strncmp(pCmdStr, 
                                    "SUBH", 
                                    4) == 0)
    return  CMD_SET_SUBSCR_HANDLE;
  else
  if ((strncmp(pCmdStr, 
               "IMPORT", 
               6) == 0) || strncmp(pCmdStr, 
                                   "IM", 
                                   2) == 0)
    return  CMD_IMPORT;
  else

  if ((strncmp(pCmdStr, 
               "EXPORT", 
               6) == 0) || strncmp(pCmdStr, 
                                   "EX", 
                                   2) == 0)
    return  CMD_EXPORT;
  else

  if ((strncmp(pCmdStr, 
               "CONVERT", 
               7) == 0) || strncmp(pCmdStr, 
                                   "CONV", 
                                   4) == 0)
    return  CMD_CONV_TO_SRI;
  else

    return  CMD_HELP;
} 


/*----------------------------------------------------------
*  ClearAllVars - Variables containing global used API data
*                 are cleared. 
*---------------------------------------------------------                  */

void ClearAllVars(void)
{
  memset(AccessCtrlStr, 
         0, 
         sizeof(AccessCtrlStr));
  memset(&ApiAvi, 
         0, 
         sizeof(ApiAvi));
  memset(NodeNameStr, 
         0, 
         sizeof(NodeNameStr));
  strcpy(HostNameStr, 
         "192.121.2.32");
  memset(&ApiProdDescr, 
         0, 
         sizeof(ApiProdDescr));
  memset(SourceFileNameStr, 
         0, 
         sizeof(SourceFileNameStr));
  memset(DestFileNameStr, 
         0, 
         sizeof(DestFileNameStr));
  memset(SearchLimFileStr, 
         0, 
         sizeof(SearchLimFileStr));
  memset(SearchDataFileStr, 
         0, 
         sizeof(SearchDataFileStr));
  memset(&SearchCrit, 
         0, 
         sizeof(SearchCrit));
  memset(ReceiverIdStr, 
         0, 
         sizeof(ReceiverIdStr));
  memset(ParamFileStr, 
         0, 
         sizeof(ParamFileStr));
  memset(OutParamFileStr, 
         0, 
         sizeof(OutParamFileStr));
  iWaitTime = 200;
} 


/*----------------------------------------------------------
*  SetAllVars - Variables containing global used API data  
*               are promted for new values.
*---------------------------------------------------------                  */

void SetAllVars(void)
{
  struct ApiProdDescrStruc *pApiProdDescr;
  char TmpStr[80];
  char *pTmpStr;

  pApiProdDescr = &ApiProdDescr;
  printf("Host name/%s/:", 
         HostNameStr);
  pTmpStr = gets(TmpStr);
  if (strlen(pTmpStr) > 0)
    strcpy(HostNameStr, 
           pTmpStr);

  printf("\nAccessControl string/%s/:", 
         AccessCtrlStr);
  pTmpStr = gets(TmpStr);
  if (strlen(pTmpStr) > 0)
    strcpy(AccessCtrlStr, 
           pTmpStr);

  printf("Source file/%s/:", 
         SourceFileNameStr);
  pTmpStr = gets(TmpStr);
  if (strlen(pTmpStr) > 0)
    strcpy(SourceFileNameStr, 
           pTmpStr);

  printf("Dest file/%s/:", 
         DestFileNameStr);
  pTmpStr = gets(TmpStr);
  if (strlen(pTmpStr) > 0)
    strcpy(DestFileNameStr, 
           pTmpStr);

  strcpy(TmpStr, 
         ParamFileStr);
  printf("InParameter file/%s/:", 
         TmpStr);
  pTmpStr = gets(TmpStr);
  if (strlen(pTmpStr) > 0)
    strcpy(ParamFileStr, 
           pTmpStr);

  strcpy(TmpStr, 
         OutParamFileStr);
  printf("OutParameter file/%s/:", 
         TmpStr);
  pTmpStr = gets(TmpStr);
  if (strlen(pTmpStr) > 0)
    strcpy(OutParamFileStr, 
           pTmpStr);

  sprintf(TmpStr, 
          "%d", 
          bPackAlg);
  printf("Packa fil (1=Nej 0=Ja) /%s/:", 
         TmpStr);
  pTmpStr = gets(TmpStr);
  if (strlen(TmpStr) > 0)
    bPackAlg = (unsigned char)atoi(pTmpStr);
  
  sprintf(TmpStr, 
          "%d", 
          BufrMode);
  printf("BUFR mode (1=8 bit 0=4 bit) /%s/:", 
         TmpStr);
  pTmpStr = gets(TmpStr);
  if (strlen(TmpStr) > 0)
    BufrMode = (unsigned char)atoi(pTmpStr);

  printf("Search result file/%s/:", 
         SearchDataFileStr);
  pTmpStr = gets(TmpStr);
  if (strlen(pTmpStr) > 0)
    strcpy(SearchDataFileStr, 
           pTmpStr);

  printf("Node name in Avi/%s/:", 
         NodeNameStr);
  pTmpStr = gets(TmpStr);
  if (strlen(pTmpStr) > 0)
    strcpy(NodeNameStr, 
           pTmpStr);

  printf("Search limit file/%s/:", 
         SearchLimFileStr);
  pTmpStr = gets(TmpStr);
  if (strlen(pTmpStr) > 0)
    strcpy(SearchLimFileStr, 
           pTmpStr);

  printf("Receiver ID/%s/:", 
         ReceiverIdStr);
  pTmpStr = gets(TmpStr);
  if (strlen(pTmpStr) > 0)
    strcpy(ReceiverIdStr, 
           pTmpStr);

  printf("Wait time/%d/:", 
         iWaitTime);
  pTmpStr = gets(TmpStr);
  if (strlen(pTmpStr) > 0)
    iWaitTime = atoi(pTmpStr);

  FetchProdDescr(pApiProdDescr);

  printf("Subscribe handle/%d/:", 
         iSubscrSock);
  pTmpStr = gets(TmpStr);
  if (strlen(pTmpStr) > 0)
    iSubscrSock = atoi(pTmpStr);
} 


/*----------------------------------------------------------
*  SetFileDefault - Variables containing global used API data  
*                   are set to new values from data on specified
*                   file.
*---------------------------------------------------------                  */

INT32 SetFileDefault(char *pFileStr,struct ApiProdDescrStruc *pProdDescr)
{
  FILE *pDataFile;
  char Line[160];
  char DataType[50];
  char Data[100];
  int iDataTypeLen = 0;
  INT32 iDataLen = 0;
  INT32 iRc = OK;
  char *pNxtValue;

  pDataFile = fopen(pFileStr, 
                    "r");
  if (pDataFile == NULL)
    return  NOK;

  while ((feof(pDataFile) == 0) && (iRc == OK) && (fgets(Line, 
                                                         sizeof(Line), 
                                                         pDataFile) != NULL)
     )
    {
      ParseCmdLine((char *)Line, 
                   (char *)DataType, 
                   &iDataTypeLen, 
                   (char *)Data, 
                   &iDataLen);
      if ((iDataTypeLen > 0) && (iDataLen > 0))
        {
          if (strncmp(DataType, 
                      "USERID", 
                      6) == 0)
            {
              memset(AccessCtrlStr, 
                     0, 
                     sizeof(AccessCtrlStr));
              strncpy(AccessCtrlStr, 
                      Data, 
                      sizeof(AccessCtrlStr));
            } 
          else
          if (strncmp(DataType, 
                      "DESTFILE", 
                      8) == 0)
            {
              memset(DestFileNameStr, 
                     0, 
                     sizeof(DestFileNameStr));
              strcpy(DestFileNameStr, 
                     Data);
            } 
          else
          if (strncmp(DataType, 
                      "PARFILEIN", 
                      8) == 0)
            {
              memset(ParamFileStr, 
                     0, 
                     sizeof(ParamFileStr));
              strcpy(ParamFileStr, 
                     Data);
            } 
          else
          if (strncmp(DataType, 
                      "PARFILEOUT", 
                      8) == 0)
            {
              memset(OutParamFileStr, 
                     0, 
                     sizeof(OutParamFileStr));
              strcpy(OutParamFileStr, 
                     Data);
            } 
          else
          if (strncmp(DataType, 
                      "NODENAME", 
                      8) == 0)
            {
              memset(NodeNameStr, 
                     0, 
                     sizeof(NodeNameStr));
              strncpy(NodeNameStr, 
                      Data, 
                      sizeof(NodeNameStr));
            } 
          else
          if (strncmp(DataType, 
                      "HOSTNAME", 
                      8) == 0)
            {
              memset(HostNameStr, 
                     0, 
                     sizeof(HostNameStr));
              strncpy(HostNameStr, 
                      Data, 
                      sizeof(HostNameStr));
            } 
          else
          if (strncmp(DataType, 
                      "PDTYPE", 
                      6) == 0)
            {
              GetProdTypeVal(Data, 
                             &pProdDescr->bProd);
            } 
          else
          if (strncmp(DataType, 
                      "PDTIME", 
                      6) == 0)
            {
              memset(pProdDescr->cTimeStr, 
                     0, 
                     sizeof(pProdDescr->cTimeStr));
              if (strstr(Data, 
                         "*") != NULL)
                BuildCurrTime(pProdDescr->cTimeStr);
              else
                strncpy(pProdDescr->cTimeStr, 
                        Data, 
                        sizeof(pProdDescr->cTimeStr));
            } 
          else
          if (strncmp(DataType, 
                      "PDRESOLUTION", 
                      12) == 0)
            {
              pProdDescr->iResolution = atoi(Data);
            } 
          else
          if (strncmp(DataType, 
                      "PDAREA", 
                      6) == 0)
            {
              memset(pProdDescr->cArea, 
                     0, 
                     sizeof(pProdDescr->cArea));
              strncpy(pProdDescr->cArea, 
                      Data, 
                      sizeof(pProdDescr->cArea));
            } 
          else
          if (strncmp(DataType, 
                      "PDCOMMENT", 
                      9) == 0)
            {
              memset(pProdDescr->uData.Foreign.cComment, 
                     0, 
                     sizeof(pProdDescr->uData.Foreign.cComment));
              strncpy(pProdDescr->uData.Foreign.cComment, 
                      Data, 
                      sizeof(pProdDescr->uData.Foreign.cComment));
            } 
          else
          if (strncmp(DataType, 
                      "PDGEOMAPTYPE", 
                      12) == 0)
            {
              pProdDescr->uData.GeoMap.bMapType = (unsigned char)atoi(Data);
            } 
          else
          if (strncmp(DataType, 
                      "PDGEOMAPGRAPHIC", 
                      15) == 0)
            {
              pProdDescr->uData.GeoMap.bMapGraphic = (unsigned char)atoi
                 (Data);
            } 
          else
          if (strncmp(DataType, 
                      "PDRRSTATUSNODE", 
                      15) == 0)
            {
              memset(pProdDescr->uData.RrStatus.cStatusNode, 
                     0, 
                     sizeof(pProdDescr->uData.RrStatus.cStatusNode));
              strncpy(pProdDescr->uData.RrStatus.cStatusNode, 
                      Data, 
                      sizeof(pProdDescr->uData.RrStatus.cStatusNode));
            } 
          else
          if (strncmp(DataType, 
                      "PDRRCAPPIHEIGHT", 
                      15) == 0)
            {
              pProdDescr->uData.RrType.uRr.RrCappi.iHeight = atoi(Data);
            } 
          else
          if (strncmp(DataType, 
                      "PDRRHMIWALL", 
                      11) == 0)
            {
              pProdDescr->uData.RrType.uRr.RrHmi.bHmiWall = (unsigned char)
                 atoi(Data);
            } 
          else
          if (strncmp(DataType, 
                      "PDRRVSIWALL", 
                      11) == 0)
            {
              pProdDescr->uData.RrType.uRr.RrVsi.bVsiWall = (unsigned char)
                 atoi(Data);
            } 
          else
          if (strncmp(DataType, 
                      "PDVSISTARTLAT", 
                      13) == 0)
            {
              strncpy(pProdDescr->uData.RrType.uRr.RrVsi.cStartLat, 
                      Data, 
                      sizeof(pProdDescr->uData.RrType.uRr.RrVsi.cStartLat));
            } 
          else
          if (strncmp(DataType, 
                      "PDVSISTARTLONG", 
                      14) == 0)
            {
              strncpy(pProdDescr->uData.RrType.uRr.RrVsi.cStartLong, 
                      Data, 
                      sizeof(pProdDescr->uData.RrType.uRr.RrVsi.cStartLong))
                 ;
            } 
          else
          if (strncmp(DataType, 
                      "PDVSIENDLAT", 
                      11) == 0)
            {
              strncpy(pProdDescr->uData.RrType.uRr.RrVsi.cEndLat, 
                      Data, 
                      sizeof(pProdDescr->uData.RrType.uRr.RrVsi.cEndLat));
            } 
          else
          if (strncmp(DataType, 
                      "PDVSIENDLONG", 
                      12) == 0)
            {
              strncpy(pProdDescr->uData.RrType.uRr.RrVsi.cEndLong, 
                      Data, 
                      sizeof(pProdDescr->uData.RrType.uRr.RrVsi.cEndLong));
            } 

          /******************************************************************/
          /* some left to implement                                         */
          /******************************************************************/

          else
          if (strncmp(DataType, 
                      "SOURCEFILE", 
                      10) == 0)
            {
              memset(SourceFileNameStr, 
                     0, 
                     sizeof(SourceFileNameStr));
              strncpy(SourceFileNameStr, 
                      Data, 
                      sizeof(SourceFileNameStr));
            } 
          else
          if (strncmp(DataType, 
                      "RECEIVERID", 
                      10) == 0)
            {
              memset(ReceiverIdStr, 
                     0, 
                     sizeof(ReceiverIdStr));
              strncpy(ReceiverIdStr, 
                      Data, 
                      sizeof(ReceiverIdStr));
            } 
          else
          if (strncmp(DataType, 
                      "PDRRMODE", 
                      8) == 0)
            {
              pProdDescr->uData.RrType.bRrMode = (unsigned char)atoi(Data);
            } 
          else
          if (strncmp(DataType, 
                      "SETTIMER", 
                      8) == 0)
            iWaitTime = atoi(Data);
          else
          if (strncmp(DataType, 
                      "CRIT", 
                      4) == 0)
            {
              SearchCrit.bName = 0;
              SearchCrit.bTime = 0;
              SearchCrit.bArea = 0;
              SearchCrit.bResolution = 0;
              pNxtValue = strtok(Data, 
                                 " ,");
              while (pNxtValue != NULL)
                {
                  GetCritVal(pNxtValue, 
                             &SearchCrit);
                  pNxtValue = strtok(NULL, 
                                     " ,");
                } 
            } 
          else
          if (strncmp(DataType, 
                      "LIM", 
                      3) == 0)
            strcpy(SearchLimFileStr, 
                   Data);
          else
          if (strncmp(DataType, 
                      "PACKALG", 
                      7) == 0)
            {
              if (strncmp(Data, 
                          "RLE", 
                          3) == 0)
                bPackAlg = 0;
              else
              if (strncmp(Data, 
                          "NONE", 
                          4) == 0)
                bPackAlg = 1;
              else
                bPackAlg = (unsigned char)atoi(Data);
            } 
          else
            {
              printf("Unknown data type %s", 
                     DataType);
              fclose(pDataFile);
              return  NOK;
            } 
        } 
      memset(Line, 
             0, 
             sizeof(Line));
    } 
  fclose(pDataFile);
  return  iRc;
} 


/*----------------------------------------------------------
*  ParseCmdLine - Command and Command data are identified
*                 and separated in different strings
*---------------------------------------------------------                  */

void ParseCmdLine(char *pLine,char *pDataType,int *piDataTypeLen,char 
                  *pData,INT32 *piDataLen)
{
  char *pNextToken;

  pNextToken = strtok(pLine, 
                      "=\r\f\n");
  if (pNextToken != NULL)
    {
      strcpy(pDataType, 
             pNextToken);
      *piDataTypeLen = strlen(pDataType);
      pNextToken = strtok(NULL, 
                          "=\r\f\n");
      if (pNextToken != NULL)
        {
          strcpy(pData, 
                 pNextToken);
          *piDataLen = strlen(pData);
        } 
      else
        *piDataLen = 0;
    } 
  else
    *piDataTypeLen = 0;
} 


/*----------------------------------------------------------
*  FetchProdDescr - Promt user to input data for a complete 
*                   new product description.
*---------------------------------------------------------                  */

void FetchProdDescr(struct ApiProdDescrStruc *pProdDescr)
{
  char TmpStr[80];
  char *pTmpStr;
  time_t lTime;
  char *pNxtValue;
  char CritStr[100];
  char ProdTypeStr[20];

  printf("Give product data:\n");
  printf("  Type/%s/:", 
         GetProdTypeStr(pProdDescr->bProd, 
                        ProdTypeStr));
  pTmpStr = gets(TmpStr);
  if (strlen(pTmpStr) > 0)
    GetProdTypeVal(pTmpStr, 
                   &pProdDescr->bProd);
  if (strlen(pProdDescr->cTimeStr) == 0)
    {
      time(&lTime);
      UtlNradTimeStr(lTime, 
                     pProdDescr->cTimeStr);
    } 
  printf("  Time/%s/ *=Current time:", 
         pProdDescr->cTimeStr);
  pTmpStr = gets(TmpStr);
  if (strlen(pTmpStr) > 0)
    if (strstr(TmpStr, 
               "*") != NULL)
      BuildCurrTime(pProdDescr->cTimeStr);
    else
      strncpy(pProdDescr->cTimeStr, 
              pTmpStr, 
              sizeof(pProdDescr->cTimeStr));
  printf("  Resolution/%d/:", 
         pProdDescr->iResolution);
  pTmpStr = gets(TmpStr);
  if (strlen(pTmpStr) > 0)
    pProdDescr->iResolution = atoi(pTmpStr);
  printf("  Area/%s/:", 
         pProdDescr->cArea);
  pTmpStr = gets(TmpStr);
  if (strlen(pTmpStr) > 0)
    strcpy(pProdDescr->cArea, 
           pTmpStr);
  switch (pProdDescr->bProd)
    {
      case  PROD_FOREIGN :
        printf("  Comment/%s/:", 
               pProdDescr->uData.Foreign.cComment);
        pTmpStr = gets(TmpStr);
        if (strlen(pTmpStr) > 0)
          strcpy(pProdDescr->uData.Foreign.cComment, 
                 pTmpStr);
        break;
      case  PROD_GEOMAP :
        printf("  MapType/%d/:", 
               pProdDescr->uData.GeoMap.bMapType);
        pTmpStr = gets(TmpStr);
        if (strlen(pTmpStr) > 0)
          pProdDescr->uData.GeoMap.bMapType = (unsigned char)atoi(pTmpStr);
        printf("  MapGraphic/%d/:", 
               pProdDescr->uData.GeoMap.bMapGraphic);
        pTmpStr = gets(TmpStr);
        if (strlen(pTmpStr) > 0)
          pProdDescr->uData.GeoMap.bMapGraphic = (unsigned char)atoi(pTmpStr
             );
        break;
      case  PROD_RRSTATUS :
        printf("  Status node/%s/:", 
               pProdDescr->uData.RrStatus.cStatusNode);
        pTmpStr = gets(TmpStr);
        if (strlen(pTmpStr) > 0)
          strcpy(pProdDescr->uData.RrStatus.cStatusNode, 
                 pTmpStr);
        break;
      case  PROD_RRPPI_Z :
      case  PROD_RRPPI_W :
      case  PROD_RRPPI_T :
        break;
      case  PROD_RRCAPPI_Z :
      case  PROD_RRCAPPI_W :
      case  PROD_RRCAPPI_T :
        printf("  Height/%d/:", 
               pProdDescr->uData.RrType.uRr.RrCappi.iHeight);
        pTmpStr = gets(TmpStr);
        if (strlen(pTmpStr) > 0)
          pProdDescr->uData.RrType.uRr.RrCappi.iHeight = atoi(pTmpStr);
        break;
      case  PROD_RRPSC_Z :
      case  PROD_RRPSC_W :
      case  PROD_RRPSC_T :
      case  PROD_RRETM_Z :
      case  PROD_RRVMI_Z :
      case  PROD_RRVMI_W :
      case  PROD_RRVMI_T :
        break;
      case  PROD_RRHMI_Z :
      case  PROD_RRHMI_W :
      case  PROD_RRHMI_T :
        printf("  HmiWall(South=0,North=1,East=2,West=3)/%d/:", 
               pProdDescr->uData.RrType.uRr.RrHmi.bHmiWall);
        pTmpStr = gets(TmpStr);
        if (strlen(pTmpStr) > 0)
          pProdDescr->uData.RrType.uRr.RrHmi.bHmiWall = (unsigned char)atoi
             (pTmpStr);
        break;
      case  PROD_RRHMAX_Z :
      case  PROD_RRHMAX_W :
      case  PROD_RRHMAX_T :
        break;
      case  PROD_RRVSI_Z :
      case  PROD_RRVSI_W :
      case  PROD_RRVSI_T :
        printf("  VsiWall(South=0,North=1,East=2,West=3)/%d/:", 
               pProdDescr->uData.RrType.uRr.RrVsi.bVsiWall);
        pTmpStr = gets(TmpStr);
        if (strlen(pTmpStr) > 0)
          pProdDescr->uData.RrType.uRr.RrVsi.bVsiWall = (unsigned char)atoi
             (pTmpStr);
        printf("  Start lat/%s/:", 
               pProdDescr->uData.RrType.uRr.RrVsi.cStartLat);
        pTmpStr = gets(TmpStr);
        if (strlen(pTmpStr) > 0)
          strcpy(pProdDescr->uData.RrType.uRr.RrVsi.cStartLat, 
                 pTmpStr);
        printf("  Start long/%s/:", 
               pProdDescr->uData.RrType.uRr.RrVsi.cStartLong);
        pTmpStr = gets(TmpStr);
        if (strlen(pTmpStr) > 0)
          strcpy(pProdDescr->uData.RrType.uRr.RrVsi.cStartLong, 
                 pTmpStr);
        printf("  End lat/%s/:", 
               pProdDescr->uData.RrType.uRr.RrVsi.cEndLat);
        pTmpStr = gets(TmpStr);
        if (strlen(pTmpStr) > 0)
          strcpy(pProdDescr->uData.RrType.uRr.RrVsi.cEndLat, 
                 pTmpStr);
        printf("  End long/%s/:", 
               pProdDescr->uData.RrType.uRr.RrVsi.cEndLong);
        pTmpStr = gets(TmpStr);
        if (strlen(pTmpStr) > 0)
          strcpy(pProdDescr->uData.RrType.uRr.RrVsi.cEndLong, 
                 pTmpStr);
        printf("  Vsi name/%s/:", 
               pProdDescr->uData.RrType.uRr.RrVsi.cVsiName);
        pTmpStr = gets(TmpStr);
        if (strlen(pTmpStr) > 0)
          strcpy(pProdDescr->uData.RrType.uRr.RrVsi.cVsiName, 
                 pTmpStr);
        break;
      case  PROD_RRSRT_Z :
        printf("  Period.Days/%d/:", 
               pProdDescr->uData.RrType.uRr.Duration.iDays);
        pTmpStr = gets(TmpStr);
        if (strlen(pTmpStr) > 0)
          pProdDescr->uData.RrType.uRr.Duration.iDays = atoi(pTmpStr);
        printf("  Period.Secs/%d/:", 
               pProdDescr->uData.RrType.uRr.Duration.iSecs);
        pTmpStr = gets(TmpStr);
        if (strlen(pTmpStr) > 0)
          pProdDescr->uData.RrType.uRr.Duration.iSecs = atoi(pTmpStr);
        break;
      default  :
        return ;
    } 
  if ((pProdDescr->bProd >= PROD_RRPPI_Z) && (pProdDescr->bProd <= 
     PROD_RRSRI_Z))
    {
      printf("  RrMode 1=Doppler 2=NonDop/%d/:", 
             pProdDescr->uData.RrType.bRrMode);
      pTmpStr = gets(TmpStr);
      if (strlen(pTmpStr) > 0)
        pProdDescr->uData.RrType.bRrMode = (unsigned char)atoi(pTmpStr);
    } 
  printf("  Search criteria /%s/:", 
         GetCritValStr(&SearchCrit, 
                       CritStr));
  pTmpStr = gets(TmpStr);
  if (strlen(pTmpStr) > 0)
    {
      pNxtValue = strtok(pTmpStr, 
                         " ,");
      while (pNxtValue != NULL)
        {
          GetCritVal(pNxtValue, 
                     &SearchCrit);
          pNxtValue = strtok(NULL, 
                             " ,");
        } 
    } 
} 


/*----------------------------------------------------------
*  HelpAction - Display help text containing all commands
*               with short descriptions.
*---------------------------------------------------------                  */

void HelpAction()
{
  printf("\n\nCommands:\n");
  printf("ModifyDefault   (Mdef) - Set parameter data\n");
  printf("StoreProduct    (StP)  - Store product \n");
  printf("GetProduct      (Gp)   - Get product \n");
  printf("SearchProduct   (SeaP) - Search products \n");
  printf("SubscribeAvi    (SubA) - Subscribe on Avi in Nordrad 'mailbox'\n");
  printf("ReceiveAvi      (RA)   - Receive product Avi from Nordrad 'mailbox'\n");
  printf("CancelAvi       (CA)   - End subscription on Avi in Nordrad \n");
  printf("Pack            (P)    - Pack a Nordrad product \n");
  printf("PackE           (PE)   - Pack an EWIS product \n");
  printf("UnPack          (UP)   - Expand (unpack) a Nordrad product \n");
  printf("UnPackE         (UPE)  - Expand (unpack) an EWIS product \n");
  printf("Import          (IM)   - Import from BUFR format \n");
  printf("Export          (EX)   - Export from NORDRAD to BUFR format \n");
  printf("Convert         (CONV) - Convert to SRI product type \n");
  printf("Reset           (RES)  - Set all parameters to initial values \n");
  printf("ShowData        (SD)   - Show all defined data \n");
  printf("GetSearchAvi    (GSA)  - Fetch received Avi's from SeaP command\n");
  printf("SetSubscrHandle (SUBH) - Set Subscribe handle \n");
  printf("FilDefault      (Fdef) - Set data from file\n");
  printf("Run             (RUN)  - Run command file script \n");
  printf("ContinueScript  (CS)   - Continue interrupted script \n");
  printf("Help            (H)    - This printout\n");
  printf("Quit            (Q)    - End program\n\n");
} 


/*----------------------------------------------------------
*  ShowData  - Display global API data values currently in
*              use to screen and to logfile if activated. 
*---------------------------------------------------------                  */

void ShowData(INT32 iType,struct ApiProdDescrStruc *pShowProdDescr)
{
  char CritStr[100];

  if (iType == SHOW_ALL)
    {
      sprintf(OutLine, 
              "     Host name=%s\n", 
              HostNameStr);
      StrOutput(OutLine);
      sprintf(OutLine, 
              "     AccessControl=%s\n", 
              AccessCtrlStr);
      StrOutput(OutLine);
      sprintf(OutLine, 
              "     Source file=%s\n", 
              SourceFileNameStr);
      StrOutput(OutLine);
      sprintf(OutLine, 
              "     Dest file=%s\n", 
              DestFileNameStr);
      StrOutput(OutLine);
      sprintf(OutLine, 
              "     Inparameter file=%s\n", 
              ParamFileStr);
      StrOutput(OutLine);
      sprintf(OutLine, 
              "     Outparameter file=%s\n", 
              OutParamFileStr);
      StrOutput(OutLine);
      sprintf(OutLine, 
              "     Pack alg (0=RLE 1=None) =%d\n", 
              bPackAlg);
      StrOutput(OutLine);

      sprintf(OutLine, 
              "     BUFR Mode (0=4 bit 1=8 bit) =%d\n", 
              BufrMode);
      StrOutput(OutLine);

      sprintf(OutLine, 
              "     Search Result file=%s\n", 
              SearchDataFileStr);
      StrOutput(OutLine);


      sprintf(OutLine, 
              "     Node name=%s\n", 
              NodeNameStr);
      StrOutput(OutLine);
      sprintf(OutLine, 
              "     Search limit file=%s\n", 
              SearchLimFileStr);
      StrOutput(OutLine);
      sprintf(OutLine, 
              "     Receiver ID=%s\n", 
              ReceiverIdStr);
      StrOutput(OutLine);
      sprintf(OutLine, 
              "     Wait time=%d\n", 
              iWaitTime);
      StrOutput(OutLine);
      sprintf(OutLine, 
              "     Search criteria=%s\n", 
              GetCritValStr(&SearchCrit, 
                            CritStr));
      StrOutput(OutLine);
      sprintf(OutLine, 
              "     Subscribe handle=%d\n", 
              iSubscrSock);
      StrOutput(OutLine);
    } 
  ShowPd(pShowProdDescr);
} 


/*----------------------------------------------------------
*  ShowPd  - Display specified ApiProduct data 
*              
*---------------------------------------------------------                  */

void ShowPd(struct ApiProdDescrStruc *pShowProdDescr)
{
  char ProdTypeStr[30];

  /**************************************************************************/
  /* ProdDescr                                                              */
  /**************************************************************************/

  sprintf(OutLine, 
          "     Type=%s\n", 
          GetProdTypeStr(pShowProdDescr->bProd, 
                         ProdTypeStr));
  StrOutput(OutLine);
  sprintf(OutLine, 
          "     Time=%s\n", 
          pShowProdDescr->cTimeStr);
  StrOutput(OutLine);
  sprintf(OutLine, 
          "     Resolution=%d\n", 
          pShowProdDescr->iResolution);
  StrOutput(OutLine);
  sprintf(OutLine, 
          "     Area=%s\n", 
          pShowProdDescr->cArea);
  StrOutput(OutLine);
  switch (pShowProdDescr->bProd)
    {
      case  PROD_FOREIGN :
        sprintf(OutLine, 
                "     Comment=%s\n", 
                pShowProdDescr->uData.Foreign.cComment);
        StrOutput(OutLine);
        break;
      case  PROD_GEOMAP :
        sprintf(OutLine, 
                "     MapType=%d\n", 
                pShowProdDescr->uData.GeoMap.bMapType);
        StrOutput(OutLine);
        sprintf(OutLine, 
                "     MapGraphic=%d\n", 
                pShowProdDescr->uData.GeoMap.bMapGraphic);
        StrOutput(OutLine);
        break;
      case  PROD_RRSTATUS :
        sprintf(OutLine, 
                "     Status node=%s\n", 
                pShowProdDescr->uData.RrStatus.cStatusNode);
        StrOutput(OutLine);
        break;
      case  PROD_RRPPI_Z :
      case  PROD_RRPPI_W :
      case  PROD_RRPPI_T :
        break;
      case  PROD_RRCAPPI_Z :
      case  PROD_RRCAPPI_W :
      case  PROD_RRCAPPI_T :
        sprintf(OutLine, 
                "     Height=%d\n", 
                pShowProdDescr->uData.RrType.uRr.RrCappi.iHeight);
        StrOutput(OutLine);
        break;
      case  PROD_RRPSC_Z :
      case  PROD_RRPSC_W :
      case  PROD_RRPSC_T :
      case  PROD_RRETM_Z :
      case  PROD_RRVMI_Z :
      case  PROD_RRVMI_W :
      case  PROD_RRVMI_T :
        break;
      case  PROD_RRHMI_Z :
      case  PROD_RRHMI_W :
      case  PROD_RRHMI_T :
        sprintf(OutLine, 
                "     HmiWall(South=0,North=1,East=2,West=3)=%d\n", 
                pShowProdDescr->uData.RrType.uRr.RrHmi.bHmiWall);
        StrOutput(OutLine);
        break;
      case  PROD_RRHMAX_Z :
      case  PROD_RRHMAX_W :
      case  PROD_RRHMAX_T :
        break;
      case  PROD_RRVSI_Z :
      case  PROD_RRVSI_W :
      case  PROD_RRVSI_T :
        sprintf(OutLine, 
                "     VsiWall(South=0,North=1,East=2,West=3)=%d\n", 
                pShowProdDescr->uData.RrType.uRr.RrVsi.bVsiWall);
        StrOutput(OutLine);
        sprintf(OutLine, 
                "     Start lat=%s\n", 
                pShowProdDescr->uData.RrType.uRr.RrVsi.cStartLat);
        StrOutput(OutLine);
        sprintf(OutLine, 
                "     Start long=%s\n", 
                pShowProdDescr->uData.RrType.uRr.RrVsi.cStartLong);
        StrOutput(OutLine);
        sprintf(OutLine, 
                "     End lat=%s\n", 
                pShowProdDescr->uData.RrType.uRr.RrVsi.cEndLat);
        StrOutput(OutLine);
        sprintf(OutLine, 
                "     End long=%s\n", 
                pShowProdDescr->uData.RrType.uRr.RrVsi.cEndLong);
        StrOutput(OutLine);
        sprintf(OutLine, 
                "     Vsi name=%s\n", 
                pShowProdDescr->uData.RrType.uRr.RrVsi.cVsiName);
        StrOutput(OutLine);
        break;
      case  PROD_RRSRT_Z :
        sprintf(OutLine, 
                "     Period.Days=%d\n", 
                pShowProdDescr->uData.RrType.uRr.Duration.iDays);
        StrOutput(OutLine);
        sprintf(OutLine, 
                "     Period.Secs=%d\n", 
                pShowProdDescr->uData.RrType.uRr.Duration.iSecs);
        StrOutput(OutLine);
        break;
    } 
  if ((pShowProdDescr->bProd >= PROD_RRPPI_Z) && (pShowProdDescr->bProd <= 
     PROD_RRSRT_Z))
    {
      sprintf(OutLine, 
              "     RrMode=%d\n", 
              pShowProdDescr->uData.RrType.bRrMode);
      StrOutput(OutLine);
    } 
} 


/*----------------------------------------------------------
*  StrOutput  - Direct outdata to the proper output medias
*---------------------------------------------------------                  */

void StrOutput(char *pOutStr)
{
  printf(pOutStr);
  if (iLogFile == TRUE)
    {
      fwrite(pOutStr, 
             sizeof(char), 
             strlen(pOutStr)+1, 
             fLogFile);
      fwrite("\n", 
             sizeof(char), 
             1, 
             fLogFile);
    } 
} 


/*----------------------------------------------------------
*  GetSearchAvi  - Fetch product descriptions stored sequently
*                  in a file, for instance a result file from
*                  a SearchProduct or Receive.
*---------------------------------------------------------                  */

void GetSearchAvi()
{
  INT32 iContinue = TRUE;
  char TmpStr[50];
  char *pTmpStr;
  struct ApiProdDescrStruc *pTmpProdDescr;
  FILE *pDataFile;
  struct ApiAviStruc TmpApiAvi;
  char OutLine[100];
  int iBytesRead,iAviSize;

  printf("Searchdata file /%s/:", 
         SearchDataFileStr);
  pTmpStr = gets(TmpStr);
  if (strlen(pTmpStr) > 0)
    strcpy(SearchDataFileStr, 
           pTmpStr);
  pDataFile = fopen(SearchDataFileStr, 
                    "r");
  if (pDataFile == NULL)
    {
      printf("File open error\n");
      return ;
    } 
  pTmpProdDescr = &TmpApiAvi.ApiProdDescr;
  while ((iContinue == TRUE) && (feof(pDataFile) == 0))
    {
      iAviSize = sizeof(TmpApiAvi);
      if ((iBytesRead = fread(&TmpApiAvi, 
                              1, 
                              iAviSize, 
                              pDataFile)) == iAviSize)
        {
          sprintf(OutLine, 
                  "     NodeName=%s\n", 
                  TmpApiAvi.cNodeName);
          StrOutput(OutLine);
          ShowData(SHOW_PD, 
                   pTmpProdDescr);
          printf("Use/Next/Quit  (U/N/Q)    /N/:");
          pTmpStr = gets(TmpStr);
          if ((pTmpStr[0] == 'U') || (pTmpStr[0] == 'u'))
            {
              memcpy(NodeNameStr, 
                     TmpApiAvi.cNodeName, 
                     sizeof(NodeNameStr));
              memcpy(&ApiProdDescr, 
                     pTmpProdDescr, 
                     sizeof(ApiProdDescr));
              fclose(pDataFile);
              return ;
            } 
          if ((pTmpStr[0] == 'Q') || (pTmpStr[0] == 'q'))
            iContinue = FALSE;
        } 
      else
        iContinue = FALSE;
    } 
  fclose(pDataFile);
} 


/*----------------------------------------------------------
*  GetCritVal  - Convert Search criteria values from text to
*                numerical values to send in search request.
*---------------------------------------------------------                  */

INT32 GetCritVal(char *pNxtValue,struct SearchCritStruc *pSearchCrit)
{
  INT32 iRc = OK;

  UtlStrToUpper(pNxtValue, 
                strlen(pNxtValue));
  if (strncmp(pNxtValue, 
              "NAMEEXACT", 
              9) == 0)
    pSearchCrit->bName = 4;
  else
  if (strncmp(pNxtValue, 
              "NAMESTRONG", 
              10) == 0)
    pSearchCrit->bName = 3;
  else
  if (strncmp(pNxtValue, 
              "NAMEMEDIUM", 
              10) == 0)
    pSearchCrit->bName = 2;
  else
  if (strncmp(pNxtValue, 
              "NAMEWEAK", 
              8) == 0)
    pSearchCrit->bName = 1;
  else
  if (strncmp(pNxtValue, 
              "NAMENONE", 
              8) == 0)
    pSearchCrit->bName = 0;
  else
  if (strncmp(pNxtValue, 
              "NAMEILLEG", 
              9) == 0)
    pSearchCrit->bName = 8;            /* error value                       */
  else
  if (strncmp(pNxtValue, 
              "TIMEEXACT", 
              9) == 0)
    pSearchCrit->bTime = 4;
  else
  if (strncmp(pNxtValue, 
              "TIMESTRONG", 
              10) == 0)
    pSearchCrit->bTime = 3;
  else
  if (strncmp(pNxtValue, 
              "TIMEEDIUM", 
              10) == 0)
    pSearchCrit->bTime = 2;
  else
  if (strncmp(pNxtValue, 
              "TIMEWEAK", 
              8) == 0)
    pSearchCrit->bTime = 1;
  else
  if (strncmp(pNxtValue, 
              "TIMENONE", 
              8) == 0)
    pSearchCrit->bTime = 0;
  else
  if (strncmp(pNxtValue, 
              "TIMEILLEG", 
              9) == 0)
    pSearchCrit->bTime = 8;            /* error value                       */
  else
  if (strncmp(pNxtValue, 
              "AREAEXACT", 
              9) == 0)
    pSearchCrit->bArea = 4;
  else
  if (strncmp(pNxtValue, 
              "AREASTRONG", 
              10) == 0)
    pSearchCrit->bArea = 3;
  else
  if (strncmp(pNxtValue, 
              "AREAMEDIUM", 
              10) == 0)
    pSearchCrit->bArea = 2;
  else
  if (strncmp(pNxtValue, 
              "AREAWEAK", 
              8) == 0)
    pSearchCrit->bArea = 1;
  else
  if (strncmp(pNxtValue, 
              "AREANONE", 
              8) == 0)
    pSearchCrit->bArea = 0;
  else
  if (strncmp(pNxtValue, 
              "AREAILLEG", 
              9) == 0)
    pSearchCrit->bArea = 8;
  else
  if (strncmp(pNxtValue, 
              "RESOLUTIONEXACT", 
              15) == 0)
    pSearchCrit->bResolution = 4;
  else
  if (strncmp(pNxtValue, 
              "RESOLUTIONSTRONG", 
              16) == 0)
    pSearchCrit->bResolution = 3;
  else
  if (strncmp(pNxtValue, 
              "RESOLUTIONMEDIUM", 
              16) == 0)
    pSearchCrit->bResolution = 2;
  else
  if (strncmp(pNxtValue, 
              "RESOLUTIONWEAK", 
              14) == 0)
    pSearchCrit->bResolution = 1;
  else
  if (strncmp(pNxtValue, 
              "RESOLUTIONNONE", 
              14) == 0)
    pSearchCrit->bResolution = 0;
  else
  if (strncmp(pNxtValue, 
              "RESOLUTIONILLEG", 
              15) == 0)
    pSearchCrit->bResolution = 8;
  else
    iRc = NOK;
  return  iRc;
} 


/*----------------------------------------------------------
*  GetCritValStr  - Convert Search criteria values from integers 
*                   to string values to present for user.
*---------------------------------------------------------                  */

char *GetCritValStr(struct SearchCritStruc *pSearchCrit,char *pCritStr)
{
  if (pSearchCrit->bName == 4)
    strcpy(pCritStr, 
           "NAMEEXACT");
  else
  if (pSearchCrit->bName == 3)
    strcpy(pCritStr, 
           "NAMESTRONG");
  else
  if (pSearchCrit->bName == 2)
    strcpy(pCritStr, 
           "NAMEMEDIUM");
  else
  if (pSearchCrit->bName == 1)
    strcpy(pCritStr, 
           "NAMEWEAK");
  else
  if (pSearchCrit->bName == 0)
    strcpy(pCritStr, 
           "NAMENONE");
  else
    strcpy(pCritStr, 
           "NAMEILLEG");
  if (pSearchCrit->bTime == 4)
    strcat(pCritStr, 
           ",TIMEEXACT");
  else
  if (pSearchCrit->bTime == 3)
    strcat(pCritStr, 
           ",TIMESTRONG");
  else
  if (pSearchCrit->bTime == 2)
    strcat(pCritStr, 
           ",TIMEEDIUM");
  else
  if (pSearchCrit->bTime == 1)
    strcat(pCritStr, 
           ",TIMEWEAK");
  else
  if (pSearchCrit->bTime == 0)
    strcat(pCritStr, 
           ",TIMENONE");
  else
    strcat(pCritStr, 
           ",TIMEILLEG");
  if (pSearchCrit->bArea == 4)
    strcat(pCritStr, 
           ",AREAEXACT");
  else
  if (pSearchCrit->bArea == 3)
    strcat(pCritStr, 
           ",AREASTRONG");
  else
  if (pSearchCrit->bArea == 2)
    strcat(pCritStr, 
           ",AREAMEDIUM");
  else
  if (pSearchCrit->bArea == 1)
    strcat(pCritStr, 
           ",AREAWEAK");
  else
  if (pSearchCrit->bArea == 0)
    strcat(pCritStr, 
           ",AREANONE");
  else
    strcat(pCritStr, 
           ",AREAILLEG");
  if (pSearchCrit->bResolution == 4)
    strcat(pCritStr, 
           ",RESOLUTIONEXACT");
  else
  if (pSearchCrit->bResolution == 3)
    strcat(pCritStr, 
           ",RESOLUTIONSTRONG");
  else
  if (pSearchCrit->bResolution == 2)
    strcat(pCritStr, 
           ",RESOLUTIONMEDIUM");
  else
  if (pSearchCrit->bResolution == 1)
    strcat(pCritStr, 
           ",RESOLUTIONWEAK");
  else
  if (pSearchCrit->bResolution == 0)
    strcat(pCritStr, 
           ",RESOLUTIONNONE");
  else
    strcat(pCritStr, 
           ",RESOLUTIONILLEG");
  return  pCritStr;
} 


/*----------------------------------------------------------
*  GetProdTypeStr - Convert Product type values from integers
*                   to string values to present for user.
*---------------------------------------------------------                  */

char *GetProdTypeStr(unsigned char bVal,char *pProdTypeStr)
{
  switch (bVal)
    {
      case  PROD_NONE :
        strcpy(pProdTypeStr, 
               "NONE");
        break;
      case  PROD_FOREIGN :
        strcpy(pProdTypeStr, 
               "FOREIGN");
        break;
      case  PROD_GEOMAP :
        strcpy(pProdTypeStr, 
               "GEOMAP");
        break;
      case  PROD_RRSTATUS :
        strcpy(pProdTypeStr, 
               "RRSTATUS");
        break;
      case  PROD_RRPPI_Z :
        strcpy(pProdTypeStr, 
               "RRPPI_Z");
        break;
      case  PROD_RRPPI_W :
        strcpy(pProdTypeStr, 
               "RRPPI_W");
        break;
      case  PROD_RRPPI_T :
        strcpy(pProdTypeStr, 
               "RRPPI_T");
        break;
      case  PROD_RRCAPPI_Z :
        strcpy(pProdTypeStr, 
               "RRCAPPI_Z");
        break;
      case  PROD_RRCAPPI_W :
        strcpy(pProdTypeStr, 
               "RRCAPPI_W");
        break;
      case  PROD_RRCAPPI_T :
        strcpy(pProdTypeStr, 
               "RRCAPPI_T");
        break;
      case  PROD_RRPSC_Z :
        strcpy(pProdTypeStr, 
               "RRPSC_Z");
        break;
      case  PROD_RRPSC_W :
        strcpy(pProdTypeStr, 
               "RRPSC_W");
        break;
      case  PROD_RRPSC_T :
        strcpy(pProdTypeStr, 
               "RRPSC_T");
        break;
      case  PROD_RRETM_Z :
        strcpy(pProdTypeStr, 
               "RRETM_Z");
        break;
      case  PROD_RRVMI_Z :
        strcpy(pProdTypeStr, 
               "RRVMI_Z");
        break;
      case  PROD_RRVMI_W :
        strcpy(pProdTypeStr, 
               "RRVMI_W");
        break;
      case  PROD_RRVMI_T :
        strcpy(pProdTypeStr, 
               "RRVMI_T");
        break;
      case  PROD_RRHMI_Z :
        strcpy(pProdTypeStr, 
               "RRHMI_Z");
        break;
      case  PROD_RRHMI_W :
        strcpy(pProdTypeStr, 
               "RRHMI_W");
        break;
      case  PROD_RRHMI_T :
        strcpy(pProdTypeStr, 
               "RRHMI_T");
        break;
      case  PROD_RRHMAX_Z :
        strcpy(pProdTypeStr, 
               "RRHMAX_Z");
        break;
      case  PROD_RRHMAX_W :
        strcpy(pProdTypeStr, 
               "RRHMAX_W");
        break;
      case  PROD_RRHMAX_T :
        strcpy(pProdTypeStr, 
               "RRHMAX_T");
        break;
      case  PROD_RRVSI_Z :
        strcpy(pProdTypeStr, 
               "RRVSI_Z");
        break;
      case  PROD_RRVSI_W :
        strcpy(pProdTypeStr, 
               "RRVSI_W");
        break;
      case  PROD_RRVSI_T :
        strcpy(pProdTypeStr, 
               "RRVSI_T");
        break;
      case  PROD_RRSRT_Z :
        strcpy(pProdTypeStr, 
               "RRSRT_Z");
        break;
      default  :
        sprintf(pProdTypeStr, 
                "%d", 
                bVal);
        break;
    } 
  return  pProdTypeStr;
} 


/*----------------------------------------------------------
*  GetProdTypeVal - Convert Product type strings to integer
*                   values to store in product description.
*---------------------------------------------------------                  */

unsigned char GetProdTypeVal(char *pProdTypeStr,unsigned char *pbVal)
{
  UtlStrToUpper(pProdTypeStr, 
                strlen(pProdTypeStr));
  if (strncmp(pProdTypeStr, 
              "FOREIGN", 
              7) == 0)
    *pbVal = PROD_FOREIGN;
  else
  if (strncmp(pProdTypeStr, 
              "GEOMAP", 
              6) == 0)
    *pbVal = PROD_GEOMAP;
  else
  if (strncmp(pProdTypeStr, 
              "RRSTATUS", 
              8) == 0)
    *pbVal = PROD_RRSTATUS;
  else
  if (strncmp(pProdTypeStr, 
              "RRPPI_Z", 
              7) == 0)
    *pbVal = PROD_RRPPI_Z;
  else
  if (strncmp(pProdTypeStr, 
              "RRPPI_W", 
              7) == 0)
    *pbVal = PROD_RRPPI_W;
  else
  if (strncmp(pProdTypeStr, 
              "RRPPI_T", 
              7) == 0)
    *pbVal = PROD_RRPPI_T;
  else
  if (strncmp(pProdTypeStr, 
              "RRCAPPI_Z", 
              9) == 0)
    *pbVal = PROD_RRCAPPI_Z;
  else
  if (strncmp(pProdTypeStr, 
              "RRCAPPI_W", 
              9) == 0)
    *pbVal = PROD_RRCAPPI_W;
  else
  if (strncmp(pProdTypeStr, 
              "RRCAPPI_T", 
              9) == 0)
    *pbVal = PROD_RRCAPPI_T;
  else
  if (strncmp(pProdTypeStr, 
              "RRPSC_Z", 
              7) == 0)
    *pbVal = PROD_RRPSC_Z;
  else
  if (strncmp(pProdTypeStr, 
              "RRPSC_W", 
              7) == 0)
    *pbVal = PROD_RRPSC_W;
  else
  if (strncmp(pProdTypeStr, 
              "RRPSC_T", 
              7) == 0)
    *pbVal = PROD_RRPSC_T;
  else
  if (strncmp(pProdTypeStr, 
              "RRETM_Z", 
              7) == 0)
    *pbVal = PROD_RRETM_Z;
  else
  if (strncmp(pProdTypeStr, 
              "RRVMI_Z", 
              7) == 0)
    *pbVal = PROD_RRVMI_Z;
  else
  if (strncmp(pProdTypeStr, 
              "RRVMI_W", 
              7) == 0)
    *pbVal = PROD_RRVMI_W;
  else
  if (strncmp(pProdTypeStr, 
              "RRVMI_T", 
              7) == 0)
    *pbVal = PROD_RRVMI_T;
  else
  if (strncmp(pProdTypeStr, 
              "RRHMI_Z", 
              7) == 0)
    *pbVal = PROD_RRHMI_Z;
  else
  if (strncmp(pProdTypeStr, 
              "RRHMI_W", 
              7) == 0)
    *pbVal = PROD_RRHMI_W;
  else
  if (strncmp(pProdTypeStr, 
              "RRHMI_T", 
              7) == 0)
    *pbVal = PROD_RRHMI_T;
  else
  if (strncmp(pProdTypeStr, 
              "RRHMAX_Z", 
              8) == 0)
    *pbVal = PROD_RRHMAX_Z;
  else
  if (strncmp(pProdTypeStr, 
              "RRHMAX_W", 
              8) == 0)
    *pbVal = PROD_RRHMAX_W;
  else
  if (strncmp(pProdTypeStr, 
              "RRHMAX_T", 
              8) == 0)
    *pbVal = PROD_RRHMAX_T;
  else
  if (strncmp(pProdTypeStr, 
              "RRVSI_Z", 
              7) == 0)
    *pbVal = PROD_RRVSI_Z;
  else
  if (strncmp(pProdTypeStr, 
              "RRVSI_W", 
              8) == 0)
    *pbVal = PROD_RRVSI_W;
  else
  if (strncmp(pProdTypeStr, 
              "RRVSI_T", 
              8) == 0)
    *pbVal = PROD_RRVSI_T;
  else
  if (strncmp(pProdTypeStr, 
              "RRSRT_Z", 
              8) == 0)
    *pbVal = PROD_RRSRT_Z;
  else
  if (strncmp(pProdTypeStr, 
              "RRSRI_Z", 
              8) == 0)
    *pbVal = PROD_RRSRI_Z;
  else
    *pbVal = (unsigned char)atoi(pProdTypeStr);
  return  *pbVal;
} 

void BuildCurrTime(char *pTimeStr)
{
  time_t lTimeInSec;
  struct tm *pTimeParts;
  INT16 iCentury,iMonth;

  time(&lTimeInSec);
  pTimeParts = localtime(&lTimeInSec);
  if (pTimeParts->tm_year < 70)
    iCentury = 2000+pTimeParts->tm_year;
  else
    iCentury = 1900+pTimeParts->tm_year;
  iMonth = pTimeParts->tm_mon+1;
  sprintf(pTimeStr, 
          "%04d-%02d-%02d %02d:%02d:%02d.00", 
          iCentury, 
          iMonth, 
          pTimeParts->tm_mday, 
          pTimeParts->tm_hour, 
          pTimeParts->tm_min, 
          pTimeParts->tm_sec);
} 

