libsim  Versione8.0.0
example_vg6d_4.f90

Programma esempio semplice per la elaborazione di file grib. Programma che legge uno ad uno i grid contenuti in un file e li elabora producendo un file di output contenente ancora grib

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 program demo4
19 
21 use grid_class
23 use log4fortran
24 use grid_id_class
27 
28 implicit none
29 
30 integer :: ier
31 type(l4f_handle) :: category
32 character(len=512):: a_name,infile='../data/in.grb',outfile='out.grb'
33 type(gridinfo_def) :: gridinfo
34 type(grid_file_id) :: ifile,ofile
35 type(grid_id) :: gaid
36 
37 doubleprecision :: ilon=0.,ilat=30.,flon=30.,flat=60.
38 REAL, ALLOCATABLE :: field(:,:,:),fieldz(:,:,:)
39 type(griddim_def) :: griddim_out
40 type(transform_def) :: trans
41 type(grid_transform) :: grid_trans
42 
43 integer :: nx=30,ny=30,component_flag=0
44 doubleprecision :: xmin=0., xmax=30., ymin=30., ymax=60.
45 doubleprecision :: latitude_south_pole=-32.5,longitude_south_pole=10.,angle_rotation=0.
46 character(len=80) :: type='regular_ll',trans_type='inter',sub_type='near'
47 
48 
49 !questa chiamata prende dal launcher il nome univoco
50 call l4f_launcher(a_name,a_name_force="demo4")
51 
52 !init di log4fortran
53 ier=l4f_init()
54 
55 !imposta a_name
56 category=l4f_category_get_handle(a_name//".main")
57 
58 call l4f_category_log(category,l4f_info,"transforming from file:"//trim(infile))
59 call l4f_category_log(category,l4f_info,"transforming to file:"//trim(outfile))
60 if(trans_type == 'inter')then
61 
62  call init(griddim_out,&
63  proj_type=type,nx=nx,ny=ny, &
64  xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, component_flag=component_flag, &
65  latitude_south_pole=latitude_south_pole,longitude_south_pole=longitude_south_pole,angle_rotation=angle_rotation, &
66  categoryappend="regular_ll")
67 
68  call griddim_unproj(griddim_out)
69 
70  print*,'grid di interpolazione >>>>>>>>>>>>>>>>>>>>'
71  call display(griddim_out)
72 
73 end if
74 
75 call init(trans, trans_type=trans_type,sub_type=sub_type, &
76  ilon=ilon,ilat=ilat,flon=flon,flat=flat,&
77  categoryappend="trasformation")
78 
79 ifile = grid_file_id_new(trim(infile),'r')
80 ofile = grid_file_id_new(trim(outfile),'w')
81 
82 ! Loop on all the messages in a file.
83 DO WHILE (.true.)
84  gaid = grid_id_new(ifile)
85  IF (.NOT.c_e(gaid)) EXIT
86 
87  call l4f_category_log(category,l4f_info,"import gridinfo")
88 
89  call init (gridinfo,gaid=gaid,categoryappend="importato")
90  call import(gridinfo)
91 
92  call display(gridinfo,namespace="")
93 
94  call l4f_category_log(category,l4f_info,"import")
95 
96  ALLOCATE (field(gridinfo%griddim%dim%nx,gridinfo%griddim%dim%ny,1))
97 
98  field(:,:,1)=decode_gridinfo(gridinfo)
99 
100  call init(grid_trans, trans, in=gridinfo%griddim,out=griddim_out,categoryappend="gridtrasformato")
101 
102  call display(griddim_out)
103 
104  ALLOCATE (fieldz(griddim_out%dim%nx,griddim_out%dim%ny,1))
105 
106  call compute(grid_trans, field, fieldz)
107 
108  call delete(gridinfo%griddim)
109  call copy(griddim_out,gridinfo%griddim,categoryappend="clonato")
110 
111 ! oppure per mantenere il vecchio gridinfo
112 ! call clone(gridinfo , gridinfo_out)
113 ! call delete(gridinfo_out%griddim)
114 ! call copy(griddim_out,gridinfo_out%griddim)
115 
116  call encode_gridinfo(gridinfo,fieldz(:,:,1))
117  call export (gridinfo)
118  call display(gridinfo,namespace="")
119 
120  call export(gridinfo%gaid,ofile)
121 
122  call delete (grid_trans)
123  call delete (gridinfo)
124  deallocate (field,fieldz)
125 
126 end do
127 
128 call delete (trans)
129 call delete(griddim_out)
130 
131 call delete(ifile)
132 call delete(ofile)
133 
134 call l4f_category_log(category,l4f_info,"terminato")
135 
136 !chiudo il logger
137 call l4f_category_delete(category)
138 ier=l4f_fini()
139 
140 end program demo4
141 

Generated with Doxygen.