Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cdo
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mpim-sw
cdo
Commits
d0756dea
Commit
d0756dea
authored
1 year ago
by
Oliver Heidmann
Committed by
Uwe Schulzweida
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
class rework Verifygrid.cc
parent
4074e3fa
No related branches found
No related tags found
1 merge request
!96
Develop
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Verifygrid.cc
+122
-106
122 additions, 106 deletions
src/Verifygrid.cc
with
122 additions
and
106 deletions
src/Verifygrid.cc
+
122
−
106
View file @
d0756dea
...
...
@@ -247,10 +247,7 @@ is_simple_polygon_convex(const Varray<Point> &cellCorners, int numCorners)
{
if
(
IS_NOT_EQUAL
(
direction
,
0.0
))
return
false
;
}
else
{
direction
=
turnsTo
;
}
else
{
direction
=
turnsTo
;
}
}
return
true
;
...
...
@@ -368,10 +365,7 @@ get_no_unique_center_points(size_t gridsize, size_t nx, const Varray<double> &gr
fprintf
(
stdout
,
"
\n
"
);
}
}
else
{
no_unique_center_points
++
;
}
else
{
no_unique_center_points
++
;
}
}
return
no_unique_center_points
;
...
...
@@ -701,10 +695,7 @@ verify_grid(size_t gridsize, size_t nx, int ncorner, const Varray<double> &grid_
fprintf
(
stdout
,
"
\n
"
);
}
}
else
{
no_counterclockwise_cells
++
;
}
else
{
no_counterclockwise_cells
++
;
}
// The winding numbers algorithm is used to test whether the presumed center point is within the bounds of the cell.
auto
windingNumber
=
winding_numbers_algorithm
(
cellCornersPlaneProjection
,
actualNumberOfCorners
+
1
,
centerPoint2D
);
...
...
@@ -783,103 +774,128 @@ print_lonlat(int dig, int gridID, size_t gridsize, const Varray<double> &lon, co
if
(
ymm
.
min
<
-
90.00001
||
ymm
.
max
>
90.00001
)
cdo_warning
(
"Grid cell center latitudes out of range!"
);
}
void
*
Verifygrid
(
void
*
argument
)
class
ModuleVerifygrid
{
cdo_initialize
(
argument
);
cdo_operator_add
(
"verifygrid"
,
0
,
0
,
nullptr
);
operator_check_argc
(
0
);
auto
streamID
=
cdo_open_read
(
0
);
auto
vlistID
=
cdo_stream_inq_vlist
(
streamID
);
auto
ngrids
=
vlistNgrids
(
vlistID
);
for
(
int
gridno
=
0
;
gridno
<
ngrids
;
++
gridno
)
{
auto
lgeo
=
true
;
auto
gridID
=
vlistGrid
(
vlistID
,
gridno
);
auto
gridtype
=
gridInqType
(
gridID
);
auto
isHealpixGrid
=
is_healpix_grid
(
gridID
);
if
(
gridtype
==
GRID_GENERIC
||
gridtype
==
GRID_SPECTRAL
)
lgeo
=
false
;
if
(
isHealpixGrid
)
lgeo
=
false
;
if
(
gridtype
==
GRID_GME
)
gridID
=
gridToUnstructured
(
gridID
,
NeedCorners
::
Yes
);
if
(
lgeo
&&
gridtype
!=
GRID_UNSTRUCTURED
&&
gridtype
!=
GRID_CURVILINEAR
)
gridID
=
gridToCurvilinear
(
gridID
,
NeedCorners
::
Yes
);
if
(
gridtype
==
GRID_UNSTRUCTURED
&&
!
gridHasCoordinates
(
gridID
))
{
auto
reference
=
dereferenceGrid
(
gridID
);
if
(
reference
.
isValid
)
gridID
=
reference
.
gridID
;
if
(
reference
.
notFound
)
{
cdo_print
(
"Reference to source grid not found!"
);
lgeo
=
false
;
}
}
auto
gridsize
=
gridInqSize
(
gridID
);
auto
nx
=
gridInqXsize
(
gridID
);
auto
ny
=
gridInqYsize
(
gridID
);
nx
=
(
nx
*
ny
==
gridsize
)
?
nx
:
0
;
if
(
lgeo
)
{
auto
ncorner
=
(
gridInqType
(
gridID
)
==
GRID_UNSTRUCTURED
)
?
gridInqNvertex
(
gridID
)
:
4
;
if
(
!
gridHasCoordinates
(
gridID
))
cdo_abort
(
"Cell center coordinates missing!"
);
Varray
<
double
>
grid_center_lat
(
gridsize
),
grid_center_lon
(
gridsize
);
gridInqYvals
(
gridID
,
grid_center_lat
.
data
());
gridInqXvals
(
gridID
,
grid_center_lon
.
data
());
CdoStreamID
streamID
;
int
vlistID
;
int
ngrids
;
public:
void
init
(
void
*
process
)
{
cdo_initialize
(
process
);
cdo_operator_add
(
"verifygrid"
,
0
,
0
,
nullptr
);
operator_check_argc
(
0
);
streamID
=
cdo_open_read
(
0
);
vlistID
=
cdo_stream_inq_vlist
(
streamID
);
ngrids
=
vlistNgrids
(
vlistID
);
}
void
run
()
{
for
(
int
gridno
=
0
;
gridno
<
ngrids
;
++
gridno
)
{
auto
lgeo
=
true
;
auto
gridID
=
vlistGrid
(
vlistID
,
gridno
);
auto
gridtype
=
gridInqType
(
gridID
);
auto
isHealpixGrid
=
is_healpix_grid
(
gridID
);
if
(
gridtype
==
GRID_GENERIC
||
gridtype
==
GRID_SPECTRAL
)
lgeo
=
false
;
if
(
isHealpixGrid
)
lgeo
=
false
;
if
(
gridtype
==
GRID_GME
)
gridID
=
gridToUnstructured
(
gridID
,
NeedCorners
::
Yes
);
if
(
lgeo
&&
gridtype
!=
GRID_UNSTRUCTURED
&&
gridtype
!=
GRID_CURVILINEAR
)
gridID
=
gridToCurvilinear
(
gridID
,
NeedCorners
::
Yes
);
if
(
gridtype
==
GRID_UNSTRUCTURED
&&
!
gridHasCoordinates
(
gridID
))
{
auto
reference
=
dereferenceGrid
(
gridID
);
if
(
reference
.
isValid
)
gridID
=
reference
.
gridID
;
if
(
reference
.
notFound
)
{
cdo_print
(
"Reference to source grid not found!"
);
lgeo
=
false
;
}
}
auto
gridsize
=
gridInqSize
(
gridID
);
auto
nx
=
gridInqXsize
(
gridID
);
auto
ny
=
gridInqYsize
(
gridID
);
nx
=
(
nx
*
ny
==
gridsize
)
?
nx
:
0
;
if
(
lgeo
)
{
auto
ncorner
=
(
gridInqType
(
gridID
)
==
GRID_UNSTRUCTURED
)
?
gridInqNvertex
(
gridID
)
:
4
;
if
(
!
gridHasCoordinates
(
gridID
))
cdo_abort
(
"Cell center coordinates missing!"
);
Varray
<
double
>
grid_center_lat
(
gridsize
),
grid_center_lon
(
gridsize
);
gridInqYvals
(
gridID
,
grid_center_lat
.
data
());
gridInqXvals
(
gridID
,
grid_center_lon
.
data
());
// Convert lat/lon units if required
cdo_grid_to_degree
(
gridID
,
CDI_XAXIS
,
gridsize
,
grid_center_lon
.
data
(),
"grid center lon"
);
cdo_grid_to_degree
(
gridID
,
CDI_YAXIS
,
gridsize
,
grid_center_lat
.
data
(),
"grid center lat"
);
print_header
(
gridtype
,
gridsize
,
nx
,
gridno
,
ngrids
);
if
(
gridHasBounds
(
gridID
))
{
if
(
ncorner
==
0
)
cdo_abort
(
"Number of cell corners undefined!"
);
auto
nalloc
=
ncorner
*
gridsize
;
Varray
<
double
>
grid_corner_lat
(
nalloc
),
grid_corner_lon
(
nalloc
);
gridInqYbounds
(
gridID
,
grid_corner_lat
.
data
());
gridInqXbounds
(
gridID
,
grid_corner_lon
.
data
());
cdo_grid_to_degree
(
gridID
,
CDI_XAXIS
,
ncorner
*
gridsize
,
grid_corner_lon
.
data
(),
"grid corner lon"
);
cdo_grid_to_degree
(
gridID
,
CDI_YAXIS
,
ncorner
*
gridsize
,
grid_corner_lat
.
data
(),
"grid corner lat"
);
verify_grid
(
gridsize
,
nx
,
ncorner
,
grid_center_lon
,
grid_center_lat
,
grid_corner_lon
,
grid_corner_lat
);
}
else
{
cdo_warning
(
"Grid cell corner coordinates missing!"
);
}
int
dig
=
Options
::
CDO_flt_digits
;
print_lonlat
(
dig
,
gridID
,
gridsize
,
grid_center_lon
,
grid_center_lat
);
}
else
{
if
(
ngrids
==
1
)
cdo_print
(
Blue
(
"Grid consists of %zu points (type: %s)"
),
gridsize
,
isHealpixGrid
?
"healpix"
:
gridNamePtr
(
gridtype
));
else
cdo_print
(
Blue
(
"Grid no %u (of %u) consists of %zu points (type: %s)"
),
gridno
+
1
,
ngrids
,
gridsize
,
gridNamePtr
(
gridtype
));
// cdo_print("");
}
}
}
void
close
()
{
cdo_stream_close
(
streamID
);
cdo_finish
();
}
};
// Convert lat/lon units if required
cdo_grid_to_degree
(
gridID
,
CDI_XAXIS
,
gridsize
,
grid_center_lon
.
data
(),
"grid center lon"
);
cdo_grid_to_degree
(
gridID
,
CDI_YAXIS
,
gridsize
,
grid_center_lat
.
data
(),
"grid center lat"
);
print_header
(
gridtype
,
gridsize
,
nx
,
gridno
,
ngrids
);
if
(
gridHasBounds
(
gridID
))
{
if
(
ncorner
==
0
)
cdo_abort
(
"Number of cell corners undefined!"
);
auto
nalloc
=
ncorner
*
gridsize
;
Varray
<
double
>
grid_corner_lat
(
nalloc
),
grid_corner_lon
(
nalloc
);
gridInqYbounds
(
gridID
,
grid_corner_lat
.
data
());
gridInqXbounds
(
gridID
,
grid_corner_lon
.
data
());
cdo_grid_to_degree
(
gridID
,
CDI_XAXIS
,
ncorner
*
gridsize
,
grid_corner_lon
.
data
(),
"grid corner lon"
);
cdo_grid_to_degree
(
gridID
,
CDI_YAXIS
,
ncorner
*
gridsize
,
grid_corner_lat
.
data
(),
"grid corner lat"
);
verify_grid
(
gridsize
,
nx
,
ncorner
,
grid_center_lon
,
grid_center_lat
,
grid_corner_lon
,
grid_corner_lat
);
}
else
{
cdo_warning
(
"Grid cell corner coordinates missing!"
);
}
int
dig
=
Options
::
CDO_flt_digits
;
print_lonlat
(
dig
,
gridID
,
gridsize
,
grid_center_lon
,
grid_center_lat
);
}
else
{
if
(
ngrids
==
1
)
cdo_print
(
Blue
(
"Grid consists of %zu points (type: %s)"
),
gridsize
,
isHealpixGrid
?
"healpix"
:
gridNamePtr
(
gridtype
));
else
cdo_print
(
Blue
(
"Grid no %u (of %u) consists of %zu points (type: %s)"
),
gridno
+
1
,
ngrids
,
gridsize
,
gridNamePtr
(
gridtype
));
// cdo_print("");
}
}
cdo_stream_close
(
streamID
);
cdo_finish
();
void
*
Verifygrid
(
void
*
process
)
{
ModuleVerifygrid
verifygrid
;
verifygrid
.
init
(
process
);
verifygrid
.
run
();
verifygrid
.
close
();
return
nullptr
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment