libsim  Versione8.0.0
dballe_test.F03
1 #include "config.h"
2 
3 program dballe_test
4 
5 use dballe_class
7 use log4fortran
8 implicit none
9 
10 type(dbasession) :: session, sessionfrom,sessionto
11 type(dbaconnection) :: connection ,connectionfrom
12 TYPE(l4f_handle) :: category
13 INTEGER :: ier
14 CHARACTER(len=512) :: a_name
15 
16 !questa chiamata prende dal launcher il nome univoco
17 call l4f_launcher(a_name,a_name_force="dballe_test")
18 !init di log4fortran
19 ier=l4f_init()
20 !imposta a_name
21 category=l4f_category_get_handle(trim(a_name)//".main")
22 
23 ! connect to dsn type DBA
24 connection=dbaconnection(dsn="sqlite:dballe_test.sqlite?wipe=true")
25 session=dbasession(connection,wipe=.true.,write=.true.)!,anaflag="write", dataflag="write", attrflag="write")
26 call write1() ! write etherogeneous ensamble of data with attributes and constant data using macro object
27 call write2() ! write an omogeneous vector of data
28 call write3() ! write an etherogeneous ensamble of data
29 call write4() ! write an etherogeneous ensamble of data and attributes
30 call delete1() ! delete one var from the entire DB
31 call delete2() ! delete one var only where are some defined metadati
32 call delete3() ! delete some attributes from one var only where are some defined metadati
33 
34 # ifndef F2003_FULL_FEATURES
35 !close everythings
36 call session%delete()
37 call connection%delete()
38 #endif
39 
40 ! connect to dsn type BUFR file for write
41 session=dbasession(filename="dballe_test.bufr",wipe=.true.,write=.true.,memdb=.false.)
42 call write0() ! write ana on file
43 call write1() ! write etherogeneous ensamble of data with attributes and constant data using macro object
44 call write2() ! write an omogeneous vector of data
45 call write3() ! write an etherogeneous ensamble of data
46 call write4() ! write an etherogeneous ensamble of data and attributes
47 
48 # ifndef F2003_FULL_FEATURES
49 !close everythings
50 call session%delete()
51 #endif
52 
53 ! connect to dsn type BUFR file for read
54 sessionfrom=dbasession(filename="dballe_test.bufr",memdb=.false.)
55 ! connect to dsn type BUFR file for write
56 sessionto=dbasession(filename="dballe_test_copy1f.bufr",wipe=.true.,write=.true.,memdb=.false.)
57 call copy1f() ! copy data and attributes of everythings to an other file
58 
59 # ifndef F2003_FULL_FEATURES
60 !close everythings
61 call sessionto%delete()
62 call sessionfrom%delete()
63 #endif
64 
65 ! use memdb
66 ! connect to dsn type DBA
67 connectionfrom=dbaconnection(dsn="mem:")
68 sessionfrom=dbasession(connectionfrom,wipe=.true.,write=.true.)!,anaflag="write", dataflag="write", attrflag="write")
69 call sessionfrom%messages_open_input(filename="dballe_test.bufr",mode="r",format="BUFR",simplified=.true.)
70 ! connect to dsn type BUFR file for write
71 sessionto=dbasession(filename="dballe_test_copy1fmem.bufr",wipe=.true.,write=.true.,memdb=.false.)
72 call copy1fmem() ! copy data and attributes of everythings to an other file
73 
74 # ifndef F2003_FULL_FEATURES
75 !close everythings
76 call sessionfrom%delete()
77 call connectionfrom%delete()
78 call sessionto%delete()
79 #endif
80 
81 !chiudo il logger
82 CALL l4f_category_delete(category)
83 ier=l4f_fini()
84 
85 contains
86 
87 subroutine write0()
88 
89 type(dbasession) :: sessionana
90 type(dbaanalist) :: anal
91 type(dbaana) :: ana
92 logical :: status
93 
94 ! connect to dsn type BUFR file for write
95 sessionana=dbasession(filename="dballe_test_ana.bufr",wipe=.true.,write=.true.,memdb=.false.)
96 
97 
98 call anal%append(dbaana(lon=11.d0,lat=45.d0))
99 call anal%append(dbaana(lon=12.d0,lat=45.d0))
100 call anal%append(dbaana(lon=13.d0,lat=45.d0))
101 
102 call anal%display()
103 
104 call anal%rewind()
105 !extrude ana
106 do while (anal%element())
107  !call sessionana%extrude(ana=anal%current())
108  ana=anal%current()
109  call ana%extrude(sessionana)
110  call anal%next()
111 end do
112 
113 # ifndef F2003_FULL_FEATURES
114 call sessionana%delete()
115 #endif
116 
117 status=anal%delete()
118 
119 end subroutine write0
120 
121 
122 subroutine write1()
123 
124 type(dbametaanddata),allocatable :: metaanddata(:)
125 type(dbadcv) :: attrv
126 integer :: i
127 
128 print *,"----------------------------------------------"
129 print *,"--------------- write1 ------------------------"
130 
131 allocate(metaanddata(2)) ! one metadata for data and one for constant data
132 
133 metaanddata(1)%metadata=dbametadata( &
134  level=dbalevel(level1=105, l1=2000) &
135  ,timerange=dbatimerange(timerange=4, p1=3600,p2=7200) &
136  ,ana=dbaana(lon=10.d0,lat=45.d0) &
137  ,network=dbanetwork("generic") &
138  ,datetime=dbadatetime(datetime_new(2014,01,06,18,00)))
139 
140 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
141 ! create an etherogeneous ensamble of data
142 allocate (metaanddata(1)%dataattrv%dataattr(2))
143 
144 ! first data
145 allocate (metaanddata(1)%dataattrv%dataattr(1)%dat,source=dbadatai("B13003",85))
146 
147 ! create an etherogeneous ensamble of attr
148 allocate (attrv%dcv(3))
149 allocate (attrv%dcv(1)%dat,source=dbadatar("*B33192",30.))
150 allocate (attrv%dcv(2)%dat,source=dbadatai("*B33193",50))
151 allocate (attrv%dcv(3)%dat,source=dbadatar("*B33194",70.))
152 !assemble data and attribute
153 metaanddata(1)%dataattrv%dataattr(1)%attrv=attrv
154 
155 ! second data
156 allocate (metaanddata(1)%dataattrv%dataattr(2)%dat,source=dbadatai("B12101",27315))
157 ! create an etherogeneous ensamble of attr
158 deallocate(attrv%dcv)
159 allocate (attrv%dcv(2))
160 allocate (attrv%dcv(1)%dat,source=dbadatar("*B33192",30.))
161 allocate (attrv%dcv(2)%dat,source=dbadatai("*B33193",50))
162 !assemble data and attribute
163 metaanddata(1)%dataattrv%dataattr(2)%attrv=attrv
164 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
165 
166 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
167 ! station costant data
168 ! copy the same metadata setting that here we have constant in time data
169 metaanddata(2)%metadata=metaanddata(1)%metadata%dbacontextana()
170 ! create an etherogeneous ensamble of data
171 allocate (metaanddata(2)%dataattrv%dataattr(2))
172 allocate (metaanddata(2)%dataattrv%dataattr(1)%dat,source=dbadatai("B07030",223))
173 allocate (metaanddata(2)%dataattrv%dataattr(1)%attrv%dcv(0)) ! we do not want attributes
174 allocate (metaanddata(2)%dataattrv%dataattr(2)%dat,source=dbadatac("B01019","My beautifull station"))
175 allocate (metaanddata(2)%dataattrv%dataattr(2)%attrv%dcv(0)) ! we do not want attributes
176 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
177 
178 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
179 ! display and save everythings
180 do i=1,size(metaanddata)
181  call metaanddata(i)%display()
182  !call session%extrude(metaanddata=metaanddata(i))
183  call metaanddata(i)%extrude(session)
184 end do
185 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
186 
187 end subroutine write1
188 
189 
190 subroutine write2()
191 
192 type(dbadatar),allocatable :: data(:)
193 
194 type(dbalevel) :: level
195 type(dbatimerange) :: timerange
196 type(dbaana) :: ana
197 type(dbanetwork) :: network
198 type(dbadatetime) :: datetime
199 integer :: i
200 
201 print *,"----------------------------------------------"
202 print *,"--------------- write2 ------------------------"
203 
204 
205 !clear the dballe session
206 call session%unsetall()
207 
208 ! set and display metadata
209 level=dbalevel(level1=105, l1=2000)
210 call level%display()
211 timerange=dbatimerange(timerange=4, p1=3600,p2=7200)
212 call timerange%display()
213 !ana=dbaana(coord=dbacoord(ilon=1000000,ilat=4500000))
214 ana=dbaana(lon=11.d0,lat=45.d0)
215 call ana%display()
216 network=dbanetwork("generic")
217 call network%display()
218 datetime=dbadatetime(datetime_new(2014,01,06,18,00))
219 call datetime%display()
220 
221 ! can set metadata step by step
222 call session%set(level=level)
223 call session%set(timerange=timerange)
224 call session%set(ana=ana)
225 call session%set(network=network)
226 call session%set(datetime=datetime)
227 
228 ! I can use the reverse vision step by step
229 !call level%dbaset(session)
230 !call timerange%dbaset(session)
231 !call ana%dbaset(session)
232 !call network%dbaset(session)
233 !call datetime%dbaset(session)
234 
235 ! create an omogeneous vector of data
236 allocate (data(2),source=[dbadatar("B12102",265.33),dbadatar("B12101",273.15)])
237 
238 !set and display omogeneous data
239 do i =1,size(data)
240  call data(i)%display()
241  call session%set(data=data(i))
242  !call data(i)%dbaset(session)
243 end do
244 
245 !write it in dsn or file
246 call session%prendilo()
247 !!$session%enq(metadata)
248 
249 !close message if I am writing on file
250 call session%close_message()
251 
252 
253 end subroutine write2
254 
255 
256 subroutine write3()
257 
258 type(dbametadata) :: metadata
259 type(dbadcv) :: datav
260 type(dbalevel) :: level
261 type(dbatimerange) :: timerange
262 type(dbaana) :: ana
263 type(dbanetwork) :: network
264 type(dbadatetime) :: datetime
265 
266 print *,"----------------------------------------------"
267 print *,"--------------- write3 ------------------------"
268 
269 
270 !clear the dballe session
271 call session%unsetall()
272 
273 ! set metadata
274 level=dbalevel(level1=105, l1=2000)
275 timerange=dbatimerange(timerange=4, p1=3600,p2=7200)
276 ana=dbaana(lon=12.d0,lat=45.d0)
277 network=dbanetwork("generic")
278 datetime=dbadatetime(datetime_new(2014,01,06,18,00))
279 
280 !assemble metadata
281 metadata=dbametadata(level=level,timerange=timerange,ana=ana,network=network,datetime=datetime)
282 call metadata%display()
283 
284 ! I can set metadata one shot
285 call session%set(metadata)
286 ! or in the reverse vision
287 !call metadata%dbaset(session)
288 
289 call metadata%display()
290 
291 ! create and display an etherogeneous ensamble of data
292 allocate (datav%dcv(2))
293 allocate (datav%dcv(1)%dat,source=dbadatai("B12102",26312))
294 allocate (datav%dcv(2)%dat,source=dbadatar("B12101",273.15))
295 call datav%display()
296 !set data
297 call session%set(datav=datav)
298 
299 ! or in the reverse vision
300 !call datav%dbaset(session)
301 
302 !write it in dsn
303 call session%prendilo()
304 !!$session%enq(metadata)
305 
306 !close message if I am writing on file
307 call session%close_message()
308 
309 end subroutine write3
310 
311 
312 subroutine write4()
313 
314 type(dbametadata) :: metadata
315 type(dbadataattrv) :: dataattrv
316 type(dbadcv) :: attrv
317 type(dbadcv) :: datav
318 
319 print *,"----------------------------------------------"
320 print *,"--------------- write4 ------------------------"
321 
322 ! clear the dballe session
323 call session%unsetall()
324 
325 ! define metadata
326 metadata=dbametadata( &
327  level=dbalevel(level1=105, l1=2000) &
328  ,timerange=dbatimerange(timerange=4, p1=3600,p2=7200) &
329  ,ana=dbaana(lon=13.d0,lat=45.d0) &
330  ,network=dbanetwork("generic") &
331  ,datetime=dbadatetime(datetime_new(2014,01,06,18,00)))
332 
333 call session%set(metadata)
334 
335 ! create and display an etherogeneous ensamble of data
336 allocate (datav%dcv(2))
337 allocate (datav%dcv(1)%dat,source=dbadatai("B12102",26312))
338 allocate (datav%dcv(2)%dat,source=dbadatar("B12101",273.15))
339 
340 ! create and display an etherogeneous ensamble of attr
341 allocate (attrv%dcv(3))
342 allocate (attrv%dcv(1)%dat,source=dbadatai("*B33192",30))
343 allocate (attrv%dcv(2)%dat,source=dbadatac("*B33193","70"))
344 allocate (attrv%dcv(3)%dat,source=dbadatad("*B33194",50.d0))
345 call attrv%display()
346 
347 ! assemble data and attribute
348 allocate (dataattrv%dataattr(2))
349 ! first with attribute
350 allocate (dataattrv%dataattr(1)%dat,source=datav%dcv(1)%dat)
351 dataattrv%dataattr(1)%attrv=attrv
352 ! second without attribute
353 allocate (dataattrv%dataattr(2)%dat,source=datav%dcv(2)%dat)
354 allocate (dataattrv%dataattr(2)%attrv%dcv(0))
355 
356 call dataattrv%display()
357 
358 ! write data and attribute
359 !call session%extrude(dataattrv=dataattrv)
360 call dataattrv%extrude(session)
361 
362 ! work on constant station data
363 call session%set(metadata%dbacontextana())
364 
365 ! write the same data and attribute as constant station data
366 !call session%extrude(dataattrv=dataattrv)
367 call dataattrv%extrude(session)
368 
369 end subroutine write4
370 
371 
372 subroutine delete1()
373 
374 type(dbafilter) :: filter
375 
376 print *,"----------------------------------------------"
377 print *,"--------------- delete1 ----------------------"
378 
379 filter=dbafilter(var="B12101")
380 call session%set(filter=filter)
381 call session%dissolve()
382 
383 end subroutine delete1
384 
385 
386 subroutine delete2()
387 
388 type(dbametadata),allocatable :: metadata(:)
389 type(dbafilter) :: filter
390 
391 print *,"----------------------------------------------"
392 print *,"--------------- delete2 ----------------------"
393 
394 
395 allocate(metadata(1))
396 
397 metadata(1)=dbametadata( &
398  level=dbalevel(level1=105, l1=2000) &
399  ,timerange=dbatimerange(timerange=4, p1=3600,p2=7200) &
400  ,ana=dbaana(lon=11.d0,lat=45.d0) &
401  ,network=dbanetwork("generic") &
402  ,datetime=dbadatetime(datetime_new(2014,01,06,18,00)))
403 
404 
405 filter=dbafilter(var="B12102")
406 call session%set(filter=filter)
407 call session%dissolve(metadata)
408 
409 deallocate(metadata)
410 
411 end subroutine delete2
412 
413 
414 
415 subroutine delete3()
416 
417 type(dbametadata),allocatable :: metadata(:)
418 type(dbafilter) :: filter
419 
420 print *,"----------------------------------------------"
421 print *,"--------------- delete3 ----------------------"
422 
423 
424 allocate(metadata(1))
425 
426 metadata(1)=dbametadata( &
427  level=dbalevel(level1=105, l1=2000) &
428  ,timerange=dbatimerange(timerange=4, p1=3600,p2=7200) &
429  ,ana=dbaana(lon=13.d0,lat=45.d0) &
430  ,network=dbanetwork("generic") &
431  ,datetime=dbadatetime(datetime_new(2014,01,06,18,00)))
432 
433 filter=dbafilter(var="B12102",starvarlist="*B33194,*B33193")
434 call session%set(filter=filter)
435 call session%dissolveattr(metadata)
436 
437 deallocate(metadata)
438 
439 end subroutine delete3
440 
441 
442 subroutine copy1f()
443 type(dbametaanddata), allocatable:: metaanddatav(:)
444 integer :: i
445 
446 print *,"----------------------------------------------"
447 print *,"--------------- copy1f ----------------------"
448 
449 ! data
450 call sessionfrom%filerewind()
451 
452 call sessionfrom%set(filter=dbafilter())
453 call sessionfrom%ingest(metaanddatav)
454 do while (size(metaanddatav) >0)
455  print*,"read/write data; count: ",sessionfrom%count
456  do i =1,size(metaanddatav)
457  print *, "display metaanddatav index: ", i
458 ! call metaanddatav(i)%display()
459  !call sessionto%extrude(metaanddata=metaanddatav(i))
460  call metaanddatav(i)%extrude(sessionto)
461  end do
462 ! call sessionto%close_message()
463  call sessionfrom%ingest(metaanddatav)
464 end do
465 deallocate (metaanddatav)
466 
467 ! constant data
468 call sessionfrom%filerewind()
469 
470 call sessionfrom%set(filter=dbafilter(contextana=.true.))
471 call sessionfrom%ingest(metaanddatav)
472 do while (size(metaanddatav) >0)
473  print*,"read/write data; count: ",sessionfrom%count
474  do i =1,size(metaanddatav)
475  print *, "display metaanddatav index: ", i
476 ! call metaanddatav(i)%display()
477  !call sessionto%extrude(metaanddata=metaanddatav(i))
478  call metaanddatav(i)%extrude(sessionto)
479  end do
480 ! call sessionto%close_message()
481  call sessionfrom%ingest(metaanddatav)
482 end do
483 
484 end subroutine copy1f
485 
486 
487 subroutine copy1fmem()
488 type(dbametaanddata),allocatable :: metaanddatav(:)
489 
490 print *,"----------------------------------------------"
491 print *,"--------------- copy1fmem ----------------------"
492 
493 
494 do while (sessionfrom%messages_read_next())
495 !!$ print*,"read/write message"
496 !!$ call sessionfrom%set(filter=dbafilter())
497 !!$ call sessionfrom%ingest(metaanddatav)
498 !!$ do i =1,size(metaanddatav)
499 !!$ call metaanddatav(i)%display()
500 !!$ call sessionto%extrude(metaanddata=metaanddatav(i))
501 !!$ end do
502 !!$ call sessionto%prendilo()
503 
504  print *,"contextana"
505  call sessionfrom%set(filter=dbafilter(contextana=.true.))
506  call sessionfrom%ingest(metaanddatav)
507 !!$ do i =1,size(metaanddatav)
508 !!$ call metaanddatav(i)%display()
509 !!$ call sessionto%extrude(metaanddata=metaanddatav(i))
510 !!$ end do
511 !!$ call sessionto%close_message()
512  call sessionfrom%remove_all()
513 end do
514 
515 end subroutine copy1fmem
516 
517 end program dballe_test
Class for expressing an absolute time value.
datetime metadata
Classi per la gestione delle coordinate temporali.
manage session handle
character version for dbadata
summ of all metadata pieces
doubleprecision version for dbadata
filter to apply before ingest data
Global log4fortran destructor.
manage connection handle to a DSN
integer version for dbadata
class for import and export data from e to DB-All.e.
classe per la gestione del logging
Global log4fortran constructor.
timerange metadata
real version for dbadata

Generated with Doxygen.