NCEPLIBS-bufr  12.2.0
All Data Structures Namespaces Files Functions Variables Macros Pages
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),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 subroutine bvers (cverstr)
361 
362  implicit none
363 
364  character*(*), intent(out) :: cverstr
365 
366  if (len(cverstr)<8) call bort('BUFRLIB: BVERS - INPUT STRING MUST CONTAIN SPACE FOR AT LEAST 8 CHARACTERS')
367 
368  cverstr = '12.2.0'
369 
370  return
371 end subroutine bvers
372 
384 integer function isize (num) result (iret)
385 
386  implicit none
387 
388  integer, intent(in) :: num
389 
390  character*128 bort_str
391 
392  if ( num >= 0 ) then
393  do iret = 1, 5
394  if ( num < 10**iret ) return
395  enddo
396  endif
397  write(bort_str,'("BUFRLIB: ISIZE - INPUT NUMBER (",I7,") IS OUT OF RANGE")') num
398  call bort(bort_str)
399 
400  return
401 end function isize
402 
421 recursive integer function igetsc(lunit) result(iret)
422 
423  use modv_vars, only: im8b
424 
425  use moda_stcode
426 
427  implicit none
428 
429  integer, intent(in) :: lunit
430  integer my_lunit, lun, il, im
431 
432  ! Check for I8 integers.
433  if (im8b) then
434  im8b = .false.
435  call x84(lunit,my_lunit,1)
436  iret = igetsc(my_lunit)
437  im8b = .true.
438  return
439  end if
440 
441  iret = 0
442 
443  ! Make sure the specified logical unit is connected to the library.
444  call status(lunit,lun,il,im)
445  if(il==0) call bort('BUFRLIB: IGETSC - BUFR FILE IS CLOSED, IT MUST BE OPEN')
446 
447  iret = iscodes(lun)
448 
449  return
450 end function igetsc
451 
460 integer function iokoper(nemo) result(iret)
461 
462  implicit none
463 
464  integer imrkopr
465 
466  character*(*), intent(in) :: nemo
467 
468  if ( len(nemo)<6 ) then
469  iret = 0
470  else if ( lge(nemo(1:3),'201') .and. lle(nemo(1:3),'208') ) then
471  iret = 1
472  else if ( nemo(1:3)=='221' ) then
473  iret = 1
474  else if ( ( ( nemo(4:6)=='000' ) .or. ( nemo(4:6)=='255' ) ) .and. &
475  ( ( nemo(1:3)=='237' ) .or. ( lge(nemo(1:3),'241') .and. lle(nemo(1:3),'243') ) ) ) then
476  iret = 1
477  else if ( ( nemo(4:6)=='000' ) .and. ( ( lge(nemo(1:3),'222') .and. lle(nemo(1:3),'225') ) .or. &
478  ( nemo(1:3)=='232' ) .or. ( nemo(1:3)=='235' ) .or. ( nemo(1:3)=='236' ) ) ) then
479  iret = 1
480  else
481  iret = imrkopr(nemo)
482  endif
483 
484  return
485 end function iokoper
486 
490 subroutine mrginv
491 
492  use modv_vars, only: iprt
493 
494  use moda_mrgcom
495 
496  implicit none
497 
498  character*128 errstr
499 
500  if(iprt>=0) then
501  call errwrt('+++++++++++++++++++++BUFRLIB+++++++++++++++++++++++')
502  call errwrt('---------------------------------------------------')
503  call errwrt('INVENTORY FROM MERGE PROCESS IN SUBROUTINE INVMRG:')
504  call errwrt('---------------------------------------------------')
505  write ( unit=errstr, fmt='(A,I8)' ) 'NUMBER OF DRB EXPANSIONS = ', nrpl
506  call errwrt(errstr)
507  write ( unit=errstr, fmt='(A,I8)' ) 'NUMBER OF MERGES = ', nmrg
508  call errwrt(errstr)
509  write ( unit=errstr, fmt='(A,I8)' ) 'NUMBER THAT ARE AMBIGUOUS = ', namb
510  call errwrt(errstr)
511  call errwrt('---------------------------------------------------')
512  write ( unit=errstr, fmt='(A,I9)' ) 'TOTAL NUMBER OF VISITS = ', ntot
513  call errwrt(errstr)
514  call errwrt('---------------------------------------------------')
515  call errwrt('+++++++++++++++++++++BUFRLIB+++++++++++++++++++++++')
516  call errwrt(' ')
517  endif
518 
519  return
520 end subroutine mrginv
integer function imrkopr(nemo)
Check whether a specified mnemonic is a Table C marker operator.
Definition: bitmaps.F90:361
subroutine bort(str)
Log an error message, then abort the application program.
Definition: borts.F90:15
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
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:461
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:422
subroutine bvers(cverstr)
Get the version number of the NCEPLIBS-bufr software.
Definition: misc.F90:361
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:385
subroutine mrginv
Print a summary of merge activity.
Definition: misc.F90:491
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