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
89b180fc
Commit
89b180fc
authored
Jan 30, 2018
by
Uwe Schulzweida
Browse files
Added function grbGetGridtype().
parent
6bdb6ebd
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/stream_cgribex.c
View file @
89b180fc
...
...
@@ -1609,77 +1609,17 @@ void cgribexDefTime(int *isec1, int vdate, int vtime, int tsteptype, int numavg,
static
void
cgribexDefGrid
(
int
*
isec1
,
int
*
isec2
,
double
*
fsec2
,
int
*
isec4
,
int
gridID
)
{
bool
lrotated
=
false
;
bool
lcurvi
=
false
;
memset
(
isec2
,
0
,
16
*
sizeof
(
int
));
ISEC1_Sec2Or3Flag
=
128
;
int
gridtype
=
gridInqType
(
gridID
);
ISEC1_GridDefinition
=
255
;
if
(
gridtype
==
GRID_GENERIC
)
{
int
gridsize
=
(
int
)
gridInqSize
(
gridID
);
int
xsize
=
(
int
)
gridInqXsize
(
gridID
);
int
ysize
=
(
int
)
gridInqYsize
(
gridID
);
if
(
(
ysize
==
32
||
ysize
==
48
||
ysize
==
64
||
ysize
==
96
||
ysize
==
160
||
ysize
==
192
||
ysize
==
240
||
ysize
==
320
||
ysize
==
384
||
ysize
==
480
||
ysize
==
768
)
&&
(
xsize
==
2
*
ysize
||
xsize
==
1
)
)
{
gridtype
=
GRID_GAUSSIAN
;
}
else
if
(
gridsize
==
1
)
{
gridtype
=
GRID_LONLAT
;
}
else
if
(
gridInqXvals
(
gridID
,
NULL
)
&&
gridInqYvals
(
gridID
,
NULL
)
)
{
gridtype
=
GRID_LONLAT
;
}
}
else
if
(
gridtype
==
GRID_CURVILINEAR
)
{
int
projID
=
gridInqProj
(
gridID
);
if
(
projID
!=
CDI_UNDEFID
&&
gridInqType
(
projID
)
==
GRID_PROJECTION
)
{
gridID
=
projID
;
gridtype
=
GRID_PROJECTION
;
}
else
{
static
bool
lwarning
=
true
;
if
(
lwarning
&&
gridInqSize
(
gridID
)
>
1
)
{
lwarning
=
false
;
Warning
(
"Curvilinear grid is unsupported in GRIB1! Created wrong Grid Description Section!"
);
}
lcurvi
=
true
;
gridtype
=
GRID_LONLAT
;
}
}
if
(
gridtype
==
GRID_PROJECTION
)
{
if
(
gridInqProjType
(
gridID
)
==
CDI_PROJ_RLL
)
{
gridtype
=
GRID_LONLAT
;
lrotated
=
true
;
}
else
if
(
gridInqProjType
(
gridID
)
==
CDI_PROJ_LCC
)
{
gridtype
=
GRID_LCC
;
}
}
ISEC2_Reduced
=
false
;
ISEC2_ScanFlag
=
0
;
int
gridsize
=
(
int
)
gridInqSize
(
gridID
);
bool
gridIsRotated
=
false
;
bool
gridIsCurvilinear
=
false
;
int
gridtype
=
grbGetGridtype
(
gridID
,
gridsize
,
&
gridIsRotated
,
&
gridIsCurvilinear
);
switch
(
gridtype
)
{
case
GRID_LONLAT
:
...
...
@@ -1692,7 +1632,7 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI
if
(
gridtype
==
GRID_GAUSSIAN
||
gridtype
==
GRID_GAUSSIAN_REDUCED
)
ISEC2_GridType
=
GRIB1_GTYPE_GAUSSIAN
;
else
if
(
gridtype
==
GRID_LONLAT
&&
lr
otated
)
else
if
(
gridtype
==
GRID_LONLAT
&&
gridIsR
otated
)
ISEC2_GridType
=
GRIB1_GTYPE_LATLON_ROT
;
else
ISEC2_GridType
=
GRIB1_GTYPE_LATLON
;
...
...
@@ -1712,7 +1652,7 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI
else
{
xfirst
=
gridInqXval
(
gridID
,
0
);
xlast
=
gridInqXval
(
gridID
,
(
lcurvi
?
nlon
*
nlat
:
nlon
)
-
1
);
xlast
=
gridInqXval
(
gridID
,
(
gridIsCurvilinear
?
nlon
*
nlat
:
nlon
)
-
1
);
xinc
=
fabs
(
gridInqXinc
(
gridID
));
}
}
...
...
@@ -1721,7 +1661,7 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI
else
{
yfirst
=
gridInqYval
(
gridID
,
0
);
ylast
=
gridInqYval
(
gridID
,
(
lcurvi
?
nlon
*
nlat
:
nlat
)
-
1
);
ylast
=
gridInqYval
(
gridID
,
(
gridIsCurvilinear
?
nlon
*
nlat
:
nlat
)
-
1
);
yinc
=
fabs
(
gridInqYinc
(
gridID
));
}
...
...
@@ -1763,7 +1703,7 @@ void cgribexDefGrid(int *isec1, int *isec2, double *fsec2, int *isec4, int gridI
if
(
ISEC2_LatIncr
&&
ISEC2_LonIncr
)
gribbyte_set_bit
(
&
ISEC2_ResFlag
,
1
);
if
(
gridInqUvRelativeToGrid
(
gridID
)
)
gribbyte_set_bit
(
&
ISEC2_ResFlag
,
5
);
if
(
lr
otated
)
if
(
gridIsR
otated
)
{
double
xpole
=
0
,
ypole
=
0
,
angle
=
0
;
gridInqParamRLL
(
gridID
,
&
xpole
,
&
ypole
,
&
angle
);
...
...
src/stream_grb.c
View file @
89b180fc
...
...
@@ -386,6 +386,71 @@ void streamInqGRIBinfo(int streamID, int *intnum, float *fltnum, off_t *bignum)
grib_info_for_grads
(
recpos
,
(
long
)
gribbuffersize
,
(
unsigned
char
*
)
gribbuffer
,
intnum
,
fltnum
,
bignum
);
}
}
int
grbGetGridtype
(
int
gridID
,
size_t
gridsize
,
bool
*
gridIsRotated
,
bool
*
gridIsCurvilinear
)
{
int
gridtype
=
gridInqType
(
gridID
);
if
(
gridtype
==
GRID_GENERIC
)
{
int
xsize
=
(
int
)
gridInqXsize
(
gridID
);
int
ysize
=
(
int
)
gridInqYsize
(
gridID
);
if
(
(
ysize
==
32
||
ysize
==
48
||
ysize
==
64
||
ysize
==
96
||
ysize
==
160
||
ysize
==
192
||
ysize
==
240
||
ysize
==
320
||
ysize
==
384
||
ysize
==
480
||
ysize
==
768
)
&&
(
xsize
==
2
*
ysize
||
xsize
==
1
)
)
{
gridtype
=
GRID_GAUSSIAN
;
}
else
if
(
gridsize
==
1
)
{
gridtype
=
GRID_LONLAT
;
}
else
if
(
gridInqXvals
(
gridID
,
NULL
)
&&
gridInqYvals
(
gridID
,
NULL
)
)
{
gridtype
=
GRID_LONLAT
;
}
}
else
if
(
gridtype
==
GRID_CURVILINEAR
)
{
int
projID
=
gridInqProj
(
gridID
);
if
(
projID
!=
CDI_UNDEFID
&&
gridInqType
(
projID
)
==
GRID_PROJECTION
)
{
gridID
=
projID
;
gridtype
=
GRID_PROJECTION
;
}
else
{
static
bool
lwarning
=
true
;
if
(
lwarning
&&
gridsize
>
1
)
{
lwarning
=
false
;
Warning
(
"Curvilinear grid is unsupported in GRIB format! Created wrong Grid Description Section!"
);
}
*
gridIsCurvilinear
=
true
;
gridtype
=
GRID_LONLAT
;
}
}
if
(
gridtype
==
GRID_PROJECTION
)
{
if
(
gridInqProjType
(
gridID
)
==
CDI_PROJ_RLL
)
{
gridtype
=
GRID_LONLAT
;
*
gridIsRotated
=
true
;
}
else
if
(
gridInqProjType
(
gridID
)
==
CDI_PROJ_LCC
)
{
gridtype
=
GRID_LCC
;
}
}
return
gridtype
;
}
/*
* Local Variables:
* c-file-style: "Java"
...
...
src/stream_grb.h
View file @
89b180fc
...
...
@@ -28,6 +28,8 @@ int grib2ltypeToZaxisType(int grib_ltype);
int
zaxisTypeToGrib1ltype
(
int
zaxistype
);
int
zaxisTypeToGrib2ltype
(
int
zaxistype
);
int
grbGetGridtype
(
int
gridID
,
size_t
gridsize
,
bool
*
gridIsRotated
,
bool
*
gridIsCurvilinear
);
struct
cdiGribParamChange
{
int
code
,
ltype
,
lev
;
...
...
src/stream_gribapi.c
View file @
89b180fc
...
...
@@ -1894,67 +1894,10 @@ getGribApiCompTypeMsg(int comptype, size_t gridsize)
static
void
gribapiDefGrid
(
int
editionNumber
,
grib_handle
*
gh
,
int
gridID
,
int
comptype
,
bool
lieee
,
int
datatype
)
{
bool
lrotated
=
false
;
bool
lcurvi
=
false
;
int
gridtype
=
gridInqType
(
gridID
);
size_t
gridsize
=
gridInqSize
(
gridID
);
if
(
gridtype
==
GRID_GENERIC
)
{
int
xsize
=
(
int
)
gridInqXsize
(
gridID
);
int
ysize
=
(
int
)
gridInqYsize
(
gridID
);
if
(
(
ysize
==
32
||
ysize
==
48
||
ysize
==
64
||
ysize
==
96
||
ysize
==
160
||
ysize
==
192
||
ysize
==
240
||
ysize
==
320
||
ysize
==
384
||
ysize
==
480
||
ysize
==
768
)
&&
(
xsize
==
2
*
ysize
||
xsize
==
1
)
)
{
gridtype
=
GRID_GAUSSIAN
;
}
else
if
(
gridsize
==
1
)
{
gridtype
=
GRID_LONLAT
;
}
else
if
(
gridInqXvals
(
gridID
,
NULL
)
&&
gridInqYvals
(
gridID
,
NULL
)
)
{
gridtype
=
GRID_LONLAT
;
}
}
else
if
(
gridtype
==
GRID_CURVILINEAR
)
{
int
projID
=
gridInqProj
(
gridID
);
if
(
projID
!=
CDI_UNDEFID
&&
gridInqType
(
projID
)
==
GRID_PROJECTION
)
{
gridID
=
projID
;
gridtype
=
GRID_PROJECTION
;
}
else
{
static
bool
lwarning
=
true
;
if
(
lwarning
&&
gridsize
>
1
)
{
lwarning
=
false
;
Warning
(
"Curvilinear grid is unsupported in GRIB format! Created wrong Grid Description Section!"
);
}
lcurvi
=
true
;
gridtype
=
GRID_LONLAT
;
}
}
if
(
gridtype
==
GRID_PROJECTION
)
{
if
(
gridInqProjType
(
gridID
)
==
CDI_PROJ_RLL
)
{
gridtype
=
GRID_LONLAT
;
lrotated
=
true
;
}
else
if
(
gridInqProjType
(
gridID
)
==
CDI_PROJ_LCC
)
{
gridtype
=
GRID_LCC
;
}
}
bool
gridIsRotated
=
false
;
bool
gridIsCurvilinear
=
false
;
int
gridtype
=
grbGetGridtype
(
gridID
,
gridsize
,
&
gridIsRotated
,
&
gridIsCurvilinear
);
if
(
gridtype
==
GRID_LONLAT
||
gridtype
==
GRID_GAUSSIAN
)
{
...
...
@@ -1998,7 +1941,7 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
len
=
sizeof
(
mesg_gaussian_reduced
)
-
1
;
mesg
=
mesg_gaussian_reduced
;
}
else
if
(
lr
otated
)
else
if
(
gridIsR
otated
)
{
static
const
char
mesg_rot_lonlat
[]
=
"rotated_ll"
;
len
=
sizeof
(
mesg_rot_lonlat
)
-
1
;
...
...
@@ -2039,7 +1982,7 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
else
{
xfirst
=
gridInqXval
(
gridID
,
0
);
xlast
=
gridInqXval
(
gridID
,
(
lcurvi
?
nlon
*
nlat
:
nlon
)
-
1
);
xlast
=
gridInqXval
(
gridID
,
(
gridIsCurvilinear
?
nlon
*
nlat
:
nlon
)
-
1
);
xinc
=
fabs
(
gridInqXinc
(
gridID
));
}
}
...
...
@@ -2048,7 +1991,7 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
else
{
yfirst
=
gridInqYval
(
gridID
,
0
);
ylast
=
gridInqYval
(
gridID
,
(
lcurvi
?
nlon
*
nlat
:
nlat
)
-
1
);
ylast
=
gridInqYval
(
gridID
,
(
gridIsCurvilinear
?
nlon
*
nlat
:
nlat
)
-
1
);
yinc
=
fabs
(
gridInqYinc
(
gridID
));
}
...
...
@@ -2086,7 +2029,7 @@ void gribapiDefGrid(int editionNumber, grib_handle *gh, int gridID, int comptype
GRIB_CHECK
(
my_grib_set_double
(
gh
,
"jDirectionIncrementInDegrees"
,
yinc
),
0
);
}
if
(
lr
otated
)
if
(
gridIsR
otated
)
{
double
xpole
=
0
,
ypole
=
0
,
angle
=
0
;
gridInqParamRLL
(
gridID
,
&
xpole
,
&
ypole
,
&
angle
);
...
...
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