15 recursive subroutine fortran_open(filename, lunit, format, position, iret)
17 use modv_vars,
only: im8b
20 character*(*),
intent(in) :: filename, format, position
21 integer,
intent(in) :: lunit
22 integer,
intent(out) :: iret
30 call x84(lunit,my_lunit,1)
31 call fortran_open(filename,my_lunit,
format,position,iret)
38 open(lunit, file=trim(filename), form=trim(format), position=trim(position), iostat=iret)
50 use modv_vars,
only: im8b
53 integer,
intent(in) :: lunit
54 integer,
intent(out) :: iret
62 call x84(lunit,my_lunit,1)
70 close(lunit, iostat=iret)
167 recursive subroutine openbf(lunit,io,lundx)
171 use modv_vars,
only: im8b, ifopbf, nfiles, iprt
182 integer,
intent(in) :: lunit, lundx
183 integer my_lunit, my_lundx, iprtprv, lun, il, im
185 character*(*),
intent(in) :: io
186 character*255 filename, fileacc
187 character*128 bort_str, errstr
188 character*28 cprint(0:4)
192 ' (limited -default) ', &
193 ' (all warnings) ', &
194 ' (all warnings+infos) ', &
195 ' (all warnings+infos+debugs)'/
202 call x84(lunit,my_lunit,1)
203 call x84(lundx,my_lundx,1)
204 call openbf(my_lunit,io,my_lundx)
214 if(iprt<-1) iprt = -1
217 call errwrt(
'++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
218 write ( unit=errstr, fmt=
'(A,I3,A,A,I3,A)' )
'BUFRLIB: OPENBF - DEGREE OF MESSAGE PRINT INDICATOR CHNGED FROM', &
219 iprtprv,cprint(iprtprv+1),
' TO',iprt,cprint(iprt+1)
221 call errwrt(
'++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
239 if( (io==
'FIRST') .or. (io==
'QUIET') )
return
243 call status(lunit,lun,il,im)
245 write(bort_str,
'("BUFRLIB: OPENBF - THERE ARE ALREADY",I3," BUFR FILES OPENED, CANNOT OPEN FILE CONNECTED TO UNIT",I4)') &
250 write(bort_str,
'("BUFRLIB: OPENBF - THE FILE CONNECTED TO UNIT",I5," IS ALREADY OPEN")') lunit
260 if (io/=
'NUL' .and. io/=
'INUL')
then
261 inquire(lunit,access=fileacc)
262 if(fileacc==
'UNDEFINED')
open(lunit)
263 inquire(lunit,name=filename)
264 filename=trim(filename)//char(0)
277 call wtstat(lunit,lun,-1,0)
278 call readdx(lunit,lun,lundx)
279 else if(io==
'INUL')
then
280 call wtstat(lunit,lun,-1,0)
281 if(lunit/=lundx)
call readdx(lunit,lun,lundx)
283 else if(io==
'NUL')
then
284 call wtstat(lunit,lun,1,0)
285 if(lunit/=lundx)
call readdx(lunit,lun,lundx)
287 else if(io==
'INX')
then
289 call wtstat(lunit,lun,-1,0)
291 else if(io==
'OUX')
then
293 call wtstat(lunit,lun,1,0)
294 else if(io==
'SEC3')
then
296 call wtstat(lunit,lun,-1,0)
298 else if(io==
'OUT')
then
300 call wtstat(lunit,lun,1,0)
301 call writdx(lunit,lun,lundx)
302 else if(io==
'NODX')
then
304 call wtstat(lunit,lun,1,0)
305 call readdx(lunit,lun,lundx)
306 else if(io==
'APN' .or. io==
'APX')
then
308 call wtstat(lunit,lun,1,0)
309 if(lunit/=lundx)
call readdx(lunit,lun,lundx)
312 call bort(
'BUFRLIB: OPENBF - ILLEGAL SECOND (INPUT) ARGUMENT')
334 use modv_vars,
only: im8b
342 integer,
intent(in) :: lunit
343 integer my_lunit, lun, il, im
350 call x84(lunit,my_lunit,1)
357 if ( .not.
allocated(
null) )
then
358 call errwrt(
'++++++++++++++++++++WARNING++++++++++++++++++++++')
359 errstr =
'BUFRLIB: CLOSBF WAS CALLED WITHOUT HAVING PREVIOUSLY CALLED OPENBF'
361 call errwrt(
'++++++++++++++++++++WARNING++++++++++++++++++++++')
365 call status(lunit,lun,il,im)
366 if(il>0 .and. im/=0)
call closmg(lunit)
368 call wtstat(lunit,lun,0,0)
372 if(
null(lun)==0)
close(lunit)
398 recursive subroutine status(lunit,lun,il,im)
400 use modv_vars,
only: im8b, nfiles
406 integer,
intent(in) :: lunit
407 integer,
intent(out) :: lun, il, im
410 character*128 bort_str, errstr
417 call x84(lunit,my_lunit,1)
418 call status(my_lunit,lun,il,im)
427 if(lunit<=0 .or. lunit>99)
then
428 write(bort_str,
'("BUFRLIB: STATUS - INPUT UNIT NUMBER (",I3,") OUTSIDE LEGAL RANGE OF 1-99")') lunit
440 if ( .not.
allocated(
iolun) )
then
441 call errwrt(
'++++++++++++++++++++WARNING++++++++++++++++++++++')
442 errstr =
'BUFRLIB: STATUS WAS CALLED WITHOUT HAVING PREVIOUSLY CALLED OPENBF'
444 call errwrt(
'++++++++++++++++++++WARNING++++++++++++++++++++++')
449 if(abs(
iolun(i))==lunit) lun = i
468 il = sign(1,
iolun(lun))
507 integer,
intent(in) :: lunit, lun, il, im
509 character*128 bort_str
514 write(bort_str,
'("BUFRLIB: WTSTAT - INVALID UNIT NUMBER PASSED INTO FIRST ARGUMENT (INPUT) (=",I3,")")') lunit
518 write(bort_str,
'("BUFRLIB: WTSTAT - INVALID FILE ID PASSED INTO SECOND ARGUMENT (INPUT) (=",I3,")")') lun
521 if(il<-1 .or. il>1)
then
522 write(bort_str,
'("BUFRLIB: WTSTAT - INVALID LOGICAL UNIT STATUS INDICATOR PASSED INTO THIRD ARGUMENT '// &
523 '(INPUT) (=",I4,")")') il
526 if(im< 0 .or. im>1)
then
527 write(bort_str,
'("BUFRLIB: WTSTAT - INVALID BUFR MESSAGE STATUS INDICATOR PASSED INTO FOURTH ARGUMENT '// &
528 '(INPUT) (=",I4,")")') im
534 if(abs(
iolun(lun))/=lunit .and. (
iolun(lun)/=0))
then
535 write(bort_str,
'("BUFRLIB: WTSTAT - ATTEMPTING TO REDEFINE EXISTING FILE UNIT (LOGICAL UNIT '// &
536 'NUMBER ",I3,")")')
iolun(lun)
543 iolun(lun) = sign(lunit,il)
578 recursive subroutine ufbcnt(lunit,kmsg,ksub)
580 use modv_vars,
only: im8b
586 integer,
intent(in) :: lunit
587 integer,
intent(out) :: kmsg, ksub
588 integer my_lunit, lun, il, im
594 call x84(lunit,my_lunit,1)
595 call ufbcnt(my_lunit,kmsg,ksub)
596 call x48(kmsg,kmsg,1)
597 call x48(ksub,ksub,1)
604 call status(lunit,lun,il,im)
605 if(il==0)
call bort(
'BUFRLIB: UFBCNT - BUFR FILE IS CLOSED, IT MUST BE OPEN FOR EITHER INPUT OR OUTPUT')
631 integer,
intent(in) :: lunxx
632 integer lunit, lun, il, im, ier, idxmsg
636 call status(lunit,lun,il,im)
637 if(il==0)
call bort(
'BUFRLIB: POSAPX - INPUT BUFR FILE IS CLOSED, IT MUST BE OPEN FOR OUTPUT')
638 if(il<0)
call bort(
'BUFRLIB: POSAPX - INPUT BUFR FILE IS OPEN FOR INPUT, IT MUST BE OPEN FOR OUTPUT')
645 if(idxmsg(
mgwa)==1)
then
696 integer,
intent(in) :: lunit, isr
697 integer lun, il, im, i, kdate, ier
699 character*128 bort_str
704 call status(lunit,lun,il,im)
706 write(bort_str,
'("BUFRLIB: REWNBF - ATTEMPING TO SAVE '// &
707 'PARAMETERS FOR FILE FOR WHICH THEY HAVE ALREADY BEEN SAVED (AND NOT YET RESTORED) (UNIT",I3,")")') lunit
711 write(bort_str,
'("BUFRLIB: REWNBF - ATTEMPING TO SAVE '// &
712 'PARAMETERS FOR BUFR FILE WHICH IS NOT OPENED FOR EITHER INPUT OR OUTPUT) (UNIT",I3,")")') lunit
717 write(bort_str,
'("BUFRLIB: REWNBF - ATTEMPING TO RESTORE '// &
718 'PARAMETERS TO BUFR FILE WHICH WERE NEVER SAVED (UNIT",I3,")")') lunit
722 write(bort_str,
'("BUFRLIB: REWNBF - ATTEMPING TO RESTORE '// &
723 'PARAMETERS TO BUFR FILE WHICH WERE NEVER SAVED (UNIT",I3,")")') lunit
728 write(bort_str,
'("BUFRLIB: REWNBF - SAVE/RESTORE SWITCH (INPUT '// &
729 'ARGUMENT ISR) IS NOT ZERO OR ONE (HERE =",I4,") (UNIT",I3,")")') isr, lunit
749 call wtstat(lunit,lun,-1,0)
765 call readmg(lunit,subset,kdate,ier)
767 write(bort_str,
'("BUFRLIB: REWNBF - HIT END OF FILE BEFORE '// &
768 'REPOSITIONING BUFR FILE IN UNIT",I3," TO ORIGINAL MESSAGE NO.",I5)') lunit,
jmsg
791 call wtstat(lunit,lun,il,im)
795 jsr(lun) = mod(
jsr(lun)+1,2)
854 recursive subroutine ufbtab(lunin,tab,i1,i2,iret,str)
856 use modv_vars,
only: im8b, bmiss, iac, iprt
866 integer*8 ival, lref, ninc, mps, lps
867 integer,
intent(in) :: lunin, i1, i2
868 integer,
intent(out) :: iret
869 integer,
parameter :: maxtg = 100
870 integer nnod, ncon, nods, nodc, ivls, kons, my_lunin, my_i1, my_i2, lunit, lun, il, im, irec, isub, i, n, ntg, &
871 jdate, jbit, kbit, lbit, mbit, nbit, nibit, nbyt, nsb, node, nbmp, nrep, lret, linc, iac_prev, ityp, &
874 character*(*),
intent(in) :: str
877 character*10 tgs(maxtg)
878 character*8 subset, cval
880 logical openit, overflow, just_count, need_node
882 real*8,
intent(out) :: tab(i1,i2)
885 common /usrstr/ nnod, ncon, nods(20), nodc(10), ivls(10), kons(10)
887 equivalence(cval,rval)
890 mps(node) = 2_8**(
ibt(node))-1
891 lps(lbit) = max(2_8**(lbit)-1,1)
896 call x84(lunin,my_lunin,1)
899 call ufbtab(my_lunin,tab,my_i1,my_i2,iret,str)
900 call x48(iret,iret,1)
910 call status(lunit,lun,il,im)
915 call openbf(lunit,
'INX',lunit)
922 tab(1:i1,1:i2) = bmiss
935 just_count = lunin<lunit
937 do while(
ireadmg(-lunit,subset,jdate)>=0)
938 iret = iret+
nmsub(lunit)
942 call parstr(str,tgs,maxtg,ntg,
' ',.true.)
944 if(tgs(i)==
'IREC') irec = i
945 if(tgs(i)==
'ISUB') isub = i
949 outer:
do while (.not. just_count)
951 if(
ireadmg(-lunit,subset,jdate)<0)
exit
953 if(irec>0) nods(irec) = 0
954 if(isub>0) nods(isub) = 0
959 inner1:
do while (.true.)
961 if(
nsub(lun)==
msub(lun)) cycle outer
968 nods(i) = abs(nods(i))
971 mbit =
mbyt(lun)*8 + 16
978 inner2:
do while (.true.)
980 if(n+1<=
nval(lun))
then
985 if(
itp(node)==1)
then
986 call upb8(ival,nbit,mbit,
mbay(1,lun))
991 if(nods(i)==node)
then
992 if(
itp(node)==1)
then
993 call upb8(ival,nbit,mbit,
mbay(1,lun))
995 elseif(
itp(node)==2)
then
996 call upb8(ival,nbit,mbit,
mbay(1,lun))
997 if(ival<mps(node)) tab(i,iret) =
ups(ival,node)
998 elseif(
itp(node)==3)
then
1001 call upc(cval,nbit/8,
mbay(1,lun),kbit,.true.)
1009 if(nods(i)>0) cycle inner2
1023 if(irec>0) tab(irec,iret) =
nmsg(lun)
1024 if(isub>0) tab(isub,iret) =
nsub(lun)
1030 if(iret+
msub(lun)>i2)
then
1034 if(irec>0.or.isub>0)
then
1036 if(irec>0) tab(irec,iret+nsb) =
nmsg(lun)
1037 if(isub>0) tab(isub,iret+nsb) = nsb
1043 inner3:
do while ( n <
nval(lun) )
1052 nods(i) = abs(nods(i))
1063 if(.not. need_node)
exit inner3
1065 if(ityp==1 .or. ityp==2)
then
1069 elseif(ityp==3)
then
1080 call up8(ninc,linc,
mbay(1,lun),jbit)
1082 call usrtpl(lun,n,int(ival))
1086 if(node==nods(i))
then
1090 if(ityp==1 .or. ityp==2)
then
1092 jbit =
ibit + linc*(nsb-1)
1093 call up8(ninc,linc,
mbay(1,lun),jbit)
1096 if(ninc<lps(linc)) tab(i,lret) =
ups(ival,node)
1098 elseif(ityp==3)
then
1103 jbit =
ibit + linc*(nsb-1)*8
1105 call upc(cval,linc,
mbay(1,lun),jbit,.true.)
1111 call bort(
'UFBTAB - INVALID ELEMENT TYPE SPECIFIED')
1117 iret = iret+
msub(lun)
1128 do while(
ireadmg(-lunit,subset,jdate)>=0)
1129 nrep = nrep+
nmsub(lunit)
1132 call errwrt(
'+++++++++++++++++++++WARNING+++++++++++++++++++++++')
1133 write ( unit=errstr, fmt=
'(A,A,I8,A)' )
'BUFRLIB: UFBTAB - THE NO. OF DATA SUBSETS IN THE BUFR FILE ', &
1134 .GT.
'IS LIMIT OF ', i2,
' IN THE 4TH ARG. (INPUT) - INCOMPLETE READ'
1136 write ( unit=errstr, fmt=
'(A,I8,A,I8,A)' )
'>>>UFBTAB STORED ', iret,
' REPORTS OUT OF ', nrep,
'<<<'
1138 call errwrt(
'+++++++++++++++++++++WARNING+++++++++++++++++++++++')
subroutine arallocf
Dynamically allocate Fortran language arrays.
subroutine bort(str)
Log an error message, then abort the application program.
subroutine upb(nval, nbits, ibay, ibit)
Decode an integer value from within a specified number of bits of an integer array,...
subroutine upb8(nval, nbits, ibit, ibay)
Decode an 8-byte integer value from within a specified number of bits of an integer array,...
real *8 function ups(ival, node)
Unpack a real*8 value from an integer by applying the proper scale and reference values.
subroutine up8(nval, nbits, ibay, ibit)
Decode an 8-byte integer value from within a specified number of bits of an integer array,...
subroutine upc(chr, nchr, ibay, ibit, cnvnull)
Decode a character string from within a specified number of bytes of an integer array,...
subroutine writdx(lunit, lun, lundx)
Write DX BUFR table (dictionary) messages to the beginning of an output BUFR file in lunit.
subroutine readdx(lunit, lun, lundx)
Initialize modules moda_tababd and moda_msgcwd with DX BUFR (dictionary) tables.
subroutine rdbfdx(lunit, lun)
Beginning at the current file pointer location within lunit, read a complete DX BUFR table into inter...
subroutine errwrt(str)
Specify a custom location for the logging of error and diagnostic messages generated by the NCEPLIBS-...
subroutine bfrini
Initialize numerous global variables and arrays within internal modules and common blocks throughout ...
Wrap C NCEPLIBS-bufr functions so they can be called from within the Fortran part of the library.
Declare arrays and variables used to store BUFR messages internally for multiple file IDs.
integer ibit
Bit pointer within ibay.
integer, dimension(:,:), allocatable mbay
Current BUFR message for each file ID.
integer, dimension(:), allocatable mbyt
Length (in bytes) of current BUFR message for each file ID.
Declare arrays and variables needed to store the current position within a BUFR file.
integer jill
File status indicator of BUFR file.
integer jimm
Message status indicator of BUFR file.
integer, dimension(:), allocatable jsr
Indicator of stack status when entering subroutine rewnbf().
integer jmsg
Sequential number of BUFR message, counting from the beginning of the file.
integer jbit
Bit pointer within BUFR message.
integer jsub
Sequential number of BUFR data subset, counting from the beginning of the current BUFR message.
integer junn
File ID of BUFR file.
integer jbyt
Length (in bytes) of BUFR message.
integer, dimension(:), allocatable jbay
BUFR message.
Declare an array used by subroutine makestab() to keep track of which logical units share DX BUFR tab...
integer, dimension(:), allocatable lus
Tracking index for each file ID.
Declare an array used by various subroutines and functions to hold a temporary working copy of a BUFR...
integer, dimension(:), allocatable mgwa
Temporary working copy of BUFR message.
Declare arrays used to store information about the current BUFR message that is in the process of bei...
integer, dimension(:), allocatable inode
Table A mnemonic for type of BUFR message.
integer, dimension(:), allocatable idate
Section 1 date-time of message.
integer, dimension(:), allocatable nmsg
Current message pointer within logical unit.
integer, dimension(:), allocatable msub
Total number of data subsets in message.
integer, dimension(:), allocatable nsub
Current subset pointer within message.
Declare an array used to store a switch for each file ID, indicating whether any BUFR messages should...
integer, dimension(:), allocatable null
Output switch for each file ID:
Declare an array used to store a switch for each file ID, indicating whether BUFR messages read from ...
integer, dimension(:), allocatable isc3
Section 3 switch 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 the internal jump/link table.
integer, dimension(:), allocatable ibt
Bit widths corresponding to tag and typ:
integer, dimension(:), allocatable itp
Integer type values corresponding to typ:
Declare an array used to store, for each file ID from which a BUFR message is currently being read as...
integer, dimension(:), allocatable msgunp
Flag indicating how to unpack data subsets from BUFR message:
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.
integer, dimension(:,:), allocatable, target inv
Inventory pointer which links each data value to its corresponding node in the internal jump/link tab...
recursive subroutine closbf(lunit)
Close the connection between logical unit lunit and the NCEPLIBS-bufr software.
subroutine rewnbf(lunit, isr)
Store or restore parameters associated with a BUFR file.
recursive subroutine fortran_open(filename, lunit, format, position, iret)
Open a Fortran file on the local system.
recursive subroutine openbf(lunit, io, lundx)
Connect a new file to the NCEPLIBS-bufr software for input or output operations, or initialize the li...
recursive subroutine fortran_close(lunit, iret)
Close a Fortran file on the local system.
recursive subroutine ufbcnt(lunit, kmsg, ksub)
Get the current location of the file pointer within a BUFR file, in terms of a message number countin...
recursive subroutine status(lunit, lun, il, im)
Check whether a specified Fortran logical unit number is currently connected to the NCEPLIBS-bufr sof...
subroutine wtstat(lunit, lun, il, im)
Update file status in library internals.
recursive subroutine ufbtab(lunin, tab, i1, i2, iret, str)
Read through every data subset in a BUFR file and return one or more specified data values from each ...
subroutine posapx(lunxx)
Position an output BUFR file for appending.
recursive subroutine closmg(lunin)
Close the BUFR message that is currently open for writing within internal arrays associated with logi...
recursive integer function nmsub(lunit)
Get the total number of data subsets available within the BUFR message that was most recently opened ...
recursive subroutine readmg(lunxx, subset, jdate, iret)
Read the next BUFR message from logical unit abs(lunxx) into internal arrays.
subroutine rdmsgw(lunit, mesg, iret)
Read the next BUFR message from logical unit lunit as an array of integer words.
recursive integer function ireadmg(lunit, subset, idate)
Call subroutine readmg() and pass back its return code as the function value.
subroutine usrtpl(lun, invn, nbmp)
Expand a subset template within internal arrays.
recursive integer function ireadsb(lunit)
Call subroutine readsb() and pass back its return code as the function value.
recursive subroutine readsb(lunit, iret)
Read the next data subset from a BUFR message.
subroutine parstr(str, tags, mtag, ntag, sep, limit80)
Parse a string containing one or more substrings into an array of substrings.
subroutine string(str, lun, i1, io)
Check whether a string is in the internal mnemonic string cache.
subroutine x48(iin4, iout8, nval)
Encode one or more 4-byte integer values as 8-byte integer values.
subroutine x84(iin8, iout4, nval)
Encode one or more 8-byte integer values as 4-byte integer values.