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
daf85b52
Commit
daf85b52
authored
Apr 14, 2014
by
Thomas Jahns
🤸
Browse files
Complete comparison of vlists.
parent
3e35d2b1
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/vlist.c
View file @
daf85b52
...
...
@@ -46,15 +46,20 @@ static int vlistIsInitialized = 0;
#endif
/* FIXME: implementation incomplete, fix once leaf nodes are complete */
static
int
vlist_compare
(
vlist_t
*
a
,
vlist_t
*
b
)
{
int
diff
;
diff
=
(
a
->
nvars
!=
b
->
nvars
)
||
(
a
->
ngrids
!=
b
->
ngrids
)
||
(
a
->
nzaxis
!=
b
->
nzaxis
)
||
(
a
->
instID
!=
b
->
instID
)
||
(
a
->
modelID
!=
b
->
modelID
)
||
(
a
->
tableID
!=
b
->
tableID
)
||
(
a
->
ntsteps
!=
b
->
ntsteps
);
diff
=
(
a
->
nvars
!=
b
->
nvars
)
|
(
a
->
ngrids
!=
b
->
ngrids
)
|
(
a
->
nzaxis
!=
b
->
nzaxis
)
|
(
a
->
instID
!=
b
->
instID
)
|
(
a
->
modelID
!=
b
->
modelID
)
|
(
a
->
tableID
!=
b
->
tableID
)
|
(
a
->
ntsteps
!=
b
->
ntsteps
)
|
(
a
->
atts
.
nelems
!=
b
->
atts
.
nelems
);
int
nvars
=
a
->
nvars
;
for
(
int
varID
=
0
;
varID
<
nvars
;
++
varID
)
diff
|=
vlistVarCompare
(
a
,
varID
,
b
,
varID
);
int
natts
=
a
->
atts
.
nelems
;
for
(
int
attID
=
0
;
attID
<
natts
;
++
attID
)
diff
|=
vlist_att_compare
(
a
,
CDI_GLOBAL
,
b
,
CDI_GLOBAL
,
attID
);
return
diff
;
}
...
...
src/vlist.h
View file @
daf85b52
...
...
@@ -164,6 +164,9 @@ void vlistDefVarValidrange(int vlistID, int varID, const double *validrange);
/* vlistInqVarValidrange: Get the valid range of a Variable */
int
vlistInqVarValidrange
(
int
vlistID
,
int
varID
,
double
*
validrange
);
int
vlist_att_compare
(
vlist_t
*
a
,
int
varIDA
,
vlist_t
*
b
,
int
varIDB
,
int
attnum
);
#if defined (HAVE_LIBGRIB_API)
extern
int
cdiNAdditionalGRIBKeys
;
extern
char
*
cdiAdditionalGRIBKeys
[];
...
...
src/vlist_att.c
View file @
daf85b52
...
...
@@ -473,6 +473,32 @@ vlistAttTypeLookup(cdi_att_t *attp)
return
type
;
}
int
vlist_att_compare
(
vlist_t
*
a
,
int
varIDA
,
vlist_t
*
b
,
int
varIDB
,
int
attnum
)
{
cdi_atts_t
*
attspa
=
get_attsp
(
a
,
varIDA
),
*
attspb
=
get_attsp
(
b
,
varIDB
);
if
(
attspa
==
NULL
&&
attspb
==
NULL
)
return
0
;
xassert
(
attnum
>=
0
&&
attnum
<
(
int
)
attspa
->
nelems
&&
attnum
<
(
int
)
attspb
->
nelems
);
cdi_att_t
*
attpa
=
attspa
->
value
+
attnum
,
*
attpb
=
attspb
->
value
+
attnum
;
size_t
len
;
if
((
len
=
attpa
->
namesz
)
!=
attpb
->
namesz
)
return
1
;
int
diff
;
if
((
diff
=
memcmp
(
attpa
->
name
,
attpb
->
name
,
len
)))
return
1
;
if
(
attpa
->
indtype
!=
attpb
->
indtype
||
attpa
->
exdtype
!=
attpb
->
exdtype
||
attpa
->
nelems
!=
attpb
->
nelems
)
return
1
;
return
memcmp
(
attpa
->
xvalue
,
attpb
->
xvalue
,
attpa
->
xsz
);
}
static
int
vlistAttGetSize
(
vlist_t
*
vlistptr
,
int
varID
,
int
attnum
,
void
*
context
)
{
...
...
src/vlist_var.c
View file @
daf85b52
...
...
@@ -2116,6 +2116,51 @@ int vlistInqVarIOrank(int vlistID, int varID)
}
int
vlistVarCompare
(
vlist_t
*
a
,
int
varIDA
,
vlist_t
*
b
,
int
varIDB
)
{
xassert
(
a
&&
b
&&
varIDA
>=
0
&&
varIDA
<
a
->
nvars
&&
varIDB
>=
0
&&
varIDB
<
b
->
nvars
);
var_t
*
pva
=
a
->
vars
+
varIDA
,
*
pvb
=
b
->
vars
+
varIDB
;
#define FCMP(f) ((pva->f) != (pvb->f))
#define FCMPSTR(fs) ((pva->fs) != (pvb->fs) && strcmp((pva->fs), (pvb->fs)))
#define FCMP2(f) (namespaceResHDecode(pva->f).idx \
!= namespaceResHDecode(pvb->f).idx)
int
diff
=
FCMP
(
fvarID
)
|
FCMP
(
mvarID
)
|
FCMP
(
flag
)
|
FCMP
(
param
)
|
FCMP
(
datatype
)
|
FCMP
(
tsteptype
)
|
FCMP
(
timave
)
|
FCMP
(
timaccu
)
|
FCMP
(
chunktype
)
|
FCMP
(
xyz
)
|
FCMP2
(
gridID
)
|
FCMP2
(
zaxisID
)
|
FCMP2
(
instID
)
|
FCMP2
(
modelID
)
|
FCMP2
(
tableID
)
|
FCMP
(
missvalused
)
|
FCMP
(
missval
)
|
FCMP
(
addoffset
)
|
FCMP
(
scalefactor
)
|
FCMPSTR
(
name
)
|
FCMPSTR
(
longname
)
|
FCMPSTR
(
stdname
)
|
FCMPSTR
(
units
)
|
FCMPSTR
(
extra
)
|
FCMP
(
comptype
)
|
FCMP
(
complevel
)
|
FCMP
(
lvalidrange
)
|
FCMP
(
validrange
[
0
])
|
FCMP
(
validrange
[
1
]);
#undef FCMP
#undef FCMP2
if
((
diff
|=
((
pva
->
levinfo
==
NULL
)
^
(
pvb
->
levinfo
==
NULL
))))
return
1
;
if
(
pva
->
levinfo
)
{
int
zaxisID
=
pva
->
zaxisID
;
int
nlevs
=
zaxisInqSize
(
zaxisID
);
diff
|=
(
memcmp
(
pva
->
levinfo
,
pvb
->
levinfo
,
sizeof
(
levinfo_t
)
*
nlevs
)
!=
0
);
if
(
diff
)
return
1
;
}
int
natts
=
a
->
vars
[
varIDA
].
atts
.
nelems
;
if
(
natts
!=
b
->
vars
[
varIDB
].
atts
.
nelems
)
return
1
;
for
(
int
attID
=
0
;
attID
<
natts
;
++
attID
)
diff
|=
vlist_att_compare
(
a
,
varIDA
,
b
,
varIDB
,
attID
);
if
((
diff
|=
((
pva
->
ensdata
==
NULL
)
^
(
pvb
->
ensdata
==
NULL
))))
return
1
;
if
(
pva
->
ensdata
)
diff
=
(
memcmp
(
pva
->
ensdata
,
pvb
->
ensdata
,
sizeof
(
*
(
pva
->
ensdata
))))
!=
0
;
return
diff
;
}
enum
{
vlistvar_nints
=
20
,
vlistvar_ndbls
=
3
,
...
...
src/vlist_var.h
View file @
daf85b52
...
...
@@ -14,6 +14,7 @@ void vlistVarPack(vlist_t *p, int varID,
char
*
buffer
,
int
bufferSize
,
int
*
pos
,
void
*
context
);
void
vlistVarUnpack
(
int
vlistID
,
char
*
buf
,
int
size
,
int
*
position
,
int
,
void
*
context
);
int
vlistVarCompare
(
vlist_t
*
a
,
int
varIDA
,
vlist_t
*
b
,
int
varIDB
);
void
vlistDefVarIOrank
(
int
,
int
,
int
);
int
vlistInqVarIOrank
(
int
,
int
);
...
...
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