libsim Versione 7.2.6
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 :: category,ier
35character(len=512):: a_name
36TYPE(arrayof_gridinfo) :: gridinfo
37
38type(griddim_def) :: griddim
39
40integer,parameter :: nx=31, ny=16, component_flag=0
41type(grid_id) :: gaid_template
42type(vol7d_level) :: level
43type(vol7d_timerange) :: timerange
44type(volgrid6d_var) :: var
45type(datetime) :: date_time
46doubleprecision :: xmin=0., xmax=30., ymin=35., ymax=50.
47!doubleprecision :: latitude_south_pole=-32.5,longitude_south_pole=10.,angle_rotation=0.
48character(len=80) :: type='regular_ll'
49REAL :: field(nx,ny)
50INTEGER :: i, j
51
52! get launcher name
53call l4f_launcher(a_name,a_name_force="demo9")
54
55! log4fortran init
56ier=l4f_init()
57
58! set a_name
59category=l4f_category_get(trim(a_name)//".main")
60
61call l4f_category_log(category,l4f_info,"start")
62
63! make room for two elements
64CALL insert(gridinfo, nelem=2)
65! define grib1 template
66gaid_template = grid_id_new(grib_api_template="regular_ll_sfc_grib1")
67! here you can change the default template
68CALL grib_set(grid_id_get_gaid(gaid_template), "centre", 80)
69CALL grib_set(grid_id_get_gaid(gaid_template), "jScansPositively", 1)
70
71! first element
72! define metadata
73CALL init(griddim, proj_type=type, nx=nx, ny=ny, &
74 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, component_flag=component_flag, &
75 categoryappend="generated")
76CALL init(date_time, year=2019, month=1, day=20, hour=0, minute=0)
77CALL init(timerange, timerange=254, p1=0, p2=0)
78CALL init(level, level1=1, l1=0, level2=imiss, l2=imiss)
79! define parameter land fraction
80CALL init(var, centre=80, category=2, number=81, discipline=255)
81! fill gridinfo with all metadata
82CALL init(gridinfo%array(1), gaid_template, griddim, date_time, timerange, level, &
83 var, clone=.true., categoryappend='inventato')
84
85! define data
86! create a N-S coastline at the center of the domain
87field(:nx/2,:) = 1.
88field(nx/2+1,:) = 0.
89CALL encode_gridinfo(gridinfo%array(1), field)
90
91! second element
92! define parameter geometric height
93CALL init(var, centre=80, category=2, number=8, discipline=255)
94! fill gridinfo with all metadata
95CALL init(gridinfo%array(2), gaid_template, griddim, date_time, timerange, level, &
96 var, clone=.true., categoryappend='inventato')
97
98! define data
99! create an E-W slope W of the coastline, 0 at the E
100DO i = 1, nx
101 field(i,:) = max(real(nx/2-i+1)/real(nx/2)*500., 0.)
102ENDDO
103CALL encode_gridinfo(gridinfo%array(2), field)
104
105CALL display(gridinfo)
106CALL l4f_category_log(category,l4f_info,"export to GRIB")
107CALL export(gridinfo, filename='const.grib', categoryappend="gridinfo scritto")
108
109CALL delete(gaid_template)
110CALL delete(gridinfo)
111
112! make room for one element
113CALL insert(gridinfo, nelem=1)
114! define grib2 template
115gaid_template = grid_id_new(grib_api_template="regular_ll_sfc_grib2")
116
117! redefine some metadata
118CALL init(timerange, timerange=254, p1=6, p2=0)
119CALL init(level, level1=103, l1=2000, level2=imiss, l2=imiss)
120! define parameter temperature
121CALL init(var, centre=80, category=0, number=0, discipline=0)
122! fill gridinfo with all metadata
123CALL init(gridinfo%array(1), gaid_template, griddim, date_time, timerange, level, &
124 var, clone=.false., categoryappend='inventato')
125! here you can change the template, after cloning but before coding metadata
126! different approach than above
127CALL grib_set(grid_id_get_gaid(gridinfo%array(1)%gaid), "centre", 80)
128CALL grib_set(grid_id_get_gaid(gridinfo%array(1)%gaid), "jScansPositively", 1)
129
130! define data
131! create an unrealistic field with all different values
132DO j = 1, ny
133 DO i = 1, nx
134 field(i,j) = 200. + (i-1)*0.5 + j*15.
135 ENDDO
136ENDDO
137CALL encode_gridinfo(gridinfo%array(1), field)
138
139CALL display(gridinfo)
140CALL l4f_category_log(category,l4f_info,"export to GRIB")
141CALL export(gridinfo, filename='t2m.grib', categoryappend="gridinfo scritto")
142
143CALL l4f_category_log(category,l4f_info,"end")
144
145CALL delete(gaid_template)
146CALL delete(gridinfo)
147
148! close logger
149CALL l4f_category_delete(category)
150ier=l4f_fini()
151
152END 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.
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.