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
073bd69a
Commit
073bd69a
authored
5 years ago
by
Uwe Schulzweida
Browse files
Options
Downloads
Patches
Plain Diff
Added cdi_write_curv_rll.c.
parent
405e8e93
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
examples/cdi_write_curv_rll.c
+120
-0
120 additions, 0 deletions
examples/cdi_write_curv_rll.c
examples/cdi_write_rll.c
+93
-0
93 additions, 0 deletions
examples/cdi_write_rll.c
with
213 additions
and
0 deletions
examples/cdi_write_curv_rll.c
0 → 100644
+
120
−
0
View file @
073bd69a
#include
<stdio.h>
#include
"cdi.h"
int
main
(
void
)
{
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
size_t
nmiss
=
0
;
double
levs
[]
=
{
101300
,
92500
,
85000
,
50000
,
20000
};
double
var1
[
nlon
*
nlat
];
double
var2
[
nlon
*
nlat
*
nlev
];
// Create a curvilinear grid
int
gridID
=
gridCreate
(
GRID_CURVILINEAR
,
nlon
*
nlat
);
{
double
lons
[]
=
{
0
,
30
,
60
,
90
,
120
,
150
,
180
,
210
,
240
,
270
,
300
,
330
};
double
lats
[]
=
{
-
75
,
-
45
,
-
15
,
15
,
45
,
75
};
double
lons2D
[
nlon
*
nlat
],
lats2D
[
nlon
*
nlat
];
for
(
int
j
=
0
;
j
<
nlat
;
++
j
)
for
(
int
i
=
0
;
i
<
nlon
;
++
i
)
{
lons2D
[
j
*
nlon
+
i
]
=
lons
[
i
];
lats2D
[
j
*
nlon
+
i
]
=
lats
[
j
];
}
gridDefXsize
(
gridID
,
nlon
);
gridDefYsize
(
gridID
,
nlat
);
gridDefXvals
(
gridID
,
lons2D
);
gridDefYvals
(
gridID
,
lats2D
);
gridDefXname
(
gridID
,
"lon"
);
gridDefYname
(
gridID
,
"lat"
);
}
// Create a rotated lon/lat grid
{
int
projID
=
gridCreate
(
GRID_PROJECTION
,
nlon
*
nlat
);
double
rlons
[]
=
{
10
,
15
,
20
,
25
,
30
,
35
,
40
,
45
,
50
,
55
,
60
,
65
};
double
rlats
[]
=
{
5
,
10
,
15
,
20
,
25
,
30
};
gridDefXsize
(
projID
,
nlon
);
gridDefYsize
(
projID
,
nlat
);
gridDefXvals
(
projID
,
rlons
);
gridDefYvals
(
projID
,
rlats
);
gridDefXname
(
projID
,
"rlon"
);
gridDefYname
(
projID
,
"rlat"
);
gridDefParamRLL
(
projID
,
-
162
.,
39
.
25
,
0
);
gridDefProj
(
gridID
,
projID
);
}
// Create a surface level Z-axis
int
zaxisID1
=
zaxisCreate
(
ZAXIS_SURFACE
,
1
);
// Create a pressure level Z-axis
int
zaxisID2
=
zaxisCreate
(
ZAXIS_PRESSURE
,
nlev
);
zaxisDefLevels
(
zaxisID2
,
levs
);
// Create a variable list
int
vlistID
=
vlistCreate
();
// Define the variables
int
varID1
=
vlistDefVar
(
vlistID
,
gridID
,
zaxisID1
,
TIME_VARYING
);
int
varID2
=
vlistDefVar
(
vlistID
,
gridID
,
zaxisID2
,
TIME_VARYING
);
// Define the variable names
vlistDefVarName
(
vlistID
,
varID1
,
"varname1"
);
vlistDefVarName
(
vlistID
,
varID2
,
"varname2"
);
// Create a Time axis
int
taxisID
=
taxisCreate
(
TAXIS_ABSOLUTE
);
// Assign the Time axis to the variable list
vlistDefTaxis
(
vlistID
,
taxisID
);
// Create a dataset in netCDF format
int
streamID
=
streamOpenWrite
(
"example.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
);
// 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
);
// 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
;
}
This diff is collapsed.
Click to expand it.
examples/cdi_write_rll.c
0 → 100644
+
93
−
0
View file @
073bd69a
#include
<stdio.h>
#include
"cdi.h"
int
main
(
void
)
{
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
size_t
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
int
gridID
=
gridCreate
(
GRID_PROJECTION
,
nlon
*
nlat
);
gridDefParamRLL
(
gridID
,
-
162
.,
39
.
25
,
0
);
gridDefXsize
(
gridID
,
nlon
);
gridDefYsize
(
gridID
,
nlat
);
gridDefXvals
(
gridID
,
lons
);
gridDefYvals
(
gridID
,
lats
);
gridDefXname
(
gridID
,
"rlon"
);
gridDefYname
(
gridID
,
"rlat"
);
// Create a surface level Z-axis
int
zaxisID1
=
zaxisCreate
(
ZAXIS_SURFACE
,
1
);
// Create a pressure level Z-axis
int
zaxisID2
=
zaxisCreate
(
ZAXIS_PRESSURE
,
nlev
);
zaxisDefLevels
(
zaxisID2
,
levs
);
// Create a variable list
int
vlistID
=
vlistCreate
();
// Define the variables
int
varID1
=
vlistDefVar
(
vlistID
,
gridID
,
zaxisID1
,
TIME_VARYING
);
int
varID2
=
vlistDefVar
(
vlistID
,
gridID
,
zaxisID2
,
TIME_VARYING
);
// Define the variable names
vlistDefVarName
(
vlistID
,
varID1
,
"varname1"
);
vlistDefVarName
(
vlistID
,
varID2
,
"varname2"
);
// Create a Time axis
int
taxisID
=
taxisCreate
(
TAXIS_ABSOLUTE
);
// Assign the Time axis to the variable list
vlistDefTaxis
(
vlistID
,
taxisID
);
// Create a dataset in netCDF format
int
streamID
=
streamOpenWrite
(
"example.nc"
,
CDI_FILETYPE_NC
);
if
(
streamID
<
0
)
{
fprintf
(
stderr
,
"%s
\n
"
,
cdiStringError
(
streamID
));
return
1
;
}
// Assign the variable list to the dataset
streamDefVlist
(
streamID
,
vlistID
);
// 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
);
// 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
;
}
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