本文整理汇总了C++中NcVar::as_long方法的典型用法代码示例。如果您正苦于以下问题:C++ NcVar::as_long方法的具体用法?C++ NcVar::as_long怎么用?C++ NcVar::as_long使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NcVar
的用法示例。
在下文中一共展示了NcVar::as_long方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadRadarFile
//.........这里部分代码省略.........
{
cerr << "ERROR: invalid data file. No variable called 'lat'!\n";
radarFile.close();
return(inputData);
}
long latCnt = latVar->num_vals();
double* latVals = new double[latCnt];
latVar->get(latVals, latCnt);
inputData.latUnits = GrabAttribute(latVar, 0);
inputData.latSpacing = strtod(GrabAttribute(latVar, 1).c_str(), NULL);
const long minLatIndex = lower_bound(latVals, latmin, latCnt);
const long maxLatIndex = upper_bound(latVals, latmax, latCnt);
delete latVals;
latCnt = (maxLatIndex - minLatIndex) + 1;
latVar->set_cur(minLatIndex);
inputData.latVals = new double[latCnt];
latVar->get(inputData.latVals, latCnt);
NcVar* lonVar = radarFile.get_var("lon");
if (NULL == lonVar)
{
cerr << "ERROR: invalid data file. No variable called 'lon'!\n";
radarFile.close();
return(inputData);
}
long lonCnt = lonVar->num_vals();
double* lonVals = new double[lonCnt];
lonVar->get(lonVals, lonCnt);
inputData.lonUnits = GrabAttribute(lonVar, 0);
inputData.lonSpacing = strtod(GrabAttribute(lonVar, 1).c_str(), NULL);
const long minLonIndex = lower_bound(lonVals, lonmin, lonCnt);
const long maxLonIndex = upper_bound(lonVals, lonmax, lonCnt);
delete lonVals;
lonCnt = (maxLonIndex - minLonIndex) + 1;
lonVar->set_cur(minLonIndex);
inputData.lonVals = new double[lonCnt];
lonVar->get(inputData.lonVals, lonCnt);
NcVar* reflectVar = NULL;
reflectVar = radarFile.get_var("value");
if ( reflectVar == NULL )
{
// Try this variable name
reflectVar = radarFile.get_var("Reflectivity");
}
if (reflectVar == NULL)
{
cerr << "ERROR: invalid data file. No variable called 'value'!\n";
radarFile.close();
return(inputData);
}
inputData.dataEdges = reflectVar->edges(); // [0] - time, [1] - lat, [2] - lon
inputData.dataEdges[1] = latCnt;
inputData.dataEdges[2] = lonCnt;
inputData.dataVals = new double[inputData.dataEdges[0] * inputData.dataEdges[1] * inputData.dataEdges[2]];
reflectVar->set_cur(0, minLatIndex, minLonIndex);
reflectVar->get(inputData.dataVals, inputData.dataEdges);
inputData.var_LongName = GrabAttribute(reflectVar, 0);
inputData.var_Units = "dBZ";//GrabAttribute(reflectVar, 1);
NcVar* timeVar = radarFile.get_var("time");
if (NULL == timeVar)
{
cerr << "ERROR: invalid data file. No variable called 'time'!\n";
radarFile.close();
return(inputData);
}
inputData.scanTime = timeVar->as_long(0);
inputData.timeUnits = GrabAttribute(timeVar, 0);
NcAtt* titleAttrib = radarFile.get_att("title");
inputData.fileTitle = (NULL == titleAttrib ? "" : titleAttrib->as_string(0));
delete titleAttrib;
radarFile.close();
// Success!
inputData.inputFilename = filename;
return(inputData);
}