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

Generated with Doxygen.