23 integer,
intent(in) :: lugb, lugi, idxver
24 character*(*) :: filename
25 integer,
intent(out) :: iret
27 integer (kind = 8) :: msk1, msk2
28 parameter(msk1 = 32000_8, msk2 = 4000_8)
29 character(len=1),
pointer,
dimension(:) :: cbuf
30 integer :: numtot, nnum, nlen, mnum, kw
31 integer :: irgi, iw, nmess
34 subroutine getg2i2r(lugb, msk1, msk2, mnum, idxver, cbuf, &
35 nlen, nnum, nmess, iret)
36 integer,
intent(in) :: lugb
37 integer (kind = 8),
intent(in) :: msk1, msk2
38 integer,
intent(in) :: mnum, idxver
39 character(len = 1),
pointer,
dimension(:) :: cbuf
40 integer,
intent(out) :: nlen, nnum, nmess, iret
52 call getg2i2r(lugb, msk1, msk2, mnum, idxver, cbuf, &
53 nlen, nnum, nmess, irgi)
54 if (irgi .gt. 1 .or. nnum .eq. 0 .or. nlen .eq. 0)
then
58 numtot = numtot + nnum
66 call bawrite(lugi, iw, nlen, kw, cbuf)
71 do while (irgi .eq. 1 .and. nnum .gt. 0)
72 if (
associated(cbuf))
then
76 call getg2i2r(11, msk1, msk2, mnum, idxver, cbuf, &
77 nlen, nnum, nmess, irgi)
78 if (irgi .le. 1 .and. nnum .gt. 0)
then
79 numtot = numtot + nnum
81 call bawrite(lugi, iw, nlen, kw, cbuf)
105 integer,
intent(in) :: lugi, nlen, nnum, idxver
106 character,
intent(in) :: filename*(*)
108 character cd8*8, ct10*10, hostname*15
115 character chead(2)*81
119 call date_and_time(cd8, ct10)
121 chead(1)(9:10) =
' 1'
122 chead(1)(12:14) =
' 1'
123 write(chead(1)(16:20),
'(i5)') 162
124 chead(1)(22:31) = cd8(1:4) //
'-' // cd8(5:6) //
'-' // cd8(7:8)
125 chead(1)(33:40) = ct10(1:2) //
':' // ct10(3:4) //
':' // ct10(5:6)
126 chead(1)(42:47) =
'GB2IX1'
127 chead(1)(49:54) =
' '
129 istat = hostnm(hostname)
130 if (istat .eq. 0)
then
131 chead(1)(56:70) =
'0000'
133 chead(1)(56:70) =
'0001'
136 chead(1)(56:70) = hostnam(hostname)
138 chead(1)(72:80) =
'grb2index'
139 chead(1)(81:81) = char(10)
142 if (idxver .eq. 1)
then
143 chead(2) =
'IX1FORM:'
145 chead(2) =
'IX2FORM:'
147 write(chead(2)(9:38),
'(3i10)') 162, nlen, nnum
148 chead(2)(41:80) = filename
149 chead(2)(81:81) = char(10)
152 call bawrite(lugi, 0, 162, kw, chead)
197 subroutine getidx(lugb, lugi, cindex, nlen, nnum, iret)
200 integer,
intent(in) :: lugb, lugi
201 character(len = 1),
pointer,
dimension(:) :: cindex
202 integer,
intent(out) :: nlen, nnum, iret
206 subroutine getidx2(lugb, lugi, idxver, cindex, nlen, nnum, iret)
207 integer,
intent(in) :: lugb, lugi
208 integer,
intent(inout) :: idxver
209 character(len = 1),
pointer,
dimension(:) :: cindex
210 integer,
intent(out) :: nlen, nnum, iret
217 call getidx2(lugb, lugi, idxver, cindex, nlen, nnum, iret)
220 if (iret .eq. 0 .and. idxver .eq. 2) iret = 97
265 subroutine getidx2(lugb, lugi, idxver, cindex, nlen, nnum, iret)
269 integer,
intent(in) :: lugb, lugi
270 integer,
intent(inout) :: idxver
271 character(len = 1),
pointer,
dimension(:) :: cindex
272 integer,
intent(out) :: nlen, nnum, iret
274 integer,
parameter :: maxidx = 10000
275 integer (kind = 8),
parameter :: msk1 = 32000_8, msk2 = 4000_8
277 integer :: irgi, mskp, nmess, i
283 character(len = 1),
pointer,
dimension(:) :: cbuf
286 type(gindex),
save :: idxlist(10000)
292 subroutine getg2i2(lugi, cbuf, idxver, nlen, nnum, iret)
293 integer,
intent(in) :: lugi
294 character(len=1),
pointer,
dimension(:) :: cbuf
295 integer,
intent(out) :: idxver, nlen, nnum, iret
297 subroutine getg2i2r(lugb, msk1, msk2, mnum, idxver, cbuf, &
298 nlen, nnum, nmess, iret)
299 integer,
intent(in) :: lugb
300 integer (kind = 8),
intent(in) :: msk1, msk2
301 integer,
intent(in) :: mnum, idxver
302 character(len = 1),
pointer,
dimension(:) :: cbuf
303 integer,
intent(out) :: nlen, nnum, nmess, iret
309 write(
g2_log_msg,
'(a, i2, a, i2, a, i1)')
'getidx2: lugb ', lugb,
' lugi ', lugi, &
315 if (lugb .eq. 0)
then
318 if (
associated(idxlist(i)%cbuf))
then
320 deallocate(idxlist(i)%cbuf)
321 nullify(idxlist(i)%cbuf)
331 if (lugb .le. 0 .or. lugb .gt. 9999)
then
332 print *,
' file unit number out of range'
333 print *,
' use unit numbers in range: 0 - 9999 '
339 if (lugi .eq. lugb)
then
340 if (
associated(idxlist(lugb)%cbuf)) &
341 deallocate(idxlist(lugb)%cbuf)
343 nullify(idxlist(lugb)%cbuf)
344 idxlist(lugb)%nlen = 0
345 idxlist(lugb)%nnum = 0
350 if (lugi .lt. 0)
then
352 if (
associated(idxlist(lugb)%cbuf)) &
353 deallocate(idxlist(lugb)%cbuf)
355 nullify(idxlist(lugb)%cbuf)
356 idxlist(lugb)%nlen = 0
357 idxlist(lugb)%nnum = 0
362 if (
associated(idxlist(lugb)%cbuf))
then
364 cindex => idxlist(lugb)%cbuf
365 nlen = idxlist(lugb)%nlen
366 nnum = idxlist(lugb)%nnum
367 idxver = idxlist(lugb)%idxver
376 call getg2i2(lux, idxlist(lugb)%cbuf, idxver, nlen, nnum, irgi)
377 elseif (lux .le. 0)
then
379 call getg2i2r(lugb, msk1, msk2, mskp, idxver, idxlist(lugb)%cbuf, &
380 nlen, nnum, nmess, irgi)
384 if (irgi .ne. 0)
then
387 print *,
' error reading index file '
393 cindex => idxlist(lugb)%cbuf
394 idxlist(lugb)%nlen = nlen
395 idxlist(lugb)%nnum = nnum
396 idxlist(lugb)%idxver = idxver
429 subroutine getg2i(lugi, cbuf, nlen, nnum, iret)
432 integer,
intent(in) :: lugi
433 character(len=1),
pointer,
dimension(:) :: cbuf
434 integer,
intent(out) :: nlen, nnum, iret
438 subroutine getg2i2(lugi, cbuf, idxver, nlen, nnum, iret)
439 integer,
intent(in) :: lugi
440 character(len=1),
pointer,
dimension(:) :: cbuf
441 integer,
intent(out) :: idxver, nlen, nnum, iret
448 call getg2i2(lugi, cbuf, idxver, nlen, nnum, iret)
449 if (idxver .eq. 2) iret = 5
511 subroutine getg2i2(lugi, cbuf, idxver, nlen, nnum, iret)
515 integer,
intent(in) :: lugi
516 character(len=1),
pointer,
dimension(:) :: cbuf
517 integer,
intent(out) :: idxver, nlen, nnum, iret
520 integer :: ios, istat, lbuf, lhead, nskp
531 call baread(lugi, 0, 162, lhead, chead)
536 if (lhead .eq. 162 .and. chead(42:47) .eq.
'GB2IX1')
then
537 read(chead(82:162),
'(2x, i1, 5x, 3i10, 2x, a40)', iostat = ios) idxver, nskp, nlen, nnum
539 write(
g2_log_msg, *)
'ios', ios,
'idxver', idxver,
'nskp', nskp,
'nlen', nlen,
'nnum', nnum
543 allocate(cbuf(nlen), stat = istat)
544 if (istat .ne. 0)
then
549 call baread(lugi, nskp, nlen, lbuf, cbuf)
550 if (lbuf .ne. nlen) iret = 3
587 subroutine getg2ir(lugb, msk1, msk2, mnum, cbuf, nlen, nnum, nmess, iret)
591 integer,
intent(in) :: lugb
592 integer,
intent(in) :: msk1, msk2
593 integer,
intent(in) :: mnum
594 character(len = 1),
pointer,
dimension(:) :: cbuf
595 integer,
intent(out) :: nlen, nnum, nmess, iret
597 integer (kind = 8) :: msk1_8, msk2_8
600 subroutine getg2i2r(lugb, msk1, msk2, mnum, idxver, cbuf, &
601 nlen, nnum, nmess, iret)
602 integer,
intent(in) :: lugb
603 integer (kind = 8),
intent(in) :: msk1, msk2
604 integer,
intent(in) :: mnum, idxver
605 character(len = 1),
pointer,
dimension(:) :: cbuf
606 integer,
intent(out) :: nlen, nnum, nmess, iret
612 call getg2i2r(lugb, msk1_8, msk2_8, mnum, 1, cbuf, nlen, nnum, nmess, iret)
648 subroutine getg2i2r(lugb, msk1, msk2, mnum, idxver, cbuf, nlen, nnum, nmess, iret)
653 integer,
intent(in) :: lugb
654 integer (kind = 8),
intent(in) :: msk1, msk2
655 integer,
intent(in) :: mnum, idxver
656 character(len = 1),
pointer,
dimension(:) :: cbuf
657 integer,
intent(out) :: nlen, nnum, nmess, iret
659 character(len = 1),
pointer,
dimension(:) :: cbuftmp
660 integer :: nbytes, newsize, next, numfld, m, mbuf
661 integer (kind = 8) :: iseek, lskip, lgrib
662 integer :: istat, init, iret1, lgrib4
663 parameter(init = 50000, next = 10000)
666 subroutine ix2gb2(lugb, lskip8, idxver, lgrib8, cbuf, numfld, mlen, iret)
667 integer,
intent(in) :: lugb
668 integer (kind = 8),
intent(in) :: lskip8
669 integer,
intent(in) :: idxver
670 integer (kind = 8),
intent(in) :: lgrib8
671 character(len = 1),
pointer,
intent(inout),
dimension(:) :: cbuf
672 integer,
intent(out) :: numfld, mlen, iret
678 write(
g2_log_msg, *)
'getg2i2r: lugb ', lugb,
' msk1 ', msk1,
' msk2 ', msk2,
'idxver', idxver
686 allocate(cbuf(mbuf), stat = istat)
687 if (istat .ne. 0)
then
694 call skgb8(lugb, iseek, msk1, lskip, lgrib)
696 if (lgrib .gt. 0)
then
697 iseek = lskip + lgrib
698 call skgb8(lugb, iseek, msk2, lskip, lgrib)
706 do while (iret .eq. 0 .and. lgrib .gt. 0)
707 lgrib4 = int(lgrib, kind(4))
708 call ix2gb2(lugb, lskip, idxver, lgrib, cbuftmp, numfld, nbytes, iret1)
709 if (iret1 .ne. 0) print *,
' SAGT ', numfld, nbytes, iret1
710 if (nbytes + nlen .gt. mbuf)
then
711 newsize = max(mbuf + next, mbuf + nbytes)
712 call realloc(cbuf, nlen, newsize, istat)
713 if (istat .ne. 0)
then
722 if (
associated(cbuftmp))
then
723 cbuf(nlen + 1 : nlen + nbytes) = cbuftmp(1 : nbytes)
724 deallocate(cbuftmp, stat = istat)
725 if (istat .ne. 0)
then
726 print *,
' deallocating cbuftmp ... ', istat
737 iseek = lskip + lgrib
738 call skgb8(lugb, iseek, msk2, lskip, lgrib)
814 subroutine getgb2s(cbuf, nlen, nnum, j, jdisc, jids, jpdtn, jpdt, jgdtn, &
815 jgdt, k, gfld, lpos, iret)
819 character(len = 1),
intent(in) :: cbuf(nlen)
820 integer,
intent(in) :: nlen, nnum, j, jdisc
821 integer,
dimension(:) :: jids(*)
822 integer,
intent(in) :: jpdtn
823 integer,
dimension(:) :: jpdt(*)
824 integer,
intent(in) :: jgdtn
825 integer,
dimension(:) :: jgdt(*)
826 integer,
intent(out) :: k
828 integer,
intent(out) :: lpos, iret
831 subroutine getgb2s2(cbuf, idxver, nlen, nnum, j, jdisc, jids, jpdtn, jpdt, jgdtn, &
832 jgdt, k, gfld, lpos, iret)
834 character(len = 1),
intent(in) :: cbuf(nlen)
835 integer,
intent(in) :: idxver, nlen, nnum, j, jdisc
836 integer,
dimension(:) :: jids(*)
837 integer,
intent(in) :: jpdtn
838 integer,
dimension(:) :: jpdt(*)
839 integer,
intent(in) :: jgdtn
840 integer,
dimension(:) :: jgdt(*)
841 integer,
intent(out) :: k
843 integer,
intent(out) :: lpos, iret
849 call getgb2s2(cbuf, 1, nlen, nnum, j, jdisc, jids, jpdtn, jpdt, jgdtn, &
850 jgdt, k, gfld, lpos, iret)
927 subroutine getgb2s2(cbuf, idxver, nlen, nnum, j, jdisc, jids, jpdtn, jpdt, jgdtn, &
928 jgdt, k, gfld, lpos, iret)
933 character(len = 1),
intent(in) :: cbuf(nlen)
934 integer,
intent(in) :: idxver, nlen, nnum, j, jdisc
935 integer,
dimension(:) :: jids(*)
936 integer,
intent(in) :: jpdtn
937 integer,
dimension(:) :: jpdt(*)
938 integer,
intent(in) :: jgdtn
939 integer,
dimension(:) :: jgdt(*)
940 integer,
intent(out) :: k
942 integer,
intent(out) :: lpos, iret
945 logical :: match1, match3, match4
946 integer :: i, icnd, inlen, iof, ipos, jpos, lsec1, lsec3, lsec4, lsec5, numgdt, numpdt, inc
949 subroutine g2_gbytec1(in, siout, iskip, nbits)
950 character*1,
intent(in) :: in(*)
951 integer,
intent(inout) :: siout
952 integer,
intent(in) :: iskip, nbits
954 subroutine gf_unpack1(cgrib, lcgrib, iofst, ids, idslen, ierr)
955 character(len = 1),
intent(in) :: cgrib(lcgrib)
956 integer,
intent(in) :: lcgrib
957 integer,
intent(inout) :: iofst
958 integer,
pointer,
dimension(:) :: ids
959 integer,
intent(out) :: ierr, idslen
961 subroutine gf_unpack3(cgrib, lcgrib, iofst, igds, igdstmpl, &
962 mapgridlen, ideflist, idefnum, ierr)
963 character(len = 1),
intent(in) :: cgrib(lcgrib)
964 integer,
intent(in) :: lcgrib
965 integer,
intent(inout) :: iofst
966 integer,
pointer,
dimension(:) :: igdstmpl, ideflist
967 integer,
intent(out) :: igds(5)
968 integer,
intent(out) :: ierr, idefnum
970 subroutine gf_unpack4(cgrib, lcgrib, iofst, ipdsnum, ipdstmpl, &
971 mappdslen, coordlist, numcoord, ierr)
972 character(len = 1),
intent(in) :: cgrib(lcgrib)
973 integer,
intent(in) :: lcgrib
974 integer,
intent(inout) :: iofst
975 real,
pointer,
dimension(:) :: coordlist
976 integer,
pointer,
dimension(:) :: ipdstmpl
977 integer,
intent(out) :: ipdsnum
978 integer,
intent(out) :: ierr, numcoord
980 subroutine gf_unpack5(cgrib, lcgrib, iofst, ndpts, idrsnum, &
981 idrstmpl, mapdrslen, ierr)
982 character(len = 1),
intent(in) :: cgrib(lcgrib)
983 integer,
intent(in) :: lcgrib
984 integer,
intent(inout) :: iofst
985 integer,
intent(out) :: ndpts, idrsnum
986 integer,
pointer,
dimension(:) :: idrstmpl
987 integer,
intent(out) :: ierr
993 write(
g2_log_msg, *)
'getgb2s2: idxver ', idxver,
' nlen ', nlen, &
994 ' nnum ', nnum,
' j ', j,
' jdisc ', jdisc
1003 nullify(gfld%idsect, gfld%local)
1004 nullify(gfld%list_opt, gfld%igdtmpl, gfld%ipdtmpl)
1005 nullify(gfld%coord_list, gfld%idrtmpl, gfld%bmap, gfld%fld)
1006 if (idxver .eq. 1)
then
1015 do while (iret .ne. 0 .and. k .lt. nnum)
1018 call g2_gbytec1(cbuf, inlen, ipos * 8, 4 * 8)
1025 call g2_gbytec1(cbuf, gfld%discipline, (ipos + inc + 41) * 8, 1 * 8)
1026 if (jdisc .ne. -1 .and. jdisc .ne. gfld%discipline)
then
1034 call g2_gbytec1(cbuf, lsec1, (ipos + inc + 44) * 8, 4 * 8)
1036 call gf_unpack1(cbuf(ipos + inc + 45), lsec1, iof, gfld%idsect, gfld%idsectlen, icnd)
1037 if (icnd .eq. 0)
then
1039 do i = 1, gfld%idsectlen
1040 if (jids(i) .ne. -9999 .and. jids(i) .ne. gfld%idsect(i))
then
1046 if (.not. match1)
then
1047 deallocate(gfld%idsect)
1053 jpos = ipos + 44 + inc + lsec1
1055 call g2_gbytec1(cbuf, lsec3, jpos * 8, 4 * 8)
1056 if (jgdtn .eq. -1)
then
1059 call g2_gbytec1(cbuf, numgdt, (jpos + 12) * 8, 2 * 8)
1060 if (jgdtn .eq. numgdt)
then
1062 call gf_unpack3(cbuf(jpos + 1), lsec3, iof, kgds, gfld%igdtmpl, &
1063 gfld%igdtlen, gfld%list_opt, gfld%num_opt, icnd)
1064 if (icnd .eq. 0)
then
1066 do i = 1, gfld%igdtlen
1067 if (jgdt(i) .ne. -9999 .and. jgdt(i).ne.gfld%igdtmpl(i))
then
1075 if (.not. match3)
then
1076 if (
associated(gfld%idsect))
deallocate(gfld%idsect)
1077 if (
associated(gfld%igdtmpl))
deallocate(gfld%igdtmpl)
1078 if (
associated(gfld%list_opt))
deallocate(gfld%list_opt)
1082 gfld%griddef = kgds(1)
1083 gfld%ngrdpts = kgds(2)
1084 gfld%numoct_opt = kgds(3)
1085 gfld%interp_opt = kgds(4)
1086 gfld%igdtnum = kgds(5)
1094 call g2_gbytec1(cbuf, lsec4, jpos * 8, 4 * 8)
1095 if (jpdtn .eq. -1)
then
1099 call g2_gbytec1(cbuf, numpdt, (jpos + 7) * 8, 2 * 8)
1100 if (jpdtn .eq. numpdt)
then
1102 call gf_unpack4(cbuf(jpos + 1), lsec4, iof, gfld%ipdtnum, &
1103 gfld%ipdtmpl, gfld%ipdtlen, gfld%coord_list, gfld%num_coord, icnd)
1104 if (icnd .eq. 0)
then
1106 do i = 1, gfld%ipdtlen
1107 if (jpdt(i) .ne. -9999 .and. jpdt(i) .ne. gfld%ipdtmpl(i))
then
1115 if (.not. match4)
then
1116 if (
associated(gfld%idsect))
deallocate(gfld%idsect)
1117 if (
associated(gfld%ipdtmpl))
deallocate(gfld%ipdtmpl)
1118 if (
associated(gfld%coord_list))
deallocate(gfld%coord_list)
1122 if (match1 .and. match3 .and. match4)
then
1124 call g2_gbytec1(cbuf, gfld%version, (ipos + inc + 40) * 8, 1 * 8)
1125 call g2_gbytec1(cbuf, gfld%ifldnum, (ipos + inc + 42) * 8, 2 * 8)
1126 gfld%unpacked = .false.
1127 jpos = ipos + 44 + inc + lsec1
1128 if (jgdtn .eq. -1)
then
1130 call gf_unpack3(cbuf(jpos + 1), lsec3, iof, kgds, gfld%igdtmpl, &
1131 gfld%igdtlen, gfld%list_opt, gfld%num_opt, icnd)
1132 gfld%griddef = kgds(1)
1133 gfld%ngrdpts = kgds(2)
1134 gfld%numoct_opt = kgds(3)
1135 gfld%interp_opt = kgds(4)
1136 gfld%igdtnum = kgds(5)
1139 if (jpdtn .eq. -1)
then
1141 call gf_unpack4(cbuf(jpos + 1), lsec4, iof, gfld%ipdtnum, &
1142 gfld%ipdtmpl, gfld%ipdtlen, gfld%coord_list, gfld%num_coord, icnd)
1145 call g2_gbytec1(cbuf, lsec5, jpos * 8, 4 * 8)
1147 call gf_unpack5(cbuf(jpos + 1), lsec5, iof, gfld%ndpts, &
1148 gfld%idrtnum, gfld%idrtmpl, gfld%idrtlen, icnd)
1150 call g2_gbytec1(cbuf, gfld%ibmap, (jpos + 5) * 8, 1 * 8)
1191 subroutine ixgb2(lugb, lskip, lgrib, cbuf, numfld, mlen, iret)
1195 integer :: lugb, lskip, lgrib
1196 character(len = 1),
pointer,
dimension(:) :: cbuf
1197 integer :: numfld, mlen, iret
1198 integer (kind = 8) :: lskip8, lgrib8
1201 subroutine ix2gb2(lugb, lskip8, idxver, lgrib8, cbuf, numfld, mlen, iret)
1202 integer,
intent(in) :: lugb
1203 integer (kind = 8),
intent(in) :: lskip8
1204 integer,
intent(in) :: idxver
1205 integer (kind = 8),
intent(in) :: lgrib8
1206 character(len = 1),
pointer,
intent(inout),
dimension(:) :: cbuf
1207 integer,
intent(out) :: numfld, mlen, iret
1214 call ix2gb2(lugb, lskip8, 1, lgrib8, cbuf, numfld, mlen, iret)
1215 lgrib = int(lgrib8, 4)
1216 end subroutine ixgb2
1255 subroutine ix2gb2(lugb, lskip8, idxver, lgrib8, cbuf, numfld, mlen, iret)
1261 integer,
intent(in) :: lugb
1262 integer (kind = 8),
intent(in) :: lskip8
1263 integer,
intent(in) :: idxver
1264 integer (kind = 8),
intent(in) :: lgrib8
1265 character(len = 1),
pointer,
intent(inout),
dimension(:) :: cbuf
1266 integer,
intent(out) :: numfld, mlen, iret
1268 character cver, cdisc
1269 character(len = 4) :: ctemp
1270 integer (kind = 8) :: loclus8, locgds8, locbms8
1271 integer locgds, loclus, locbms
1272 integer :: indbmp, numsec, newsize, g2_mova2i, mbuf, lindex
1274 integer :: ilndrs, ilnpds, istat
1275 integer (kind = 8) :: ibread8, lbread8, ibskip8, lengds8
1276 integer (kind = 8) :: ilnpds8, ilndrs8
1277 integer :: lensec, lensec1
1278 integer :: mypos, inc
1283 parameter(linmax = 5000)
1286 parameter(init = 50000)
1289 parameter(next = 10000)
1292 parameter(mxbms = 6)
1293 integer :: IXDS1, IXDS2
1294 parameter(ixds1 = 28, ixds2 = 52)
1297 parameter(ixids = 44)
1299 parameter(ixsdr = 20)
1301 integer :: IXBMS1, IXBMS2
1302 parameter(ixbms1 = 24, ixbms2 = 44)
1304 integer :: INT1_BITS, INT2_BITS, INT4_BITS, INT8_BITS
1305 parameter(int1_bits = 8, int2_bits = 16, int4_bits = 32, int8_bits = 64)
1307 integer :: IXDRS1, IXDRS2
1308 parameter(ixdrs1 = 20, ixdrs2 = 36)
1311 character cbread(LINMAX), cindex(LINMAX)
1312 character cids(LINMAX), cgds(LINMAX)
1315 subroutine g2_gbytec1(in, siout, iskip, nbits)
1316 character*1,
intent(in) :: in(*)
1317 integer,
intent(inout) :: siout
1318 integer,
intent(in) :: iskip, nbits
1321 character*1,
intent(inout) :: out(*)
1322 integer (kind = 8),
intent(in) :: sin
1323 integer,
intent(in) :: iskip, nbits
1326 character*1,
intent(inout) :: out(*)
1327 integer,
intent(in) :: in
1328 integer,
intent(in) :: iskip, nbits
1334 write(
g2_log_msg, *)
'ix2gb2: lugb ', lugb,
' lskip8 ', lskip8,
' idxver ', idxver
1340 if (idxver .eq. 1)
then
1361 allocate(cbuf(mbuf), stat = istat)
1362 if (istat .ne. 0)
then
1369 ibread8 = min(lgrib8, linmax)
1370 call bareadl(lugb, lskip8, ibread8, lbread8, cbread)
1371 if (lbread8 .ne. ibread8)
then
1377 if (cbread(8) .ne. char(2))
then
1387 call g2_gbytec1(cbread, lensec1, 16 * int1_bits, int4_bits)
1388 lensec1 = min(lensec1, int(ibread8, kind(lensec1)))
1391 cids(1:lensec1) = cbread(17:16 + lensec1)
1397 ibskip8 = lskip8 + 16_8 + int(lensec1, kind(8))
1401 ibread8 = max(5, mxbms)
1405 call bareadl(lugb, ibskip8, ibread8, lbread8, cbread)
1409 ctemp = cbread(1)//cbread(2)//cbread(3)//cbread(4)
1410 if (ctemp .eq.
'7777')
return
1413 if (lbread8 .ne. ibread8)
then
1420 call g2_gbytec1(cbread, lensec, 0, int4_bits)
1421 call g2_gbytec1(cbread, numsec, int4_bits, int1_bits)
1425 if (numsec .eq. 2)
then
1427 loclus8 = ibskip8 - lskip8
1428 loclus = int(ibskip8 - lskip8, kind(4))
1429 elseif (numsec .eq. 3)
then
1434 call bareadl(lugb, ibskip8, lengds8, lbread8, cgds)
1435 if (lbread8 .ne. lengds8)
then
1440 locgds = int(ibskip8 - lskip8, kind(4))
1441 locgds8 = ibskip8 - lskip8
1442 elseif (numsec .eq. 4)
then
1455 if (idxver .eq. 1)
then
1457 lskip = int(lskip8, kind(4))
1458 call g2_sbytec1(cindex, lskip, mypos, int4_bits)
1460 mypos = mypos + int4_bits
1461 call g2_sbytec1(cindex, loclus, mypos, int4_bits)
1463 mypos = mypos + int4_bits
1464 call g2_sbytec1(cindex, locgds, mypos, int4_bits)
1466 mypos = mypos + int4_bits
1467 call g2_sbytec1(cindex, int(ibskip8 - lskip8, kind(4)), mypos, int4_bits)
1469 write(
g2_log_msg, *)
' writing pds location to index: mypos/8 ', mypos/8, &
1470 ' loc ', int(ibskip8 - lskip8, kind(4))
1474 mypos = mypos + int4_bits * 4
1477 call g2_sbytec81(cindex, lskip8, mypos, int8_bits)
1479 mypos = mypos + int8_bits
1480 call g2_sbytec81(cindex, loclus8, mypos, int8_bits)
1482 mypos = mypos + int8_bits
1483 call g2_sbytec81(cindex, locgds8, mypos, int8_bits)
1485 mypos = mypos + int8_bits
1486 call g2_sbytec81(cindex, ibskip8 - lskip8, mypos, int8_bits)
1488 mypos = mypos + int8_bits * 4
1492 write(
g2_log_msg, *)
' writing total len to index: mypos/8 ', mypos/8, lgrib8
1497 call g2_sbytec81(cindex, lgrib8, mypos, int8_bits)
1499 mypos = mypos + int8_bits
1500 cindex((mypos / 8) + 1) = cver
1502 mypos = mypos + int1_bits
1503 cindex((mypos / 8) + 1) = cdisc
1505 mypos = mypos + int1_bits
1506 call g2_sbytec1(cindex, numfld + 1, mypos, int2_bits)
1508 mypos = mypos + int2_bits
1511 cindex(ixids + 1 + inc:ixids + lensec1 + inc) = cids(1:lensec1)
1512 lindex = ixids + lensec1 + inc
1519 cindex(lindex + 1:lindex + lengds8) = cgds(1:lengds8)
1521 lindex = lindex + int(lengds8, kind(lindex))
1530 call bareadl(lugb, ibskip8, ilnpds8, lbread8, cindex(lindex + 1))
1531 if (lbread8 .ne. ilnpds8)
then
1536 lindex = lindex + ilnpds
1537 mypos = mypos + ilnpds
1539 write(
g2_log_msg, *)
' after writing pds location to index: mypos/8 ', mypos/8
1542 elseif (numsec .eq. 5)
then
1546 write(
g2_log_msg, *)
' before writing drs to index: ibskip8 - lskip8 ', ibskip8 - lskip8, ixdrs2
1550 if (idxver .eq. 1)
then
1551 call g2_sbytec1(cindex, int(ibskip8 - lskip8, kind(4)), ixdrs1 * int1_bits, int4_bits)
1553 call g2_sbytec81(cindex, ibskip8 - lskip8, ixdrs2 * int1_bits, int8_bits)
1560 call bareadl(lugb, ibskip8, ilndrs8, lbread8, cindex(lindex + 1))
1561 if (lbread8 .ne. ilndrs8)
then
1566 lindex = lindex + ilndrs
1567 elseif (numsec .eq. 6)
then
1570 indbmp = g2_mova2i(cbread(6))
1572 write(
g2_log_msg, *)
' section 6: indbmp', indbmp
1576 if (indbmp .lt. 254)
then
1577 if (idxver .eq. 1)
then
1578 locbms = int(ibskip8 - lskip8, kind(4))
1579 call g2_sbytec1(cindex, locbms, ixbms1 * int1_bits, int4_bits)
1581 locbms8 = ibskip8 - lskip8
1582 call g2_sbytec81(cindex, locbms8, ixbms2 * int1_bits, int8_bits)
1585 write(
g2_log_msg, *)
' section 6: locbms', locbms,
'locbms8', locbms8
1588 elseif (indbmp .eq. 254)
then
1589 if (idxver .eq. 1)
then
1590 call g2_sbytec1(cindex, locbms, ixbms1 * int1_bits, int4_bits)
1592 call g2_sbytec81(cindex, locbms8, ixbms2 * int1_bits, int8_bits)
1594 elseif (indbmp .eq. 255)
then
1595 if (idxver .eq. 1)
then
1596 call g2_sbytec1(cindex, int(ibskip8 - lskip8, kind(4)), ixbms1 * int1_bits, int4_bits)
1598 call g2_sbytec81(cindex, ibskip8 - lskip8, ixbms2 * int1_bits, int8_bits)
1603 cindex(lindex + 1:lindex + mxbms) = cbread(1:mxbms)
1608 lindex = lindex + mxbms
1612 call g2_sbytec1(cindex, lindex, 0, int4_bits)
1614 elseif (numsec .eq. 7)
then
1617 write(
g2_log_msg, *)
' writing offset to the data in cindex: ibskip8 - lskip8 ', ibskip8 - lskip8, &
1622 if (idxver .eq. 1)
then
1623 call g2_sbytec1(cindex, int(ibskip8 - lskip8, kind(4)), ixds1 * int1_bits, int4_bits)
1625 call g2_sbytec81(cindex, ibskip8 - lskip8, ixds2 * int1_bits, int8_bits)
1633 if (lindex + mlen .gt. mbuf)
then
1634 newsize = max(mbuf + next, mbuf + lindex)
1635 call realloc(cbuf, mlen, newsize, istat)
1636 if (istat .ne. 0)
then
1645 cbuf(mlen + 1:mlen + lindex) = cindex(1:lindex)
1646 mlen = mlen + lindex
1654 ibskip8 = ibskip8 + lensec
1667 integer,
intent(out) :: iret
1668 character(len = 1),
pointer,
dimension(:) :: cindex
1669 integer :: nlen, nnum
1673 subroutine getidx(lugb, lugi, cbuf, nlen, nnum, irgi)
1674 character(len = 1),
pointer,
dimension(:) :: cbuf
1675 integer,
intent(in) :: lugb, lugi
1676 integer,
intent(out) :: nlen, nnum, irgi
1682 call getidx(0, 0, cindex, nlen, nnum, iret)
subroutine g2_sbytec81(out, sin, iskip, nbits)
Put one arbitrary sized (up to 64 bits) scalar into a packed bit string, taking the low order bits fr...
subroutine g2_sbytec1(out, in, iskip, nbits)
Put one arbitrary sized (up to 32 bits) values from an integer scalar into a packed bit string,...
subroutine g2_gbytec1(in, siout, iskip, nbits)
Extract one arbitrary size big-endian integer value (up to 32 bits) from a packed bit string into a s...
subroutine g2_create_index(lugb, lugi, idxver, filename, iret)
Create a version 1 or 2 index file for a GRIB2 file.
subroutine ix2gb2(lugb, lskip8, idxver, lgrib8, cbuf, numfld, mlen, iret)
Generate a version 1 or 2 index record for each field in a GRIB2 message.
subroutine getgb2s(cbuf, nlen, nnum, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, k, gfld, lpos, iret)
Find information about a GRIB field from the index and fill a grib_mod::gribfield.
subroutine getidx(lugb, lugi, cindex, nlen, nnum, iret)
Find, read or generate a version 1 GRIB2 index for a GRIB2 file (which must be < 2 GB).
subroutine g2_write_index_headers(lugi, nlen, nnum, idxver, filename)
Write index headers.
subroutine getg2i2r(lugb, msk1, msk2, mnum, idxver, cbuf, nlen, nnum, nmess, iret)
Generate a version 1 or 2 index record for each message in a GRIB2 file.
subroutine getg2ir(lugb, msk1, msk2, mnum, cbuf, nlen, nnum, nmess, iret)
Generate a version 1 index record for each message in a GRIB2 file.
subroutine ixgb2(lugb, lskip, lgrib, cbuf, numfld, mlen, iret)
Generate a version 1 index record for each field in a GRIB2 message.
subroutine getidx2(lugb, lugi, idxver, cindex, nlen, nnum, iret)
Find, read or generate a version 1 or 2 GRIB2 index for a GRIB2 file (which may be > 2 GB).
subroutine gf_finalize(iret)
Free all memory associated with the library.
subroutine getg2i(lugi, cbuf, nlen, nnum, iret)
Read a version 1 index file and return its contents.
subroutine getg2i2(lugi, cbuf, idxver, nlen, nnum, iret)
Read a version 1 or 2 index file and return its contents.
subroutine getgb2s2(cbuf, idxver, nlen, nnum, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, k, gfld, lpos, iret)
Find information about a GRIB field from the index and fill a grib_mod::gribfield.
subroutine gf_unpack1(cgrib, lcgrib, iofst, ids, idslen, ierr)
Unpack Section 1 (Identification Section) of a GRIB2 message, starting at octet 6 of that Section.
subroutine gf_unpack5(cgrib, lcgrib, iofst, ndpts, idrsnum, idrstmpl, mapdrslen, ierr)
Unpack Section 5 (Data Representation Section) of a GRIB2 message, starting at octet 6 of that Sectio...
subroutine gf_unpack4(cgrib, lcgrib, iofst, ipdsnum, ipdstmpl, mappdslen, coordlist, numcoord, ierr)
Unpack Section 4 (Product Definition Section) of a GRIB2 message, starting at octet 6 of that Section...
subroutine gf_unpack3(cgrib, lcgrib, iofst, igds, igdstmpl, mapgridlen, ideflist, idefnum, ierr)
Unpack Section 3 (Grid Definition Section) of a GRIB2 message, starting at octet 6 of that Section.
Logging for the g2 library.
character *120 g2_log_msg
Fill this with the logging message.
subroutine g2_log(level)
Print a debug message for the g2 library.
This Fortran module contains the declaration of derived type gribfield.
Reallocate memory, preserving contents.
subroutine skgb8(lugb, iseek8, mseek8, lskip8, lgrib8)
Search a file for the next GRIB1 or GRIB2 message.