DDtimedump.c 2.94 KB
/*----------------- REFRESH ------------------------------*/
/*                  v.2.0
 * authors:       Andrey O. Fedorov, V.Grushin
 * Insitution:    
 * date :         aug 28,1997
 * sinopsis:
 *     aug 28, 2009 - New netCDF

 * usage DDtimedump nc_times_file
 *
 * Description:
 * The program reads the output of the rehash program and reformats
 * the data for more conveniet reading form:
 * 
 *
 * Dimensions:
 * 
 * TimeLength  17
 * NameLength  
 * Record      Unlimited
 * Variables:
 *
 * char StartTime[TIMELENGTH]
 * char EndTime[TIMELENGTH]
 * 
 * Attributes:
 * none
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <netcdf.h>

/* Global Constant definitions */

#define TIME_LENGTH_NAME "TimeLength"
#define TIME_LENGTH 17L
#define REC_DIM_NAME "record"
#define REC_DIM NC_UNLIMITED
#define NAME_DIM_NAME "NameLength"
#define NAME_DIM 32L

#define SUM_DIM_NAME  "SummaryLength"
#define SUM_DIM 68L 

#define STARTTIME "StartTime"
#define STOPTIME   "StopTime"
#define FILENAME   "FileName"

#define SUMMARY  "Summary"

#define TIME_TYPE NC_CHAR

/*--------------------- MAIN --------------------------------*/
 
main(int argc, char **argv)
 
{
   static char description[] = "usage: DDtimedump nc_times_file ";

   char Start[TIME_LENGTH],
        Stop [TIME_LENGTH],
        Name [NAME_DIM],
        Sum [SUM_DIM];

/* NC definitions */
   int tmID, sumID;  /* nc file descriptor */
   int TlDimID,RecDimID, NlDimID, SumDimID;  /* ID of dimensions */
   
   size_t TimeStart[2] = {0L,0L};
   size_t DataStart[1] = {0L};
   size_t DataCount[1] = {TIME_LENGTH};
   size_t TimeCount[2] = {1L,TIME_LENGTH};
   size_t NameCount[2] = {1L, NAME_DIM};
   size_t SumCount[2]  = {1L, SUM_DIM};
   int DimVector[2];
   long RN = 0;

/* Times files definitions */
   int StartID, StopID,NameID;
   int DataStartID, DataStopID;
   int SumInfoID;
   char tmName[NAME_DIM];
   int i,okget,status;

 //  ncopts = NC_VERBOSE;
/*-----------------------------------------------------------------*/
/*
 * Check arguments
 */
   if(argc != 2)  {fprintf(stderr,"argc=%d \n %s\n",
				      argc,description); exit(1); }
/*-----------------------------------------------------------------*/
/*
 * Opening the rehash-created ncdf file 
 */

     status = nc_open(argv[1],NC_NOWRITE,&tmID);
 
     status = nc_inq_varid(tmID, STARTTIME, &StartID);
     status  = nc_inq_varid(tmID, STOPTIME, &StopID);
     status  = nc_inq_varid(tmID, FILENAME, &NameID);
 
     do
      {     
               
       status = nc_get_vara_text(tmID,StartID,TimeStart,TimeCount, Start);
       status = nc_get_vara_text(tmID,StopID ,TimeStart,TimeCount, Stop );
       status = nc_get_vara_text(tmID,NameID ,TimeStart,NameCount, Name );
 
       strcpy(Sum,Start);
       strcat(Sum," ");
       strcat(Sum,Stop);
       strcat(Sum," ");
       strcat(Sum,Name);
       printf("%s \n",Sum);


       TimeStart[0]++;
      } while(status == NC_NOERR);

   nc_close(tmID);
   
   return(0);
}