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
|
#include <stdio.h>
#include "cdi.h"
int
main(void)
{
enum
{
nlon = 12, // Number of longitudes
nlat = 6, // Number of latitudes
nlev = 5, // Number of levels
nts = 3, // Number of time steps
};
SizeType numMissVals;
double var1[nlon * nlat];
double var2[nlon * nlat * nlev];
// Open the dataset
int streamID = streamOpenRead("example.nc");
if (streamID < 0)
{
fprintf(stderr, "%s\n", cdiStringError(streamID));
return 1;
}
// Get the variable list of the dataset
int vlistID = streamInqVlist(streamID);
// Set the variable IDs
int varID1 = 0;
int varID2 = 1;
// Get the Time axis from the variable list
int taxisID = vlistInqTaxis(vlistID);
// Loop over the number of time steps
for (int tsID = 0; tsID < nts; tsID++)
{
// Inquire the time step
streamInqTimestep(streamID, tsID);
// Get the verification date and time
int vdate = taxisInqVdate(taxisID);
int vtime = taxisInqVtime(taxisID);
printf("read timestep %d: date=%d time=%d\n", tsID + 1, vdate, vtime);
// Read var1 and var2
streamReadVar(streamID, varID1, var1, &numMissVals);
streamReadVar(streamID, varID2, var2, &numMissVals);
}
// Close the input stream
streamClose(streamID);
return 0;
}
|