/* **********************************************************************
 * *                                                                    *
 * *              Return Text Representing Data Type                    *
 * *                                                                    *
 * **********************************************************************
 * File: libs/user/DataNames.c
 *
 *  COPYRIGHT (c) 1992, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003,
 *                         2004, 2005, 2006 BY
 *             VAISALA INC., WESTFORD MASSACHUSETTS, U.S.A.
 * 
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED.
 */
#include <string.h>

#include "sigtypes.h"
#include "headers.h"
#include "iris_task.h"
#include "setup.h"
#include "uf.h"

#include "user_lib.h"
#include "dsp_lib.h"

/*===========================================================================
 */
char* sdata_name15( UINT4 idata_a )
{
  static char stext[16] ;

  switch( idata_a )
    {
    case DB_AXDIL2   : strncpy( stext, "Axis of Dill"   , sizeof(stext) ) ; break;
    case DB_DBT      :
    case DB_DBT2     : strncpy( stext, "Total Power"    , sizeof(stext) ) ; break;
    case DB_DBZ      :
    case DB_DBZ2     : strncpy( stext, "Reflectivity"   , sizeof(stext) ) ; break;
    case DB_DBZC     :
    case DB_DBZC2    : strncpy( stext, "dBZc"           , sizeof(stext) ) ; break;
    case DB_DEFORM2  : strncpy( stext, "Deformation"    , sizeof(stext) ) ; break;
    case DB_DIVERGE2 : strncpy( stext, "Divergence"     , sizeof(stext) ) ; break;
    case DB_FLIQUID2 : strncpy( stext, "Rain Accum"     , sizeof(stext) ) ; break;
    case DB_HDIR2    : strncpy( stext, "Wind Direction" , sizeof(stext) ) ; break;
    case DB_HEIGHT   : strncpy( stext, "Height"         , sizeof(stext) ) ; break;
    case DB_HCLASS   :
    case DB_HCLASS2  : strncpy( stext, "HydroClass"     , sizeof(stext) ) ; break;
    case DB_HVEL2    : strncpy( stext, "Wind Speed"     , sizeof(stext) ) ; break;
    case DB_KDP      :
    case DB_KDP2     : strncpy( stext, "Kdp Diff Phase" , sizeof(stext) ) ; break;
    case DB_LDRH     : 
    case DB_LDRH2    : strncpy( stext, "LDR Horizontal" , sizeof(stext) ) ; break;
    case DB_LDRV     : 
    case DB_LDRV2    : strncpy( stext, "LDR Vertical"   , sizeof(stext) ) ; break;
    case DB_NULL     : strncpy( stext, "Not Applicable" , sizeof(stext) ) ; break;
    case DB_ORAIN    : strncpy( stext, "ORainfall Rate" , sizeof(stext) ) ; break;
    case DB_OTHER    : strncpy( stext, "Other Data"     , sizeof(stext) ) ; break;
    case DB_PHIDP    :
    case DB_PHIDP2   : strncpy( stext, "PhiDp Dif Phase", sizeof(stext) ) ; break;
    case DB_PHIH     :
    case DB_PHIH2    : strncpy( stext, "Phi Horizontal" , sizeof(stext) ) ; break;
    case DB_PHIV     :
    case DB_PHIV2    : strncpy( stext, "Phi Vertical"   , sizeof(stext) ) ; break;
    case DB_RHOHV    : 
    case DB_RHOHV2   : strncpy( stext, "RhoHV CorelCoef", sizeof(stext) ) ; break;
    case DB_RHOH     : 
    case DB_RHOH2    : strncpy( stext, "Rho Horizontal" , sizeof(stext) ) ; break;
    case DB_RHOV     : 
    case DB_RHOV2    : strncpy( stext, "Rho Vertical"   , sizeof(stext) ) ; break;
    case DB_RAINRATE2: strncpy( stext, "Rainfall Rate"  , sizeof(stext) ) ; break;
    case DB_SHEAR    : strncpy( stext, "Wind Shear"     , sizeof(stext) ) ; break;
    case DB_SQI      : 
    case DB_SQI2     : strncpy( stext, "SQI"            , sizeof(stext) ) ; break;
    case DB_TIME2    : strncpy( stext, "Time"           , sizeof(stext) ) ; break;
    case DB_USER     :
    case DB_USER2    : strncpy( stext, "User Data"      , sizeof(stext) ) ; break;
    case DB_VEL      :
    case DB_VEL2     : strncpy( stext, "Mean Velocity"  , sizeof(stext) ) ; break;
    case DB_VELC     :
    case DB_VELC2    : strncpy( stext, "Corr Velocity"  , sizeof(stext) ) ; break;
    case DB_VIL2     : strncpy( stext, "VIL"            , sizeof(stext) ) ; break;
    case DB_VVEL2    : strncpy( stext, "Vert Velocity"  , sizeof(stext) ) ; break;
    case DB_WIDTH    :
    case DB_WIDTH2   : strncpy( stext, "Spectrum Width" , sizeof(stext) ) ; break;
    case DB_XHDR     : strncpy( stext, "Extended Header", sizeof(stext) ) ; break;
    case DB_ZDR      :
    case DB_ZDR2     : strncpy( stext, "Diff Refl"      , sizeof(stext) ) ; break;
    case DB_ZDRC     :
    case DB_ZDRC2    : strncpy( stext, "ZDRc"           , sizeof(stext) ) ; break;
    case DB_FLAGS:
    case DB_FLAGS2   : strncpy( stext, "Bin Flags"      , sizeof(stext) ) ; break;
    default:           strncpy( stext, "Unknown data"   , sizeof(stext) ) ; break;
    }
  return &stext[0] ;
}

/*===========================================================================
 */
char *sDataName3( UINT4 idata_a )    
{
  static char stext[4] ;

  switch( idata_a )
    {
    case DB_AXDIL2   : strncpy( stext, "Ax",  sizeof(stext) ) ; break;
    case DB_DBT      :
    case DB_DBT2     : strncpy( stext, "T",   sizeof(stext) ) ; break;
    case DB_DBZ      :
    case DB_DBZ2     : strncpy( stext, "Z",   sizeof(stext) ) ; break;
    case DB_DBZC     :
    case DB_DBZC2    : strncpy( stext, "Zc",  sizeof(stext) ) ; break;
    case DB_DEFORM2  : strncpy( stext, "Def", sizeof(stext) ) ; break;
    case DB_DIVERGE2 : strncpy( stext, "Div", sizeof(stext) ) ; break;
    case DB_FLIQUID2 : strncpy( stext, "Lq",  sizeof(stext) ) ; break;
    case DB_HDIR2    : strncpy( stext, "Dir", sizeof(stext) ) ; break;
    case DB_HEIGHT   : strncpy( stext, "Ht",  sizeof(stext) ) ; break;
    case DB_HCLASS   :
    case DB_HCLASS2  : strncpy( stext, "HCl", sizeof(stext) ) ; break;
    case DB_HVEL2    : strncpy( stext, "Spd", sizeof(stext) ) ; break;
    case DB_KDP      :
    case DB_KDP2     : strncpy( stext, "Kdp", sizeof(stext) ) ; break;
    case DB_LDRH     :
    case DB_LDRH2    : strncpy( stext, "LDH", sizeof(stext) ) ; break;
    case DB_LDRV     :
    case DB_LDRV2    : strncpy( stext, "LDV", sizeof(stext) ) ; break;
    case DB_NULL     : strncpy( stext, "NA",  sizeof(stext) ) ; break;
    case DB_ORAIN    : strncpy( stext, "OR",  sizeof(stext) ) ; break;
    case DB_OTHER    : strncpy( stext, "Ot",  sizeof(stext) ) ; break;
    case DB_PHIDP    :
    case DB_PHIDP2   : strncpy( stext, "PDP", sizeof(stext) ) ; break;
    case DB_PHIH     :
    case DB_PHIH2    : strncpy( stext, "PhH", sizeof(stext) ) ; break;
    case DB_PHIV     :
    case DB_PHIV2    : strncpy( stext, "PhV", sizeof(stext) ) ; break;
    case DB_RHOHV    :
    case DB_RHOHV2   : strncpy( stext, "RHV", sizeof(stext) ) ; break;
    case DB_RHOH     :
    case DB_RHOH2    : strncpy( stext, "RhH", sizeof(stext) ) ; break;
    case DB_RHOV     :
    case DB_RHOV2    : strncpy( stext, "RhV", sizeof(stext) ) ; break;
    case DB_RAINRATE2: strncpy( stext, "R",   sizeof(stext) ) ; break;
    case DB_SHEAR    : strncpy( stext, "Sh",  sizeof(stext) ) ; break;
    case DB_SQI      :
    case DB_SQI2     : strncpy( stext, "SQI", sizeof(stext) ) ; break;
    case DB_TIME2    : strncpy( stext, "Tm",  sizeof(stext) ) ; break;
    case DB_USER     :
    case DB_USER2    : strncpy( stext, "Us",  sizeof(stext) ) ; break;
    case DB_VEL      :
    case DB_VEL2     : strncpy( stext, "V",   sizeof(stext) ) ; break;
    case DB_VELC     :
    case DB_VELC2    : strncpy( stext, "Vc",  sizeof(stext) ) ; break;
    case DB_VIL2     : strncpy( stext, "Vil", sizeof(stext) ) ; break;
    case DB_VVEL2    : strncpy( stext, "VV",  sizeof(stext) ) ; break;
    case DB_WIDTH    :
    case DB_WIDTH2   : strncpy( stext, "W",   sizeof(stext) ) ; break;
    case DB_XHDR     : strncpy( stext, "XH",  sizeof(stext) ) ; break;
    case DB_ZDR      :
    case DB_ZDR2     : strncpy( stext, "ZDR", sizeof(stext) ) ; break;
    case DB_ZDRC     :
    case DB_ZDRC2    : strncpy( stext, "DRc", sizeof(stext) ) ; break;
    case DB_FLAGS:
    case DB_FLAGS2   : strncpy( stext, "FLG", sizeof(stext) ) ; break;
    default:           strncpy( stext, "XXX", sizeof(stext) ) ; break;
    }
  return &stext[0] ;
}

/*===========================================================================
 * Generate 6 character data type name.  These can be used for file names, so
 * do not use characters which cause searching confusion, like: "/", "*",
 * "?", or leading ".".
 */
char *sdata_name6( UINT4 idata_a )    
{
  static char stext[7] ;

  switch( idata_a )
    {
    case DB_AXDIL2   : strncpy( stext, "Axis"  , sizeof(stext) ) ; break;
    case DB_DBT      : strncpy( stext, "dBT"   , sizeof(stext) ) ; break;
    case DB_DBT2     : strncpy( stext, "dBT2"  , sizeof(stext) ) ; break;
    case DB_DBZC     : strncpy( stext, "dBZc"  , sizeof(stext) ) ; break;
    case DB_DBZC2    : strncpy( stext, "dBZc2" , sizeof(stext) ) ; break;
    case DB_DBZ      : strncpy( stext, "dBZ"   , sizeof(stext) ) ; break;
    case DB_DBZ2     : strncpy( stext, "dBZ2"  , sizeof(stext) ) ; break;
    case DB_DEFORM2  : strncpy( stext, "Deform", sizeof(stext) ) ; break;
    case DB_DIVERGE2 : strncpy( stext, "Diverg", sizeof(stext) ) ; break;
    case DB_FLIQUID2 : strncpy( stext, "Rain"  , sizeof(stext) ) ; break;
    case DB_HDIR2    : strncpy( stext, "Direct", sizeof(stext) ) ; break;
    case DB_HEIGHT   : strncpy( stext, "Height", sizeof(stext) ) ; break;
    case DB_HCLASS   : strncpy( stext, "HClass", sizeof(stext) ) ; break;
    case DB_HCLASS2  : strncpy( stext, "HCl2"  , sizeof(stext) ) ; break;
    case DB_HVEL2    : strncpy( stext, "Speed" , sizeof(stext) ) ; break;
    case DB_KDP      : strncpy( stext, "Kdp"   , sizeof(stext) ) ; break;
    case DB_KDP2     : strncpy( stext, "Kdp2"  , sizeof(stext) ) ; break;
    case DB_LDRH     : strncpy( stext, "LDRH"  , sizeof(stext) ) ; break;
    case DB_LDRH2    : strncpy( stext, "LDRH2" , sizeof(stext) ) ; break;
    case DB_LDRV     : strncpy( stext, "LDRV"  , sizeof(stext) ) ; break;
    case DB_LDRV2    : strncpy( stext, "LDRV2" , sizeof(stext) ) ; break;
    case DB_NULL     : strncpy( stext, "Null"  , sizeof(stext) ) ; break;
    case DB_ORAIN    : strncpy( stext, "ORain" , sizeof(stext) ) ; break;
    case DB_OTHER    : strncpy( stext, "Other" , sizeof(stext) ) ; break;
    case DB_PHIDP    : strncpy( stext, "PhiDP" , sizeof(stext) ) ; break;
    case DB_PHIDP2   : strncpy( stext, "PhiDP2", sizeof(stext) ) ; break;
    case DB_PHIH     : strncpy( stext, "PhiH"  , sizeof(stext) ) ; break;
    case DB_PHIH2    : strncpy( stext, "PhiH2" , sizeof(stext) ) ; break;
    case DB_PHIV     : strncpy( stext, "PhiV"  , sizeof(stext) ) ; break;
    case DB_PHIV2    : strncpy( stext, "PhiV2" , sizeof(stext) ) ; break;
    case DB_RHOHV    : strncpy( stext, "RhoHV" , sizeof(stext) ) ; break;
    case DB_RHOHV2   : strncpy( stext, "RhoHV2", sizeof(stext) ) ; break;
    case DB_RHOH     : strncpy( stext, "RhoH"  , sizeof(stext) ) ; break;
    case DB_RHOH2    : strncpy( stext, "RhoH2" , sizeof(stext) ) ; break;
    case DB_RHOV     : strncpy( stext, "RhoV"  , sizeof(stext) ) ; break;
    case DB_RHOV2    : strncpy( stext, "RhoV2" , sizeof(stext) ) ; break;
    case DB_RAINRATE2: strncpy( stext, "R"     , sizeof(stext) ) ; break;
    case DB_SHEAR    : strncpy( stext, "Shear" , sizeof(stext) ) ; break;
    case DB_SQI      : strncpy( stext, "SQI"   , sizeof(stext) ) ; break;
    case DB_SQI2     : strncpy( stext, "SQI2"  , sizeof(stext) ) ; break;
    case DB_TIME2    : strncpy( stext, "Time"  , sizeof(stext) ) ; break;
    case DB_USER     : strncpy( stext, "User"  , sizeof(stext) ) ; break;
    case DB_USER2    : strncpy( stext, "User2" , sizeof(stext) ) ; break;
    case DB_VEL      : strncpy( stext, "V"     , sizeof(stext) ) ; break;
    case DB_VEL2     : strncpy( stext, "V2"    , sizeof(stext) ) ; break;
    case DB_VELC     : strncpy( stext, "Vc"    , sizeof(stext) ) ; break;
    case DB_VELC2    : strncpy( stext, "Vc2"   , sizeof(stext) ) ; break;
    case DB_VIL2     : strncpy( stext, "VIL"   , sizeof(stext) ) ; break;
    case DB_VVEL2    : strncpy( stext, "Vert_V", sizeof(stext) ) ; break;
    case DB_WIDTH    : strncpy( stext, "W"     , sizeof(stext) ) ; break;
    case DB_WIDTH2   : strncpy( stext, "W2"    , sizeof(stext) ) ; break;
    case DB_XHDR     : strncpy( stext, "Xhdr"  , sizeof(stext) ) ; break;
    case DB_ZDR      : strncpy( stext, "ZDR"   , sizeof(stext) ) ; break;
    case DB_ZDR2     : strncpy( stext, "ZDR2"  , sizeof(stext) ) ; break;
    case DB_ZDRC     : strncpy( stext, "ZDRc"  , sizeof(stext) ) ; break;
    case DB_ZDRC2    : strncpy( stext, "ZDRc2" , sizeof(stext) ) ; break;
    case DB_FLAGS    : strncpy( stext, "Flags" , sizeof(stext) ) ; break;
    case DB_FLAGS2   : strncpy( stext, "Flags2", sizeof(stext) ) ; break;
    default:           strncpy( stext, "XXXXXX", sizeof(stext) ) ; break;
    }
  return &stext[0] ;
}

/*===========================================================================
 * Convert a 6-character data type name to the numberical data type.
 * Returns -1 if it does not find a match.
 */
SINT2 iDataFromName6
( const char *sDataName6_a )    /* Null terminated name */
{
  SINT2 iData;

  for ( iData=0; iData<NUM_DEFINED_DATA; iData++)
    {
      if ( 0 == strcmp( sDataName6_a, sdata_name6(iData) )) return iData;
    }
  return -1;
}

/* ======================================================================
 * Generate 6-character data names, without size information
 */
char *sdata_name6_ns( UINT4 idtype_a )    
{
  UINT4 idtype, ires, ialt;

  idtype = idtype_a;
  ires = idata_resolution( idtype );
  if (ires!=8)
    {
      ialt = idata_alt_type( idtype );
      if (ialt != -1) idtype = ialt;
    }

  return sdata_name6( idtype );
}

/* ==========================================================================
 * This subroutine returns a text string describing the valid span of the data
 * parameter.  String includes a trailing null.
 */
char* sDataSpan12
( UINT2 idata_a,
  UINT4 iFlags_a )
{
  static char stext[13];
  switch( idata_a )
    {   
    case DB_DBT:
    case DB_DBT2:
    case DB_DBZ:  
    case DB_DBZ2:
    case DB_DBZC:
    case DB_DBZC2:    strncpy( stext, "-32 to 96"  , sizeof(stext) ); break;
    case DB_DEFORM2:  strncpy( stext, "0 to 32"    , sizeof(stext) ); break;
    case DB_DIVERGE2: strncpy( stext, "-32 to 32"  , sizeof(stext) ); break;
    case DB_FLIQUID2:
      if (iFlags_a & SCALE_RAIN_INCHES)
	strncpy( stext, "0 to 4000"  , sizeof(stext) );
      else
	strncpy( stext, "0 to 100000", sizeof(stext) );
      break;
    case DB_HEIGHT:
      if (iFlags_a & SCALE_HEIGHT_KFT)
	strncpy( stext, "0 to 83"   , sizeof(stext) );
      else
	strncpy( stext, "0 to 25.3"  , sizeof(stext) );
      break;
    case DB_HCLASS:
    case DB_HCLASS2: strncpy( stext, "Rain to Snow", sizeof(stext) ); break;
    case DB_KDP:
    case DB_KDP2:     strncpy( stext, "-50 to +50" , sizeof(stext) ); break;
    case DB_LDRH:
    case DB_LDRH2:
    case DB_LDRV:
    case DB_LDRV2:    strncpy( stext, "-45 to +5"  , sizeof(stext) ); break;
    case DB_ORAIN:    strncpy( stext, "0 to 25"    , sizeof(stext) ); break;
    case DB_OTHER:    strncpy( stext, ""           , sizeof(stext) ); break;
    case DB_PHIH:
    case DB_PHIH2:
    case DB_PHIV:
    case DB_PHIV2:
    case DB_PHIDP:
    case DB_PHIDP2:   strncpy( stext, "0 to 180"   , sizeof(stext) ); break;
    case DB_RAINRATE2:
      if (iFlags_a & SCALE_RAINRATE_IN_HOUR)
	strncpy( stext, "0 to 400"   , sizeof(stext) );
      else
      	strncpy( stext, "0 to 10000" , sizeof(stext) );
      break;
    case DB_RHOH:
    case DB_RHOH2:
    case DB_RHOV:
    case DB_RHOV2:
    case DB_RHOHV:
    case DB_RHOHV2:
    case DB_SQI: 
    case DB_SQI2:     strncpy( stext, "0 to 1"     , sizeof(stext) ); break;
    case DB_SHEAR:    strncpy( stext, "+- 25"      , sizeof(stext) ); break;
    case DB_TIME2:    strncpy( stext, "0 to 720"   , sizeof(stext) ); break;
    case DB_USER:     strncpy( stext, "1 to 254"   , sizeof(stext) ); break;
    case DB_USER2:    strncpy( stext, "1 to 65534" , sizeof(stext) ); break;
    case DB_VEL2:
    case DB_VEL:      strncpy( stext, "+- Vu"      , sizeof(stext) ); break;
    case DB_VELC:     strncpy( stext, "-75 to 75"  , sizeof(stext) ); break;
    case DB_VIL2:     strncpy( stext, "0 to 65"    , sizeof(stext) ); break;
    case DB_VVEL2:    strncpy( stext, "-327 to 327", sizeof(stext) ); break;
    case DB_WIDTH2:
    case DB_WIDTH:    strncpy( stext, "0 to Vu"    , sizeof(stext) ); break;
    case DB_ZDR2:
    case DB_ZDR:
    case DB_ZDRC2:
    case DB_ZDRC:     strncpy( stext, "-8 to +8"   , sizeof(stext) ); break;
    case DB_FLAGS:    strncpy( stext, "0 to 255"   , sizeof(stext) ); break;
    case DB_FLAGS2:   strncpy( stext, "0 to 65535" , sizeof(stext) ); break;
    case DB_NULL:
    default:          strncpy( stext, "???"        , sizeof(stext) ); break;
    };
  return &stext[0];
}

/*============================================================================
 * This subroutine returns a text string describing the units used for the
 * data type.
 */
char* sdata_units6
( UINT2 idata_a,
  UINT4 iFlags_a )
{
  static char stext[7];
  switch( idata_a )
    {
    case DB_HDIR2:
    case DB_AXDIL2:   strncpy( stext, "deg"   , sizeof(stext) ); break;
    case DB_DBT2:
    case DB_DBT:
    case DB_DBZ2:
    case DB_DBZ:
    case DB_DBZC:
    case DB_DBZC2:     strncpy( stext, "dBZ"   , sizeof(stext) ); break;
    case DB_DEFORM2:
    case DB_DIVERGE2: strncpy( stext, "10**-4", sizeof(stext) ); break;
    case DB_FLIQUID2:
      if (iFlags_a & SCALE_RAIN_INCHES)
	strncpy( stext, "inches", sizeof(stext) );
      else
	strncpy( stext, "mm"    , sizeof(stext) );
      break;
    case DB_HEIGHT:
      if (iFlags_a & SCALE_HEIGHT_KFT)
	strncpy( stext, "kft"   , sizeof(stext) );
      else
	strncpy( stext, "km"    , sizeof(stext) );
      break;
    case DB_HCLASS:
    case DB_HCLASS2:  strncpy( stext, "types", sizeof(stext) ); break;
    case DB_KDP:
    case DB_KDP2:     strncpy( stext, "deg/km", sizeof(stext) ); break;
    case DB_LDRH:
    case DB_LDRH2:
    case DB_LDRV:
    case DB_LDRV2:    strncpy( stext, "dB"    , sizeof(stext) ); break;
    case DB_PHIDP:
    case DB_PHIDP2:
    case DB_PHIH:
    case DB_PHIH2: 
    case DB_PHIV:
    case DB_PHIV2:    strncpy( stext, "deg"   , sizeof(stext) ); break;
    case DB_RAINRATE2:
      if (iFlags_a & SCALE_RAINRATE_IN_HOUR)
	strncpy( stext, "in/hr" , sizeof(stext) );
      else
	strncpy( stext, "mm/hr" , sizeof(stext) );
      break;
    case DB_SHEAR:    strncpy( stext, "m/s/km", sizeof(stext) ); break;
    case DB_RHOH:
    case DB_RHOH2:
    case DB_RHOV:
    case DB_RHOV2:
    case DB_RHOHV:
    case DB_RHOHV2:
    case DB_SQI:
    case DB_SQI2:     strncpy( stext, ""      , sizeof(stext) ); break;
    case DB_TIME2:    strncpy( stext, "min"   , sizeof(stext) ); break;
    case DB_USER:
    case DB_USER2:     strncpy( stext, "N/A"   , sizeof(stext) ); break;
    case DB_HVEL2:
    case DB_VVEL2:
    case DB_VEL:
    case DB_VEL2:
    case DB_VELC:
    case DB_VELC2:    strncpy( stext, "m/s"   , sizeof(stext) ); break;
    case DB_VIL2:     strncpy( stext, "mm"    , sizeof(stext) ); break;
    case DB_WIDTH2:
    case DB_WIDTH:    strncpy( stext, "m/s"   , sizeof(stext) ); break;
    case DB_XHDR:     strncpy( stext, "Xhdr"  , sizeof(stext) ); break;
    case DB_ZDR2:
    case DB_ZDR:
    case DB_ZDRC2:
    case DB_ZDRC:     strncpy( stext, "dB"    , sizeof(stext) ); break;
    case DB_FLAGS2:
    case DB_FLAGS:    strncpy( stext, "Bit"   , sizeof(stext) ); break;
    case DB_NULL:
    default:          strncpy( stext, "???"   , sizeof(stext) ); break;
  }
  return &stext[0];
}      

/* ======================================================================
 * This routine returns the antenna scan type in ten characters.
 */
char *scan_name10( UINT2 iscan_a )
{
  static char stext[11];

  switch( iscan_a )
    {
    case TASK_SCAN_PPI:    strncpy( stext, "PPI Sector", sizeof(stext) ); break;
    case TASK_SCAN_RHI:    strncpy( stext, "RHI",        sizeof(stext) ); break;
    case TASK_SCAN_MANUAL: strncpy( stext, "Manual",     sizeof(stext) ); break;
    case TASK_SCAN_CONT:   strncpy( stext, "PPI Full",   sizeof(stext) ); break;
    case TASK_SCAN_EXEC:   strncpy( stext, "Exec",       sizeof(stext) ); break;
    case TASK_SCAN_FILE:   strncpy( stext, "File",       sizeof(stext) ); break;
    default:          strncpy( stext, "None",       sizeof(stext) ); break;
    }
  stext[sizeof(stext)-1] = 0;
  return stext;
}
/* ================================================================
 * Get the UF format's name for the data type
 */
char *sUfName2FromData
( char sText_a[3],                    /* Uf string stored here */
  UINT1 idata_a,                      /* IRIS data type here */
  const struct uf_data_map Map_a[] )  /* Optional mapping override table */
{
  /* Check mapping table first if it exists */
  if (Map_a)
    {
      int iIndex=0;
      /* Mapping table array is variable length, it ends on the first missing string */
      while( Map_a[iIndex].sUfDataType[0] )
	{
	  if (Map_a[iIndex].iIrisDataType == idata_a)
	    {
	      strncpy( sText_a, Map_a[iIndex].sUfDataType, 2 ) ;
	      sText_a[2]=0;
	      return sText_a;
	    }
	  iIndex++;
	}
    }

  /* Now use compiled in defaults */
  switch( idata_a )
    {
    case DB_DBT      :
    case DB_DBT2     : strcpy( sText_a, "ZT" ) ; break;
    case DB_DBZ      :
    case DB_DBZ2     : strcpy( sText_a, "DZ" ) ; break;
    case DB_DBZC     :
    case DB_DBZC2    : strcpy( sText_a, "CZ" ) ; break;
    case DB_KDP      :
    case DB_KDP2     : strcpy( sText_a, "KD" ) ; break;
    case DB_LDRH     : 
    case DB_LDRH2    : strcpy( sText_a, "LH" ) ; break;
    case DB_LDRV     : 
    case DB_LDRV2    : strcpy( sText_a, "LV" ) ; break;
    case DB_PHIDP    :
    case DB_PHIDP2   : strcpy( sText_a, "PH" ) ; break;
    case DB_RHOHV    :
    case DB_RHOHV2   : strcpy( sText_a, "RH" ) ; break;
    case DB_SQI      :
    case DB_SQI2     : strcpy( sText_a, "SQ" ) ; break;
    case DB_VEL      :
    case DB_VEL2     :
    case DB_VELC     :
    case DB_VELC2    : strcpy( sText_a, "VR" ) ; break;
    case DB_WIDTH    :
    case DB_WIDTH2   : strcpy( sText_a, "SW" ) ; break;
    case DB_ZDR      :
    case DB_ZDR2     :
    case DB_ZDRC     :
    case DB_ZDRC2    : strcpy( sText_a, "DR" ) ; break;

    case DB_AXDIL2   :
    case DB_DEFORM2  :
    case DB_DIVERGE2 :
    case DB_FLIQUID2 :
    case DB_HDIR2    :
    case DB_HCLASS   :
    case DB_HCLASS2   :
    case DB_HEIGHT   :
    case DB_HVEL2    :
    case DB_NULL     :
    case DB_ORAIN    :
    case DB_OTHER    :
    case DB_PHIH     :
    case DB_PHIH2    :
    case DB_PHIV     :
    case DB_PHIV2    :
    case DB_RAINRATE2:
    case DB_RHOH     : 
    case DB_RHOH2    :
    case DB_RHOV     : 
    case DB_RHOV2    :
    case DB_SHEAR    :
    case DB_TIME2    : 
    case DB_USER     :
    case DB_VIL2     :
    case DB_VVEL2    :
    case DB_XHDR     :
    case DB_FLAGS    :
    case DB_FLAGS2   :
    default:           strcpy( sText_a, "??" ) ; break;
    }
  return sText_a;
}
/* ================================================================
 * Get the UF format's name for the data type
 */
UINT1 iDataFromUfName2
( const char *sName2_a,               /* Uf string passed here, only 2 chars examined */
  const struct uf_data_map Map_a[] )  /* Optional mapping override table */
{

  /* This is not just a reverse calling of sUfName2FromData because we
   * may want to map two different strings into the same data type.
   */

  /* Check mapping table first if it exists */
  if (Map_a)
    {
      int iIndex=0;
      /* Mapping table array is variable length, it ends on the first missing string */
      while( Map_a[iIndex].sUfDataType[0] )
	{
	  if ( 0 == strncmp( sName2_a, Map_a[iIndex].sUfDataType, 2))
	    return Map_a[iIndex].iIrisDataType;
	  iIndex++;
	}
    }

  /* Now use compiled in defaults */
  if      ( 0 == strncmp( sName2_a, "CZ", 2))
    return DB_DBZC;
  else if ( 0 == strncmp( sName2_a, "DZ", 2))
    return DB_DBZ;
  else if ( 0 == strncmp( sName2_a, "DR", 2))
    return DB_ZDR;
  else if ( 0 == strncmp( sName2_a, "KD", 2))
    return DB_KDP;
  else if ( 0 == strncmp( sName2_a, "LH", 2))
    return DB_LDRH;
  else if ( 0 == strncmp( sName2_a, "LV", 2))
    return DB_LDRV;
  else if ( 0 == strncmp( sName2_a, "PH", 2))
    return DB_PHIDP;
  else if ( 0 == strncmp( sName2_a, "RH", 2))
    return DB_RHOHV;
  else if ( 0 == strncmp( sName2_a, "SQ", 2))
    return DB_SQI;
  else if ( 0 == strncmp( sName2_a, "SW", 2))
    return DB_WIDTH;
  else if ( 0 == strncmp( sName2_a, "ZT", 2))
    return DB_DBT;
  else if ( 0 == strncmp( sName2_a, "VR", 2))
    return DB_VEL;
  else
    return DB_NULL;
}
