Skip to content

Commit

Permalink
#2867 Added get_nc_att_values
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard Soh committed Apr 30, 2024
1 parent 8c007f4 commit 6327237
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
28 changes: 21 additions & 7 deletions src/libcode/vx_nc_util/nc_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,17 @@ 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 @@ -1729,18 +1740,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 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)) {
int cell_count = get_data_size(var);
ncbyte *signed_data = new ncbyte[cell_count];
return_status = get_nc_data_t(var, signed_data);
for (int idx=0; idx<cell_count; idx++) {
data[idx] = (uchar)signed_data[idx];
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";
}
int data_count = get_data_size(var);
ncbyte *signed_data = new ncbyte[data_count];
return_status = get_nc_data_t(var, signed_data);
for (int idx=0; idx<data_count; idx++) data[idx] = (uchar)signed_data[idx];
delete [] signed_data;
}
else {
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 @@ -194,6 +194,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 @@ -256,11 +257,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 6327237

Please sign in to comment.