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
61fca261
Commit
61fca261
authored
Jan 04, 2018
by
Uwe Schulzweida
Browse files
Added CDI function cdiDefKeyInt()/cdiInqKeyInt().
parent
5f9a8c5f
Changes
11
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
61fca261
2018-02-25 Uwe Schulzweida
* Version 1.9.3 released
2018-01-04 Uwe Schulzweida
* Added CDI function cdiDefKeyInt()/cdiInqKeyInt()
2017-12-07 Uwe Schulzweida
* Check positive attribute for scalar z coordinates (bug fix)
...
...
src/Makefile.am
View file @
61fca261
...
...
@@ -117,6 +117,8 @@ libcdi_la_SOURCES = \
version.c
\
vlist.c
\
vlist.h
\
cdi_key.c
\
cdi_key.h
\
cdi_att.c
\
cdi_att.h
\
vlist_var.c
\
...
...
src/Makefile.in
View file @
61fca261
...
...
@@ -188,11 +188,12 @@ am__libcdi_la_SOURCES_DIST = basetime.c basetime.h binary.c binary.h \
cdf_read.c cdf_lazy_grid.c cdf_lazy_grid.h subtype.c subtype.h
\
swap.h table.c table.h tablepar.h taxis.c taxis.h timebase.c
\
timebase.h tsteps.c util.c varscan.c varscan.h version.c
\
vlist.c vlist.h cdi_att.c cdi_att.h vlist_var.c vlist_var.h
\
zaxis.c zaxis.h stream.c stream_write.c stream_read.c swap.c
\
iterator.c iterator.h iterator_fallback.c iterator_fallback.h
\
iterator_grib.c iterator_grib.h cfortran.h cdiFortran.c
\
gribapi_utilities.c stream_gribapi.c
vlist.c vlist.h cdi_key.c cdi_key.h cdi_att.c cdi_att.h
\
vlist_var.c vlist_var.h zaxis.c zaxis.h stream.c
\
stream_write.c stream_read.c swap.c iterator.c iterator.h
\
iterator_fallback.c iterator_fallback.h iterator_grib.c
\
iterator_grib.h cfortran.h cdiFortran.c gribapi_utilities.c
\
stream_gribapi.c
am__objects_1
=
cdiFortran.lo
@USE_FC_TRUE@
am__objects_2
=
$(am__objects_1)
am__objects_3
=
gribapi_utilities.lo stream_gribapi.lo
...
...
@@ -209,7 +210,7 @@ am_libcdi_la_OBJECTS = basetime.lo binary.lo calendar.lo cdf.lo \
stream_srv.lo stream_var.lo grb_write.lo grb_read.lo
\
cdf_write.lo cdf_read.lo cdf_lazy_grid.lo subtype.lo table.lo
\
taxis.lo timebase.lo tsteps.lo util.lo varscan.lo version.lo
\
vlist.lo cdi_att.lo vlist_var.lo zaxis.lo stream.lo
\
vlist.lo
cdi_key.lo
cdi_att.lo vlist_var.lo zaxis.lo stream.lo
\
stream_write.lo stream_read.lo swap.lo iterator.lo
\
iterator_fallback.lo iterator_grib.lo
$(am__objects_2)
\
$(am__objects_4)
...
...
@@ -531,11 +532,11 @@ libcdi_la_SOURCES = basetime.c basetime.h binary.c binary.h calendar.c \
cdf_read.c cdf_lazy_grid.c cdf_lazy_grid.h subtype.c subtype.h
\
swap.h table.c table.h tablepar.h taxis.c taxis.h timebase.c
\
timebase.h tsteps.c util.c varscan.c varscan.h version.c
\
vlist.c vlist.h cdi_
att
.c cdi_
att.h vlist_var.c vlist_var
.h
\
zaxis.c zaxis.h stream.c stream_write.c stream_read.c swap
.c
\
iterator.c iterator.h iterator_fallback
.c iterator
_fallback
.h
\
iterator_
grib
.c iterator_
grib.h
$(am__append_2)
\
$(am__append_3)
vlist.c vlist.h cdi_
key
.c cdi_
key.h cdi_att.c cdi_att
.h
\
vlist_var.c vlist_var.h zaxis.c zaxis.h stream
.c
\
stream_write.c stream_read.c swap.c iterator
.c iterator.h
\
iterator_
fallback
.c iterator_
fallback.h iterator_grib.c
\
iterator_grib.h
$(am__append_2)
$(am__append_3)
# cfortran.h is an optional part of libcdi
libcdi_la_USE_FC_extra_sources
=
\
...
...
@@ -703,6 +704,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/cdi_cksum.Plo@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/cdi_error.Plo@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/cdi_int.Plo@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/cdi_key.Plo@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/cdi_util.Plo@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/cdipioFortran.Plo@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/cgribexlib.Plo@am__quote@
...
...
src/cdi_att.c
View file @
61fca261
...
...
@@ -53,7 +53,7 @@ cdi_att_t *find_att(cdi_atts_t *attsp, const char *name)
{
cdi_att_t
*
attp
=
atts
+
attid
;
if
(
attp
->
namesz
==
slen
&&
memcmp
(
attp
->
name
,
name
,
slen
)
==
0
)
return
attp
;
/
*
Normal return
*/
return
attp
;
/
/
Normal return
}
return
NULL
;
...
...
@@ -264,7 +264,7 @@ int cdi_inq_att(int indtype, int cdiID, int varID, const char *name, size_t mxsz
xassert
(
attsp
!=
NULL
);
cdi_att_t
*
attp
=
find_att
(
attsp
,
name
);
if
(
attp
!=
NULL
)
/
*
name in use
*/
if
(
attp
!=
NULL
)
/
/
name in use
{
if
(
attp
->
indtype
==
indtype
)
{
...
...
src/cdi_att.h
View file @
61fca261
...
...
@@ -13,23 +13,23 @@
* CDI attribute
*/
typedef
struct
{
size_t
xsz
;
/
*
amount of space at xvalue
*/
size_t
namesz
;
/
*
size of name
*/
char
*
name
;
/
*
attribute name
*/
int
indtype
;
/
*
internal data type of xvalue (INT, FLT or TXT)
*/
int
exdtype
;
/
*
external data type
*/
/
*
indtype exdtype
*/
/
*
TXT TXT
*/
/
*
INT INT16, INT32
*/
/
*
FLT FLT32, FLT64
*/
size_t
nelems
;
/
*
number of elements
*/
void
*
xvalue
;
/
*
the actual data
*/
size_t
xsz
;
/
/
amount of space at xvalue
size_t
namesz
;
/
/
size of name
char
*
name
;
/
/
attribute name
int
indtype
;
/
/
internal data type of xvalue (INT, FLT or TXT)
int
exdtype
;
/
/
external data type
/
/
indtype exdtype
/
/
TXT TXT
/
/
INT INT16, INT32
/
/
FLT FLT32, FLT64
size_t
nelems
;
/
/
number of elements
void
*
xvalue
;
/
/
the actual data
}
cdi_att_t
;
typedef
struct
{
size_t
nalloc
;
/
*
number allocated >= nelems
*/
size_t
nelems
;
/
*
length of the array
*/
size_t
nalloc
;
/
/
number allocated >= nelems
size_t
nelems
;
/
/
length of the array
cdi_att_t
value
[
MAX_ATTRIBUTES
];
}
cdi_atts_t
;
...
...
src/cdi_key.c
0 → 100644
View file @
61fca261
#ifdef HAVE_CONFIG_H
#include
"config.h"
#endif
#include
"cdi.h"
#include
"cdi_int.h"
#include
"vlist.h"
#include
"grid.h"
#include
"zaxis.h"
static
cdi_keys_t
*
get_keysp
(
vlist_t
*
vlistptr
,
int
varID
)
{
cdi_keys_t
*
keysp
=
NULL
;
/*
if ( varID == CDI_GLOBAL )
{
keysp = &vlistptr->keys;
}
else
*/
{
if
(
varID
>=
0
&&
varID
<
vlistptr
->
nvars
)
keysp
=
&
(
vlistptr
->
vars
[
varID
].
keys
);
}
return
keysp
;
}
static
cdi_key_t
*
new_key
(
cdi_keys_t
*
keysp
,
int
key
)
{
xassert
(
keysp
!=
NULL
);
if
(
keysp
->
nelems
==
keysp
->
nalloc
)
return
NULL
;
cdi_key_t
*
keyp
=
&
(
keysp
->
value
[
keysp
->
nelems
]);
keysp
->
nelems
++
;
keyp
->
key
=
key
;
// keyp->v = 0;
return
keyp
;
}
static
cdi_key_t
*
find_key
(
cdi_keys_t
*
keysp
,
int
key
)
{
xassert
(
keysp
!=
NULL
);
if
(
keysp
->
nelems
==
0
)
return
NULL
;
cdi_key_t
*
keys
=
keysp
->
value
;
for
(
size_t
keyid
=
0
;
keyid
<
keysp
->
nelems
;
keyid
++
)
{
cdi_key_t
*
keyp
=
keys
+
keyid
;
if
(
keyp
->
key
==
key
)
return
keyp
;
// Normal return
}
return
NULL
;
}
static
cdi_keys_t
*
cdi_get_keysp
(
int
objID
,
int
varID
)
{
cdi_keys_t
*
keysp
=
NULL
;
/*
if ( varID == CDI_GLOBAL && reshGetTxCode(objID) == GRID )
{
grid_t *gridptr = grid_to_pointer(objID);
keysp = &gridptr->keys;
}
else if ( varID == CDI_GLOBAL && reshGetTxCode(objID) == ZAXIS )
{
zaxis_t *zaxisptr = zaxis_to_pointer(objID);
keysp = &zaxisptr->keys;
}
else
*/
{
vlist_t
*
vlistptr
=
vlist_to_pointer
(
objID
);
keysp
=
get_keysp
(
vlistptr
,
varID
);
}
return
keysp
;
}
// cqdiDefKeyInt: Define a CDI varianble integer value from a key
int
cdiDefKeyInt
(
int
cdiID
,
int
varID
,
int
key
,
int
value
)
{
int
status
=
CDI_NOERR
;
cdi_keys_t
*
keysp
=
cdi_get_keysp
(
cdiID
,
varID
);
xassert
(
keysp
!=
NULL
);
cdi_key_t
*
keyp
=
find_key
(
keysp
,
key
);
if
(
keyp
==
NULL
)
keyp
=
new_key
(
keysp
,
key
);
if
(
keyp
!=
NULL
)
{
if
(
keyp
->
v
.
i
!=
value
)
{
keyp
->
v
.
i
=
value
;
//reshSetStatus(cdiID, &vlistOps, RESH_DESYNC_IN_USE);
}
}
return
status
;
}
// cdiInqKeyInt: Get a CDI variable integer value from a key
int
cdiInqKeyInt
(
int
cdiID
,
int
varID
,
int
key
,
int
*
value
)
{
int
status
=
CDI_NOERR
;
cdi_keys_t
*
keysp
=
cdi_get_keysp
(
cdiID
,
varID
);
xassert
(
keysp
!=
NULL
);
cdi_key_t
*
keyp
=
find_key
(
keysp
,
key
);
if
(
keyp
!=
NULL
)
// key in use
{
// if ( keyp->indtype == indtype )
{
*
value
=
keyp
->
v
.
i
;
}
/*
else
{
Warning("Key %d has wrong data type!", key);
status = -2;
}
*/
}
else
{
//Warning("Internal problem, key %d not found!", key);
status
=
-
1
;
}
return
status
;
}
/*
* Local Variables:
* c-file-style: "Java"
* c-basic-offset: 2
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
src/cdi_key.h
0 → 100644
View file @
61fca261
#ifndef CDI_KEY_H
#define CDI_KEY_H
/*
* CDI key
*/
typedef
struct
{
int
key
;
// CDI key
union
{
int
i
;
double
d
;
char
*
s
;
}
v
;
}
cdi_key_t
;
typedef
struct
{
size_t
nalloc
;
// number allocated >= nelems
size_t
nelems
;
// length of the array
cdi_key_t
value
[
MAX_KEYS
];
}
cdi_keys_t
;
#endif
/*
* Local Variables:
* c-file-style: "Java"
* c-basic-offset: 2
* indent-tabs-mode: nil
* show-trailing-whitespace: t
* require-trailing-newline: t
* End:
*/
src/cdi_limits.h
View file @
61fca261
#ifndef CDI_LIMITS_H
#define CDI_LIMITS_H
#define MAX_GRIDS_PS 128
/* maximum number of different grids per stream */
#define MAX_ZAXES_PS 128
/* maximum number of different zaxes per stream */
#define MAX_ATTRIBUTES 256
/* maximum number of attributes per variable */
#define MAX_SUBTYPES_PS 128
/* maximum number of different subtypes per stream */
#define MAX_GRIDS_PS 128 // maximum number of different grids per stream
#define MAX_ZAXES_PS 128 // maximum number of different zaxes per stream
#define MAX_ATTRIBUTES 256 // maximum number of attributes per variable
#define MAX_KEYS 64 // maximum number of keys per variable
#define MAX_SUBTYPES_PS 128 // maximum number of different subtypes per stream
#endif
/* CDI_LIMITS_H */
/*
...
...
src/make_cdilib
View file @
61fca261
...
...
@@ -150,6 +150,7 @@ files="basetime.c \
util.c
\
varscan.c
\
vlist.c
\
cdi_key.c
\
cdi_att.c
\
vlist_var.c
\
zaxis.c"
...
...
src/vlist.h
View file @
61fca261
...
...
@@ -17,6 +17,7 @@
#define VALIDMISS 1.e+303
#include
"cdi_key.h"
#include
"cdi_att.h"
#include
"grid.h"
...
...
@@ -54,9 +55,9 @@ typedef struct
int
param
;
int
gridID
;
int
zaxisID
;
int
timetype
;
/
*
TIME_*
*/
int
tsteptype
;
/
*
TSTEP_*
*/
int
datatype
;
/
*
CDI_DATATYPE_PACKX for GRIB data, else CDI_DATATYPE_FLT32 or CDI_DATATYPE_FLT64
*/
int
timetype
;
/
/
TIME_*
int
tsteptype
;
/
/
TSTEP_*
int
datatype
;
/
/
CDI_DATATYPE_PACKX for GRIB data, else CDI_DATATYPE_FLT32 or CDI_DATATYPE_FLT64
int
instID
;
int
modelID
;
int
tableID
;
...
...
@@ -66,7 +67,7 @@ typedef struct
int
productDefinitionTemplate
;
int
chunktype
;
int
xyz
;
bool
missvalused
;
/
*
true if missval is defined
*/
bool
missvalused
;
/
/
true if missval is defined
bool
lvalidrange
;
char
*
name
;
char
*
longname
;
...
...
@@ -80,15 +81,16 @@ typedef struct
levinfo_t
*
levinfo
;
int
comptype
;
// compression type
int
complevel
;
// compression level
ensinfo_t
*
ensdata
;
/* Ensemble information */
ensinfo_t
*
ensdata
;
// Ensemble information
cdi_keys_t
keys
;
cdi_atts_t
atts
;
int
iorank
;
int
subtypeID
;
/
*
subtype ID for tile-related meta-data, currently for GRIB-API only.
*/
int
subtypeID
;
/
/
subtype ID for tile-related meta-data, currently for GRIB-API only.
int
opt_grib_nentries
;
/
*
current no. key-value pairs
*/
int
opt_grib_kvpair_size
;
/
*
current allocated size
*/
opt_key_val_pair_t
*
opt_grib_kvpair
;
/
*
(optional) list of keyword/value pairs
*/
int
opt_grib_nentries
;
/
/
current no. key-value pairs
int
opt_grib_kvpair_size
;
/
/
current allocated size
opt_key_val_pair_t
*
opt_grib_kvpair
;
/
/
(optional) list of keyword/value pairs
}
var_t
;
...
...
src/vlist_var.c
View file @
61fca261
...
...
@@ -56,6 +56,8 @@ void vlistvarInitEntry(int vlistID, int varID)
vlistptr
->
vars
[
varID
].
levinfo
=
NULL
;
vlistptr
->
vars
[
varID
].
comptype
=
CDI_COMPRESS_NONE
;
vlistptr
->
vars
[
varID
].
complevel
=
1
;
vlistptr
->
vars
[
varID
].
keys
.
nalloc
=
MAX_KEYS
;
vlistptr
->
vars
[
varID
].
keys
.
nelems
=
0
;
vlistptr
->
vars
[
varID
].
atts
.
nalloc
=
MAX_ATTRIBUTES
;
vlistptr
->
vars
[
varID
].
atts
.
nelems
=
0
;
vlistptr
->
vars
[
varID
].
lvalidrange
=
false
;
...
...
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