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

Added example/cdi_write_local.c

parent f106ce3e
......@@ -24,7 +24,7 @@ case "${HOSTNAME}" in
--enable-iso-c-interface \
--enable-swig \
--enable-python \
--with-eccodes=$HOME/local/eccodes-2.3.0 \
--with-eccodes=$HOME/local/eccodes-2.6.0 \
--with-netcdf=$HOME/local/netcdf-4.4.1.1 \
--with-szlib=$HOME/local \
CC=icc CFLAGS="-g -D_REENTRANT -Wall -Wwrite-strings -O3 -march=native -fp-model source"
......@@ -35,10 +35,10 @@ case "${HOSTNAME}" in
--enable-iso-c-interface \
--enable-swig \
--enable-python \
--with-eccodes=$HOME/local/eccodes-2.3.0 \
--with-eccodes=$HOME/local/eccodes-2.6.0 \
--with-netcdf=$HOME/local/netcdf-4.4.1.1 \
--with-szlib=$HOME/local \
LDFLAGS="-Wl,-rpath,$HOME/local/eccodes-2.3.0/lib" \
LDFLAGS="-Wl,-rpath,$HOME/local/eccodes-2.6.0/lib" \
CC=gcc CFLAGS="-g -pipe -D_REENTRANT -Wall -Wwrite-strings -W -Wfloat-equal -pedantic -O3 -march=native"
;;
cinglung*|feilung*|wanglung*)
......
......@@ -2,7 +2,7 @@
#
EXTRA_DIST = cdi_read_f2003.f90 cdi_write_f2003.f90
#
noinst_PROGRAMS = cdi_write cdi_write_relativ cdi_write_ens cdi_write_hybrid cdi_read cdi_copy
noinst_PROGRAMS = cdi_write cdi_write_relativ cdi_write_ens cdi_write_hybrid cdi_write_local cdi_read cdi_copy
if CREATE_ISOC
noinst_PROGRAMS += cdi_read_f2003 cdi_write_f2003
endif
......@@ -15,17 +15,12 @@ AM_FCFLAGS = $(FPP_INCOPT)$(top_srcdir)/src $(FC_MOD_FLAG)../src
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_hybrid_SOURCES = cdi_write_hybrid.c
#
cdi_write_local_SOURCES = cdi_write_local.c
cdi_read_SOURCES = cdi_read.c
#
cdi_copy_SOURCES = cdi_copy.c
#
cdi_read_f2003_SOURCES = cdi_read_f2003.f90
......
......@@ -80,8 +80,8 @@ build_triplet = @build@
host_triplet = @host@
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)
cdi_write_local$(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
......@@ -180,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_local_OBJECTS = cdi_write_local.$(OBJEXT)
cdi_write_local_OBJECTS = $(am_cdi_write_local_OBJECTS)
cdi_write_local_LDADD = $(LDADD)
cdi_write_local_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)
......@@ -237,12 +241,12 @@ 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_relativ_SOURCES)
$(cdi_write_local_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_relativ_SOURCES)
$(cdi_write_local_SOURCES) $(cdi_write_relativ_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
......@@ -473,17 +477,12 @@ AM_FCFLAGS = $(FPP_INCOPT)$(top_srcdir)/src $(FC_MOD_FLAG)../src
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_hybrid_SOURCES = cdi_write_hybrid.c
#
cdi_write_local_SOURCES = cdi_write_local.c
cdi_read_SOURCES = cdi_read.c
#
cdi_copy_SOURCES = cdi_copy.c
#
cdi_read_f2003_SOURCES = cdi_read_f2003.f90
......@@ -574,6 +573,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_local$(EXEEXT): $(cdi_write_local_OBJECTS) $(cdi_write_local_DEPENDENCIES) $(EXTRA_cdi_write_local_DEPENDENCIES)
@rm -f cdi_write_local$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(cdi_write_local_OBJECTS) $(cdi_write_local_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)
......@@ -590,6 +593,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_local.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdi_write_relativ.Po@am__quote@
.c.o:
......
#include <stdio.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 gridID, zaxisID1, zaxisID2, taxisID;
int vlistID, varID1, varID2, streamID;
size_t nmiss = 0;
double lons[nlon] = {0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330};
double lats[nlat] = {-75, -45, -15, 15, 45, 75};
double levs[nlev] = {101300, 92500, 85000, 50000, 20000};
double var1[nlon*nlat];
double var2[nlon*nlat*nlev];
// Create a regular lon/lat grid
gridID = gridCreate(GRID_LONLAT, nlon*nlat);
gridDefXsize(gridID, nlon);
gridDefYsize(gridID, nlat);
gridDefXvals(gridID, lons);
gridDefYvals(gridID, lats);
// Create a surface level Z-axis
zaxisID1 = zaxisCreate(ZAXIS_SURFACE, 1);
// Create a pressure level Z-axis
zaxisID2 = zaxisCreate(ZAXIS_PRESSURE, nlev);
zaxisDefLevels(zaxisID2, levs);
// Create a variable list
vlistID = vlistCreate();
// Define the variables
varID1 = vlistDefVar(vlistID, gridID, zaxisID1, TSTEP_AVG);
varID2 = vlistDefVar(vlistID, gridID, zaxisID2, TIME_VARYING);
// Define the variable names
vlistDefVarName(vlistID, varID1, "varname1");
vlistDefVarName(vlistID, varID2, "varname2");
cdiDefKeyInt(vlistID, varID1, CDI_KEY_TYPEOFGENERATINGPROCESS, 4);
// Create a Time axis
taxisID = taxisCreate(TAXIS_ABSOLUTE);
// Assign the Time axis to the variable list
vlistDefTaxis(vlistID, taxisID);
// Create a dataset in netCDF format
streamID = streamOpenWrite("example_loc.grb", CDI_FILETYPE_GRB2);
if ( streamID < 0 )
{
fprintf(stderr, "%s\n", cdiStringError(streamID));
return(1);
}
// Assign the variable list to the dataset
streamDefVlist(streamID, vlistID);
int vlistID0 = streamInqVlist(streamID);
printf("vlist ID %d %d\n", vlistID, vlistID0);
for ( int varID = 0; varID < 2; ++varID )
{
vlistDefVarIntKey(vlistID0, varID, "centre", 252);
vlistDefVarIntKey(vlistID0, varID, "subCentre", 2);
vlistDefVarIntKey(vlistID0, varID, "grib2LocalSectionPresent", 1);
vlistDefVarIntKey(vlistID0, varID, "grib2LocalSectionNumber", 1);
vlistDefVarIntKey(vlistID0, varID, "localDefinitionNumber", 1);
vlistDefVarIntKey(vlistID0, varID, "mpimType", 1);
vlistDefVarIntKey(vlistID0, varID, "mpimClass", 2);
vlistDefVarIntKey(vlistID0, varID, "mpimUser", 1403);
// vlistDefVarIntKey(vlistID0, varID, "shortendRevNo", 99);
}
// 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);
vlistDefVarIntKey(vlistID0, varID1, "dataTime", 1200+(tsID+1)*10);
// Init var1 and var2
for ( size_t i = 0; i < nlon*nlat; i++ ) var1[i] = 1.1;
for ( size_t 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;
}
......@@ -959,8 +959,8 @@ distclean-generic:
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
@ENABLE_CDI_LIB_FALSE@install-exec-local:
@ENABLE_CDI_LIB_FALSE@uninstall-local:
@ENABLE_CDI_LIB_FALSE@install-exec-local:
clean: clean-am
clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
......
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