函数:c++
void readScaleAndOffset(const char* FileName,const char* VarName) { NcFile dataFile(FileName, NcFile::read); NcVar Varf = dataFile.getVar(VarName); //查看维度 cout << "XSizef" << Varf.getDim(0).getSize() << endl; cout << "YSizef" << Varf.getDim(1).getSize() << endl; cout << "ZSizef" << Varf.getDim(2).getSize() << endl; cout << "WSizef" << Varf.getDim(3).getSize() << endl; //查看压缩值 NcVarAtt AttT = Varf.getAtt("scale_factor"); NcType TypeT = AttT.getType(); int TypeId = TypeT.getId(); //float,长度是1 float fScale = 0.0f; AttT.getValues(&fScale); AttT = Varf.getAtt("add_offset"); float fOffset = 0.0f; AttT.getValues(&fOffset); cout << "scale_factor" << fScale << endl; cout << "add_offset" << fOffset << endl; }
结果:
XSizef1 YSizef30 ZSizef501 WSizef751 scale_factor0.00189809 add_offset-7.62598
读取数据:
vector<size_t> vectorS; vectorS.push_back(0);//time vectorS.push_back(0);//level vectorS.push_back(0);//latitude vectorS.push_back(0);//longtitude float buf[1]; Varf.getVar(vectorS, buf); cout << "buf[0]" << buf[0] << endl;//raw buf[0] *= fScale; buf[0] += fOffset; cout << "buf[0]" << buf[0] << endl;//real
怎么编译 netcdf-c++?看这里!