码迷,mamicode.com
首页 > 编程语言 > 详细

[原][c++][netcdf]通过c\c++读取字段的scale_factor与add_offset

时间:2020-05-21 00:01:38      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:off   c++   varname   offset   lan   tty   reads   amp   编译   

函数: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

 

怎么编译 netcdf-c++?看这里!

[原][c++][netcdf]通过c\c++读取字段的scale_factor与add_offset

标签:off   c++   varname   offset   lan   tty   reads   amp   编译   

原文地址:https://www.cnblogs.com/lyggqm/p/12927292.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!