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
d5fce445
Commit
d5fce445
authored
9 years ago
by
Thomas Jahns
Committed by
Sergey Kosukhin
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup of example programs.
parent
04a4b26b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!34
Version 2.2.0
,
!13
Consolidation with CDI-PIO (develop)
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/cdi_copy.c
+30
-27
30 additions, 27 deletions
examples/cdi_copy.c
examples/cdi_write_ens.c
+5
-5
5 additions, 5 deletions
examples/cdi_write_ens.c
with
35 additions
and
32 deletions
examples/cdi_copy.c
+
30
−
27
View file @
d5fce445
#include
<stdio.h>
#include
<stdlib.h>
#include
"cdi.h"
int
main
(
void
)
{
enum
{
nlon
=
12
,
// Number of longitudes
nlat
=
6
,
// Number of latitudes
nlev
=
5
,
// Number of levels
nts
=
3
,
// Number of time steps
};
SizeType
nmiss
;
double
var1
[
nlon
*
nlat
];
double
var2
[
nlon
*
nlat
*
nlev
];
// Open the input dataset
int
streamID1
=
streamOpenRead
(
"example.nc"
);
...
...
@@ -26,43 +17,55 @@ main(void)
// Get the variable list of the dataset
int
vlistID1
=
streamInqVlist
(
streamID1
);
// Set the variable IDs
int
varID1
=
0
;
int
varID2
=
1
;
int
nvars
=
vlistNvars
(
vlistID1
);
int
varDataSize
=
0
;
double
*
varData
=
NULL
;
for
(
int
varID
=
0
;
varID
<
nvars
;
++
varID
)
{
int
varSize
=
vlistInqVarSize
(
vlistID1
,
varID
);
varDataSize
=
varSize
>
varDataSize
?
varSize
:
varDataSize
;
}
varData
=
malloc
((
size_t
)
varDataSize
*
sizeof
(
double
));
if
(
!
varData
)
{
perror
(
"cannot allocate temporary copying buffer"
);
return
EXIT_FAILURE
;
}
// Open the output dataset (GRIB format)
int
streamID2
=
streamOpenWrite
(
"example.grb"
,
CDI_FILETYPE_GRB
);
if
(
streamID2
<
0
)
{
fprintf
(
stderr
,
"%s
\n
"
,
cdiStringError
(
streamID2
));
return
1
;
return
EXIT_FAILURE
;
}
int
vlistID2
=
vlistDuplicate
(
vlistID1
);
streamDefVlist
(
streamID2
,
vlistID2
);
// Loop over the number of time steps
for
(
int
tsID
=
0
;
tsID
<
nts
;
tsID
++
)
// Loop over the input time steps
int
tsID
=
0
;
while
(
streamInqTimestep
(
streamID1
,
tsID
))
{
// Inquire the input time step
streamInqTimestep
(
streamID1
,
tsID
);
// Define the output time step
streamDefTimestep
(
streamID2
,
tsID
);
// Read var1 and var2
streamReadVar
(
streamID1
,
varID1
,
var1
,
&
nmiss
);
streamReadVar
(
streamID1
,
varID2
,
var2
,
&
nmiss
);
// Write var1 and var2
streamWriteVar
(
streamID2
,
varID1
,
var1
,
nmiss
);
streamWriteVar
(
streamID2
,
varID2
,
var2
,
nmiss
);
for
(
int
varID
=
0
;
varID
<
nvars
;
++
varID
)
{
SizeType
nmiss
;
// Read var
streamReadVar
(
streamID1
,
varID
,
varData
,
&
nmiss
);
// Write var
streamWriteVar
(
streamID2
,
varID
,
varData
,
nmiss
);
}
++
tsID
;
}
// Close the streams
streamClose
(
streamID1
);
streamClose
(
streamID2
);
return
0
;
return
EXIT_SUCCESS
;
}
This diff is collapsed.
Click to expand it.
examples/cdi_write_ens.c
+
5
−
5
View file @
d5fce445
...
...
@@ -89,11 +89,11 @@ main(void)
for
(
varID
=
0
;
varID
<
nvars
;
varID
++
)
{
int
g
ridID
=
vlistInqVarGrid
(
vlistID
,
varID
);
int
z
axisID
=
vlistInqVarZaxis
(
vlistID
,
varID
);
size_t
gridsize
=
(
size_t
)
gridInqSize
(
g
ridID
);
size_t
n
level
=
(
size_t
)
zaxisInqSize
(
z
axisID
);
if
(
gridsize
*
n
level
>
datasize
)
datasize
=
gridsize
*
n
level
;
int
varG
ridID
=
vlistInqVarGrid
(
vlistID
,
varID
);
int
varZ
axisID
=
vlistInqVarZaxis
(
vlistID
,
varID
);
size_t
gridsize
=
(
size_t
)
gridInqSize
(
varG
ridID
);
size_t
varN
level
=
(
size_t
)
zaxisInqSize
(
varZ
axisID
);
if
(
gridsize
*
varN
level
>
datasize
)
datasize
=
gridsize
*
varN
level
;
}
data
=
(
double
*
)
malloc
(
datasize
*
sizeof
(
double
));
...
...
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