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 );
246 jlVals[0] = -( M_PI / 2 ) * 180 / M_PI;
249 for( i = 1; i != gwVals.size() + 1; i++ )
251 gwSum += gwVals[i - 1];
252 jlVals[i] = std::asin( gwSum ) * 180 / M_PI;
258 std::string gwName(
"gw" );
264 std::vector< double > gwVals(
lDims[4] );
267 jlVals[0] = -( M_PI / 2 ) * 180 / M_PI;
269 for( std::size_t i = 1; i !=
jlVals.size(); i++ )
271 gwSum += gwVals[i - 1];
272 jlVals[i] = std::asin( gwSum ) * 180 / M_PI;
278 std::vector< double > gwVals(
lDims[4] - 1 );
282 for(
int j = 0; j !=
lDims[1] - 1; j++ )
285 for( ; i !=
jlVals.size() - 1; i++ )
287 gwSum += gwVals[
lDims[1] - 1 + i];
288 jlVals[i] = std::asin( gwSum ) * 180 / M_PI;
295 int start =
lDims[1] - 1;
296 int end =
lDims[4] - 1;
297 std::vector< double > gwVals( end );
300 for(
int j = 0; j != start - 1; j++ )
303 for( ; i !=
jlVals.size(); i++ )
305 gwSum += gwVals[start - 1 + i];
306 jlVals[i] = std::asin( gwSum ) * 180 / M_PI;
313 MB_SET_ERR( MB_FAILURE,
"Couldn't find 'lat' variable" );
320 if( ( vmit = varInfo.find(
"time" ) ) != varInfo.end() && ( *vmit ).second.varDims.size() == 1 )
324 else if( ( vmit = varInfo.find(
"t" ) ) != varInfo.end() && ( *vmit ).second.varDims.size() == 1 )
332 tVals.push_back( (
double)t );
341 std::map< std::string, ReadNC::VarData >::iterator mit;
342 for( mit = varInfo.begin(); mit != varInfo.end(); ++mit )
359 std::vector< std::string > ijdimNames( 4 );
360 ijdimNames[0] =
"__slon";
361 ijdimNames[1] =
"__slat";
362 ijdimNames[2] =
"__lon";
363 ijdimNames[3] =
"__lat";
365 std::string tag_name;
369 for(
unsigned int i = 0; i != ijdimNames.size(); i++ )
371 std::vector< int > val( 2, 0 );
372 if( ijdimNames[i] ==
"__slon" )
377 else if( ijdimNames[i] ==
"__slat" )
382 else if( ijdimNames[i] ==
"__lon" )
387 else if( ijdimNames[i] ==
"__lat" )
392 std::stringstream ss_tag_name;
393 ss_tag_name << ijdimNames[i] <<
"_LOC_MINMAX";
394 tag_name = ss_tag_name.str();
397 if(
MB_SUCCESS == rval ) dbgOut.
tprintf( 2,
"Conventional tag %s is created.\n", tag_name.c_str() );
402 switch( varInfo[
"lon"].varDataType )
408 MB_SET_ERR( MB_FAILURE,
"Unexpected variable data type for 'lon'" );
411 for(
unsigned int i = 0; i != ijdimNames.size(); i++ )
415 if( ijdimNames[i] ==
"__slon" )
420 else if( ijdimNames[i] ==
"__slat" )
425 else if( ijdimNames[i] ==
"__lon" )
430 else if( ijdimNames[i] ==
"__lat" )
436 std::stringstream ss_tag_name;
437 ss_tag_name << ijdimNames[i] <<
"_LOC_VALS";
438 tag_name = ss_tag_name.str();
442 if(
MB_SUCCESS == rval ) dbgOut.
tprintf( 2,
"Conventional tag %s is created.\n", tag_name.c_str() );
446 for(
unsigned int i = 0; i != ijdimNames.size(); i++ )
448 std::vector< int > val( 2, 0 );
449 if( ijdimNames[i] ==
"__slon" )
454 else if( ijdimNames[i] ==
"__slat" )
459 else if( ijdimNames[i] ==
"__lon" )
464 else if( ijdimNames[i] ==
"__lat" )
469 std::stringstream ss_tag_name;
470 ss_tag_name << ijdimNames[i] <<
"_GLOBAL_MINMAX";
471 tag_name = ss_tag_name.str();
474 if(
MB_SUCCESS == rval ) dbgOut.
tprintf( 2,
"Conventional tag %s is created.\n", tag_name.c_str() );