libsim Versione 8.0.0
example_vg6d_9.f90

Example to create a grib editionNumber = 2 file from data generated in memory using a grib_api template.

Example to create a grib editionNumber = 2 file from data generated in memory using a grib_api template

1! Copyright (C) 2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
2! authors:
3! Davide Cesari <dcesari@arpa.emr.it>
4! Paolo Patruno <ppatruno@arpa.emr.it>
5
6! This program is free software; you can redistribute it and/or
7! modify it under the terms of the GNU General Public License as
8! published by the Free Software Foundation; either version 2 of
9! the License, or (at your option) any later version.
10
11! This program is distributed in the hope that it will be useful,
12! but WITHOUT ANY WARRANTY; without even the implied warranty of
13! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14! GNU General Public License for more details.
15
16! You should have received a copy of the GNU General Public License
17! along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19!!!!!!!!!!!!!!!!
20! Example to create a grib editionNumber = 2 file from data generated in memory using a grib_api template.
21!!!!!!!!!!!!!!!!
22
23PROGRAM demo9
26USE grid_class
32IMPLICIT NONE
33
34integer :: ier
35type(l4f_handle) :: category
36character(len=512):: a_name
37TYPE(arrayof_gridinfo) :: gridinfo
38
39type(griddim_def) :: griddim
40
41integer,parameter :: nx=31, ny=16, component_flag=0
42type(grid_id) :: gaid_template
43type(vol7d_level) :: level
44type(vol7d_timerange) :: timerange
45type(volgrid6d_var) :: var
46type(datetime) :: date_time
47doubleprecision :: xmin=0., xmax=30., ymin=35., ymax=50.
48!doubleprecision :: latitude_south_pole=-32.5,longitude_south_pole=10.,angle_rotation=0.
49character(len=80) :: type='regular_ll'
50REAL :: field(nx,ny)
51INTEGER :: i, j
52
53! get launcher name
54call l4f_launcher(a_name,a_name_force="demo9")
55
56! log4fortran init
57ier=l4f_init()
58
59! set a_name
60category=l4f_category_get_handle(trim(a_name)//".main")
61
62call l4f_category_log(category,l4f_info,"start")
63
64! make room for two elements
65CALL insert(gridinfo, nelem=2)
66! define grib1 template
67gaid_template = grid_id_new(grib_api_template="regular_ll_sfc_grib1")
68! here you can change the default template
69CALL grib_set(grid_id_get_gaid(gaid_template), "centre", 80)
70CALL grib_set(grid_id_get_gaid(gaid_template), "jScansPositively", 1)
71
72! first element
73! define metadata
74CALL init(griddim, proj_type=type, nx=nx, ny=ny, &
75 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, component_flag=component_flag, &
76 categoryappend="generated")
77CALL init(date_time, year=2019, month=1, day=20, hour=0, minute=0)
78CALL init(timerange, timerange=254, p1=0, p2=0)
79CALL init(level, level1=1, l1=0, level2=imiss, l2=imiss)
80! define parameter land fraction
81CALL init(var, centre=80, category=2, number=81, discipline=255)
82! fill gridinfo with all metadata
83CALL init(gridinfo%array(1), gaid_template, griddim, date_time, timerange, level, &
84 var, clone=.true., categoryappend='inventato')
85
86! define data
87! create a N-S coastline at the center of the domain
88field(:nx/2,:) = 1.
89field(nx/2+1,:) = 0.
90CALL encode_gridinfo(gridinfo%array(1), field)
91
92! second element
93! define parameter geometric height
94CALL init(var, centre=80, category=2, number=8, discipline=255)
95! fill gridinfo with all metadata
96CALL init(gridinfo%array(2), gaid_template, griddim, date_time, timerange, level, &
97 var, clone=.true., categoryappend='inventato')
98
99! define data
100! create an E-W slope W of the coastline, 0 at the E
101DO i = 1, nx
102 field(i,:) = max(real(nx/2-i+1)/real(nx/2)*500., 0.)
103ENDDO
104CALL encode_gridinfo(gridinfo%array(2), field)
105
106CALL display(gridinfo)
107CALL l4f_category_log(category,l4f_info,"export to GRIB")
108CALL export(gridinfo, filename='const.grib', categoryappend="gridinfo scritto")
109
110CALL delete(gaid_template)
111CALL delete(gridinfo)
112
113! make room for one element
114CALL insert(gridinfo, nelem=1)
115! define grib2 template
116gaid_template = grid_id_new(grib_api_template="regular_ll_sfc_grib2")
117
118! redefine some metadata
119CALL init(timerange, timerange=254, p1=6, p2=0)
120CALL init(level, level1=103, l1=2000, level2=imiss, l2=imiss)
121! define parameter temperature
122CALL init(var, centre=80, category=0, number=0, discipline=0)
123! fill gridinfo with all metadata
124CALL init(gridinfo%array(1), gaid_template, griddim, date_time, timerange, level, &
125 var, clone=.false., categoryappend='inventato')
126! here you can change the template, after cloning but before coding metadata
127! different approach than above
128CALL grib_set(grid_id_get_gaid(gridinfo%array(1)%gaid), "centre", 80)
129CALL grib_set(grid_id_get_gaid(gridinfo%array(1)%gaid), "jScansPositively", 1)
130
131! define data
132! create an unrealistic field with all different values
133DO j = 1, ny
134 DO i = 1, nx
135 field(i,j) = 200. + (i-1)*0.5 + j*15.
136 ENDDO
137ENDDO
138CALL encode_gridinfo(gridinfo%array(1), field)
139
140CALL display(gridinfo)
141CALL l4f_category_log(category,l4f_info,"export to GRIB")
142CALL export(gridinfo, filename='t2m.grib', categoryappend="gridinfo scritto")
143
144CALL l4f_category_log(category,l4f_info,"end")
145
146CALL delete(gaid_template)
147CALL delete(gridinfo)
148
149! close logger
150CALL l4f_category_delete(category)
151ier=l4f_fini()
152
153END PROGRAM demo9
Distruttori per le 2 classi.
Costruttori per le classi datetime e timedelta.
Method for inserting elements of the array at a desired position.
Export griddim object to grid_id.
Clone the object, creating a new independent instance of the object exactly equal to the starting one...
Encode a data array into a grid_id object associated to a gridinfo object.
Emit log message for a category with specific priority.
Global log4fortran destructor.
Global log4fortran constructor.
Classi per la gestione delle coordinate temporali.
Module for describing geographically referenced regular grids.
This module defines an abstract interface to different drivers for access to files containing gridded...
Class for managing information about a single gridded georeferenced field, typically imported from an...
classe per la gestione del logging
Classe per la gestione dei livelli verticali in osservazioni meteo e affini.
Classe per la gestione degli intervalli temporali di osservazioni meteo e affini.
Class for managing physical variables in a grib 1/2 fashion.

Generated with Doxygen.