Commit 425ecc09 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

gridPrint: GME support

parent 8c0677bd
Uwe Schulzweida <schulzweida@dkrz.de>
Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
......@@ -3,6 +3,7 @@
* using GRIB library version 1.0.0
* rename *New functions to *Create
* stream_ieg: multiply pressure levels with 100 (report: Holger Goettel)
* gridPrint: GME support
* add dummy functions gridDestroy, zaxisDestroy, taxisDestroy
* Version 1.0.0 released
......
......@@ -5,6 +5,7 @@
\section{Write a dataset}
\begin{lstlisting}[frame=single, backgroundcolor=\color{zebg}, basicstyle=\footnotesize]
#include <stdio.h>
#include "cdi.h"
#define NLON 12 /* Number of longitudes */
......@@ -25,7 +26,7 @@ int main(void)
/* Create a regular lon/lat grid */
gridID = gridCreate(GRID_LONLAT, NLON*NLAT);
gridID = gridCreate(GRID_LONLAT, NLON*NLAT);
gridDefXsize(gridID, NLON);
gridDefYsize(gridID, NLAT);
gridDefXvals(gridID, lons);
......@@ -56,7 +57,12 @@ int main(void)
vlistDefTaxis(vlistID, taxisID);
/* Create a dataset in netCDF format */
streamID = streamOpenWrite("example.nc", FILETYPE_NC);
streamID = streamOpenWrite("example.nc", FILETYPE_NC);
if ( streamID < 0 )
{
fprintf(stderr, "%s\n", cdiStringError(streamID));
return(1);
}
/* Assign the variable list to the dataset */
streamDefVlist(streamID, vlistID);
......@@ -135,6 +141,7 @@ data:
\section{Read a dataset}
\begin{lstlisting}[frame=single, backgroundcolor=\color{zebg}, basicstyle=\footnotesize]
#include <stdio.h>
#include "cdi.h"
#define NLON 12 /* Number of longitudes */
......@@ -151,7 +158,12 @@ int main(void)
/* Open the dataset */
streamID = streamOpenRead("example.nc");
streamID = streamOpenRead("example.nc");
if ( streamID < 0 )
{
fprintf(stderr, "%s\n", cdiStringError(streamID));
return(1);
}
/* Get the variable list of the dataset */
vlistID = streamInqVlist(streamID);
......@@ -189,6 +201,7 @@ int main(void)
\section{Copy a dataset}
\begin{lstlisting}[frame=single, backgroundcolor=\color{zebg}, basicstyle=\footnotesize]
#include <stdio.h>
#include "cdi.h"
#define NLON 12 /* Number of longitudes */
......@@ -205,7 +218,12 @@ int main(void)
/* Open the input dataset */
streamID1 = streamOpenRead("example.nc");
streamID1 = streamOpenRead("example.nc");
if ( streamID1 < 0 )
{
fprintf(stderr, "%s\n", cdiStringError(streamID1));
return(1);
}
/* Get the variable list of the dataset */
vlistID1 = streamInqVlist(streamID1);
......@@ -217,8 +235,13 @@ int main(void)
/* Get the Time axis form the variable list */
taxisID = vlistInqTaxis(vlistID1);
/* Open the output dataset */
streamID2 = streamOpenWrite("example.grb", FILETYPE_GRB);
/* Open the output dataset (GRIB format) */
streamID2 = streamOpenWrite("example.grb", FILETYPE_GRB);
if ( streamID2 < 0 )
{
fprintf(stderr, "%s\n", cdiStringError(streamID2));
return(1);
}
vlistID2 = vlistDuplicate(vlistID1);
......
......@@ -31,20 +31,21 @@ Number of gridpoints.
\subsection*{Example}
Here is an example using {\tt gridCreate} to create a {\tt LONLAT} Grid:
Here is an example using {\tt gridCreate} to create a regular lon/lat Grid:
\begin{lstlisting}[backgroundcolor=\color{zebg}, basicstyle=\footnotesize]
#include <cdi.h>
#include "cdi.h"
...
#define NLON 12
#define NLAT 6
...
double lons[NLON] = {0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330};
double lats[NLAT] = {-75, -45, -15, 15, 45, 75};
int gridID;
int nlon = 12;
int nlat = 6;
double lons[nlon] = {0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330};
double lats[nlat] = {-75, -45, -15, 15, 45, 75};
...
gridID = gridCreate(GRID_LONLAT, nlon*nlat);
gridDefXsize(gridID, nlon);
gridDefYsize(gridID, nlat);
gridID = gridCreate(GRID_LONLAT, NLON*NLAT);
gridDefXsize(gridID, NLON);
gridDefYsize(gridID, NLAT);
gridDefXvals(gridID, lons);
gridDefYvals(gridID, lats);
...
......
......@@ -10,7 +10,7 @@ C compiler always looks, you must use the {\tt -I} option when invoking
the compiler, to specify a directory where {\tt cdi.h} is installed, for example:
\begin{verbatim}
cc -c -I/usr/local/cdi/include myprogram.f
cc -c -I/usr/local/cdi/include myprogram.c
\end{verbatim}
Alternatively, you could specify an absolute path name in the {\tt include}
......
......@@ -52,7 +52,7 @@ Here is an example using {\tt streamOpenWrite} to create a new netCDF file
named {\tt foo.nc} for writing:
\begin{lstlisting}[backgroundcolor=\color{zebg}, basicstyle=\footnotesize]
#include <cdi.h>
#include "cdi.h"
...
int streamID;
...
......@@ -111,7 +111,7 @@ Here is an example using {\tt streamOpenRead} to open an existing netCDF
file named {\tt foo.nc} for reading:
\begin{lstlisting}[backgroundcolor=\color{zebg}, basicstyle=\footnotesize]
#include <cdi.h>
#include "cdi.h"
...
int streamID;
...
......
......@@ -27,9 +27,26 @@ Number of levels
\subsection*{Result}
{\tt zaxisCreate} returns an identifier to the vertical Z-axis.
{\tt zaxisCreate} returns an identifier to the Z-axis.
\subsection*{Example}
Here is an example using {\tt zaxisCreate} to create a pressure level Z-axis:
\begin{lstlisting}[backgroundcolor=\color{zebg}, basicstyle=\footnotesize]
#include "cdi.h"
...
#define NLEV 5
...
double levs[NLEV] = {101300, 92500, 85000, 50000, 20000};
int zaxisID;
...
zaxisID = zaxisCreate(ZAXIS_PRESSURE, NLEV);
zaxisDefLevels(zaxisID, levs);
...
\end{lstlisting}
\section{Destroy a vertical Z-axis: {\tt zaxisDestroy}}
\index{zaxisDestroy}
......
......@@ -9,6 +9,8 @@
IMPLICIT NONE
INCLUDE 'cdi.inc'
INTEGER NLON, NLAT, NLEV, NTIME
PARAMETER (NLON = 12) ! Number of longitudes
PARAMETER (NLAT = 6) ! Number of latitudes
......@@ -25,12 +27,10 @@
DATA lats /-75, -45, -15, 15, 45, 75/
DATA levs /101300, 92500, 85000, 50000, 20000/
INCLUDE 'cdi.inc'
nmiss = 0
! Create a regular lon/lat grid
gridID = gridCreate(GRID_LONLAT, NLON*NLAT)
gridID = gridCreate(GRID_LONLAT, NLON*NLAT)
CALL gridDefXsize(gridID, NLON)
CALL gridDefYsize(gridID, NLAT)
CALL gridDefXvals(gridID, lons)
......@@ -61,7 +61,11 @@
CALL vlistDefTaxis(vlistID, taxisID)
! Create a dataset in netCDF format
streamID = streamOpenWrite("example.nc", FILETYPE_NC)
streamID = streamOpenWrite("example.nc", FILETYPE_NC)
IF ( streamID < 0 ) THEN
WRITE(0,*) cdiStringError(streamID)
STOP
END IF
! Assign the variable list to the dataset
CALL streamDefVlist(streamID, vlistID)
......@@ -146,6 +150,8 @@ data:
IMPLICIT NONE
INCLUDE 'cdi.inc'
INTEGER NLON, NLAT, NLEV, NTIME
PARAMETER (NLON = 12) ! Number of longitudes
PARAMETER (NLAT = 6) ! Number of latitudes
......@@ -157,10 +163,12 @@ data:
INTEGER nmiss, status, vdate, vtime
REAL*8 var1(NLON*NLAT), var2(NLON*NLAT*NLEV)
INCLUDE 'cdi.inc'
! Open the dataset
streamID = streamOpenRead("example.nc")
IF ( streamID < 0 ) THEN
WRITE(0,*) cdiStringError(streamID)
STOP
END IF
! Get the variable list of the dataset
vlistID = streamInqVlist(streamID)
......@@ -200,6 +208,8 @@ data:
IMPLICIT NONE
INCLUDE 'cdi.inc'
INTEGER NLON, NLAT, NLEV, NTIME
PARAMETER (NLON = 12) ! Number of longitudes
PARAMETER (NLAT = 6) ! Number of latitudes
......@@ -211,10 +221,12 @@ data:
INTEGER i, nmiss, status, vdate, vtime
REAL*8 var1(NLON*NLAT), var2(NLON*NLAT*NLEV)
INCLUDE 'cdi.inc'
! Open the input dataset
streamID1 = streamOpenRead("example.nc")
IF ( streamID1 < 0 ) THEN
WRITE(0,*) cdiStringError(streamID1)
STOP
END IF
! Get the variable list of the dataset
vlistID1 = streamInqVlist(streamID1)
......@@ -226,8 +238,12 @@ data:
! Get the Time axis form the variable list
taxisID = vlistInqTaxis(vlistID1)
! Open the output dataset
! Open the output dataset (GRIB format)
streamID2 = streamOpenWrite("example.grb", FILETYPE_GRB)
IF ( streamID2 < 0 ) THEN
WRITE(0,*) cdiStringError(streamID2)
STOP
END IF
vlistID2 = vlistDuplicate(vlistID1)
......
......@@ -31,20 +31,21 @@ Number of gridpoints.
\subsection*{Example}
Here is an example using {\tt gridCreate} to create a {\tt LONLAT} Grid:
Here is an example using {\tt gridCreate} to create a regular lon/lat Grid:
\begin{lstlisting}[backgroundcolor=\color{zebg}, basicstyle=\footnotesize]
INCLUDE 'cdi.h'
...
#define NLON 12
#define NLAT 6
...
REAL*8 lons(NLON) = (/0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330/)
REAL*8 lats(NLAT) = (/-75, -45, -15, 15, 45, 75/)
INTEGER gridID
INTEGER nlon = 12
INTEGER nlat = 6
REAL*8 lons(nlon) = (/0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330/)
REAL*8 lats(nlat) = (/-75, -45, -15, 15, 45, 75/)
...
gridID = gridCreate(GRID_LONLAT, nlon*nlat)
CALL gridDefXsize(gridID, nlon)
CALL gridDefYsize(gridID, nlat)
gridID = gridCreate(GRID_LONLAT, NLON*NLAT)
CALL gridDefXsize(gridID, NLON)
CALL gridDefYsize(gridID, NLAT)
CALL gridDefXvals(gridID, lons)
CALL gridDefYvals(gridID, lats)
...
......
......@@ -27,9 +27,26 @@ Number of levels
\subsection*{Result}
{\tt zaxisCreate} returns an identifier to the vertical Z-axis.
{\tt zaxisCreate} returns an identifier to the Z-axis.
\subsection*{Example}
Here is an example using {\tt zaxisCreate} to create a pressure level Z-axis:
\begin{lstlisting}[backgroundcolor=\color{zebg}, basicstyle=\footnotesize]
INCLUDE 'cdi.h'
...
#define NLEV 5
...
REAL*8 levs(NLEV) = (/101300, 92500, 85000, 50000, 20000/)
INTEGER zaxisID
...
zaxisID = zaxisCreate(ZAXIS_PRESSURE, NLEV)
CALL zaxisDefLevels(zaxisID, levs)
...
\end{lstlisting}
\section{Destroy a vertical Z-axis: {\tt zaxisDestroy}}
\index{zaxisDestroy}
......
CDI is a C and Fortran Interface to access Climate model Data.
% CDI is a C and Fortran Interface to access Climate model Data.
\input{install}
......@@ -367,8 +367,8 @@ sub printfortran {
$line =~ s/const char \*/CHARACTER\*(\*) /og;
$line =~ s/char \*/CHARACTER\*(\*) /og;
$line =~ s/if /IF /og;
$line =~ s/#include </INCLUDE \'/og;
$line =~ s/>$/\'/og;
$line =~ s/#include \"/INCLUDE \'/og;
$line =~ s/\"$/\'/og;
$line =~ s/handle_error/CALL handle_error/og;
printfsrc (" $line");
}
......
......@@ -3,13 +3,13 @@
bin_PROGRAMS = cdi_write cdi_read cdi_copy
#
cdi_write_SOURCES = cdi_write.c
cdi_write_LDADD = $(top_srcdir)/src/libcdi.a $(LDFLAGS) -lm
cdi_write_LDADD = ../src/libcdi.a $(LDFLAGS) -lm
#
cdi_read_SOURCES = cdi_read.c
cdi_read_LDADD = $(top_srcdir)/src/libcdi.a $(LDFLAGS) -lm
cdi_read_LDADD = ../src/libcdi.a $(LDFLAGS) -lm
#
cdi_copy_SOURCES = cdi_copy.c
cdi_copy_LDADD = $(top_srcdir)/src/libcdi.a $(LDFLAGS) -lm
cdi_copy_LDADD = ../src/libcdi.a $(LDFLAGS) -lm
#
CPPFLAGS = -I$(top_srcdir)/src
#
......
......@@ -86,13 +86,13 @@ install_sh = @install_sh@
bin_PROGRAMS = cdi_write cdi_read cdi_copy
#
cdi_write_SOURCES = cdi_write.c
cdi_write_LDADD = $(top_srcdir)/src/libcdi.a $(LDFLAGS) -lm
cdi_write_LDADD = ../src/libcdi.a $(LDFLAGS) -lm
#
cdi_read_SOURCES = cdi_read.c
cdi_read_LDADD = $(top_srcdir)/src/libcdi.a $(LDFLAGS) -lm
cdi_read_LDADD = ../src/libcdi.a $(LDFLAGS) -lm
#
cdi_copy_SOURCES = cdi_copy.c
cdi_copy_LDADD = $(top_srcdir)/src/libcdi.a $(LDFLAGS) -lm
cdi_copy_LDADD = ../src/libcdi.a $(LDFLAGS) -lm
#
CLEANFILES = `ls *~`
subdir = examples
......@@ -104,15 +104,15 @@ PROGRAMS = $(bin_PROGRAMS)
am_cdi_copy_OBJECTS = cdi_copy.$(OBJEXT)
cdi_copy_OBJECTS = $(am_cdi_copy_OBJECTS)
cdi_copy_DEPENDENCIES = $(top_srcdir)/src/libcdi.a
cdi_copy_DEPENDENCIES = ../src/libcdi.a
cdi_copy_LDFLAGS =
am_cdi_read_OBJECTS = cdi_read.$(OBJEXT)
cdi_read_OBJECTS = $(am_cdi_read_OBJECTS)
cdi_read_DEPENDENCIES = $(top_srcdir)/src/libcdi.a
cdi_read_DEPENDENCIES = ../src/libcdi.a
cdi_read_LDFLAGS =
am_cdi_write_OBJECTS = cdi_write.$(OBJEXT)
cdi_write_OBJECTS = $(am_cdi_write_OBJECTS)
cdi_write_DEPENDENCIES = $(top_srcdir)/src/libcdi.a
cdi_write_DEPENDENCIES = ../src/libcdi.a
cdi_write_LDFLAGS =
DEFS = @DEFS@
......
#include <stdio.h>
#include "cdi.h"
#define NLON 12 /* Number of longitudes */
......@@ -15,6 +16,11 @@ int main(void)
/* Open the input dataset */
streamID1 = streamOpenRead("example.nc");
if ( streamID1 < 0 )
{
fprintf(stderr, "%s\n", cdiStringError(streamID1));
return(1);
}
/* Get the variable list of the dataset */
vlistID1 = streamInqVlist(streamID1);
......@@ -26,8 +32,13 @@ int main(void)
/* Get the Time axis form the variable list */
taxisID = vlistInqTaxis(vlistID1);
/* Open the output dataset */
/* Open the output dataset (GRIB format) */
streamID2 = streamOpenWrite("example.grb", FILETYPE_GRB);
if ( streamID2 < 0 )
{
fprintf(stderr, "%s\n", cdiStringError(streamID2));
return(1);
}
vlistID2 = vlistDuplicate(vlistID1);
......
......@@ -2,6 +2,8 @@
IMPLICIT NONE
INCLUDE 'cdi.inc'
INTEGER NLON, NLAT, NLEV, NTIME
PARAMETER (NLON = 12) ! Number of longitudes
PARAMETER (NLAT = 6) ! Number of latitudes
......@@ -13,10 +15,12 @@
INTEGER i, nmiss, status, vdate, vtime
REAL*8 var1(NLON*NLAT), var2(NLON*NLAT*NLEV)
INCLUDE 'cdi.inc'
! Open the input dataset
streamID1 = streamOpenRead("example.nc")
streamID1 = streamOpenRead("example.nc")
IF ( streamID1 < 0 ) THEN
WRITE(0,*) cdiStringError(streamID1)
STOP
END IF
! Get the variable list of the dataset
vlistID1 = streamInqVlist(streamID1)
......@@ -28,8 +32,12 @@
! Get the Time axis form the variable list
taxisID = vlistInqTaxis(vlistID1)
! Open the output dataset
streamID2 = streamOpenWrite("example.grb", FILETYPE_GRB)
! Open the output dataset (GRIB format)
streamID2 = streamOpenWrite("example.grb", FILETYPE_GRB)
IF ( streamID2 < 0 ) THEN
WRITE(0,*) cdiStringError(streamID2)
STOP
END IF
vlistID2 = vlistDuplicate(vlistID1)
......
#include <stdio.h>
#include "cdi.h"
#define NLON 12 /* Number of longitudes */
......@@ -14,7 +15,12 @@ int main(void)
/* Open the dataset */
streamID = streamOpenRead("example.nc");
streamID = streamOpenRead("example.nc");
if ( streamID < 0 )
{
fprintf(stderr, "%s\n", cdiStringError(streamID));
return(1);
}
/* Get the variable list of the dataset */
vlistID = streamInqVlist(streamID);
......
......@@ -2,6 +2,8 @@
IMPLICIT NONE
INCLUDE 'cdi.inc'
INTEGER NLON, NLAT, NLEV, NTIME
PARAMETER (NLON = 12) ! Number of longitudes
PARAMETER (NLAT = 6) ! Number of latitudes
......@@ -13,10 +15,12 @@
INTEGER nmiss, status, vdate, vtime
REAL*8 var1(NLON*NLAT), var2(NLON*NLAT*NLEV)
INCLUDE 'cdi.inc'
! Open the dataset
streamID = streamOpenRead("example.nc")
streamID = streamOpenRead("example.nc")
IF ( streamID < 0 ) THEN
WRITE(0,*) cdiStringError(streamID)
STOP
END IF
! Get the variable list of the dataset
vlistID = streamInqVlist(streamID)
......
#include <stdio.h>
#include "cdi.h"
#define NLON 12 /* Number of longitudes */
......@@ -18,7 +19,7 @@ int main(void)
/* Create a regular lon/lat grid */
gridID = gridCreate(GRID_LONLAT, NLON*NLAT);
gridID = gridCreate(GRID_LONLAT, NLON*NLAT);
gridDefXsize(gridID, NLON);
gridDefYsize(gridID, NLAT);
gridDefXvals(gridID, lons);
......@@ -49,7 +50,12 @@ int main(void)
vlistDefTaxis(vlistID, taxisID);
/* Create a dataset in netCDF format */
streamID = streamOpenWrite("example.nc", FILETYPE_NC);
streamID = streamOpenWrite("example.nc", FILETYPE_NC);
if ( streamID < 0 )
{
fprintf(stderr, "%s\n", cdiStringError(streamID));
return(1);
}
/* Assign the variable list to the dataset */
streamDefVlist(streamID, vlistID);
......
......@@ -2,6 +2,8 @@
IMPLICIT NONE
INCLUDE 'cdi.inc'
INTEGER NLON, NLAT, NLEV, NTIME
PARAMETER (NLON = 12) ! Number of longitudes
PARAMETER (NLAT = 6) ! Number of latitudes
......@@ -18,12 +20,10 @@
DATA lats /-75, -45, -15, 15, 45, 75/
DATA levs /101300, 92500, 85000, 50000, 20000/
INCLUDE 'cdi.inc'
nmiss = 0
! Create a regular lon/lat grid
gridID = gridCreate(GRID_LONLAT, NLON*NLAT)
gridID = gridCreate(GRID_LONLAT, NLON*NLAT)
CALL gridDefXsize(gridID, NLON)
CALL gridDefYsize(gridID, NLAT)
CALL gridDefXvals(gridID, lons)
......@@ -54,7 +54,11 @@
CALL vlistDefTaxis(vlistID, taxisID)
! Create a dataset in netCDF format
streamID = streamOpenWrite("example.nc", FILETYPE_NC)
streamID = streamOpenWrite("example.nc", FILETYPE_NC)
IF ( streamID < 0 ) THEN
WRITE(0,*) cdiStringError(streamID)
STOP
END IF
! Assign the variable list to the dataset
CALL streamDefVlist(streamID, vlistID)
......
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