3 #define _USE_MATH_DEFINES
23 std::vector< std::string >& dimNames = readNC->
dimNames;
27 if( ( std::find( dimNames.begin(), dimNames.end(), std::string(
"lon" ) ) != dimNames.end() ) &&
28 ( std::find( dimNames.begin(), dimNames.end(), std::string(
"lat" ) ) != dimNames.end() ) )
32 if( ( std::find( dimNames.begin(), dimNames.end(), std::string(
"slon" ) ) != dimNames.end() ) &&
33 ( std::find( dimNames.begin(), dimNames.end(), std::string(
"slat" ) ) != dimNames.end() ) )
37 std::map< std::string, ReadNC::AttData >::iterator attIt = readNC->
globalAtts.find(
"source" );
38 if( attIt == readNC->
globalAtts.end() )
return false;
39 unsigned int sz = attIt->second.attLen;
41 att_data.resize( sz + 1 );
42 att_data[sz] =
'\000';
44 NCFUNC( get_att_text )( fileId, attIt->second.attVarId, attIt->second.attName.c_str(), &att_data[0] );
45 if( success )
return false;
46 if( att_data.find(
"CAM" ) == std::string::npos )
return false;
59 std::map< std::string, ReadNC::VarData >& varInfo =
_readNC->
varInfo;
67 std::vector< std::string >::iterator vit;
69 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"lon" ) ) != dimNames.end() )
70 idx = vit - dimNames.begin();
73 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'lon' dimension" );
77 gCDims[3] = dimLens[idx] - 1;
80 std::vector< double > til_vals( 2 );
82 if( std::fabs( 2 * til_vals[1] - til_vals[0] - 360 ) < 0.001 )
globallyPeriodic[0] = 1;
90 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"lat" ) ) != dimNames.end() )
91 idx = vit - dimNames.begin();
94 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'lat' dimension" );
98 gCDims[4] = dimLens[idx] - 1;
109 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"time" ) ) != dimNames.end() )
110 idx = vit - dimNames.begin();
111 else if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"t" ) ) != dimNames.end() )
112 idx = vit - dimNames.begin();
115 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'time' or 't' dimension" );
121 if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"lev" ) ) != dimNames.end() )
122 idx = vit - dimNames.begin();
123 else if( ( vit = std::find( dimNames.begin(), dimNames.end(),
"ilev" ) ) != dimNames.end() )
124 idx = vit - dimNames.begin();
127 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'lev' or 'ilev' dimension" );
133 int rank = 0, procs = 1;
144 for(
int i = 0; i < 6; i++ )
146 for(
int i = 0; i < 3; i++ )
152 for(
int i = 0; i < 3; i++ )
153 parData.
pDims[i] = pdims[i];
158 dbgOut.
tprintf( 1,
"Contiguous chunks of size %d bytes.\n",
163 for(
int i = 0; i < 6; i++ )
194 std::map< std::string, ReadNC::VarData >::iterator vmit;
197 if( ( vmit = varInfo.find(
"lon" ) ) != varInfo.end() && ( *vmit ).second.varDims.size() == 1 )
203 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'lon' variable" );
209 if( ( vmit = varInfo.find(
"lat" ) ) != varInfo.end() && ( *vmit ).second.varDims.size() == 1 )
215 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'lat' variable" );
221 if( ( vmit = varInfo.find(
"lon" ) ) != varInfo.end() && ( *vmit ).second.varDims.size() == 1 )
225 for( i = 0; i !=
ilCVals.size(); i++ )
232 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'lon' variable" );
238 if( ( vmit = varInfo.find(
"lat" ) ) != varInfo.end() && ( *vmit ).second.varDims.size() == 1 )
242 std::string gwName(
"gw" );
243 std::vector< double > gwVals(
lDims[4] -
lDims[1] - 1 );
245 "Trouble reading 'gw' variable" );
247 jlVals[0] = -( M_PI / 2 ) * 180 / M_PI;
250 for( i = 1; i != gwVals.size() + 1; i++ )
252 gwSum += gwVals[i - 1];
253 jlVals[i] = std::asin( gwSum ) * 180 / M_PI;
259 std::string gwName(
"gw" );
265 std::vector< double > gwVals(
lDims[4] );
267 "Trouble reading 'gw' variable" );
269 jlVals[0] = -( M_PI / 2 ) * 180 / M_PI;
271 for( std::size_t i = 1; i !=
jlVals.size(); i++ )
273 gwSum += gwVals[i - 1];
274 jlVals[i] = std::asin( gwSum ) * 180 / M_PI;
280 std::vector< double > gwVals(
lDims[4] - 1 );
282 "Trouble reading 'gw' variable" );
285 for(
int j = 0; j !=
lDims[1] - 1; j++ )
288 for( ; i !=
jlVals.size() - 1; i++ )
290 gwSum += gwVals[
lDims[1] - 1 + i];
291 jlVals[i] = std::asin( gwSum ) * 180 / M_PI;
298 int start =
lDims[1] - 1;
299 int end =
lDims[4] - 1;
300 std::vector< double > gwVals( end );
302 "Trouble reading 'gw' variable" );
304 for(
int j = 0; j != start - 1; j++ )
307 for( ; i !=
jlVals.size(); i++ )
309 gwSum += gwVals[start - 1 + i];
310 jlVals[i] = std::asin( gwSum ) * 180 / M_PI;
317 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'lat' variable" );
324 if( ( vmit = varInfo.find(
"time" ) ) != varInfo.end() && ( *vmit ).second.varDims.size() == 1 )
328 else if( ( vmit = varInfo.find(
"t" ) ) != varInfo.end() && ( *vmit ).second.varDims.size() == 1 )
336 tVals.push_back( (
double)t );
345 std::map< std::string, ReadNC::VarData >::iterator mit;
346 for( mit = varInfo.begin(); mit != varInfo.end(); ++mit )
363 std::vector< std::string > ijdimNames( 4 );
364 ijdimNames[0] =
"__slon";
365 ijdimNames[1] =
"__slat";
366 ijdimNames[2] =
"__lon";
367 ijdimNames[3] =
"__lat";
369 std::string tag_name;
373 for(
unsigned int i = 0; i != ijdimNames.size(); i++ )
375 std::vector< int > val( 2, 0 );
376 if( ijdimNames[i] ==
"__slon" )
381 else if( ijdimNames[i] ==
"__slat" )
386 else if( ijdimNames[i] ==
"__lon" )
391 else if( ijdimNames[i] ==
"__lat" )
396 std::stringstream ss_tag_name;
397 ss_tag_name << ijdimNames[i] <<
"_LOC_MINMAX";
398 tag_name = ss_tag_name.str();
401 "Trouble creating conventional tag " << tag_name );
403 "Trouble setting data to conventional tag " << tag_name );
404 dbgOut.
tprintf( 2,
"Conventional tag %s is created.\n", tag_name.c_str() );
409 switch( varInfo[
"lon"].varDataType )
415 MB_SET_ERR( MB_FAILURE,
"Unexpected variable data type for 'lon'" );
418 for(
unsigned int i = 0; i != ijdimNames.size(); i++ )
422 if( ijdimNames[i] ==
"__slon" )
427 else if( ijdimNames[i] ==
"__slat" )
432 else if( ijdimNames[i] ==
"__lon" )
437 else if( ijdimNames[i] ==
"__lat" )
443 std::stringstream ss_tag_name;
444 ss_tag_name << ijdimNames[i] <<
"_LOC_VALS";
445 tag_name = ss_tag_name.str();
448 "Trouble creating conventional tag " << tag_name );
450 "Trouble setting data to conventional tag " << tag_name );
451 dbgOut.
tprintf( 2,
"Conventional tag %s is created.\n", tag_name.c_str() );
455 for(
unsigned int i = 0; i != ijdimNames.size(); i++ )
457 std::vector< int > val( 2, 0 );
458 if( ijdimNames[i] ==
"__slon" )
463 else if( ijdimNames[i] ==
"__slat" )
468 else if( ijdimNames[i] ==
"__lon" )
473 else if( ijdimNames[i] ==
"__lat" )
478 std::stringstream ss_tag_name;
479 ss_tag_name << ijdimNames[i] <<
"_GLOBAL_MINMAX";
480 tag_name = ss_tag_name.str();
483 "Trouble creating conventional tag " << tag_name );
485 "Trouble setting data to conventional tag " << tag_name );
486 dbgOut.
tprintf( 2,
"Conventional tag %s is created.\n", tag_name.c_str() );