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
a29e8a31
Commit
a29e8a31
authored
Nov 14, 2007
by
Uwe Schulzweida
Browse files
update attributes
parent
bf9b553c
Changes
7
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
a29e8a31
2007-12-?? Uwe Schulzweida <Uwe.Schulzweida@zmaw.de>
* using GRIB library version 1.0.7
* new attribute routines: vlistInqNatts, vlist
Inq
Attr
,
vlist
Def
Attr
and vlistInqAttr
for Int, Flt and Txt
* new attribute routines: vlistInqNatts, vlist
Def
Attr
and
vlist
Inq
Attr
for Int, Flt and Txt
* add support for Lambert conformal grids
* Version 1.0.9 released
...
...
src/stream_cdf.c
View file @
a29e8a31
...
...
@@ -81,6 +81,8 @@ typedef struct {
int
positive
;
int
dimids
[
8
];
int
dimtype
[
8
];
int
natts
;
int
*
atts
;
size_t
vlen
;
double
*
vdata
;
double
missval
;
...
...
@@ -310,6 +312,44 @@ int cdfDefDatatype(int datatype)
#endif
#if defined (HAVE_LIBNETCDF)
void
defineAttributes
(
int
vlistID
,
int
varID
,
int
fileID
,
int
ncvarID
)
{
int
natts
,
iatt
;
int
attrtype
,
attrlen
;
size_t
len
;
int
attrint
;
double
attrflt
;
char
attrname
[
1024
];
char
attrtxt
[
8192
];
vlistInqNatts
(
vlistID
,
varID
,
&
natts
);
for
(
iatt
=
0
;
iatt
<
natts
;
iatt
++
)
{
vlistInqAttr
(
vlistID
,
varID
,
iatt
,
attrname
,
&
attrtype
,
&
attrlen
);
if
(
attrtype
==
DATATYPE_TXT
)
{
vlistInqAttrTxt
(
vlistID
,
varID
,
attrname
,
sizeof
(
attrtxt
),
attrtxt
);
len
=
strlen
(
attrtxt
);
cdf_put_att_text
(
fileID
,
ncvarID
,
attrname
,
len
+
1
,
attrtxt
);
}
else
if
(
attrtype
==
DATATYPE_INT
)
{
vlistInqAttrInt
(
vlistID
,
varID
,
attrname
,
1
,
&
attrint
);
cdf_put_att_int
(
fileID
,
ncvarID
,
attrname
,
NC_INT
,
1L
,
&
attrint
);
}
else
if
(
attrtype
==
DATATYPE_FLT
)
{
vlistInqAttrFlt
(
vlistID
,
varID
,
attrname
,
1
,
&
attrflt
);
cdf_put_att_double
(
fileID
,
ncvarID
,
attrname
,
NC_DOUBLE
,
1L
,
&
attrflt
);
}
}
}
#endif
int
cdfCopyRecord
(
int
streamID2
,
int
streamID1
)
{
static
char
func
[]
=
"cdfCopyRecord"
;
...
...
@@ -2250,6 +2290,9 @@ int cdfDefVar(int streamID, int varID)
streamptr
->
vars
[
varID
].
ncvarid
=
ncvarid
;
/* Attributes */
defineAttributes
(
vlistID
,
varID
,
fileID
,
ncvarid
);
if
(
streamptr
->
ncmode
==
2
)
cdf_enddef
(
fileID
);
#endif
...
...
@@ -3257,6 +3300,8 @@ int cdfInqContents(int streamID)
ncvars
[
ncvarid
].
longname
[
0
]
=
0
;
ncvars
[
ncvarid
].
stdname
[
0
]
=
0
;
ncvars
[
ncvarid
].
units
[
0
]
=
0
;
ncvars
[
ncvarid
].
natts
=
0
;
ncvars
[
ncvarid
].
atts
=
NULL
;
}
/* read global attributtes*/
...
...
@@ -3368,7 +3413,7 @@ int cdfInqContents(int streamID)
{
cdfGetAttText
(
fileID
,
ncvarid
,
attname
,
ncvars
[
ncvarid
].
longname
,
MAXNAMELEN
);
}
if
(
strcmp
(
attname
,
"standard_name"
)
==
0
)
else
if
(
strcmp
(
attname
,
"standard_name"
)
==
0
)
{
cdfGetAttText
(
fileID
,
ncvarid
,
attname
,
ncvars
[
ncvarid
].
stdname
,
MAXNAMELEN
);
}
...
...
@@ -3668,6 +3713,38 @@ int cdfInqContents(int streamID)
}
}
}
else
{
if
(
ncvars
[
ncvarid
].
natts
==
0
)
ncvars
[
ncvarid
].
atts
=
(
int
*
)
malloc
(
nvatts
*
sizeof
(
int
));
ncvars
[
ncvarid
].
atts
[
ncvars
[
ncvarid
].
natts
++
]
=
iatt
;
/*
int attrint;
double attrflt;
nc_type attrtype;
cdf_inq_attlen(fileID, ncvarid, attname, &attlen);
cdf_inq_atttype(fileID, ncvarid, attname, &attrtype);
if ( attlen == 1 && (attrtype == NC_INT || attrtype == NC_SHORT) )
{
cdfGetAttInt(fileID, ncvarid, attname, &attrint);
printf("int: %s.%s = %d\n", ncvars[ncvarid].name, attname, attrint);
}
else if ( attlen == 1 && (attrtype == NC_FLOAT || attrtype == NC_DOUBLE) )
{
cdfGetAttDouble(fileID, ncvarid, attname, &attrflt);
printf("flt: %s.%s = %g\n", ncvars[ncvarid].name, attname, attrflt);
}
else if ( attrtype == NC_CHAR )
{
cdfGetAttText(fileID, ncvarid, attname, attstring, attstringlen-1);
attstring[attlen] = 0;
printf("txt: %s.%s = %s\n", ncvars[ncvarid].name, attname, attstring);
}
else
printf("att: %s.%s = unknown\n", ncvars[ncvarid].name, attname);
*/
}
}
}
...
...
@@ -3840,8 +3917,12 @@ int cdfInqContents(int streamID)
{
if
(
strcmp
(
ncvars
[
ncvarid
].
longname
,
"hybrid level at layer midpoints"
)
==
0
)
ncvars
[
ncvarid
].
zaxistype
=
ZAXIS_HYBRID
;
else
if
(
strncmp
(
ncvars
[
ncvarid
].
longname
,
"hybrid level at midpoints"
,
25
)
==
0
)
ncvars
[
ncvarid
].
zaxistype
=
ZAXIS_HYBRID
;
else
if
(
strcmp
(
ncvars
[
ncvarid
].
longname
,
"hybrid level at layer interfaces"
)
==
0
)
ncvars
[
ncvarid
].
zaxistype
=
ZAXIS_HYBRID_HALF
;
else
if
(
strncmp
(
ncvars
[
ncvarid
].
longname
,
"hybrid level at interfaces"
,
26
)
==
0
)
ncvars
[
ncvarid
].
zaxistype
=
ZAXIS_HYBRID_HALF
;
else
ncvars
[
ncvarid
].
zaxistype
=
ZAXIS_GENERIC
;
}
...
...
@@ -3930,8 +4011,12 @@ int cdfInqContents(int streamID)
{
if
(
strcmp
(
ncvars
[
ncvarid
].
longname
,
"hybrid level at layer midpoints"
)
==
0
)
ncvars
[
ncvarid
].
zaxistype
=
ZAXIS_HYBRID
;
else
if
(
strncmp
(
ncvars
[
ncvarid
].
longname
,
"hybrid level at midpoints"
,
25
)
==
0
)
ncvars
[
ncvarid
].
zaxistype
=
ZAXIS_HYBRID
;
else
if
(
strcmp
(
ncvars
[
ncvarid
].
longname
,
"hybrid level at layer interfaces"
)
==
0
)
ncvars
[
ncvarid
].
zaxistype
=
ZAXIS_HYBRID_HALF
;
else
if
(
strncmp
(
ncvars
[
ncvarid
].
longname
,
"hybrid level at interfaces"
,
26
)
==
0
)
ncvars
[
ncvarid
].
zaxistype
=
ZAXIS_HYBRID_HALF
;
else
ncvars
[
ncvarid
].
zaxistype
=
ZAXIS_GENERIC
;
continue
;
...
...
@@ -4609,6 +4694,56 @@ int cdfInqContents(int streamID)
vlistInqVarGrid
(
vlistID
,
varID
),
vlistInqVarZaxis
(
vlistID
,
varID
));
}
for
(
varID
=
0
;
varID
<
nvars
;
varID
++
)
{
ncvarid
=
varids
[
varID
];
if
(
ncvars
[
ncvarid
].
natts
)
{
int
attnum
,
attrint
;
double
attrflt
;
nc_type
attrtype
;
nvatts
=
ncvars
[
ncvarid
].
natts
;
for
(
iatt
=
0
;
iatt
<
nvatts
;
iatt
++
)
{
attnum
=
ncvars
[
ncvarid
].
atts
[
iatt
];
cdf_inq_attname
(
fileID
,
ncvarid
,
attnum
,
attname
);
cdf_inq_attlen
(
fileID
,
ncvarid
,
attname
,
&
attlen
);
cdf_inq_atttype
(
fileID
,
ncvarid
,
attname
,
&
attrtype
);
if
(
attlen
==
1
&&
(
attrtype
==
NC_INT
||
attrtype
==
NC_SHORT
)
)
{
cdfGetAttInt
(
fileID
,
ncvarid
,
attname
,
&
attrint
);
vlistDefAttrInt
(
vlistID
,
varID
,
attname
,
1
,
&
attrint
);
if
(
CDI_Debug
)
printf
(
"int: %s.%s = %d
\n
"
,
ncvars
[
ncvarid
].
name
,
attname
,
attrint
);
}
else
if
(
attlen
==
1
&&
(
attrtype
==
NC_FLOAT
||
attrtype
==
NC_DOUBLE
)
)
{
cdfGetAttDouble
(
fileID
,
ncvarid
,
attname
,
&
attrflt
);
vlistDefAttrFlt
(
vlistID
,
varID
,
attname
,
1
,
&
attrflt
);
if
(
CDI_Debug
)
printf
(
"flt: %s.%s = %g
\n
"
,
ncvars
[
ncvarid
].
name
,
attname
,
attrflt
);
}
else
if
(
attrtype
==
NC_CHAR
)
{
cdfGetAttText
(
fileID
,
ncvarid
,
attname
,
attstring
,
attstringlen
-
1
);
attstring
[
attlen
]
=
0
;
vlistDefAttrTxt
(
vlistID
,
varID
,
attname
,
attlen
+
1
,
attstring
);
if
(
CDI_Debug
)
printf
(
"txt: %s.%s = %s
\n
"
,
ncvars
[
ncvarid
].
name
,
attname
,
attstring
);
}
else
{
if
(
CDI_Debug
)
printf
(
"att: %s.%s = unknown
\n
"
,
ncvars
[
ncvarid
].
name
,
attname
);
}
}
free
(
ncvars
[
ncvarid
].
atts
);
}
}
if
(
varids
)
free
(
varids
);
for
(
varID
=
0
;
varID
<
nvars
;
varID
++
)
...
...
@@ -4675,7 +4810,7 @@ int cdfInqContents(int streamID)
if
(
modelID
!=
UNDEFID
)
vlistDefVarModel
(
vlistID
,
varID
,
modelID
);
if
(
tableID
!=
UNDEFID
)
vlistDefVarTable
(
vlistID
,
varID
,
tableID
);
}
cdiCreateTimesteps
(
streamID
);
/* time varID */
...
...
@@ -4905,17 +5040,9 @@ void cdfDefGlobalAtts(int streamID)
{
#if defined (HAVE_LIBNETCDF)
int
fileID
,
vlistID
;
int
iatt
;
size_t
len
;
VLIST
*
vlistptr
;
STREAM
*
streamptr
;
int
natts
;
char
attrname
[
256
];
int
attrtype
;
int
attrlen
;
int
attrint
;
double
attrflt
;
char
attrtxt
[
2048
];
streamptr
=
stream_to_pointer
(
streamID
);
...
...
@@ -4933,27 +5060,7 @@ void cdfDefGlobalAtts(int streamID)
if
(
natts
>
0
&&
streamptr
->
ncmode
==
2
)
cdf_redef
(
fileID
);
for
(
iatt
=
0
;
iatt
<
natts
;
++
iatt
)
{
vlistInqAttr
(
vlistID
,
CDI_GLOBAL
,
iatt
,
attrname
,
&
attrtype
,
&
attrlen
);
if
(
attrtype
==
DATATYPE_TXT
)
{
vlistInqAttrTxt
(
vlistID
,
CDI_GLOBAL
,
attrname
,
sizeof
(
attrtxt
),
attrtxt
);
len
=
strlen
(
attrtxt
);
cdf_put_att_text
(
fileID
,
NC_GLOBAL
,
attrname
,
len
+
1
,
attrtxt
);
}
else
if
(
attrtype
==
DATATYPE_INT
)
{
vlistInqAttrInt
(
vlistID
,
CDI_GLOBAL
,
attrname
,
1
,
&
attrint
);
cdf_put_att_int
(
fileID
,
NC_GLOBAL
,
attrname
,
NC_INT
,
1L
,
&
attrint
);
}
else
if
(
attrtype
==
DATATYPE_FLT
)
{
vlistInqAttrFlt
(
vlistID
,
CDI_GLOBAL
,
attrname
,
1
,
&
attrflt
);
cdf_put_att_double
(
fileID
,
NC_GLOBAL
,
attrname
,
NC_DOUBLE
,
1L
,
&
attrflt
);
}
}
defineAttributes
(
vlistID
,
CDI_GLOBAL
,
fileID
,
NC_GLOBAL
);
if
(
natts
>
0
&&
streamptr
->
ncmode
==
2
)
cdf_enddef
(
fileID
);
...
...
src/stream_int.c
View file @
a29e8a31
...
...
@@ -341,7 +341,7 @@ STREAM *stream_new_entry(void)
static
char
func
[]
=
"stream_new_entry"
;
STREAM
*
streamptr
;
cdiInitialize
();
/* ***************** make MT versio
b
!!! */
cdiInitialize
();
/* ***************** make MT versio
n
!!! */
STREAM_INIT
...
...
src/vlist.c
View file @
a29e8a31
...
...
@@ -156,7 +156,7 @@ static void vlist_init_entry(VLIST *vlistptr)
vlistptr
->
varsAllocated
=
0
;
vlistptr
->
ntsteps
=
CDI_UNDEFID
;
vlistptr
->
atts
.
nalloc
=
MAX_ATTRIBUTES
;
vlistptr
->
atts
.
nelems
=
0
;
vlistptr
->
atts
.
nelems
=
0
;
}
...
...
@@ -315,7 +315,11 @@ void vlistDestroy(int vlistID)
vlistDelAtts
(
vlistID
,
CDI_GLOBAL
);
for
(
varID
=
0
;
varID
<
nvars
;
varID
++
)
if
(
vlistptr
->
vars
[
varID
].
levinfo
)
free
(
vlistptr
->
vars
[
varID
].
levinfo
);
{
if
(
vlistptr
->
vars
[
varID
].
levinfo
)
free
(
vlistptr
->
vars
[
varID
].
levinfo
);
vlistDelAtts
(
vlistID
,
varID
);
}
if
(
vlistptr
->
vars
)
free
(
vlistptr
->
vars
);
...
...
@@ -417,6 +421,9 @@ void vlistCopy(int vlistID2, int vlistID1)
vlistptr2
->
vars
[
varID
].
levinfo
=
(
LEVINFO
*
)
malloc
(
nlevs
*
sizeof
(
LEVINFO
));
memcpy
(
vlistptr2
->
vars
[
varID
].
levinfo
,
vlistptr1
->
vars
[
varID
].
levinfo
,
nlevs
*
sizeof
(
LEVINFO
));
vlistptr2
->
vars
[
varID
].
atts
.
nelems
=
0
;
vlistCopyVarAtts
(
vlistID1
,
varID
,
vlistID2
,
varID
);
}
}
...
...
@@ -627,6 +634,9 @@ void vlistCopyFlag(int vlistID2, int vlistID1)
vlistptr2
->
vars
[
varID2
].
levinfo
=
(
LEVINFO
*
)
malloc
(
nlevs2
*
sizeof
(
LEVINFO
));
vlistptr2
->
vars
[
varID2
].
atts
.
nelems
=
0
;
vlistCopyVarAtts
(
vlistID1
,
varID
,
vlistID2
,
varID2
);
if
(
nlevs
!=
nlevs2
)
{
int
zaxisType
;
...
...
src/vlist.h
View file @
a29e8a31
...
...
@@ -64,6 +64,7 @@ typedef struct
double
addoffset
;
LEVINFO
*
levinfo
;
int
szip
;
CDI_atts
atts
;
}
VARINFO
;
...
...
src/vlist_att.c
View file @
a29e8a31
...
...
@@ -21,7 +21,8 @@ CDI_atts *get_attsp(VLIST *vlistptr, int varID)
}
else
{
/* attsp = vlistptr->vars[varID]->atts; */
if
(
varID
>=
0
&&
varID
<
vlistptr
->
nvars
)
attsp
=
&
(
vlistptr
->
vars
[
varID
].
atts
);
}
return
(
attsp
);
...
...
@@ -106,7 +107,7 @@ int vlistInqNatts(int vlistID, int varID, int *nattsp)
vlistptr
=
vlist_to_pointer
(
vlistID
);
attsp
=
get_attsp
(
vlistptr
,
varID
);
if
(
attsp
=
=
NULL
)
Error
(
func
,
"Internal problem, attributes not found!"
);
assert
(
attsp
!
=
NULL
);
*
nattsp
=
attsp
->
nelems
;
...
...
@@ -127,7 +128,7 @@ int vlistInqAttr(int vlistID, int varID, int attrnum, char *name, int *typep, in
vlistptr
=
vlist_to_pointer
(
vlistID
);
attsp
=
get_attsp
(
vlistptr
,
varID
);
if
(
attsp
=
=
NULL
)
Error
(
func
,
"Internal problem, attributes not found!"
);
assert
(
attsp
!
=
NULL
);
if
(
attrnum
>=
0
&&
attrnum
<
(
int
)
attsp
->
nelems
)
attrp
=
&
(
attsp
->
value
[
attrnum
]);
...
...
@@ -161,7 +162,7 @@ int vlistDelAtts(int vlistID, int varID)
vlistptr
=
vlist_to_pointer
(
vlistID
);
attsp
=
get_attsp
(
vlistptr
,
varID
);
if
(
attsp
=
=
NULL
)
Error
(
func
,
"Internal problem, attributes not found!"
);
assert
(
attsp
!
=
NULL
);
for
(
attrid
=
0
;
attrid
<
(
int
)
attsp
->
nelems
;
attrid
++
)
{
...
...
@@ -203,7 +204,7 @@ int vlist_def_attr(int type, int vlistID, int varID, const char *name, size_t le
vlistptr
=
vlist_to_pointer
(
vlistID
);
attsp
=
get_attsp
(
vlistptr
,
varID
);
if
(
attsp
=
=
NULL
)
Error
(
func
,
"Internal problem, attributes not found!"
);
assert
(
attsp
!
=
NULL
);
attrp
=
find_attr
(
attsp
,
name
);
if
(
attrp
!=
NULL
)
/* name in use */
...
...
@@ -238,7 +239,7 @@ int vlist_inq_attr(int type, int vlistID, int varID, const char *name, size_t mx
vlistptr
=
vlist_to_pointer
(
vlistID
);
attsp
=
get_attsp
(
vlistptr
,
varID
);
if
(
attsp
=
=
NULL
)
Error
(
func
,
"Internal problem, attributes not found!"
);
assert
(
attsp
!
=
NULL
);
attrp
=
find_attr
(
attsp
,
name
);
if
(
attrp
!=
NULL
)
/* name in use */
...
...
@@ -268,7 +269,7 @@ int vlistCopyVarAtts(int vlistID1, int varID_1, int vlistID2, int varID_2)
vlistptr1
=
vlist_to_pointer
(
vlistID1
);
attsp1
=
get_attsp
(
vlistptr1
,
varID_1
);
if
(
attsp1
=
=
NULL
)
Error
(
func
,
"Internal problem, attributes not found!"
);
assert
(
attsp1
!
=
NULL
);
for
(
attrid
=
0
;
attrid
<
(
int
)
attsp1
->
nelems
;
attrid
++
)
{
...
...
src/vlist_var.c
View file @
a29e8a31
...
...
@@ -36,6 +36,8 @@ static void vlistvarInitEntry(int vlistID, int varID)
vlistptr
->
vars
[
varID
].
nlevs
=
0
;
vlistptr
->
vars
[
varID
].
levinfo
=
NULL
;
vlistptr
->
vars
[
varID
].
szip
=
FALSE
;
vlistptr
->
vars
[
varID
].
atts
.
nalloc
=
MAX_ATTRIBUTES
;
vlistptr
->
vars
[
varID
].
atts
.
nelems
=
0
;
}
static
int
vlistvarNewEntry
(
int
vlistID
)
...
...
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