Commit 0ba18a3d authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

example/cdi_write_relativ.c added.

parent 4b999370
......@@ -2,8 +2,7 @@
#
EXTRA_DIST = cdi_read_f2003.f90 cdi_write_f2003.f90
#
noinst_PROGRAMS = cdi_write cdi_write_ens cdi_write_hybrid cdi_read \
cdi_copy
noinst_PROGRAMS = cdi_write cdi_write_relativ cdi_write_ens cdi_write_hybrid cdi_read cdi_copy
if CREATE_ISOC
noinst_PROGRAMS += cdi_read_f2003 cdi_write_f2003
endif
......@@ -17,9 +16,11 @@ LDADD = $(top_builddir)/src/libcdi.la
#
cdi_write_SOURCES = cdi_write.c
#
cdi_write_relativ_SOURCES = cdi_write_relativ.c
#
cdi_write_ens_SOURCES = cdi_write_ens.c
#
cdi_write_const_SOURCES = cdi_write_const.c
cdi_write_const_SOURCES = cdi_write_const.c
#
cdi_write_hybrid_SOURCES = cdi_write_hybrid.c
#
......
......@@ -78,9 +78,10 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
noinst_PROGRAMS = cdi_write$(EXEEXT) cdi_write_ens$(EXEEXT) \
cdi_write_hybrid$(EXEEXT) cdi_read$(EXEEXT) cdi_copy$(EXEEXT) \
$(am__EXEEXT_1) $(am__EXEEXT_2)
noinst_PROGRAMS = cdi_write$(EXEEXT) cdi_write_relativ$(EXEEXT) \
cdi_write_ens$(EXEEXT) cdi_write_hybrid$(EXEEXT) \
cdi_read$(EXEEXT) cdi_copy$(EXEEXT) $(am__EXEEXT_1) \
$(am__EXEEXT_2)
@CREATE_ISOC_TRUE@am__append_1 = cdi_read_f2003 cdi_write_f2003
@ENABLE_NETCDF_TRUE@am__append_2 = cdi_write_const
subdir = examples
......@@ -179,6 +180,10 @@ am_cdi_write_hybrid_OBJECTS = cdi_write_hybrid.$(OBJEXT)
cdi_write_hybrid_OBJECTS = $(am_cdi_write_hybrid_OBJECTS)
cdi_write_hybrid_LDADD = $(LDADD)
cdi_write_hybrid_DEPENDENCIES = $(top_builddir)/src/libcdi.la
am_cdi_write_relativ_OBJECTS = cdi_write_relativ.$(OBJEXT)
cdi_write_relativ_OBJECTS = $(am_cdi_write_relativ_OBJECTS)
cdi_write_relativ_LDADD = $(LDADD)
cdi_write_relativ_DEPENDENCIES = $(top_builddir)/src/libcdi.la
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
......@@ -231,11 +236,13 @@ am__v_FCLD_1 =
SOURCES = $(cdi_copy_SOURCES) $(cdi_read_SOURCES) \
$(cdi_read_f2003_SOURCES) $(cdi_write_SOURCES) \
$(cdi_write_const_SOURCES) $(cdi_write_ens_SOURCES) \
$(cdi_write_f2003_SOURCES) $(cdi_write_hybrid_SOURCES)
$(cdi_write_f2003_SOURCES) $(cdi_write_hybrid_SOURCES) \
$(cdi_write_relativ_SOURCES)
DIST_SOURCES = $(cdi_copy_SOURCES) $(cdi_read_SOURCES) \
$(cdi_read_f2003_SOURCES) $(cdi_write_SOURCES) \
$(cdi_write_const_SOURCES) $(cdi_write_ens_SOURCES) \
$(cdi_write_f2003_SOURCES) $(cdi_write_hybrid_SOURCES)
$(cdi_write_f2003_SOURCES) $(cdi_write_hybrid_SOURCES) \
$(cdi_write_relativ_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
......@@ -457,6 +464,8 @@ LDADD = $(top_builddir)/src/libcdi.la
#
cdi_write_SOURCES = cdi_write.c
#
cdi_write_relativ_SOURCES = cdi_write_relativ.c
#
cdi_write_ens_SOURCES = cdi_write_ens.c
#
cdi_write_const_SOURCES = cdi_write_const.c
......@@ -555,6 +564,10 @@ cdi_write_hybrid$(EXEEXT): $(cdi_write_hybrid_OBJECTS) $(cdi_write_hybrid_DEPEND
@rm -f cdi_write_hybrid$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(cdi_write_hybrid_OBJECTS) $(cdi_write_hybrid_LDADD) $(LIBS)
cdi_write_relativ$(EXEEXT): $(cdi_write_relativ_OBJECTS) $(cdi_write_relativ_DEPENDENCIES) $(EXTRA_cdi_write_relativ_DEPENDENCIES)
@rm -f cdi_write_relativ$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(cdi_write_relativ_OBJECTS) $(cdi_write_relativ_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
......@@ -567,6 +580,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdi_write_const.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdi_write_ens.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdi_write_hybrid.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdi_write_relativ.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
......
#include <stdio.h>
#include "cdi.h"
int main(void)
{
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 = 0;
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 var2[nlon*nlat*nlev];
// Create a regular lon/lat grid
int gridID = gridCreate(GRID_LONLAT, nlon*nlat);
gridDefXsize(gridID, nlon);
gridDefYsize(gridID, nlat);
gridDefXvals(gridID, lons);
gridDefYvals(gridID, lats);
// Create a surface level Z-axis
int zaxisID1 = zaxisCreate(ZAXIS_SURFACE, 1);
// Create a pressure level Z-axis
int zaxisID2 = zaxisCreate(ZAXIS_PRESSURE, nlev);
zaxisDefLevels(zaxisID2, levs);
// Create a variable list
int vlistID = vlistCreate();
// Define the variables
int varID1 = vlistDefVar(vlistID, gridID, zaxisID1, TSTEP_INSTANT);
int varID2 = vlistDefVar(vlistID, gridID, zaxisID2, TSTEP_INSTANT);
// Define the variable names
vlistDefVarName(vlistID, varID1, "varname1");
vlistDefVarName(vlistID, varID2, "varname2");
// Create a Time axis
int taxisID = taxisCreate(TAXIS_RELATIVE);
// Assign the Time axis to the variable list
vlistDefTaxis(vlistID, taxisID);
// Create a dataset in netCDF format
int streamID = streamOpenWrite("example.nc", CDI_FILETYPE_NC);
if ( streamID < 0 )
{
fprintf(stderr, "%s\n", cdiStringError(streamID));
return 1;
}
// Assign the variable list to the dataset
streamDefVlist(streamID, vlistID);
// Loop over the number of time steps
for ( int tsID = 0; tsID < nts; tsID++ )
{
// Set the verification date to 1985-01-01 + tsID
taxisDefVdate(taxisID, 19850101+tsID);
// Set the verification time to 12:00:00
taxisDefVtime(taxisID, 120000);
// Define the time step
streamDefTimestep(streamID, tsID);
// Init var1 and var2
for ( int i = 0; i < nlon*nlat; i++ ) var1[i] = 1.1;
for ( int i = 0; i < nlon*nlat*nlev; i++ ) var2[i] = 2.2;
// Write var1 and var2
streamWriteVar(streamID, varID1, var1, nmiss);
streamWriteVar(streamID, varID2, var2, nmiss);
}
// Close the output stream
streamClose(streamID);
// Destroy the objects
vlistDestroy(vlistID);
taxisDestroy(taxisID);
zaxisDestroy(zaxisID1);
zaxisDestroy(zaxisID2);
gridDestroy(gridID);
return 0;
}
Supports Markdown
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