Commit bd5e3c3f authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

Merge declaration and definition.

parent 3572162f
#include <stdio.h> #include <stdio.h>
#include "cdi.h" #include "cdi.h"
int nlon = 12; // Number of longitudes
int nlat = 6; // Number of latitudes
int nlev = 5; // Number of levels
int nts = 3; // Number of time steps
int main(void) int main(void)
{ {
int vlistID1, vlistID2, varID1, varID2, streamID1, streamID2, tsID; const int nlon = 12; // Number of longitudes
const int nlat = 6; // Number of latitudes
const int nlev = 5; // Number of levels
const int nts = 3; // Number of time steps
int nmiss; int nmiss;
double var1[nlon*nlat]; double var1[nlon*nlat];
double var2[nlon*nlat*nlev]; double var2[nlon*nlat*nlev];
// Open the input dataset // Open the input dataset
streamID1 = streamOpenRead("example.nc"); int streamID1 = streamOpenRead("example.nc");
if ( streamID1 < 0 ) if ( streamID1 < 0 )
{ {
fprintf(stderr, "%s\n", cdiStringError(streamID1)); fprintf(stderr, "%s\n", cdiStringError(streamID1));
return(1); return 1;
} }
// Get the variable list of the dataset // Get the variable list of the dataset
vlistID1 = streamInqVlist(streamID1); int vlistID1 = streamInqVlist(streamID1);
// Set the variable IDs // Set the variable IDs
varID1 = 0; int varID1 = 0;
varID2 = 1; int varID2 = 1;
// Open the output dataset (GRIB format) // Open the output dataset (GRIB format)
streamID2 = streamOpenWrite("example.grb", FILETYPE_GRB); int streamID2 = streamOpenWrite("example.grb", FILETYPE_GRB);
if ( streamID2 < 0 ) if ( streamID2 < 0 )
{ {
fprintf(stderr, "%s\n", cdiStringError(streamID2)); fprintf(stderr, "%s\n", cdiStringError(streamID2));
return(1); return 1;
} }
vlistID2 = vlistDuplicate(vlistID1); int vlistID2 = vlistDuplicate(vlistID1);
streamDefVlist(streamID2, vlistID2); streamDefVlist(streamID2, vlistID2);
// Loop over the number of time steps // Loop over the number of time steps
for ( tsID = 0; tsID < nts; tsID++ ) for ( int tsID = 0; tsID < nts; tsID++ )
{ {
// Inquire the input time step // Inquire the input time step
streamInqTimestep(streamID1, tsID); streamInqTimestep(streamID1, tsID);
......
#include <stdio.h> #include <stdio.h>
#include "cdi.h" #include "cdi.h"
int nlon = 12; // Number of longitudes
int nlat = 6; // Number of latitudes
int nlev = 5; // Number of levels
int nts = 3; // Number of time steps
int main(void) int main(void)
{ {
int taxisID, vlistID, varID1, varID2, streamID, tsID; const int nlon = 12; // Number of longitudes
const int nlat = 6; // Number of latitudes
const int nlev = 5; // Number of levels
const int nts = 3; // Number of time steps
int nmiss, vdate, vtime; int nmiss, vdate, vtime;
double var1[nlon*nlat]; double var1[nlon*nlat];
double var2[nlon*nlat*nlev]; double var2[nlon*nlat*nlev];
// Open the dataset // Open the dataset
streamID = streamOpenRead("example.nc"); int streamID = streamOpenRead("example.nc");
if ( streamID < 0 ) if ( streamID < 0 )
{ {
fprintf(stderr, "%s\n", cdiStringError(streamID)); fprintf(stderr, "%s\n", cdiStringError(streamID));
return(1); return 1;
} }
// Get the variable list of the dataset // Get the variable list of the dataset
vlistID = streamInqVlist(streamID); int vlistID = streamInqVlist(streamID);
// Set the variable IDs // Set the variable IDs
varID1 = 0; int varID1 = 0;
varID2 = 1; int varID2 = 1;
// Get the Time axis from the variable list // Get the Time axis from the variable list
taxisID = vlistInqTaxis(vlistID); int taxisID = vlistInqTaxis(vlistID);
// Loop over the number of time steps // Loop over the number of time steps
for ( tsID = 0; tsID < nts; tsID++ ) for ( int tsID = 0; tsID < nts; tsID++ )
{ {
// Inquire the time step // Inquire the time step
streamInqTimestep(streamID, tsID); streamInqTimestep(streamID, tsID);
......
#include <stdio.h> #include <stdio.h>
#include "cdi.h" #include "cdi.h"
#define nlon 12 // Number of longitudes
#define nlat 6 // Number of latitudes
#define nlev 5 // Number of levels
#define nts 3 // Number of time steps
int main(void) int main(void)
{ {
int gridID, zaxisID1, zaxisID2, taxisID; const int nlon = 12; // Number of longitudes
int vlistID, varID1, varID2, streamID, tsID; const int nlat = 6; // Number of latitudes
int i, nmiss = 0; const int nlev = 5; // Number of levels
double lons[nlon] = {0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330}; const int nts = 3; // Number of time steps
double lats[nlat] = {-75, -45, -15, 15, 45, 75}; int nmiss = 0;
double levs[nlev] = {101300, 92500, 85000, 50000, 20000}; double lons[] = {0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330};
double lats[] = {-75, -45, -15, 15, 45, 75};
double levs[] = {101300, 92500, 85000, 50000, 20000};
double var1[nlon*nlat]; double var1[nlon*nlat];
double var2[nlon*nlat*nlev]; double var2[nlon*nlat*nlev];
// Create a regular lon/lat grid // Create a regular lon/lat grid
gridID = gridCreate(GRID_LONLAT, nlon*nlat); int gridID = gridCreate(GRID_LONLAT, nlon*nlat);
gridDefXsize(gridID, nlon); gridDefXsize(gridID, nlon);
gridDefYsize(gridID, nlat); gridDefYsize(gridID, nlat);
gridDefXvals(gridID, lons); gridDefXvals(gridID, lons);
gridDefYvals(gridID, lats); gridDefYvals(gridID, lats);
// Create a surface level Z-axis // Create a surface level Z-axis
zaxisID1 = zaxisCreate(ZAXIS_SURFACE, 1); int zaxisID1 = zaxisCreate(ZAXIS_SURFACE, 1);
// Create a pressure level Z-axis // Create a pressure level Z-axis
zaxisID2 = zaxisCreate(ZAXIS_PRESSURE, nlev); int zaxisID2 = zaxisCreate(ZAXIS_PRESSURE, nlev);
zaxisDefLevels(zaxisID2, levs); zaxisDefLevels(zaxisID2, levs);
// Create a variable list // Create a variable list
vlistID = vlistCreate(); int vlistID = vlistCreate();
// Define the variables // Define the variables
varID1 = vlistDefVar(vlistID, gridID, zaxisID1, TSTEP_INSTANT); int varID1 = vlistDefVar(vlistID, gridID, zaxisID1, TSTEP_INSTANT);
varID2 = vlistDefVar(vlistID, gridID, zaxisID2, TSTEP_INSTANT); int varID2 = vlistDefVar(vlistID, gridID, zaxisID2, TSTEP_INSTANT);
// Define the variable names // Define the variable names
vlistDefVarName(vlistID, varID1, "varname1"); vlistDefVarName(vlistID, varID1, "varname1");
vlistDefVarName(vlistID, varID2, "varname2"); vlistDefVarName(vlistID, varID2, "varname2");
// Create a Time axis // Create a Time axis
taxisID = taxisCreate(TAXIS_ABSOLUTE); int taxisID = taxisCreate(TAXIS_ABSOLUTE);
// Assign the Time axis to the variable list // Assign the Time axis to the variable list
vlistDefTaxis(vlistID, taxisID); vlistDefTaxis(vlistID, taxisID);
// Create a dataset in netCDF format // Create a dataset in netCDF format
streamID = streamOpenWrite("example.nc", FILETYPE_NC); int streamID = streamOpenWrite("example.nc", FILETYPE_NC);
if ( streamID < 0 ) if ( streamID < 0 )
{ {
fprintf(stderr, "%s\n", cdiStringError(streamID)); fprintf(stderr, "%s\n", cdiStringError(streamID));
return(1); return 1;
} }
// Assign the variable list to the dataset // Assign the variable list to the dataset
streamDefVlist(streamID, vlistID); streamDefVlist(streamID, vlistID);
// Loop over the number of time steps // Loop over the number of time steps
for ( tsID = 0; tsID < nts; tsID++ ) for ( int tsID = 0; tsID < nts; tsID++ )
{ {
// Set the verification date to 1985-01-01 + tsID // Set the verification date to 1985-01-01 + tsID
taxisDefVdate(taxisID, 19850101+tsID); taxisDefVdate(taxisID, 19850101+tsID);
...@@ -71,8 +68,8 @@ int main(void) ...@@ -71,8 +68,8 @@ int main(void)
streamDefTimestep(streamID, tsID); streamDefTimestep(streamID, tsID);
// Init var1 and var2 // Init var1 and var2
for ( i = 0; i < nlon*nlat; i++ ) var1[i] = 1.1; for ( int i = 0; i < nlon*nlat; i++ ) var1[i] = 1.1;
for ( i = 0; i < nlon*nlat*nlev; i++ ) var2[i] = 2.2; for ( int i = 0; i < nlon*nlat*nlev; i++ ) var2[i] = 2.2;
// Write var1 and var2 // Write var1 and var2
streamWriteVar(streamID, varID1, var1, nmiss); streamWriteVar(streamID, varID1, var1, nmiss);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment