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

Generated with Doxygen.