Skip to content

Commit

Permalink
#1815 Added get_att_unixtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Howard Soh committed Jun 27, 2022
1 parent 38211de commit 1f63628
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 49 deletions.
86 changes: 41 additions & 45 deletions src/libcode/vx_nc_util/nc_var_info.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
// ** Copyright UCAR (c) 1992 - 2022
// ** University Corporation for Atmospheric Research (UCAR)
Expand All @@ -9,8 +7,6 @@
// *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*




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


Expand All @@ -27,6 +23,8 @@ using namespace std;
#include "vx_log.h"
#include "vx_cal.h"

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

unixtime get_att_value_unixtime(const NcAtt *att) {
ConcatString s;
unixtime time_value = -1;
Expand All @@ -53,7 +51,6 @@ unixtime get_att_value_unixtime(const NcAtt *att) {
return time_value;
}


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


Expand All @@ -65,9 +62,7 @@ unixtime get_att_value_unixtime(const NcAtt *att) {
////////////////////////////////////////////////////////////////////////


NcVarInfo::NcVarInfo()

{
NcVarInfo::NcVarInfo() {

init_from_scratch();

Expand All @@ -77,9 +72,7 @@ init_from_scratch();
////////////////////////////////////////////////////////////////////////


NcVarInfo::~NcVarInfo()

{
NcVarInfo::~NcVarInfo() {

clear();

Expand All @@ -89,9 +82,7 @@ clear();
////////////////////////////////////////////////////////////////////////


NcVarInfo::NcVarInfo(const NcVarInfo & i)

{
NcVarInfo::NcVarInfo(const NcVarInfo & i) {

init_from_scratch();

Expand All @@ -103,9 +94,7 @@ assign(i);
////////////////////////////////////////////////////////////////////////


NcVarInfo & NcVarInfo::operator=(const NcVarInfo & i)

{
NcVarInfo & NcVarInfo::operator=(const NcVarInfo & i) {

if ( this == &i ) return ( * this );

Expand All @@ -119,9 +108,7 @@ return ( * this );
////////////////////////////////////////////////////////////////////////


void NcVarInfo::init_from_scratch()

{
void NcVarInfo::init_from_scratch() {

Dims = (NcDim **) 0;

Expand All @@ -135,9 +122,7 @@ return;
////////////////////////////////////////////////////////////////////////


void NcVarInfo::clear()

{
void NcVarInfo::clear() {

var = (NcVar *) 0; // don't delete

Expand Down Expand Up @@ -175,9 +160,7 @@ return;
////////////////////////////////////////////////////////////////////////


void NcVarInfo::dump(ostream & out, int depth) const

{
void NcVarInfo::dump(ostream & out, int depth) const {

Indent prefix(depth);

Expand Down Expand Up @@ -245,9 +228,7 @@ return;
////////////////////////////////////////////////////////////////////////


int NcVarInfo::lead_time() const

{
int NcVarInfo::lead_time() const {

return ( (int) (ValidTime - InitTime) );

Expand All @@ -257,9 +238,7 @@ return ( (int) (ValidTime - InitTime) );
////////////////////////////////////////////////////////////////////////


void NcVarInfo::assign(const NcVarInfo & i)

{
void NcVarInfo::assign(const NcVarInfo & i) {

clear();

Expand Down Expand Up @@ -315,10 +294,8 @@ return;

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


bool get_att_str(const NcVarInfo &info, const ConcatString att_name, ConcatString &att_value)

{
bool get_att_str(const NcVarInfo &info, const ConcatString att_name,
ConcatString &att_value) {

NcVarAtt *att ;
bool found = false;
Expand Down Expand Up @@ -349,13 +326,10 @@ bool get_att_str(const NcVarInfo &info, const ConcatString att_name, ConcatStrin

}


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


bool get_att_int(const NcVarInfo &info, const ConcatString att_name, int &att_value)

{
bool get_att_int(const NcVarInfo &info, const ConcatString att_name,
int &att_value) {

att_value = bad_data_int;

Expand Down Expand Up @@ -385,17 +359,32 @@ bool get_att_int(const NcVarInfo &info, const ConcatString att_name, int &att_va

}

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

bool get_att_accum_time(const NcVarInfo &info, int &att_value) {
return get_att_int(info, accum_time_sec_att_name, att_value);
}

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

bool get_att_level(const NcVarInfo &info, ConcatString &att_value) {
return get_att_str(info, level_att_name, att_value);
}

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

bool get_att_name(const NcVarInfo &info, ConcatString &att_value) {
return get_att_str(info, name_att_name, att_value);
}

bool get_att_unixtime(const NcVarInfo &info, const ConcatString att_name, unixtime &att_value)
////////////////////////////////////////////////////////////////////////

{
bool get_att_unixtime(const NcVar *var, const ConcatString att_name,
unixtime &att_value) {

att_value = (unixtime) bad_data_int;

NcVarAtt *att = get_nc_att(info.var, att_name, false);
NcVarAtt *att = get_nc_att(var, att_name, false);
bool found = IS_VALID_NC_P(att);
if( found ) att_value = get_att_value_unixtime(att);

Expand All @@ -409,7 +398,14 @@ bool get_att_unixtime(const NcVarInfo &info, const ConcatString att_name, unixti

}


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

bool get_att_unixtime(const NcVarInfo &info, const ConcatString att_name,
unixtime &att_value) {

return get_att_unixtime(info.var, att_name, att_value);

}

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

20 changes: 16 additions & 4 deletions src/libcode/vx_nc_util/nc_var_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ using namespace netCDF;

#include "vx_util.h"

extern unixtime get_att_value_unixtime(const NcAtt *);
////////////////////////////////////////////////////////////////////////

static const string accum_time_att_name = "accum_time";
static const string accum_time_sec_att_name = "accum_time_sec";
static const string init_time_att_name = "init_time";
static const string init_time_ut_att_name = "init_time_ut";
static const string level_att_name = "level";
static const string name_att_name = "name";
static const string valid_time_att_name = "valid_time";
static const string valid_time_ut_att_name = "valid_time_ut";

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

Expand Down Expand Up @@ -85,15 +94,18 @@ class NcVarInfo {
////////////////////////////////////////////////////////////////////////



extern bool get_att_str(const NcVarInfo &, const ConcatString, ConcatString &);

extern bool get_att_int(const NcVarInfo &, const ConcatString, int &);

// unixtimes could be ints or strings
extern bool get_att_accum_time(const NcVarInfo &, int &);
extern bool get_att_level(const NcVarInfo &, ConcatString &);
extern bool get_att_name(const NcVarInfo &, ConcatString &);

// unixtimes could be ints or strings
extern bool get_att_unixtime(const NcVar *, const ConcatString, unixtime &);
extern bool get_att_unixtime(const NcVarInfo &, const ConcatString, unixtime &);

extern unixtime get_att_value_unixtime(const NcAtt *);

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

Expand Down

0 comments on commit 1f63628

Please sign in to comment.