参考自ECMWF网站https://confluence.ecmwf.int/display/OPTR/ecCodes%3A+GRIB+and+BUFR+data+decoding+and+encoding+software+2019的ppt

引言

  • eccodes高端命令行工具
  • 在输入文件中遍历所有messages
  • 对于每个message采用一个用户定义的规则
  • 该规则使用ecCodes规定的宏语言的格式
  • 注意该宏语言并没有一个全面的(full-blown)编程的能力
  • 在grib_filter和bufr_filter中的宏语言的语法是相同的
  • 在一个message中通过关键字keys访问数据
  • 打印一个message的内容
  • 在一个message中保存值
  • 使用控制结构(if,switch)
  • 将消息写入磁盘

grib_filter 用法

grib_filter [-o out_file ] rules_file in_file1 in_file2 …
  • 输入文件中每一个场都被处理,在规则文件rules_file中的规则被应用在其中
  • 仅当有一个写的指令被应用时,一个GRIB message被写在一个输出文件中
  • 在rules_file中每一个指令必须以一个分号“;”结尾
  • rules_file中的语法错误会报告,连同错误的行号
  • 永远都要将-o out_file 放在其它选项之前!
  • 或者,可以从标准输入中读取规则:

cat rules_file | grib_filter in_file1 in_file2 …

echo ‘print “Hello”;’ | grib_filter in_file1 in_file2 …

规则语法-print声明

  • print “some text”; # this is a comment
  • print “some text [key]";

-打印到标准输出 Print to the standard output

-检索方括号中的关键字的值 Retrieve the value of the keys in squared brackets.

-如果在消息中没有找到关键字的值,将会被赋值为"undef" If a key is not found in the message then the value of [key] will be displayed as "undef"

-[key] --> native type

-[key:i ] --> integer

-[key:s ] --> string

-[key:d ] --> double

-[key!c%F'S'] --> arrays: c -->columns F -->format (C style) S -->separator

  • print (“filename”) “some text [key]";

例子1——使用print (注:分割线上面的是rule.filter的内容,下面是命令及输出)

# A simple print
print "ed = [edition] centre is [centre:s] = [centre:i]";
----------------------------------------------------------------------------------------------
> grib_filter rule.filter x.grib1
ed = 1 centre is ecmf = 98

例子2——使用有格式的print

# one column 3 decimal digits
print "[distinctLatitudes!1%.3f]";
----------------------------------------------------------------------------------------------
-90.000
-88.500
-87.000
-85.500

例子3——用分隔符输出

# three columns 5 decimal digits comma separated
print "[latLonValues!3%.5f',']";
------------------------------------------------------------------------
> grib_filter rule.filter x.grib1
90.00000,0.00000,1.00000,
90.00000,1.50000,1.00000,
90.00000,3.00000,1.00000,

规则语法——write声明

  • write;

- 在命令行中用-o选项定义输出文件,将现有消息写到该输出文件中

grib_filter -o outfile rules_file grib_file

如果-o选项没有指定,使用缺省值”filter.out“

  • write "filename_[key]";

-将当前message写入文件"filename_[key]"中,其中方括号内的key用message中检索到的值代替

-如果两个message对于[key]有不同的值,它们同样写到不同文件中

例子4——write 声明

# Creating multiple files
write "[centre]_[dataDate]_[step].grib[edition]";
-------------------------------------------------------------
> grib_filter rule.filter x.grib1
> ls
ecmf_20080213_0.grib1
ecmf_20080213_6.grib1
ecmf_20080213_12.grib1
ecmf_20080213_24.grib1

规则语法——append声明

  • append;

- 在命令行中用-o选项定义输出文件,将现有消息追加到该输出文件中

grib_filter -o outfile rules_file grib_file

如果-o选项没有指定,使用缺省值”filter.out“

  • append "filename_[key]";

-将当前message追加写入文件"filename_[key]"中,其中方括号内的key用message中检索到的值代替

-如果文件不存在则创建它

-如果两个message对于[key]有不同的值,它们同样写到不同文件中

例子5——append 声明

append;

---------------------------------------------------------------------
> grib_count out.grib
> 1
>
> grib_filter o out.grib rule.filter in.grib
>
> grib_count out.grib
> 2

规则语法——设置关键字

  • set key1 = key2 ; # 将key1的值设为key2 set key1 to the value of key2
  • set key = {val1,val2,val3,val4} ; # 设置一个关键字数组 set an array key
  • set key = "string" ; # 将关键字设成一个字符串 set key to a string
  • set key = expression ; # 将关键字设置成一个表达式 set key to an expression
  • set key = MISSING ; # 将关键字的值设置成缺失 set value of key to missing
  • 表达式运算符:

== 等于 equal to
!= 不等于 not equal to
is 等于字符串 equals to for strings
|| 或 or
&& 且 and
! 非 not
* / + - 算术运算符 arithmetic operators
( )

例子6——设置关键字

set _edition =2; 
write "[file][edition]";
---------------------------------------------------------------------
> grib_filter rule.filter x.grib
> ls
x.grib
x.grib2

例子7——设置一个数组关键字

set values = {12.2,14.8,13.7,72.3};
print "values = { [values] }";
write "[file].[edition]";
-----------------------------------------------------------------------
> grib_filter rule.filter x.grib
values = { 12.2 14.8 13.7 72.3 }

规则语法——临时关键字(transient keys)

  • transient key1 = key2; - 定义一个新的关键字key1并将它的值设置为key2  Defines the new key1 and assigns to it the value of key2
  • transient key1 = "string";
  • transient key1 = expression;
  • 表达式运算符:

== 等于 equal to
!= 不等于 not equal to
is 等于字符串 equals to for strings
|| 或 or
&& 且 and
! 非 not
* / + - 算术运算符 arithmetic operators
( )

例子8——临时关键字

transient mystep = step + 24;
print "step = [step] mystep = [mystep]";
-----------------------------------------------------
> grib_filter rule.filter x.grib
step = 24 mystep = 48

实例(略)

规则语法——if 声明

  • if ( expression ) { instructions }                                      没有'else if'-你需要创建一个新的'if'块
  • if ( expression ) { instructions }
    else { instructions }
  • 表达式运算符:

== 等于 equal to
!= 不等于 not equal to
is 等于字符串 equals to for strings
|| 或 or
&& 且 and
! 非 not
* / + - 算术运算符 arithmetic operators
( )

例子9——if声明

if (localDefinitionNumber == 1) {
set edition = 2;
write;
}
--------------------------------------------------------
> grib_filter o out.grib2 rule.filter x.grib1
> ls
out.grib2

规则语法——swich 声明

是'if-else'声明的替代版

当你有代码需要从许多要跟随的路径中选择一个时,更方便

switch (var) {
case val1:
# set of actions
case val2:
# set of actions
default
# default block of actions
}

默认:case是强制的,即使if是空的

例子10——switch声明

print "processing [paramId] [shortName] [stepType]";
switch (shortName) {
case "tp" :
set stepType accum";
case "sp" :
set typeOfLevel ="surface";
default:
print "Unexpected parameter";
}
write;

例子11

if (centre is "lfpw" &&
(indicatorOfParameter == 6 ||
indicatorOfParameter == 11 ||
indicatorOfParameter == 8) )
{
if (step!=0) {
set typeOfGeneratingProcess=0;
set typeOfProcessedData=0;
} else {
# Other steps
set typeOfProcessedData=1;


switch (typeOfLevel) {
case "hybrid":
set changeDecimalPrecision=1;
case "surface":
set changeDecimalPrecision=2;
case "isobaricInhPa":
if (level > 300) {
print "level > 300);
set level = level*2 + 15;
}# end if (level > 300)
default:
print "Unknown level type!";
}# end switch (typeOfLevel)
}# end if (step!=0)
write;
}# end main if

规则语法——assert 声明

  • assert(condition);
  • 如果状态评估是假则filter会丢弃
# This filter should be run on GRIB edition 1 only;
# abort otherwise
assert (edition == 1) ;
...
> grib_filter o out.grib2 rule.filter x.grib2
ECCODES ERROR : Assertion failure:
binop (access('edition=2'),long(2))

eccodes 使用girb_filter工具的更多相关文章

  1. ecCodes 学习 利用ecCodes fortran90 api对GRIB文件进行读写

    参考 https://www.ecmwf.int/assets/elearning/eccodes/eccodes2/story_html5.htmlhttps://confluence.ecmwf. ...

  2. Unity3d入门 - 关于unity工具的熟悉

    上周由于工作内容较多,花在unity上学习的时间不多,但总归还是学习了一些东西,内容如下: .1 根据相关的教程在mac上安装了unity. .2 学习了unity的主要的工具分布和对应工具的相关的功 ...

  3. 细说前端自动化打包工具--webpack

    背景 记得2004年的时候,互联网开发就是做网页,那时也没有前端和后端的区分,有时一个网站就是一些纯静态的html,通过链接组织在一起.用过Dreamweaver的都知道,做网页就像用word编辑文档 ...

  4. 应用工具 .NET Portability Analyzer 分析迁移dotnet core

    大多数开发人员更喜欢一次性编写好业务逻辑代码,以后再重用这些代码.与构建不同的应用以面向多个平台相比,这种方法更加容易.如果您创建与 .NET Core 兼容的.NET 标准库,那么现在比以往任何时候 ...

  5. .NetCore中的日志(2)集成第三方日志工具

    .NetCore中的日志(2)集成第三方日志工具 0x00 在.NetCore的Logging组件中集成NLog 上一篇讨论了.NetCore中日志框架的结构,这一篇讨论一下.NetCore的Logg ...

  6. dll文件32位64位检测工具以及Windows文件夹SysWow64的坑

    自从操作系统升级到64位以后,就要不断的需要面对32位.64位的问题.相信有很多人并不是很清楚32位程序与64位程序的区别,以及Program Files (x86),Program Files的区别 ...

  7. Java基础Map接口+Collections工具类

    1.Map中我们主要讲两个接口 HashMap  与   LinkedHashMap (1)其中LinkedHashMap是有序的  怎么存怎么取出来 我们讲一下Map的增删改查功能: /* * Ma ...

  8. 渗透测试工具BurpSuite做网站的安全测试(基础版)

    渗透测试工具BurpSuite做网站的安全测试(基础版) 版权声明:本文为博主原创文章,未经博主允许不得转载. 学习网址: https://t0data.gitbooks.io/burpsuite/c ...

  9. CorelDRAW X8 如何破解激活(附国际版安装包+激活工具) 2016-12-15

    之前有位搞平面的好友“小瘦”说CDR X8无法破解,只能用X7.呃……呃……呃……好像是的 其实CDR8难激活主要在于一个点“没有离线激活了,只可以在线激活”,逆天不是专供逆向的,当然没能力去破解,这 ...

  10. Web Api 入门实战 (快速入门+工具使用+不依赖IIS)

    平台之大势何人能挡? 带着你的Net飞奔吧!:http://www.cnblogs.com/dunitian/p/4822808.html 屁话我也就不多说了,什么简介的也省了,直接简单概括+demo ...

随机推荐

  1. Postgresql WAL日志浅析

    一.预写日志(WAL) 预写式日志(Write Ahead Log,WAL)是保证数据完整性的一种标准方法.简单来说,WAL的中心概念是数据文件(存储着表和索引)的修改必须在这些动作被日志记录之后才被 ...

  2. TextBox 事件

    1.键盘事件 界面代码: <Grid> <Grid.RowDefinitions> <RowDefinition Height="auto">& ...

  3. 溢出标志位OF与进位标志位CF判断

    1.OF与CF概述 OF(Overflow Flag,溢出标志位):有符号数之间加减运算的溢出标志 CF(Carry Flag,进位标志位):无符号数之间加减运算的溢出标志 快速判断(加法)(减法可转 ...

  4. fastai fit_one_cycle AttributeError: 'function' object has no attribute 'parameters'

    初学fastai   fit_one_cycle语句报错指向614行, 即: return [p for p in m.parameters() if p.requires_grad] 在以前遇到这种 ...

  5. python collection Chainmap Counter

    chainmap是一个方便的工具类.它是使用链的方式将多个dict链在一起, 并不是真正的生成一个新的dict,从而允许程序可以这获取任意一个dict 所包含的所有key对应的value. 但是由于式 ...

  6. Bouncy Castle密码算法库

    Bouncy Castle密码算法库 一.开发背景 Bouncy Castle 是一种用于 Java 平台的开放源码的轻量级密码术包.它支持大量的密码术算法,并提供 JCE 1.2.1 的实现.因为 ...

  7. Echarts 圆形立体柱状图

    先放个效果图 const resData = [ { label: "上海", value: 66 }, { label: "北京", value: 26 }, ...

  8. UE4启动顺序

    GameMode PlayerController Actor Level gameMode , playerController控制pawn , 激活默认相机active camera , getP ...

  9. oracle 行转列,动态年份,月份列。已解决!

    -----------------存储过程包体----------- procedure GetComparativeAnalysisTB(p_StartTime varchar2, ----开始时间 ...

  10. plugin的原理

    plugin插件的原理 扩展webpack, 加入自定义的构建行为 webpack内部的钩子 hooks tap: 可以注册同步钩子和异步钩子 tapAsync: 回调方式注册异步钩子 tapProm ...