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
cdo
Commits
29ec1414
Commit
29ec1414
authored
Feb 17, 2017
by
Uwe Schulzweida
Browse files
Added function cdo_define_sample_grid().
parent
b404ecca
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/Makefile.am
View file @
29ec1414
...
...
@@ -66,6 +66,7 @@ libcdo_la_SOURCES = \
grid.c
\
grid.h
\
grid_area.c
\
grid_define.c
\
grid_gme.c
\
grid_lcc.c
\
grid_rot.c
\
...
...
src/Makefile.in
View file @
29ec1414
...
...
@@ -118,16 +118,16 @@ am_libcdo_la_OBJECTS = libcdo_la-array.lo libcdo_la-cdo_pthread.lo \
libcdo_la-fieldc.lo libcdo_la-fieldmem.lo \
libcdo_la-fieldmer.lo libcdo_la-fieldzon.lo \
libcdo_la-gradsdeslib.lo libcdo_la-grid.lo \
libcdo_la-grid_area.lo libcdo_la-grid_
gm
e.lo \
libcdo_la-grid_
lcc
.lo libcdo_la-grid_
rot
.lo \
libcdo_la-grid_
f
ro
m_name
.lo libcdo_la-grid_
read
.lo \
libcdo_la-grid_read
_pingo
.lo libcdo_la-grid_
print
.lo \
libcdo_la-grid
reference
.lo libcdo_la-grid
des
.lo \
libcdo_la-griddes
_h5
.lo libcdo_la-griddes_
nc
.lo \
libcdo_la-
hetaeta
.lo libcdo_la-
institution
.lo \
libcdo_la-in
terpol
.lo libcdo_la-
job.lo libcdo_la-juldate
.lo \
libcdo_la-
grid_search
.lo libcdo_la-
listarray
.lo \
libcdo_la-list.lo libcdo_la-listbuf.lo \
libcdo_la-grid_area.lo libcdo_la-grid_
defin
e.lo \
libcdo_la-grid_
gme
.lo libcdo_la-grid_
lcc
.lo \
libcdo_la-grid_ro
t
.lo libcdo_la-grid_
from_name
.lo \
libcdo_la-grid_read.lo libcdo_la-grid_
read_pingo
.lo \
libcdo_la-grid
_print
.lo libcdo_la-grid
reference
.lo \
libcdo_la-griddes.lo libcdo_la-griddes_
h5
.lo \
libcdo_la-
griddes_nc
.lo libcdo_la-
hetaeta
.lo \
libcdo_la-in
stitution
.lo libcdo_la-
interpol
.lo \
libcdo_la-
job.lo libcdo_la-juldate
.lo libcdo_la-
grid_search
.lo \
libcdo_la-listarray.lo
libcdo_la-list.lo libcdo_la-listbuf.lo \
libcdo_la-merge_sort2.lo libcdo_la-modules.lo \
libcdo_la-namelist.lo libcdo_la-namelist_parser.lo \
libcdo_la-normal.lo libcdo_la-nth_element.lo \
...
...
@@ -521,12 +521,12 @@ libcdo_la_SOURCES = array.h array.c cdo_int.h compare.h cdo_pthread.c \
expr_lex.c expr_yacc.c expr_yacc.h features.c field.c field.h \
field2.c fieldc.c fieldmem.c fieldmer.c fieldzon.c functs.h \
gradsdeslib.c gradsdeslib.h grid.c grid.h grid_area.c \
grid_gme.c grid_lcc.c grid_rot.c grid_from_name.c grid_read.c \
grid_
read_pingo
.c grid_
print
.c gridre
ference
.c grid
des
.c \
griddes.h griddes_h5.c griddes_nc.c
hetaeta.c hetaeta.h
\
institution.c interpol.c interpol.h job.c
juldate.c
\
grid_search.c grid_search.h listarray.c listarray.h
list.c
\
list.h listbuf.c listbuf.h merge_sort2.c merge_sort2.h \
grid_define.c
grid_gme.c grid_lcc.c grid_rot.c \
grid_
from_name
.c grid_
read
.c grid
_
re
ad_pingo
.c grid
_print
.c \
gridreference.c griddes.c
griddes.h griddes_h5.c griddes_nc.c \
hetaeta.c hetaeta.h
institution.c interpol.c interpol.h job.c \
juldate.c
grid_search.c grid_search.h listarray.c listarray.h \
list.c
list.h listbuf.c listbuf.h merge_sort2.c merge_sort2.h \
modules.c modules.h namelist.c namelist.h namelist_parser.c \
normal.c nth_element.c nth_element.h operator_help.h par_io.c \
par_io.h parse_literal.c percentiles_hist.c percentiles_hist.h \
...
...
@@ -1045,6 +1045,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-gradsdeslib.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-grid.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-grid_area.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-grid_define.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-grid_from_name.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-grid_gme.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcdo_la-grid_lcc.Plo@am__quote@
...
...
@@ -1388,6 +1389,13 @@ libcdo_la-grid_area.lo: grid_area.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcdo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libcdo_la-grid_area.lo `test -f 'grid_area.c' || echo '$(srcdir)/'`grid_area.c
libcdo_la-grid_define.lo: grid_define.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcdo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libcdo_la-grid_define.lo -MD -MP -MF $(DEPDIR)/libcdo_la-grid_define.Tpo -c -o libcdo_la-grid_define.lo `test -f 'grid_define.c' || echo '$(srcdir)/'`grid_define.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libcdo_la-grid_define.Tpo $(DEPDIR)/libcdo_la-grid_define.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='grid_define.c' object='libcdo_la-grid_define.lo' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcdo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libcdo_la-grid_define.lo `test -f 'grid_define.c' || echo '$(srcdir)/'`grid_define.c
libcdo_la-grid_gme.lo: grid_gme.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libcdo_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libcdo_la-grid_gme.lo -MD -MP -MF $(DEPDIR)/libcdo_la-grid_gme.Tpo -c -o libcdo_la-grid_gme.lo `test -f 'grid_gme.c' || echo '$(srcdir)/'`grid_gme.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libcdo_la-grid_gme.Tpo $(DEPDIR)/libcdo_la-grid_gme.Plo
...
...
src/SampleGrid.c
View file @
29ec1414
...
...
@@ -198,8 +198,7 @@ void *SampleGrid(void *argument)
if
(
(
gridtype
!=
GRID_CURVILINEAR
)
&&
(
gridInqXsize
(
gridSrcID
)
>
0
&&
gridInqYsize
(
gridSrcID
)
>
0
)
)
{
if
(
operatorID
==
SAMPLEGRID
)
// TODO gridIDsampled = define_sample_grid(gridSrcID, resampleFactor);
cdoAbort
(
"Call to define_sample_grid() missing"
);
gridIDsampled
=
cdo_define_sample_grid
(
gridSrcID
,
resampleFactor
);
else
if
(
operatorID
==
SUBGRID
)
{
...
...
src/grid.c
View file @
29ec1414
...
...
@@ -30,9 +30,7 @@
#endif
#include
<cdi.h>
#include
"cdo.h"
#include
"cdo_int.h"
#include
"error.h"
#include
"grid.h"
...
...
@@ -70,7 +68,7 @@ int ntr_to_nlat(int ntr)
/*
int nlat2 = (int)lround(((ntr+1)*3.+1.)/2.);
if ( nlat == nlat2 )
Err
or("Computation of latitudes failed for truncation %d", ntr);
cdoAb
or
t
("Computation of latitudes failed for truncation %d", ntr);
*/
}
...
...
@@ -87,7 +85,7 @@ int ntr_to_nlat_linear(int ntr)
/*
int nlat2 = (int)lround(((ntr+1)*2.+1.)/2.);
if ( nlat == nlat2 )
Err
or("Computation of latitudes failed for truncation %d", ntr);
cdoAb
or
t
("Computation of latitudes failed for truncation %d", ntr);
*/
}
...
...
@@ -235,7 +233,7 @@ int gridToZonal(int gridID1)
}
else
{
Err
or
(
"Gridtype %s unsupported!"
,
gridNamePtr
(
gridtype
));
cdoAb
or
t
(
"Gridtype %s unsupported!"
,
gridNamePtr
(
gridtype
));
}
return
gridID2
;
...
...
@@ -268,7 +266,7 @@ int gridToMeridional(int gridID1)
}
else
{
Err
or
(
"Gridtype %s unsupported!"
,
gridNamePtr
(
gridtype
));
cdoAb
or
t
(
"Gridtype %s unsupported!"
,
gridNamePtr
(
gridtype
));
}
return
gridID2
;
...
...
@@ -560,11 +558,11 @@ void lcc_to_geo(int gridID, int gridsize, double *xvals, double *yvals)
while ( lonParY < 0 ) lonParY += 360;
*/
if
(
IS_NOT_EQUAL
(
xincm
,
yincm
)
)
Warning
(
"X and Y increment must be equal on Lambert Conformal grid (Xinc = %g, Yinc = %g)
\n
"
,
cdo
Warning
(
"X and Y increment must be equal on Lambert Conformal grid (Xinc = %g, Yinc = %g)
\n
"
,
xincm
,
yincm
);
/*
if ( IS_NOT_EQUAL(lat1, lat2) )
Warning("Lat1 and Lat2 must be equal on Lambert Conformal grid (Lat1 = %g, Lat2 = %g)\n",
cdo
Warning("Lat1 and Lat2 must be equal on Lambert Conformal grid (Lat1 = %g, Lat2 = %g)\n",
lat1, lat2);
*/
map_set
(
PROJ_LC
,
originLat
,
originLon
,
xincm
,
lonParY
,
lat1
,
lat2
,
&
proj
);
...
...
@@ -684,7 +682,7 @@ void grid_inq_param_laea(int gridID, double *a, double *lon_0, double *lat_0, do
}
}
else
Warning
(
"%s mapping parameter missing!"
,
projection
);
cdo
Warning
(
"%s mapping parameter missing!"
,
projection
);
}
}
...
...
@@ -731,7 +729,7 @@ void grid_inq_param_lcc(int gridID, double *a, double *lon_0, double *lat_0, dou
}
}
else
Warning
(
"%s mapping parameter missing!"
,
projection
);
cdo
Warning
(
"%s mapping parameter missing!"
,
projection
);
}
}
...
...
@@ -1032,7 +1030,7 @@ int qu2reg_subarea(int gridsize, int np, double xfirst, double xlast,
void
field2regular
(
int
gridID1
,
int
gridID2
,
double
missval
,
double
*
array
,
int
nmiss
,
int
lnearest
)
{
int
gridtype
=
gridInqType
(
gridID1
);
if
(
gridtype
!=
GRID_GAUSSIAN_REDUCED
)
Err
or
(
"Not a reduced Gaussian grid!"
);
if
(
gridtype
!=
GRID_GAUSSIAN_REDUCED
)
cdoAb
or
t
(
"Not a reduced Gaussian grid!"
);
int
lmiss
=
nmiss
>
0
;
int
lperio
=
1
;
...
...
@@ -1060,7 +1058,7 @@ void field2regular(int gridID1, int gridID2, double missval, double *array, int
(
void
)
qu2reg3_double
(
array
,
rowlon
,
ny
,
nx
,
missval
,
&
iret
,
lmiss
,
lperio
,
lnearest
);
}
if
(
gridInqSize
(
gridID2
)
!=
nx
*
ny
)
Err
or
(
"Gridsize differ!"
);
if
(
gridInqSize
(
gridID2
)
!=
nx
*
ny
)
cdoAb
or
t
(
"Gridsize differ!"
);
Free
(
rowlon
);
}
...
...
@@ -1072,7 +1070,7 @@ int gridToRegular(int gridID1)
double
*
xvals
=
NULL
;
int
gridtype
=
gridInqType
(
gridID1
);
if
(
gridtype
!=
GRID_GAUSSIAN_REDUCED
)
Err
or
(
"Not a reduced Gaussian grid!"
);
if
(
gridtype
!=
GRID_GAUSSIAN_REDUCED
)
cdoAb
or
t
(
"Not a reduced Gaussian grid!"
);
int
ny
=
gridInqYsize
(
gridID1
);
int
np
=
gridInqNP
(
gridID1
);
...
...
@@ -1785,7 +1783,7 @@ int gridToUnstructured(int gridID1, int lbounds)
}
default:
{
Err
or
(
"Grid type >%s< unsupported!"
,
gridNamePtr
(
gridtype
));
cdoAb
or
t
(
"Grid type >%s< unsupported!"
,
gridNamePtr
(
gridtype
));
break
;
}
}
...
...
src/grid.h
View file @
29ec1414
...
...
@@ -129,4 +129,7 @@ int W3FB12(double xi, double xj, double alat1, double elon1, double dx,
double elonv, double alatan, double *alat, double *elon);
*/
// Define a sampled grid of another grid
int
cdo_define_sample_grid
(
int
gridID
,
int
sampleFactor
);
#endif
/* _GRID_H */
src/grid_define.c
0 → 100644
View file @
29ec1414
#include
<cdi.h>
#include
"cdo_int.h"
#include
"grid.h"
extern
int
cdoDebugExt
;
/*
@Function define_sample_grid
@Title Define a sampled grid of another grid
@Prototype int define_sample_grid(int gridSrcID, int sampleFactor)
@Parameter
@Item gridSrcID Source grid
@Item sampleFactor sampleFactor; typically 2,3,4 ...
@Description
The function @func{define_sample_grid} defines a sampled grid of another grid
@EndFunction
*/
int
cdo_define_sample_grid
(
int
gridSrcID
,
int
sampleFactor
)
{
/* Example of horizontal grids (Harmonie HARM36_L25):
#
# gridID 2
#
gridtype = lcc
gridsize = 622521
xsize = 789
ysize = 789
originLon = -7.89
originLat = 42.935
lonParY = 0
lat1 = 52.5
lat2 = 52.5
xinc = 2500
yinc = 2500
projection = northpole
=> RESULT:
#
# gridID 2
#
gridtype = lcc
gridsize = 156025
xsize = 395
ysize = 395
originLon = -7.89
originLat = 42.935
lonParY = 0
lat1 = 52.5
lat2 = 52.5
xinc = 5000
yinc = 5000
projection = northpole
*/
if
(
cdoDebugExt
)
cdoPrint
(
"cdo_define_sample_grid(gridSrcID=%d, sampleFactor=%d) ...
\n
"
,
gridSrcID
,
sampleFactor
);
int
gridtype
=
gridInqType
(
gridSrcID
);
int
gridXsize
=
gridInqXsize
(
gridSrcID
);
int
gridYsize
=
gridInqYsize
(
gridSrcID
);
if
(
(
sampleFactor
<
1
)
||
(
gridXsize
<
1
)
||
(
gridYsize
<
1
)
||
(
sampleFactor
>
(
gridXsize
/
4
)
)
||
(
sampleFactor
>
(
gridYsize
/
4
))
)
cdoAbort
(
"cdo_define_sample_grid() Unsupported sampleFactor (%d)! Note that: gridXsize = %d, gridYsize = %d"
,
sampleFactor
,
gridXsize
,
gridYsize
);
// TODO if ( cdoDebugExt>20 ) gridPrint(gridSrcID,1,0);
//const double *xvals = gridInqXvalsPtr(gridSrcID);
//const double *yvals = gridInqYvalsPtr(gridSrcID);
/*
double xfirst = gridInqXval(gridSrcID,0); // staggered grid of u-wind
double yfirst = gridInqYval(gridSrcID,0);
double xlast = gridInqXval(gridSrcID, gridXsize-1);
double ylast = gridInqYval(gridSrcID, gridYsize-1);
double xinc = gridInqXinc(gridSrcID);
double yinc = gridInqYinc(gridSrcID);
*/
int
xsize
=
(
gridXsize
+
(
sampleFactor
-
1
))
/
sampleFactor
;
// HARM36_L25: (789 + 2-1) / 2 = 395
int
ysize
=
(
gridYsize
+
(
sampleFactor
-
1
))
/
sampleFactor
;
int
gridID_sampled
=
gridCreate
(
gridtype
,
xsize
*
ysize
);
// TODO
/*
grid_sampled->scanningMode = grid_src->scanningMode;
grid_sampled->iScansNegatively = grid_src->iScansNegatively;
grid_sampled->jScansPositively = grid_src->jScansPositively;
grid_sampled->jPointsAreConsecutive = grid_src->jPointsAreConsecutive;
grid_sampled->uvRelativeToGrid = grid_src->uvRelativeToGrid;
*/
gridDefXsize
(
gridID_sampled
,
xsize
);
gridDefYsize
(
gridID_sampled
,
ysize
);
// for the case of Lambert projection ...
// TODO
/*
grid_sampled->lcc_xinc = grid_src->lcc_xinc * sampleFactor;
grid_sampled->lcc_yinc = grid_src->lcc_yinc * sampleFactor;
grid_sampled->xinc = grid_src->xinc * sampleFactor;
grid_sampled->yinc = grid_src->yinc * sampleFactor;
*/
double
*
xvals
=
(
double
*
)
Malloc
(
gridXsize
*
sizeof
(
double
));
gridInqXvals
(
gridSrcID
,
xvals
);
for
(
int
i
=
0
,
j
=
0
;
i
<
gridXsize
;
i
+=
sampleFactor
)
xvals
[
j
++
]
=
xvals
[
i
];
gridDefXvals
(
gridID_sampled
,
xvals
);
Free
(
xvals
);
double
*
yvals
=
(
double
*
)
Malloc
(
gridYsize
*
sizeof
(
double
));
gridInqYvals
(
gridSrcID
,
yvals
);
for
(
int
i
=
0
,
j
=
0
;
i
<
gridYsize
;
i
+=
sampleFactor
)
yvals
[
j
++
]
=
yvals
[
i
];
gridDefYvals
(
gridID_sampled
,
yvals
);
Free
(
yvals
);
// TODO
/*
if ( grid_sampled->type == GRID_LCC )
gridDefLCC( gridID_sampled, grid_sampled->lcc_originLon, grid_sampled->lcc_originLat, grid_sampled->lcc_lonParY,
grid_sampled->lcc_lat1, grid_sampled->lcc_lat2, grid_sampled->lcc_xinc, grid_sampled->lcc_yinc,
grid_sampled->lcc_projflag, grid_sampled->lcc_scanflag);
*/
if
(
cdoDebugExt
>
20
)
{
printf
(
"cdo SampleGrid: define_sample_grid():
\n
"
);
// TODO gridPrint(gridID_sampled, 1,0);
}
return
gridID_sampled
;
}
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