ODB2格式观测数据处理库: odc(一)
05/27
本文最后更新于
2024年08月02日,已超过
211天没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!
ODB-2数据格式是ECMWF开发用于气象观测数据存储的一种紧凑的表格形式数据格式。
odc库是用于对ODB-2数据格式编码和解码处理的专用库,提供C/C++/Fortran接口,并提供命令行工具。
项目地址:https://github.com/ecmwf/odc
依赖
安装
- ecbuild安装
下载最新版本3.8.2, https://github.com/ecmwf/ecbuild/archive/refs/tags/3.8.2.tar.gz
具体安装过程见[[ecBuild构建工具]]。
- eckit安装
下载最新版本1.25.0,https://github.com/ecmwf/eckit/archive/refs/tags/1.25.0.tar.gz。
$ tar xzvf eckit-1.25.0.tar.gz
$ cd eckit-1.25.0
$ mkdir build
$ cd build
$ export CC=icc CXX=icpc
$ ecbuild --prefix=/path/to/install/eckit/1.25.0 -- ..
$ make -j10 #10个线程并行编译
$ make install
$ /path/to/install/eckit/1.25.0/bin/eckit-version
- odc安装
$ tar xzvf odc-1.5.0.tar.gz
$ cd odc-1.5.0
$ export eckit_DIR=/path/to/install/eckit/1.25.0
$ mkdir build
$ cd build
$ export CC=icc CXX=icpc FC=ifort
$ ecbuild --prefix=/path/to/install/odc/1.5.0 -DENABLE_FORTRAN=ON -- ..
$ make -j10 #10个线程并行编译
$ make test
$ make install
$ /path/to/install/odc/1.5.0/bin/odc --version
使用
在~/.bashrc
中设置环境变量并source生效
export ODC_DIR=/path/to/install/odc/1.5.0
export PATH=$ODC_DIR/bin:$PATH
export LD_LIBRARY_PATH=$ODC_DIR/lib64:$LD_LIBRARY_PATH
C测试程序
// odc_test.c
#include "odc/api/odc.h"
int main() {
odc_initialise_api();
return 0;
}
编译运行:
$ icc -I/path/to/install/odc/1.5.0/include -o odc_test odc_test.c -L/path/to/install/odc/1.5.0/lib64 -lodccore
$ ./odc_test
Fortran测试程序
program odc_test
use odc
implicit none
integer :: rc
rc = odc_initialise_api()
end program
编译程序:
$ ifort -I$ODC_DIR/module/odc -o odc_test_f odc_test.f90 -L$ODC_DIR/lib64 -lfodc -lodccore
$ ./odc_test_f
命令行工具
odc库提供了命令行工具odc
直接操作ODB-2数据。
$ odc
Usage:
odc <command> [<command's-parameters>]
odc help <command>
Available commands:
compare Compares two ODB files
count Counts number of rows in files
header Shows header(s) and metadata(s) of file
import Imports data from a text file
index Creates index of reports for a given file
ls Shows file's contents
mdset Creates a new file resetting types or values (constants only) of columns.
merge Merges rows from files
set Creates a new file setting columns to given values
split Splits file according to given template
sql Executes SQL statement
可以从网页https://odc.readthedocs.io/en/latest/content/tools.html
下载测试数据data-1.odb进行测试。
$ odc ls data-1.odb

