libsim  Versione7.2.1
example_vg6d_3.f90

Programma esempio semplice per gridinfo e volgrid6d. Programma che importa da file un vettore di gridinfo poi lo importa in volgrid6d. Da volgrid6d viene di nuovo creato un vettore di gridinfo per poi exportare su file.

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 demo3
19 
22 use log4fortran
23 use grid_id_class
26 implicit none
27 
28 integer :: category,ier
29 character(len=512):: a_name
30 type(arrayof_gridinfo) :: gridinfoin, gridinfoout
31 type(volgrid6d),pointer :: volgrid(:)
32 
33 TYPE(grid_file_id) :: ifile
34 TYPE(grid_id) :: gaid, gaid_template
35 INTEGER :: ngrib
36 
37 !questa chiamata prende dal launcher il nome univoco
38 call l4f_launcher(a_name,a_name_force="demo3")
39 
40 !init di log4fortran
41 ier=l4f_init()
42 
43 !imposta a_name
44 category=l4f_category_get(a_name//".main")
45 
46 
47 ngrib=0
48 
49 ifile = grid_file_id_new('../data/in.grb','r')
50 ngrib = grid_file_id_count(ifile)
51 
52 call l4f_category_log(category,l4f_info,&
53  "Numero totale di grib: "//to_char(ngrib))
54 
55 ! aggiungo ngrib elementi vuoti
56 CALL insert(gridinfoin, nelem=ngrib)
57 
58 ngrib=0
59 
60 ! Loop on all the messages in a file.
61 DO WHILE (.true.)
62  gaid = grid_id_new(ifile)
63  IF (.NOT.c_e(gaid)) EXIT
64 
65  CALL l4f_category_log(category,l4f_info,"import gridinfoin")
66  ngrib = ngrib + 1
67  CALL init (gridinfoin%array(ngrib), gaid=gaid, categoryappend=trim(to_char(ngrib)))
68  CALL import(gridinfoin%array(ngrib))
69 ENDDO
70 
71 call delete(ifile)
72 call display(gridinfoin)
73 
74 call l4f_category_log(category,l4f_info,"import")
75 
76 call import(volgrid, gridinfoin, categoryappend="volume di test")
77 
78 call l4f_category_log(category,l4f_info,"delete gridinfoin")
79 
80 CALL delete(gridinfoin)
81 
82 ! qui posso fare tutti i conti possibili
83 
84 gaid_template = grid_id_new(grib_api_template="regular_ll_sfc_grib1")
85 
86 call l4f_category_log(category,l4f_info,"export a un grib fatto come voglio io")
87 
88 call export(volgrid, gridinfoout, gaid_template=gaid_template)
89 
90 ifile = grid_file_id_new('out.grb','w')
91 
92 do ngrib=1,gridinfoout%arraysize
93  ! write the new message to a file
94 
95  if(c_e(gridinfoout%array(ngrib)%gaid)) then
96  call export(gridinfoout%array(ngrib))
97  call export(gridinfoout%array(ngrib)%gaid,ifile)
98  end if
99 end do
100 
101 call delete(ifile)
102 
103 call l4f_category_log(category,l4f_info,"terminato")
104 
105 call delete(gridinfoout)
106 
107 !chiudo il logger
108 call l4f_category_delete(category)
109 ier=l4f_fini()
110 
111 end program demo3

Generated with Doxygen.