- 积分
- 55961
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-6-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 MeteoInfo 于 2013-8-30 11:35 编辑
MeteoInfo Java版具有更好的跨平台能力,对于做模式的人来说通常会用Linux或者Unix,很适合使用Java版。之前说过由于Jython对中文的支持不好,选择了Groovy作为MeteoInfo Java版的脚本语言。这里给出一个将GRIB数据转为HYSPLIT模式用的ARL数据的Groovy脚本例子。
MeteoInfo Java版里包含了一个脚本代码编辑器,可以在MeteoInfo桌面程序的“工具 -> 脚本”菜单打开编辑器,在编辑器中可以新建、打开、编辑、保存脚本程序并运行。
也可以在命令行中运行MeteoInfo.jar时加上“-e”参数,从而在不启动MeteoInfo桌面程序的情况下直接打开脚本剪辑器:
还可以直接在命令行中运行脚本程序,不启动任何界面,适合脚本自动运行:
示例程序转成的ARL数据:
脚本代码:
- //--------------------------------------------------------
- // Author: Yaqiang Wang
- // Date: 2013-8-27
- // Purpose: Convert GRIB data to ARL data
- // Note: Sample
- //-----------------------------------------------------------
- import org.meteoinfo.data.*
- import org.meteoinfo.data.meteodata.*
- import org.meteoinfo.data.meteodata.arl.*
- // Set directory
- dataDir = 'D:/Temp/'
- // Set output data file
- outfn = dataDir + 'arl/test.arl'
- // Read GRIB data file
- mydata = new MeteoDataInfo()
- infn = dataDir + 'grib/fnl_20110416_00_00'
- println infn + '\n'
- mydata.openNetCDFData(infn)
- println 'GRIB file has been opened...\n'
- // Set output ARL data info
- arlDI = new ARLDataInfo()
- // Set variable and level list
- gvars = ['Pressure_surface','Temperature_height_above_ground',
- 'u-component_of_wind_height_above_ground','v-component_of_wind_height_above_ground',
- 'Total_precipitation_surface_0_Hour_Accumulation','Geopotential_height_isobaric','Temperature_isobaric',
- 'u-component_of_wind_isobaric','v-component_of_wind_isobaric','Vertical_velocity_pressure_isobaric',
- 'Relative_humidity_isobaric']
- avars = ['PRSS','T02M','U10M','V10M','TPP6','HGTS','TEMP','UWND','VWND','WWND','RELH']
- levels = [0,1000.0,2000.0,3000.0,5000.0,7000.0,10000.0,15000.0,20000.0,25000.0,30000.0,35000.0,40000.0,45000.0,
- 50000.0,55000.0,60000.0,65000.0,70000.0,75000.0,80000.0,
- 85000.0,90000.0,92500.0,95000.0,97500.0,100000.0]
- levels.each { l->
- arlDI.levels.add(l)
- if (l == 0){
- arlDI.LevelVarList.add(['PRSS','T02M','U10M','V10M','TPP6'])
- } else if (l < 10000) {
- arlDI.LevelVarList.add(['HGTS','TEMP','UWND','VWND'])
- } else {
- arlDI.LevelVarList.add(['HGTS','TEMP','UWND','VWND','WWND','RELH'])
- }
- }
- // Write ARL data file
- dataInfo = mydata.getDataInfo()
- arlDI.createDataFile(outfn)
- arlDI.X = dataInfo.getXDimension().getValues()
- arlDI.Y = dataInfo.getYDimension().getValues()
- variables = dataInfo.getVariables()
- tNum = dataInfo.getTimeNum()
- for (t in 0..tNum-1){
- mydata.setTimeIndex(t)
- atime = dataInfo.getTimes().get(t)
- aDH = arlDI.getDataHead(mydata.getProjectionInfo(), 'FNL1', 2)
- arlDI.writeIndexRecord(atime, aDH)
- lidx = 0
- arlDI.levels.each { l->
- println l
- println '\n'
- arlDI.LevelVarList[lidx].each { v->
- vName = gvars[avars.indexOf(v)]
- println vName + '\n'
- if (lidx == 0){
- mydata.setLevelIndex(lidx)
- } else {
- variable = dataInfo.getVariable(vName)
- nlidx = variable.getZDimension().getDimValue().indexOf (new Double(l))
- println 'Level index: ' + nlidx.toString() + '\n'
- mydata.setLevelIndex(nlidx)
- }
- gData = mydata.getGridData(vName)
- if (gData == null){
- println 'Grid data is null!\n'
- }
- if (v == 'PRSS' || v == 'WWND'){
- gData = gData.divide(100)
- } else if (v == 'TPP6'){
- gData = gData.divide(1000)
- }
- aDL = new DataLabel(atime)
- aDL.setLevel(lidx)
- aDL.setVarName(v)
- aDL.setGrid(99)
- aDL.setForecast(0)
- arlDI.writeGridData(aDL, gData)
- }
- lidx += 1
- }
- }
- arlDI.closeDataFile()
- println 'Finished!'
|
|