static char szModuleName__[] = "c:/nordrad/unix/import.c";
static char szLastVersion[] = "Version 0.16";
static char szLastSave[] = "1997-02-10*22:37";

/************************************************************
Abstract
Import.c - Nordrad API primitive to convert external radar
           format to Nordrad format.

(C) Copyright AU-System Communication AB 1994.

Change activity
990125		ARG, Modified entry names to avoid collision w. filep
1997-12-09      ARg  Adding parameters MIRROR and HEIGHT01-HEIGHT12
1997-10-22      ARg  Error when creating proddescr corrected
1997-08-89      ARg  Handle missing BUFR parameters by reading from
		     parameterfile
1997-02-09      ARg  Modified for 8 bit BUFR
1994-04-07 1.00 BBN  Initial version by Bj”rn Brodin.

Part of  Nordrad.

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

#ifdef   VMS
#include <types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stat.h>
#else
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <malloc.h>
#endif
#include <math.h>
#include <netdb.h>
#include "netdef.h"
#include "api.h"
#include "net.h"
#include "utl.h"
#include "fil.h"
#include "shft.h"
#include "rr_fil.h"

/*----------------------------------------------------------
*       D E F I N E S 
*---------------------------------------------------------                  */
#define MAX_PARA_FILE_SIZE 4200    /* Max NoOfBytes of parameter file...*/


/*----------------------------------------------------------
*       Functions
*---------------------------------------------------------                  */

INT32 GetParFileValue(char *pParFileStr,char *pIdentifier,INT32 iType,INT32 
                      *piValue,float *pfValue);

INT32 GetLevelsFromParFile(char *pParameterFileStr, 
			   Levels_t *pLevelAttr,
			   INT32 Cnt);

INT32 ImportFromBufr(char *pBufferFileStr,char *pInParamFileStr,char 
          *pOutParamFileStr,char *pDestFileStr,unsigned char
                     PackAlg,struct ApiProdDescrStruc *pApiProdDescr);

INT32 ConvToNradFrmt(BUF *pAttrInfo,DAT *pDate,char *pParameterFileStr,char 
                     *pPixelFileStr,Fil_t *pOutFile,struct ApiProdDescrStruc
                     *pApiProdDescr);

INT32 pckCompressNradProd(char *SourceFileStr,char *DestFileStr);
int Decode(char *nbuf,BUF *pAttrInfo,DAT *pDate,char *npar,char *npix);

INT32 FetchCnvParam( char *pOutParamFileStr, char *pParameterFileStr,
		     BUF *AttrInfo, DAT *DateInfo);
char *FetchFloatPara(char *pBuf,char *pParaStr, float *pResult, int *pErr );
char *FetchIntPara(char *pBuf,char *pParaStr, int *pResult, int *pErr );
INT32 NradExecute(char *argv[] );

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

INT32 ImportFromBufr(char *pBufferFileStr,
                     char *pInParamFileStr,
                     char *pOutParamFileStr,
                     char *pDestFileStr,
                     unsigned char PackAlg,
                     struct ApiProdDescrStruc *pApiProdDescr)
{
  INT32 iRc = OK;
  char PixelFileStr[MAX_FILE_NAME_SIZE];
  char UnpDestFileStr[MAX_FILE_NAME_SIZE];
  char PckDestFileStr[MAX_FILE_NAME_SIZE];
  BUF AttrInfo;
  DAT DateInfo;
  INT32 iDummyRc = 0;
  Fil_t OutFile;
  char *ExecPar[10];                        /* Watch the size*/

  memset( &AttrInfo, 0, sizeof(AttrInfo) );
  memset( &DateInfo, 0, sizeof(DateInfo) );
  memset(UnpDestFileStr, 
         0, 
         sizeof(UnpDestFileStr));
  if (PackAlg == RLE)
    {
      strcpy(PckDestFileStr, 
             pDestFileStr);
      tmpnam(UnpDestFileStr);          /* names for temporary files         */
    } 
  else
    strcpy(UnpDestFileStr, 
           pDestFileStr);
  tmpnam(PixelFileStr);
  if (strlen(PixelFileStr) == 0)
    return  APITMPFERR;

/************* O L D   C O D E ************************************
  iRc = (INT32)Decode(pBufferFileStr, 
                      &AttrInfo, 
                      &DateInfo, 
                      pOutParamFileStr, 
                      PixelFileStr);
************ E N D   O L D   C O D E ******************************/

  /*=== Build command string and execute it===*/
  /*=== Build the execution  command ===*/
  ExecPar[0] = "decbufr";
  ExecPar[1] = pBufferFileStr;
  ExecPar[2] = pOutParamFileStr;
  ExecPar[3] = PixelFileStr;
  ExecPar[4] = NULL;
          
  iRc = (INT32)NradExecute( ExecPar);
  if (iRc == NOK)    iRc = BUFERROR;

  
  /*=== Fetch all parameters from par.-file  ===*/
  if (iRc != BUFERROR)
   iRc = FetchCnvParam( pOutParamFileStr,
                        pInParamFileStr, 
                        &AttrInfo, 
                        &DateInfo);
  
  
  
  if (iRc == 0)
    {
      memset(&OutFile, 
             0, 
             sizeof(OutFile));
      strcpy(OutFile.Name, 
             UnpDestFileStr);
      fiCreate(&OutFile, 
               OutFile.Name, 
               512, 
               AttrInfo.ntlin *AttrInfo.ntcols, 
               &iRc);

      if ((OutFile.fp == NULL) || (iRc != OK))
        {
          if (iRc == -1)
            return  APIDESTFIL;
          else
            if (iRc == -3)
              return  PGFILLFILE;
            else
              return  APIILLPAR;
        } 

      iRc = ConvToNradFrmt(&AttrInfo, 
                           &DateInfo, 
                           pInParamFileStr, 
                           PixelFileStr, 
                           &OutFile, 
                           pApiProdDescr);
      fiClose(&OutFile, 
              &iTmpRc);
      if (PackAlg == RLE)
        {
        if (iRc == OK)
          {
          iRc = pckCompressNradProd(UnpDestFileStr, 
                                    PckDestFileStr);
          iDummyRc = remove(UnpDestFileStr);
          }     /* if (iRc == OK) */
        else
          iDummyRc = remove(UnpDestFileStr);
          
        }       /* if (PackAlg == RLE) */
      if (iRc == OK)
        iRc = APIOK;
    }   /* if (iRc == 0) */
  else
    iRc = BUFNRDERROR;
  iDummyRc = remove(PixelFileStr);
  return  iRc;
} 

INT32 ConvToNradFrmt(BUF *pAttrInfo,DAT *pDate,char *pParameterFileStr,char 
                     *pPixelFileStr,Fil_t *pOutFile,struct ApiProdDescrStruc
                     *pApiProdDescr)
{
  INT32 iRc = OK;
  FILE *pPixFile;
  Attr_t PixelInfoOut;
  Pixel_t *pPixelAttrOut;
  Attr_t TimeInfoOut;
  Time_t *pTimeAttrOut;
  Attr_t AreaDefInfoOut;
  AreaDef_t *pAreaDefAttrOut;
  Attr_t QuantityInfoOut;
  Quantity_t *pQuantityAttrOut;
  Attr_t ProdNameInfoOut;
  Attr_t AreaWallAttr;
  Attr_t ZtoRConstInfoOut;
  Z_To_R_Constants_t *pZtoRConstAttrOut;
  Attr_t IntStoreInfo;
  IntStore_t *pIntStoreAttr;
  Attr_t ResolutionInfo;
  Attr_t AreaInfo;
  Area_t *pAreaAttr;
  Resolution_t *pResolutionAttr;
  Attr_t RrTypeInfoOut;
  RrTyp_t *pRrTypeAttr;
  Attr_t LevelInfo;
  Levels_t *pLevelAttr;
  unsigned char *pInData;              /* BBN 940526 to unsigned            */
  INT32 iPixDataSize = 0;
  INT32 iTotalNoOfBytesWritten;
  INT32 iNextRow;
  unsigned char *pTmpRow;
  unsigned char *pRowPos;
  float fTmpFloat;
  INT32 iInd = 0;
  INT32 iOffset = 0;
  char tmpTime[20];
  INT32 iAttrLen = 0;
  char AreaStr[20] = "                   ";
  unsigned char ClassLimTab[CLASS_TAB_MAX+1];
  INT32 iTabInd = 0;
  INT32 iHandledBytes = 0;
  float fBot;
  float fTop;
  float fCurrLim;
  float fBufLimCorr;
  float fUnitConv;
  float fDummyVal;
  INT32 iDummyVal;
  INT32 iHeight;
  char ProjTypeStr[40];
  char MirrorStr [10];
  INT32 iMirror = 1;
  /**************************************************************************/
  /* -------- initialize atribute structures -----------                    */
  /**************************************************************************/

  pPixelAttrOut = (Pixel_t *)PixelInfoOut.buff;
  pTimeAttrOut = (Time_t *)TimeInfoOut.buff;
  pAreaDefAttrOut = (AreaDef_t *)AreaDefInfoOut.buff;
  pQuantityAttrOut = (Quantity_t *)QuantityInfoOut.buff;
  pZtoRConstAttrOut = (Z_To_R_Constants_t *)ZtoRConstInfoOut.buff;
  pIntStoreAttr = (IntStore_t *)IntStoreInfo.buff;
  pResolutionAttr = (Resolution_t *)ResolutionInfo.buff;
  pAreaAttr = (Area_t *)AreaInfo.buff;
  pRrTypeAttr = (RrTyp_t *)RrTypeInfoOut.buff;
  pLevelAttr = (Levels_t *)LevelInfo.buff;

  /**************************************************************************/
  /* ---< Create Nordrad file attribute in OutFile >----                    */
  /**************************************************************************/

  pPixelAttrOut->FileOffset = 513;
  pPixelAttrOut->RowCnt = pAttrInfo->ntlin;
  pPixelAttrOut->ColCnt = pAttrInfo->ntcols;
  pPixelAttrOut->StorePixels = pPixelAttrOut->RowCnt *pPixelAttrOut->ColCnt;
  pPixelAttrOut->StoreBits = 8;
  pPixelAttrOut->StoreMax = 255;
  pPixelAttrOut->Compressed = FALSE;
  iAttrLen = sizeof(Pixel_t);
  fiWriteAttr(pOutFile, 
              (Attr_t *)pPixelAttrOut, 
              Pixel_Attr, 
              iAttrLen, 
              &iRc);
  if (iRc < 0)
    return  BUFNRDERROR;

  memset(&AreaDefInfoOut, 
         0, 
         sizeof(AreaDefInfoOut));
  switch (pAttrInfo->iproj)
    {
      case 1 :
        pAreaDefAttrOut->Proj.ProjectionType = Polar_Stereographic;

/*        pAreaDefAttrOut->Proj.ProjData.Pos.Lat = pAttrInfo->ilat1;*/
/*        pAreaDefAttrOut->Proj.ProjData.Pos.Long = pAttrInfo->ilat2;*/
	iRc = GetParFileValue(pParameterFileStr, 
                              "LAT", 
                              GET_FLOAT_TYPE, 
                              (INT32 *)&iDummyVal, 
                              &fTmpFloat);
	if (iRc != OK)
            return iRc;

	pAreaDefAttrOut->Proj.ProjData.Pos.Lat = fTmpFloat;
        iRc = GetParFileValue(pParameterFileStr, 
                              "LONG", 
                              GET_FLOAT_TYPE, 
                              &iDummyVal, 
                              &fTmpFloat);
	if (iRc != OK)
            return iRc;

        pAreaDefAttrOut->Proj.ProjData.Pos.Long = fTmpFloat;

        break;
      default  :
        iRc = GetParFileValue(pParameterFileStr, 
                              "PROJECTION", 
                              GET_STR_TYPE, 
                              (INT32 *)ProjTypeStr, 
                              &fDummyVal);
        if (iRc != OK)
          return iRc;

        UtlStrToUpper(ProjTypeStr, 
                      strlen(ProjTypeStr));
        if (strcmp(ProjTypeStr, 
                   "GNOMONIC") == 0)
          pAreaDefAttrOut->Proj.ProjectionType = Gnomonic;
        else
          if (strcmp(ProjTypeStr, 
                     "POLARSTEREOGRAPHIC") == 0)

            pAreaDefAttrOut->Proj.ProjectionType = Polar_Stereographic;
          else
            if (strcmp(ProjTypeStr, 
                       "UNKNOWN") == 0)

              pAreaDefAttrOut->Proj.ProjectionType = Unknown;
            else
              return  BUFPARCONT;

        if (pAreaDefAttrOut->Proj.ProjectionType != Unknown)
          {
            iRc = GetParFileValue(pParameterFileStr, 
                                  "LAT", 
                                  GET_FLOAT_TYPE, 
                                  (INT32 *)&iDummyVal, 
                                  &fTmpFloat);
            if (iRc != OK)
              return iRc;

            pAreaDefAttrOut->Proj.ProjData.Pos.Lat = fTmpFloat;
            iRc = GetParFileValue(pParameterFileStr, 
                                  "LONG", 
                                  GET_FLOAT_TYPE, 
                                  &iDummyVal, 
                                  &fTmpFloat);
            if (iRc != OK)
              return iRc;

            pAreaDefAttrOut->Proj.ProjData.Pos.Long = fTmpFloat;
          }                            /* if                                
                                       (pAreaDefAttrOut->Proj.ProjectionType
                                          != Unknown)                       */
        else
          {
            fTmpFloat = 0.0;
            pAreaDefAttrOut->Proj.ProjData.Pos.Long = fTmpFloat;
            pAreaDefAttrOut->Proj.ProjData.Pos.Lat  = fTmpFloat;
          }                            /* else                              */

        /********************************************************************/
        /* Do something                                                     */
        /********************************************************************/

        break;
    } 
  ;                                    /* switch(pAttrInfo->iproj)          */
  pAreaDefAttrOut->NorthEast.LatLong.Lat  = pAttrInfo->ilat[2];
  pAreaDefAttrOut->NorthEast.LatLong.Long = pAttrInfo->ilon[2];
  pAreaDefAttrOut->SouthWest.LatLong.Lat  = pAttrInfo->ilat[4];
  pAreaDefAttrOut->SouthWest.LatLong.Long = pAttrInfo->ilon[4];
  iAttrLen = sizeof(AreaDef_t);
  fiWriteAttr(pOutFile, 
              (Attr_t *)pAreaDefAttrOut, 
              AreaProperties_Attr, 
              iAttrLen, 
              &iRc);
  if (iRc < 0)
    return  iRc;

  sprintf(tmpTime, 
          "%02d%02d%02d%02d%02d", 
          pDate->datim[1], 
          pDate->datim[2], 
          pDate->datim[3], 
          pDate->datim[4], 
          pDate->datim[5]);
  strcat(tmpTime, 
         "00");
  memcpy(pTimeAttrOut->timeString, 
         tmpTime, 
         12);
  iAttrLen = sizeof(Time_t);
  fiWriteAttr(pOutFile, 
              (Attr_t *)pTimeAttrOut, 
              Time_Attr, 
              iAttrLen, 
              &iRc);
  if (iRc < 0)
    return  iRc;

  switch (pAttrInfo->iPictType)
    {
    case 0 :
      {
      ProdNameInfoOut.buff[0] = PROD_RRPPI_Z;
      pApiProdDescr->bProd = PROD_RRPPI_Z;
      break;
      } /* case 0 : */
    case 2:
      {
      ProdNameInfoOut.buff[0] = PROD_RRCAPPI_Z;
      pApiProdDescr->bProd = PROD_RRCAPPI_Z;
      iRc = GetParFileValue(pParameterFileStr, 
			    "HEIGHT", 
			    GET_INT_TYPE, 
			    (INT32 *)&iHeight, 
			    &fDummyVal);
      if (iRc != OK)	
	return iRc;
      pApiProdDescr->uData.RrType.uRr.RrCappi.iHeight = iHeight;
      break;
      } /* case 2: */
    case 9:
      {
      ProdNameInfoOut.buff[0] = PROD_RRPSC_Z;
      pApiProdDescr->bProd = PROD_RRPSC_Z;
      break;
      } /* case 9: */
    case 10:
      {
      ProdNameInfoOut.buff[0] = PROD_RRHMI_Z;  /* North */
      AreaWallAttr.buff[0] = NORTH;
      pApiProdDescr->bProd = PROD_RRHMI_Z;
      pApiProdDescr->uData.RrType.uRr.RrHmi.bHmiWall = NORTH;
      
      iRc = GetLevelsFromParFile(pParameterFileStr, 
			         pLevelAttr,
				 (INT32) pPixelAttrOut->RowCnt);
      if (iRc != OK)
         return  iRc;
      break;
      } /* case 10: */
    case 11:
      {
      ProdNameInfoOut.buff[0] = PROD_RRHMI_Z;  /* East */
      AreaWallAttr.buff[0] = EAST;
      pApiProdDescr->bProd = PROD_RRHMI_Z;
      pApiProdDescr->uData.RrType.uRr.RrHmi.bHmiWall = EAST;

      iRc = GetLevelsFromParFile(pParameterFileStr, 
			         pLevelAttr,
				 (INT32) pPixelAttrOut->ColCnt);
      if (iRc != OK)
         return  iRc;


      break;
      } /* case 11: */
    case 14:
      {
      ProdNameInfoOut.buff[0] = PROD_RRVMI_Z;
      pApiProdDescr->bProd = PROD_RRVMI_Z;
      break;
      } /* case 14: */
    case 15:
      {
      ProdNameInfoOut.buff[0] = PROD_RRSRI_Z;
      pApiProdDescr->bProd = PROD_RRSRI_Z;
      break;
      } /* case 15: */
    default:
      return  BUFPARCONT;
    }   /* switch (pAttrInfo->iPictType) */

  iAttrLen = sizeof(char);
  fiWriteAttr(pOutFile, 
              (Attr_t *)&ProdNameInfoOut.buff[0], 
              Name_Attr, 
              iAttrLen, 
              &iRc);
  if (iRc < 0)
    return  iRc;

  if (ProdNameInfoOut.buff[0] == PROD_RRSRI_Z)
    {
    pQuantityAttrOut->Unit = mm_h;
    pQuantityAttrOut->What = q_Log_Surface_Rain_Intensity;
    }   /* if (ProdNameInfoOut.buff[0] == PROD_RRSRI_Z) */
  else
    {
    pQuantityAttrOut->Unit = Dbz;
    pQuantityAttrOut->What = q_Refl;
    }   /* else */

  iAttrLen = sizeof(Quantity_t);
  fiWriteAttr(pOutFile, 
              (Attr_t *)pQuantityAttrOut, 
              Quantity_Attr, 
              iAttrLen, 
              &iRc);
  if (iRc < 0)
    return  iRc;

  pResolutionAttr->Resolution = pAttrInfo->isizev;
  iAttrLen = sizeof(Resolution_t);
  fiWriteAttr(pOutFile, 
              (Attr_t *)pResolutionAttr, 
              Resolution_Attr, 
              iAttrLen, 
              &iRc);
  if (iRc < 0)
    return  iRc;

  *pRrTypeAttr = Rr_Normal;	/* Let's just pretend */
  iAttrLen = sizeof(RrTyp_t);
  fiWriteAttr(pOutFile, 
              (Attr_t *)&RrTypeInfoOut.buff[0], 
              RrTyp_Attr, 
              iAttrLen, 
              &iRc);
  if (iRc < 0)
    return  iRc;

  if (ProdNameInfoOut.buff[0] == PROD_RRHMI_Z)
    {
    iAttrLen = 8;
    fiWriteAttr(pOutFile, 
                (Attr_t *)&AreaWallAttr.buff[0], 
	        AreaWall_Attr,
                iAttrLen, 
                &iRc);
    if (iRc < 0)
      return  iRc;

    iAttrLen = MaxLevels_c * sizeof (Height_t);
    fiWriteAttr(pOutFile, 
                (Attr_t *)&LevelInfo.buff[0], 
	        Levels_Attr,
                iAttrLen, 
                &iRc);
    if (iRc < 0)
      return  iRc;
    }

  if (ProdNameInfoOut.buff[0] == PROD_RRSRI_Z)
     {
     pZtoRConstAttrOut->Factor = pAttrInfo->ifaczr;
     pZtoRConstAttrOut->Exponent=pAttrInfo->iexpzr;/*Removed /100 ads 951002*/
     pZtoRConstAttrOut->Type = 0;
     iAttrLen = sizeof(Z_To_R_Constants_t);
     fiWriteAttr(pOutFile, 
                 (Attr_t *)pZtoRConstAttrOut, 
                 Z_To_R_Constants_Attr, 
                 iAttrLen, 
                 &iRc);
     if (iRc < 0)
       return  iRc;

     iRc = GetParFileValue(pParameterFileStr, 
                           "SLOPE", 
                           GET_FLOAT_TYPE, 
                           &iDummyVal, 
                           &pIntStoreAttr->Slope);
     if (iRc != OK)
       return  iRc;

     iRc = GetParFileValue(pParameterFileStr, 
                           "ORD", 
                           GET_FLOAT_TYPE, 
                           &iDummyVal, 
                           &pIntStoreAttr->Ord);
     if (iRc != OK)
       return  iRc;

     iRc = GetParFileValue(pParameterFileStr, 
                           "OFFSET", 
                           GET_INT_TYPE, 
                           &iOffset, 
                           &fDummyVal);
     if (iRc != OK)
        return  iRc;

     pIntStoreAttr->Offset = iOffset;
     iAttrLen = sizeof(IntStore_t);
     fiWriteAttr(pOutFile, 
                 (Attr_t *)pIntStoreAttr, 
                 IntStore_Attr, 
                 iAttrLen, 
                 &iRc);
     if (iRc < 0)
        return  iRc;
     }  /* if (ProdNameInfoOut.buff[0] == PROD_RRSRI_Z) */
   else
     {
     pIntStoreAttr->Ord = pAttrInfo->Ord;
     pIntStoreAttr->Slope = pAttrInfo->Slope;
     pIntStoreAttr->Offset = 0;
     iAttrLen = sizeof(IntStore_t);
     fiWriteAttr(pOutFile, 
                 (Attr_t *)pIntStoreAttr, 
                 IntStore_Attr, 
                 iAttrLen, 
                 &iRc);
     if (iRc < 0)
        return  iRc;
     }  /* else */

  iRc = GetParFileValue(pParameterFileStr, 
                        "AREA", 
                        GET_STR_TYPE, 
                        (INT32 *)AreaStr, 
                        &fDummyVal);
  if (iRc != OK)
    return  iRc;

  memcpy(pAreaAttr->Name, 
         AreaStr, 
         16);
  iAttrLen = sizeof(Area_t);
  fiWriteAttr(pOutFile, 
              (Attr_t *)pAreaAttr, 
              Area_Attr, 
              iAttrLen, 
              &iRc);
  if (iRc < 0)
    return  iRc;

  /**************************************************************************/
  /* ---< Re arrange pixel data for nordrad format >----                    */
  /**************************************************************************/

  /*************************************************************************/
  /* Find out if the input file should be mirrored or not                  */
  /*************************************************************************/

  iRc = GetParFileValue(pParameterFileStr, 
			"MIRROR", 
                        GET_STR_TYPE, 
                        (INT32 *)MirrorStr, 
                        &fDummyVal);
  if (iRc == OK)
     {
     /* It is OK if the parameter is not found */
     /* In that case we'll mirror the image    */

      UtlStrToUpper(MirrorStr, 
                    strlen(MirrorStr));
      if (strcmp(MirrorStr, 
          "TRUE") == 0)
	iMirror = 1;
      else
         if (strcmp(MirrorStr, 
             "FALSE") == 0)
	   iMirror = 0;
     }

  iPixDataSize = pPixelAttrOut->ColCnt *pPixelAttrOut->RowCnt;
  pTmpRow = (unsigned char *)malloc(pPixelAttrOut->ColCnt);
  pInData = (unsigned char *)malloc(iPixDataSize);
  if ((pInData == NULL) || (pTmpRow == NULL))
    return  APINOMEM;

  if (ProdNameInfoOut.buff[0] == PROD_RRSRI_Z)
     {
     /* We will only have to convert the pixel values when */
     /* we are dealing with a 4 bit code expressing        */
     /* surface rain intensity                             */
     memset(ClassLimTab, 
            255, 
            sizeof(ClassLimTab));
     fBufLimCorr = 10000000.00;           /* pow(10,7);               */
     fUnitConv = 1000.00*3600.00;         /* m/sec > mm/h            */
     fCurrLim = (pAttrInfo->ibotvl/fBufLimCorr);
     fBot = fCurrLim *fUnitConv;
     for (iTabInd = 0; (iTabInd < pAttrInfo->ntpixv); iTabInd++)
        {
        fCurrLim = pAttrInfo->itopvl[iTabInd+1]/fBufLimCorr;
        fTop = fCurrLim *fUnitConv;
        if ((fBot == 0.0) && (fTop == 0.0))
           ClassLimTab[iTabInd] = 0;
        else
           {
           if (fTop == 0.0)
              fTop = 0.01;
           fTmpFloat = (log10(fTop)+log10(fBot+0.01))/2.0;
           iDummyVal = ((fTmpFloat-pIntStoreAttr->Ord)/pIntStoreAttr->Slope)+
                          pIntStoreAttr->Offset;
           if (iDummyVal > 255)
              ClassLimTab[iTabInd] = 255;
           else
              ClassLimTab[iTabInd] = (unsigned char)iDummyVal;
           } 
       fBot = fTop;
       } /* for (iTabInd = 0; (iTabInd < pAttrInfo->ntpixv); iTabInd++) */
     
    ClassLimTab[0] = 0;
    ClassLimTab[15] = 255;
    }   /* if (ProdNameInfoOut.buff[0] == PROD_RRSRI_Z) */

  /**************************************************************************/
  /* read from image converted from file with BUFR format                   */
  /**************************************************************************/

#ifdef   VMS
  pPixFile = fopen(pPixelFileStr, 
                   "rb", 
                   "ctx=stm");
#else
  pPixFile = fopen(pPixelFileStr, 
                   "rb");
#endif
  if (pPixFile == NULL)
    return  APITMPFERR;
    
  fseek(pPixFile, 
        0L, 
        SEEK_SET);
        
  iHandledBytes = fread(pInData, 
                        sizeof(char), 
                        iPixDataSize, 
                        pPixFile);
  if (iHandledBytes != iPixDataSize)
    return  APITMPFERR;

  fiOpen(pOutFile, 
         UpdateMode, 
         &iRc);
  if (iRc != OK)
    {
      if (iRc == -1)
        return  PGFFILNOTFND;
      else
        if (iRc == -3)
          return  PGFILLFILE;
        else
          return  APIILLPAR;
    } 

  fiAllocate(pOutFile, 
             iPixDataSize, 
             &pPixelAttrOut->FileOffset, 
             &iRc);
  if (iRc != OK)
    return  BUFNRDERROR;

  pPixelAttrOut->FileOffset += 1;

  /**************************************************************************/
  /* If the file should be mirrored                                         */
  /*     set pointer to last row in image data and read one row at a time   */
  /*     backwords toward beginning.                                        */ 
  /* add in next position from start in target file                         */
  /**************************************************************************/

  if (iMirror == 1)
     iNextRow = iPixDataSize-pPixelAttrOut->ColCnt;
  else
     iNextRow = 0;

  pRowPos = &pInData[iNextRow];
  iTotalNoOfBytesWritten = 0;

  if (ProdNameInfoOut.buff[0] == PROD_RRSRI_Z)
     {
     /* Convert pixels */
     while (iTotalNoOfBytesWritten < iPixDataSize)
        {
        iInd = 0;
        while (iInd < pPixelAttrOut->ColCnt)
           {
           pTmpRow[iInd] = (unsigned char)ClassLimTab[pRowPos[iInd]];
           iInd++;
           }    /* while (iInd < pPixelAttrOut->ColCnt) */ 
        iHandledBytes = fwrite(&pTmpRow[0], 
                               sizeof(char), 
                               pPixelAttrOut->ColCnt, 
                               pOutFile->fp);
        if (iHandledBytes != pPixelAttrOut->ColCnt)
           {
           fiClose(pOutFile, 
                   &iTmpRc);
           fclose(pPixFile);
           free(pTmpRow);
           free(pInData);
           return  BUFNRDERROR;
           } 

        iTotalNoOfBytesWritten += iHandledBytes;
        if (iMirror == 1)
           iNextRow -= pPixelAttrOut->ColCnt;
	else
           iNextRow += pPixelAttrOut->ColCnt;

        pRowPos = &pInData[iNextRow];
        }       /* while (iTotalNoOfBytesWritten < iPixDataSize) */
     }  /* if (ProdNameInfoOut.buff[0] == PROD_RRSRI_Z) */
   else
     {
     /* Don't convert pixels */
     while (iTotalNoOfBytesWritten < iPixDataSize)
        {
        iHandledBytes = fwrite(pRowPos, 
                               sizeof(char), 
                               pPixelAttrOut->ColCnt, 
                               pOutFile->fp);
        if (iHandledBytes != pPixelAttrOut->ColCnt)
           {
           fiClose(pOutFile, 
                   &iTmpRc);
           fclose(pPixFile);
           free(pTmpRow);
           free(pInData);
           return  BUFNRDERROR;
           } 

        iTotalNoOfBytesWritten += iHandledBytes;
        if (iMirror == 1)
           iNextRow -= pPixelAttrOut->ColCnt;
	else
           iNextRow += pPixelAttrOut->ColCnt;

        pRowPos = &pInData[iNextRow];
        }       /* while (iTotalNoOfBytesWritten < iPixDataSize) */
     }  /* else */
  fclose(pPixFile);
  free(pTmpRow);
  free(pInData);

  /**************************************************************************/
  /* create a product description memset(pApiProdDescr,0,sizeof(struct      */
  /* ApiProdDescrStruc));                                                   */
  /**************************************************************************/

  if (pTimeAttrOut->timeString[0] == '9')     /* ASCII 9 */
    {
    memcpy(&pApiProdDescr->cTimeStr[0], 
           "19", 
           2);
    }   /* if (pTimeAttrOut->timeString[0] == '9') */
  else
    {
    memcpy(&pApiProdDescr->cTimeStr[0], 
           "20", 
           2);
    }   /* if (pTimeAttrOut->timeString[0] != '9') */
         
  memcpy(&pApiProdDescr->cTimeStr[2], 
         &pTimeAttrOut->timeString[0], 
         2);
  memcpy(&pApiProdDescr->cTimeStr[4], 
         "-", 
         1);
  memcpy(&pApiProdDescr->cTimeStr[5], 
         &pTimeAttrOut->timeString[2], 
         2);
  memcpy(&pApiProdDescr->cTimeStr[7], 
         "-", 
         1);
  memcpy(&pApiProdDescr->cTimeStr[8], 
         &pTimeAttrOut->timeString[4], 
         2);
  memcpy(&pApiProdDescr->cTimeStr[10], 
         " ", 
         1);
  memcpy(&pApiProdDescr->cTimeStr[11], 
         &pTimeAttrOut->timeString[6], 
         2);
  memcpy(&pApiProdDescr->cTimeStr[13], 
         ":", 
         1);
  memcpy(&pApiProdDescr->cTimeStr[14], 
         &pTimeAttrOut->timeString[8], 
         2);
  memcpy(&pApiProdDescr->cTimeStr[16], 
         ":", 
         1);
  memcpy(&pApiProdDescr->cTimeStr[17], 
         &pTimeAttrOut->timeString[10], 
         2);
  memcpy(&pApiProdDescr->cTimeStr[19], 
         ".", 
         1);
  memcpy(&pApiProdDescr->cTimeStr[20], 
         "00", 
         2);
  pApiProdDescr->cTimeStr[22] = 0;
  memcpy(pApiProdDescr->cArea, 
         pAreaAttr->Name, 
         sizeof(pApiProdDescr->cArea));
  pApiProdDescr->iResolution = pAttrInfo->isizev;
  pApiProdDescr->uData.RrType.bRrMode = 2;/* NonDoppler enl J.Svensson 97-02-13 */
  return  iRc;
} 

INT32 GetLevelsFromParFile(char *pParameterFileStr, 
			   Levels_t *pLevelAttr,
			   INT32 Cnt)
{
  float fDummyVal;
  INT32 iRc;
  int   iIx;
  char  chKeyString [10];

  for (iIx = 0; iIx < MaxLevels_c; iIx++)
     {
        pLevelAttr->Levels [iIx] = 0; 
     }  /* for (iIx = 1; iIx <= MaxLevels_c; iIx++) */

  for (iIx = 0; iIx < Cnt; iIx++)
     {
	sprintf (chKeyString,"HEIGHT%02d",iIx+1);

	iRc = GetParFileValue(pParameterFileStr, 
                              chKeyString, 
                              GET_INT_TYPE, 
                              &(pLevelAttr->Levels[iIx]), 
                              &fDummyVal);
        if (iRc != OK)
          return iRc;

     }  /* for (iIx = 1; iIx <= Cnt; iIx++) */
   iRc = OK;
   return iRc;
}



INT32 GetParFileValue(char *pParFileStr,char *pIdentifier,INT32 iType,INT32 
                      *piValue,float *pfValue)
{
  FILE *pParFile;
  char Line[200];
  char *pLine;
  char *pIdStr;
  char *pValStr;
  INT32 iSearch = TRUE;

  *piValue = 0;
  pParFile = fopen(pParFileStr, 
                   "r");
  if (pParFile != NULL)
    {
      pLine = Line;
      fgets(Line, 
            sizeof(Line), 
            pParFile);
      while ((feof(pParFile) == 0) && (iSearch == TRUE))
        {
          pIdStr = strtok(pLine, 
                          " =\r\f\n");
          UtlStrToUpper(pIdStr, 
                        strlen(pIdStr));
          if (strcmp(pIdStr, 
                     pIdentifier) == 0)
            {
              pValStr = strtok(NULL, 
                               " =\r\f\n");
              if (pValStr != NULL)
                {
                  if (iType == GET_INT_TYPE)
                    *piValue = atoi(pValStr);
                  else
                    if (iType == GET_STR_TYPE)

                      strcpy((char *)piValue, 
                             pValStr);
                    else
                      if (iType == GET_FLOAT_TYPE)

                        *pfValue = atof(pValStr);
                }                      /* if (pValStr != NULL)              */
              iSearch = FALSE;
            }                          /* if (strcmp(pIdStr,pIdentifier) == 
                                          0)                                */
          pLine = Line;
          fgets(Line, 
                sizeof(Line), 
                pParFile);
        }                              /* while ((feof(pParFile) == 0) &&   
                                          (iSearch == TRUE))                */
      fclose(pParFile);
      if (iSearch == FALSE)
        return  OK;
      else
        return  BUFPARCONT;
    }                                  /* if (pParFile != NULL)             */
  else
    return  BUFPARNAME;
} 

INT32 FetchCnvParam( char *pOutParamFileStr, 
		     char *pParameterFileStr,
		     BUF *AttrInfo, 
		     DAT *DateInfo) 
/*===========================================================================
  Returns -1 on file-errors 0 on OK 1 on conversion-errors*/
{
  FILE *ParFilep;
  int FileLen, Err, iIx;
  float HelpFloat;
  char HelpBuf[MAX_PARA_FILE_SIZE];
  char *pHelp;
  char *pHelpBuf;
  char *pSaveBufPos;
  INT32 iDummyVal;
  float fDummyVal;
  INT32 iRc = OK;


  pHelp = HelpBuf;

  memset(&HelpBuf, 0, sizeof(HelpBuf));         /* Clear using end-of-string*/
  Err = 0;
  if ( (ParFilep = fopen(pOutParamFileStr, "r")) == NULL)
    return -1;
  
  FileLen = fread( HelpBuf, sizeof(char), sizeof(HelpBuf) , ParFilep);
  if (FileLen <0) {
    fclose(ParFilep);
    return -1;
    }


  pHelpBuf = strstr((char *) &HelpBuf, "3  1 192");
  if (NULL != pHelpBuf)
    {
       /* If we find the string 3  1 192 then the contents */
       /* is probably correct ? */

    /* Year */
    pHelp = FetchIntPara(pHelp, "0  4   1",
			 &(DateInfo->datim[1]), &Err);/* 1*/
    if (DateInfo->datim[1] >= 2000) 
      {
      DateInfo->datim[1] -= 2000;                         /* One century */
      }   /* if (DateInfo->datim[1] >= 2000) */
    else
      {
      DateInfo->datim[1] -= 1900;                         /* One century */
      }
    /* Month */
    pHelp = FetchIntPara(pHelp, "0  4   2",
			 &(DateInfo->datim[2]), &Err);/* 2*/
    /* Day */
    pHelp = FetchIntPara(pHelp, "0  4   3",
			 &(DateInfo->datim[3]), &Err);/* 3*/
    /* Hour */
    pHelp = FetchIntPara(pHelp, "0  4   4",
			 &(DateInfo->datim[4]), &Err);/* 4*/
    /* Minute */
    pHelp = FetchIntPara(pHelp, "0  4   5",
			 &(DateInfo->datim[5]), &Err);/* 5*/

    pSaveBufPos = pHelp;

    /* Latitude */
    pHelp = FetchFloatPara(pHelp,"0  5   2",
			   &(AttrInfo->ilat[1]), &Err );/* 6*/
    /* Longitude */
    pHelp = FetchFloatPara(pHelp,"0  6   2",
			   &(AttrInfo->ilon[1]), &Err );/* 7*/
    /* Latitude */
    pHelp = FetchFloatPara(pHelp,"0  5   2",
			   &(AttrInfo->ilat[2]), &Err );/* 8*/
    /* Longitude */
    pHelp = FetchFloatPara(pHelp,"0  6   2",
			   &(AttrInfo->ilon[2]), &Err );/* 9*/
    /* Latitude */
    pHelp = FetchFloatPara(pHelp,"0  5   2",
			   &(AttrInfo->ilat[3]), &Err );/*10*/
    /* Longitude */
    pHelp = FetchFloatPara(pHelp,"0  6   2",
			   &(AttrInfo->ilon[3]), &Err );/*11*/
    /* Latitude */
    pHelp = FetchFloatPara(pHelp,"0  5   2",
			   &(AttrInfo->ilat[4]), &Err );/*12*/
    /* Longitude */
    pHelp = FetchFloatPara(pHelp,"0  6   2",
			   &(AttrInfo->ilon[4]), &Err );/*13*/

    if (Err != 0)
    {	
      iRc = GetParFileValue(pParameterFileStr, 
			    "LATNORTHEAST", 
			    GET_FLOAT_TYPE, 
			    (INT32 *)&iDummyVal, 
			    &(AttrInfo->ilat[2]));
      if (iRc != OK)	
	return  Err;

      iRc = GetParFileValue(pParameterFileStr, 
			    "LONGNORTHEAST", 
			    GET_FLOAT_TYPE, 
			    (INT32 *)&iDummyVal, 
			    &(AttrInfo->ilon[2]));
      if (iRc != OK)	
	return  Err;
      iRc = GetParFileValue(pParameterFileStr, 
			    "LATSOUTHWEST", 
			    GET_FLOAT_TYPE, 
			    (INT32 *)&iDummyVal, 
			    &(AttrInfo->ilat[4]));
      if (iRc != OK)	
	return  Err;
      iRc = GetParFileValue(pParameterFileStr, 
			    "LONGSOUTHWEST", 
			    GET_FLOAT_TYPE, 
			    (INT32 *)&iDummyVal, 
			    &(AttrInfo->ilon[4]));
      if (iRc != OK)	
	return  Err;

      pHelp = pSaveBufPos;
      
      Err = 0;
    }

    /* Projection type */
    pHelp = FetchIntPara(pHelp, "0 29   1",
			 &(AttrInfo->iproj), &Err );  /* 14*/

    /* Latitude */
/*    pHelp = FetchFloatPara(pHelp, "0  5   2", */
/*			   &(AttrInfo->ilat1), &Err ); *//* 15*/
    /* Latitude */
/*    pHelp = FetchFloatPara(pHelp, "0  5   2",*/
/*			   &(AttrInfo->ilat2), &Err );*//* 16*/

    /* Pixel size on horizontal -1 */
    pHelp = FetchIntPara(pHelp, "0  5  33",
			 &(AttrInfo->isizeh), &Err ); /* 17*/
    Err = 0;
    
    /* Pixel size on horizontal -2 (used as resolution) */
    pHelp = FetchIntPara(pHelp, "0  6  33",
			 &(AttrInfo->isizev) , &Err); /* 18*/
    if (Err != 0)
      {	
      iRc = GetParFileValue(pParameterFileStr, 
			    "RESOLUTION", 
			    GET_INT_TYPE, 
			    (INT32 *)&(AttrInfo->isizev), 
			    &fDummyVal);
      if (iRc != OK)	
	return  Err;
      Err = 0;
      }
    /* Number of pixels per row (= Number of rows) */
    pHelp = FetchIntPara(pHelp, "0 30  21",
			 &(AttrInfo->ntcols) , &Err); /* 19*/
    if (Err != 0)
      {	
      iRc = GetParFileValue(pParameterFileStr, 
			    "COLUMNS", 
			    GET_INT_TYPE, 
			    (INT32 *)&(AttrInfo->ntcols), 
			    &fDummyVal);
      if (iRc != OK)	
	return  Err;
      Err = 0;
      }

    /* Number of pixels per column (= Number of rows) */
    pHelp = FetchIntPara(pHelp, "0 30  22",
			 &(AttrInfo->ntlin) , &Err);  /* 20*/
    if (Err != 0)
      {	
      iRc = GetParFileValue(pParameterFileStr, 
			    "ROWS", 
			    GET_INT_TYPE, 
			    (INT32 *)&(AttrInfo->ntlin), 
			    &fDummyVal);
      if (iRc != OK)	
	return  Err;
      Err = 0;
      }

    /* Picture type  */
    pHelp = FetchIntPara(pHelp, "0 30  31", &(AttrInfo->iPictType), &Err );
    if (Err != 0)
      {	
      iRc = GetParFileValue(pParameterFileStr, 
			    "PICTTYPE", 
			    GET_INT_TYPE, 
			    &(AttrInfo->iPictType), 
			    &fDummyVal);
      if (iRc != OK)	
	return  Err;
      Err = 0;
      }

    /* Search for the reflectivity parameter (alfa) */

    pHelpBuf = strstr((char *) &HelpBuf, "0 25 202");
    if (NULL == pHelpBuf)
      {
      /* No reflectivity parameter found, this must be a  */
      /* four bit SRI product                             */
      /* Rainfall intensity */
      pHelp = FetchIntPara(pHelp, "0 21  36",
			   &(AttrInfo->ibotvl),&Err); /* 24*/
      /* Pixel value (4 bits) */
      pHelp = FetchIntPara(pHelp, "0 31   1",
			   &(AttrInfo->ntpixv),&Err); /* 25*/
      for (iIx= 1; iIx <= AttrInfo->ntpixv ; iIx++)
	{                 /* 26-41*/
	pHelp = FetchFloatPara(pHelp, "0 21  36", &HelpFloat, &Err );
	AttrInfo->itopvl[iIx]  = HelpFloat * 10;
	}
      /* I to R conversion factor */
      pHelp =FetchFloatPara(pHelp, "0 25   7",
			    &(AttrInfo->ifaczr),&Err);/* 43*/
      /* Z to R conversion exponent */
      pHelp =FetchFloatPara(pHelp, "0 25   8",
			    &(AttrInfo->iexpzr),&Err);/* 44*/
      }   /* if (NULL == pHelpBuf) */
    else
      {
      /* Some special treatment must be performed here 	         */
      /* The routine FetchFloatPara expects to find the value      */
      /* before the keystring, but for '0 25 202' and '0 25 203'   */
      /* the keystring is found both before and after the value    */
      /* We must position after the first keystring before calling */
      /* FetchFloatPara.                                           */

      pHelp = pHelpBuf + strlen ("0 25 202");
      /* alfa */
      pHelp = FetchFloatPara(pHelp, "0 25 202",
			     &(AttrInfo->Ord),&Err);

      /* beta */
      pHelpBuf = strstr((char *) &HelpBuf, "0 25 203");
      pHelp = pHelpBuf + strlen ("0 25 203");

      pHelp = FetchFloatPara(pHelp, "0 25 203",
			     &(AttrInfo->Slope),&Err);
      }   /* else */	
    } /* if (NULL != pHelpBuf) */
  else
    {
    /* This may be a file where a lot of expected parameters */
    /* are missing (a danish one) */

    /* Year */
    pHelp = FetchIntPara(pHelp, "0  4   1",
			 &(DateInfo->datim[1]), &Err);/* 1*/
    if (DateInfo->datim[1] >= 2000) 
      {
      DateInfo->datim[1] -= 2000;                         /* One century */
      }   /* if (DateInfo->datim[1] >= 2000) */
    else
      {
      DateInfo->datim[1] -= 1900;                         /* One century */
      }
    /* Month */
    pHelp = FetchIntPara(pHelp, "0  4   2",
			 &(DateInfo->datim[2]), &Err);/* 2*/
    /* Day */
    pHelp = FetchIntPara(pHelp, "0  4   3",
			 &(DateInfo->datim[3]), &Err);/* 3*/
    /* Hour */
    pHelp = FetchIntPara(pHelp, "0  4   4",
			 &(DateInfo->datim[4]), &Err);/* 4*/
    /* Minute */
    pHelp = FetchIntPara(pHelp, "0  4   5",
			 &(DateInfo->datim[5]), &Err);/* 5*/


      /* Some special treatment must be performed here 	         */
      /* The routine FetchIntPara expects to find the value      */
      /* before the keystring, but for '0 30  21' and '0 30  22'   */
      /* the keystring is found both before and after the value    */
      /* We must position after the first keystring before calling */
      /* FetchIntPara.                                           */

    pHelpBuf = strstr((char *) &HelpBuf, "0 30  21");

    if (NULL != pHelpBuf)
      {
      pHelp = pHelpBuf + strlen ("0 30  21");
    
      /* Number of pixels per row (= Number of columns) */
      pHelp = FetchIntPara(pHelp, "0 30  21",
			   &(AttrInfo->ntcols) , &Err); /* 19*/
      if (Err != 0)
	{	
	iRc = GetParFileValue(pParameterFileStr, 
			      "COLUMNS", 
			      GET_INT_TYPE, 
			      (INT32 *)&(AttrInfo->ntcols), 
			      &fDummyVal);
	if (iRc != OK)	
	  return  Err;
	Err = 0;
	}
      } /*     if (NULL != pHelpBuf) */
    else
      {	
      iRc = GetParFileValue(pParameterFileStr, 
			    "COLUMNS", 
			    GET_INT_TYPE, 
			    (INT32 *)&(AttrInfo->ntcols), 
			    &fDummyVal);
      if (iRc != OK)	
	return  Err;
      Err = 0;
      }
      

    pHelpBuf = strstr((char *) &HelpBuf, "0 30  22");

    if (NULL != pHelpBuf)
      {
      pHelp = pHelpBuf + strlen ("0 30  22");

      /* Number of pixels per column ( = Number of rows) */
      pHelp = FetchIntPara(pHelp, "0 30  22",
			   &(AttrInfo->ntlin) , &Err);  /* 20*/
      if (Err != 0)
	{	
	iRc = GetParFileValue(pParameterFileStr, 
			      "ROWS", 
			      GET_INT_TYPE, 
			      (INT32 *)&(AttrInfo->ntlin), 
			      &fDummyVal);
	if (iRc != OK)	
	  return  Err;
	Err = 0;
	}
      }
    else
      {	
      iRc = GetParFileValue(pParameterFileStr, 
			    "ROWS", 
			    GET_INT_TYPE, 
			    (INT32 *)&(AttrInfo->ntlin), 
			    &fDummyVal);
      if (iRc != OK)		
	return  Err;
      Err = 0;
      }


    pSaveBufPos = pHelp;

    /* Latitude */
/*    pHelp = FetchFloatPara(pHelp,"0  5   2",*/
/*			   &(AttrInfo->ilat1), &Err );*//* 6*/
    /* Longitude */
/*    pHelp = FetchFloatPara(pHelp,"0  6   2",*/
/*			   &(AttrInfo->ilat2), &Err );*//* 7*/

    iRc = GetParFileValue(pParameterFileStr, 
			  "LATNORTHEAST", 
			  GET_FLOAT_TYPE, 
			  (INT32 *)&iDummyVal, 
			  &(AttrInfo->ilat[2]));
    if (iRc != OK)	
      return  Err;

    iRc = GetParFileValue(pParameterFileStr, 
			  "LONGNORTHEAST", 
			  GET_FLOAT_TYPE, 
			  (INT32 *)&iDummyVal, 
			  &(AttrInfo->ilon[2]));
    if (iRc != OK)	
      return  Err;
    iRc = GetParFileValue(pParameterFileStr, 
			  "LATSOUTHWEST", 
			  GET_FLOAT_TYPE, 
			  (INT32 *)&iDummyVal, 
			  &(AttrInfo->ilat[4]));
    if (iRc != OK)	
      return  Err;
    iRc = GetParFileValue(pParameterFileStr, 
			  "LONGSOUTHWEST", 
			  GET_FLOAT_TYPE, 
			  (INT32 *)&iDummyVal, 
			  &(AttrInfo->ilon[4]));
    if (iRc != OK)		
      return  Err;

    
    /* Pixel size on horizontal -2 (used as resolution) */
    pHelp = FetchIntPara(pHelp, "0  6  33",
			 &(AttrInfo->isizev) , &Err); /* 18*/
    if (Err != 0)
      {	
      iRc = GetParFileValue(pParameterFileStr, 
			    "RESOLUTION", 
			    GET_INT_TYPE, 
			    (INT32 *)&(AttrInfo->isizev), 
			    &fDummyVal);
      if (iRc != OK)	
	return  Err;
      Err = 0;
      }

    /* Search for the reflectivity parameter (alfa) */

    pHelpBuf = strstr((char *) &HelpBuf, "0 25 202");
    if (NULL == pHelpBuf)
      {
      /* No reflectivity parameter found, this must be a  */
      /* four bit SRI product                             */
      /* Rainfall intensity */
      pHelp = FetchIntPara(pHelp, "0 21  36",
			   &(AttrInfo->ibotvl),&Err); /* 24*/
      /* Pixel value (4 bits) */
      pHelp = FetchIntPara(pHelp, "0 31   1",
			   &(AttrInfo->ntpixv),&Err); /* 25*/
      for (iIx= 1; iIx <= AttrInfo->ntpixv ; iIx++)
	{                 /* 26-41*/
	pHelp = FetchFloatPara(pHelp, "0 21  36", &HelpFloat, &Err );
	AttrInfo->itopvl[iIx]  = HelpFloat * 10;
	}
      /* I to R conversion factor */
      pHelp =FetchFloatPara(pHelp, "0 25   7",
			    &(AttrInfo->ifaczr),&Err);/* 43*/
      /* Z to R conversion exponent */
      pHelp =FetchFloatPara(pHelp, "0 25   8",
			    &(AttrInfo->iexpzr),&Err);/* 44*/
      }   /* if (NULL == pHelpBuf) */
    else
      {
      /* Some special treatment must be performed here 	         */
      /* The routine FetchFloatPara expects to find the value      */
      /* before the keystring, but for '0 25 202' and '0 25 203'   */
      /* (as well as 0 30  31)                                     */
      /* the keystring is found both before and after the value    */
      /* We must position after the first keystring before calling */
      /* FetchFloatPara.                                           */

      pHelp = pHelpBuf + strlen ("0 25 202");
      /* alfa */
      pHelp = FetchFloatPara(pHelp, "0 25 202",
			     &(AttrInfo->Ord),&Err);

      /* beta */
      pHelpBuf = strstr((char *) &HelpBuf, "0 25 203");
      pHelp = pHelpBuf + strlen ("0 25 203");

      pHelp = FetchFloatPara(pHelp, "0 25 203",
			     &(AttrInfo->Slope),&Err);
      }   /* else */	

    /* Picture type  */

    pHelpBuf = strstr((char *) &HelpBuf, "0 30  31");
    if (NULL == pHelpBuf)
      {
      iRc = GetParFileValue(pParameterFileStr, 
			    "PICTTYPE", 
			    GET_INT_TYPE, 
			    &(AttrInfo->iPictType), 
			    &fDummyVal);
      if (iRc != OK)	
	return iRc;
      }
    else
      {
      pHelp = pHelpBuf + strlen ("0 30  31");
      pHelp = FetchIntPara(pHelp, "0 30  31", &(AttrInfo->iPictType), &Err );
      if (Err != 0)
        {	
        iRc = GetParFileValue(pParameterFileStr, 
			      "PICTTYPE", 
			      GET_INT_TYPE, 
			      &(AttrInfo->iPictType), 
			      &fDummyVal);
        if (iRc != OK)	
	  return  Err;
        Err = 0;
        }
      }
    }

  fclose(ParFilep);

  return Err;
}

