Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpim-sw
libcdi
Commits
bd5e3c3f
Commit
bd5e3c3f
authored
Dec 07, 2014
by
Uwe Schulzweida
Browse files
Merge declaration and definition.
parent
3572162f
Changes
3
Hide whitespace changes
Inline
Side-by-side
examples/cdi_copy.c
View file @
bd5e3c3f
#include
<stdio.h>
#include
"cdi.h"
int
nlon
=
12
;
// Number of longitudes
int
nlat
=
6
;
// Number of latitudes
int
nlev
=
5
;
// Number of levels
int
nts
=
3
;
// Number of time steps
int
main
(
void
)
{
int
vlistID1
,
vlistID2
,
varID1
,
varID2
,
streamID1
,
streamID2
,
tsID
;
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
;
double
var1
[
nlon
*
nlat
];
double
var2
[
nlon
*
nlat
*
nlev
];
// Open the input dataset
streamID1
=
streamOpenRead
(
"example.nc"
);
int
streamID1
=
streamOpenRead
(
"example.nc"
);
if
(
streamID1
<
0
)
{
fprintf
(
stderr
,
"%s
\n
"
,
cdiStringError
(
streamID1
));
return
(
1
)
;
return
1
;
}
// Get the variable list of the dataset
vlistID1
=
streamInqVlist
(
streamID1
);
int
vlistID1
=
streamInqVlist
(
streamID1
);
// Set the variable IDs
varID1
=
0
;
varID2
=
1
;
int
varID1
=
0
;
int
varID2
=
1
;
// Open the output dataset (GRIB format)
streamID2
=
streamOpenWrite
(
"example.grb"
,
FILETYPE_GRB
);
int
streamID2
=
streamOpenWrite
(
"example.grb"
,
FILETYPE_GRB
);
if
(
streamID2
<
0
)
{
fprintf
(
stderr
,
"%s
\n
"
,
cdiStringError
(
streamID2
));
return
(
1
)
;
return
1
;
}
vlistID2
=
vlistDuplicate
(
vlistID1
);
int
vlistID2
=
vlistDuplicate
(
vlistID1
);
streamDefVlist
(
streamID2
,
vlistID2
);
// Loop over the number of time steps
for
(
tsID
=
0
;
tsID
<
nts
;
tsID
++
)
for
(
int
tsID
=
0
;
tsID
<
nts
;
tsID
++
)
{
// Inquire the input time step
streamInqTimestep
(
streamID1
,
tsID
);
...
...
examples/cdi_read.c
View file @
bd5e3c3f
#include
<stdio.h>
#include
"cdi.h"
int
nlon
=
12
;
// Number of longitudes
int
nlat
=
6
;
// Number of latitudes
int
nlev
=
5
;
// Number of levels
int
nts
=
3
;
// Number of time steps
int
main
(
void
)
{
int
taxisID
,
vlistID
,
varID1
,
varID2
,
streamID
,
tsID
;
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
,
vdate
,
vtime
;
double
var1
[
nlon
*
nlat
];
double
var2
[
nlon
*
nlat
*
nlev
];
// Open the dataset
streamID
=
streamOpenRead
(
"example.nc"
);
int
streamID
=
streamOpenRead
(
"example.nc"
);
if
(
streamID
<
0
)
{
fprintf
(
stderr
,
"%s
\n
"
,
cdiStringError
(
streamID
));
return
(
1
)
;
return
1
;
}
// Get the variable list of the dataset
vlistID
=
streamInqVlist
(
streamID
);
int
vlistID
=
streamInqVlist
(
streamID
);
// Set the variable IDs
varID1
=
0
;
varID2
=
1
;
int
varID1
=
0
;
int
varID2
=
1
;
// Get the Time axis from the variable list
taxisID
=
vlistInqTaxis
(
vlistID
);
int
taxisID
=
vlistInqTaxis
(
vlistID
);
// Loop over the number of time steps
for
(
tsID
=
0
;
tsID
<
nts
;
tsID
++
)
for
(
int
tsID
=
0
;
tsID
<
nts
;
tsID
++
)
{
// Inquire the time step
streamInqTimestep
(
streamID
,
tsID
);
...
...
examples/cdi_write.c
View file @
bd5e3c3f
#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
,
tsID
;
int
i
,
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
};
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
gridID
=
gridCreate
(
GRID_LONLAT
,
nlon
*
nlat
);
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
zaxisID1
=
zaxisCreate
(
ZAXIS_SURFACE
,
1
);
int
zaxisID1
=
zaxisCreate
(
ZAXIS_SURFACE
,
1
);
// Create a pressure level Z-axis
zaxisID2
=
zaxisCreate
(
ZAXIS_PRESSURE
,
nlev
);
int
zaxisID2
=
zaxisCreate
(
ZAXIS_PRESSURE
,
nlev
);
zaxisDefLevels
(
zaxisID2
,
levs
);
// Create a variable list
vlistID
=
vlistCreate
();
int
vlistID
=
vlistCreate
();
// Define the variables
varID1
=
vlistDefVar
(
vlistID
,
gridID
,
zaxisID1
,
TSTEP_INSTANT
);
varID2
=
vlistDefVar
(
vlistID
,
gridID
,
zaxisID2
,
TSTEP_INSTANT
);
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
taxisID
=
taxisCreate
(
TAXIS_ABSOLUTE
);
int
taxisID
=
taxisCreate
(
TAXIS_ABSOLUTE
);
// Assign the Time axis to the variable list
vlistDefTaxis
(
vlistID
,
taxisID
);
// Create a dataset in netCDF format
streamID
=
streamOpenWrite
(
"example.nc"
,
FILETYPE_NC
);
int
streamID
=
streamOpenWrite
(
"example.nc"
,
FILETYPE_NC
);
if
(
streamID
<
0
)
{
fprintf
(
stderr
,
"%s
\n
"
,
cdiStringError
(
streamID
));
return
(
1
)
;
return
1
;
}
// Assign the variable list to the dataset
streamDefVlist
(
streamID
,
vlistID
);
// Loop over the number of time steps
for
(
tsID
=
0
;
tsID
<
nts
;
tsID
++
)
for
(
int
tsID
=
0
;
tsID
<
nts
;
tsID
++
)
{
// Set the verification date to 1985-01-01 + tsID
taxisDefVdate
(
taxisID
,
19850101
+
tsID
);
...
...
@@ -71,8 +68,8 @@ int main(void)
streamDefTimestep
(
streamID
,
tsID
);
// Init var1 and var2
for
(
i
=
0
;
i
<
nlon
*
nlat
;
i
++
)
var1
[
i
]
=
1
.
1
;
for
(
i
=
0
;
i
<
nlon
*
nlat
*
nlev
;
i
++
)
var2
[
i
]
=
2
.
2
;
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
);
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment