Skip to content

Commit

Permalink
Merge pull request #2226 from dtcenter/feature_template_with_hpp
Browse files Browse the repository at this point in the history
Feature template with hpp
  • Loading branch information
hsoh-u committed Aug 8, 2022
2 parents 86ab23f + f2cdf99 commit 07737e5
Show file tree
Hide file tree
Showing 25 changed files with 1,138 additions and 975 deletions.
2 changes: 1 addition & 1 deletion src/libcode/vx_data2d_nc_met/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ include ${top_srcdir}/Make-include
noinst_LIBRARIES = libvx_data2d_nc_met.a
libvx_data2d_nc_met_a_SOURCES = \
get_met_grid.cc get_met_grid.h \
met_file.cc met_file.h \
met_file.cc met_file.h met_file.hpp \
var_info_nc_met.cc var_info_nc_met.h \
data2d_nc_met.cc data2d_nc_met.h \
vx_data2d_nc_met.h
Expand Down
2 changes: 1 addition & 1 deletion src/libcode/vx_data2d_nc_met/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ MAINTAINERCLEANFILES = Makefile.in
noinst_LIBRARIES = libvx_data2d_nc_met.a
libvx_data2d_nc_met_a_SOURCES = \
get_met_grid.cc get_met_grid.h \
met_file.cc met_file.h \
met_file.cc met_file.h met_file.hpp \
var_info_nc_met.cc var_info_nc_met.h \
data2d_nc_met.cc data2d_nc_met.h \
vx_data2d_nc_met.h
Expand Down
42 changes: 4 additions & 38 deletions src/libcode/vx_data2d_nc_met/met_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,6 @@ static const int max_met_args = 30;

////////////////////////////////////////////////////////////////////////

template <typename T>

void copy_nc_data_as_double(double *to_array, const T *from_array,
const int x_slot, const int y_slot,
const int nx, const int ny,
double missing_value, double fill_value) {
double value;
int x, y, offset, start_offset;

offset = 0;
if (x_slot > y_slot) {
for (y=0; y<ny; ++y) {
start_offset = y * nx;
for (x=0; x<nx; ++x) {
value = (double)from_array[x + start_offset];
if(is_eq(value, missing_value) || is_eq(value, fill_value))
value = bad_data_double;
to_array[offset++] = value;
}
}
}
else {
for (x=0; x<nx; ++x) {
start_offset = x * ny;
for (y=0; y<ny; ++y) {
value = (double)from_array[y + start_offset];
if(is_eq(value, missing_value) || is_eq(value, fill_value))
value = bad_data_double;
to_array[offset++] = value;
}
}
}
}

////////////////////////////////////////////////////////////////////////

void check_nc_data_2d(const double *from_array, const int nx, const int ny,
const double missing_value) {
int count_zero, count_missing, count_valid;
Expand Down Expand Up @@ -411,8 +375,9 @@ short s;
float f;
double d = bad_data_double;
bool status;
double fill_value;
double missing_value = get_var_missing_value(var);
double fill_value = get_var_fill_value(var);
get_var_fill_value(var, fill_value);

status = get_nc_data(var, &d, (long *)a);

Expand Down Expand Up @@ -563,8 +528,9 @@ const int y_slot = y_slot_tmp;
// get the bad data value
//

double fill_value;
double missing_value = get_var_missing_value(v);
double fill_value = get_var_fill_value(v);
get_var_fill_value(v, fill_value);

//
// set up the DataPlane object
Expand Down
3 changes: 3 additions & 0 deletions src/libcode/vx_data2d_nc_met/met_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class MetNcFile {

////////////////////////////////////////////////////////////////////////

#include "met_file.hpp"

////////////////////////////////////////////////////////////////////////

#endif /* __MET_FILE_H__ */

Expand Down
66 changes: 66 additions & 0 deletions src/libcode/vx_data2d_nc_met/met_file.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@


// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
// ** Copyright UCAR (c) 1992 - 2022
// ** University Corporation for Atmospheric Research (UCAR)
// ** National Center for Atmospheric Research (NCAR)
// ** Research Applications Lab (RAL)
// ** P.O.Box 3000, Boulder, Colorado, 80307-3000, USA
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*




////////////////////////////////////////////////////////////////////////


#ifndef __MET_FILE_HPP__
#define __MET_FILE_HPP__


////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////

template <typename T>

void copy_nc_data_as_double(double *to_array, const T *from_array,
const int x_slot, const int y_slot,
const int nx, const int ny,
double missing_value, double fill_value) {
double value;
int x, y, offset, start_offset;

offset = 0;
if (x_slot > y_slot) {
for (y=0; y<ny; ++y) {
start_offset = y * nx;
for (x=0; x<nx; ++x) {
value = (double)from_array[x + start_offset];
if(is_eq(value, missing_value) || is_eq(value, fill_value))
value = bad_data_double;
to_array[offset++] = value;
}
}
}
else {
for (x=0; x<nx; ++x) {
start_offset = x * ny;
for (y=0; y<ny; ++y) {
value = (double)from_array[y + start_offset];
if(is_eq(value, missing_value) || is_eq(value, fill_value))
value = bad_data_double;
to_array[offset++] = value;
}
}
}
}

////////////////////////////////////////////////////////////////////////

#endif /* __MET_FILE_HPP__ */


////////////////////////////////////////////////////////////////////////


3 changes: 2 additions & 1 deletion src/libcode/vx_data2d_nc_pinterp/pinterp_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,10 @@ bool status = false;
int i;
short s;
float f;
double fill_value;
double d = bad_data_double;
double missing_value = get_var_missing_value(var);
double fill_value = get_var_fill_value(var);
get_var_fill_value(var, fill_value);

status = get_nc_data(var, &d, (long *)a);

Expand Down
6 changes: 4 additions & 2 deletions src/libcode/vx_data2d_nccf/nccf_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -893,8 +893,9 @@ double NcCfFile::getData(NcVar * var, const LongArray & a) const
bool status = false;
double d = bad_data_double;

double fill_value;
double missing_value = get_var_missing_value(var);
double fill_value = get_var_fill_value(var);
get_var_fill_value(var, fill_value);

status = get_nc_data(var, &d, (long *)a);

Expand Down Expand Up @@ -1017,8 +1018,9 @@ bool NcCfFile::getData(NcVar * v, const LongArray & a, DataPlane & plane) const
// get the bad data values
//

double fill_value;
double missing_value = get_var_missing_value(v);
double fill_value = get_var_fill_value(v);
get_var_fill_value(v, fill_value);

// set up the DataPlane object

Expand Down
1 change: 1 addition & 0 deletions src/libcode/vx_data2d_python/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ include ${top_srcdir}/Make-include
noinst_LIBRARIES = libvx_data2d_python.a
libvx_data2d_python_a_SOURCES = \
dataplane_from_numpy_array.h dataplane_from_numpy_array.cc \
dataplane_from_numpy_array.hpp \
dataplane_from_xarray.h dataplane_from_xarray.cc \
grid_from_python_dict.h grid_from_python_dict.cc \
python_dataplane.h python_dataplane.cc \
Expand Down
1 change: 1 addition & 0 deletions src/libcode/vx_data2d_python/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ MAINTAINERCLEANFILES = Makefile.in
noinst_LIBRARIES = libvx_data2d_python.a
libvx_data2d_python_a_SOURCES = \
dataplane_from_numpy_array.h dataplane_from_numpy_array.cc \
dataplane_from_numpy_array.hpp \
dataplane_from_xarray.h dataplane_from_xarray.cc \
grid_from_python_dict.h grid_from_python_dict.cc \
python_dataplane.h python_dataplane.cc \
Expand Down
43 changes: 0 additions & 43 deletions src/libcode/vx_data2d_python/dataplane_from_numpy_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,49 +43,6 @@ return;
////////////////////////////////////////////////////////////////////////


template <typename T>
void load_numpy (void * buf,
const int Nx, const int Ny,
const int data_endian,
void (*shuf)(void *),
DataPlane & out)


{

bool need_swap = (shuf != 0) && (native_endian != data_endian);

int j, x, y, r, c;
const int Nxy = Nx*Ny;
T * u = (T *) buf;
T value;

for (j=0; j<Nxy; ++j) {

nympy_array_one_to_two(j, Nx, r, c);

x = c;

y = Ny - 1 - r;

memcpy(&value, u + j, sizeof(T));

if ( need_swap ) shuf(&value);

out.set((double) value, x, y);

} // for j



return;

}


////////////////////////////////////////////////////////////////////////


bool dataplane_from_numpy_array(Python3_Numpy & np, const Python3_Dict & attrs, DataPlane & dp_out, Grid & grid_out, VarInfoPython &vinfo)

{
Expand Down
3 changes: 3 additions & 0 deletions src/libcode/vx_data2d_python/dataplane_from_numpy_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ extern bool dataplane_from_numpy_array(Python3_Numpy & np, const Python3_Dict &

////////////////////////////////////////////////////////////////////////

#include "dataplane_from_numpy_array.hpp"

////////////////////////////////////////////////////////////////////////

#endif /* __MET_DATAPLANE_FROM_NUMPY_ARRAY_H__ */

Expand Down
68 changes: 68 additions & 0 deletions src/libcode/vx_data2d_python/dataplane_from_numpy_array.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
// ** Copyright UCAR (c) 1992 - 2022
// ** University Corporation for Atmospheric Research (UCAR)
// ** National Center for Atmospheric Research (NCAR)
// ** Research Applications Lab (RAL)
// ** P.O.Box 3000, Boulder, Colorado, 80307-3000, USA
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*

////////////////////////////////////////////////////////////////////////


#ifndef __MET_DATAPLANE_FROM_NUMPY_ARRAY_HPP__
#define __MET_DATAPLANE_FROM_NUMPY_ARRAY_HPP__


////////////////////////////////////////////////////////////////////////

extern inline void nympy_array_one_to_two(const int n, const int Ncols, int & row, int & col);

////////////////////////////////////////////////////////////////////////


template <typename T>
void load_numpy (void * buf,
const int Nx, const int Ny,
const int data_endian,
void (*shuf)(void *),
DataPlane & out)


{

bool need_swap = (shuf != 0) && (native_endian != data_endian);

int j, x, y, r, c;
const int Nxy = Nx*Ny;
T * u = (T *) buf;
T value;

for (j=0; j<Nxy; ++j) {

nympy_array_one_to_two(j, Nx, r, c);

x = c;

y = Ny - 1 - r;

memcpy(&value, u + j, sizeof(T));

if ( need_swap ) shuf(&value);

out.set((double) value, x, y);

} // for j



return;

}

////////////////////////////////////////////////////////////////////////

#endif /* __MET_DATAPLANE_FROM_NUMPY_ARRAY_HPP__ */


////////////////////////////////////////////////////////////////////////

2 changes: 1 addition & 1 deletion src/libcode/vx_nc_util/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ include ${top_srcdir}/Make-include
noinst_LIBRARIES = libvx_nc_util.a
libvx_nc_util_a_SOURCES = \
nc_var_info.cc nc_var_info.h \
nc_utils.cc nc_utils.h \
nc_utils.cc nc_utils.h nc_utils.hpp \
write_netcdf.cc write_netcdf.h \
grid_output.cc grid_output.h \
load_tc_data.cc load_tc_data.h \
Expand Down
2 changes: 1 addition & 1 deletion src/libcode/vx_nc_util/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ MAINTAINERCLEANFILES = Makefile.in
noinst_LIBRARIES = libvx_nc_util.a
libvx_nc_util_a_SOURCES = \
nc_var_info.cc nc_var_info.h \
nc_utils.cc nc_utils.h \
nc_utils.cc nc_utils.h nc_utils.hpp \
write_netcdf.cc write_netcdf.h \
grid_output.cc grid_output.h \
load_tc_data.cc load_tc_data.h \
Expand Down
Loading

0 comments on commit 07737e5

Please sign in to comment.