NCEPLIBS-bufr  12.3.0
tankrcpt.F90
Go to the documentation of this file.
1 
4 
23 recursive subroutine atrcpt(msgin,lmsgot,msgot)
24 
25  use bufrlib
26 
27  use modv_vars, only: im8b, nbytw
28 
29  use moda_tnkrcp
30 
31  implicit none
32 
33  integer, intent(in) :: msgin(*), lmsgot
34  integer, intent(out) :: msgot(*)
35  integer my_lmsgot, len0, len1, l2, l3, l4, l5, iad1, iad2, lenm, lenmot, len1ot, ibit, iupbs01, bort_target_set
36 
37  ! Check for I8 integers.
38 
39  if(im8b) then
40  im8b=.false.
41  call x84(lmsgot, my_lmsgot, 1)
42  call atrcpt(msgin, my_lmsgot*2, msgot)
43  im8b=.true.
44  return
45  endif
46 
47  ! If we're catching bort errors, set a target return location if one doesn't already exist.
48 
49  if (bort_target_set() == 1) then
50  call catch_bort_atrcpt_c(msgin,lmsgot,msgot)
52  return
53  endif
54 
55  ! Get some section lengths and addresses from the input message.
56 
57  call getlens(msgin,1,len0,len1,l2,l3,l4,l5)
58 
59  iad1 = len0
60  iad2 = iad1 + len1
61 
62  lenm = iupbs01(msgin,'LENM')
63 
64  ! Check for overflow of the output array. Note that the new message will be 6 bytes longer than the input message.
65 
66  lenmot = lenm + 6
67  if(lenmot>(lmsgot*nbytw)) &
68  call bort('BUFRLIB: ATRCPT - OVERFLOW OF OUTPUT MESSAGE ARRAY; TRY A LARGER DIMENSION FOR THIS ARRAY')
69 
70  len1ot = len1 + 6
71 
72  ! Write Section 0 of the new message into the output array.
73 
74  call mvb ( msgin, 1, msgot, 1, 4 )
75  ibit = 32
76  call pkb ( lenmot, 24, msgot, ibit )
77  call mvb ( msgin, 8, msgot, 8, 1 )
78 
79  ! Store the length of the new Section 1.
80 
81  ibit = iad1*8
82  call pkb ( len1ot, 24, msgot, ibit )
83 
84  ! Copy the remainder of Section 1 from the input array to the output array.
85 
86  call mvb ( msgin, iad1+4, msgot, (ibit/8)+1, len1-3 )
87 
88  ! Append the tank receipt time data to the new Section 1.
89 
90  ibit = iad2*8
91  call pkb ( itryr, 16, msgot, ibit )
92  call pkb ( itrmo, 8, msgot, ibit )
93  call pkb ( itrdy, 8, msgot, ibit )
94  call pkb ( itrhr, 8, msgot, ibit )
95  call pkb ( itrmi, 8, msgot, ibit )
96 
97  ! Copy Sections 2, 3, 4 and 5 from the input array to the output array.
98 
99  call mvb ( msgin, iad2+1, msgot, (ibit/8)+1, lenm-iad2 )
100 
101  return
102 end subroutine atrcpt
103 
121 recursive subroutine rtrcptb(mbay,iyr,imo,idy,ihr,imi,iret)
122 
123  use modv_vars, only: im8b
124 
125  implicit none
126 
127  integer, intent(in) :: mbay(*)
128  integer, intent(out) :: iyr, imo, idy, ihr, imi, iret
129  integer is1byt, imgbyt, iupbs01, iupb
130 
131  ! Check for I8 integers.
132 
133  if(im8b) then
134  im8b=.false.
135  call rtrcptb(mbay,iyr,imo,idy,ihr,imi,iret)
136  call x48(iyr,iyr,1)
137  call x48(imo,imo,1)
138  call x48(idy,idy,1)
139  call x48(ihr,ihr,1)
140  call x48(imi,imi,1)
141  call x48(iret,iret,1)
142  im8b=.true.
143  return
144  endif
145 
146  iret = -1
147 
148  ! Check whether the message contains a tank receipt time.
149 
150  if(iupbs01(mbay,'BEN')==4) then
151  is1byt = 23
152  else
153  is1byt = 19
154  endif
155  if( (is1byt+5) > iupbs01(mbay,'LEN1') ) return
156 
157  ! Unpack the tank receipt time.
158 
159  ! Note that is1byt is a starting byte number relative to the beginning of Section 1, so we still need to account for
160  ! Section 0 when specifying the actual byte numbers to unpack within the overall message.
161 
162  imgbyt = is1byt + iupbs01(mbay,'LEN0')
163 
164  iyr = iupb(mbay,imgbyt,16)
165  imo = iupb(mbay,imgbyt+2,8)
166  idy = iupb(mbay,imgbyt+3,8)
167  ihr = iupb(mbay,imgbyt+4,8)
168  imi = iupb(mbay,imgbyt+5,8)
169 
170  iret = 0
171 
172  return
173 end subroutine rtrcptb
174 
192 recursive subroutine rtrcpt(lunit,iyr,imo,idy,ihr,imi,iret)
193 
194  use bufrlib
195 
196  use modv_vars, only: im8b
197 
198  use moda_bitbuf
199 
200  implicit none
201 
202  integer, intent(in) :: lunit
203  integer, intent(out) :: iyr, imo, idy, ihr, imi, iret
204  integer my_lunit, lun, il, im, bort_target_set
205 
206  ! Check for I8 integers.
207 
208  if(im8b) then
209  im8b=.false.
210  call x84(lunit,my_lunit,1)
211  call rtrcpt(my_lunit,iyr,imo,idy,ihr,imi,iret)
212  call x48(iyr,iyr,1)
213  call x48(imo,imo,1)
214  call x48(idy,idy,1)
215  call x48(ihr,ihr,1)
216  call x48(imi,imi,1)
217  call x48(iret,iret,1)
218  im8b=.true.
219  return
220  endif
221 
222  ! If we're catching bort errors, set a target return location if one doesn't already exist.
223 
224  if (bort_target_set() == 1) then
225  call catch_bort_rtrcpt_c(lunit,iyr,imo,idy,ihr,imi,iret)
226  call bort_target_unset
227  return
228  endif
229 
230  ! Check the file status.
231 
232  call status(lunit,lun,il,im)
233  if(il==0) call bort('BUFRLIB: RTRCPT - INPUT BUFR FILE IS CLOSED; IT MUST BE OPEN FOR INPUT')
234  if(il>0) call bort('BUFRLIB: RTRCPT - INPUT BUFR FILE IS OPEN FOR OUTPUT; IT MUST BE OPEN FOR INPUT')
235  if(im==0) call bort('BUFRLIB: RTRCPT - A MESSAGE MUST BE OPEN IN INPUT BUFR FILE; NONE ARE')
236 
237  ! Unpack the tank receipt time.
238 
239  call rtrcptb(mbay(1,lun),iyr,imo,idy,ihr,imi,iret)
240 
241  return
242 end subroutine rtrcpt
243 
271 recursive subroutine strcpt(cf,iyr,imo,idy,ihr,imi)
272 
273  use bufrlib
274 
275  use modv_vars, only: im8b
276 
277  use moda_tnkrcp
278 
279  implicit none
280 
281  character, intent(in) :: cf
282  character*128 bort_str
283  character my_cf
284 
285  integer, intent(in) :: iyr, imo, idy, ihr, imi
286  integer my_iyr, my_imo, my_idy, my_ihr, my_imi, bort_target_set
287 
288  ! Check for I8 integers
289 
290  if(im8b) then
291  im8b=.false.
292  call x84(iyr,my_iyr,1)
293  call x84(imo,my_imo,1)
294  call x84(idy,my_idy,1)
295  call x84(ihr,my_ihr,1)
296  call x84(imi,my_imi,1)
297  call strcpt(cf,my_iyr,my_imo,my_idy,my_ihr,my_imi)
298  im8b=.true.
299  return
300  endif
301 
302  ! If we're catching bort errors, set a target return location if one doesn't already exist.
303 
304  if (bort_target_set() == 1) then
305  call catch_bort_strcpt_c(cf,iyr,imo,idy,ihr,imi)
306  call bort_target_unset
307  return
308  endif
309 
310  my_cf = cf
311  call capit(my_cf)
312  if(my_cf /= 'Y' .and. my_cf /= 'N') then
313  write(bort_str,'("BUFRLIB: STRCPT - INPUT ARGUMENT IS ",A1,", IT MUST BE EITHER Y, y, N OR n")') cf
314  call bort(bort_str)
315  endif
316 
317  ctrt = my_cf
318  if(ctrt=='Y') then
319  itryr = iyr
320  itrmo = imo
321  itrdy = idy
322  itrhr = ihr
323  itrmi = imi
324  endif
325 
326  return
327 end subroutine strcpt
recursive subroutine bort(str)
Log an error message, then either return to or abort the application program.
Definition: borts.F90:15
subroutine bort_target_unset
Clear any existing bort target.
Definition: borts.F90:180
integer function bort_target_set()
Sets a new bort target, if bort catching is enabled and such a target doesn't already exist.
Definition: borts.F90:160
recursive integer function iupb(mbay, nbyt, nbit)
Decode an integer value from within a specified number of bits of an integer array,...
Definition: cidecode.F90:226
subroutine pkb(nval, nbits, ibay, ibit)
Encode an integer value within a specified number of bits of an integer array, starting at the bit im...
Definition: ciencode.F90:140
subroutine mvb(ib1, nb1, ib2, nb2, nbm)
Copy a specified number of bytes from one packed binary array to another.
Definition: copydata.F90:767
subroutine capit(str)
Capitalize all of the alphabetic characters in a string.
Definition: misc.F90:334
Wrap C NCEPLIBS-bufr functions so they can be called from within the Fortran part of the library.
Definition: bufrlib.F90:11
Declare arrays and variables used to store BUFR messages internally for multiple file IDs.
integer, dimension(:,:), allocatable mbay
Current BUFR message for each file ID.
Declare variables used to store tank receipt time information within Section 1 of BUFR messages.
integer itrhr
Tank receipt hour.
integer itryr
Tank receipt year.
integer itrdy
Tank receipt day.
character ctrt
Flag indicating whether tank receipt times are to be included within output BUFR messages; this varia...
integer itrmi
Tank receipt minute.
integer itrmo
Tank receipt month.
recursive subroutine status(lunit, lun, il, im)
Check whether a specified Fortran logical unit number is currently connected to the NCEPLIBS-bufr sof...
recursive subroutine getlens(mbay, ll, len0, len1, len2, len3, len4, len5)
Read the section lengths of a BUFR message, up to a specified point in the message.
recursive integer function iupbs01(mbay, s01mnem)
Read a specified value from within Section 0 or Section 1 of a BUFR message.
Definition: s013vals.F90:245
recursive subroutine strcpt(cf, iyr, imo, idy, ihr, imi)
Specify a tank receipt time to be included within Section 1 of all BUFR messages output by future cal...
Definition: tankrcpt.F90:272
recursive subroutine rtrcpt(lunit, iyr, imo, idy, ihr, imi, iret)
Read the tank receipt time (if one exists) from Section 1 of a BUFR message.
Definition: tankrcpt.F90:193
recursive subroutine rtrcptb(mbay, iyr, imo, idy, ihr, imi, iret)
Read the tank receipt time (if one exists) from Section 1 of a BUFR message.
Definition: tankrcpt.F90:122
recursive subroutine atrcpt(msgin, lmsgot, msgot)
Read an input message and output an equivalent BUFR message with a tank receipt time added to Section...
Definition: tankrcpt.F90:24
subroutine x48(iin4, iout8, nval)
Encode one or more 4-byte integer values as 8-byte integer values.
Definition: x4884.F90:18
subroutine x84(iin8, iout4, nval)
Encode one or more 8-byte integer values as 4-byte integer values.
Definition: x4884.F90:65