IODA Bundle
legacy_test_client_lib_fortran_local.f90
Go to the documentation of this file.
1 ! (C) Copyright 1996-2012 ECMWF.
2 !
3 ! This software is licensed under the terms of the Apache Licence Version 2.0
4 ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5 ! In applying this licence, ECMWF does not waive the privileges and immunities
6 ! granted to it by virtue of its status as an intergovernmental organisation nor
7 ! does it submit to any jurisdiction.
8 !
9 
11  use, intrinsic :: iso_c_binding
12  use odc_c_binding
13  implicit none
14 
15  integer, parameter :: max_varlen = 128
16  integer(kind=4) :: ncolumns
17 
18  write(0,*) "Calling odb_start..."
19  call odb_start()
20 
25 
26 contains
27 
28 
30  implicit none
31  type(c_ptr) :: odb_handle, odb_it
32  integer(kind=C_INT) :: cerr
33  character(kind=C_CHAR, len=64) :: config = c_null_char
34  type(c_ptr) :: ptr_colname
35  type(c_ptr) :: ptr_bitfield_names
36  type(c_ptr) :: ptr_bitfield_sizes
37  character(kind=C_CHAR), dimension(:), pointer :: f_ptr_colname
38  character(kind=C_CHAR,len=1), dimension(:), pointer :: f_ptr_bitfield_names
39  character(kind=C_CHAR,len=1), dimension(:), pointer :: f_ptr_bitfield_sizes
40  character(len=max_varlen) :: colname
41  character(len=max_varlen) :: bitfield_names
42  character(len=max_varlen) :: bitfield_sizes
43  integer(kind=4) :: i, ci
44 
45  character(kind=C_CHAR, len=2048) :: sql='select partition_number,number_of_rows from &
46  &"local://stage,class=OD,date=20151108,time=1200,type=OFB,&
47  &obsgroup=conv,reportype=16030,stream=oper,expver=qu12,&
48  &odbpathnameschema=''{date}/{time}/{reportype}.odb'',&
49  &odbserverroots=''~/data/root'',&
50  &partitionsinfo=''~/data/partitions_info.txt'',&
51  &n_parts=13,&
52  &database=localhost";'//achar(0)
53  integer(kind=C_INT) :: itype, newdataset, c_ncolumns=2, size_name
54  integer(kind=C_INT) :: bitfield_names_size, bitfield_sizes_size
55  real(kind=c_double), dimension(:), allocatable:: one_row
56  character(len=8) :: tmp_str
57 
58  write(0,*) 'example_fortran_api_stage_local: ', sql
59 
60  odb_handle = odb_select_new(config, cerr)
61  if (cerr /=0) stop 1
62 
63  odb_it = odb_select_iterator_new(odb_handle, sql, cerr);
64  if (cerr /=0) stop 2
65 
66  cerr = odb_select_get_no_of_columns(odb_it, ncolumns)
67  if (cerr /=0) stop 1
68  write(0,*) '-=-=-=-=-= example_fortran_api_stage_local: number of columns: ', ncolumns
69  if (ncolumns /= 2) stop 2
70 
71  do ci=0, ncolumns - 1
72  cerr = odb_select_get_column_name(odb_it, ci, ptr_colname, size_name)
73  if (cerr /=0) stop 1
74  call c_f_pointer(cptr=ptr_colname, fptr=f_ptr_colname, shape=(/size_name/));
75  do i=1, size_name
76  colname(i:i) = f_ptr_colname(i)
77  end do
78  write(0,*) ' : ', colname(1:i)
79  end do
80 
81  allocate(one_row(c_ncolumns))
82  cerr=0
83  i = 0
84  do
85  cerr = odb_select_get_next_row(odb_it, c_ncolumns, one_row, newdataset)
86  if ( cerr /= 0) exit
87  i = i + 1
88  enddo
89  deallocate(one_row)
90 
91  write(0,*) '-=-=-=-=-= example_fortran_api_stage_local: number of rows: ', i
92  if (i /= 13) stop 22
93 
94  cerr = odb_select_iterator_delete(odb_it)
95  cerr = odb_read_delete(odb_handle)
97 
99  implicit none
100  type(c_ptr) :: odb_handle, odb_it
101  integer(kind=C_INT) :: cerr
102  character(kind=C_CHAR, len=64) :: config = c_null_char
103  type(c_ptr) :: ptr_colname
104  type(c_ptr) :: ptr_bitfield_names
105  type(c_ptr) :: ptr_bitfield_sizes
106  character(kind=C_CHAR), dimension(:), pointer :: f_ptr_colname
107  character(kind=C_CHAR,len=1), dimension(:), pointer :: f_ptr_bitfield_names
108  character(kind=C_CHAR,len=1), dimension(:), pointer :: f_ptr_bitfield_sizes
109  character(len=max_varlen) :: colname
110  character(len=max_varlen) :: bitfield_names
111  character(len=max_varlen) :: bitfield_sizes
112  integer(kind=4) :: i, ci
113 
114  character(kind=C_CHAR, len=2048) :: sql='select * from &
115  & "local://retrieve,class=OD,date=20151108,time=1200,type=OFB,&
116  & obsgroup=conv,reportype=16030,stream=oper,expver=qu12,&
117  & odbpathnameschema=''{date}/{time}/{reportype}.odb'',&
118  & odbserverroots=''~/data/root'',&
119  & partitionsinfo=''~/data/partitions_info.txt'',&
120  & n_parts=13,&
121  & part_number=0,&
122  & database=localhost";'//achar(0)
123  integer(kind=C_INT) :: itype, newdataset, c_ncolumns=52, size_name
124  integer(kind=C_INT) :: bitfield_names_size, bitfield_sizes_size
125  real(kind=c_double), dimension(:), allocatable:: one_row
126  character(len=8) :: tmp_str
127 
128  write(0,*) 'example_fortran_api_retrieve_part_local: ', sql
129 
130  odb_handle = odb_select_new(config, cerr)
131  if (cerr /=0) stop 1
132 
133  odb_it = odb_select_iterator_new(odb_handle, sql, cerr);
134  if (cerr /=0) stop 1
135 
136  cerr = odb_select_get_no_of_columns(odb_it, ncolumns)
137  if (cerr /=0) stop 1
138  write(0,*) '-=-=-=-=-= example_fortran_api_retrieve_part_local: number of columns: ', ncolumns
139  if (c_ncolumns /= ncolumns) stop 2
140 
141  do ci=0, ncolumns - 1
142  cerr = odb_select_get_column_name(odb_it, ci, ptr_colname, size_name)
143  if (cerr /=0) stop 1
144  call c_f_pointer(cptr=ptr_colname, fptr=f_ptr_colname, shape=(/size_name/));
145  do i=1, size_name
146  colname(i:i) = f_ptr_colname(i)
147  end do
148  write(0,*) ' : ', colname(1:i)
149  end do
150 
151  allocate(one_row(c_ncolumns))
152  cerr=0
153  i = 0
154  do
155  cerr = odb_select_get_next_row(odb_it, c_ncolumns, one_row, newdataset)
156  if ( cerr /= 0) exit
157  i = i + 1
158  enddo
159  deallocate(one_row)
160 
161  write(0,*) '-=-=-=-=-= example_fortran_api_retrieve_part_local: number of rows: ', i
162  if (i /= 9938) stop 22
163 
164  cerr = odb_select_iterator_delete(odb_it)
165  cerr = odb_read_delete(odb_handle)
166 
168 
Initialize ODB API. This function must be called before any other function from the ODB API.
subroutine example_fortran_api_stage_local
program test_client_lib_fortran_local
subroutine example_fortran_api_retrieve_part_local
Provides Fortran bindings for ODB API.