1 REAL*8 FUNCTION GETVALNB
( LUNIT
, TAGPV
, NTAGPV
, TAGNB
, NTAGNB
)
3 C$$$ SUBPROGRAM DOCUMENTATION BLOCK
6 C PRGMMR: J. ATOR ORG: NP12 DATE: 2012-09-12
8 C ABSTRACT: THIS FUNCTION SHOULD ONLY BE CALLED WHEN A BUFR FILE IS
9 C OPENED FOR INPUT, AND A SUBSET DEFINITION MUST ALREADY BE IN SCOPE
10 C VIA A PREVIOUS CALL TO BUFR ARCHIVE LIBRARY SUBROUTINE READSB OR
11 C EQUIVALENT. THE FUNCTION WILL FIRST SEARCH FOR THE (NTAGPV)th
12 C OCCURRENCE OF MNEMONIC TAGPV WITHIN THE OVERALL SUBSET DEFINITION,
13 C COUNTING FROM THE BEGINNING OF THE SUBSET. IF FOUND, IT WILL THEN
14 C SEARCH FORWARD (IF NTAGNB IS POSITIVE) OR BACKWARD (IF NTAGNB IS
15 C NEGATIVE) FROM THAT POINT WITHIN THE SUBSET FOR THE (NTAGNB)th
16 C OCCURRENCE OF MNEMONIC TAGNB AND RETURN THE VALUE CORRESPONDING
19 C PROGRAM HISTORY LOG:
20 C 2012-09-12 J. ATOR -- ORIGINAL AUTHOR
22 C USAGE: CALL GETVALNB (LUNIT, TAGPV, NTAGPV, TAGNB, NTAGNB)
23 C INPUT ARGUMENT LIST:
24 C LUNIT - INTEGER: FORTRAN LOGICAL UNIT NUMBER FOR BUFR FILE
25 C TAGPV - CHARACTER*(*): PIVOT MNEMONIC; THE FUNCTION WILL
26 C FIRST SEARCH FOR the (NTAGPV)th OCCURRENCE OF THIS
27 C MNEMONIC, COUNTING FROM THE BEGINNING OF THE OVERALL
29 C NTAGPV - INTEGER: ORDINAL OCCURRENCE OF TAGPV TO SEARCH FOR
30 C TAGNB - CHARACTER*(*): NEARBY MNEMONIC; ASSUMING TAGPV IS
31 C SUCCESSFULLY FOUND, THE FUNCTION WILL THEN SEARCH
32 C NEARBY FOR THE (NTAGNB)th OCCURRENCE OF TAGNB AND
33 C RETURN THE CORRESPONDING VALUE
34 C NTAGNB - INTEGER: ORDINAL OCCURRENCE OF TAGNB TO SEARCH FOR,
35 C COUNTING FROM THE LOCATION OF TAGPV WITHIN THE OVERALL
36 C SUBSET DEFINITION. IF TAGNB IS POSITIVE, THE FUNCTION
37 C WILL SEARCH IN A FORWARD DIRECTION FROM THE LOCATION OF
38 C TAGPV, OR IF TAGNB IS NEGATIVE IT WILL INSTEAD SEARCH
39 C IN A BACKWARDS DIRECTION.
41 C OUTPUT ARGUMENT LIST:
42 C GETVALNB - REAL*8: VALUE CORRESPONDING TO (NTAGNB)th OCCURRENCE
43 C OF TAGNB. IF FOR ANY REASON THIS VALUE CANNOT BE
44 C LOCATED, THEN THE BUFR ARCHIVE LIBRARY MISSING VALUE
45 C BMISS WILL BE RETURNED.
48 C THIS ROUTINE CALLS: PARSTR STATUS
49 C THIS ROUTINE IS CALLED BY: None
50 C Normally called only by application
54 C LANGUAGE: FORTRAN 77
55 C MACHINE: PORTABLE TO ALL PLATFORMS
61 COMMON /MSGCWD
/ NMSG
(NFILES
),NSUB
(NFILES
),MSUB
(NFILES
),
62 . INODE
(NFILES
),IDATE
(NFILES
)
63 COMMON /BTABLES
/ MAXTAB
,NTAB
,TAG
(MAXJL
),TYP
(MAXJL
),KNT
(MAXJL
),
64 . JUMP
(MAXJL
),LINK
(MAXJL
),JMPB
(MAXJL
),
65 . IBT
(MAXJL
),IRF
(MAXJL
),ISC
(MAXJL
),
66 . ITP
(MAXJL
),VALI
(MAXJL
),KNTI
(MAXJL
),
67 . ISEQ
(MAXJL
,2),JSEQ
(MAXJL
)
68 COMMON /USRINT
/ NVAL
(NFILES
),INV
(MAXSS
,NFILES
),VAL
(MAXSS
,NFILES
)
70 CHARACTER*10 TAG
,TGS
(15)
73 CHARACTER*
(*) TAGPV
, TAGNB
81 C----------------------------------------------------------------------
82 C----------------------------------------------------------------------
88 CALL STATUS
(LUNIT
,LUN
,IL
,IM
)
90 IF (INODE
(LUN
).NE
.INV
(1,LUN
)) RETURN
92 C Locate the (NTAGPV)th occurrence of TAGPV.
94 CALL PARSTR
(TAGPV
,TGS
,MAXTG
,NTG
,' ',.TRUE
.)
100 DO WHILE ((.NOT
.GOTNODPV
).AND
.(N
.LE
.NVAL
(LUN
)))
102 IF(TGS
(1).EQ
.TAG
(NOD
)) THEN
104 IF(ITAGCT
.EQ
.NTAGPV
) THEN
113 IF (.NOT
.GOTNODPV
) RETURN
115 C Starting from TAGPV, search nearby for the
116 C +/-(NTAGNB)th occurrence of TAGNB.
118 CALL PARSTR
(TAGNB
,TGS
,MAXTG
,NTG
,' ',.TRUE
.)
121 ISTEP
= ISIGN
(1,NTAGNB
)
124 DO WHILE ((N
.GE
.1).AND
.(N
.LE
.NVAL
(LUN
)))
126 IF(TGS
(1).EQ
.TAG
(NOD
)) THEN
128 IF(ITAGCT
.EQ
.IABS
(NTAGNB
)) THEN
129 GETVALNB
= VAL
(N
,LUN
)