DDtimedump.c
2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*----------------- 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);
}