From 207daf69fd7a40b40397522dca8c48fdc9ad8a7d Mon Sep 17 00:00:00 2001
From: Elena.Budnik <ebudnik@irap.omp.eu>
Date: Thu, 24 Oct 2019 20:02:48 +0200
Subject: [PATCH] exclude obsolete cdf2nc

---
 CMakeLists.txt.All                               |    6 ++++--
 src/DECODERS/cdf2nc/CMakeLists.txt               |   26 --------------------------
 src/DECODERS/cdf2nc/cdf2nc.c                     | 1616 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 src/DECODERS/cdf2nc/cdf_to_netcdf_mapping.dat    |   12 ------------
 src/DECODERS/cdfnew2nc/cdf_to_netcdf_mapping.dat |   12 ++++++++++++
 5 files changed, 16 insertions(+), 1656 deletions(-)
 delete mode 100644 src/DECODERS/cdf2nc/CMakeLists.txt
 delete mode 100755 src/DECODERS/cdf2nc/cdf2nc.c
 delete mode 100644 src/DECODERS/cdf2nc/cdf_to_netcdf_mapping.dat
 create mode 100644 src/DECODERS/cdfnew2nc/cdf_to_netcdf_mapping.dat

diff --git a/CMakeLists.txt.All b/CMakeLists.txt.All
index 1afdba3..93e625d 100644
--- a/CMakeLists.txt.All
+++ b/CMakeLists.txt.All
@@ -28,6 +28,9 @@ endif()
 
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
 
+# Fedora30
+# include_directories( AFTER "/usr/include/tirpc" )
+
 find_package( Threads REQUIRED )
 find_package( CRYPT REQUIRED )
 find_package( NetCDF REQUIRED )
@@ -62,7 +65,6 @@ configure_file (
 MESSAGE( STATUS "Build DD_Server Project" )
 add_subdirectory(src/SERVER)
 add_subdirectory(src/DECODERS/ascii2nc)
-add_subdirectory(src/DECODERS/cdf2nc)
 add_subdirectory(src/DECODERS/cdfnew2nc)
 add_subdirectory(src/DECODERS/nc2nc)
 add_subdirectory(src/DECODERS/themis)
@@ -84,7 +86,7 @@ install(DIRECTORY "src/DDADMIN/MANAGER/" DESTINATION bin/USERMANAGER)
 install(DIRECTORY "src/DDSERVICES/SOAP/" DESTINATION DDService)
 install(DIRECTORY "src/DDSERVICES/REST/" DESTINATION DDService)
 
-install(FILES "src/DECODERS/cdf2nc/cdf_to_netcdf_mapping.dat" DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE  GROUP_READ  WORLD_READ) 
+install(FILES "src/DECODERS/cdfnew2nc/cdf_to_netcdf_mapping.dat" DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE  GROUP_READ  WORLD_READ) 
 
 file(GLOB config_files "info/REMOTEDATA/*.xml")
 install(FILES ${config_files} DESTINATION ${DDBASEINFO} PERMISSIONS OWNER_READ OWNER_WRITE  GROUP_READ WORLD_READ)
diff --git a/src/DECODERS/cdf2nc/CMakeLists.txt b/src/DECODERS/cdf2nc/CMakeLists.txt
deleted file mode 100644
index 199beaf..0000000
--- a/src/DECODERS/cdf2nc/CMakeLists.txt
+++ /dev/null
@@ -1,26 +0,0 @@
-
-PROJECT(cdf2nc)
-
-include_directories(
-  ${DDCLIENTINCLUDE_DIR}
-  ${NETCDFINCLUDE_DIR}
-  ${libcdf_INCLUDE_DIR}
-)
-
-#Configuration de l'exécutable
-file(
-        GLOB_RECURSE
-        source_files
-        ./*
-)
-  
-ADD_EXECUTABLE (cdf2nc ${source_files} )
-
-target_link_libraries(
-  cdf2nc
-  ${DDCLIENTLIBRARY}
-  ${NETCDFLIBRARY}
-  ${libcdf_LIBRARIES}
-)
-
-install (TARGETS cdf2nc DESTINATION bin)
diff --git a/src/DECODERS/cdf2nc/cdf2nc.c b/src/DECODERS/cdf2nc/cdf2nc.c
deleted file mode 100755
index 3deb3b3..0000000
--- a/src/DECODERS/cdf2nc/cdf2nc.c
+++ /dev/null
@@ -1,1616 +0,0 @@
-/**
-*  @file cdf2nc.c
-*  @version $Id: cdf2nc.c,v 1.7 2014/06/25 10:32:50 budnik Exp $
-*  @brief DD Server Decoder 
-*/
-
-/*=====================================================================
- *                     cdf2nc.c
- *                       V.1.2
- *  CDF to NetCDF converter
- *  usage: cdf2nc <FILE NAME>.cdf
- *
- *  Versions:
- *  Aug 4, 2007, V.1.0, Knizhnikova-Fedorova
- *  Aug 6, 2007, V.1.1, Fedorov, "Time" dimension
- *  Jan 16, 2008 V.1.2  Exclude "false" CDF dimension (1)
- *=====================================================================*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <netcdf.h>
-#include <cdf.h>
-#include <string.h>
-#include <time.h>
-#include <math.h>
-#include <DD.h>
- 
-#define MAX_FILE_NAME_LEN  120      /* Max. file name length              */
-#define MAX_ATTRS          3000     /* Max # of CDF attributes            */
-#define UNKNOWN_DT         -99      /* Unsupported CDF datatype indicator */
-
-#define DEFAULT_MAPPING_FILE   "cdf_to_netcdf_mapping.dat"
-#define MAX_REC_LENGTH         NC_MAX_NAME+CDF_ATTR_NAME_LEN+2
-                                 /* Max record length of DEFAULT_MAPPING_FILE */
-
-#define TRUE               1
-#define FALSE              0
-
-#define TIMESHIFT  62167219200.0  /*01/01/1970 - 01/01/0000  Gregorian Calendar*/
-#define UNLIMITDIM "Time"         /* Name of unlimided dimension */
-#define DD_TIME_STRING_LEN      17
-
-/*************************************
-   Global variables and structures
-**************************************/
-CDFid    id;        /* CDF file ID      */ 
-int      ncid;      /* netCDF file ID   */
-
-short isTimeSet = 0;
-
-long nZvars,        /* Number of zVariables in a CDF file                     */
-     nAttrs;        /* Number of attributes (global & variable) in a CDF file */
-
-typedef struct ncdim {          /* netCDF dimension structure */
-    char name[NC_MAX_NAME+1];           /* Dimension name */
-    int  size;                          /* Dimension size */
-    int  id;                            /* Dimension id   */
-} netcdfDimension;
-
-netcdfDimension ncDims[NC_MAX_DIMS];       /* max dimensions per netCDF file */
-int  totNCdims = 0;         /* Total # of netCDF dimensions created          */
-
-int StartTimeID, StopTimeID, TimeLengthID;
- 
-char StartT[TIMELENGTH]; // Start time  
-char StopT[TIMELENGTH];  // Stop time  
-
-dd_time_t StartTime, StopTime;
-
-typedef struct cdfvar {           /* CDF variable structure */
-     char name[CDF_VAR_NAME_LEN+1];   
-     long datatype;                   
-     long numElements;            /* string length for CDF_CHAR, 1 otherwise */
-     long dimensionality;             /* variable dimensionality             */
-     long dimSizes[CDF_MAX_DIMS];     /* variable dimension sizes            */
-     long recVariance;                /* record variance                     */
-     long numRecs;                    /* # of records this variable contains */
-} CDFvar;
-
-char SpecialSymbol[9] = {' ', '#', '%', '@', '+', '.', '>', '<', '/'};
-
-/****************************************************************************
- *   Arrays to hold the CDF-to-netCDF mapping information that are loaded
- *   from the default or user-define mapping file.
- ****************************************************************************/
-char netcdfAttrNames[MAX_ATTRS][NC_MAX_NAME];
-char cdfAttrNames[MAX_ATTRS][CDF_ATTR_NAME_LEN+1];
-char comments[MAX_ATTRS][CDF_ATTR_NAME_LEN+1];
-
-int  totAttrsInMappingFile;           /* # of attributes in the mapping file */
-char mappingFile[MAX_FILE_NAME_LEN];  /* Mapping file name                   */
-
-int DEBUG = FALSE;
-
-
-/**************************
-   Function prototypes
-**************************/
-int endsWith(char *, char *);
-char * strlaststr(char *, char *);
-void get_cdf_attribute(long, long, long, int);
-void get_cdf_attr_data(char *, long, long, long, int);
-char * cdf_str_datatype (long);
-char * NC_datatype (nc_type);
-nc_type get_netcdf_datatype (long);
-void usage();
-CDFid cdf_open(char *);
-void read_cdf_file_info();
-void get_zVariables();
-void create_netcdf_dimensions (CDFvar, int *, int *);
-int create_netcdf_variable (CDFvar, int, short *);
-void get_cdf_variable_data (long, CDFvar);
-void read_cdf_variable_data (long, long, long, long, long [], void *);
-void removeFilepath();
-void handle_netcdf_error (int);
-void memory_error(char *, char *);
-void cdf_status_handler (CDFstatus, char *);
-void insufficient_memory();    /* used for debug */
-char * getNextArgument (int, char *[], int);
-void parseCmdLine (int, char *[]);
-void errorMsg (char *);
-void map_CDF_attr_to_netCDF (char *, char *);
-char *  isotime_to_dd_time (char * str_isotime);
-
-/**************************************************************************** 
-   NOTE:
-
-   CDF has the following features that are not supported by netCDF:
-
-   - CDF_EPOCH datatype (8-byte real number) that is used to store time 
-     values referenced from a particular epoch that is 
-     01-Jan-0000 00:00:00.000.  CDF_EPOCH values are the number of 
-     milliseconds since the epoch described above.
-
-   - CDF_EPOCH16 datatype (16-byte real number) that is used to store time 
-     values referenced from a particular epoch that is 
-     01-Jan-0000 00:00:00.000.000.000.000.  CDF_EPOCH16 values are the 
-     number of milliseconds since the epoch described above.
-
-   - CDF global attribute (not variable attribute) can have multiple
-     attribute entries and each entry can have a different datatype.
-*****************************************************************************/
-int main(int argc, char *argv[])
-{
-    FILE  *inFile;             /* Pointer to the CDF-to-netCDF mapping file */
-    char  rec[MAX_REC_LENGTH];     /* CDF-to-netCDF mapping record */
-
-    /************************/
-    /*  netCDF declaration  */
-    /************************/
-    int  status,                  /* netCDF status code */
-         dummy, i; 
-
-    char *ptr, fileName[MAX_FILE_NAME_LEN];
-
-    /**********************/
-    /*  CDF declaration   */
-    /**********************/
-    CDFstatus   cstatus;           /* CDF status code */
-    long        attrId;            /* CDF attribute ID */
-
-    if (argc <= 1) 
-        usage();                   /* CDF input file name not specified */
-    else {
-        strcpy(fileName, argv[argc-1]);       /* Get the input file name */
-        strcpy(mappingFile, "UNSPECIFIED");
-        parseCmdLine(argc, argv);
-        if (strcmp(mappingFile, fileName) == 0)
-            errorMsg("** Error - either input file or mapping file is missing");
-        if (strcmp(mappingFile,"UNSPECIFIED") == 0)
-        {
-           strcpy(mappingFile,getenv("DDLIB"));
-           strcat(mappingFile, DEFAULT_MAPPING_FILE);
-        }
-    }
-
-    /***********************************************/
-    /*  Load the CDF-to-netCDF mapping information */
-    /***********************************************/
-    if ((inFile = fopen(mappingFile, "r")) == NULL) {
-         printf ("**  Cannot open file: %s  **\n", mappingFile);
-        exit (1);
-    }
-
-    totAttrsInMappingFile = 0;
-    while (fgets(rec, MAX_REC_LENGTH, inFile) != NULL) {
-        rec[strlen(rec)-1] = '\0';       /* Remove the newline character */
-
-        /* Process the mapping record if it's not a comment */
-        if (rec[0] != '#'  &&  rec[0] != ' ' && strlen(rec) > 0) {
-            sscanf(rec, "%s %s",
-                   netcdfAttrNames[totAttrsInMappingFile],
-                   cdfAttrNames[totAttrsInMappingFile]);
-            ptr = (char *) strstr(rec, "//");
-            if (ptr != NULL) {
-                ptr += 3;
-                strcpy (comments[totAttrsInMappingFile], ptr);
-
-            }
-            if (DEBUG)
-                printf("%s %s %s\n",
-                       netcdfAttrNames[totAttrsInMappingFile],
-                       cdfAttrNames[totAttrsInMappingFile],
-                       comments[totAttrsInMappingFile]);
-            totAttrsInMappingFile++;
-        }
-    }
-
-    /***********************************************************
-     *  Process the CDF information and create a netCDF file
-     ***********************************************************/
-  //  printf ("\nInput file name: %s\n", fileName);
-    id = cdf_open (fileName);
-
-    /* Remove the file path if it exists (/home/mydata.cdf => mydata.cdf). */
-    removeFilepath(fileName);
-
-    if (endsWith(fileName,".cdf")) {
-        /* Strip off the .cdf file extension. */
-        ptr = (char *) strlaststr(fileName, ".cdf");
-        if (ptr != NULL) *ptr = '\0'; 
-    }
-    strcat(fileName, ".nc");
-    status = nc_create(fileName, NC_CLOBBER, &ncid);
-    if (status != NC_NOERR) handle_netcdf_error(status);
-  //  printf ("Output file name: %s\n", fileName);
-
-    /***********************************************************************
-     * Get the number of dimensions, number of variables, number of global
-     * attributes.
-     *
-     * Note that the information retrieved from read_cdf_file_info are stored
-     * into the global variables defined at the top.
-     ***********************************************************************/
-    read_cdf_file_info ();
-    if (DEBUG) printf ("nAttrs=%d, nZvars=%d\n", nAttrs, nZvars);
-
-    /* Get the CDF global attributes and create netCDF global attributes. */
-    if (DEBUG) printf ("Global attributes:\n");
-    dummy = -1; 
-    for (attrId = 0; attrId < nAttrs; attrId++) 
-         get_cdf_attribute(attrId, GLOBAL_SCOPE, (long) dummy, dummy);
-
-    /* Write the placeholder attributes. */
-    for (i=0; i < totAttrsInMappingFile; i++) {
-        if (strcmp(cdfAttrNames[i],"*") == 0) {
-           status = nc_put_att_text (ncid, 
-                                     NC_GLOBAL,           /* vavriable ID */
-                                     netcdfAttrNames[i],  /* Attribute name */
-                                     strlen(comments[i]), /* # of attr values */
-                                     comments[i]);                            
-         }
-    }
-
-    /* Process CDF variables and create netCDF variables */
-    if (nZvars > 0) get_zVariables();
-
-    /* Close the netCDF and CDF files */
-    cstatus = CDFlib (CLOSE_, CDF_, NULL_);
-    if (cstatus != CDF_OK) cdf_status_handler (cstatus, "CLOSE_, CDF_");
-
-    status = nc_close(ncid);
-    if (status != NC_NOERR) handle_netcdf_error(status);
-}
-
-
-/*----------------------------------------------------------------------------
- *  TRUE if s1 ends with s2.  Otherwise, FALSE is returned.
- *---------------------------------------------------------------------------*/
-int endsWith (char *s1, char *s2)
-{ 
-    int  i;
-    char *ps1, *ps2;
-
-    if (strlen(s2) > strlen(s1))
-        return FALSE;
-
-    ps1 = s1 + strlen(s1) - strlen(s2); 
-    ps2 = s2;
-
-    for (i=0; i < strlen(s2); i++) 
-        if (*(ps1++) != *(ps2++))
-            return FALSE;
-     
-    return TRUE;
-}
-
-
-/*---------------------------------------------------------------------------------
- *  Find the last occurence of s2 in s1.  If s21 is not found, s1 is returned. 
- *--------------------------------------------------------------------------------*/
-char * strlaststr (char *s1, char *s2)
-{
-    char *sc2, *psc1, *ps1;
-
-    if (*s2 == '\0')
-        return((char *)s1);
-
-    ps1 = s1 + strlen(s1);
-
-    while(ps1 != s1) {
-        --ps1;
-        for (psc1 = ps1, sc2 = s2; ; )
-                if (*(psc1++) != *(sc2++))
-                        break;
-                else if (*sc2 == '\0')
-                        return ((char *)ps1);
-    }
-    return ((char *)NULL);
-}
-
-
-/*--------------------------------------------------------------------------
- *  This routine opens a CDF file
- *-------------------------------------------------------------------------*/
-CDFid cdf_open (char *fileName)     
-{
-   CDFstatus status;
-   CDFid     id;
-   char      msg[80];
-
-   status = CDFlib (OPEN_, CDF_, fileName,    /* in - file name to be opened */
-                                 &id,         /* out - CDF file ID           */
-                     NULL_);
-   if (status != CDF_OK)  {
-       strcpy(msg, "OPEN_, CDF_, ");       
-       strcat(msg, fileName);
-       cdf_status_handler (status, msg);
-   }
-   return id;
-}
-
-
-/*---------------------------------------------------------------------------
- *   This routine retrievs the following information:
- *
- *      nAttr - number of attributes (including global and variable)
- *      nZvars - number of zVariables
- *
- *   CDF file can have both rVariables (old style) and zVariables (new style)
- *   simultaneously.  zVariable is a superset of rVariable, and it is a lot
- *   more efficient and offers all the functionality a rVariable offers and 
- *   more.  Treat all CDF variables as zVariables.
- *--------------------------------------------------------------------------*/
-void read_cdf_file_info ()
-{
-    CDFstatus status;
-
-    status = CDFlib (SELECT_, CDF_zMODE_, zMODEon2,
-                     GET_, CDF_NUMATTRS_,  &nAttrs, 
-                           CDF_NUMzVARS_,  &nZvars, 
-                     NULL_);
-    if (status != CDF_OK) cdf_status_handler (status, "GET_, CDF_FILEINFO_");
-}
-
-
-/*----------------------------------------------------------------------------
- *  This routine retrieves the CDF attribute (global or variable) name
- *  and its data for the given CDF attribute ID.  
- *---------------------------------------------------------------------------*/
-void get_cdf_attribute(long attrNum,        /* in - CDF attribute number/id */
-                       long scope,          /* in - CDF attribute scope     */
-                       long cdfVarId,       /* in - CDF variable number/id  */
-                       int  netcdfVarId)    /* in - netCDF variable ID      */
-{
-    int           ncstatus, i, len;
-    long          status, numEntries, datatype, attrScope, entryNum, 
-                  numElements;
-    nc_type       ncDatatype;      /* netCDF datatype */
-    
-    char          *cPtr, attrName[CDF_ATTR_NAME_LEN+1],
-                  mappedAttrName[CDF_ATTR_NAME_LEN+1];
-    signed char   *scPtr;
-    short         *sPtr;
-    int           *iPtr;
-    float         *fPtr;
-    double        *dPtr;
-
-    status = CDFlib (SELECT_, ATTR_, attrNum,
-                     GET_,    ATTR_NAME_, attrName,
-                              ATTR_SCOPE_, &attrScope,
-                     NULL_);
-    if (status != CDF_OK) cdf_status_handler (status, "SELECT_, ATTR_");      
-
-    /****************************************************************/
-    /* If the attribute scope is not the requested attribute scope  */
-    /* (VARIABLE_SCOPE or GLOBAL_SCOPE), do not process the current */
-    /* attribute.                                                   */
-    /****************************************************************/
-    if (attrScope != scope) return;
-
-    map_CDF_attr_to_netCDF(attrName, mappedAttrName);
-    strcpy(attrName, mappedAttrName);
-
-    if (attrScope == GLOBAL_SCOPE) {
-        status = CDFlib (GET_,  ATTR_NUMgENTRIES_, &numEntries, NULL_);
-        if (status != CDF_OK) 
-            cdf_status_handler (status, "GET_, ATTR_NUMgENTRIES_");
-        if (DEBUG) printf ("\t%s", attrName);
-
-        /*********************************************************************
-         * While the CDF global attribute can have multiple entries of 
-         * of different datatypes, the CDF variable attribute can only have 
-         * one attribute entry.  netCDF doesn't allow more than 1 attribute
-         * entry - handle this case 
-         ********************************************************************/
-        for (entryNum=0; entryNum < numEntries; entryNum++) {
-             if (entryNum > 0)            /* Attribute has more than 1 entry */
-                 sprintf (attrName, "%s_%d", mappedAttrName, entryNum);
-             status = CDFlib (SELECT_, gENTRY_, entryNum,
-                              GET_,    gENTRY_DATATYPE_, &datatype,
-                                       gENTRY_NUMELEMS_, &numElements,
-                              NULL_);
-             if (status == NO_SUCH_ENTRY) return;
-             if (status != CDF_OK) cdf_status_handler(status,"GET_ATTR_INFO_");
-             get_cdf_attr_data (attrName, gENTRY_DATA_, datatype, numElements,
-                                netcdfVarId);
-        }
-    }
-    else {
-        /*********************************************************************
-         * IMPORTANT NOTE:
-         *     For the variable attribute, entry number is the variable ID.
-         *********************************************************************/
-        status = CDFlib (SELECT_, zENTRY_, cdfVarId,
-                         GET_,    zENTRY_DATATYPE_, &datatype,
-                                  zENTRY_NUMELEMS_, &numElements,
-                         NULL_);
-        /******************************************************************/
-        /* If there's no attribute entry for the current attribute number */
-        /* selected, process the next attribute.                          */
-        /******************************************************************/
-        if (status == NO_SUCH_ENTRY) return;    
-
-        if (status != CDF_OK) cdf_status_handler (status,"GET_ATTR_INFO_");
-        if (DEBUG) printf ("\t%s", attrName);
-        get_cdf_attr_data (attrName, zENTRY_DATA_, datatype, numElements,
-                           netcdfVarId);
-    }
-}
-
-
-/*--------------------------------------------------------------------------
- *  This routine retrieves the CDF attribute data (a.k.a. attribute entries)
- *  and write its values to the target netCDF file.
- *--------------------------------------------------------------------------*/
-void get_cdf_attr_data (char *attrName,    /* in - attribute name          */
-                        long entryData,    /* in - type of attr entry data */
-                        long datatype,     /* in - attribute datatype      */ 
-                        long numElements,  /* in - # of attribute values   */
-                        int netcdfVarId)   /* in - netCDF variable ID      */
-{
-    char     entryDataType[20], msg[100],
-             epString[EPOCH_STRING_LEN+1],
-             ep16String[EPOCH16_STRING_LEN+1];
-    double   epoch16[2];
-
-    nc_type  ncDatatype;                  /* netCDF datatype    */
-    int      nc_status,                   /* netCDF status code */
-             varId;                       /* netCDF variable ID */
-    long     status;                      /* CDF status code    */
-
-    char          *cPtr;
-    signed char   *scPtr;
-    short         *sPtr;
-    int           *iPtr, i;
-    float         *fPtr;
-    double        *dPtr;
-
-    /*************************************************
-     * entryData has one of following values: 
-     * 
-     *    gENTRY_DATA_ - global attribute entry
-     *    rENTRY_DATA_ - rVariable attribute entry
-     *    zENTRY_DATA_ - zVariable attribute entry
-     *************************************************/
-    if (entryData == gENTRY_DATA_) {
-        varId = NC_GLOBAL;
-        strcpy(entryDataType, "gENTRY_DATA_");
-    }
-    else {
-        varId = netcdfVarId;
-        strcpy(entryDataType, "zENTRY_DATA_");
-    }
-    strcpy (msg, "get_cdf_attr_data, GET_, ");
-    strcat (msg, entryDataType);
-    strcat (msg, cdf_str_datatype(datatype));
-
-    /*  Map the CDF datatype to an appropriate netCDF datatype. */
-    ncDatatype = get_netcdf_datatype (datatype);
-
-    /* Remove trailing blank spaces if there are any */
-    for (i=strlen(attrName)-1; i >= 0; i--) {
-         if (attrName[i] != ' ') {
-             attrName[i+1] = '\0';
-             break;
-         }
-    }
-    /* Replace blanks space(s) with underscore(s). */
-    for (i=0; i < strlen(attrName); i++) {
-         if (attrName[i] == ' ') attrName[i] = '_';
-    }
-
-    switch (datatype) {
-    case CDF_CHAR:
-	 case CDF_UCHAR:	 
-        cPtr = (char *) malloc(numElements * sizeof(char) + 1);
-        if (cPtr == NULL) memory_error("get_cdf_attr_data", "NC_CHAR");
-        status = CDFlib (GET_, entryData, cPtr, NULL_);
-        if (status != CDF_OK) cdf_status_handler (status, msg);
-        *(cPtr+numElements) = '\0';               /* End of string mark */
-        if (DEBUG) printf (" = \"%s\"", cPtr);
-        nc_status = nc_put_att_text(ncid, varId, attrName, numElements, cPtr);
-        if (nc_status != NC_NOERR) handle_netcdf_error(nc_status);
-        free(cPtr);
-        break;
-
-    case CDF_BYTE:
-    case CDF_INT1:
-        scPtr = (signed char *) malloc (sizeof(signed char) * numElements);
-        if (scPtr == NULL) memory_error("get_cdf_attr_data", "NC_BYTE");
-        status = CDFlib (GET_, entryData, scPtr, NULL_);
-        if (status != CDF_OK) cdf_status_handler (status, msg);
-        if (DEBUG) {
-            printf (" = ");
-            for (i=0; i < numElements; i++) {
-                 if (i > 0) printf (", ");
-                 printf ("%d", *(scPtr+i));
-            }
-        }
-        nc_status = nc_put_att_schar(ncid, varId, attrName, ncDatatype, 
-                                     numElements, scPtr);
-        if (nc_status != NC_NOERR) handle_netcdf_error(nc_status);
-        free (scPtr);
-        break;
-
-    case CDF_INT2:
-    case CDF_UINT1:
-        sPtr = (short *) malloc (sizeof(short) * numElements);
-        if (sPtr == NULL) memory_error("get_cdf_attr_data", "NC_SHORT");
-        status = CDFlib (GET_, entryData, sPtr, NULL_);
-        if (status != CDF_OK) cdf_status_handler (status, msg);
-        if (DEBUG) {    
-            printf (" = ");    
-            for (i=0; i < numElements; i++) {    
-                 if (i > 0) printf (", ");    
-                 printf ("%d", *(sPtr+i));   
-            }    
-        }    
-        nc_status = nc_put_att_short(ncid, varId, attrName, ncDatatype, 
-                                     numElements, sPtr);
-        if (nc_status != NC_NOERR) handle_netcdf_error(nc_status);
-        free (sPtr);
-        break;
-
-    case CDF_INT4:
-    case CDF_UINT2:
-        iPtr = (int *) malloc (sizeof(int) * numElements);
-        if (iPtr == NULL) memory_error("get_cdf_attr_data", "NC_INT");
-        status = CDFlib (GET_, entryData, iPtr, NULL_);
-        if (status != CDF_OK) cdf_status_handler (status, msg);
-        if (DEBUG) {
-            printf (" = ");
-            for (i=0; i < numElements; i++) {
-                 if (i > 0) printf (", ");
-                 printf ("%d", *(iPtr+i));
-            }
-        }
-        nc_status = nc_put_att_int(ncid, varId, attrName, ncDatatype, 
-                                   numElements, iPtr);
-        if (nc_status != NC_NOERR) handle_netcdf_error(nc_status);
-        free (iPtr);
-        break;
-
-    case CDF_FLOAT:
-    case CDF_REAL4:
-        fPtr = (float *) malloc (sizeof(float) * numElements);
-        if (fPtr == NULL) memory_error("get_cdf_attr_data", "NC_FLOAT");
-        status = CDFlib (GET_, entryData, fPtr, NULL_);
-        if (status != CDF_OK) cdf_status_handler (status, msg);
-        if (DEBUG) {
-            printf (" = ");
-            for (i=0; i < numElements; i++) {
-                 if (i > 0) printf (", ");
-                 printf ("%g", *(fPtr+i));
-            }
-        }
-        nc_status = nc_put_att_float(ncid, varId, attrName, ncDatatype, 
-                                     numElements, fPtr);
-        if (nc_status != NC_NOERR) handle_netcdf_error(nc_status);
-        free (fPtr);
-        break;
-
-    case CDF_DOUBLE:
-    case CDF_REAL8:
-    case CDF_UINT4:
-        dPtr = (double *) malloc (sizeof(double) * numElements);
-        if (dPtr == NULL) memory_error("get_cdf_attr_data", "NC_DOUBLE");
-        status = CDFlib (GET_, entryData, dPtr, NULL_);
-        if (status != CDF_OK) cdf_status_handler (status, msg);
-        if (DEBUG) {
-            printf (" = ");
-            for (i=0; i < numElements; i++) {
-                 if (i > 0) printf (", ");
-                 printf ("%g", *(dPtr+i));
-            }
-        }
-        nc_status = nc_put_att_double(ncid, varId, attrName,
-                                      ncDatatype, numElements, dPtr);
-        if (nc_status != NC_NOERR) handle_netcdf_error(nc_status);
-        free (dPtr);
-        break;
-
-    case CDF_EPOCH:       /* 8-byte real number */ 
-        dPtr = (double *) malloc (sizeof(double) * numElements);
-        if (dPtr == NULL) memory_error("get_cdf_attr_data", "CDF_EPOCH");
-        status = CDFlib (GET_, entryData, dPtr, NULL_);
-        if (status != CDF_OK) cdf_status_handler (status, msg);
-        if (DEBUG) printf (" = ");
-        for (i=0; i < numElements; i++) {
-             encodeEPOCH (*(dPtr+i), epString);
-             nc_status = nc_put_att_text(ncid, varId, attrName,
-                                         EPOCH_STRING_LEN, epString);
-             if (nc_status != NC_NOERR) handle_netcdf_error(nc_status);
-             if (DEBUG)  {
-                 if (i > 0) printf (", ");
-                 printf (epString);
-             }
-        }
-        free (dPtr);
-        break;
-
-    case CDF_EPOCH16:       /* 16-byte real number */
-        dPtr = (double *) malloc (sizeof(double) * numElements * 2);
-        if (dPtr == NULL) memory_error("get_cdf_attr_data", "CDF_EPOCH16");
-        status = CDFlib (GET_, entryData, dPtr, NULL_);
-        if (status != CDF_OK) cdf_status_handler (status, msg);
-        if (DEBUG) printf (" = "); 
-        for (i=0; i < numElements; i++) {
-             epoch16[0] = *(dPtr+i*2);
-             epoch16[1] = *(dPtr+i*2+1);
-             encodeEPOCH16 (epoch16, ep16String);
-             nc_status = nc_put_att_text(ncid, varId, attrName,
-                                         strlen(ep16String), ep16String);
-             if (nc_status != NC_NOERR) handle_netcdf_error(nc_status);
-             if (DEBUG)  {
-                 if (i > 0) printf (", "); 
-                 printf (ep16String);
-             }   
-        }
-        free (dPtr);
-        break;
-
-    default:
-            printf ("** Error in get_cdf_attribute: bad data type");
-    }
-    if (DEBUG) printf (" ;\n");
-}
-
-
-/*--------------------------------------------------------------------------
- *  Get the zVariables in the CDF file.
- *--------------------------------------------------------------------------*/
-void get_zVariables() 
-{
-   CDFstatus status;
-   int       i, ncstatus, createUnlimitedDim, unlimitedDimId, 
-             attrId, netcdfVarId; 
-   char      netcdfDimName[NC_MAX_NAME+1];       /* netCDF dimension name */
-   long      holdDim, holdDim0;
-   long      varId,
-             recInterval,                /* No. of recors to skip            */
-             dimIndices[CDF_MAX_DIMS],   /* Beginning location of the array  */
-                                         /* to be dumped                     */
-             dimIntervals[CDF_MAX_DIMS]; /* No. of elements to skip          */
-   CDFvar  var;
-   size_t start[NC_MAX_DIMS],                 /* index for where to read first */ 
-               count[NC_MAX_DIMS];              /* # of values to read */
-   short timeDefined = 0;
-
-   if (DEBUG) printf ("\n");
-
-   createUnlimitedDim = TRUE;
- 
-   for (varId=0; varId < nZvars; varId++) {
-        status = CDFlib (SELECT_,zVAR_, varId,
-                         GET_, zVAR_NAME_, var.name,
-                               zVAR_DATATYPE_, &var.datatype,
-                               zVAR_NUMELEMS_, &var.numElements,
-                               zVAR_NUMDIMS_, &var.dimensionality,
-                               zVAR_DIMSIZES_, var.dimSizes,
-                               zVAR_NUMRECS_, &var.numRecs,
-                               zVAR_RECVARY_, &var.recVariance,
-                         NULL_);   
-        if (status != CDF_OK) cdf_status_handler (status, "GET_, zVARS_");
-
-        if (DEBUG) {
-            printf ("\nvar name = %s, %s/%d, %d:[", 
-                    var.name, cdf_str_datatype(var.datatype), 
-                    var.numElements, var.dimensionality); 
-            for (i=0; i < var.dimensionality; i++) {
-                 if (i > 0) printf (",");
-                 printf ("%d", var.dimSizes[i]);
-            }
-            printf("], numRecs = %d\n", var.numRecs);
-        }
-
-        create_netcdf_dimensions (var, &createUnlimitedDim, &unlimitedDimId); 
-      
-        
-         netcdfVarId = create_netcdf_variable (var, unlimitedDimId, &timeDefined);
-       
-        /* Leave the define mode before adding data */
-        ncstatus = nc_enddef(ncid);
-        if (ncstatus != NC_NOERR) handle_netcdf_error(ncstatus);
-
-        get_cdf_variable_data (varId, var);
-
-        /* Enter the define mode before writing netCDF variable attributes */
-        /* and creating a variable.                                        */
-        ncstatus = nc_redef(ncid);
-        if (ncstatus != NC_NOERR) handle_netcdf_error(ncstatus);
-
-        /* Get the variable attributes */
-        for (attrId = 0; attrId < nAttrs; attrId++)
-             get_cdf_attribute(attrId, VARIABLE_SCOPE, varId, netcdfVarId);
-   }
-// DD Variables   
-         nc_def_dim (ncid, "TimeLength", TIMELENGTH, &TimeLengthID);
-         nc_def_var (ncid, "StartTime", NC_CHAR, 1, &TimeLengthID, &StartTimeID);
-         nc_def_var (ncid, "StopTime", NC_CHAR, 1, &TimeLengthID, &StopTimeID);
-          ncstatus = nc_enddef(ncid);
-         if (ncstatus != NC_NOERR) handle_netcdf_error(ncstatus);
-                start[0] = 0L;
-                start[1] = 0L;
-                count[0]= 1L;
-                count[1] = TIMELENGTH;
-                ncstatus = nc_put_vara_text(ncid, StartTimeID, &start[1], &count[1], StartTime);
-                if (ncstatus != NC_NOERR) handle_netcdf_error(ncstatus);
-                ncstatus = nc_put_vara_text(ncid, StopTimeID, &start[1], &count[1], StopTime);
-                if (ncstatus != NC_NOERR) handle_netcdf_error(ncstatus);
-}
-
-
-/*--------------------------------------------------------------------------
- *  This routine creates a netCDF dimension.
- *--------------------------------------------------------------------------*/
-void create_netcdf_dimensions (CDFvar var, 
-                               int *createUnlimitedDim,
-                               int *unlimitedDimId)
-{
-   int     status,                             /* netCDF status code */
-           i, j, dimensionCreated;
-   long    dimensionality;
-   char    netcdfDimName[NC_MAX_NAME+1];       /* netCDF dimension name */
-
-   if (*createUnlimitedDim) {
-       if (var.recVariance == VARY) {
-           status = nc_def_dim(ncid, UNLIMITDIM, NC_UNLIMITED,unlimitedDimId);
-           if (status != NC_NOERR) handle_netcdf_error(status);
-           *createUnlimitedDim = FALSE;
-       }
-   }
-
-   dimensionality = var.dimensionality;
-
-   if (var.datatype == CDF_CHAR) {
-       var.dimSizes[dimensionality] = var.numElements;
-       dimensionality++;
-   }
-   else if (var.datatype == CDF_EPOCH) {
-       var.dimSizes[dimensionality] = TIMELENGTH; //EPOCH_STRING_LEN;
-       dimensionality++;
-   }
-   else if (var.datatype == CDF_EPOCH16) {
-       var.dimSizes[dimensionality] = TIMELENGTH; //EPOCH16_STRING_LEN;
-       dimensionality++;
-   }
-
-   for (i=0; i < dimensionality; i++) {
-        dimensionCreated = FALSE;
-        for (j=0; j < totNCdims; j++) {
-             if (ncDims[j].size == var.dimSizes[i]) {
-                 dimensionCreated = TRUE;
-                 break;
-             }
-        }
-        if (!dimensionCreated && var.dimSizes[i] > 1) {
-            ncDims[totNCdims].size = var.dimSizes[i];
-            sprintf (netcdfDimName, "dim%d", totNCdims);
-            strcpy(ncDims[totNCdims].name, netcdfDimName);
-            status = nc_def_dim(ncid,                      /* in  */
-                                ncDims[totNCdims].name,    /* in  */
-                                ncDims[totNCdims].size,    /* in  */
-                                &ncDims[totNCdims].id);    /* out */
-            if (status != NC_NOERR) handle_netcdf_error(status);
-            totNCdims++;
-        }
-   }
-}
-
-
-/*--------------------------------------------------------------------------
- *  This routine creates a netCDF variable.
- *--------------------------------------------------------------------------*/
-int create_netcdf_variable (CDFvar var,          /* in - CDF variable     */
-                            int unlimitedDimId, short *timeDefined)  /* in - unlimited dim ID */
-{
-   int     status,                       /* netCDF status code */
-           i, j, k, ii,
-           varId,                        /* netCDF variable ID */
-           dimensionality,               /* netCDF dimensionality */
-           dims[NC_MAX_DIMS];            /* netCDF dimensions */
-   nc_type datatype;
-
-   int  nc_dimensionality, nc_dims[NC_MAX_DIMS];    
-   char      ourTime[]={"Time\0"};
-
-   dimensionality = var.dimensionality;
-   datatype = get_netcdf_datatype (var.datatype);
-
-   /*********************************************************************
-    * While the string value is treated as 0-d in CDF, it is treated as 
-    * 1-D in netCDF.                                                   
-    *********************************************************************/
-   if (var.datatype == CDF_CHAR) {
-       var.dimSizes[dimensionality] = var.numElements;
-       dimensionality++;
-   }
-
-   /*********************************************************************
-    * In CDF, CDF_EPOCH and CDF_EPOCH16 are used to store a date and time
-    * value into a 8-byte and 16-byte real value, respectively.  Since netCDF 
-    * doesn't support EPOCH, the CDF EPOCH variable needs to be translated 
-    * as a string value. 
-    *********************************************************************/
-   else if ((var.datatype == CDF_EPOCH) && (! *timeDefined)) {
-      
-       *timeDefined = 1; 
-       var.dimSizes[dimensionality] = TIMELENGTH;//EPOCH_STRING_LEN;
-       strcpy(var.name, ourTime);
-       dimensionality++;
-   }
-   else if (var.datatype == CDF_EPOCH16) {
-       var.dimSizes[dimensionality] = TIMELENGTH;//EPOCH16_STRING_LEN;
-       strcpy(var.name, ourTime);
-       dimensionality++;
-   }
-
-   /************************************************************************
-    *  If CDF's record variance is true, then the netCDF's first dimension 
-    *  reflects the record number.                               
-    ************************************************************************/
-   k = 0;
-   if (var.recVariance == VARY) { 
-       dims[k++] = unlimitedDimId;
-       dimensionality++;
-   }
-
-   for (i=0; i < dimensionality; i++) {
-        for (j=0; j < totNCdims; j++) {
-             if (ncDims[j].size == var.dimSizes[i]) { 
-                 dims[k++] = ncDims[j].id;
-                 break;
-             }
-        }
-   }
-
-   /* Remove trailing blank spaces if there are any */
-   for (i=strlen(var.name)-1; i >= 0; i--) {
-        if (var.name[i] != ' ') {
-            var.name[i+1] = '\0'; 
-            break;
-        }
-   }
-
-  
-   /* Replace special symbols with underscore(s). */
- for (ii=0; ii < 9; ii++) 
-   for (i=0; i < strlen(var.name); i++) {
-        if (var.name[i] == SpecialSymbol[ii]) {
-                var.name[i] = '_'; 
-        }
-   }
-   
-
-/*  Exclude "false" dimension  */
-   nc_dimensionality = dimensionality;
-   for (i=0; i < dimensionality; i++) {
-    if (  var.dimSizes[i] == 1 ) { 
-             nc_dimensionality--;
-             j = i;
-             break;
-        }
-  }
-   /* Create a netCDF variable. */
-                      
-   status = nc_def_var(ncid, var.name, datatype, nc_dimensionality, dims, &varId); 
-   
-   if (status != NC_NOERR) handle_netcdf_error(status);
-
-   return varId;
-}
-
-
-/*--------------------------------------------------------------------------
- *  Get the CDF variable data and write the data just read into the 
- *  netCDF variable created in create_netcdf_variable.
- *--------------------------------------------------------------------------*/
-void get_cdf_variable_data (long varId,      /* in - variable ID/number     */
-                            CDFvar var)      /* in - CDF variable structure */
-{
-   CDFstatus status;                         /* CDF status code    */
-   int       ncstatus;                       /* netCDF status code */
-   char      epString[EPOCH_STRING_LEN+1];
-   char      ep16String[EPOCH16_STRING_LEN+1];
-  
-   double    epoch16[2];
-
-    size_t start[NC_MAX_DIMS],              /* index for where to read first */ 
-           count[NC_MAX_DIMS];              /* # of values to read           */
-
-    int     i, j, k, divide, 
-                  dimensionality,
-                  numValues;               /* # of values on each record */
-                                              
-    int           nc_dimensionality,
-                  nc_dimSizes[NC_MAX_DIMS];
-
-    char          *cPtr;
-    signed char   *scPtr;
-    short         *sPtr;
-    int           *iPtr;
-    float         *fPtr;
-    double        *dPtr;
-    long          recNo, 
-                  totRecs,              /* total # of records to read */
-                  numRecsLeftToRead,
-                  numRecs;       /* # of records to read and write at a time */ 
-     
-    dd_time_t curTime;
-
-    j = 0;
-    start[0]  = 0;
-    numValues = 1;                      /* # of values on each CDF record */
-
-    if (var.recVariance == VARY) {   /* Treat it as a netCDF record variable */
-        start[j] = 0;                         /* start record #        */
-        count[j++] = var.numRecs;             /* # of records to write */
-    }
-
-   dimensionality = var.dimensionality;
-
-   if (var.datatype == CDF_CHAR) {
-       var.dimSizes[dimensionality] = var.numElements;
-       dimensionality++;
-   }
-
-   /*********************************************************************
-    * In CDF, CDF_EPOCH and CDF_EPOCH16 are used to store a date and time
-    * value into a 8-byte and 16-byte real value, respectively.  Since netCDF
-    * doesn't support EPOCH, the CDF EPOCH variable needs to be translated
-    * as a string value.
-    *********************************************************************/
-   else if (var.datatype == CDF_EPOCH) { 
-       var.dimSizes[dimensionality] = TIMELENGTH;
-       dimensionality++;
-   }
-   else if (var.datatype == CDF_EPOCH16) { 
-       var.dimSizes[dimensionality] = TIMELENGTH;
-       dimensionality++;
-   }
-
-    for (i=0; i < dimensionality; i++) {
-         start[j] = 0;
-         if (var.dimSizes[i] > 1) count[j++] = var.dimSizes[i];
-         numValues *= var.dimSizes[i];
-    }
-
-    if (var.datatype == CDF_EPOCH)
-        numValues /= TIMELENGTH;
-    else if (var.datatype == CDF_EPOCH16)
-        numValues /= TIMELENGTH;
-
-    totRecs           = var.numRecs;      /* total # of records for this var */
-    numRecsLeftToRead = var.numRecs;
-
-    while (numRecsLeftToRead > 0) {
-        recNo   = start[0];               /* record # to start reading */
-        divide  = 1;
-        numRecs = numRecsLeftToRead;      /* # of records to read at a time */
-
-        switch (var.datatype) {
-        case CDF_CHAR:
-            cPtr = NULL;
-            while (cPtr == NULL) {
-               cPtr = (char *) malloc (sizeof(char) * numValues * numRecs);
-               if (cPtr == NULL) {
-                   if (DEBUG) insufficient_memory();
-                   divide *= 2;
-                   numRecs = totRecs / divide;
-               }
-            }
-            read_cdf_variable_data (varId,
-                                    recNo,          /* starting record # */
-                                    numRecs,        /* # of records to read */
-                                    var.dimensionality,
-                                    var.dimSizes,   /* dimesion sizes */
-                                    cPtr);          /* data pointer   */
-            if (DEBUG) {
-                printf ("   retrieved CDF data = \n");
-                for (k=0; k < numRecs; k++) {
-                  printf("\"");
-                  for (i=0; i < numValues; i++) 
-                    printf ("%c", *(cPtr+(k*numValues+i)));
-                  printf("\"\n");
-                }
-            }
-
-            start[0] = 0;
-            start[1] = 0;
-            if (var.recVariance == VARY) {
-                count[0] = numRecs;
-            }
-
-            if (DEBUG) {
-                for (i=0; i < dimensionality; i++)
-                     printf ("   start[%d] = %d, count[%d] = %d\n",
-                             i, start[i], i, count[i]);
-            }
-            ncstatus = nc_put_vara_text(ncid, varId, start, count, cPtr);
-            if (ncstatus != NC_NOERR) handle_netcdf_error(ncstatus);
-            if (DEBUG && ncstatus != NC_NOERR) {
-                if (ncstatus != NC_NOERR) 
-                    printf ("   Error putting data...\n");
-                else
-                    printf ("   Done putting data...\n");
-            }
-            free (cPtr);
-            break;
-
-        case CDF_BYTE:
-        case CDF_INT1:
-            scPtr = NULL;
-            while (scPtr == NULL) {
-               scPtr = 
-                 (signed char *) malloc (sizeof(signed char)*numValues*numRecs);
-               if (scPtr == NULL) {
-                   if (DEBUG) insufficient_memory();
-                   divide *= 2;
-                   numRecs = totRecs / divide;
-               }
-            }
-            read_cdf_variable_data (varId,
-                                    recNo,           /* starting record # */
-                                    numRecs,         /* # of records to read */
-                                    var.dimensionality,
-                                    var.dimSizes,    /* dimesion sizes */
-                                    scPtr);          /* data pointer   */
-            if (var.recVariance == VARY)
-                count[0] = numRecs;
-            ncstatus = nc_put_vara_schar(ncid, varId, start, count, scPtr);
-            if (ncstatus != NC_NOERR) handle_netcdf_error(ncstatus);
-            free (scPtr);
-            break;
-
-        case CDF_INT2:
-        case CDF_UCHAR:
-        case CDF_UINT1:
-            sPtr = NULL;
-            while (sPtr == NULL) {
-               sPtr = (short *) malloc (sizeof(short) * numValues * numRecs);
-               if (sPtr == NULL) {
-                   if (DEBUG) insufficient_memory();
-                   divide *= 2;
-                   numRecs = totRecs / divide;
-               }
-            }
-            read_cdf_variable_data (varId,
-                                    recNo,          /* starting record #    */
-                                    numRecs,        /* # of records to read */
-                                    var.dimensionality,
-                                    var.dimSizes,   /* dimesion sizes */
-                                    sPtr);          /* data pointer   */
-            if (var.recVariance == VARY)
-                count[0] = numRecs;
-            ncstatus = nc_put_vara_short(ncid, varId, start, count, sPtr);
-            if (ncstatus != NC_NOERR) handle_netcdf_error(ncstatus);
-            free (sPtr);
-            break;
-
-        case CDF_INT4:
-        case CDF_UINT2:
-            iPtr = NULL;
-            while (iPtr == NULL) {
-               iPtr = (int *) malloc (sizeof(int) * numValues * numRecs);
-               if (iPtr == NULL) {
-                   if (DEBUG) insufficient_memory();
-                   divide *= 2;
-                   numRecs = totRecs / divide;
-               }
-            }
-            read_cdf_variable_data (varId,
-                                    recNo,          /* starting record #    */
-                                    numRecs,        /* # of records to read */
-                                    var.dimensionality,
-                                    var.dimSizes,   /* dimesion sizes */
-                                    iPtr);          /* data pointer   */
-            if (var.recVariance == VARY)
-                count[0] = numRecs;
-            ncstatus = nc_put_vara_int(ncid, varId, start, count, iPtr);
-            if (ncstatus != NC_NOERR) handle_netcdf_error(ncstatus);
-            free (iPtr);
-            break;
-
-        case CDF_FLOAT:
-        case CDF_REAL4:
-            fPtr = NULL;
-            while (fPtr == NULL) {
-               fPtr = (float *) malloc (sizeof(float) * numValues * numRecs);
-               if (fPtr == NULL) {
-                   if (DEBUG) insufficient_memory();
-                   divide *= 2;
-                   numRecs = totRecs / divide;
-               }
-            }
-            read_cdf_variable_data (varId,
-                                    recNo,          /* starting record #    */
-                                    numRecs,        /* # of records to read */
-                                    var.dimensionality,
-                                    var.dimSizes,   /* dimesion sizes */
-                                    fPtr);          /* data pointer   */
-            if (var.recVariance == VARY)
-                count[0] = numRecs;
-            ncstatus = nc_put_vara_float(ncid, varId, start, count, fPtr);
-            if (ncstatus != NC_NOERR) handle_netcdf_error(ncstatus);
-            free (fPtr);
-            break;
-
-        case CDF_DOUBLE:
-        case CDF_REAL8:
-        case CDF_UINT4:
-            dPtr = NULL;
-            while (dPtr == NULL) {
-               dPtr = (double *) malloc (sizeof(double) * numValues * numRecs);
-               if (dPtr == NULL) {
-                   if (DEBUG) insufficient_memory();
-                   divide *= 2;
-                   numRecs = totRecs / divide;
-               }
-            }
-            read_cdf_variable_data (varId,
-                                    recNo,           /* starting record # */
-                                    numRecs,         /* # of records to read */
-                                    var.dimensionality,
-                                    var.dimSizes,    /* dimesion sizes */
-                                    dPtr);           /* data pointer   */
-            if (var.recVariance == VARY)
-                count[0] = numRecs;
-
-            ncstatus = nc_put_vara_double(ncid, varId, start, count, dPtr);
-            if (ncstatus != NC_NOERR) handle_netcdf_error(ncstatus);
-            free (dPtr);
-            break;
-
-        case CDF_EPOCH:
-            dPtr = NULL;
-            while (dPtr == NULL) {
-               dPtr = (double *) malloc (sizeof(double)*numValues*numRecs);
-               if (dPtr == NULL) {
-                   if (DEBUG) insufficient_memory();
-                   divide *= 2;
-                   numRecs = totRecs / divide;
-               }
-            }
-            read_cdf_variable_data (varId,
-                                    recNo,           /* starting record # */
-                                    numRecs,         /* # of records to read */
-                                    var.dimensionality,
-                                    var.dimSizes,    /* dimesion sizes */
-                                    dPtr);           /* data pointer   */
-   
-                count[0] = 1L;
-      
-            /* Get  the EPOCH value  into a  DD Timestring. */
-
-            for (i = 0; i < numRecs*numValues; i++) {
-                *(dPtr+i) /= 1000.0;
- 
-                *(dPtr+i) -= TIMESHIFT;   
-                strcpy(curTime,Double2DD_Time((double)*(dPtr+i)));       
-                ncstatus =  nc_put_vara_text(ncid, varId, start, count, curTime); 
-                if (ncstatus != NC_NOERR) handle_netcdf_error(ncstatus);  
-                if ((i == 0) && (isTimeSet == 0)) strcpy(StartTime,curTime);                 
-                start[0]++;
-            }
- // First Epoch type is considered as Time               
-               if (isTimeSet == 0) strcpy(StopTime,curTime);
-               isTimeSet = 1;
-            free (dPtr);
-            break;
-
-        case CDF_EPOCH16:
-            dPtr = NULL;
-            while (dPtr == NULL) {
-               dPtr = (double *) malloc (sizeof(double) * numValues*numRecs*2);
-               if (dPtr == NULL) {
-                   if (DEBUG) insufficient_memory();
-                   divide *= 2;
-                   numRecs = totRecs / divide;
-               }
-            }
-            read_cdf_variable_data (varId,
-                                    recNo,           /* starting record # */
-                                    numRecs,         /* # of records to read */
-                                    var.dimensionality,
-                                    var.dimSizes,    /* dimesion sizes */
-                                    dPtr);           /* data pointer   */
-
-             count[0] = 1L;
- 
-
-            /* Get all the EPOCH16 values into a single string. */
-            for (i=0; i < numRecs; i++) {
-                 epoch16[0] = *(dPtr+i*2);
-                 epoch16[1] = *(dPtr+i*2+1);
-                 encodeEPOCH16_4 (epoch16, ep16String);
-                 ncstatus = nc_put_vara_text(ncid, varId, start, count, isotime_to_dd_time(ep16String));
-                 if (ncstatus != NC_NOERR) handle_netcdf_error(ncstatus);  
-                 if ((i == 0) && (isTimeSet == 0)) strcpy(StartTime,isotime_to_dd_time(ep16String));                 
-                 start[0]++;           
-            }
-                      
-            free (dPtr);
-            // First Epoch type is considered as Time               
-               if (isTimeSet == 0) strcpy(StopTime,isotime_to_dd_time(ep16String));
-               isTimeSet = 1;
-            break;
-
-        default:
-            printf ("** Error in getVarData: bad type");
-        }    
-
-        numRecsLeftToRead = totRecs - numRecs;
-        if (numRecsLeftToRead > 0) {
-            totRecs  = numRecsLeftToRead;
-            start[0] = numRecs;
-        }
-    }       /* end of the 'while' loop */
-
-}
-
-
-/*--------------------------------------------------------------------------
- *  This routine returns the string representation of the given CDF 
- *  datatype.
- *--------------------------------------------------------------------------*/
-char *  cdf_str_datatype (long type)
-{
-    switch (type) {
-      case CDF_BYTE:
-         return "CDF_BYTE";
-
-      case CDF_INT1:
-         return "CDF_INT1";
-
-      case CDF_CHAR:
-         return "CDF_CHAR";
-
-      case CDF_INT2:
-         return "CDF_INT2";
-
-      case CDF_UCHAR:
-         return "CDF_UCHAR";
-
-      case CDF_UINT1:
-         return "CDF_UINT1";
-
-      case CDF_INT4:
-         return "CDF_INT4";
-
-      case CDF_UINT2:
-         return "CDF_UINT2";
-
-      case CDF_FLOAT:
-         return "CDF_FLOAT";
-
-      case CDF_REAL4:
-         return "CDF_REAL4";
-
-      case CDF_DOUBLE:
-         return "CDF_DOUBLE";
-
-      case CDF_REAL8:
-         return "CDF_REAL8";
-
-      case CDF_UINT4:
-         return "CDF_UINT4";
-
-      case CDF_EPOCH:
-         return "CDF_EPOCH";
-
-      case CDF_EPOCH16:
-         return "CDF_EPOCH16";
-    }
-}
-
-
-/*--------------------------------------------------------------------------
- *  This routine returns the string representation of the given netCDF 
- *  datatype.
- *--------------------------------------------------------------------------*/
-char *  NC_datatype (nc_type type)
-{
-    switch (type) {
-      case NC_BYTE:
-        return "byte";
-      case NC_CHAR:
-        return "char";
-      case NC_SHORT:
-        return "short";   
-      case NC_INT:
-        return "int";
-      case NC_FLOAT:
-        return "float";
-      case NC_DOUBLE:      
-        return "double";
-      default:
-        return "UNKNOWN";
-    }
-}
-
-
-/*--------------------------------------------------------------------------
- *  This routine returns the netCDF datatype for the given CDF datatype.
- *--------------------------------------------------------------------------*/
-nc_type get_netcdf_datatype (long type)
-{
-    nc_type  netcdf_type;
-
-    switch (type) {
-      case CDF_BYTE:
-      case CDF_INT1:
-        netcdf_type = NC_BYTE;
-        break;
-
-      case CDF_CHAR:
-      case CDF_EPOCH:
-      case CDF_EPOCH16:
-        netcdf_type = NC_CHAR;
-        break;
-
-      case CDF_INT2:
-      case CDF_UCHAR:
-      case CDF_UINT1:
-        netcdf_type = NC_SHORT;
-        break;
-
-      case CDF_INT4:
-      case CDF_UINT2:
-        netcdf_type = NC_INT;
-        break;
-
-      case CDF_FLOAT:
-      case CDF_REAL4:
-        netcdf_type = NC_FLOAT;
-        break;
-
-      case CDF_DOUBLE:
-      case CDF_REAL8:
-      case CDF_UINT4:
-        netcdf_type = NC_DOUBLE;
-        break;
-
-      default: { 
-        printf ("** ERROR: Unknown CDF datatype\n");
-        exit (1);
-      }
-    }
-    return netcdf_type;
-}
-
-
-/*---------------------------------------------------------------------------
- *  Read the CDF variable data for the given CDF variable number.
- *---------------------------------------------------------------------------*/
-void read_cdf_variable_data (long varNum,      /* CDF variable number        */
-                             long recNo,       /* record # for start reading */
-                             long recCount,    /* # of records to read       */
-                             long dim,         /* CDF dimensionality         */
-                             long dimSizes[],  /* CDF dimesion sizes         */
-                             void *data)       /* data pointer               */
-{
-   CDFstatus status;
-   int       i;
-   long      recInterval,                /* No. of recors to skip            */
-             dimIndices[CDF_MAX_DIMS],   /* Beginning location of the array  */
-                                         /* to be dumped                     */
-             dimIntervals[CDF_MAX_DIMS]; /* No. of elements to skip          */
-
-   recInterval = 1L;             /* # of records to skip between writes   */
-
-   for (i=0; i < dim; i++) {
-        dimIndices[i]   = 0;     /* Dump data from the beginning of array */
-        dimIntervals[i] = 1;     /* Dump all the elements in the array    */
-   }
-
-   status = CDFlib (SELECT_,zVAR_, varNum,
-                            zVAR_RECNUMBER_, recNo,
-                            zVAR_RECCOUNT_, recCount,
-                            zVAR_RECINTERVAL_, recInterval,
-                            zVAR_DIMINDICES_, dimIndices,
-                            zVAR_DIMCOUNTS_, dimSizes,
-                            zVAR_DIMINTERVALS_, dimIntervals,
-                    GET_, zVAR_HYPERDATA_, data,
-                    NULL_);
-   if (status != CDF_OK) cdf_status_handler (status, "GET_, zVAR_HYPERDATA_");
-}
-
-
-/*--------------------------------------------------------------------------
- *  Remove the filepath from a file name.
- *
- *  Example:
- *      /home/data/mydata.txt => mydata.txt
- *--------------------------------------------------------------------------*/
-void removeFilepath (char *fileName) {
-    char *ptr;
-
-    ptr = strrchr(fileName, '/');        /* Unix file path separator */
-    if (ptr != NULL) {
-        ptr++;
-        strcpy(fileName, ptr);
-    }
-    else {
-       ptr = strrchr(fileName, '\\');     /* Windows file separator */
-       if (ptr != NULL) {
-           ptr++;
-           strcpy(fileName, ptr);
-       }
-    }
-}
-
-
-/*--------------------------------------------------------------------------
- *  Handles a CDF error.
- *--------------------------------------------------------------------------*/
-void cdf_status_handler (CDFstatus status, char *source)
-{
-   char  message[CDF_STATUSTEXT_LEN+1];
-
-   CDFerror (status, message);              /* Get the appropriate message */
-
-   if (status < CDF_WARN) {
-       printf ("An error has occurred, halting...\n");
-       printf ("%s\n", message);
-       printf ("** Error source: %s\n", source);
-       exit (status);
-   }
-   else if (status < CDF_OK) {
-       printf ("Warning, function may not have compeleted as expected...\n");
-       printf ("%s\n", message);
-   }
-   else if (status > CDF_OK) {
-       printf ("Function compeleted successfully, but be advised that...\n");
-       printf ("%s\n", message);
-   }
-}
-
-
-/*--------------------------------------------------------------------------
- *  Handles a netCDF error.
- *--------------------------------------------------------------------------*/
-void handle_netcdf_error(int status) {
- 
-  fprintf(stderr, "%s\n", nc_strerror(status));
-}
-
-
-/*--------------------------------------------------------------------------
- *  Handles a memory allocation error.
- *--------------------------------------------------------------------------*/
-void memory_error(char *source, char *datatype) {
-   printf ("** Memory allocation error occurred in %s. data type = %s", 
-           source, datatype);
-   exit (1);
-}
-
-void insufficient_memory () {
-   printf("Insufficient memory to load all the records at once");
-}
-
-
-/*--------------------------------------------------------------------------*/
-void usage()
-{
-   printf ("\nDescription:\n");
-   printf ("    This program converts a CDF file into a netCDF file.");
-   printf ("\n");
-   printf ("Usage: cdf2nc -[Options] <CDF file name>\n");
-   printf ("\n");
-   printf ("Options:\n");
-   printf ("    -map <mapfile>    Use the user-supplied mapping file.\n");
-   printf ("    -debug            Show debug information.\n");
-   printf ("\n");
-   printf ("Examples of usage: \n");
-   printf ("1) cdf-to-netCDF test.cdf\n");
-   printf ("   will convert the test.cdf file into the test.nc file.\n\n");
-   printf ("2) cdf-to-netCDF -map mymap.dat test.cdf\n");
-   printf ("   will convert the test.cdf file into the test.nc file using\n");
-   printf ("   the user-supplied mapping file called 'mymap.dat' instead\n");
-   printf ("   of using the default cdf-to-netCDF mapping file.\n");
-   printf ("\n");
-   exit(1);
-}
-
-void parseCmdLine (int argc, char *argv[])
-{
-   int  i;
-   char *nextArg;
-
-   for (i=0; i < argc; i++) {
-        if (strcmp(argv[i],"-map") == 0) {
-            nextArg = getNextArgument(argc, argv, i);
-            if (strcmp(nextArg, "No next argument") == 0 ||
-                *(nextArg+0) == '-')
-                errorMsg("** Error - mapping file is not defined");
-            else
-                 strcpy(mappingFile, nextArg);
-        }
-        else if (strcmp(argv[i],"-debug") == 0)
-            DEBUG = TRUE;
-   }
-}
-
-
-char * getNextArgument (int argc, char *argv[], int currentIndex)
-{
-    char *nextArg, msg[30];
-    int  nextIndex;
-
-    nextIndex  = currentIndex+1;
-    if (nextIndex == argc) {
-        strcpy (msg, "No next argument");
-        nextArg = msg;
-    }
-    else
-        nextArg = argv[nextIndex];
-
-    return nextArg;
-}
-
-void errorMsg (char *msg)
-{
-   printf ("%s\n", msg);
-   exit (1);
-}
-
-
-void map_CDF_attr_to_netCDF (char *searchAttr,     /* in - CDF attr name     */
-                             char *mappedAttrName) /* out - netCDF attr name */
-{
-   int i;
-
-   strcpy(mappedAttrName, searchAttr);
-
-   for (i=0; i < totAttrsInMappingFile; i++) {
-        if (strcmp(cdfAttrNames[i], searchAttr) == 0) {
-            strcpy(mappedAttrName, netcdfAttrNames[i]);
-            break;
-        }
-   }
-}
-
-/*******************************************************************************
- *  
- *      Convert an ISO 8601 date time to a DD Time string 
- */
-char *  isotime_to_dd_time (char * input)
-{
-        static char     output [DD_TIME_STRING_LEN + 1];
-        int             i, count, ddd;
-        int             yy, mm, dd, h, m, s, ms;
-        int             duration[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
-
-        count = sscanf (input, "%d-%d-%dT%d:%d:%d.%3d", & yy, & mm, & dd, & h, & m, & s, &ms);
-
-        if (count != 7) {
-                printf ("Unexpected time format: %s\n", input);
-                strcpy (output, "ERROR ");
-                goto EXIT;
-        }
-
-        if (leap_year (yy)) duration [2] = 29;
-
-        ddd = dd - 1;   /* Jan-01 : 0 => ddd in [0, 366[ */
-
-        for (i = 1; i < mm; i++) ddd += duration [i];
-        
-        sprintf (output, "%04.4d%03.3d%02.2d%02.2d%02.2d%03.3d",
-                yy, ddd, h, m, s, ms); 
-
-EXIT:   return output;
-}
-/*******************************************************************************
- *
- *      Check if the given year is a leap one
- */
-int     leap_year (int year)
-{
-        if ((year % 400) == 0) return TRUE;
-        if ((year % 100) == 0) return FALSE;
-        if ((year % 4)   == 0) return TRUE;
-        return FALSE;
-}
-
diff --git a/src/DECODERS/cdf2nc/cdf_to_netcdf_mapping.dat b/src/DECODERS/cdf2nc/cdf_to_netcdf_mapping.dat
deleted file mode 100644
index ae9a844..0000000
--- a/src/DECODERS/cdf2nc/cdf_to_netcdf_mapping.dat
+++ /dev/null
@@ -1,12 +0,0 @@
-#netCDF            CDF                Comment
-#----              ---                -------
-history            Revise_History     // History of revision
-_FillValue         FILLVAL            // Fill value 
-
-# The asterisk (*) is a placeholder indicator and its corresponding mapping
-# attribute is created in the output file.  The following example creates
-# 2 attributes (P1 and P2), if uncommented.  The value
-# of P1 and P2 will be "Placeholder 1" and "Placeholder 2", resctively.
-
-#P1                 *                  // Value of P1
-#P2                 *                  // Value of P2
diff --git a/src/DECODERS/cdfnew2nc/cdf_to_netcdf_mapping.dat b/src/DECODERS/cdfnew2nc/cdf_to_netcdf_mapping.dat
new file mode 100644
index 0000000..ae9a844
--- /dev/null
+++ b/src/DECODERS/cdfnew2nc/cdf_to_netcdf_mapping.dat
@@ -0,0 +1,12 @@
+#netCDF            CDF                Comment
+#----              ---                -------
+history            Revise_History     // History of revision
+_FillValue         FILLVAL            // Fill value 
+
+# The asterisk (*) is a placeholder indicator and its corresponding mapping
+# attribute is created in the output file.  The following example creates
+# 2 attributes (P1 and P2), if uncommented.  The value
+# of P1 and P2 will be "Placeholder 1" and "Placeholder 2", resctively.
+
+#P1                 *                  // Value of P1
+#P2                 *                  // Value of P2
--
libgit2 0.21.2