52 subroutine gb_info(cgrib, lcgrib, listsec0, listsec1, &
53 numfields, numlocal, maxlocal, ierr)
57 character(len = 1),
intent(in) :: cgrib(lcgrib)
58 integer,
intent(in) :: lcgrib
59 integer,
intent(out) :: listsec0(3), listsec1(13)
60 integer,
intent(out) :: numlocal, numfields, maxlocal, ierr
62 character(len = 4),
parameter :: grib =
'GRIB', c7777 =
'7777'
63 character(len = 4) :: ctemp
64 integer,
parameter :: zero = 0, one = 1
65 integer,
parameter :: mapsec1len = 13
66 integer,
parameter :: mapsec1(mapsec1len) = (/ 2, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1 /)
67 integer :: iofst, istart
68 integer :: nbits, lensec1, lensec0, lensec, lenposs, lengrib, j
69 integer (kind = 8) :: lengrib8
70 integer :: i, ipos, isecnum
73 subroutine g2_gbytec(in, iout, iskip, nbits)
74 character*1,
intent(in) :: in(*)
75 integer,
intent(inout) :: iout(*)
76 integer,
intent(in) :: iskip, nbits
79 character*1,
intent(in) :: in(*)
80 integer,
intent(inout) :: siout
81 integer,
intent(in) :: iskip, nbits
84 character*1,
intent(in) :: in(*)
85 integer (kind = 8),
intent(inout) :: siout
86 integer,
intent(in) :: iskip, nbits
87 integer (kind = 8) :: iout(1)
92 write(
g2_log_msg, *)
'gb_info: lcgrib ', lcgrib
104 ctemp = cgrib(j) // cgrib(j + 1) // cgrib(j + 2) // cgrib(j+3)
105 if (ctemp .eq. grib )
then
110 if (istart .eq. 0)
then
111 print *,
'gb_info: Beginning characters GRIB not found.'
117 iofst = 8 * (istart + 5)
118 call g2_gbytec(cgrib, listsec0(1), iofst, 8)
120 call g2_gbytec(cgrib, listsec0(2), iofst, 8)
125 write(
g2_log_msg, *)
'before getting len: iofst/8 ', iofst/8
132 lengrib = int(lengrib8, kind(4))
135 listsec0(3) = lengrib
137 ipos = istart + lensec0
140 if (listsec0(2) .ne. 2)
then
141 print *,
'gb_info: can only decode GRIB edition 2.'
151 if (isecnum .ne. 1)
then
152 print *,
'gb_info: Could not find section 1.'
161 nbits = mapsec1(i) * 8
162 call g2_gbytec(cgrib, listsec1(i), iofst, nbits)
163 iofst = iofst + nbits
165 ipos = ipos + lensec1
170 ctemp = cgrib(ipos) // cgrib(ipos + 1) // cgrib(ipos + 2) // cgrib(ipos + 3)
171 if (ctemp .eq. c7777 )
then
173 if (ipos .ne. (istart + lengrib))
then
174 print *,
'gb_info: "7777" found, but not where expected.'
180 iofst = (ipos - 1) * 8
186 if (ipos .gt. (istart + lengrib))
then
187 print *,
'gb_info: "7777" not found at end of GRIB message.'
191 if (isecnum .ge. 2 .AND. isecnum .le. 7)
then
192 if (isecnum .eq. 2)
then
194 numlocal = numlocal + 1
196 if (lenposs .gt. maxlocal) maxlocal = lenposs
197 elseif (isecnum .eq. 4)
then
199 numfields = numfields + 1
202 print *,
'gb_info: Invalid section number found in GRIB message: ', isecnum
282 subroutine gribinfo(cgrib, lcgrib, listsec0, listsec1, &
283 numlocal, numfields, maxvals, ierr)
286 character(len = 1),
intent(in) :: cgrib(lcgrib)
287 integer,
intent(in) :: lcgrib
288 integer,
intent(out) :: listsec0(3), listsec1(13), maxvals(7)
289 integer,
intent(out) :: numlocal, numfields, ierr
291 integer :: i, ipos, isecnum, j, lengrib, lenposs, lensec, lensec0, lensec1
292 integer :: maxcoordlist, maxdeflist, maxdrstmpl, maxgridpts, maxpdstmpl, maxgdstmpl
293 integer :: maxsec2len, nbits, nbyte, ngdpts, numcoord
294 character(len = 4),
parameter :: grib =
'GRIB', c7777 =
'7777'
295 character(len = 4) :: ctemp
296 integer,
parameter :: zero = 0, one = 1
297 integer,
parameter :: mapsec1len = 13
298 integer,
parameter :: mapsec1(mapsec1len) = (/ 2, 2, 1, 1, 1, 2, 1, 1, &
300 integer iofst, istart
301 integer (kind = 8) :: lengrib8
317 ctemp = cgrib(j) // cgrib(j + 1) // cgrib(j + 2) // cgrib(j + 3)
318 if (ctemp .eq. grib)
then
323 if (istart .eq. 0)
then
324 print *,
'gribinfo: Beginning characters GRIB not found.'
330 iofst = 8 * (istart + 5)
331 call g2_gbytec(cgrib, listsec0(1), iofst, 8)
333 call g2_gbytec(cgrib, listsec0(2), iofst, 8)
339 lengrib = int(lengrib8, kind(4))
342 listsec0(3) = lengrib
344 ipos = istart + lensec0
347 if (listsec0(2) .ne. 2)
then
348 print *,
'gribinfo: can only decode GRIB edition 2.'
358 if (isecnum .ne. 1)
then
359 print *,
'gribinfo: Could not find section 1.'
368 nbits = mapsec1(i) * 8
369 call g2_gbytec(cgrib, listsec1(i), iofst, nbits)
370 iofst = iofst + nbits
372 ipos = ipos + lensec1
378 ctemp = cgrib(ipos) // cgrib(ipos + 1) // cgrib(ipos + 2) // &
380 if (ctemp .eq. c7777)
then
382 if (ipos .ne. (istart + lengrib))
then
383 print *,
'gribinfo: "7777" found, but not where expected.'
389 iofst = (ipos - 1) * 8
395 if (ipos .gt. (istart + lengrib))
then
396 print *,
'gribinfo: "7777" not found at end of GRIB message.'
400 if (isecnum .eq. 2)
then
403 numlocal = numlocal + 1
405 if (lenposs .gt. maxsec2len) maxsec2len = lenposs
406 elseif (isecnum .eq. 3)
then
412 if (ngdpts .gt. maxgridpts) maxgridpts = ngdpts
413 lenposs = lensec - 14
414 if (lenposs .gt. maxgdstmpl) maxgdstmpl = lenposs
415 if (nbyte .ne. 0)
then
416 lenposs = lenposs / nbyte
417 if (lenposs .gt. maxdeflist) maxdeflist = lenposs
419 elseif (isecnum .eq. 4)
then
420 numfields = numfields + 1
423 if (numcoord .ne. 0)
then
424 if (numcoord .gt. maxcoordlist) maxcoordlist = numcoord
427 if (lenposs.gt.maxpdstmpl) maxpdstmpl = lenposs
428 elseif (isecnum .eq. 5)
then
430 if (lenposs .gt. maxdrstmpl) maxdrstmpl = lenposs
434 maxvals(1) = maxsec2len
435 maxvals(2) = maxgdstmpl
436 maxvals(3) = maxdeflist
437 maxvals(4) = maxpdstmpl
438 maxvals(5) = maxcoordlist
439 maxvals(6) = maxdrstmpl
440 maxvals(7) = maxgridpts
543 subroutine getfield(cgrib, lcgrib, ifldnum, igds, igdstmpl, &
544 igdslen, ideflist, idefnum, ipdsnum, ipdstmpl, ipdslen, &
545 coordlist, numcoord, ndpts, idrsnum, idrstmpl, idrslen, &
546 ibmap, bmap, fld, ierr)
549 character(len = 1),
intent(in) :: cgrib(lcgrib)
550 integer,
intent(in) :: lcgrib, ifldnum
551 integer,
intent(out) :: igds(*), igdstmpl(*), ideflist(*)
552 integer,
intent(out) :: ipdsnum, ipdstmpl(*)
553 integer,
intent(out) :: idrsnum, idrstmpl(*)
554 integer,
intent(out) :: ndpts, ibmap, idefnum, numcoord
555 integer,
intent(out) :: igdslen, ipdslen, idrslen
556 real,
intent(out) :: fld(*), coordlist(*)
557 logical*1,
intent(out) :: bmap(*)
558 integer,
intent(out) :: ierr
560 character(len = 4),
parameter :: grib =
'GRIB', c7777 =
'7777'
561 character(len = 4) :: ctemp
562 integer :: listsec0(2)
563 integer :: iofst, istart
564 real (kind = 4) :: ieee(1)
565 logical :: have3, have4, have5, have6, have7
566 integer (kind = 8) :: lengrib8
567 integer :: numfld, j, lengrib, lensec0, ipos
568 integer :: lensec, isecnum, jerr, ier, numlocal
580 if (ifldnum .le. 0)
then
581 print *,
'getfield: Request for field number ' &
590 ctemp = cgrib(j) // cgrib(j + 1) // cgrib(j + 2) // cgrib(j + 3)
591 if (ctemp .eq. grib)
then
596 if (istart .eq. 0)
then
597 print *,
'getfield: Beginning characters GRIB not found.'
603 iofst = 8 * (istart + 5)
604 call g2_gbytec(cgrib, listsec0(1), iofst, 8)
606 call g2_gbytec(cgrib, listsec0(2), iofst, 8)
612 lengrib = int(lengrib8, kind(4))
616 ipos = istart + lensec0
619 if (listsec0(2) .ne. 2)
then
620 print *,
'getfield: can only decode GRIB edition 2.'
630 ctemp = cgrib(ipos) // cgrib(ipos + 1) // cgrib(ipos + 2) // &
632 if (ctemp .eq. c7777)
then
635 if (ipos.ne.(istart + lengrib))
then
636 print *,
'getfield: "7777" found, but not ' &
644 iofst = (ipos - 1) * 8
653 if (isecnum .eq. 3)
then
655 call unpack3(cgrib, lcgrib, iofst, igds, igdstmpl, &
656 igdslen, ideflist, idefnum, jerr)
657 if (jerr .eq. 0)
then
667 if (isecnum .eq. 4)
then
669 if (numfld .eq. ifldnum)
then
671 call unpack4(cgrib, lcgrib, iofst, ipdsnum, ipdstmpl, &
672 ipdslen, coordlist, numcoord, jerr)
673 if (jerr .eq. 0)
then
684 if ((isecnum .eq. 5) .and. (numfld .eq. ifldnum))
then
686 call unpack5(cgrib, lcgrib, iofst, ndpts, idrsnum, &
687 idrstmpl, idrslen, jerr)
688 if (jerr .eq. 0)
then
698 if (isecnum .eq. 6)
then
700 call unpack6(cgrib, lcgrib, iofst, igds(2), ibmap, bmap, &
702 if (jerr .eq. 0)
then
712 if ((isecnum .eq. 7) .and. (numfld .eq. ifldnum))
then
713 if (idrsnum .eq. 0)
then
714 call simunpack(cgrib(ipos + 5), lensec - 6, idrstmpl, &
717 elseif (idrsnum .eq. 2 .or. idrsnum .eq. 3)
then
718 call comunpack(cgrib(ipos + 5), lensec - 6, lensec, &
719 idrsnum,idrstmpl, ndpts, fld, ier)
725 elseif (idrsnum .eq. 50)
then
726 call simunpack(cgrib(ipos + 5), lensec - 6, idrstmpl, &
728 ieee = transfer(idrstmpl(5), ieee, 1)
729 call rdieee(ieee, fld(1), 1)
731 elseif (idrsnum .eq. 40 .or. idrsnum .eq. 40000)
then
732 call jpcunpack(cgrib(ipos + 5), lensec - 5, idrstmpl, &
735 elseif (idrsnum .eq. 41 .or. idrsnum .eq. 40010)
then
736 call pngunpack(cgrib(ipos + 5), lensec - 5, idrstmpl, &
740 print *,
'getfield: Data Representation Template ', &
741 idrsnum,
' not yet implemented.'
750 if (ipos .gt. (istart + lengrib))
then
751 print *,
'getfield: "7777" not found at end' &
757 if (have3 .and. have4 .and. have5 .and. have6 .and. have7) &
764 print *,
'getfield: GRIB message contained ', numlocal, &
766 print *,
'getfield: The request was for the ', ifldnum, &
811 subroutine unpack3(cgrib, lcgrib, iofst, igds, igdstmpl, &
812 mapgridlen, ideflist, idefnum, ierr)
816 character(len = 1),
intent(in) :: cgrib(lcgrib)
817 integer,
intent(in) :: lcgrib
818 integer,
intent(inout) :: iofst
819 integer,
intent(out) :: igds(*), igdstmpl(*), ideflist(*)
820 integer,
intent(out) :: ierr, idefnum
822 integer,
allocatable :: mapgrid(:)
823 integer :: mapgridlen, ibyttem
825 integer :: lensec, iret, i, nbits, isign, newmapgridlen
843 if (igds(1) .eq. 0)
then
844 allocate(mapgrid(lensec))
848 if (iret .ne. 0)
then
862 nbits = iabs(mapgrid(i)) * 8
863 if (mapgrid(i) .ge. 0)
then
864 call g2_gbytec1(cgrib, igdstmpl(i), iofst, nbits)
867 call g2_gbytec1(cgrib, igdstmpl(i), iofst + 1, nbits-1)
868 if (isign .eq. 1) igdstmpl(i) = -igdstmpl(i)
870 iofst = iofst + nbits
871 ibyttem = ibyttem + iabs(mapgrid(i))
881 do i = mapgridlen + 1, newmapgridlen
882 nbits = iabs(mapgrid(i)) * 8
883 if (mapgrid(i) .ge. 0)
then
884 call g2_gbytec1(cgrib, igdstmpl(i), iofst, nbits)
887 call g2_gbytec1(cgrib, igdstmpl(i), iofst + 1, nbits - &
889 if (isign .eq. 1) igdstmpl(i) = -igdstmpl(i)
891 iofst = iofst + nbits
892 ibyttem = ibyttem + iabs(mapgrid(i))
894 mapgridlen = newmapgridlen
899 if (igds(3) .ne. 0)
then
901 idefnum = (lensec - 14 - ibyttem) / igds(3)
902 call g2_gbytesc(cgrib, ideflist, iofst, nbits, 0, idefnum)
903 iofst = iofst + (nbits * idefnum)
907 if (
allocated(mapgrid))
deallocate(mapgrid)
936 subroutine unpack4(cgrib, lcgrib, iofst, ipdsnum, ipdstmpl, &
937 mappdslen, coordlist, numcoord, ierr)
941 character(len = 1),
intent(in) :: cgrib(lcgrib)
942 integer,
intent(in) :: lcgrib
943 integer,
intent(inout) :: iofst
944 real,
intent(out) :: coordlist(*)
945 integer,
intent(out) :: ipdsnum, ipdstmpl(*)
946 integer,
intent(out) :: ierr, numcoord
948 real(4),
allocatable :: coordieee(:)
949 integer,
allocatable :: mappds(:)
952 integer :: lensec, iret, i, nbits, isign, newmappdslen
959 allocate(mappds(lensec))
977 nbits = iabs(mappds(i)) * 8
978 if (mappds(i) .ge. 0)
then
979 call g2_gbytec1(cgrib, ipdstmpl(i), iofst, nbits)
982 call g2_gbytec1(cgrib, ipdstmpl(i), iofst + 1, nbits-1)
983 if (isign .eq. 1) ipdstmpl(i) = -ipdstmpl(i)
985 iofst = iofst + nbits
995 do i = mappdslen + 1, newmappdslen
996 nbits = iabs(mappds(i)) * 8
997 if (mappds(i) .ge. 0)
then
998 call g2_gbytec1(cgrib, ipdstmpl(i), iofst, nbits)
1001 call g2_gbytec1(cgrib, ipdstmpl(i), iofst + 1, nbits-1)
1002 if (isign .eq. 1) ipdstmpl(i) = -ipdstmpl(i)
1004 iofst = iofst + nbits
1006 mappdslen = newmappdslen
1011 if (numcoord .ne. 0)
then
1012 allocate (coordieee(numcoord))
1013 call g2_gbytescr(cgrib, coordieee, iofst, 32, 0, numcoord)
1014 call rdieee(coordieee, coordlist, numcoord)
1015 deallocate (coordieee)
1016 iofst = iofst + (32*numcoord)
1018 if (
allocated(mappds))
deallocate(mappds)
1043 subroutine unpack5(cgrib, lcgrib, iofst, ndpts, idrsnum, &
1044 idrstmpl, mapdrslen, ierr)
1048 character(len = 1),
intent(in) :: cgrib(lcgrib)
1049 integer,
intent(in) :: lcgrib
1050 integer,
intent(inout) :: iofst
1051 integer,
intent(out) :: ndpts, idrsnum, idrstmpl(*)
1052 integer,
intent(out) :: ierr
1055 integer,
allocatable :: mapdrs(:)
1056 integer :: mapdrslen
1058 integer :: lensec, i, nbits, isign, newmapdrslen, iret
1065 allocate(mapdrs(lensec))
1083 nbits = iabs(mapdrs(i))*8
1084 if (mapdrs(i).ge.0)
then
1085 call g2_gbytec1(cgrib, idrstmpl(i), iofst, nbits)
1088 call g2_gbytec1(cgrib, idrstmpl(i), iofst + 1, nbits-1)
1089 if (isign.eq.1) idrstmpl(i) = -idrstmpl(i)
1091 iofst = iofst + nbits
1100 do i = mapdrslen + 1, newmapdrslen
1101 nbits = iabs(mapdrs(i)) * 8
1102 if (mapdrs(i) .ge. 0)
then
1103 call g2_gbytec1(cgrib, idrstmpl(i), iofst, nbits)
1106 call g2_gbytec1(cgrib, idrstmpl(i), iofst + 1, nbits - 1)
1107 if (isign .eq. 1) idrstmpl(i) = -idrstmpl(i)
1109 iofst = iofst + nbits
1111 mapdrslen = newmapdrslen
1113 if (
allocated(mapdrs))
deallocate(mapdrs)
1137 subroutine unpack6(cgrib, lcgrib, iofst, ngpts, ibmap, bmap, ierr)
1140 character(len = 1),
intent(in) :: cgrib(lcgrib)
1141 integer,
intent(in) :: lcgrib, ngpts
1142 integer,
intent(inout) :: iofst
1143 integer,
intent(out) :: ibmap
1144 integer,
intent(out) :: ierr
1145 logical*1,
intent(out) :: bmap(ngpts)
1147 integer :: intbmap(ngpts)
1158 if (ibmap.eq.0)
then
1159 call g2_gbytesc(cgrib, intbmap, iofst, 1, 0, ngpts)
1160 iofst = iofst + ngpts
1163 if (intbmap(j).eq.0) bmap(j) = .false.
1165 elseif (ibmap.eq.254)
then
1167 elseif (ibmap.eq.255)
then
1168 bmap(1:ngpts) = .true.
1170 print *,
'unpack6: Predefined bitmap ', ibmap, &
1191 subroutine getdim(csec3, lcsec3, width, height, iscan)
1194 character(len=1),
intent(in) :: csec3(*)
1195 integer,
intent(in) :: lcsec3
1196 integer,
intent(out) :: width,height,iscan
1198 integer,
pointer,
dimension(:) :: igdstmpl,list_opt
1200 integer iofst, igdtlen, num_opt, jerr
1203 subroutine gf_unpack3(cgrib, lcgrib, iofst, igds, igdstmpl, &
1204 mapgridlen, ideflist, idefnum, ierr)
1205 character(len = 1),
intent(in) :: cgrib(lcgrib)
1206 integer,
intent(in) :: lcgrib
1207 integer,
intent(inout) :: iofst
1208 integer,
pointer,
dimension(:) :: igdstmpl, ideflist
1209 integer,
intent(out) :: igds(5)
1210 integer,
intent(out) :: ierr, idefnum
1214 nullify(igdstmpl, list_opt)
1217 call gf_unpack3(csec3, lcsec3, iofst, igds, igdstmpl, &
1218 igdtlen, list_opt, num_opt, jerr)
1220 selectcase( igds(5) )
1223 height = igdstmpl(9)
1224 iscan = igdstmpl(19)
1227 height = igdstmpl(9)
1228 iscan = igdstmpl(16)
1231 height = igdstmpl(9)
1232 iscan = igdstmpl(18)
1235 height = igdstmpl(9)
1236 iscan = igdstmpl(18)
1239 height = igdstmpl(9)
1240 iscan = igdstmpl(19)
1243 height = igdstmpl(9)
1244 iscan = igdstmpl(17)
1247 height = igdstmpl(9)
1248 iscan = igdstmpl(16)
1259 if (
associated(igdstmpl))
deallocate(igdstmpl)
1260 if (
associated(list_opt))
deallocate(list_opt)
1292 subroutine getlocal(cgrib, lcgrib, localnum, csec2, lcsec2, ierr)
1295 character(len = 1),
intent(in) :: cgrib(lcgrib)
1296 integer,
intent(in) :: lcgrib, localnum
1297 character(len = 1),
intent(out) :: csec2(*)
1298 integer,
intent(out) :: lcsec2, ierr
1300 character(len = 4),
parameter :: grib =
'GRIB', c7777 =
'7777'
1301 character(len = 4) :: ctemp
1302 integer :: listsec0(2)
1303 integer iofst, istart, numlocal
1304 integer :: lengrib, lensec, lensec0, j, ipos, isecnum
1310 if (localnum .le. 0)
then
1311 print *,
'getlocal: Request for local section must be positive.'
1319 ctemp = cgrib(j)//cgrib(j+1)//cgrib(j+2)//cgrib(j+3)
1320 if (ctemp .eq. grib)
then
1325 if (istart .eq. 0)
then
1326 print *,
'getlocal: Beginning characters GRIB not found.'
1332 iofst = 8 * (istart + 5)
1333 call g2_gbytec(cgrib, listsec0(1), iofst, 8)
1335 call g2_gbytec(cgrib, listsec0(2), iofst, 8)
1341 ipos = istart + lensec0
1344 if (listsec0(2) .ne. 2)
then
1345 print *,
'getlocal: can only decode GRIB edition 2.'
1355 ctemp = cgrib(ipos) // cgrib(ipos + 1) // cgrib(ipos + 2) // cgrib(ipos + 3)
1356 if (ctemp .eq. c7777)
then
1360 if (ipos .ne. (istart + lengrib))
then
1361 print *,
'getlocal: "7777" found, but not where expected.'
1369 iofst = (ipos - 1) * 8
1377 if (isecnum .eq. 2)
then
1378 numlocal = numlocal + 1
1379 if (numlocal.eq.localnum)
then
1381 csec2(1:lcsec2) = cgrib(ipos + 5:ipos + lensec - 1)
1388 ipos = ipos + lensec
1389 if (ipos .gt. (istart + lengrib))
then
1390 print *,
'getlocal: "7777" not found at end of GRIB message.'
1398 print *,
'getlocal: GRIB message contained ', numlocal,
' local sections.'
1399 print *,
'getlocal: The request was for the ', localnum,
' occurrence.'
1421 character(len = 1),
intent(in) :: csec3(*)
1422 integer,
intent(in) :: lcsec3
1423 integer,
intent(out) :: jj, kk, mm
1425 integer,
pointer,
dimension(:) :: igdstmpl, list_opt
1427 integer iofst, igdtlen, num_opt, jerr
1430 subroutine gf_unpack3(cgrib, lcgrib, iofst, igds, igdstmpl, &
1431 mapgridlen, ideflist, idefnum, ierr)
1432 character(len = 1),
intent(in) :: cgrib(lcgrib)
1433 integer,
intent(in) :: lcgrib
1434 integer,
intent(inout) :: iofst
1435 integer,
pointer,
dimension(:) :: igdstmpl, ideflist
1436 integer,
intent(out) :: igds(5)
1437 integer,
intent(out) :: ierr, idefnum
1441 nullify(igdstmpl, list_opt)
1444 call gf_unpack3(csec3, lcsec3, iofst, igds, igdstmpl, &
1445 igdtlen, list_opt, num_opt, jerr)
1447 selectcase( igds(5) )
1463 if (
associated(igdstmpl))
deallocate(igdstmpl)
1464 if (
associated(list_opt))
deallocate(list_opt)
1529 igdslen, ideflist, idefnum, ipdsnum, ipdstmpl, ipdslen, coordlist, numcoord, ierr)
1532 character(len = 1),
intent(in) :: cgrib(lcgrib)
1533 integer,
intent(in) :: lcgrib, ifldnum
1534 integer,
intent(out) :: igds(*), igdstmpl(*), ideflist(*)
1535 integer,
intent(out) :: ipdsnum, ipdstmpl(*)
1536 integer,
intent(out) :: idefnum, numcoord
1537 integer,
intent(out) :: ierr
1538 real,
intent(out) :: coordlist(*)
1540 character(len = 4),
parameter :: grib =
'GRIB', c7777 =
'7777'
1541 character(len = 4) :: ctemp
1542 integer:: listsec0(2)
1543 integer iofst, istart
1544 logical have3, have4
1545 integer :: igdslen, ipdslen, ipos, isecnum, j, jerr, lengrib, lensec, lensec0, numfld
1548 subroutine g2_gbytec1(in, siout, iskip, nbits)
1549 character*1,
intent(in) :: in(*)
1550 integer,
intent(inout) :: siout
1551 integer,
intent(in) :: iskip, nbits
1561 if (ifldnum .le. 0)
then
1562 print *,
'gettemplates: Request for field number must be positive.'
1570 ctemp = cgrib(j) // cgrib(j + 1) // cgrib(j + 2) // cgrib(j + 3)
1571 if (ctemp .eq. grib )
then
1576 if (istart .eq. 0)
then
1577 print *,
'gettemplates: Beginning characters GRIB not found.'
1583 iofst = 8 * (istart + 5)
1584 call g2_gbytec1(cgrib, listsec0(1), iofst, 8)
1586 call g2_gbytec1(cgrib, listsec0(2), iofst, 8)
1592 ipos = istart + lensec0
1595 if (listsec0(2) .ne. 2)
then
1596 print *,
'gettemplates: can only decode GRIB edition 2.'
1606 ctemp = cgrib(ipos) // cgrib(ipos + 1) // cgrib(ipos + 2) // cgrib(ipos + 3)
1607 if (ctemp .eq. c7777 )
then
1610 if (ipos .ne. (istart + lengrib))
then
1611 print *,
'gettemplates: "7777" found, but not where expected.'
1618 iofst = (ipos - 1) * 8
1628 if (isecnum .eq. 3)
then
1630 call unpack3(cgrib, lcgrib, iofst, igds, igdstmpl, igdslen, ideflist, idefnum, jerr)
1631 if (jerr .eq. 0)
then
1641 if (isecnum .eq. 4)
then
1643 if (numfld .eq. ifldnum)
then
1645 call unpack4(cgrib, lcgrib, iofst, ipdsnum, ipdstmpl, ipdslen, coordlist, numcoord, jerr)
1646 if (jerr .eq. 0)
then
1657 ipos = ipos + lensec
1658 if (ipos .gt. (istart + lengrib))
then
1659 print *,
'gettemplates: "7777" not found at end of GRIB message.'
1664 if (have3 .and. have4)
return
1669 print *,
'gettemplates: GRIB message contained ', numfld,
' different fields.'
1670 print *,
'gettemplates: The request was for the ', ifldnum,
' field.'
subroutine comunpack(cpack, len, lensec, idrsnum, idrstmpl, ndpts, fld, ier)
Unpack a data field that was packed using a complex packing algorithm as defined in the GRIB2 documen...
subroutine g2_gbytesc(in, iout, iskip, nbits, nskip, n)
Extract arbitrary size big-endian integer values (up to 32 bits each) from a packed bit string.
subroutine rdieee(rieee, a, num)
Copy array of 32-bit IEEE floating point values to local floating point representation.
subroutine g2_gbytec(in, iout, iskip, nbits)
Extract one arbitrary size big-endian value (up to 32 bits) from a packed bit string into one element...
subroutine g2_gbytec81(in, siout, iskip, nbits)
Extract one arbitrary size big-endian integer value (up to 64 bits) from a packed bit string into a s...
subroutine g2_gbytescr(in, rout, iskip, nbits, nskip, n)
Extract big-endian floating-point values (32 bits each) from 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 getfield(cgrib, lcgrib, ifldnum, igds, igdstmpl, igdslen, ideflist, idefnum, ipdsnum, ipdstmpl, ipdslen, coordlist, numcoord, ndpts, idrsnum, idrstmpl, idrslen, ibmap, bmap, fld, ierr)
Return the Grid Definition, Product Definition, Bit-map (if applicable), and the unpacked data for a ...
subroutine gb_info(cgrib, lcgrib, listsec0, listsec1, numfields, numlocal, maxlocal, ierr)
Find the number of gridded fields and Local Use Sections in a GRIB2 message.
subroutine gettemplates(cgrib, lcgrib, ifldnum, igds, igdstmpl, igdslen, ideflist, idefnum, ipdsnum, ipdstmpl, ipdslen, coordlist, numcoord, ierr)
Return the Grid Definition and Product Definition for a data field.
subroutine unpack6(cgrib, lcgrib, iofst, ngpts, ibmap, bmap, ierr)
This subroutine unpacks Section 6 (Bit-Map Section) starting at octet 6 of that Section.
subroutine unpack4(cgrib, lcgrib, iofst, ipdsnum, ipdstmpl, mappdslen, coordlist, numcoord, ierr)
This subroutine unpacks Section 4 (Product Definition Section) starting at octet 6 of that Section.
subroutine getlocal(cgrib, lcgrib, localnum, csec2, lcsec2, ierr)
Return the contents of Section 2 (Local Use) from a GRIB2 message.
subroutine unpack3(cgrib, lcgrib, iofst, igds, igdstmpl, mapgridlen, ideflist, idefnum, ierr)
This subroutine unpacks Section 3 (Grid Definition Section) starting at octet 6 of that Section.
subroutine getdim(csec3, lcsec3, width, height, iscan)
Return the dimensions and scanning mode of a grid definition packed in the Grid Definition Section.
subroutine getpoly(csec3, lcsec3, jj, kk, mm)
Return the J, K, and M pentagonal resolution parameters specified in a GRIB2 Grid Definition Section ...
subroutine unpack5(cgrib, lcgrib, iofst, ndpts, idrsnum, idrstmpl, mapdrslen, ierr)
This subroutine unpacks Section 5 (Data Representation Section) starting at octet 6 of that Section.
subroutine gribinfo(cgrib, lcgrib, listsec0, listsec1, numlocal, numfields, maxvals, ierr)
Find the number of Local Use Sections and gridded fields in a GRIB2 message, and the maximum sizes of...
subroutine jpcunpack(cpack, len, idrstmpl, ndpts, fld)
Unpack a data field from a JPEG2000 code stream as defined in Data Representation Template 5....
subroutine pngunpack(cpack, len, idrstmpl, ndpts, fld)
Unpack a data field with PNG, defined in [Data Representation Template 5.40](https://www....
subroutine simunpack(cpack, len, idrstmpl, ndpts, fld)
Unpack a data field that was packed using a simple packing, [Data Representation Template 5....
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.
Handles Data Representation Templates used in Section 5.
subroutine getdrstemplate(number, nummap, map, needext, iret)
Return DRS template information for a specified Data Representation Template.
subroutine extdrstemplate(number, list, nummap, map)
Generate the remaining octet map for a given Data Representation Template, if required.
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 info on all the available GRIB2 Grid Definition Templates used in [Secti...
subroutine getgridtemplate(number, nummap, map, needext, iret)
Get the grid template information for a specified Grid Definition Template.
subroutine extgridtemplate(number, list, nummap, map)
Generate the remaining octet map for a given Grid Definition Template, if required.
Information on all GRIB2 Product Definition Templates used in Section 4 - the Product Definition Sect...
subroutine extpdstemplate(number, list, nummap, map)
This subroutine generates the remaining octet map for a given Product Definition Template,...
subroutine getpdstemplate(number, nummap, map, needext, iret)
This subroutine returns PDS template information for a specified Product Definition Template.