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

函数:c++

cpp 复制代码
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;
}

结果:

cpp 复制代码
XSizef1
YSizef30
ZSizef501
WSizef751
scale_factor0.00189809
add_offset-7.62598

读取数据:

cpp 复制代码
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
相关推荐
Navigator_Z9 小时前
LeetCode //C - 1318. Minimum Flips to Make a OR b Equal to c
c语言·算法·leetcode
yiangL_9 小时前
课后作业4:基于 Python 的古诗词词云可视化(P205)
开发语言·python
JosieBook10 小时前
【鸿蒙开源】把 Windows 任务栏上的流量表搬到鸿蒙 PC:TrafficMonitor 1.86 的 C++ 内核移植实践
c++·windows·harmonyos
Huangjin007_11 小时前
【C++ 算法竞赛篇】STL 常用知识点速通指南
c++·算法
geovindu11 小时前
rust: Functional Options Pattern
开发语言·后端·设计模式·rust·函数式选项模式·惯用法型模式
skywalk816312 小时前
把「假成功」赶出工具层:lightharness 两天升级复盘(4×5 模式矩阵 + 工具层 5 个缺陷)
开发语言·前端·人工智能·lightharness
敲上瘾12 小时前
Qt控件通用属性:geometry、qrc资源到QSS样式表等
开发语言·c++·qt·ui
炸膛坦客13 小时前
单片机/C/C++八股:(三十三)取别名
c语言·c++·单片机
听情歌落俗14 小时前
嵌入式学习1-C语言基础语法与STM32实践
c语言·开发语言
小飞在努力14 小时前
【实现负载均匀在线判题⑤】MVC 架构搭建与 Model 题目数据模块实现
c语言·开发语言·c++·笔记·后端