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
ca208715
Commit
ca208715
authored
4 years ago
by
Volker Neff
Browse files
Options
Downloads
Patches
Plain Diff
finish cdi_write example
parent
0ecfb940
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/cdi_write.jl
+74
-7
74 additions, 7 deletions
examples/cdi_write.jl
interfaces/julia/libcdi.jl
+73
-1
73 additions, 1 deletion
interfaces/julia/libcdi.jl
with
147 additions
and
8 deletions
examples/cdi_write.jl
+
74
−
7
View file @
ca208715
include
(
"./../interfaces/julia/libcdi.jl"
)
using
.
cdi
using
.
cdi
.
ZAXIS
using
.
cdi
.
GRID
using
.
cdi
.
TIME
using
.
cdi
.
TAXIS
using
.
cdi
.
FileTypes
println
(
"cdi_write example has started"
)
const
lons
=
convert
(
Vector
{
Number
},
[
0
,
30
,
60
,
90
,
120
,
150
,
180
,
210
,
240
,
270
,
300
,
330
])
const
lats
=
convert
(
Vector
{
Number
},
[
-
75
,
-
45
,
-
15
,
15
,
45
,
75
])
const
levs
=
convert
(
Vector
{
Number
},
[
101300
,
92500
,
85000
,
50000
,
20000
])
const
lons
=
[
0
,
30
,
60
,
90
,
120
,
150
,
180
,
210
,
240
,
270
,
300
,
330
]
const
lats
=
[
-
75
,
-
45
,
-
15
,
15
,
45
,
75
]
const
levs
=
[
101300
,
92500
,
85000
,
50000
,
20000
]
const
nts
=
3
# number of timestamps
cons
t
var1
=
Vector
{
Float64
}(
undef
,
length
(
lons
)
*
length
(
lats
))
const
var
2
=
Vector
{
Float64
}(
undef
,
length
(
lons
)
*
length
(
lats
)
*
length
(
levs
)
)
const
size
=
length
(
lons
)
*
length
(
lats
)
# Ini
t var1
and var2
const
var
1
=
fill
(
1.1
,
length
(
lons
)
*
length
(
lats
))
const
var2
=
fill
(
2.2
,
length
(
lons
)
*
length
(
lats
)
*
length
(
levs
))
gridID
=
gridCreate
(
LONLAT
,
size
)
# Create a regular lon/lat grid
gridID
=
gridCreate
(
GRID
.
LONLAT
,
length
(
lons
)
*
length
(
lats
))
gridDefXsize
(
gridID
,
length
(
lons
))
gridDefYsize
(
gridID
,
length
(
lats
))
gridDefXvals
(
gridID
,
lons
)
gridDefYvals
(
gridID
,
lats
)
# Create a surface level Z-axis
zaxisID1
=
zaxisCreate
(
ZAXIS
.
SURFACE
,
1
)
# Create a pressure level Z-axis
zaxisID2
=
zaxisCreate
(
ZAXIS
.
PRESSURE
,
length
(
levs
))
zaxisDefLevels
(
zaxisID2
,
levs
)
# Create a variable list
vlistID
=
vlistCreate
()
# Define the variables
varID1
=
vlistDefVar
(
vlistID
,
gridID
,
zaxisID1
,
TIME
.
VARYING
)
varID2
=
vlistDefVar
(
vlistID
,
gridID
,
zaxisID2
,
TIME
.
VARYING
)
# Define the variable names
vlistDefVarName
(
vlistID
,
varID1
,
"varname1"
)
vlistDefVarName
(
vlistID
,
varID2
,
"varname2"
)
# Create a Time axis
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"
,
FileTypes
.
FILETYPE_NC
);
if
streamID
<
0
println
(
cdiStringError
(
streamID
))
exit
(
1
)
end
# Assign the variable list to the dataset
streamDefVlist
(
streamID
,
vlistID
);
# Loop over the number of time steps
for
tsID
in
0
:
nts
# 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
);
# Write var1 and var2
streamWriteVar
(
streamID
,
varID1
,
var1
,
0
);
streamWriteVar
(
streamID
,
varID2
,
var2
,
0
);
end
# Close the output stream
streamClose
(
streamID
);
# Destroy the objects
vlistDestroy
(
vlistID
);
taxisDestroy
(
taxisID
);
zaxisDestroy
(
zaxisID1
);
zaxisDestroy
(
zaxisID2
);
gridDestroy
(
gridID
);
\ No newline at end of file
This diff is collapsed.
Click to expand it.
interfaces/julia/libcdi.jl
+
73
−
1
View file @
ca208715
...
...
@@ -30,7 +30,79 @@ function zaxisDefLevels(zaxisID::Cint, levels::Vector{T}) where {T <: Number}
ccall
((
:
zaxisDefLevels
,
"libcdi"
),
Cvoid
,
(
Cint
,
Ptr
{
Cdouble
}),
zaxisID
,
levels
)
end
function
vlistCreate
()
:
Cint
ccall
((
:
vlistCreate
,
"libcdi"
),
Cint
,
())
end
function
vlistDefVar
(
vlistID
::
Cint
,
gridID
::
Cint
,
zaxisID
::
Cint
,
timetype
::
TIME_t
)
ccall
((
:
vlistDefVar
,
"libcdi"
),
Cint
,
(
Cint
,
Cint
,
Cint
,
Cint
),
vlistID
,
gridID
,
zaxisID
,
timetype
)
end
function
vlistDefVarName
(
vlistID
::
Cint
,
varID
::
Cint
,
name
::
AbstractString
)
ccall
((
:
vlistDefVarName
,
"libcdi"
),
Cvoid
,
(
Cint
,
Cint
,
Cstring
),
vlistID
,
varID
,
name
)
end
function
taxisCreate
(
taxistype
::
TAXIS_t
)
return
ccall
((
:
taxisCreate
,
"libcdi"
),
Cint
,
(
Cint
,),
taxistype
)
end
function
vlistDefTaxis
(
vlistID
::
Cint
,
taxisID
::
Cint
)
ccall
((
:
vlistDefTaxis
,
"libcdi"
),
Cvoid
,
(
Cint
,
Cint
),
vlistID
,
taxisID
)
end
function
streamOpenWrite
(
path
::
AbstractString
,
filetype
::
FileTypes_t
)
return
ccall
((
:
streamOpenWrite
,
"libcdi"
),
Cint
,
(
Cstring
,
Cint
),
path
,
filetype
)
end
function
cdiStringError
(
cdiErrno
::
Cint
)
str
=
ccall
((
:
cdiStringError
,
"libcdi"
),
Cstring
,
(
Cint
,),
cdiErrno
)
return
unsafe_string
(
str
)
end
function
streamDefVlist
(
streamID
::
Cint
,
vlistID
::
Cint
)
ccall
((
:
streamDefVlist
,
"libcdi"
),
Cvoid
,
(
Cint
,
Cint
),
streamID
,
vlistID
)
end
function
taxisDefVdate
(
taxisID
::
Cint
,
date
::
Int64
)
ccall
((
:
taxisDefVdate
,
"libcdi"
),
Cvoid
,
(
Cint
,
Int64
),
taxisID
,
date
)
end
function
taxisDefVtime
(
taxisID
::
Cint
,
time
::
Number
)
ccall
((
:
taxisDefVtime
,
"libcdi"
),
Cvoid
,
(
Cint
,
Cint
),
taxisID
,
time
)
end
function
streamDefTimestep
(
streamID
::
Cint
,
tsID
::
Number
)
::
Cint
return
ccall
((
:
streamDefTimestep
,
"libcdi"
),
Cint
,
(
Cint
,
Cint
),
streamID
,
tsID
)
end
function
streamWriteVar
(
streamID
::
Cint
,
varID
::
Cint
,
data
::
Vector
{
T
},
nmiss
::
Number
)
where
{
T
<:
Number
}
ccall
((
:
streamWriteVar
,
"libcdi"
),
Cvoid
,
(
Cint
,
Cint
,
Ptr
{
Cdouble
},
Csize_t
),
streamID
,
varID
,
data
,
nmiss
)
end
function
streamClose
(
streamID
::
Cint
)
ccall
((
:
streamClose
,
"libcdi"
),
Cvoid
,
(
Cint
,),
streamID
)
end
function
vlistDestroy
(
vlistID
::
Cint
)
ccall
((
:
vlistDestroy
,
"libcdi"
),
Cvoid
,
(
Cint
,),
vlistID
)
end
function
taxisDestroy
(
taxisID
::
Cint
)
ccall
((
:
taxisDestroy
,
"libcdi"
),
Cvoid
,
(
Cint
,),
taxisID
)
end
function
zaxisDestroy
(
zaxisID
::
Cint
)
ccall
((
:
zaxisDestroy
,
"libcdi"
),
Cvoid
,
(
Cint
,),
zaxisID
)
end
function
gridDestroy
(
gridID
::
Cint
)
ccall
((
:
gridDestroy
,
"libcdi"
),
Cvoid
,
(
Cint
,),
gridID
)
end
export
gridCreate
,
gridDefXsize
,
gridDefYsize
,
gridDefXvals
,
gridDefYvals
,
zaxisCreate
,
zaxisDefLevels
export
gridCreate
,
gridDefXsize
,
gridDefYsize
,
gridDefXvals
,
gridDefYvals
export
zaxisCreate
,
zaxisDefLevels
,
vlistCreate
,
vlistDefVar
,
vlistDefVarName
export
taxisCreate
,
vlistDefTaxis
,
streamOpenWrite
,
cdiStringError
export
streamDefVlist
,
taxisDefVdate
,
taxisDefVtime
,
streamDefTimestep
,
streamWriteVar
export
streamClose
,
vlistDestroy
,
taxisDestroy
,
zaxisDestroy
,
gridDestroy
end
#module cdi
\ No newline at end of file
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