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
3ce4c9ca
Commit
3ce4c9ca
authored
Nov 21, 2018
by
Uwe Schulzweida
Browse files
Renamed strIsEqual() to strStartsWith().
parent
69643073
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/cdf_util.c
View file @
3ce4c9ca
...
...
@@ -16,13 +16,15 @@ char *strToLower(char *str)
}
bool
str
IsEqual
(
const
char
*
vstr
,
const
char
*
cstr
)
bool
str
StartsWith
(
const
char
*
vstr
,
const
char
*
cstr
)
{
bool
is_equal
=
false
;
size_t
clen
=
(
cstr
!=
NULL
)
?
strlen
(
cstr
)
:
0
;
if
(
vstr
&&
*
vstr
)
is_equal
=
(
memcmp
(
vstr
,
cstr
,
clen
)
==
0
);
if
(
vstr
&&
*
vstr
)
{
size_t
clen
=
(
cstr
!=
NULL
)
?
strlen
(
cstr
)
:
0
;
size_t
vlen
=
(
vstr
!=
NULL
)
?
strlen
(
vstr
)
:
0
;
if
(
clen
<=
vlen
)
is_equal
=
(
memcmp
(
vstr
,
cstr
,
clen
)
==
0
);
}
return
is_equal
;
}
...
...
@@ -34,13 +36,13 @@ int get_timeunit(size_t len, const char *ptu)
if
(
len
>
2
)
{
if
(
str
IsEqual
(
ptu
,
"sec"
)
)
timeunit
=
TUNIT_SECOND
;
else
if
(
str
IsEqual
(
ptu
,
"minute"
)
)
timeunit
=
TUNIT_MINUTE
;
else
if
(
str
IsEqual
(
ptu
,
"hour"
)
)
timeunit
=
TUNIT_HOUR
;
else
if
(
str
IsEqual
(
ptu
,
"day"
)
)
timeunit
=
TUNIT_DAY
;
else
if
(
str
IsEqual
(
ptu
,
"month"
)
)
timeunit
=
TUNIT_MONTH
;
else
if
(
str
IsEqual
(
ptu
,
"calendar_month"
)
)
timeunit
=
TUNIT_MONTH
;
else
if
(
str
IsEqual
(
ptu
,
"year"
)
)
timeunit
=
TUNIT_YEAR
;
if
(
str
StartsWith
(
ptu
,
"sec"
)
)
timeunit
=
TUNIT_SECOND
;
else
if
(
str
StartsWith
(
ptu
,
"minute"
)
)
timeunit
=
TUNIT_MINUTE
;
else
if
(
str
StartsWith
(
ptu
,
"hour"
)
)
timeunit
=
TUNIT_HOUR
;
else
if
(
str
StartsWith
(
ptu
,
"day"
)
)
timeunit
=
TUNIT_DAY
;
else
if
(
str
StartsWith
(
ptu
,
"month"
)
)
timeunit
=
TUNIT_MONTH
;
else
if
(
str
StartsWith
(
ptu
,
"calendar_month"
)
)
timeunit
=
TUNIT_MONTH
;
else
if
(
str
StartsWith
(
ptu
,
"year"
)
)
timeunit
=
TUNIT_YEAR
;
}
else
if
(
len
==
1
&&
ptu
[
0
]
==
's'
)
timeunit
=
TUNIT_SECOND
;
...
...
@@ -52,13 +54,13 @@ bool is_time_units(const char *timeunits)
{
while
(
isspace
(
*
timeunits
)
)
timeunits
++
;
bool
status
=
str
IsEqual
(
timeunits
,
"sec"
)
||
str
IsEqual
(
timeunits
,
"minute"
)
||
str
IsEqual
(
timeunits
,
"hour"
)
||
str
IsEqual
(
timeunits
,
"day"
)
||
str
IsEqual
(
timeunits
,
"month"
)
||
str
IsEqual
(
timeunits
,
"calendar_month"
)
||
str
IsEqual
(
timeunits
,
"year"
);
bool
status
=
str
StartsWith
(
timeunits
,
"sec"
)
||
str
StartsWith
(
timeunits
,
"minute"
)
||
str
StartsWith
(
timeunits
,
"hour"
)
||
str
StartsWith
(
timeunits
,
"day"
)
||
str
StartsWith
(
timeunits
,
"month"
)
||
str
StartsWith
(
timeunits
,
"calendar_month"
)
||
str
StartsWith
(
timeunits
,
"year"
);
return
status
;
}
...
...
@@ -83,8 +85,8 @@ bool is_timeaxis_units(const char *timeunits)
{
while
(
isspace
(
*
ptu
)
)
ptu
++
;
int
timetype
=
str
IsEqual
(
ptu
,
"as"
)
?
TAXIS_ABSOLUTE
:
str
IsEqual
(
ptu
,
"since"
)
?
TAXIS_RELATIVE
:
-
1
;
int
timetype
=
str
StartsWith
(
ptu
,
"as"
)
?
TAXIS_ABSOLUTE
:
str
StartsWith
(
ptu
,
"since"
)
?
TAXIS_RELATIVE
:
-
1
;
status
=
timetype
!=
-
1
;
}
...
...
@@ -192,14 +194,14 @@ bool is_lon_axis(const char *units, const char *stdname)
lc_units
[
15
]
=
0
;
strToLower
(
lc_units
);
if
(
(
str
IsEqual
(
lc_units
,
"degree"
)
||
str
IsEqual
(
lc_units
,
"radian"
))
&&
(
str
IsEqual
(
stdname
,
"grid_longitude"
)
||
str
IsEqual
(
stdname
,
"longitude"
))
)
if
(
(
str
StartsWith
(
lc_units
,
"degree"
)
||
str
StartsWith
(
lc_units
,
"radian"
))
&&
(
str
StartsWith
(
stdname
,
"grid_longitude"
)
||
str
StartsWith
(
stdname
,
"longitude"
))
)
{
status
=
true
;
}
else
if
(
str
IsEqual
(
lc_units
,
"degree"
)
&&
!
str
IsEqual
(
stdname
,
"grid_latitude"
)
&&
!
str
IsEqual
(
stdname
,
"latitude"
)
)
else
if
(
str
StartsWith
(
lc_units
,
"degree"
)
&&
!
str
StartsWith
(
stdname
,
"grid_latitude"
)
&&
!
str
StartsWith
(
stdname
,
"latitude"
)
)
{
int
ioff
=
6
;
if
(
lc_units
[
ioff
]
==
's'
)
ioff
++
;
...
...
@@ -221,14 +223,14 @@ bool is_lat_axis(const char *units, const char *stdname)
lc_units
[
15
]
=
0
;
strToLower
(
lc_units
);
if
(
(
str
IsEqual
(
lc_units
,
"degree"
)
||
str
IsEqual
(
lc_units
,
"radian"
))
&&
(
str
IsEqual
(
stdname
,
"grid_latitude"
)
||
str
IsEqual
(
stdname
,
"latitude"
))
)
if
(
(
str
StartsWith
(
lc_units
,
"degree"
)
||
str
StartsWith
(
lc_units
,
"radian"
))
&&
(
str
StartsWith
(
stdname
,
"grid_latitude"
)
||
str
StartsWith
(
stdname
,
"latitude"
))
)
{
status
=
true
;
}
else
if
(
str
IsEqual
(
lc_units
,
"degree"
)
&&
!
str
IsEqual
(
stdname
,
"grid_longitude"
)
&&
!
str
IsEqual
(
stdname
,
"longitude"
)
)
else
if
(
str
StartsWith
(
lc_units
,
"degree"
)
&&
!
str
StartsWith
(
stdname
,
"grid_longitude"
)
&&
!
str
StartsWith
(
stdname
,
"longitude"
)
)
{
int
ioff
=
6
;
if
(
lc_units
[
ioff
]
==
's'
)
ioff
++
;
...
...
@@ -324,21 +326,21 @@ void set_zaxistype(const char *attstring, int *zaxistype)
void
set_calendar
(
const
char
*
attstring
,
int
*
calendar
)
{
if
(
str
IsEqual
(
attstring
,
"standard"
)
)
if
(
str
StartsWith
(
attstring
,
"standard"
)
)
*
calendar
=
CALENDAR_STANDARD
;
else
if
(
str
IsEqual
(
attstring
,
"gregorian"
)
)
else
if
(
str
StartsWith
(
attstring
,
"gregorian"
)
)
*
calendar
=
CALENDAR_GREGORIAN
;
else
if
(
str
IsEqual
(
attstring
,
"none"
)
)
else
if
(
str
StartsWith
(
attstring
,
"none"
)
)
*
calendar
=
CALENDAR_NONE
;
else
if
(
str
IsEqual
(
attstring
,
"proleptic"
)
)
else
if
(
str
StartsWith
(
attstring
,
"proleptic"
)
)
*
calendar
=
CALENDAR_PROLEPTIC
;
else
if
(
str
IsEqual
(
attstring
,
"360"
)
)
else
if
(
str
StartsWith
(
attstring
,
"360"
)
)
*
calendar
=
CALENDAR_360DAYS
;
else
if
(
str
IsEqual
(
attstring
,
"365"
)
||
str
IsEqual
(
attstring
,
"noleap"
)
)
else
if
(
str
StartsWith
(
attstring
,
"365"
)
||
str
StartsWith
(
attstring
,
"noleap"
)
)
*
calendar
=
CALENDAR_365DAYS
;
else
if
(
str
IsEqual
(
attstring
,
"366"
)
||
str
IsEqual
(
attstring
,
"all_leap"
)
)
else
if
(
str
StartsWith
(
attstring
,
"366"
)
||
str
StartsWith
(
attstring
,
"all_leap"
)
)
*
calendar
=
CALENDAR_366DAYS
;
else
Warning
(
"calendar >%s< unsupported!"
,
attstring
);
...
...
src/cdi_int.h
View file @
3ce4c9ca
...
...
@@ -39,7 +39,7 @@ char *strdup(const char *s);
#endif
char
*
strToLower
(
char
*
str
);
bool
str
IsEqual
(
const
char
*
vstr
,
const
char
*
cstr
);
bool
str
StartsWith
(
const
char
*
vstr
,
const
char
*
cstr
);
#ifndef M_PI
#define M_PI 3.14159265358979323846
/* pi */
...
...
src/stream_cdf_i.c
View file @
3ce4c9ca
...
...
@@ -222,7 +222,7 @@ int setBaseTime(const char *timeunits, taxis_t *taxis)
{
while
(
isspace
(
tu
[
pos
])
)
++
pos
;
if
(
str
IsEqual
(
tu
+
pos
,
"since"
)
)
if
(
str
StartsWith
(
tu
+
pos
,
"since"
)
)
taxistype
=
TAXIS_RELATIVE
;
while
(
pos
<
len
&&
!
isspace
(
tu
[
pos
])
)
++
pos
;
...
...
@@ -234,7 +234,7 @@ int setBaseTime(const char *timeunits, taxis_t *taxis)
{
if
(
timeunit
==
TUNIT_DAY
)
{
if
(
!
str
IsEqual
(
tu
+
pos
,
"%y%m%d.%f"
)
)
if
(
!
str
StartsWith
(
tu
+
pos
,
"%y%m%d.%f"
)
)
{
Message
(
"Unsupported format %s for TIMEUNIT day!"
,
tu
+
pos
);
timeunit
=
-
1
;
...
...
@@ -242,7 +242,7 @@ int setBaseTime(const char *timeunits, taxis_t *taxis)
}
else
if
(
timeunit
==
TUNIT_MONTH
)
{
if
(
!
str
IsEqual
(
tu
+
pos
,
"%y%m.%f"
)
)
if
(
!
str
StartsWith
(
tu
+
pos
,
"%y%m.%f"
)
)
{
Message
(
"Unsupported format %s for TIMEUNIT month!"
,
tu
+
pos
);
timeunit
=
-
1
;
...
...
@@ -584,7 +584,7 @@ int cdf_time_dimid(int fileID, int ndims, int nvars, ncdim_t *ncdims)
{
dimname
[
0
]
=
0
;
cdf_inq_dimname
(
fileID
,
ncdims
[
dimid
].
dimid
,
dimname
);
if
(
str
IsEqual
(
dimname
,
"time"
)
||
str
IsEqual
(
dimname
,
"Time"
)
)
return
dimid
;
if
(
str
StartsWith
(
dimname
,
"time"
)
||
str
StartsWith
(
dimname
,
"Time"
)
)
return
dimid
;
}
for
(
int
varid
=
0
;
varid
<
nvars
;
++
varid
)
...
...
@@ -1070,7 +1070,7 @@ int cdf_get_cell_varid(char *attstring, int ncid)
printf("cell_measures >%s<\n", cell_measures);
printf("cell_var >%s<\n", cell_var);
*/
if
(
str
IsEqual
(
cell_measures
,
"area"
)
)
if
(
str
StartsWith
(
cell_measures
,
"area"
)
)
{
int
nc_var_id
;
int
status
=
nc_inq_varid
(
ncid
,
cell_var
,
&
nc_var_id
);
...
...
@@ -1206,31 +1206,31 @@ void cdfScanVarAttr(int nvars, ncvar_t *ncvars, int ndims, ncdim_t *ncdims, int
if
(
attstringsize
>
CDI_MAX_NAME
)
attstringsize
=
CDI_MAX_NAME
;
}
if
(
isText
&&
str
IsEqual
(
attname
,
"long_name"
)
)
if
(
isText
&&
str
StartsWith
(
attname
,
"long_name"
)
)
{
memcpy
(
ncvars
[
ncvarid
].
longname
,
attstring
,
attstringsize
);
}
else
if
(
isText
&&
str
IsEqual
(
attname
,
"units"
)
)
else
if
(
isText
&&
str
StartsWith
(
attname
,
"units"
)
)
{
memcpy
(
ncvars
[
ncvarid
].
units
,
attstring
,
attstringsize
);
}
else
if
(
str
IsEqual
(
attname
,
"calendar"
)
)
else
if
(
str
StartsWith
(
attname
,
"calendar"
)
)
{
ncvars
[
ncvarid
].
calendar
=
true
;
}
else
if
(
isText
&&
str
IsEqual
(
attname
,
"param"
)
)
else
if
(
isText
&&
str
StartsWith
(
attname
,
"param"
)
)
{
int
pnum
=
0
,
pcat
=
255
,
pdis
=
255
;
sscanf
(
attstring
,
"%d.%d.%d"
,
&
pnum
,
&
pcat
,
&
pdis
);
ncvars
[
ncvarid
].
param
=
cdiEncodeParam
(
pnum
,
pcat
,
pdis
);
cdf_set_var
(
ncvars
,
ncvarid
,
TRUE
);
}
else
if
(
isNumber
&&
str
IsEqual
(
attname
,
"code"
)
)
else
if
(
isNumber
&&
str
StartsWith
(
attname
,
"code"
)
)
{
cdfGetAttInt
(
ncid
,
ncvarid
,
attname
,
1
,
&
ncvars
[
ncvarid
].
code
);
cdf_set_var
(
ncvars
,
ncvarid
,
TRUE
);
}
else
if
(
isNumber
&&
str
IsEqual
(
attname
,
"table"
)
)
else
if
(
isNumber
&&
str
StartsWith
(
attname
,
"table"
)
)
{
int
tablenum
;
cdfGetAttInt
(
ncid
,
ncvarid
,
attname
,
1
,
&
tablenum
);
...
...
@@ -1243,36 +1243,36 @@ void cdfScanVarAttr(int nvars, ncvar_t *ncvars, int ndims, ncdim_t *ncdims, int
}
cdf_set_var
(
ncvars
,
ncvarid
,
TRUE
);
}
else
if
(
isText
&&
str
IsEqual
(
attname
,
"trunc_type"
)
)
else
if
(
isText
&&
str
StartsWith
(
attname
,
"trunc_type"
)
)
{
if
(
str
IsEqual
(
attstring
,
"Triangular"
)
)
if
(
str
StartsWith
(
attstring
,
"Triangular"
)
)
ncvars
[
ncvarid
].
gridtype
=
GRID_SPECTRAL
;
}
else
if
(
isText
&&
(
str
IsEqual
(
attname
,
"grid_type"
)
||
str
IsEqual
(
attname
,
"CDI_grid_type"
))
)
else
if
(
isText
&&
(
str
StartsWith
(
attname
,
"grid_type"
)
||
str
StartsWith
(
attname
,
"CDI_grid_type"
))
)
{
strToLower
(
attstring
);
set_gridtype
(
attstring
,
&
ncvars
[
ncvarid
].
gridtype
);
cdf_set_var
(
ncvars
,
ncvarid
,
TRUE
);
}
else
if
(
isText
&&
str
IsEqual
(
attname
,
"level_type"
)
)
else
if
(
isText
&&
str
StartsWith
(
attname
,
"level_type"
)
)
{
strToLower
(
attstring
);
set_zaxistype
(
attstring
,
&
ncvars
[
ncvarid
].
zaxistype
);
cdf_set_var
(
ncvars
,
ncvarid
,
TRUE
);
}
else
if
(
isNumber
&&
str
IsEqual
(
attname
,
"trunc_count"
)
)
else
if
(
isNumber
&&
str
StartsWith
(
attname
,
"trunc_count"
)
)
{
cdfGetAttInt
(
ncid
,
ncvarid
,
attname
,
1
,
&
ncvars
[
ncvarid
].
truncation
);
}
else
if
(
isNumber
&&
str
IsEqual
(
attname
,
"truncation"
)
)
else
if
(
isNumber
&&
str
StartsWith
(
attname
,
"truncation"
)
)
{
cdfGetAttInt
(
ncid
,
ncvarid
,
attname
,
1
,
&
ncvars
[
ncvarid
].
truncation
);
}
else
if
(
isNumber
&&
str
IsEqual
(
attname
,
"number_of_grid_in_reference"
)
)
else
if
(
isNumber
&&
str
StartsWith
(
attname
,
"number_of_grid_in_reference"
)
)
{
cdfGetAttInt
(
ncid
,
ncvarid
,
attname
,
1
,
&
ncvars
[
ncvarid
].
position
);
}
else
if
(
isNumber
&&
str
IsEqual
(
attname
,
"add_offset"
)
)
else
if
(
isNumber
&&
str
StartsWith
(
attname
,
"add_offset"
)
)
{
cdfGetAttDouble
(
ncid
,
ncvarid
,
attname
,
1
,
&
ncvars
[
ncvarid
].
addoffset
);
/*
...
...
@@ -1282,7 +1282,7 @@ void cdfScanVarAttr(int nvars, ncvar_t *ncvars, int ndims, ncdim_t *ncdims, int
*/
/* (also used for lon/lat) cdf_set_var(ncvars, ncvarid, TRUE); */
}
else
if
(
isNumber
&&
str
IsEqual
(
attname
,
"scale_factor"
)
)
else
if
(
isNumber
&&
str
StartsWith
(
attname
,
"scale_factor"
)
)
{
cdfGetAttDouble
(
ncid
,
ncvarid
,
attname
,
1
,
&
ncvars
[
ncvarid
].
scalefactor
);
/*
...
...
@@ -1292,7 +1292,7 @@ void cdfScanVarAttr(int nvars, ncvar_t *ncvars, int ndims, ncdim_t *ncdims, int
*/
/* (also used for lon/lat) cdf_set_var(ncvars, ncvarid, TRUE); */
}
else
if
(
isText
&&
str
IsEqual
(
attname
,
"climatology"
)
)
else
if
(
isText
&&
str
StartsWith
(
attname
,
"climatology"
)
)
{
int
ncboundsid
;
int
status
=
nc_inq_varid
(
ncid
,
attstring
,
&
ncboundsid
);
...
...
@@ -1306,7 +1306,7 @@ void cdfScanVarAttr(int nvars, ncvar_t *ncvars, int ndims, ncdim_t *ncdims, int
else
Warning
(
"%s - %s"
,
nc_strerror
(
status
),
attstring
);
}
else
if
(
isText
&&
str
IsEqual
(
attname
,
"bounds"
)
)
else
if
(
isText
&&
str
StartsWith
(
attname
,
"bounds"
)
)
{
int
ncboundsid
;
int
status
=
nc_inq_varid
(
ncid
,
attstring
,
&
ncboundsid
);
...
...
@@ -1319,18 +1319,19 @@ void cdfScanVarAttr(int nvars, ncvar_t *ncvars, int ndims, ncdim_t *ncdims, int
else
Warning
(
"%s - %s"
,
nc_strerror
(
status
),
attstring
);
}
else
if
(
isText
&&
str
IsEqual
(
attname
,
"formula_terms"
)
)
else
if
(
isText
&&
str
StartsWith
(
attname
,
"formula_terms"
)
)
{
ncvars
[
ncvarid
].
lformulaterms
=
true
;
}
else
if
(
isText
&&
str
IsEqual
(
attname
,
"cell_measures"
)
&&
(
nc_cell_id
=
cdf_get_cell_varid
(
attstring
,
ncid
))
!=
CDI_UNDEFID
)
else
if
(
isText
&&
str
StartsWith
(
attname
,
"cell_measures"
)
&&
(
nc_cell_id
=
cdf_get_cell_varid
(
attstring
,
ncid
))
!=
CDI_UNDEFID
)
{
ncvars
[
ncvarid
].
cellarea
=
nc_cell_id
;
ncvars
[
nc_cell_id
].
isvar
=
FALSE
;
cdf_set_var
(
ncvars
,
ncvarid
,
TRUE
);
}
else
if
(
isText
&&
(
str
IsEqual
(
attname
,
"associate"
)
||
str
IsEqual
(
attname
,
"coordinates"
))
)
else
if
(
isText
&&
(
str
StartsWith
(
attname
,
"associate"
)
||
str
StartsWith
(
attname
,
"coordinates"
))
)
{
printf
(
"attname: %s
\n
"
,
attname
);
bool
lstop
=
false
;
char
*
pstring
=
attstring
;
...
...
@@ -1361,7 +1362,7 @@ void cdfScanVarAttr(int nvars, ncvar_t *ncvars, int ndims, ncdim_t *ncdims, int
int
k
;
for
(
k
=
0
;
k
<
nchecked_vars
;
++
k
)
if
(
str
IsEqual
(
checked_vars
[
k
],
varname
)
)
break
;
if
(
str
StartsWith
(
checked_vars
[
k
],
varname
)
)
break
;
if
(
k
==
nchecked_vars
)
{
...
...
@@ -1375,7 +1376,7 @@ void cdfScanVarAttr(int nvars, ncvar_t *ncvars, int ndims, ncdim_t *ncdims, int
cdf_set_var
(
ncvars
,
ncvarid
,
TRUE
);
}
else
if
(
isText
&&
str
IsEqual
(
attname
,
"auxiliary_variable"
)
)
else
if
(
isText
&&
str
StartsWith
(
attname
,
"auxiliary_variable"
)
)
{
bool
lstop
=
false
;
char
*
pstring
=
attstring
;
...
...
@@ -1408,7 +1409,7 @@ void cdfScanVarAttr(int nvars, ncvar_t *ncvars, int ndims, ncdim_t *ncdims, int
cdf_set_var
(
ncvars
,
ncvarid
,
TRUE
);
}
else
if
(
isText
&&
str
IsEqual
(
attname
,
"grid_mapping"
)
)
else
if
(
isText
&&
str
StartsWith
(
attname
,
"grid_mapping"
)
)
{
int
nc_gmap_id
;
int
status
=
nc_inq_varid
(
ncid
,
attstring
,
&
nc_gmap_id
);
...
...
@@ -1422,12 +1423,12 @@ void cdfScanVarAttr(int nvars, ncvar_t *ncvars, int ndims, ncdim_t *ncdims, int
cdf_set_var
(
ncvars
,
ncvarid
,
TRUE
);
}
else
if
(
isText
&&
str
IsEqual
(
attname
,
"positive"
)
)
else
if
(
isText
&&
str
StartsWith
(
attname
,
"positive"
)
)
{
strToLower
(
attstring
);
if
(
str
IsEqual
(
attstring
,
"down"
)
)
ncvars
[
ncvarid
].
positive
=
POSITIVE_DOWN
;
else
if
(
str
IsEqual
(
attstring
,
"up"
)
)
ncvars
[
ncvarid
].
positive
=
POSITIVE_UP
;
if
(
str
StartsWith
(
attstring
,
"down"
)
)
ncvars
[
ncvarid
].
positive
=
POSITIVE_DOWN
;
else
if
(
str
StartsWith
(
attstring
,
"up"
)
)
ncvars
[
ncvarid
].
positive
=
POSITIVE_UP
;
if
(
ncvars
[
ncvarid
].
ndims
==
1
)
{
...
...
@@ -1441,19 +1442,19 @@ void cdfScanVarAttr(int nvars, ncvar_t *ncvars, int ndims, ncdim_t *ncdims, int
ncvars
[
ncvarid
].
islev
=
true
;
}
}
else
if
(
isNumber
&&
str
IsEqual
(
attname
,
"_FillValue"
)
)
else
if
(
isNumber
&&
str
StartsWith
(
attname
,
"_FillValue"
)
)
{
cdfGetAttDouble
(
ncid
,
ncvarid
,
attname
,
1
,
&
ncvars
[
ncvarid
].
fillval
);
ncvars
[
ncvarid
].
deffillval
=
true
;
/* cdf_set_var(ncvars, ncvarid, TRUE); */
}
else
if
(
isNumber
&&
str
IsEqual
(
attname
,
"missing_value"
)
)
else
if
(
isNumber
&&
str
StartsWith
(
attname
,
"missing_value"
)
)
{
cdfGetAttDouble
(
ncid
,
ncvarid
,
attname
,
1
,
&
ncvars
[
ncvarid
].
missval
);
ncvars
[
ncvarid
].
defmissval
=
true
;
/* cdf_set_var(ncvars, ncvarid, TRUE); */
}
else
if
(
isNumber
&&
str
IsEqual
(
attname
,
"valid_range"
)
&&
attlen
==
2
)
else
if
(
isNumber
&&
str
StartsWith
(
attname
,
"valid_range"
)
&&
attlen
==
2
)
{
if
(
ncvars
[
ncvarid
].
lvalidrange
==
false
)
{
...
...
@@ -1472,7 +1473,7 @@ void cdfScanVarAttr(int nvars, ncvar_t *ncvars, int ndims, ncdim_t *ncdims, int
}
}
}
else
if
(
isNumber
&&
str
IsEqual
(
attname
,
"valid_min"
)
&&
attlen
==
1
)
else
if
(
isNumber
&&
str
StartsWith
(
attname
,
"valid_min"
)
&&
attlen
==
1
)
{
bool
lignore
=
xtypeIsFloat
(
atttype
)
!=
xtypeIsFloat
(
xtype
);
if
(
!
cdiIgnoreValidRange
&&
lignore
==
false
)
...
...
@@ -1485,7 +1486,7 @@ void cdfScanVarAttr(int nvars, ncvar_t *ncvars, int ndims, ncdim_t *ncdims, int
Warning
(
"Inconsistent data type for attribute %s:valid_min, ignored!"
,
name
);
}
}
else
if
(
isNumber
&&
str
IsEqual
(
attname
,
"valid_max"
)
&&
attlen
==
1
)
else
if
(
isNumber
&&
str
StartsWith
(
attname
,
"valid_max"
)
&&
attlen
==
1
)
{
bool
lignore
=
xtypeIsFloat
(
atttype
)
!=
xtypeIsFloat
(
xtype
);
if
(
!
cdiIgnoreValidRange
&&
lignore
==
false
)
...
...
@@ -1498,11 +1499,11 @@ void cdfScanVarAttr(int nvars, ncvar_t *ncvars, int ndims, ncdim_t *ncdims, int
Warning
(
"Inconsistent data type for attribute %s:valid_max, ignored!"
,
name
);
}
}
else
if
(
isText
&&
str
IsEqual
(
attname
,
"_Unsigned"
)
)
else
if
(
isText
&&
str
StartsWith
(
attname
,
"_Unsigned"
)
)
{
strToLower
(
attstring
);
if
(
str
IsEqual
(
attstring
,
"true"
)
)
if
(
str
StartsWith
(
attstring
,
"true"
)
)
{
ncvars
[
ncvarid
].
lunsigned
=
true
;
/*
...
...
@@ -1513,27 +1514,27 @@ void cdfScanVarAttr(int nvars, ncvar_t *ncvars, int ndims, ncdim_t *ncdims, int
}
/* cdf_set_var(ncvars, ncvarid, TRUE); */
}
else
if
(
isText
&&
str
IsEqual
(
attname
,
"cdi"
)
)
else
if
(
isText
&&
str
StartsWith
(
attname
,
"cdi"
)
)
{
strToLower
(
attstring
);
if
(
str
IsEqual
(
attstring
,
"ignore"
)
)
if
(
str
StartsWith
(
attstring
,
"ignore"
)
)
{
ncvars
[
ncvarid
].
ignore
=
true
;
cdf_set_var
(
ncvars
,
ncvarid
,
FALSE
);
}
}
else
if
(
isNumber
&&
(
str
IsEqual
(
attname
,
"realization"
)
||
str
IsEqual
(
attname
,
"ensemble_members"
)
||
str
IsEqual
(
attname
,
"forecast_init_type"
))
)
(
str
StartsWith
(
attname
,
"realization"
)
||
str
StartsWith
(
attname
,
"ensemble_members"
)
||
str
StartsWith
(
attname
,
"forecast_init_type"
))
)
{
int
temp
;
cdfGetAttInt
(
ncid
,
ncvarid
,
attname
,
1
,
&
temp
);
if
(
str
IsEqual
(
attname
,
"realization"
)
)
ncvars
[
ncvarid
].
perturbationNumber
=
temp
;
else
if
(
str
IsEqual
(
attname
,
"ensemble_members"
)
)
ncvars
[
ncvarid
].
numberOfForecastsInEnsemble
=
temp
;
else
if
(
str
IsEqual
(
attname
,
"forecast_init_type"
)
)
ncvars
[
ncvarid
].
typeOfEnsembleForecast
=
temp
;
if
(
str
StartsWith
(
attname
,
"realization"
)
)
ncvars
[
ncvarid
].
perturbationNumber
=
temp
;
else
if
(
str
StartsWith
(
attname
,
"ensemble_members"
)
)
ncvars
[
ncvarid
].
numberOfForecastsInEnsemble
=
temp
;
else
if
(
str
StartsWith
(
attname
,
"forecast_init_type"
)
)
ncvars
[
ncvarid
].
typeOfEnsembleForecast
=
temp
;
cdf_set_var
(
ncvars
,
ncvarid
,
TRUE
);
}
...
...
@@ -1583,11 +1584,11 @@ void cdfVerifyVarAttr(int nvars, ncvar_t *ncvars, int ndims, ncdim_t *ncdims)
attstringsize
=
strlen
(
attstring
)
+
1
;
if
(
attstringsize
>
CDI_MAX_NAME
)
attstringsize
=
CDI_MAX_NAME
;
if
(
str
IsEqual
(
attname
,
"axis"
))
if
(
str
StartsWith
(
attname
,
"axis"
))
{
cdfScanAttrAxis
(
ncvars
,
ncdims
,
ncvarid
,
strToLower
(
attstring
),
nvdims
,
dimidsp
);
}
else
if
(
str
IsEqual
(
attname
,
"standard_name"
))
else
if
(
str
StartsWith
(
attname
,
"standard_name"
))
{
memcpy
(
ncvars
[
ncvarid
].
stdname
,
attstring
,
attstringsize
);
}
...
...
@@ -1854,14 +1855,14 @@ void verify_coordinate_vars_1(int ncid, int ndims, ncdim_t *ncdims, ncvar_t *ncv
strcmp
(
ncvars
[
ncvarid
].
longname
,
"generalized height"
)
==
0
)
&&
strcmp
(
ncvars
[
ncvarid
].
stdname
,
"height"
)
==
0
)
ncvars
[
ncvarid
].
zaxistype
=
ZAXIS_REFERENCE
;
else
if
(
str
IsEqual
(
ncvars
[
ncvarid
].
stdname
,
"air_pressure"
)
)
else
if
(
str
StartsWith
(
ncvars
[
ncvarid
].
stdname
,
"air_pressure"
)
)
ncvars
[
ncvarid
].
zaxistype
=
ZAXIS_PRESSURE
;
}
if
(
!
ncvars
[
ncvarid
].
islon
&&
ncvars
[
ncvarid
].
longname
[
0
]
!=
0
&&
!
ncvars
[
ncvarid
].
islat
&&
ncvars
[
ncvarid
].
longname
[
1
]
!=
0
)
{
if
(
str
IsEqual
(
ncvars
[
ncvarid
].
longname
+
1
,
"ongitude"
)
)
if
(
str
StartsWith
(
ncvars
[
ncvarid
].
longname
+
1
,
"ongitude"
)
)
{
ncvars
[
ncvarid
].
islon
=
true
;
cdf_set_var
(
ncvars
,
ncvarid
,
FALSE
);
...
...
@@ -1869,7 +1870,7 @@ void verify_coordinate_vars_1(int ncid, int ndims, ncdim_t *ncdims, ncvar_t *ncv
ncdims
[
ncdimid
].
dimtype
=
X_AXIS
;
continue
;
}
else
if
(
str
IsEqual
(
ncvars
[
ncvarid
].
longname
+
1
,
"atitude"
)
)
else
if
(
str
StartsWith
(
ncvars
[
ncvarid
].
longname
+
1
,
"atitude"
)
)
{
ncvars
[
ncvarid
].
islat
=
true
;
cdf_set_var
(
ncvars
,
ncvarid
,
FALSE
);
...
...
@@ -1960,19 +1961,19 @@ void verify_coordinate_vars_2(int nvars, ncvar_t *ncvars)
{
ncvars
[
ncvarid
].
isc
=
true
;
}
else
if
(
str
IsEqual
(
ncvars
[
ncvarid
].
stdname
,
"air_pressure"
)
)
else
if
(
str
StartsWith
(
ncvars
[
ncvarid
].
stdname
,
"air_pressure"
)
)
ncvars
[
ncvarid
].
zaxistype
=
ZAXIS_PRESSURE
;
/* not needed anymore for rotated grids */
if
(
!
ncvars
[
ncvarid
].
islon
&&
ncvars
[
ncvarid
].
longname
[
0
]
!=
0
&&
!
ncvars
[
ncvarid
].
islat
&&
ncvars
[
ncvarid
].
longname
[
1
]
!=
0
)
{
if
(
str
IsEqual
(
ncvars
[
ncvarid
].
longname
+
1
,
"ongitude"
)
)
if
(
str
StartsWith
(
ncvars
[
ncvarid
].
longname
+
1
,
"ongitude"
)
)
{
ncvars
[
ncvarid
].
islon
=
true
;
continue
;
}
else
if
(
str
IsEqual
(
ncvars
[
ncvarid
].
longname
+
1
,
"atitude"
)
)
else
if
(
str
StartsWith
(
ncvars
[
ncvarid
].
longname
+
1
,
"atitude"
)
)
{
ncvars
[
ncvarid
].
islat
=
true
;
continue
;
...
...
@@ -3245,7 +3246,7 @@ void cdf_define_all_vars(stream_t *streamptr, int vlistID, int instID, int model
size_t
len
=
strlen
(
name
);
if
(
len
>
3
&&
isdigit
((
int
)
name
[
3
])
)
{
if
(
str
IsEqual
(
name
,
"var"
)
)
if
(
str
StartsWith
(
name
,
"var"
)
)
{
vlistDefVarCode
(
vlistID
,
varID
,
atoi
(
name
+
3
));
// vlistDestroyVarName(vlistID, varID);
...
...
@@ -3253,7 +3254,7 @@ void cdf_define_all_vars(stream_t *streamptr, int vlistID, int instID, int model
}
else
if
(
len
>
4
&&
isdigit
((
int
)
name
[
4
])
)
{
if
(
str
IsEqual
(
name
,
"code"
)
)
if
(
str
StartsWith
(
name
,
"code"
)
)
{
vlistDefVarCode
(
vlistID
,
varID
,
atoi
(
name
+
4
));
// vlistDestroyVarName(vlistID, varID);
...
...
@@ -3261,7 +3262,7 @@ void cdf_define_all_vars(stream_t *streamptr, int vlistID, int instID, int model
}
else
if
(
len
>
5
&&
isdigit
((
int
)
name
[
5
])
)
{
if
(
str
IsEqual
(
name
,
"param"
)
)
if
(
str
StartsWith
(
name
,
"param"
)
)
{
int
pnum
=
-
1
,
pcat
=
255
,
pdis
=
255
;
sscanf
(
name
+
5
,
"%d.%d.%d"
,
&
pnum
,
&
pcat
,
&
pdis
);
...
...
src/stream_gribapi.c
View file @
3ce4c9ca
...
...
@@ -3289,7 +3289,7 @@ size_t gribapiEncode(int varID, int levelID, int vlistID, int gridID, int zaxisI
gribapiGetString
(
gh
,
"shortName"
,
grb_name
,
sizeof
(
grb_name
));
strToLower
(
cdi_name
);
strToLower
(
grb_name
);
if
(
(
strlen
(
cdi_name
)
!=
strlen
(
grb_name
))
||
!
str
IsEqual
(
cdi_name
,
grb_name
)
)
if
(
(
strlen
(
cdi_name
)
!=
strlen
(
grb_name
))
||
!
str
StartsWith
(
cdi_name
,
grb_name
)
)
Message
(
"*** GRIB2 shortName does not correspond to chosen variable name:
\"
%s
\"
(
\"
%s
\"
)."
,
grb_name
[
0
]
?
grb_name
:
"unknown"
,
cdi_name
);
}
...
...
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