Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libcdi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mpim-sw
libcdi
Commits
8c0677bd
Commit
8c0677bd
authored
18 years ago
by
Uwe Schulzweida
Browse files
Options
Downloads
Patches
Plain Diff
add f_examples.tex
parent
48501709
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitattributes
+1
-0
1 addition, 0 deletions
.gitattributes
doc/tex/f_examples.tex
+262
-0
262 additions, 0 deletions
doc/tex/f_examples.tex
with
263 additions
and
0 deletions
.gitattributes
+
1
−
0
View file @
8c0677bd
...
...
@@ -34,6 +34,7 @@ doc/tex/c_zaxis.tex -text
doc/tex/cdi_cman.tex -text
doc/tex/cdi_fman.tex -text
doc/tex/cleanup -text
doc/tex/f_examples.tex -text
doc/tex/f_grid.tex -text
doc/tex/f_link.tex -text
doc/tex/f_quick_ref.tex -text
...
...
This diff is collapsed.
Click to expand it.
doc/tex/f_examples.tex
0 → 100644
+
262
−
0
View file @
8c0677bd
\appendix
\chapter
{
\label
{
appendixa
}
Examples
}
\section
{
Write a dataset
}
\begin{lstlisting}
[frame=single, backgroundcolor=
\color
{
zebg
}
, basicstyle=
\footnotesize
]
PROGRAM CDIWRITE
IMPLICIT NONE
INTEGER NLON, NLAT, NLEV, NTIME
PARAMETER (NLON = 12) ! Number of longitudes
PARAMETER (NLAT = 6) ! Number of latitudes
PARAMETER (NLEV = 5) ! Number of levels
PARAMETER (NTIME = 3) ! Number of time steps
INTEGER gridID, zaxisID1, zaxisID2, taxisID
INTEGER vlistID, varID1, varID2, streamID, tsID
INTEGER i, nmiss, status
REAL*8 lons(NLON), lats(NLAT), levs(NLEV)
REAL*8 var1(NLON*NLAT), var2(NLON*NLAT*NLEV)
DATA lons /0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330/
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)
CALL gridDefXsize(gridID, NLON)
CALL gridDefYsize(gridID, NLAT)
CALL gridDefXvals(gridID, lons)
CALL 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)
CALL zaxisDefLevels(zaxisID2, levs)
! Create a variable list
vlistID = vlistCreate()
! Define the variables
varID1 = vlistDefVar(vlistID, gridID, zaxisID1, TIME
_
VARIABLE)
varID2 = vlistDefVar(vlistID, gridID, zaxisID2, TIME
_
VARIABLE)
! Define the variable names
CALL vlistDefVarName(vlistID, varID1, "varname1")
CALL vlistDefVarName(vlistID, varID2, "varname2")
! Create a Time axis
taxisID = taxisCreate(TAXIS
_
ABSOLUTE)
! Assign the Time axis to the variable list
CALL vlistDefTaxis(vlistID, taxisID)
! Create a dataset in netCDF format
streamID = streamOpenWrite("example.nc", FILETYPE
_
NC)
! Assign the variable list to the dataset
CALL streamDefVlist(streamID, vlistID)
! Loop over the number of time steps
DO tsID = 0, NTIME-1
! Set the verification date to 1985-01-01 + tsID
CALL taxisDefVdate(taxisID, 19850101+tsID)
! Set the verification time to 12:00
CALL taxisDefVtime(taxisID, 1200)
! Define the time step
status = streamDefTimestep(streamID, tsID)
! Init var1 and var2
DO i = 1, NLON*NLAT
var1(i) = 1
END DO
DO i = 1, NLON*NLAT*NLEV
var2(i) = 2
END DO
! Write var1 and var2
CALL streamWriteVar(streamID, varID1, var1, nmiss)
CALL streamWriteVar(streamID, varID2, var2, nmiss)
END DO
! Close the output stream
CALL streamClose(streamID)
! Destroy the objects
CALL vlistDestroy(vlistID)
CALL taxisDestroy(taxisID)
CALL zaxisDestroy(zaxisID1)
CALL zaxisDestroy(zaxisID2)
CALL gridDestroy(gridID)
END
\end{lstlisting}
\subsection
{
Result
}
\begin{lstlisting}
[frame=single, backgroundcolor=
\color
{
zebg
}
, basicstyle=
\footnotesize
]
netcdf example
{
dimensions:
lon = 12 ;
lat = 6 ;
lev = 5 ;
time = UNLIMITED ; // (3 currently)
variables:
double lon(lon) ;
lon:long
_
name = "longitude" ;
lon:units = "degrees
_
east" ;
lon:standard
_
name = "longitude" ;
double lat(lat) ;
lat:long
_
name = "latitude" ;
lat:units = "degrees
_
north" ;
lat:standard
_
name = "latitude" ;
double lev(lev) ;
lev:long
_
name = "pressure" ;
lev:units = "Pa" ;
double time(time) ;
time:units = "day as
%Y%m%d.%f" ;
float varname1(time, lat, lon) ;
float varname2(time, lev, lat, lon) ;
data:
lon = 0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330 ;
lat = -75, -45, -15, 15, 45, 75 ;
lev = 101300, 92500, 85000, 50000, 20000 ;
time = 19850101.5, 19850102.5, 19850103.5 ;
}
\end{lstlisting}
\section
{
Read a dataset
}
\begin{lstlisting}
[frame=single, backgroundcolor=
\color
{
zebg
}
, basicstyle=
\footnotesize
]
PROGRAM CDIREAD
IMPLICIT NONE
INTEGER NLON, NLAT, NLEV, NTIME
PARAMETER (NLON = 12) ! Number of longitudes
PARAMETER (NLAT = 6) ! Number of latitudes
PARAMETER (NLEV = 5) ! Number of levels
PARAMETER (NTIME = 3) ! Number of time steps
INTEGER gridID, zaxisID1, zaxisID2, taxisID
INTEGER vlistID, varID1, varID2, streamID, tsID
INTEGER nmiss, status, vdate, vtime
REAL*8 var1(NLON*NLAT), var2(NLON*NLAT*NLEV)
INCLUDE 'cdi.inc'
! Open the dataset
streamID = streamOpenRead("example.nc")
! Get the variable list of the dataset
vlistID = streamInqVlist(streamID)
! Set the variable IDs
varID1 = 0
varID2 = 1
! Get the Time axis form the variable list
taxisID = vlistInqTaxis(vlistID)
! Loop over the number of time steps
DO tsID = 0, NTIME-1
! Inquire the time step
status = streamInqTimestep(streamID, tsID)
! Get the verification date and time
vdate = taxisInqVdate(taxisID)
vtime = taxisInqVtime(taxisID)
! Read var1 and var2
CALL streamReadVar(streamID, varID1, var1, nmiss)
CALL streamReadVar(streamID, varID2, var2, nmiss)
END DO
! Close the input stream
CALL streamClose(streamID)
END
\end{lstlisting}
\section
{
Copy a dataset
}
\begin{lstlisting}
[frame=single, backgroundcolor=
\color
{
zebg
}
, basicstyle=
\footnotesize
]
PROGRAM CDICOPY
IMPLICIT NONE
INTEGER NLON, NLAT, NLEV, NTIME
PARAMETER (NLON = 12) ! Number of longitudes
PARAMETER (NLAT = 6) ! Number of latitudes
PARAMETER (NLEV = 5) ! Number of levels
PARAMETER (NTIME = 3) ! Number of time steps
INTEGER gridID, zaxisID1, zaxisID2, taxisID, tsID
INTEGER vlistID1, vlistID2, varID1, varID2, streamID1, streamID2
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")
! Get the variable list of the dataset
vlistID1 = streamInqVlist(streamID1)
! Set the variable IDs
varID1 = 0
varID2 = 1
! Get the Time axis form the variable list
taxisID = vlistInqTaxis(vlistID1)
! Open the output dataset
streamID2 = streamOpenWrite("example.grb", FILETYPE
_
GRB)
vlistID2 = vlistDuplicate(vlistID1)
CALL streamDefVlist(streamID2, vlistID2)
! Loop over the number of time steps
DO tsID = 0, NTIME-1
! Inquire the input time step */
status = streamInqTimestep(streamID1, tsID)
! Get the verification date and time
vdate = taxisInqVdate(taxisID)
vtime = taxisInqVtime(taxisID)
! Define the output time step
status = streamDefTimestep(streamID2, tsID)
! Read var1 and var2
CALL streamReadVar(streamID1, varID1, var1, nmiss)
CALL streamReadVar(streamID1, varID2, var2, nmiss)
! Write var1 and var2
CALL streamWriteVar(streamID2, varID1, var1, nmiss)
CALL streamWriteVar(streamID2, varID2, var2, nmiss)
END DO
! Close the streams
CALL streamClose(streamID1)
CALL streamClose(streamID2)
END
\end{lstlisting}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment