TypechoJoeTheme

MetMan's Blog

网站页面

ODB2格式观测数据处理库: odc(一)

MetMan博 主
2024-05-27
/
0 评论
/
116 阅读
/
186 个字
/
百度已收录
05/27
本文最后更新于 2024年08月02日,已超过 48天没有更新。如果文章内容或图片资源失效,请留言反馈,我会及时处理,谢谢!

ODB-2数据格式是ECMWF开发用于气象观测数据存储的一种紧凑的表格形式数据格式。

odc库是用于对ODB-2数据格式编码和解码处理的专用库,提供C/C++/Fortran接口,并提供命令行工具。

项目地址:https://github.com/ecmwf/odc

依赖

安装

  1. ecbuild安装

下载最新版本3.8.2, https://github.com/ecmwf/ecbuild/archive/refs/tags/3.8.2.tar.gz

具体安装过程见[[ecBuild构建工具]]。

  1. 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
  1. 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
obcodb2
朗读
赞(0)
赞赏
感谢您的支持,我会继续努力哒!
版权属于:

MetMan's Blog

本文链接:

https://blog.metman.top/index.php/archives/106/(转载时请注明本文出处及文章链接)

评论 (0)

互动读者

标签云

最新回复

暂无回复

登录
X
用户名
密码