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
29 call x84(lunit,my_lunit,1)
30 call fortran_open(filename,my_lunit,
format,position,iret)
36 open(lunit, file=trim(filename), form=trim(format), position=trim(position), iostat=iret)
48 use modv_vars,
only: im8b
51 integer,
intent(in) :: lunit
52 integer,
intent(out) :: iret
59 call x84(lunit,my_lunit,1)
66 close(lunit, iostat=iret)
163 recursive subroutine openbf(lunit,io,lundx)
167 use modv_vars,
only: im8b, ifopbf, nfiles, iprt
178 integer,
intent(in) :: lunit, lundx
179 integer my_lunit, my_lundx, iprtprv, lun, il, im, lcio,
bort_target_set
181 character*(*),
intent(in) :: io
182 character*255 filename, fileacc
183 character*128 bort_str, errstr
184 character*28 cprint(0:4)
189 ' (limited -default) ', &
190 ' (all warnings) ', &
191 ' (all warnings+infos) ', &
192 ' (all warnings+infos+debugs)'/
198 call x84(lunit,my_lunit,1)
199 call x84(lundx,my_lundx,1)
200 call openbf(my_lunit,io,my_lundx)
218 if(iprt<-1) iprt = -1
221 call errwrt(
'++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
222 write ( unit=errstr, fmt=
'(A,I3,A,A,I3,A)' )
'BUFRLIB: OPENBF - DEGREE OF MESSAGE PRINT INDICATOR CHNGED FROM', &
223 iprtprv,cprint(iprtprv+1),
' TO',iprt,cprint(iprt+1)
225 call errwrt(
'++++++++++++++BUFR ARCHIVE LIBRARY+++++++++++++++++')
243 if( (io==
'FIRST') .or. (io==
'QUIET') )
return
247 call status(lunit,lun,il,im)
249 write(bort_str,
'("BUFRLIB: OPENBF - THERE ARE ALREADY",I3," BUFR FILES OPENED, CANNOT OPEN FILE CONNECTED TO UNIT",I4)') &
254 write(bort_str,
'("BUFRLIB: OPENBF - THE FILE CONNECTED TO UNIT",I5," IS ALREADY OPEN")') lunit
264 if (io/=
'NUL' .and. io/=
'INUL')
then
265 inquire(lunit,access=fileacc)
266 if(fileacc==
'UNDEFINED')
open(lunit)
267 inquire(lunit,name=filename)
268 filename=trim(filename)//char(0)
281 call wtstat(lunit,lun,-1,0)
282 call readdx(lunit,lun,lundx)
283 else if(io==
'INUL')
then
284 call wtstat(lunit,lun,-1,0)
285 if(lunit/=lundx)
call readdx(lunit,lun,lundx)
287 else if(io==
'NUL')
then
288 call wtstat(lunit,lun,1,0)
289 if(lunit/=lundx)
call readdx(lunit,lun,lundx)
291 else if(io==
'INX')
then
293 call wtstat(lunit,lun,-1,0)
295 else if(io==
'OUX')
then
297 call wtstat(lunit,lun,1,0)
298 else if(io==
'SEC3')
then
300 call wtstat(lunit,lun,-1,0)
302 else if(io==
'OUT')
then
304 call wtstat(lunit,lun,1,0)
305 call writdx(lunit,lun,lundx)
306 else if(io==
'NODX')
then
308 call wtstat(lunit,lun,1,0)
309 call readdx(lunit,lun,lundx)
310 else if(io==
'APN' .or. io==
'APX')
then
312 call wtstat(lunit,lun,1,0)
313 if(lunit/=lundx)
call readdx(lunit,lun,lundx)
316 call bort(
'BUFRLIB: OPENBF - ILLEGAL SECOND (INPUT) ARGUMENT')
338 use modv_vars,
only: im8b
346 integer,
intent(in) :: lunit
353 call x84(lunit,my_lunit,1)
367 if ( .not.
allocated(
null) )
then
368 call errwrt(
'++++++++++++++++++++WARNING++++++++++++++++++++++')
369 errstr =
'BUFRLIB: CLOSBF WAS CALLED WITHOUT HAVING PREVIOUSLY CALLED OPENBF'
371 call errwrt(
'++++++++++++++++++++WARNING++++++++++++++++++++++')
375 call status(lunit,lun,il,im)
376 if(il>0 .and. im/=0)
call closmg(lunit)
378 call wtstat(lunit,lun,0,0)
382 if(
null(lun)==0)
close(lunit)
408 recursive subroutine status(lunit,lun,il,im)
412 use modv_vars,
only: im8b, nfiles
418 integer,
intent(in) :: lunit
419 integer,
intent(out) :: lun, il, im
422 character*128 bort_str, errstr
428 call x84(lunit,my_lunit,1)
429 call status(my_lunit,lun,il,im)
445 if(lunit<=0 .or. lunit>99)
then
446 write(bort_str,
'("BUFRLIB: STATUS - INPUT UNIT NUMBER (",I3,") OUTSIDE LEGAL RANGE OF 1-99")') lunit
458 if ( .not.
allocated(
iolun) )
then
459 call errwrt(
'++++++++++++++++++++WARNING++++++++++++++++++++++')
460 errstr =
'BUFRLIB: STATUS WAS CALLED WITHOUT HAVING PREVIOUSLY CALLED OPENBF'
462 call errwrt(
'++++++++++++++++++++WARNING++++++++++++++++++++++')
467 if(abs(
iolun(i))==lunit) lun = i
486 il = sign(1,
iolun(lun))
525 integer,
intent(in) :: lunit, lun, il, im
527 character*128 bort_str
532 write(bort_str,
'("BUFRLIB: WTSTAT - INVALID UNIT NUMBER PASSED INTO FIRST ARGUMENT (INPUT) (=",I3,")")') lunit
536 write(bort_str,
'("BUFRLIB: WTSTAT - INVALID FILE ID PASSED INTO SECOND ARGUMENT (INPUT) (=",I3,")")') lun
539 if(il<-1 .or. il>1)
then
540 write(bort_str,
'("BUFRLIB: WTSTAT - INVALID LOGICAL UNIT STATUS INDICATOR PASSED INTO THIRD ARGUMENT '// &
541 '(INPUT) (=",I4,")")') il
544 if(im< 0 .or. im>1)
then
545 write(bort_str,
'("BUFRLIB: WTSTAT - INVALID BUFR MESSAGE STATUS INDICATOR PASSED INTO FOURTH ARGUMENT '// &
546 '(INPUT) (=",I4,")")') im
552 if(abs(
iolun(lun))/=lunit .and. (
iolun(lun)/=0))
then
553 write(bort_str,
'("BUFRLIB: WTSTAT - ATTEMPTING TO REDEFINE EXISTING FILE UNIT (LOGICAL UNIT '// &
554 'NUMBER ",I3,")")')
iolun(lun)
561 iolun(lun) = sign(lunit,il)
596 recursive subroutine ufbcnt(lunit,kmsg,ksub)
600 use modv_vars,
only: im8b
606 integer,
intent(in) :: lunit
607 integer,
intent(out) :: kmsg, ksub
614 call x84(lunit,my_lunit,1)
615 call ufbcnt(my_lunit,kmsg,ksub)
616 call x48(kmsg,kmsg,1)
617 call x48(ksub,ksub,1)
632 call status(lunit,lun,il,im)
633 if(il==0)
call bort(
'BUFRLIB: UFBCNT - BUFR FILE IS CLOSED, IT MUST BE OPEN FOR EITHER INPUT OR OUTPUT')
659 integer,
intent(in) :: lunxx
660 integer lunit, lun, il, im, ier, idxmsg
664 call status(lunit,lun,il,im)
665 if(il==0)
call bort(
'BUFRLIB: POSAPX - INPUT BUFR FILE IS CLOSED, IT MUST BE OPEN FOR OUTPUT')
666 if(il<0)
call bort(
'BUFRLIB: POSAPX - INPUT BUFR FILE IS OPEN FOR INPUT, IT MUST BE OPEN FOR OUTPUT')
673 if(idxmsg(
mgwa)==1)
then
724 integer,
intent(in) :: lunit, isr
725 integer lun, il, im, i, kdate, ier
727 character*128 bort_str
732 call status(lunit,lun,il,im)
734 write(bort_str,
'("BUFRLIB: REWNBF - ATTEMPING TO SAVE '// &
735 'PARAMETERS FOR FILE FOR WHICH THEY HAVE ALREADY BEEN SAVED (AND NOT YET RESTORED) (UNIT",I3,")")') lunit
739 write(bort_str,
'("BUFRLIB: REWNBF - ATTEMPING TO SAVE '// &
740 'PARAMETERS FOR BUFR FILE WHICH IS NOT OPENED FOR EITHER INPUT OR OUTPUT) (UNIT",I3,")")') lunit
745 write(bort_str,
'("BUFRLIB: REWNBF - ATTEMPING TO RESTORE '// &
746 'PARAMETERS TO BUFR FILE WHICH WERE NEVER SAVED (UNIT",I3,")")') lunit
750 write(bort_str,
'("BUFRLIB: REWNBF - ATTEMPING TO RESTORE '// &
751 'PARAMETERS TO BUFR FILE WHICH WERE NEVER SAVED (UNIT",I3,")")') lunit
756 write(bort_str,
'("BUFRLIB: REWNBF - SAVE/RESTORE SWITCH (INPUT '// &
757 'ARGUMENT ISR) IS NOT ZERO OR ONE (HERE =",I4,") (UNIT",I3,")")') isr, lunit
777 call wtstat(lunit,lun,-1,0)
793 call readmg(lunit,subset,kdate,ier)
795 write(bort_str,
'("BUFRLIB: REWNBF - HIT END OF FILE BEFORE '// &
796 'REPOSITIONING BUFR FILE IN UNIT",I3," TO ORIGINAL MESSAGE NO.",I5)') lunit,
jmsg
819 call wtstat(lunit,lun,il,im)
823 jsr(lun) = mod(
jsr(lun)+1,2)
896 recursive subroutine ufbtab(lunin,tab,i1,i2,iret,str)
900 use modv_vars,
only: part, im8b, bmiss, iac, iprt
910 integer*8 ival, lref, ninc, mps, lps
911 integer,
intent(in) :: lunin, i1, i2
912 integer,
intent(inout) :: iret
913 integer,
parameter :: maxtg = 100
914 integer nnod, ncon, nods, nodc, ivls, kons, my_lunin, my_i1, my_i2, lunit, lun, il, im, irec, isub, i, n, ntg, &
915 jdate, jbit, kbit, lbit, mbit, nbit, nibit, nbyt, nsb, node, nbmp, nrep, lret, linc, iac_prev, ityp, &
918 character*(*),
intent(in) :: str
922 character*10 tgs(maxtg)
923 character*8 subset, cval
925 logical :: openit, overflow, just_count, need_node, need_newmsg
927 real*8,
intent(out) :: tab(i1,i2)
930 common /usrstr/ nnod, ncon, nods(20), nodc(10), ivls(10), kons(10)
934 equivalence(cval,rval)
937 mps(node) = 2_8**(
ibt(node))-1
938 lps(lbit) = max(2_8**(lbit)-1,1)
943 call x84(lunin,my_lunin,1)
946 call ufbtab(my_lunin,tab,my_i1,my_i2,iret,str)
947 call x48(iret,iret,1)
954 call strsuc(str,cstr,lcstr)
965 tab(1:i1,1:i2) = bmiss
971 just_count = lunin<lunit
972 if (.not. just_count)
then
974 call parstr(str,tgs,maxtg,ntg,
' ',.true.)
976 if(tgs(i)==
'IREC') irec = i
977 if(tgs(i)==
'ISUB') isub = i
983 if(part.and.iret<0)
then
986 need_newmsg = .false.
992 call status(lunit,lun,il,im)
996 call openbf(lunit,
'INX',lunit)
1001 need_newmsg = .true.
1005 do while(
ireadmg(-lunit,subset,jdate)>=0)
1006 iret = iret+
nmsub(lunit)
1011 outer:
do while (.not. just_count)
1013 if(need_newmsg)
then
1015 if(
ireadmg(-lunit,subset,jdate)<0)
exit
1016 call string(str,lun,i1,0)
1017 if(irec>0) nods(irec) = 0
1018 if(isub>0) nods(isub) = 0
1026 inner1:
do while (.true.)
1028 if(
nsub(lun)==
msub(lun)) cycle outer
1040 nods(i) = abs(nods(i))
1043 mbit =
mbyt(lun)*8 + 16
1050 inner2:
do while (.true.)
1052 if(n+1<=
nval(lun))
then
1057 if(
itp(node)==1)
then
1058 call upb8(ival,nbit,mbit,
mbay(1,lun))
1063 if(nods(i)==node)
then
1064 if(
itp(node)==1)
then
1065 call upb8(ival,nbit,mbit,
mbay(1,lun))
1067 elseif(
itp(node)==2)
then
1068 call upb8(ival,nbit,mbit,
mbay(1,lun))
1069 if(ival<mps(node)) tab(i,iret) =
ups(ival,node)
1070 elseif(
itp(node)==3)
then
1073 call upc(cval,nbit/8,
mbay(1,lun),kbit,.true.)
1081 if(nods(i)>0) cycle inner2
1095 if(irec>0) tab(irec,iret) =
nmsg(lun)
1096 if(isub>0) tab(isub,iret) =
nsub(lun)
1102 if(iret+
msub(lun)>i2)
then
1111 if(irec>0.or.isub>0)
then
1113 if(irec>0) tab(irec,iret+nsb) =
nmsg(lun)
1114 if(isub>0) tab(isub,iret+nsb) = nsb
1120 inner3:
do while ( n <
nval(lun) )
1129 nods(i) = abs(nods(i))
1140 if(.not. need_node)
exit inner3
1142 if(ityp==1 .or. ityp==2)
then
1146 elseif(ityp==3)
then
1157 call up8(ninc,linc,
mbay(1,lun),jbit)
1159 call usrtpl(lun,n,int(ival))
1163 if(node==nods(i))
then
1167 if(ityp==1 .or. ityp==2)
then
1169 jbit =
ibit + linc*(nsb-1)
1170 call up8(ninc,linc,
mbay(1,lun),jbit)
1173 if(ninc<lps(linc)) tab(i,lret) =
ups(ival,node)
1175 elseif(ityp==3)
then
1180 jbit =
ibit + linc*(nsb-1)*8
1182 call upc(cval,linc,
mbay(1,lun),jbit,.true.)
1188 call bort(
'UFBTAB - INVALID ELEMENT TYPE SPECIFIED')
1194 iret = iret+
msub(lun)
1205 do while(
ireadmg(-lunit,subset,jdate)>=0)
1206 nrep = nrep+
nmsub(lunit)
1209 call errwrt(
'+++++++++++++++++++++WARNING+++++++++++++++++++++++')
1210 write ( unit=errstr, fmt=
'(A,A,I8,A)' )
'BUFRLIB: UFBTAB - THE NO. OF DATA SUBSETS IN THE BUFR FILE ', &
1211 .GT.
'IS LIMIT OF ', i2,
' IN THE 4TH ARG. (INPUT) - INCOMPLETE READ'
1213 write ( unit=errstr, fmt=
'(A,I8,A,I8,A)' )
'>>>UFBTAB STORED ', iret,
' REPORTS OUT OF ', nrep,
'<<<'
1215 call errwrt(
'+++++++++++++++++++++WARNING+++++++++++++++++++++++')
1260 use modv_vars,
only: part
1264 logical,
intent(in) :: xpart
subroutine arallocf
Dynamically allocate Fortran language arrays.
recursive subroutine bort(str)
Log an error message, then either return to or abort the application program.
subroutine bort_target_unset
Clear any existing bort target.
integer function bort_target_set()
Sets a new bort target, if bort catching is enabled and such a target doesn't already exist.
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 strsuc(str1, str2, lens)
Remove leading and trailing blanks from a character string.
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...
subroutine setpart(xpart)
Specify whether future calls to subroutine ufbtab() should attempt to return full or partial results.
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.