Commit 72af9ddc authored by Florian Prill's avatar Florian Prill
Browse files

[cdi-tiles] Imported prototype implementation of CDI tiles.

parent 3369d52d
......@@ -14,6 +14,9 @@ app/Makefile.in -text
app/cdi.c -text
app/createtable.c -text
app/printinfo.h -text
basic_test/Makefile -text
basic_test/example.f90 -text
basic_test/main.c -text
/cdi.settings.in -text
config/compile -text
config/config.guess -text
......@@ -28,6 +31,7 @@ config/missing -text
config/mkinstalldirs -text
/configure -text
/configure.ac -text
/do_configure.sh -text
doc/Doxyfile -text
doc/cdi_cman.pdf -text
doc/cdi_fman.pdf -text
......@@ -295,6 +299,8 @@ src/stream_record.c -text
src/stream_srv.c -text
src/stream_srv.h -text
src/stream_var.c -text
src/subtype.c -text
src/subtype.h -text
src/swap.c -text
src/swap.h -text
src/table.c -text
......
CFLAGS = -O0 -g -fstack-protector-all --std=c99
all:
gcc ${CFLAGS} -I../build/include -c main.c -o main.o
gcc -L../build/lib64 main.o -lcdi -o main
fortran:
gcc ${CFLAGS} -DHAVE_CF_INTERFACE -DHAVE_LIBNETCDF -DHAVE_LIBGRIB -DHAVE_LIBGRIB_API -I/opt/grib_api/include -c ../src/cdilib.c -o cdilib.o
gfortran -I../build/include cdilib.o example.f90 -L/opt/grib_api/lib64 -lgrib_api -ljasper -lnetcdff -lnetcdf -o example
run:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../build/lib64 ./main
runfortran:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../build/lib64:/opt/grib_api/lib64 ./example
clean:
rm -f main main.o example cdilib.o
PROGRAM example
INCLUDE "cdi.inc"
INTEGER, PARAMETER :: identificationNumberOfTile = 4
INTEGER, PARAMETER :: attribute = 4
INTEGER, PARAMETER :: wp = SELECTED_REAL_KIND(12,307)
INTEGER :: streamID, vlistID, varID, subtypeID, gridID, &
& nvars, tile_index, size, nmiss
REAL(wp), ALLOCATABLE :: data_vec(:)
CHARACTER(LEN=128) :: name
WRITE (0,*) "cdi-tiles example"
! Register additional GRIB keys which are read when file is opened.
CALL cdiDefAdditionalKey("identificationNumberOfTile")
CALL cdiDefAdditionalKey("attribute")
streamID = streamOpenRead("NWP_tiles_test.grb")
! streamID = streamOpenRead("NWP_tiles_test.nc")
vlistID = streamInqVlist(streamID)
nvars = streamInqNvars(streamID)
! loop over variables
DO varID=0,(nvars-1)
CALL vlistInqVarName(vlistID, varID, name);
subtypeID = vlistInqVarSubtype(vlistID, varID)
tile_index = subtypeInqTile(subtypeID, identificationNumberOfTile, attribute)
IF (tile_index /= CDI_UNDEFID) THEN
CALL subtypeDefActiveIndex(subtypeID, tile_index)
WRITE (0,*) "VAR ", TRIM(name)
WRITE (0,*) " identificationNumberOfTile = ", &
& vlistInqVarIntKey(vlistID, varID, "identificationNumberOfTile")
WRITE (0,*) " attribute = ", &
& vlistInqVarIntKey(vlistID, varID, "attribute")
! query grid size, allocate buffer
gridID = vlistInqVarGrid(vlistID, varID)
size = gridInqSize(gridID)
ALLOCATE(data_vec(size))
CALL streamReadVarSlice(streamID, varID, 0, data_vec, nmiss)
WRITE (0,*) " first val=", data_vec(1)
DEALLOCATE(data_vec)
ELSE
WRITE (0,*) "VAR ", TRIM(name), ": no matching record found!"
END IF
END DO
CALL streamClose(streamID)
END PROGRAM example
#include <stdlib.h>
#include <cdi.h>
int main(void) {
printf("\ncdi-tiles example\n-----------------\n\n");
/* Register additional GRIB keys which are read when file is opened. */
cdiDefAdditionalKey("identificationNumberOfTile");
cdiDefAdditionalKey("attribute");
int streamID = streamOpenRead("NWP_tiles_test.grb");
/* loop over variables */
int vlistID = streamInqVlist(streamID);
int nvars = streamInqNvars(streamID);
int
identificationNumberOfTile = 4,
attribute = 4;
printf("identificationNumberOfTile = %d\n", identificationNumberOfTile);
printf("attribute = %d\n\n", attribute);
for (int varID=0; varID<nvars; varID++)
{
int subtypeID = vlistInqVarSubtype(vlistID, varID);
int tile_index = subtypeInqTile(subtypeID, identificationNumberOfTile, attribute);
char name[CDI_MAX_NAME];
vlistInqVarName(vlistID, varID, name);
if (tile_index != CDI_UNDEFID) {
subtypeDefActiveIndex(subtypeID, tile_index);
printf("variable %-10.10s: subentry ID = %d\n", name, tile_index);
printf(" identificationNumberOfTile = %d\n",
vlistInqVarIntKey(vlistID, varID, "identificationNumberOfTile"));
printf(" attribute = %d\n",
vlistInqVarIntKey(vlistID, varID, "attribute"));
/* query grid size, allocate buffer */
int gridID = vlistInqVarGrid(vlistID, varID);
int size = gridInqSize(gridID);
double* data_vec = (double*) malloc(size*sizeof(double));
int nmiss;
streamReadVarSlice(streamID, varID, 0, data_vec, &nmiss);
double avg = 0;
for (int i=0; i<size; i++)
avg += data_vec[i];
avg /= size;
printf(" first val=%e, average: %6.3f\n", data_vec[0], avg);
free(data_vec);
} else {
printf("variable %-10.10s: no matching record found!\n", name);
}
}
streamClose(streamID);
printf("done.\n");
return 0;
}
LDFLAGS=-L/opt/grib_api/lib64 \
./configure --prefix=$HOME/CDI/branches/cdi-tiles/build \
--with-netcdf=yes --with-grib-api=/opt/grib_api
......@@ -22,6 +22,15 @@ Clear the list of additional GRIB keys..
Register an additional GRIB key which is read when file is opened..
\section*{\tt \htmlref{cdiGetStringError}{cdiGetStringError}}
\begin{verbatim}
void cdiGetStringError (int vlistID, char *name);
\end{verbatim}
Get CDI error String.
\section*{\tt \htmlref{gridCreate}{gridCreate}}
\begin{verbatim}
......@@ -618,6 +627,51 @@ Write a variable.
Write a horizontal slice of a variable.
\section*{\tt \htmlref{subtypeCreate}{subtypeCreate}}
\begin{verbatim}
int subtypeCreate (int subtype);
\end{verbatim}
Create a variable subtype.
\section*{\tt \htmlref{subtypeDefActiveIndex}{subtypeDefActiveIndex}}
\begin{verbatim}
void subtypeDefActiveIndex (int subtypeID, int index);
\end{verbatim}
Set the currently active index of a subtype (e.g. current tile index)..
\section*{\tt \htmlref{subtypeInqActiveIndex}{subtypeInqActiveIndex}}
\begin{verbatim}
int subtypeInqActiveIndex (int subtypeID);
\end{verbatim}
Get the currently active index of a subtype (e.g. current tile index)..
\section*{\tt \htmlref{subtypeInqSize}{subtypeInqSize}}
\begin{verbatim}
int subtypeInqSize (int subtypeID);
\end{verbatim}
Get the size of a subtype (e.g. no. of tiles)..
\section*{\tt \htmlref{subtypeInqTile}{subtypeInqTile}}
\begin{verbatim}
int subtypeInqTile (int subtypeID, int identificationNumberOfTile, int attribute);
\end{verbatim}
Specialized version of subtypeInqSubEntry looking for tile/attribute pair..
\section*{\tt \htmlref{taxisCreate}{taxisCreate}}
\begin{verbatim}
......@@ -843,7 +897,7 @@ Define the time axis of a variable list.
int vlistDefVar (int vlistID, int gridID, int zaxisID, int tsteptype);
\end{verbatim}
Create a new Variable.
Create a new variable.
\section*{\tt \htmlref{vlistDefVarCode}{vlistDefVarCode}}
......@@ -1120,6 +1174,15 @@ Get the parameter number of a Variable.
Get the standard name of a Variable.
\section*{\tt \htmlref{vlistInqVarSubtype}{vlistInqVarSubtype}}
\begin{verbatim}
int vlistInqVarSubtype (int vlistID, int varID);
\end{verbatim}
Return subtype ID for a given variable..
\section*{\tt \htmlref{vlistInqVarUnits}{vlistInqVarUnits}}
\begin{verbatim}
......
......@@ -22,6 +22,15 @@ Clear the list of additional GRIB keys..
Register an additional GRIB key which is read when file is opened..
\section*{\tt \htmlref{cdiGetStringError}{cdiGetStringError}}
\begin{verbatim}
SUBROUTINE cdiGetStringError (INTEGER vlistID, CHARACTER*(*) name)
\end{verbatim}
Get CDI error String.
\section*{\tt \htmlref{gridCreate}{gridCreate}}
\begin{verbatim}
......@@ -620,6 +629,53 @@ Write a variable.
Write a horizontal slice of a variable.
\section*{\tt \htmlref{subtypeCreate}{subtypeCreate}}
\begin{verbatim}
INTEGER FUNCTION subtypeCreate (INTEGER subtype)
\end{verbatim}
Create a variable subtype.
\section*{\tt \htmlref{subtypeDefActiveIndex}{subtypeDefActiveIndex}}
\begin{verbatim}
SUBROUTINE subtypeDefActiveIndex (INTEGER subtypeID, INTEGER index)
\end{verbatim}
Set the currently active index of a subtype (e.g. current tile index)..
\section*{\tt \htmlref{subtypeInqActiveIndex}{subtypeInqActiveIndex}}
\begin{verbatim}
INTEGER FUNCTION subtypeInqActiveIndex (INTEGER subtypeID)
\end{verbatim}
Get the currently active index of a subtype (e.g. current tile index)..
\section*{\tt \htmlref{subtypeInqSize}{subtypeInqSize}}
\begin{verbatim}
INTEGER FUNCTION subtypeInqSize (INTEGER subtypeID)
\end{verbatim}
Get the size of a subtype (e.g. no. of tiles)..
\section*{\tt \htmlref{subtypeInqTile}{subtypeInqTile}}
\begin{verbatim}
INTEGER FUNCTION subtypeInqTile (INTEGER subtypeID,
INTEGER identificationNumberOfTile,
INTEGER attribute)
\end{verbatim}
Specialized version of subtypeInqSubEntry looking for tile/attribute pair..
\section*{\tt \htmlref{taxisCreate}{taxisCreate}}
\begin{verbatim}
......@@ -849,7 +905,7 @@ Define the time axis of a variable list.
INTEGER tsteptype)
\end{verbatim}
Create a new Variable.
Create a new variable.
\section*{\tt \htmlref{vlistDefVarCode}{vlistDefVarCode}}
......@@ -1139,6 +1195,15 @@ Get the parameter number of a Variable.
Get the standard name of a Variable.
\section*{\tt \htmlref{vlistInqVarSubtype}{vlistInqVarSubtype}}
\begin{verbatim}
INTEGER FUNCTION vlistInqVarSubtype (INTEGER vlistID, INTEGER varID)
\end{verbatim}
Return subtype ID for a given variable..
\section*{\tt \htmlref{vlistInqVarUnits}{vlistInqVarUnits}}
\begin{verbatim}
......
......@@ -79,7 +79,7 @@ static void modelRun(MPI_Comm commModel)
#endif
for ( i = 0; i < nVars; i++ )
{
varID[i] = vlistDefVar ( vlistID, gridID, zaxisID[i], TIME_VARIABLE );
varID[i] = vlistDefVar ( vlistID, gridID, zaxisID[i], TIME_VARIABLE);
#ifdef USE_MPI
{
int start = uniform_partition_start((int [2]){ 0, (int)varSize[i] - 1 },
......
......@@ -104,7 +104,7 @@ static void modelRun(MPI_Comm commModel)
for ( j = 0; j < nVars; j++ )
{
varID[i][j] = vlistDefVar(vlistID[i], gridID, zaxisID[i][j],
TIME_VARIABLE );
TIME_VARIABLE);
varSize[i][j] = nlon * nlat * (size_t)nlev[i][j];
#ifdef USE_MPI
{
......
......@@ -157,7 +157,7 @@ am_libcdi_la_OBJECTS = basetime.lo binary.lo calendar.lo cdf.lo \
stream_fcommon.lo cdi_int.lo stream_record.lo stream_srv.lo \
stream_var.lo table.lo taxis.lo timebase.lo tsteps.lo util.lo \
varscan.lo version.lo vlist.lo vlist_att.lo vlist_var.lo \
zaxis.lo stream.lo swap.lo
zaxis.lo stream.lo swap.lo subtype.lo
libcdi_la_OBJECTS = $(am_libcdi_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
......@@ -538,7 +538,9 @@ libcdi_la_SOURCES = \
zaxis.c \
zaxis.h \
stream.c \
swap.c
swap.c \
subtype.c \
subtype.h
libcdiresunpack_la_SOURCES = \
resource_unpack.c
......@@ -769,6 +771,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vlist_att.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vlist_var.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zaxis.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/subtype.Plo@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
......
......@@ -168,6 +168,37 @@ extern "C" {
#define ZAXIS_MIX_LAYER 24 /* Mixing Layer */
#define ZAXIS_REFERENCE 25 /* zaxis reference number */
/* SUBTYPE types */
enum {
SUBTYPE_TILES = 0 /* Tiles variable */
} subtype_kind;
#define MAX_KV_PAIRS_MATCH 10
/* Data structure defining a key-value search, possibly with multiple
key-value pairs in combination.
Currently, only multiple pairs combined by AND are supported.
*/
typedef struct {
int nAND; /* no. of key-value pairs that have to match */
int key_value_pairs[2][MAX_KV_PAIRS_MATCH]; /* key-value pairs */
} subtype_query_t;
enum {
/* subtype attributes wrt. TILES */
SUBTYPE_ATT_IDENTIFICATION_NO_OF_TILE = 0,
SUBTYPE_ATT_IDENTIFICATION_NO_OF_ATTR = 1,
SUBTYPE_ATT_TILE_CLASSIFICATION = 2,
SUBTYPE_ATT_NUMBER_OF_TILES = 3,
SUBTYPE_ATT_NUMBER_OF_ATTR = 4,
SUBTYPE_ATT_ATTRIBUTE = 5
} subtype_attributes;
/* TIME types */
#define TIME_CONSTANT 0 /* obsolate, use TSTEP_CONSTANT */
......@@ -228,6 +259,11 @@ void cdiReset(void);
const char *cdiStringError(int cdiErrno);
/* cdiGetStringError: Get CDI error String */
/* Wrapper for cdiStringError, since direct use of */
/* cdiStringError results in SEGFAULT with Cray compiler */
void cdiGetStringError(int vlistID, char *name);
void cdiDebug(int debug);
const char *cdiLibraryVersion(void);
......@@ -426,7 +462,10 @@ int vlistInqModel(int vlistID);
/* VLIST VAR routines */
/* vlistDefVar: Create a new Variable */
/* vlistDefVar: Create a new tile-based variable */
int vlistDefVarTiles(int vlistID, int gridID, int zaxisID, int tsteptype, int tilesetID);
/* vlistDefVar: Create a new variable */
int vlistDefVar(int vlistID, int gridID, int zaxisID, int tsteptype);
void vlistChangeVarGrid(int vlistID, int varID, int gridID);
......@@ -1030,9 +1069,47 @@ void streamDefHistory(int streamID, int size, const char *history);
int streamInqHistorySize(int streamID);
void streamInqHistoryString(int streamID, char *history);
/* Subtype routines */
/* subtypeCreate: Create a variable subtype */
int subtypeCreate(int subtype);
/* Gives a textual summary of the variable subtype */
void subtypePrint(int subtypeID);
/* Compares two subtype data structures. */
int subtypeCompare(int subtypeID1, int subtypeID2);
/* subtypeInqSize: Get the size of a subtype (e.g. no. of tiles). */
int subtypeInqSize(int subtypeID);
/* subtypeInqActiveIndex: Get the currently active index of a subtype (e.g. current tile index). */
int subtypeInqActiveIndex(int subtypeID);
/* subtypeDefActiveIndex: Set the currently active index of a subtype (e.g. current tile index). */
void subtypeDefActiveIndex(int subtypeID, int index);
/* Generate a "query object" out of a key-value pair. */
subtype_query_t keyValuePair(const char* key, int value);
/* Generate an AND-combined "query object" out of two previous
query objects. */
subtype_query_t matchAND(subtype_query_t q1, subtype_query_t q2);
/* subtypeInqSubEntry: Returns subtype entry ID for a given criterion. */
int subtypeInqSubEntry(int subtypeID, subtype_query_t criterion);
/* subtypeInqTile: Specialized version of subtypeInqSubEntry looking for tile/attribute pair. */
int subtypeInqTile(int subtypeID, int identificationNumberOfTile, int attribute);
/* vlistInqVarSubtype: Return subtype ID for a given variable. */
int vlistInqVarSubtype(int vlistID, int varID);
void gribapiLibraryVersion(int *major_version, int *minor_version, int *revision_version);
/*
#if defined (__cplusplus)
}
......
......@@ -4,7 +4,7 @@
!
! Author:
! -------
! Uwe Schulzweida, MPI-MET, Hamburg, February 2015
! Uwe Schulzweida, MPI-MET, Hamburg, March 2015
!
INTEGER CDI_MAX_NAME
......@@ -285,6 +285,20 @@
INTEGER ZAXIS_REFERENCE
PARAMETER (ZAXIS_REFERENCE = 25)
!
! SUBTYPE types
!
INTEGER MAX_KV_PAIRS_MATCH
PARAMETER (MAX_KV_PAIRS_MATCH = 10)
!
! Data structure defining a key-value search, possibly with multiple
! key-value pairs in combination.
!
! Currently, only multiple pairs combined by AND are supported.
!
!
! subtype attributes wrt. TILES
!
!
! TIME types
!
INTEGER TIME_CONSTANT
......@@ -386,6 +400,17 @@
! (INTEGER cdiErrno)
EXTERNAL cdiStringError
!
! Wrapper for cdiStringError, since direct use of
!
!
! cdiStringError results in SEGFAULT with Cray compiler
!
! cdiGetStringError
! (INTEGER vlistID,
! CHARACTER*(*) name)
EXTERNAL cdiGetStringError
! cdiDebug
! (INTEGER debug)
EXTERNAL cdiDebug
......@@ -849,6 +874,14 @@
!
! VLIST VAR routines
!
INTEGER vlistDefVarTiles
! (INTEGER vlistID,
! INTEGER gridID,
! INTEGER zaxisID,
! INTEGER tsteptype,
! INTEGER tilesetID)
EXTERNAL vlistDefVarTiles
INTEGER vlistDefVar
! (INTEGER vlistID,
! INTEGER gridID,
......@@ -2362,6 +2395,59 @@
! CHARACTER*(*) history)
EXTERNAL streamInqHistoryString
!
! Subtype routines
!
INTEGER subtypeCreate
! (INTEGER subtype)
EXTERNAL subtypeCreate
!
! Gives a textual summary of the variable subtype
!
! subtypePrint
! (INTEGER subtypeID)
EXTERNAL subtypePrint
!
! Compares two subtype data structures.
!
INTEGER subtypeCompare
! (INTEGER subtypeID1,
! INTEGER subtypeID2)
EXTERNAL subtypeCompare
INTEGER subtypeInqSize
! (INTEGER subtypeID)
EXTERNAL subtypeInqSize
INTEGER subtypeInqActiveIndex
! (INTEGER subtypeID)
EXTERNAL subtypeInqActiveIndex
! subtypeDefActiveIndex
! (INTEGER subtypeID,
! INTEGER index)
EXTERNAL subtypeDefActiveIndex
!
! Generate a "query object" out of a key-value pair.
!
!
! Generate an AND-combined "query object" out of two previous
! query objects.
!
INTEGER subtypeInqTile
! (INTEGER subtypeID,
! INTEGER identificationNumberOfTile,
! INTEGER attribute)
EXTERNAL subtypeInqTile
INTEGER vlistInqVarSubtype
! (INTEGER vlistID,
! INTEGER varID)
EXTERNAL vlistInqVarSubtype
! gribapiLibraryVersion
! (INTEGER major_version,
! INTEGER minor_version,
......
......@@ -42,6 +42,18 @@
/* ZAXIS types */
/* SUBTYPE types */