Skip to content

Commit

Permalink
Feature 1421 precision (#1610)
Browse files Browse the repository at this point in the history
* Use 0 instead of NULL to avoid compile warning

* #1421 Use double instead of float at getData

* Use 0 instead of NULL to avoid compile warning
  • Loading branch information
hsoh-u committed Dec 17, 2020
1 parent d832593 commit 995ea5a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
20 changes: 10 additions & 10 deletions met/src/libcode/vx_data2d_nccf/nccf_file.cc
Expand Up @@ -995,9 +995,9 @@ bool NcCfFile::getData(NcVar * v, const LongArray & a, DataPlane & plane) const
// get the data
int *i;
short *s;
double *d;
float *f;
const int plane_size = nx * ny;
float *f = new float[plane_size];
double *d = new double[plane_size];

size_t dim_size;
long offsets[dim_count];
Expand Down Expand Up @@ -1039,26 +1039,26 @@ bool NcCfFile::getData(NcVar * v, const LongArray & a, DataPlane & plane) const
case NcType::nc_SHORT:
s = new short[plane_size];
get_nc_data(v, s, lengths, offsets);
for (int x=0; x<plane_size; ++x) f[x] = (float)s[x];
for (int x=0; x<plane_size; ++x) d[x] = (double)s[x];
delete [] s;
break;

case NcType::nc_INT:
i = new int[plane_size];
get_nc_data(v, i, lengths, offsets);
for (int x=0; x<plane_size; ++x) f[x] = (float)i[x];
for (int x=0; x<plane_size; ++x) d[x] = (double)i[x];
delete [] i;
break;

case NcType::nc_FLOAT:
f = new float[plane_size];
get_nc_data(v, f, lengths, offsets);
for (int x=0; x<plane_size; ++x) d[x] = (double)f[x];
delete [] f;
break;

case NcType::nc_DOUBLE:
d = new double[plane_size];
get_nc_data(v, d, lengths, offsets);
for (int x=0; x<plane_size; ++x) f[x] = (float)d[x];
delete [] d;
break;

default:
Expand All @@ -1077,7 +1077,7 @@ bool NcCfFile::getData(NcVar * v, const LongArray & a, DataPlane & plane) const
if (swap_to_north) y_offset = ny - 1 - y;

for (int x = 0; x< nx; ++x) {
float value = f[offset++];
double value = d[offset++];

if( is_eq(value, missing_value) || is_eq(value, fill_value) ) {
value = bad_data_double;
Expand All @@ -1095,7 +1095,7 @@ bool NcCfFile::getData(NcVar * v, const LongArray & a, DataPlane & plane) const
y_offset = y;
if (swap_to_north) y_offset = ny - 1 - y;

float value = f[offset++];
double value = d[offset++];

if( is_eq(value, missing_value) || is_eq(value, fill_value) ) {
value = bad_data_double;
Expand All @@ -1108,7 +1108,7 @@ bool NcCfFile::getData(NcVar * v, const LongArray & a, DataPlane & plane) const
} // for x
}

delete [] f;
delete [] d;

// done
mlog << Debug(6) << method_name << "took "
Expand Down
4 changes: 2 additions & 2 deletions met/src/libcode/vx_nc_obs/nc_obs_util.cc
Expand Up @@ -1282,7 +1282,7 @@ int write_nc_string_array (NcVar *ncVar, StringArray &strArray, const int str_le
// Initialize data_buf
for (int indexX=0; indexX<buf_size; indexX++)
for (int indexY=0; indexY<str_len; indexY++)
data_buf[indexX][indexY] = NULL;
data_buf[indexX][indexY] = 0;

int buf_index = 0;
int processed_count = 0;
Expand All @@ -1295,7 +1295,7 @@ int write_nc_string_array (NcVar *ncVar, StringArray &strArray, const int str_le
len2 = strnlen(data_buf[buf_index], str_len);
if (len2 < len) len2 = len;
strncpy(data_buf[buf_index], string_data.c_str(), len);
if (len < str_len) data_buf[buf_index][len] = NULL;
if (len < str_len) data_buf[buf_index][len] = 0;
for (int idx=len; idx<len2; idx++)
data_buf[buf_index][idx] = bad_data_char;

Expand Down
10 changes: 5 additions & 5 deletions met/src/tools/other/ioda2nc/ioda2nc.cc
Expand Up @@ -396,8 +396,8 @@ void process_ioda_file(int i_pb) {
// Initialize
filtered_times.clear();
min_msg_ut = max_msg_ut = (unixtime) 0;
min_time_str[0] = NULL;
max_time_str[0] = NULL;
min_time_str[0] = 0;
max_time_str[0] = 0;

// Set the file name for the IODA file
file_name << ioda_files[i_pb];
Expand Down Expand Up @@ -658,7 +658,7 @@ void process_ioda_file(int i_pb) {
if(has_msg_type) {
int buf_len = sizeof(modified_hdr_typ);
strncpy(hdr_typ, hdr_msg_types+(i_read*nstring), nstring);
hdr_typ[nstring] = NULL;
hdr_typ[nstring] = 0;
// Null terminate the message type string
cleanup_hdr_buf(hdr_typ, nstring);

Expand All @@ -681,13 +681,13 @@ void process_ioda_file(int i_pb) {
else {
strncpy(modified_hdr_typ, hdr_typ, buf_len);
}
modified_hdr_typ[buf_len-1] = NULL;
modified_hdr_typ[buf_len-1] = 0;
}

if(has_station_id) {
char tmp_sid[nstring+1];
strncpy(tmp_sid, hdr_station_ids+(i_read*nstring), nstring);
tmp_sid[nstring] = NULL;
tmp_sid[nstring] = 0;
cleanup_hdr_buf(tmp_sid, nstring);
hdr_sid = tmp_sid;
}
Expand Down

0 comments on commit 995ea5a

Please sign in to comment.