File: querydata.F90

package info (click to toggle)
odb-api 0.18.1-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 26,452 kB
  • sloc: cpp: 115,083; ansic: 86,859; f90: 30,318; sql: 12,508; sh: 9,939; yacc: 3,680; python: 2,432; lex: 1,593; perl: 1,116; fortran: 341; csh: 214; makefile: 111; lisp: 17
file content (47 lines) | stat: -rw-r--r-- 1,621 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
PROGRAM querydata
!*** querydata.F90 ***
USE odb_module
implicit none
REAL(8), ALLOCATABLE :: x(:,:)
INTEGER(4) :: myproc,nproc,npools,jp,h
INTEGER(4) :: nrows, ncols, nra, rc
INTEGER(4) :: numargs, iargc, jque, jr, jc, nc
character(len=64) dbname, queryname
character(len=64), allocatable :: colnames(:)
rc = ODB_init(myproc=myproc,nproc=nproc)
numargs = iargc()
if (numargs < 1) then
  CALL ODB_abort('querydata',&
  'Usage: querydata DBname [query1 [query2] ...]',numargs)
endif
CALL getarg(1,dbname)    ! Database name
do jque=2,numargs
  CALL getarg(jque,queryname) ! Query name
  npools = 0 ! Gets true value from ODB_open()
  h = ODB_open(dbname,'READONLY',npools)
  write(*,*)'Exec query#',jque-1,'="'//trim(queryname)//'"'
  rc = ODB_addview(h,queryname) ! Not necessary anymore
  nc = ODB_getnames(h,queryname,'name')
  ALLOCATE(colnames(nc))
  nc = ODB_getnames(h,queryname,'name',colnames)
  do jp=myproc,npools,nproc ! Round-robin, "my" pools only
    rc = ODB_select(h,queryname,nrows,ncols,nra=nra,poolno=jp)
    if (nrows > 0) then
      ALLOCATE(x(nra,0:ncols))
      rc = ODB_get(h,queryname,x,nrows,ncols,poolno=jp)
      write(*,'((3a20))') (trim(colnames(jc)),jc=1,nc)
      do jr=1,nrows
        write(*,'(1p,(5x,3(1x,g20.10)))') x(jr,1:ncols)
      enddo
      DEALLOCATE(x)
    endif
    rc = ODB_cancel(h,queryname,poolno=jp)
    ! The following is the same as the less preferred
    ! rc = ODB_swapout(h,'*',poolno=jp)
    rc = ODB_release(h,poolno=jp)
  enddo ! do jp=myproc,npools,nproc
  DEALLOCATE(colnames)
  rc = ODB_close(h)
enddo ! do jque=2,numargs
rc = ODB_end()
END PROGRAM querydata