Skip to content

Commit

Permalink
CMIP5: new check of global attribute source
Browse files Browse the repository at this point in the history
  • Loading branch information
h-dh committed Jan 25, 2016
1 parent abcafd3 commit 65dd8ce
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 27 deletions.
2 changes: 2 additions & 0 deletions include/qa_CMIP5.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ struct CMOR
void checkReqAtt_global(void);
void checkReqAtt_variable(Variable&);

void checkSource(void);

// the next one is applied to several checks
void checkStringValues(
struct DimensionMetaData& f_DMD,
Expand Down
199 changes: 174 additions & 25 deletions src/QA_CMIP5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2805,6 +2805,8 @@ CMOR::checkRequestedAttributes(void)
}
}

checkSource();

/*
// check attribute _FillValue and missing_value, if available
std::string fV("_FillValue");
Expand Down Expand Up @@ -2845,31 +2847,6 @@ CMOR::checkRequestedAttributes(void)
}
}
// for data variables, both _FillValue and missing_value
// should be defined in CORDEX
for( size_t i=0 ; i < pQA->pIn->dataVarIndex.size() ; ++i)
{
Variable &var = pQA->pIn->variable[pQA->pIn->dataVarIndex[i]];
bool is_fV = var.isValidAtt(fV) ;
bool is_mV = var.isValidAtt(mV) ;
if( (is_fV || is_mV) && (is_fV != is_mV) )
{
std::string key("3_12");
if( notes->inq( key, var.name) )
{
std::string capt(hdhC::tf_var(var.name, hdhC::colon)) ;
capt += "if " + hdhC::tf_att(fV);
capt += "or " + mV ;
capt += ", then both should be defined";
(void) notes->operate(capt) ;
notes->setCheckMetaStr( pQA->fail );
}
}
}
*/

return ;
Expand Down Expand Up @@ -3159,6 +3136,178 @@ CMOR::checkReqAtt_variable(Variable &var)
return;
}

void
CMOR::checkSource(void)
{
// global attribure 'source'
Variable& glob = pQA->pIn->variable[pQA->pIn->varSz] ;

std::string n_source("source");

Split x_colon(glob.getAttValue(n_source),";");

// note: existence is checked elsewhere
if( x_colon.size() == 0 )
return;

// some words
std::string n_model_id("model_id");

std::vector<std::string> vs_dscr;
vs_dscr.push_back("atmosphere:");
vs_dscr.push_back("ocean:");
vs_dscr.push_back("sea ice:");
vs_dscr.push_back("land:");

Split x_word(x_colon[0]);
x_word.setProtector("()",true);

Split x_brackets;

for( size_t i=0; i < x_colon.size() ; ++i )
{
size_t j=0;
x_word = x_colon[i] ;

if( i==0 )
{
std::string model_id(glob.getAttValue(n_model_id)) ;

if( x_word[j].size() == 0 )
{
std::string key("2_7a");
if( notes->inq(key) )
{
std::string capt(hdhC::tf_att(n_global, n_source, hdhC::colon));
capt += "The 1st item should be the model_id attribute";

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

else
{
if( model_id.size() != x_word[j].size() )
{
std::string key("2_7b");
if( notes->inq(key) )
{
std::string capt(hdhC::tf_att(n_global, n_source, hdhC::colon));
capt += "The model_id does not match, found";
capt += hdhC::tf_val(x_word[j]) ;
capt += ", expected";
capt += hdhC::tf_val(model_id) ;

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

++j;
}

if( x_word[j].size() > 1 )
{
if( ! hdhC::isDigit(x_word[1]) )
{
std::string key("2_7c");
if( notes->inq(key) )
{
std::string capt(hdhC::tf_att(n_global, n_source, hdhC::colon));
capt += "The 2nd item should be a year in digits";

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

++j;
}
}
}

// look for descriptors
size_t dscr_ix;
for( dscr_ix=0 ; dscr_ix < vs_dscr.size() ; ++dscr_ix )
if( vs_dscr[dscr_ix] == x_word[j] )
break;

if( dscr_ix < vs_dscr.size() )
{
// model_name is required before ()-term
if( x_word[j][0] == '(' )
{
std::string key("2_7d");
if( notes->inq(key) )
{
std::string capt(hdhC::tf_att(n_global, n_source, hdhC::colon));
capt += "The descriptor";
capt += hdhC::tf_val(vs_dscr[dscr_ix]) ;
capt += " should be followed by a model_name";

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

// the term in brackets
bool foundBrackets=false;

for( ; j < x_word.size() ; ++j )
{
size_t last = x_word[j].size() - 2;

if( x_word[j][0] == '(' && x_word[j][last] == ')' )
{
foundBrackets=true;
x_brackets = x_word[j].substr(1,last-1);

bool isA = (x_brackets.size() == 1 && dscr_ix != 2 )
? true : false ; // sea ice: or land:

if( !isA )
isA = x_brackets.size() != 2 ? true : false;
if( x_brackets.size() == 1 )

if(isA)
{
std::string key("2_7f");
if( notes->inq(key) )
{
std::string capt(hdhC::tf_att(n_global, n_source, hdhC::colon));
capt += "faulty term (<technical_name>, <resolution_and_levels>), found";
capt += hdhC::tf_val(x_brackets.getStr()) ;

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

break;
}
}
}

if( dscr_ix < vs_dscr.size() && !foundBrackets )
{
std::string key("2_7e");
if( notes->inq(key) )
{
std::string capt(hdhC::tf_att(n_global, n_source, hdhC::colon));
capt += "Missing bracketed term in ";
capt += x_colon[i];

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

return;
}

void
CMOR::checkStringValues( struct DimensionMetaData& f_DMD,
struct DimensionMetaData& t_DMD,
Expand Down
11 changes: 9 additions & 2 deletions tables/projects/CMIP5/CMIP5_check-list.conf
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ 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
Attribute <forcing> should be a comma separated list, fond blanks & 2_6b
Attribute <source>: Missing model_id (1st item) & 2_7a
Attribute <source>: The 1st item does not match the model_id & 2_7b
Attribute <source>: Missing year of the model (2nd item) & 2_7c
Attribute <source>: Descriptor <name> should be followed by <model_name> & 2_7d

Attribute <source>: Bracketed item is missing & 2_7e
Attribute <source>: faulty term <technical_name, resolution_and_levels> & 2_7f

# Variables (3)
Variable <name> not found in the sub-table pointed by table_id & 3_1
Expand All @@ -111,7 +118,7 @@ Variable's standard name does not match the table request & 3_3
Variable's long name does not match the table request & 3_4
Variable's axis does not match the table request & 3_5

# Note: Indication of a change in the layering or model grid.
# Note: Indication of a change in the layering/dimensions of the model grid.
<variable>:<dimension>: checksum & 3_6
<variable>:<dimension>: units & 3_7
<variable>:<dimension>: size & 3_8
Expand Down

0 comments on commit 65dd8ce

Please sign in to comment.