eccodes 使用girb_filter工具
参考自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工具的更多相关文章
- ecCodes 学习 利用ecCodes fortran90 api对GRIB文件进行读写
参考 https://www.ecmwf.int/assets/elearning/eccodes/eccodes2/story_html5.htmlhttps://confluence.ecmwf. ...
- Unity3d入门 - 关于unity工具的熟悉
上周由于工作内容较多,花在unity上学习的时间不多,但总归还是学习了一些东西,内容如下: .1 根据相关的教程在mac上安装了unity. .2 学习了unity的主要的工具分布和对应工具的相关的功 ...
- 细说前端自动化打包工具--webpack
背景 记得2004年的时候,互联网开发就是做网页,那时也没有前端和后端的区分,有时一个网站就是一些纯静态的html,通过链接组织在一起.用过Dreamweaver的都知道,做网页就像用word编辑文档 ...
- 应用工具 .NET Portability Analyzer 分析迁移dotnet core
大多数开发人员更喜欢一次性编写好业务逻辑代码,以后再重用这些代码.与构建不同的应用以面向多个平台相比,这种方法更加容易.如果您创建与 .NET Core 兼容的.NET 标准库,那么现在比以往任何时候 ...
- .NetCore中的日志(2)集成第三方日志工具
.NetCore中的日志(2)集成第三方日志工具 0x00 在.NetCore的Logging组件中集成NLog 上一篇讨论了.NetCore中日志框架的结构,这一篇讨论一下.NetCore的Logg ...
- dll文件32位64位检测工具以及Windows文件夹SysWow64的坑
自从操作系统升级到64位以后,就要不断的需要面对32位.64位的问题.相信有很多人并不是很清楚32位程序与64位程序的区别,以及Program Files (x86),Program Files的区别 ...
- Java基础Map接口+Collections工具类
1.Map中我们主要讲两个接口 HashMap 与 LinkedHashMap (1)其中LinkedHashMap是有序的 怎么存怎么取出来 我们讲一下Map的增删改查功能: /* * Ma ...
- 渗透测试工具BurpSuite做网站的安全测试(基础版)
渗透测试工具BurpSuite做网站的安全测试(基础版) 版权声明:本文为博主原创文章,未经博主允许不得转载. 学习网址: https://t0data.gitbooks.io/burpsuite/c ...
- CorelDRAW X8 如何破解激活(附国际版安装包+激活工具) 2016-12-15
之前有位搞平面的好友“小瘦”说CDR X8无法破解,只能用X7.呃……呃……呃……好像是的 其实CDR8难激活主要在于一个点“没有离线激活了,只可以在线激活”,逆天不是专供逆向的,当然没能力去破解,这 ...
- Web Api 入门实战 (快速入门+工具使用+不依赖IIS)
平台之大势何人能挡? 带着你的Net飞奔吧!:http://www.cnblogs.com/dunitian/p/4822808.html 屁话我也就不多说了,什么简介的也省了,直接简单概括+demo ...
随机推荐
- kotlin学习-Coroutines(协程)
协程(又名纤程),轻量级线程(建立在线程基础上,属于用户态调用),非阻塞式编程(像同步编写一样),在用户态内进行任务调度,避免与内核态过多交互问题,提高程序快速响应.协程使用挂起当前上下文替代阻塞,被 ...
- Windows 干净启动
1. 卸载设备中全部的第三方反病毒软件与系统优化软件 (例如 360.腾讯电脑管家.鲁大师等).2. 按 "Windows 徽标键+R",输入 "msconfig&quo ...
- flexible.js源码分析
(function flexible(window,document){ // 获取html的根元素 var docEl = document.documentElement; // dpr 物理像素 ...
- [后端-Python]-项目练习集
1 1. 2 ''' 3 knowledge_point: 4 1.练习if...else: 5 2.练习while; 6 3.练习列表的切片取值: 7 8 requirements: 9 购物车: ...
- LinuxK8S集群搭建三(部署dashboard)
系统环境: CentOS 7 64位 准备工作: 通过虚拟机创建三台CentOS服务器,可参照之前的文章192.168.28.128 --master192.168.28.130 --node0119 ...
- Apache druid笔记
Apache Duid学习笔记2 1.历史节点的查询效率与内存数据比成正比,内存越大则读取磁盘的次数越少, 历史节点内存越大总数据量越小则查询速度越快. 2.缓存机制可以选择外部和内部缓存,外部缓存如 ...
- Software--C#--grammer_Delegate--Event
2018-05-01 10:49:47 委托是一种类型,而事件是一个类或结构的成员,如同字段,属性.必须在类或结构中声明. 引申 - Observe 观察者模式 Publish/Subscribe ...
- CS客户端 App.Config更新问题
appconfig更新必须要重启才可以 这个方法为热更新不用重新启动 public void ModifyConfig(string serverName, string dbName, strin ...
- torrent种子
- Activity 的窗口去头的方式
1\窗口去头的第一种方式 public class SplashActivity extends Activity { @Override protected void onCreate(Bundle ...