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
440a14ed
Commit
440a14ed
authored
Aug 16, 2013
by
Uwe Schulzweida
Browse files
netCDF: write reference of an unstructured grid
parent
1696cc61
Changes
2
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
440a14ed
...
...
@@ -3,6 +3,10 @@
* Version 1.6.2 released
* using CGRIBEX library version 1.6.2
2013-08-16 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* netCDF: write reference of an unstructured grid
2013-08-15 Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* made gridtype GRID_REFERENCE part of GRID_UNSTRUCTED
...
...
src/stream_cdf.c
View file @
440a14ed
...
...
@@ -84,6 +84,7 @@ typedef struct {
int
calendar
;
int
tableID
;
int
truncation
;
int
position
;
int
defmissval
;
int
deffillval
;
int
xtype
;
...
...
@@ -1898,6 +1899,47 @@ void cdfDefGdim(stream_t *streamptr, int gridID)
#endif
#if defined (HAVE_LIBNETCDF)
static
void
cdfDefGridReference
(
stream_t
*
streamptr
,
int
gridID
)
{
int
fileID
=
streamptr
->
fileID
;
int
number
=
gridInqNumber
(
gridID
);
if
(
number
>
0
)
{
cdf_put_att_int
(
fileID
,
NC_GLOBAL
,
"number_of_grid_used"
,
NC_INT
,
1
,
&
number
);
}
if
(
gridInqReference
(
gridID
,
NULL
)
)
{
char
gridfile
[
8912
];
gridInqReference
(
gridID
,
gridfile
);
if
(
gridfile
[
0
]
!=
0
)
cdf_put_att_text
(
fileID
,
NC_GLOBAL
,
"grid_file_uri"
,
strlen
(
gridfile
),
gridfile
);
}
}
static
void
cdfDefGridUUID
(
stream_t
*
streamptr
,
int
gridID
)
{
char
uuidOfHGrid
[
17
];
gridInqUUID
(
gridID
,
uuidOfHGrid
);
if
(
uuidOfHGrid
[
0
]
!=
0
)
{
char
uuidOfHGridStr
[
37
];
uuid2str
(
uuidOfHGrid
,
uuidOfHGridStr
);
if
(
uuidOfHGridStr
[
0
]
!=
0
&&
strlen
(
uuidOfHGridStr
)
==
36
)
{
int
fileID
=
streamptr
->
fileID
;
//if ( streamptr->ncmode == 2 ) cdf_redef(fileID);
cdf_put_att_text
(
fileID
,
NC_GLOBAL
,
"uuidOfHGrid"
,
36
,
uuidOfHGridStr
);
//if ( streamptr->ncmode == 2 ) cdf_enddef(fileID);
}
}
}
static
void
cdfDefUnstructured
(
stream_t
*
streamptr
,
int
gridID
)
{
...
...
@@ -1982,6 +2024,10 @@ void cdfDefUnstructured(stream_t *streamptr, int gridID)
nvertex
=
gridInqNvertex
(
gridID
);
if
(
nvertex
>
0
)
cdf_def_dim
(
fileID
,
vertname
,
nvertex
,
&
nvdimID
);
cdfDefGridReference
(
streamptr
,
gridID
);
cdfDefGridUUID
(
streamptr
,
gridID
);
if
(
gridInqXvalsPtr
(
gridID
)
)
{
cdf_def_var
(
fileID
,
xaxisname
,
(
nc_type
)
xtype
,
1
,
&
dimID
,
&
ncxvarid
);
...
...
@@ -2540,26 +2586,6 @@ void cdfDefMapping(stream_t *streamptr, int gridID)
#endif
#if defined (HAVE_LIBNETCDF)
static
void
cdfDefGridUUID
(
stream_t
*
streamptr
,
int
gridID
)
{
char
uuidOfHGrid
[
17
];
gridInqUUID
(
gridID
,
uuidOfHGrid
);
if
(
uuidOfHGrid
[
0
]
!=
0
)
{
char
uuidOfHGridStr
[
37
];
uuid2str
(
uuidOfHGrid
,
uuidOfHGridStr
);
if
(
uuidOfHGridStr
[
0
]
!=
0
&&
strlen
(
uuidOfHGridStr
)
==
36
)
{
int
fileID
=
streamptr
->
fileID
;
if
(
streamptr
->
ncmode
==
2
)
cdf_redef
(
fileID
);
cdf_put_att_text
(
fileID
,
NC_GLOBAL
,
"uuidOfHGrid"
,
36
,
uuidOfHGridStr
);
if
(
streamptr
->
ncmode
==
2
)
cdf_enddef
(
fileID
);
}
}
}
static
void
cdfDefGrid
(
stream_t
*
streamptr
,
int
gridID
)
{
...
...
@@ -2657,8 +2683,6 @@ void cdfDefGrid(stream_t *streamptr, int gridID)
{
Error
(
"Unsupported grid type: %s"
,
gridNamePtr
(
gridtype
));
}
cdfDefGridUUID
(
streamptr
,
gridID
);
}
#endif
...
...
@@ -3034,6 +3058,13 @@ int cdfDefVar(stream_t *streamptr, int varID)
len
=
strlen
(
cellarea
);
cdf_put_att_text
(
fileID
,
ncvarid
,
"cell_measures"
,
len
,
cellarea
);
}
if
(
gridtype
==
GRID_UNSTRUCTURED
)
{
int
position
=
gridInqPosition
(
gridID
);
if
(
position
>
0
)
cdf_put_att_int
(
fileID
,
ncvarid
,
"number_of_grid_in_reference"
,
NC_INT
,
1
,
&
position
);
}
}
else
if
(
gridtype
==
GRID_SPECTRAL
||
gridtype
==
GRID_FOURIER
)
{
...
...
@@ -3623,8 +3654,7 @@ void cdf_write_var_chunk(stream_t *streamptr, int varID, int memtype,
if
(
zid
!=
UNDEFID
)
{
int
size
=
zaxisInqSize
(
zaxisID
);
xassert
(
rect
[
2
][
0
]
>=
0
&&
rect
[
2
][
0
]
<=
rect
[
2
][
1
]
&&
rect
[
2
][
1
]
<=
size
);
xassert
(
rect
[
2
][
0
]
>=
0
&&
rect
[
2
][
0
]
<=
rect
[
2
][
1
]
&&
rect
[
2
][
1
]
<=
size
);
start
[
ndims
]
=
rect
[
2
][
0
];
count
[
ndims
]
=
rect
[
2
][
1
]
-
rect
[
2
][
0
]
+
1
;
ndims
++
;
...
...
@@ -3633,8 +3663,7 @@ void cdf_write_var_chunk(stream_t *streamptr, int varID, int memtype,
{
size_t
size
;
cdf_inq_dimlen
(
fileID
,
yid
,
&
size
);
xassert
(
rect
[
1
][
0
]
>=
0
&&
rect
[
1
][
0
]
<=
rect
[
1
][
1
]
&&
rect
[
1
][
1
]
<=
size
);
xassert
(
rect
[
1
][
0
]
>=
0
&&
rect
[
1
][
0
]
<=
rect
[
1
][
1
]
&&
rect
[
1
][
1
]
<=
size
);
start
[
ndims
]
=
rect
[
1
][
0
];
count
[
ndims
]
=
rect
[
1
][
1
]
-
rect
[
1
][
0
]
+
1
;
ndims
++
;
...
...
@@ -3643,8 +3672,7 @@ void cdf_write_var_chunk(stream_t *streamptr, int varID, int memtype,
{
size_t
size
;
cdf_inq_dimlen
(
fileID
,
xid
,
&
size
);
xassert
(
rect
[
0
][
0
]
>=
0
&&
rect
[
0
][
0
]
<=
rect
[
0
][
1
]
&&
rect
[
0
][
1
]
<=
size
);
xassert
(
rect
[
0
][
0
]
>=
0
&&
rect
[
0
][
0
]
<=
rect
[
0
][
1
]
&&
rect
[
0
][
1
]
<=
size
);
start
[
ndims
]
=
rect
[
0
][
0
];
count
[
ndims
]
=
rect
[
0
][
1
]
-
rect
[
0
][
0
]
+
1
;
ndims
++
;
...
...
@@ -4226,6 +4254,7 @@ void init_ncvars(long nvars, ncvar_t *ncvars)
ncvars
[
ncvarid
].
vlen
=
0
;
ncvars
[
ncvarid
].
vdata
=
NULL
;
ncvars
[
ncvarid
].
truncation
=
0
;
ncvars
[
ncvarid
].
position
=
0
;
ncvars
[
ncvarid
].
positive
=
0
;
ncvars
[
ncvarid
].
chunked
=
0
;
ncvars
[
ncvarid
].
chunktype
=
UNDEFID
;
...
...
@@ -4738,6 +4767,10 @@ void cdfScanVarAttributes(int nvars, ncvar_t *ncvars, ncdim_t *ncdims,
{
cdfGetAttInt
(
ncid
,
ncvarid
,
attname
,
1
,
&
ncvars
[
ncvarid
].
truncation
);
}
else
if
(
strcmp
(
attname
,
"number_of_grid_in_reference"
)
==
0
&&
atttype
!=
NC_CHAR
)
{
cdfGetAttInt
(
ncid
,
ncvarid
,
attname
,
1
,
&
ncvars
[
ncvarid
].
position
);
}
else
if
(
strcmp
(
attname
,
"add_offset"
)
==
0
&&
atttype
!=
NC_CHAR
)
{
cdfGetAttDouble
(
ncid
,
ncvarid
,
attname
,
1
,
&
ncvars
[
ncvarid
].
addoffset
);
...
...
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