NCEPLIBS-bufr  12.3.0
misc.F90
Go to the documentation of this file.
1 
5 
15 subroutine bfrini
16 
17  use modv_vars, only: maxtba, maxtbb, maxtbd, mxmsgl, nfiles, adsn, idnr, lun1, lun2
18 
19  use moda_stbfr
20  use moda_idrdm
21  use moda_msglim
22  use moda_bitbuf
23  use moda_bufrmg
24  use moda_bufrsr
25  use moda_tababd
26  use moda_usrint
27  use moda_dscach
28 
29  implicit none
30 
31  integer ndndx(10), nldxa(10), nldxb(10), nldxd(10), nld30(10), nxstr, ldxa, ldxb, ldxd, ld30, &
32  i, j, i1, ifxy
33 
34  character*240 cmtdir
35  character*56 dxstr
36  character*6 dndx(25,10)
37 
38  common /dxtab/ nxstr(10), ldxa(10), ldxb(10), ldxd(10), ld30(10), dxstr(10)
39 
40  data (dndx(i,1),i=1,25)/ &
41  '102000','031001','000001','000002', &
42  '110000','031001','000010','000011','000012','000013','000015','000016','000017','000018','000019','000020', &
43  '107000','031001','000010','000011','000012','000013','101000','031001','000030'/
44 
45  data (dndx(i,2),i=1,15)/ &
46  '103000','031001','000001','000002','000003', &
47  '101000','031001','300004', &
48  '105000','031001','300003','205064','101000','031001','000030'/
49 
50  data ndndx / 25 , 15 , 8*0 /
51  data nldxa / 35 , 67 , 8*0 /
52  data nldxb / 80 , 112 , 8*0 /
53  data nldxd / 38 , 70 , 8*0 /
54  data nld30 / 5 , 6 , 8*0 /
55 
56  ! Initialize module @ref moda_bitbuf
57 
58  maxbyt = min(10000,mxmsgl)
59 
60  ! Initialize module @ref moda_stbfr
61 
62  do i=1,nfiles
63  iolun(i) = 0
64  iomsg(i) = 0
65  enddo
66 
67  ! Initialize module @ref moda_idrdm
68 
69  do i=1,nfiles
70  idrdm(i) = 0
71  enddo
72 
73  ! Initialize module @ref moda_msglim
74 
75  do i=1,nfiles
76  msglim(i) = 3
77  enddo
78 
79  ! Initialize module @ref moda_usrint
80 
81  do i=1,nfiles
82  nval(i) = 0
83  enddo
84 
85  ! Initialize idnr array
86 
87  do i=1,10
88  idnr(i) = ifxy(adsn(i))
89  enddo
90 
91  ! Initialize module @ref moda_tababd
92 
93  ! ntba(0) is the maximum number of entries within internal BUFR table A
94  ntba(0) = maxtba
95  ! ntbb(0) is the maximum number of entries within internal BUFR Table B
96  ntbb(0) = maxtbb
97  ! ntbd(0) is the maximum number of entries within internal BUFR Table D
98  ntbd(0) = maxtbd
99 
100  ! Initialize common /dxtab/
101 
102  do j=1,10
103  ldxa(j) = nldxa(j)
104  ldxb(j) = nldxb(j)
105  ldxd(j) = nldxd(j)
106  ld30(j) = nld30(j)
107  dxstr(j) = ' '
108  nxstr(j) = ndndx(j)*2
109  do i=1,ndndx(j)
110  i1 = i*2-1
111  call ipkm(dxstr(j)(i1:i1+1),2,ifxy(dndx(i,j)))
112  enddo
113  enddo
114 
115  ! Initialize module @ref moda_bufrmg
116 
117  do i=1,nfiles
118  msglen(i) = 0
119  enddo
120 
121  ! Initialize module @ref moda_bufrsr
122 
123  do i=1,nfiles
124  jsr(i) = 0
125  enddo
126 
127  ! Initialize module @ref moda_dscach
128 
129  ncnem = 0
130 
131  ! Initialize master BUFR table information
132 
133  cmtdir = &
134  '/home/runner/work/NCEPLIBS-bufr/NCEPLIBS-bufr/bufr/build-doc' // &
135 's/install/tables'
136  call mtinfo(cmtdir,lun1,lun2)
137 
138  return
139 end subroutine bfrini
140 
155 recursive subroutine strnum( str, num, iret )
156  use modv_vars, only: im8b
157 
158  implicit none
159 
160  character*(*), intent(in) :: str
161 
162  integer, intent(out) :: num, iret
163 
164  character str2*40
165 
166  integer lens, ios
167 
168  ! Check for I8 integers.
169  if (im8b) then
170  im8b = .false.
171  call strnum ( str, num, iret )
172  call x48 ( num, num, 1 )
173  call x48 ( iret, iret, 1 )
174  im8b = .true.
175  return
176  end if
177 
178  ! Decode the integer from the string.
179  iret = 0
180  num = 0
181  call strsuc ( str, str2, lens )
182  if ( lens == 0 ) return
183  read ( str2(1:lens), '(I40)', iostat = ios ) num
184  if ( ios /= 0 ) iret = -1
185 
186  return
187 end subroutine strnum
188 
198 subroutine strsuc(str1,str2,lens)
199  implicit none
200 
201  character*(*), intent(in) :: str1
202  character*(*), intent(out) :: str2
203 
204  integer, intent(out) :: lens
205 
206  str2 = adjustl(str1)
207  lens = len_trim(str2)
208 
209  return
210 end subroutine strsuc
211 
235 integer function irev(n) result(iret)
236 
237  use modv_vars, only: nbytw, iordle
238 
239  implicit none
240 
241  integer, intent(in) :: n
242 
243  integer int, jnt, i
244 
245  character*8 cint,dint
246 
247  equivalence(cint,int)
248  equivalence(dint,jnt)
249 
250 #ifdef BIG_ENDIAN
251  iret = n
252 #else
253  int = n
254  do i=1,nbytw
255  dint(i:i) = cint(iordle(i):iordle(i))
256  enddo
257  iret = jnt
258 #endif
259 
260  return
261 end function irev
262 
281 subroutine jstnum(str,sign,iret)
282 
283  use modv_vars, only: iprt
284 
285  implicit none
286 
287  integer, intent(out) :: iret
288  integer lstr, num, ier
289 
290  character*(*), intent(inout) :: str
291  character, intent(out) :: sign
292  character*128 errstr
293 
294  iret = 0
295 
296  if(str==' ') call bort('BUFRLIB: JSTNUM - INPUT BLANK CHARACTER STRING NOT ALLOWED')
297 
298  str = adjustl(str)
299  lstr = len(str)
300  if(str(1:1)=='+') then
301  str = str(2:lstr)
302  sign = '+'
303  elseif(str(1:1)=='-') then
304  str = str(2:lstr)
305  sign = '-'
306  else
307  sign = '+'
308  endif
309 
310  call strnum(str,num,ier)
311  if(ier<0) then
312  if(iprt>=0) then
313  call errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
314  errstr = 'BUFRLIB: JSTNUM: ENCODED VALUE WITHIN RESULTANT CHARACTER STRING (' // str // ') IS NOT AN INTEGER - '// &
315  'RETURN WITH IRET = -1'
316  call errwrt(errstr)
317  call errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
318  call errwrt(' ')
319  endif
320  iret = -1
321  endif
322 
323  return
324 end subroutine jstnum
325 
333 subroutine capit(str)
334 
335  implicit none
336 
337  integer i, j
338 
339  character*(*), intent(inout) :: str
340  character*26, parameter :: upcs = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
341  character*26, parameter :: lwcs = 'abcdefghijklmnopqrstuvwxyz'
342 
343  do i=1,len(str)
344  do j=1,26
345  if(str(i:i)==lwcs(j:j)) then
346  str(i:i) = upcs(j:j)
347  exit
348  endif
349  enddo
350  enddo
351 
352  return
353 end subroutine capit
354 
360 recursive subroutine bvers (cverstr)
361 
362  use bufrlib
363 
364  implicit none
365 
366  character*(*), intent(out) :: cverstr
367  character*9 c_cverstr
368 
369  integer cvslen, bort_target_set
370 
371  ! If we're catching bort errors, set a target return location if one doesn't already exist.
372 
373  if (bort_target_set() == 1) then
374  call catch_bort_bvers_c(c_cverstr,len(c_cverstr))
375  cvslen = min(len(cverstr),8)
376  cverstr(1:cvslen) = c_cverstr(1:cvslen)
377  call bort_target_unset
378  return
379  endif
380 
381  if (len(cverstr)<8) call bort('BUFRLIB: BVERS - INPUT STRING MUST CONTAIN SPACE FOR AT LEAST 8 CHARACTERS')
382 
383  cverstr = '12.3.0'
384 
385  return
386 end subroutine bvers
387 
399 integer function isize (num) result (iret)
400 
401  implicit none
402 
403  integer, intent(in) :: num
404 
405  character*128 bort_str
406 
407  if ( num >= 0 ) then
408  do iret = 1, 5
409  if ( num < 10**iret ) return
410  enddo
411  endif
412  write(bort_str,'("BUFRLIB: ISIZE - INPUT NUMBER (",I7,") IS OUT OF RANGE")') num
413  call bort(bort_str)
414 
415  return
416 end function isize
417 
436 recursive integer function igetsc(lunit) result(iret)
437 
438  use bufrlib
439 
440  use modv_vars, only: im8b
441 
442  use moda_stcode
443 
444  implicit none
445 
446  integer, intent(in) :: lunit
447  integer my_lunit, lun, il, im, bort_target_set
448 
449  ! Check for I8 integers.
450  if (im8b) then
451  im8b = .false.
452  call x84(lunit,my_lunit,1)
453  iret = igetsc(my_lunit)
454  im8b = .true.
455  return
456  end if
457 
458  ! If we're catching bort errors, set a target return location if one doesn't already exist.
459 
460  if (bort_target_set() == 1) then
461  call catch_bort_igetsc_c(lunit,iret)
462  call bort_target_unset
463  return
464  endif
465 
466  iret = 0
467 
468  ! Make sure the specified logical unit is connected to the library.
469  call status(lunit,lun,il,im)
470  if(il==0) call bort('BUFRLIB: IGETSC - BUFR FILE IS CLOSED, IT MUST BE OPEN')
471 
472  iret = iscodes(lun)
473 
474  return
475 end function igetsc
476 
485 integer function iokoper(nemo) result(iret)
486 
487  implicit none
488 
489  integer imrkopr
490 
491  character*(*), intent(in) :: nemo
492 
493  if ( len(nemo)<6 ) then
494  iret = 0
495  else if ( lge(nemo(1:3),'201') .and. lle(nemo(1:3),'208') ) then
496  iret = 1
497  else if ( nemo(1:3)=='221' ) then
498  iret = 1
499  else if ( ( ( nemo(4:6)=='000' ) .or. ( nemo(4:6)=='255' ) ) .and. &
500  ( ( nemo(1:3)=='237' ) .or. ( lge(nemo(1:3),'241') .and. lle(nemo(1:3),'243') ) ) ) then
501  iret = 1
502  else if ( ( nemo(4:6)=='000' ) .and. ( ( lge(nemo(1:3),'222') .and. lle(nemo(1:3),'225') ) .or. &
503  ( nemo(1:3)=='232' ) .or. ( nemo(1:3)=='235' ) .or. ( nemo(1:3)=='236' ) ) ) then
504  iret = 1
505  else
506  iret = imrkopr(nemo)
507  endif
508 
509  return
510 end function iokoper
511 
515 subroutine mrginv
516 
517  use modv_vars, only: iprt
518 
519  use moda_mrgcom
520 
521  implicit none
522 
523  character*128 errstr
524 
525  if(iprt>=0) then
526  call errwrt('+++++++++++++++++++++BUFRLIB+++++++++++++++++++++++')
527  call errwrt('---------------------------------------------------')
528  call errwrt('INVENTORY FROM MERGE PROCESS IN SUBROUTINE INVMRG:')
529  call errwrt('---------------------------------------------------')
530  write ( unit=errstr, fmt='(A,I8)' ) 'NUMBER OF DRB EXPANSIONS = ', nrpl
531  call errwrt(errstr)
532  write ( unit=errstr, fmt='(A,I8)' ) 'NUMBER OF MERGES = ', nmrg
533  call errwrt(errstr)
534  write ( unit=errstr, fmt='(A,I8)' ) 'NUMBER THAT ARE AMBIGUOUS = ', namb
535  call errwrt(errstr)
536  call errwrt('---------------------------------------------------')
537  write ( unit=errstr, fmt='(A,I9)' ) 'TOTAL NUMBER OF VISITS = ', ntot
538  call errwrt(errstr)
539  call errwrt('---------------------------------------------------')
540  call errwrt('+++++++++++++++++++++BUFRLIB+++++++++++++++++++++++')
541  call errwrt(' ')
542  endif
543 
544  return
545 end subroutine mrginv
integer function imrkopr(nemo)
Check whether a specified mnemonic is a Table C marker operator.
Definition: bitmaps.F90:376
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 subroutine ipkm(cbay, nbyt, n)
Encode an integer value within a specified number of bytes of a character string, up to a maximum of ...
Definition: ciencode.F90:194
subroutine errwrt(str)
Specify a custom location for the logging of error and diagnostic messages generated by the NCEPLIBS-...
Definition: errwrt.F90:32
recursive subroutine mtinfo(cmtdir, lunmt1, lunmt2)
Specify the directory location and Fortran logical unit numbers to be used when reading master BUFR t...
Definition: mastertable.F90:35
recursive subroutine bvers(cverstr)
Get the version number of the NCEPLIBS-bufr software.
Definition: misc.F90:361
subroutine jstnum(str, sign, iret)
Left-justify a character string containing an encoded integer, by removing all leading blanks and any...
Definition: misc.F90:282
integer function iokoper(nemo)
Check whether a specified mnemonic is a Table C operator supported by the NCEPLIBS-bufr software.
Definition: misc.F90:486
integer function irev(n)
Return a copy of an integer value with the bytes possibly reversed.
Definition: misc.F90:236
recursive integer function igetsc(lunit)
Check for an abnormal status code associated with the processing of a file.
Definition: misc.F90:437
recursive subroutine strnum(str, num, iret)
Decode an integer from a character string.
Definition: misc.F90:156
subroutine strsuc(str1, str2, lens)
Remove leading and trailing blanks from a character string.
Definition: misc.F90:199
subroutine bfrini
Initialize numerous global variables and arrays within internal modules and common blocks throughout ...
Definition: misc.F90:16
subroutine capit(str)
Capitalize all of the alphabetic characters in a string.
Definition: misc.F90:334
integer function isize(num)
Compute the number of characters needed to encode an integer as a string.
Definition: misc.F90:400
subroutine mrginv
Print a summary of merge activity.
Definition: misc.F90:516
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 maxbyt
Maximum length of an output BUFR message.
Declare arrays used to store, for each output file ID, a copy of the BUFR message that was most recen...
integer, dimension(:), allocatable msglen
Length (in integers) of BUFR message most recently written to each output file ID.
Declare arrays and variables needed to store the current position within a BUFR file.
integer, dimension(:), allocatable jsr
Indicator of stack status when entering subroutine rewnbf().
Declare arrays and variables for the internal Table A mnemonic cache that is used for Section 3 decod...
integer ncnem
Number of entries in the internal Table A mnemonic cache (up to a maximum of mxcnem).
Declare an array used by subroutine readerme() to read in a new DX dictionary table as a consecutive ...
integer, dimension(:), allocatable idrdm
DX BUFR tables message count for each file ID.
Declare variables for use when merging parts of different data subsets.
integer nmrg
Number of merges.
integer ntot
Total number of calls to subroutine invmrg().
integer namb
Number of potential merges that weren't made because of ambiguities.
integer nrpl
Number of expansions of Table D mnemonics using short (1-bit) delayed replication.
Declare an array used to keep track of which logical units should not have any empty (zero data subse...
integer, dimension(:), allocatable msglim
Tracking index for each file ID.
Declare arrays used to store file and message status indicators for all logical units that have been ...
integer, dimension(:), allocatable iolun
File status indicators.
integer, dimension(:), allocatable iomsg
Message status indicator corresponding to iolun, denoting whether a BUFR message is currently open wi...
Declare an array used to store a status code for each file ID if an error or other abnormal result oc...
integer, dimension(:), allocatable iscodes
Abnormal status codes.
Declare arrays and variables used to store DX BUFR tables internally for multiple file IDs.
integer, dimension(:), allocatable ntba
Number of Table A entries for each file ID (up to a maximum of maxtba, whose value is stored in array...
integer, dimension(:), allocatable ntbd
Number of Table D entries for each file ID (up to a maximum of maxtbd, whose value is stored in array...
integer, dimension(:), allocatable ntbb
Number of Table B entries for each file ID (up to a maximum of maxtbb, whose value is stored in array...
Declare arrays used to store data values and associated metadata for the current BUFR data subset in ...
integer, dimension(:), allocatable nval
Number of data values in BUFR data subset.
recursive subroutine status(lunit, lun, il, im)
Check whether a specified Fortran logical unit number is currently connected to the NCEPLIBS-bufr sof...
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