NCEPLIBS-bufr  12.1.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
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), ibct, ipd1, ipd2, ipd3, ipd4, nrpl, nmrg, namb, ntot, &
32  maxdx, idxv, nxstr, ldxa, ldxb, ldxd, ld30, i, j, i1, ifxy
33 
34  character*240 cmtdir
35  character*56 dxstr
36  character*6 dndx(25,10)
37 
38  common /padesc/ ibct, ipd1, ipd2, ipd3, ipd4
39  common /dxtab/ maxdx, idxv, nxstr(10), ldxa(10), ldxb(10), ldxd(10), ld30(10), dxstr(10)
40  common /mrgcom/ nrpl,nmrg,namb,ntot
41 
42  data (dndx(i,1),i=1,25)/ &
43  '102000','031001','000001','000002', &
44  '110000','031001','000010','000011','000012','000013','000015','000016','000017','000018','000019','000020', &
45  '107000','031001','000010','000011','000012','000013','101000','031001','000030'/
46 
47  data (dndx(i,2),i=1,15)/ &
48  '103000','031001','000001','000002','000003', &
49  '101000','031001','300004', &
50  '105000','031001','300003','205064','101000','031001','000030'/
51 
52  data ndndx / 25 , 15 , 8*0 /
53  data nldxa / 35 , 67 , 8*0 /
54  data nldxb / 80 , 112 , 8*0 /
55  data nldxd / 38 , 70 , 8*0 /
56  data nld30 / 5 , 6 , 8*0 /
57 
58  ! Initialize module moda_bitbuf
59 
60  maxbyt = min(10000,mxmsgl)
61 
62  ! Initialize common /padesc/
63 
64  ibct = ifxy('063000')
65  ipd1 = ifxy('102000')
66  ipd2 = ifxy('031001')
67  ipd3 = ifxy('206001')
68  ipd4 = ifxy('063255')
69 
70  ! Initialize module moda_stbfr
71 
72  do i=1,nfiles
73  iolun(i) = 0
74  iomsg(i) = 0
75  enddo
76 
77  ! Initialize module moda_idrdm
78 
79  do i=1,nfiles
80  idrdm(i) = 0
81  enddo
82 
83  ! Initialize module moda_msglim
84 
85  do i=1,nfiles
86  msglim(i) = 3
87  enddo
88 
89  ! Initialize module moda_usrint
90 
91  do i=1,nfiles
92  nval(i) = 0
93  enddo
94 
95  ! Initialize idnr array
96 
97  do i=1,10
98  idnr(i) = ifxy(adsn(i))
99  enddo
100 
101  ! Initialize module moda_tababd
102 
103  ! ntba(0) is the maximum number of entries within internal BUFR table A
104  ntba(0) = maxtba
105  ! ntbb(0) is the maximum number of entries within internal BUFR Table B
106  ntbb(0) = maxtbb
107  ! ntbd(0) is the maximum number of entries within internal BUFR Table D
108  ntbd(0) = maxtbd
109 
110  ! Initialize common /dxtab/
111 
112  maxdx = maxbyt
113  ! idxv is the version number of the local tables
114  idxv = 1
115 
116  do j=1,10
117  ldxa(j) = nldxa(j)
118  ldxb(j) = nldxb(j)
119  ldxd(j) = nldxd(j)
120  ld30(j) = nld30(j)
121  dxstr(j) = ' '
122  nxstr(j) = ndndx(j)*2
123  do i=1,ndndx(j)
124  i1 = i*2-1
125  call ipkm(dxstr(j)(i1:i1),2,ifxy(dndx(i,j)))
126  enddo
127  enddo
128 
129  ! Initialize module moda_bufrmg
130 
131  do i=1,nfiles
132  msglen(i) = 0
133  enddo
134 
135  ! Initialize common /mrgcom/
136 
137  nrpl = 0
138  nmrg = 0
139  namb = 0
140  ntot = 0
141 
142  ! Initialize module moda_bufrsr
143 
144  do i=1,nfiles
145  jsr(i) = 0
146  enddo
147 
148  ! Initialize module moda_dscach
149 
150  ncnem = 0
151 
152  ! Initialize common /mstinf/
153 
154  cmtdir = &
155  '/home/runner/work/NCEPLIBS-bufr/NCEPLIBS-bufr/bufr/build-doc' // &
156 's/install/tables'
157  call mtinfo(cmtdir,98,99)
158 
159  return
160 end subroutine bfrini
161 
176 recursive subroutine strnum( str, num, iret )
177  use modv_vars, only: im8b
178 
179  implicit none
180 
181  character*(*), intent(in) :: str
182 
183  integer, intent(out) :: num, iret
184 
185  character str2*40
186 
187  integer lens, ios
188 
189  ! Check for I8 integers.
190  if (im8b) then
191  im8b = .false.
192  call strnum ( str, num, iret )
193  call x48 ( num, num, 1 )
194  call x48 ( iret, iret, 1 )
195  im8b = .true.
196  return
197  end if
198 
199  ! Decode the integer from the string.
200  iret = 0
201  num = 0
202  call strsuc ( str, str2, lens )
203  if ( lens == 0 ) return
204  read ( str2(1:lens), '(I40)', iostat = ios ) num
205  if ( ios /= 0 ) iret = -1
206 
207  return
208 end subroutine strnum
209 
219 subroutine strsuc(str1,str2,lens)
220  implicit none
221 
222  character*(*), intent(in) :: str1
223  character*(*), intent(out) :: str2
224 
225  integer, intent(out) :: lens
226 
227  str2 = adjustl(str1)
228  lens = len_trim(str2)
229 
230  return
231 end subroutine strsuc
232 
256 integer function irev(n) result(iret)
257 
258  use modv_vars, only: nbytw, iordle
259 
260  implicit none
261 
262  integer, intent(in) :: n
263 
264  integer int, jnt, i
265 
266  character*8 cint,dint
267 
268  equivalence(cint,int)
269  equivalence(dint,jnt)
270 
271 #ifdef BIG_ENDIAN
272  iret = n
273 #else
274  int = n
275  do i=1,nbytw
276  dint(i:i) = cint(iordle(i):iordle(i))
277  enddo
278  iret = jnt
279 #endif
280 
281  return
282 end function irev
283 
302 subroutine jstnum(str,sign,iret)
303 
304  implicit none
305 
306  integer, intent(out) :: iret
307  integer iprt, lstr, num, ier
308 
309  character*(*), intent(inout) :: str
310  character, intent(out) :: sign
311  character*128 errstr
312 
313  common /quiet/ iprt
314 
315  iret = 0
316 
317  if(str==' ') call bort('BUFRLIB: JSTNUM - INPUT BLANK CHARACTER STRING NOT ALLOWED')
318 
319  str = adjustl(str)
320  lstr = len(str)
321  if(str(1:1)=='+') then
322  str = str(2:lstr)
323  sign = '+'
324  elseif(str(1:1)=='-') then
325  str = str(2:lstr)
326  sign = '-'
327  else
328  sign = '+'
329  endif
330 
331  call strnum(str,num,ier)
332  if(ier<0) then
333  if(iprt>=0) then
334  call errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
335  errstr = 'BUFRLIB: JSTNUM: ENCODED VALUE WITHIN RESULTANT CHARACTER STRING (' // str // ') IS NOT AN INTEGER - '// &
336  'RETURN WITH IRET = -1'
337  call errwrt(errstr)
338  call errwrt('+++++++++++++++++++++WARNING+++++++++++++++++++++++')
339  call errwrt(' ')
340  endif
341  iret = -1
342  endif
343 
344  return
345 end subroutine jstnum
346 
354 subroutine capit(str)
355 
356  implicit none
357 
358  integer i, j
359 
360  character*(*), intent(inout) :: str
361  character*26 upcs, lwcs
362 
363  data upcs /'ABCDEFGHIJKLMNOPQRSTUVWXYZ'/
364  data lwcs /'abcdefghijklmnopqrstuvwxyz'/
365 
366  do i=1,len(str)
367  do j=1,26
368  if(str(i:i)==lwcs(j:j)) then
369  str(i:i) = upcs(j:j)
370  exit
371  endif
372  enddo
373  enddo
374 
375  return
376 end subroutine capit
377 
383 subroutine bvers (cverstr)
384 
385  implicit none
386 
387  character*(*), intent(out) :: cverstr
388 
389  if (len(cverstr)<8) call bort('BUFRLIB: BVERS - INPUT STRING MUST CONTAIN SPACE FOR AT LEAST 8 CHARACTERS')
390 
391  cverstr = '12.1.0'
392 
393  return
394 end subroutine bvers
395 
407 integer function isize (num) result (iret)
408 
409  implicit none
410 
411  integer, intent(in) :: num
412 
413  character*128 bort_str
414 
415  if ( num >= 0 ) then
416  do iret = 1, 5
417  if ( num < 10**iret ) return
418  enddo
419  endif
420  write(bort_str,'("BUFRLIB: ISIZE - INPUT NUMBER (",I7,") IS OUT OF RANGE")') num
421  call bort(bort_str)
422 
423  return
424 end function isize
425 
444 recursive integer function igetsc(lunit) result(iret)
445 
446  use modv_vars, only: im8b
447 
448  use moda_stcode
449 
450  implicit none
451 
452  integer, intent(in) :: lunit
453  integer my_lunit, lun, il, im
454 
455  ! Check for I8 integers.
456  if (im8b) then
457  im8b = .false.
458  call x84(lunit,my_lunit,1)
459  iret = igetsc(my_lunit)
460  im8b = .true.
461  return
462  end if
463 
464  iret = 0
465 
466  ! Make sure the specified logical unit is connected to the library.
467  call status(lunit,lun,il,im)
468  if(il==0) call bort('BUFRLIB: IGETSC - BUFR FILE IS CLOSED, IT MUST BE OPEN')
469 
470  iret = iscodes(lun)
471 
472  return
473 end function igetsc
474 
483 integer function iokoper(nemo) result(iret)
484 
485  implicit none
486 
487  integer imrkopr
488 
489  character*(*), intent(in) :: nemo
490 
491  if ( len(nemo)<6 ) then
492  iret = 0
493  else if ( lge(nemo(1:3),'201') .and. lle(nemo(1:3),'208') ) then
494  iret = 1
495  else if ( nemo(1:3)=='221' ) then
496  iret = 1
497  else if ( ( ( nemo(4:6)=='000' ) .or. ( nemo(4:6)=='255' ) ) .and. &
498  ( ( nemo(1:3)=='237' ) .or. ( lge(nemo(1:3),'241') .and. lle(nemo(1:3),'243') ) ) ) then
499  iret = 1
500  else if ( ( nemo(4:6)=='000' ) .and. ( ( lge(nemo(1:3),'222') .and. lle(nemo(1:3),'225') ) .or. &
501  ( nemo(1:3)=='232' ) .or. ( nemo(1:3)=='235' ) .or. ( nemo(1:3)=='236' ) ) ) then
502  iret = 1
503  else
504  iret = imrkopr(nemo)
505  endif
506 
507  return
508 end function iokoper
509 
513 subroutine mrginv
514 
515  implicit none
516 
517  integer nrpl, nmrg, namb, ntot, iprt
518 
519  character*128 errstr
520 
521  common /mrgcom/ nrpl, nmrg, namb, ntot
522  common /quiet/ iprt
523 
524  if(iprt>=0) then
525  call errwrt('+++++++++++++++++++++BUFRLIB+++++++++++++++++++++++')
526  call errwrt('---------------------------------------------------')
527  call errwrt('INVENTORY FROM MERGE PROCESS IN SUBROUTINE INVMRG:')
528  call errwrt('---------------------------------------------------')
529  write ( unit=errstr, fmt='(A,I8)' ) 'NUMBER OF DRB EXPANSIONS = ', nrpl
530  call errwrt(errstr)
531  write ( unit=errstr, fmt='(A,I8)' ) 'NUMBER OF MERGES = ', nmrg
532  call errwrt(errstr)
533  write ( unit=errstr, fmt='(A,I8)' ) 'NUMBER THAT ARE AMBIGUOUS = ', namb
534  call errwrt(errstr)
535  call errwrt('---------------------------------------------------')
536  write ( unit=errstr, fmt='(A,I9)' ) 'TOTAL NUMBER OF VISITS = ', ntot
537  call errwrt(errstr)
538  call errwrt('---------------------------------------------------')
539  call errwrt('+++++++++++++++++++++BUFRLIB+++++++++++++++++++++++')
540  call errwrt(' ')
541  endif
542 
543  return
544 end subroutine mrginv
integer function imrkopr(nemo)
Check whether a specified mnemonic is a Table C marker operator.
Definition: bitmaps.F90:354
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:303
integer function iokoper(nemo)
Check whether a specified mnemonic is a Table C operator supported by the NCEPLIBS-bufr software.
Definition: misc.F90:484
integer function irev(n)
Return a copy of an integer value with the bytes possibly reversed.
Definition: misc.F90:257
recursive integer function igetsc(lunit)
Check for an abnormal status code associated with the processing of a file.
Definition: misc.F90:445
subroutine bvers(cverstr)
Get the version number of the NCEPLIBS-bufr software.
Definition: misc.F90:384
recursive subroutine strnum(str, num, iret)
Decode an integer from a character string.
Definition: misc.F90:177
subroutine strsuc(str1, str2, lens)
Remove leading and trailing blanks from a character string.
Definition: misc.F90:220
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:355
integer function isize(num)
Compute the number of characters needed to encode an integer as a string.
Definition: misc.F90:408
subroutine mrginv
Print a summary of merge activity.
Definition: misc.F90:514
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 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