-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Howard Soh
committed
Aug 5, 2022
1 parent
dc2d3a6
commit a1eae43
Showing
5 changed files
with
1,099 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__ */ | ||
|
||
|
||
//////////////////////////////////////////////////////////////////////// | ||
|
||
|
68 changes: 68 additions & 0 deletions
68
src/libcode/vx_data2d_python/dataplane_from_numpy_array.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__ */ | ||
|
||
|
||
//////////////////////////////////////////////////////////////////////// | ||
|
Oops, something went wrong.