ODC库使用建议
12/02
本文最后更新于
2024年12月02日,已超过
89天没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!
odc库使用建议
- ODC库必须初始化
在程序调用实际odc库函数前,必须调用odc_initialise_api
函数。因为odc内部使用eckit库,如果odc程序未使用eckit,必须要初始化函数初始化eckit,否则程序会报错。
Attempting to access a non-existent instance of Main()
backtrace [1] stack has 12 addresses
(/path/to/eckit/1.25.0/lib64/libeckit.so+eckit::BackTrace::dump[abi:cxx11]())0x1af
(/path/to/eckit/1.25.0/lib64/libeckit.so+eckit::Main::instance())0x4d
(/path/to/eckit/1.25.0/lib64/libeckit.so+eckit::ResourceBase::init())0x7e
(/path/to/eckit/1.25.0/lib64/libeckit.so+eckit::FileHandle::open(char const*))0x132
(/path/to/eckit/1.25.0/lib64/libeckit.so+eckit::FileHandle::openForRead())0x1f
(/path/to/odc/1.5.0/lib64/libodccore.so+std::_Function_handler<void (), odc_open_path::{lambda()#1}>::_M_invoke(std::_Any_data const&))0x5b
(/path/to/odc/1.5.0/lib64/libodccore.so+odc_open_path)0x2d
(/path/to/odc/1.5.0/lib64/libfodc.so+odc_mp_reader_open_path_)0x12d
(./odc_test.exe)
(./odc_test.exe)
(/lib64/libc.so.6+__libc_start_main)0xf3
(./odc_test.exe)
end of backtrace dump ...
此外,官方建议调用odc_integer_behaviour(ODC_INTEGERS_AS_LONGS)
设置odc API中整数处理,传入参数ODC_INTEGERS_AS_LONGS表示64位有符号整数。默认整数表示为64位浮点数。一般建议使用64位整数。
- 每个odc函数检测其返回状态
odc API函数一般都会返回一个整数状态码,判断其执行是否成功。通常建议对每个返回状态码进行检查,确保odc函数执行正常。官方示例将检测函数封装为
subroutine check_call(err, desc)
integer, intent(in) :: err
character(*), intent(in) :: desc
if (err /= ODC_SUCCESS) then
write(error_unit, *) '**** An error occurred in ODC library'
write(error_unit, *) 'Description: ', desc
write(error_unit, *) 'Error: ', odc_error_string(err)
stop 1
end if
end subroutine
调用示例如下:
call check_call(reader%open_path(trim(path)), "opening path")
- 编译链接路径
odc库安装目录中模块文件及动态库所在路径与一般库不太一样,需要注意。
$ ifort -I${ODC_DIR}/module/odc -o odc_test.exe odc_test.f90 -L${ODC_DIR}/lib64 -lodccore -lfodc
- 解码前使用odc命令行工具查看数据
类似netcdf文件在读取前使用ncdump
命令查看数据坐标、变量信息,使用odc
命令查看odc数据的表格信息,尤其是每列属性。
$ odc ls test.odc
$ odc header test.odc
示例:
$ odc header example.odb
可以看到第4列wigos@hdr
类型为字符串,宽度为16字节。
第8列为BITFIELD类型,四个flags,名称及bit_size分别为{flag_a:1; flag_b:2; flag_c:3; flag_d:1}

