Skip to content

Commit

Permalink
#2867 Added get_nc_att_values. Added the argument allow_conversion to…
Browse files Browse the repository at this point in the history
… get_nc_data(netCDF::NcVar *, uchar *data)
  • Loading branch information
Howard Soh committed Apr 30, 2024
1 parent d9d287c commit 96fde58
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
22 changes: 19 additions & 3 deletions src/libcode/vx_nc_util/nc_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,16 @@ bool get_nc_att_value(const NcVar *var, const ConcatString &att_name,

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

bool get_nc_att_values(const NcVar *var, const ConcatString &att_name,
unsigned short *att_val, bool exit_on_error) {
static const char *method_name = "get_nc_att_value(NcVar,float) -> ";
bool status = get_nc_att_values_(var, att_name, att_val, exit_on_error,
(unsigned short)bad_data_int, method_name);
return status;
}

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

bool get_nc_att_value(const NcVarAtt *att, ConcatString &att_val) {
bool status = false;

Expand Down Expand Up @@ -1750,15 +1760,21 @@ bool get_nc_data(NcVar *var, char **data) {

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

bool get_nc_data(NcVar *var, uchar *data) {
bool get_nc_data(NcVar *var, uchar *data, bool allow_conversion) {
bool return_status = false;
int cell_count = get_data_size(var);
int data_type = GET_NC_TYPE_ID_P(var);
static const char *method_name = "get_nc_data(NcVar *, uchar *) -> ";
if (NC_UBYTE == data_type) return_status = get_nc_data_t(var, data);
else if (NC_BYTE == data_type && has_unsigned_attribute(var)) {
else if (NC_BYTE == data_type) {
if (!has_unsigned_attribute(var) && !allow_conversion) {
mlog << Debug(1) << "\n" << method_name
<< "INFO: Unexpected conversion from 'ncbyte' for variable \""
<< GET_NC_NAME_P(var) << "\".\n\n";
}
ncbyte *signed_data = new ncbyte[cell_count];
if (return_status = get_nc_data_t(var, signed_data)) {
return_status = get_nc_data_t(var, signed_data);
if (return_status) {
for (int idx=0; idx<cell_count; idx++) {
data[idx] = (uchar)signed_data[idx];
}
Expand Down
5 changes: 3 additions & 2 deletions src/libcode/vx_nc_util/nc_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ extern bool get_nc_att_value(const netCDF::NcVar *, const ConcatString &, Concat
extern bool get_nc_att_value(const netCDF::NcVar *, const ConcatString &, int &, bool exit_on_error = false);
extern bool get_nc_att_value(const netCDF::NcVar *, const ConcatString &, float &, bool exit_on_error = false);
extern bool get_nc_att_value(const netCDF::NcVar *, const ConcatString &, double &, bool exit_on_error = false);
extern bool get_nc_att_values(const netCDF::NcVar *, const ConcatString &, unsigned short *, bool exit_on_error = false);

extern bool has_att(netCDF::NcFile *, const ConcatString name, bool exit_on_error=false);
extern bool has_att(netCDF::NcVar *, const ConcatString name, bool do_log=false);
Expand Down Expand Up @@ -257,11 +258,11 @@ extern ConcatString* get_string_val(netCDF::NcVar *var, const int index, const i
extern bool get_nc_data(netCDF::NcVar *, int *data);
extern bool get_nc_data(netCDF::NcVar *, char *data);
extern bool get_nc_data(netCDF::NcVar *, char **data);
extern bool get_nc_data(netCDF::NcVar *, uchar *data);
extern bool get_nc_data(netCDF::NcVar *, uchar *data, bool allow_conversion=false);
extern bool get_nc_data(netCDF::NcVar *, float *data);
extern bool get_nc_data(netCDF::NcVar *, double *data);
extern bool get_nc_data(netCDF::NcVar *, time_t *data);
extern bool get_nc_data(netCDF::NcVar *, ncbyte *data);
//extern bool get_nc_data(netCDF::NcVar *, ncbyte *data);
extern bool get_nc_data(netCDF::NcVar *, unsigned short *data);

extern bool get_nc_data(netCDF::NcVar *, int *data, const LongArray &curs);
Expand Down

0 comments on commit 96fde58

Please sign in to comment.