44 function c_f_string(c_str) result(f_str)
45 character(kind=c_char,len=1),
intent(in) :: c_str(*)
46 character(len=:),
allocatable :: f_str
50 do while (c_str(nchars) /= c_null_char)
55 allocate(
character(len=nchars) :: f_str)
56 f_str = transfer(c_str(1:nchars), f_str)
57 end function c_f_string
69 subroutine copy_f_c_str(f_str, c_str, c_str_len)
70 character(len=*),
target,
intent(in) :: f_str
71 character(kind=c_char, len=1),
intent(inout) :: c_str(*)
72 integer,
intent(in) :: c_str_len
73 integer :: max_str_len
75 if (c_str_len /= 0)
then
76 max_str_len = min(c_str_len, len_trim(f_str) + 1)
77 c_str(1)(1:max_str_len) = f_str(1:max_str_len)
78 c_str(1)(max_str_len:max_str_len) = c_null_char
80 end subroutine copy_f_c_str
93 subroutine open_c(lunit, filepath) bind(C, name='open_f')
94 integer(c_int), value,
intent(in) :: lunit
95 character(kind=c_char, len=1) :: filepath
97 open(lunit, file=c_f_string(filepath))
109 subroutine close_c(lunit) bind(C, name='close_f')
110 integer(c_int), value,
intent(in) :: lunit
125 subroutine openbf_c(bufr_unit, cio, table_file_id) bind(C, name='openbf_f')
126 integer(c_int), value,
intent(in) :: bufr_unit
127 character(kind=c_char, len=1),
intent(in) :: cio
128 integer(c_int), value,
intent(in) :: table_file_id
130 call
openbf(bufr_unit, c_f_string(cio), table_file_id)
141 subroutine closbf_c(bufr_unit) bind(C, name='closbf_f')
142 integer(c_int), value,
intent(in) :: bufr_unit
169 function ireadmg_c(bufr_unit, c_subset, iddate, subset_str_len) result(ires) bind(C, name='ireadmg_f')
170 integer(c_int), value,
intent(in) :: bufr_unit
171 character(kind=c_char, len=1),
intent(inout) :: c_subset(*)
172 integer(c_int),
intent(out) :: iddate
173 integer(c_int), value,
intent(in) :: subset_str_len
174 integer(c_int) :: ires
175 character(len=25) :: f_subset
178 ires =
ireadmg(bufr_unit, f_subset, iddate)
179 call copy_f_c_str(f_subset, c_subset, int(subset_str_len))
190 function ireadsb_c(bufr_unit) result(ires) bind(C, name='ireadsb_f')
191 integer(c_int), value,
intent(in) :: bufr_unit
192 integer(c_int) :: ires
210 subroutine ufbint_c(bufr_unit, c_data, dim_1, dim_2, iret, table_b_mnemonic) bind(C, name='ufbint_f')
211 integer(c_int), value,
intent(in) :: bufr_unit
212 type(c_ptr
),
intent(inout) :: c_data
213 integer(c_int), value,
intent(in) :: dim_1, dim_2
214 integer(c_int),
intent(out) :: iret
215 character(kind=c_char, len=1),
intent(in) :: table_b_mnemonic
216 real,
pointer :: f_data
218 call c_f_pointer(c_data, f_data)
219 call
ufbint(bufr_unit, f_data, dim_1, dim_2, iret, c_f_string(table_b_mnemonic))
234 subroutine ufbrep_c(bufr_unit, c_data, dim_1, dim_2, iret, table_b_mnemonic) bind(C, name='ufbrep_f')
235 integer(c_int), value,
intent(in) :: bufr_unit
236 type(c_ptr
),
intent(inout) :: c_data
237 integer(c_int), value,
intent(in) :: dim_1, dim_2
238 integer(c_int),
intent(out) :: iret
239 character(kind=c_char, len=1),
intent(in) :: table_b_mnemonic
240 real,
pointer :: f_data
242 call c_f_pointer(c_data, f_data)
243 call
ufbrep(bufr_unit, f_data, dim_1, dim_2, iret, c_f_string(table_b_mnemonic))
256 subroutine mtinfo_c(path, file_unit_1, file_unit_2) bind(C, name='mtinfo_f')
257 character(kind=c_char, len=1),
intent(in) :: path
258 integer(c_int), value,
intent(in) :: file_unit_1
259 integer(c_int), value,
intent(in) :: file_unit_2
261 call
mtinfo(c_f_string(path), file_unit_1, file_unit_2)
subroutine, public exitbufr_c()
Wraps BUFRLIB "exitbufr" subroutine. Closes all open file units used by BUFRLIB.
function ireadmg(LUNIT, SUBSET, IDATE)
This function calls BUFRLIB subroutine readmg() and passes back its return code as the function value...
subroutine, public open_c(lunit, filepath)
Wraps fortran "open" statement so we can open a Fortran file from a C program.
function ireadsb(LUNIT)
This function calls BUFRLIB subroutine readsb() and passes back its return code as the function value...
subroutine ufbrep(LUNIN, USR, I1, I2, IRET, STR)
This subroutine reads or writes one or more data values from or to the BUFR data subset that is curre...
subroutine, public openbf_c(bufr_unit, cio, table_file_id)
Wraps BUFRLIB "openbf" subroutine.
subroutine, public ufbint_c(bufr_unit, c_data, dim_1, dim_2, iret, table_b_mnemonic)
Wraps BUFRLIB "ufbint" function.
subroutine mtinfo(CMTDIR, LUNMT1, LUNMT2)
This subroutine allows the specification of the directory location and Fortran logical unit numbers t...
subroutine closbf(LUNIT)
This subroutine closes the connection between logical unit LUNIT and the BUFRLIB software.
subroutine openbf(LUNIT, IO, LUNDX)
This subroutine connects a new file to the BUFRLIB software for input or output operations.
integer(c_int) function, public ireadsb_c(bufr_unit)
Wraps BUFRLIB "ireadsb" function.
subroutine, public ufbrep_c(bufr_unit, c_data, dim_1, dim_2, iret, table_b_mnemonic)
Wraps BUFRLIB "ufbrep" function.
subroutine ufbint(LUNIN, USR, I1, I2, IRET, STR)
This subroutine reads or writes one or more data values from or to the BUFR data subset that is curre...
subroutine, public closbf_c(bufr_unit)
Wraps BUFRLIB "closbf" subroutine.
subroutine exitbufr
This subroutine frees all dynamically-allocated memory, closes all logical units that are open within...
subroutine, public mtinfo_c(path, file_unit_1, file_unit_2)
Wraps BUFRLIB "mtinfo" function.
This module contains functions which wrap certain Fortran BUFRLIB functions so they can be called fro...
integer(c_int) function, public ireadmg_c(bufr_unit, c_subset, iddate, subset_str_len)
Wraps BUFRLIB "ireadmg" subroutine.
subroutine, public close_c(lunit)
Wraps fortran "close" statement so we can close a Fortran file from a C program.