Skip to content

Commit

Permalink
check of attribute forcing
Browse files Browse the repository at this point in the history
  • Loading branch information
h-dh committed Dec 8, 2015
1 parent 8b116a9 commit 0f341ef
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 10 deletions.
12 changes: 8 additions & 4 deletions include/hdhC.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ namespace hdhC
const double EQUALITY_TOLERANCE=1.e-12 ;

static std::string blank(" ");
static std::string no_blank("no_blank");
static std::string colon(":");
static std::string empty("");
static std::string NA("N/A");
static std::string no_blank("no_blank");
static std::string no_colon("no_colon");
static std::string upper("upper");
static std::string lower("lower");
static std::string empty("");
static std::string s_void("void_bool");
static std::string upper("upper");

//! Epsilon tolerance in comparisons.
/*! Facilitates equality comparisons of floating numbers,
Expand Down Expand Up @@ -491,7 +492,7 @@ clearSpaces(std::string &str);

//! concatenate a string-vector to a comma-separated (with blanks) string
std::string
catVector2Str(std::vector<std::string>&);
catStringVector(std::vector<std::string>&);

//! strip off surrounding characters.
/*! Surrounding strings 'strip are removed; default: ' ' and '\t'.
Expand All @@ -509,6 +510,9 @@ stripSides(std::string, std::string strip=empty, std::string key=empty );
std::string
unique(std::string &str, char);

std::vector<std::string>
unique(std::vector<std::string> &vs, std::string=":space:");

std::string
unique(std::string &str, std::string=":space:");

Expand Down
1 change: 1 addition & 0 deletions include/qa.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ class QA : public IObj

std::string n_axis;
std::string n_cell_methods;
std::string n_frequency;
std::string n_long_name;
std::string n_outputVarName;
std::string n_positive;
Expand Down
7 changes: 7 additions & 0 deletions include/qa_CMIP5.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ struct CMOR
struct DimensionMetaData& f_DMD,
struct DimensionMetaData& t_DMD) ;

void checkEnsembleMemItem(std::string& rqName, std::string& attVal);
void checkForcing(std::vector<std::string>&, std::string&);

void checkRequestedAttributes(void);
void checkReqAtt_global(void);
void checkReqAtt_variable(Variable&);
Expand Down Expand Up @@ -210,6 +213,8 @@ struct CMOR
static std::string n_CMOR_tables;
static std::string n_CMOR_variable_name;
static std::string n_coordinates;
static std::string n_forcing;
static std::string n_global;
static std::string n_index_axis;
static std::string n_long_name;
static std::string n_name_alt;
Expand Down Expand Up @@ -251,6 +256,8 @@ std::string CMOR::n_CMOR_name ="CMOR_name";
std::string CMOR::n_CMOR_tables ="CMOR_tables";
std::string CMOR::n_CMOR_variable_name ="CMOR_variable_name";
std::string CMOR::n_coordinates ="coordinates";
std::string CMOR::n_forcing ="forcing";
std::string CMOR::n_global ="global";
std::string CMOR::n_index_axis ="index_axis";
std::string CMOR::n_long_name ="long_name";
std::string CMOR::n_name_alt ="name_alt";
Expand Down
2 changes: 1 addition & 1 deletion scripts/qa-dkrz
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,7 @@ getNextSubPath()
progressTotalFileNum=0
local fs lline num
while read -a lline ; do
if [ ${#lline[*]} -gt 2 ] ; then
if [ ${#lline[*]} -gt 1 ] ; then
test ${lline[0]} = '---EOF---' && break
num=$( ls ${PROJECT_DATAV[${lline[0]}]}/${lline[1]}/*.nc \
| grep -c . 2> /dev/null)
Expand Down
140 changes: 137 additions & 3 deletions src/QA_CMIP5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ DRS_CV::checkFilenameGeographic(Split& x_filename)

// valid stand-alone '-' separated words
std::vector<std::string> kw;
kw.push_back("global");
kw.push_back(CMOR::n_global);
kw.push_back("lnd");
kw.push_back("ocn");
kw.push_back("zonalavg");
Expand Down Expand Up @@ -2205,6 +2205,126 @@ CMOR::checkDimSheet_validMax(InFile& in,
return;
}

void
CMOR::checkEnsembleMemItem(std::string& rqName, std::string& attVal)
{
std::string capt;
std::string key;

if( ! hdhC::isDigit(attVal) )
{
key = "2_5a";
capt = n_global + hdhC::blank ;
capt += hdhC::tf_att(rqName);
capt += "must be integer, found ";
capt += attVal;
}
else
{
int id=atoi(attVal.c_str());

if( id == 0 && pExp->getFrequency() != "fx" )
{
key = "2_5b";
capt = n_global + hdhC::blank ;
capt += hdhC::tf_att(rqName);
capt += "must be an integer > 0 for";
capt += hdhC::tf_assign(pQA->n_frequency, pExp->getFrequency());
}

else if( id > 0 && pExp->getFrequency() == "fx" )
{
key = "2_5c";
capt = n_global + hdhC::blank ;
capt += hdhC::tf_att(rqName);
capt += "must be equal 0 for frequency=<fx> ";
}
}

if( capt.size() )
{
if( notes->inq( key, n_global) )
{
(void) notes->operate(capt) ;
notes->setCheckMetaStr(pQA->fail);
pQA->setExit( notes->getExitValue() ) ;
}
}

return;
}

void
CMOR::checkForcing(std::vector<std::string>& vs_rqValue, std::string& aV)
{
if( aV == hdhC::NA )
return;

Split x_aV(aV, ",");

std::vector<std::string> vs_items(x_aV.getItems());
vs_items = hdhC::unique(vs_items);

std::string item;
size_t p0, p1;

// not a comma-sep list, but separated by blanks?
if( vs_items.size() == 1 && aV.find(" ") < std::string::npos )
{
std::string key("2_6b");
if( notes->inq( key, pQA->s_global ) )
{
std::string capt(pQA->s_global);
capt += hdhC::blank;
capt += hdhC::tf_att(hdhC::empty, n_forcing, aV);
capt += "should be a comma separated list, found blanks";

(void) notes->operate(capt) ;
notes->setCheckMetaStr( pQA->fail );
}

x_aV.setSeparator(' ');
x_aV = aV;
vs_items = x_aV.getItems() ;
vs_items = hdhC::unique(vs_items);
}

for( size_t i=0 ; i < vs_items.size() ; ++i )
{
if( (p0=vs_items[i].find("(")) < std::string::npos )
{
if( p0 )
item = vs_items[i].substr(0,p0);

if( (p1=vs_items[i].find(")")) < std::string::npos )
item += vs_items[i].substr(++p1);
}
else
item=vs_items[i];

// check
if( ! hdhC::isAmong(item, vs_rqValue) )
{
std::string key("2_6a");
if( notes->inq( key, pQA->s_global ) )
{
std::string capt(pQA->s_global);
capt += hdhC::blank;
capt += hdhC::tf_att(hdhC::empty, n_forcing, item);
capt += "not among DRS-CV requested values";
capt += hdhC::tf_val( hdhC::catStringVector(vs_rqValue)) ;

(void) notes->operate(capt) ;
notes->setCheckMetaStr( pQA->fail );

break;
}
}
}

return;
}

void
CMOR::checkRequestedAttributes(void)
{
Expand Down Expand Up @@ -2357,6 +2477,12 @@ CMOR::checkReqAtt_global(void)
capt=" missing requested value=";
capt += rqValue;

if( rqName == n_forcing )
{
capt += ", expected at least";
capt += hdhC::tf_assign(n_forcing, "N/A") ;
}

(void) notes->operate(capt) ;
notes->setCheckMetaStr( pQA->fail );

Expand All @@ -2368,8 +2494,16 @@ CMOR::checkReqAtt_global(void)
// note that several alternatives may be acceptable
Split x_rqValue(rqValue, "|");
std::vector<std::string> vs_rqValue(x_rqValue.getItems());
vs_rqValue = hdhC::unique(vs_rqValue);

if( rqName == n_forcing )
checkForcing(vs_rqValue, aV);
else if( rqName == "initialization_method"
|| rqName == "physics_version_method"
|| rqName == "realization" )
checkEnsembleMemItem(rqName, aV) ;

if( x_rqValue[0] == "YYYY-MM-DDTHH:MM:SSZ" )
else if( x_rqValue[0] == "YYYY-MM-DDTHH:MM:SSZ" )
{
// a valid date format may have T substituted by a blank
// and Z omitted or the latter be lower case.
Expand Down Expand Up @@ -3976,7 +4110,7 @@ QA_Exp::getMIP_tableName(std::string tName)
{
std::string key("7_7");

if( notes->inq( key, "global") )
if( notes->inq( key, CMOR::n_global) )
{
std::string capt("invalid MIP table name in global attribute, found ") ;
capt += hdhC::tf_att(hdhC::empty, "table_id", x_tableID.getStr()) ;
Expand Down
12 changes: 11 additions & 1 deletion src/hdhC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2212,7 +2212,7 @@ std::string clearSpaces(std::string &str )

//! concatenate a string-vector to a comma-separated (with blanks) string
std::string
catVector2Str(std::vector<std::string>& vs)
catStringVector(std::vector<std::string>& vs)
{
std::string s;
for( size_t i=0 ; i < vs.size() ; ++i)
Expand Down Expand Up @@ -2356,6 +2356,16 @@ std::string unique(std::string &str, char c)
return s ;
}

std::vector<std::string>
unique(std::vector<std::string> &vs, std::string pat)
{
std::vector<std::string> vs_t;
for(size_t i=0 ; i < vs.size() ; ++i)
vs_t.push_back( unique(vs[i], pat ) );

return vs_t;
}

std::string unique(std::string &str, std::string pat)
{
if( !str.size() )
Expand Down
7 changes: 6 additions & 1 deletion tables/projects/CMIP5/CMIP5_check-list.conf
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ Geographical indicator g-XXXX[-yyy][-zzz]: given zzz but missing XXXX & 1_7g
Attribute <name>: missing requested value=<value> & 2_1
Attribute <name>: unmatched requested value=<value> & 2_2
Requested attribute <name> is missing & 2_3
#Attribute creation_date does not comply with YYYY-MM-DDTHH:MM:SSZ & 2_4
Attribute creation_date does not comply with YYYY-MM-DDTHH:MM:SSZ & 2_4
Attribute <name> must be integer & 2_5a
Attribute <name> must be integer > 0 for non-fixed variables & 2_5b
Attribute <name> must be equal zero for fixed variables & 2_5c
Attribute <forcing> does not match the DRS CV list & 2_6a
Attribute <forcing> shozuld be a comma separated list, fond blanks & 2_6b

# Variables (3)
Variable <name> not found in the standard table & 3_1
Expand Down

0 comments on commit 0f341ef

Please sign in to comment.