47subroutine cnv12(ifl1, ifl2, ipack, usemiss, imiss, uvvect, table_ver)
51 integer,
intent(in) :: ifl1, ifl2, ipack
52 logical,
intent(in) :: usemiss, uvvect
54 parameter(maxpts = 40000000, msk1 = 32000)
55 CHARACTER(len = 1),
allocatable,
dimension(:) :: cgrib, cgribin
56 integer KPDS(200), KGDS(200), KPTR(200)
57 integer LPDS(200), LGDS(200), KENS(200), LENS(200)
58 integer KPROB(2), KCLUST(16), KMEMBR(80)
60 real,
allocatable,
dimension(:) :: FLD
61 real,
allocatable,
dimension(:) :: FLDV
62 real,
allocatable,
dimension(:) :: coordlist
63 integer :: listsec0(2) = (/0, 2/), imiss
64 integer :: listsec1(13) = (/7, 0, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0/)
65 integer :: ideflist(MAXPTS), idefnum
66 integer :: igds(5) = (/0, 0, 0, 0, 0/), igdstmpl(200), ipdstmpl(200)
67 integer :: ipdstmplv(200)
68 integer :: idrstmpl(200), idrstmplv(200)
69 integer :: currlen = 0, table_ver
70 integer,
parameter :: mingrib = 500
71 logical :: ensemble, ecmwf
72 Logical*1,
allocatable,
dimension(:) :: bmp, bmpv
77 allocate(coordlist(maxpts))
79 listsec1(3) = table_ver
83 call skgb(ifl1, iseek, msk1, lskip, lgrib)
84 if (lgrib .eq. 0)
exit
85 if (lgrib.gt.currlen)
then
86 if (
allocated(cgribin))
deallocate(cgribin)
87 allocate(cgribin(lgrib), stat = is)
90 if (lcgrib .lt. mingrib) lcgrib = mingrib
91 if (
allocated(cgrib))
deallocate(cgrib)
92 allocate(cgrib(lcgrib), stat = is)
94 call baread(ifl1, lskip, lgrib, lengrib, cgribin)
95 if (lgrib .eq. lengrib)
then
96 call w3fi63(cgribin, kpds, kgds, bmp, fld, kptr, iret)
99 print *,
' cnvgrib: Error unpacking GRIB field.', iret
104 print *,
' cnvgrib: IO Error on input GRIB file.'
110 if ((kpds(5) .eq. 34).AND.uvvect) cycle
111 listsec1(1) = kpds(1)
112 listsec1(2) = kpds(23)
114 if (kpds(16) .eq. 1) listsec1(5) = 0
115 listsec1(6) = ((kpds(21)-1)*100)+kpds(8)
116 listsec1(7) = kpds(9)
117 listsec1(8) = kpds(10)
118 listsec1(9) = kpds(11)
119 listsec1(10) = kpds(12)
121 if (kpds(16) .eq. 1) listsec1(13) = 0
123 if ((kpds(23) .eq. 2) .or. &
124 (kptr(3).gt.28 .and. kpds(19) .eq. 2 .and. &
125 (kpds(5) .eq. 191 .or. kpds(5) .eq. 192)))
then
130 call pdseup(kens, kprob, xprob, kclust, kmembr, ilast, cgribin(9))
131 if (kens(2) .eq. 1) listsec1(13) = 3
132 if (kens(2) .eq. 2 .OR. kens(2) .eq. 3) listsec1(13) = 4
133 if (kens(2) .eq. 5) listsec1(13) = 5
136 if (kpds(1) .eq. 98) ecmwf = .true.
141 if (ensemble.and.(kpds(5) .eq. 191 .or. kpds(5) .eq. 192).and. &
142 kpds(19) .eq. 2)
then
151 call gribcreate(cgrib, lcgrib, listsec0, listsec1, ierr)
152 if (ierr .ne. 0)
then
153 write(6, *)
' ERROR creating new GRIB2 field = ', ierr
158 call gds2gdt(kgds, igds, igdstmpl, idefnum, ideflist, ierr)
159 if (ierr .ne. 0)
then
162 if (listsec1(1) .eq. 7) igdstmpl(1) = 6
163 if ((listsec1(1) .eq. 7 .and. igds(5) .eq. 20 &
164 .and. kpds(2) .eq. 25) .and. &
165 (kpds(5) .eq. 91 .or. kpds(5) .eq. 238))
then
168 call addgrid(cgrib, lcgrib, igds, igdstmpl, 200, ideflist, &
170 if (ierr .ne. 0)
then
171 write(6, *)
' ERROR adding GRIB2 grid = ', ierr
177 call pds2pdtens(kpds, kens, kprob, xprob, kclust, kmembr, &
178 ipdsnum, ipdstmpl, numcoord, coordlist, ierr)
180 call pds2pdt(kpds, ipdsnum, ipdstmpl, numcoord, coordlist, ierr)
182 if (ierr .ne. 0)
then
188 if (btest(kpds(4), 6))
then
196 if ((usemiss) .AND. (ipack .eq. 2 .OR. ipack .eq. 31 .OR. &
199 rmiss = minval(fld(1:numpts))
200 if (rmiss .lt. -9999.0)
then
206 if (.NOT. bmp(i))
then
212 call mkieee(rmiss, idrstmpl(8), 1)
220 if (ipack .eq. 0)
then
222 elseif (ipack .eq. 2)
then
225 elseif (ipack .eq. 31 .OR. ipack .eq. 32)
then
228 idrstmpl(17) = mod(ipack, 10)
229 elseif (ipack .eq. 40 .OR. ipack .eq. 41 .OR. &
230 ipack .eq. 40000 .OR. ipack .eq. 40010)
then
240 if (kpds(5) .eq. 61) idrsnum = 2
242 idrstmpl(2) = kptr(19)
243 idrstmpl(3) = kpds(22)
246 call addfield(cgrib, lcgrib, ipdsnum, ipdstmpl, 200, &
247 coordlist, numcoord, idrsnum, idrstmpl, 200, &
248 fld, numpts, ibmap, bmp, ierr)
250 if (ierr .ne. 0)
then
251 write(6, *)
' ERROR adding GRIB2 field = ', ierr
255 if ((kpds(5) .eq. 33) .AND. uvvect)
then
256 if (.not.
allocated(fldv))
allocate(fldv(maxpts))
257 if (.not.
allocated(bmpv))
allocate(bmpv(maxpts))
264 CALL getgbe(ifl1, ifli1, maxpts, jsrch, lpds, lgds, lens, numptso, &
265 jsrch, kpds, kgds, kens, bmpv, fldv, icnd)
266 if (icnd .ne. 0)
then
267 write(6, *)
' ERROR READING/UNPACKING GRIB1 V = ', icnd
274 ipdstmplv(1), ipdstmplv(2))
282 if (btest(kpds(4), 6))
then
284 if (any(bmp(1:igds(2)) .NEQV. bmpv(1:igds(2))))
then
288 if ((usemiss) .AND. (ipack .eq. 2 .OR. ipack .eq. 31 .OR. &
291 rmiss = minval(fldv(1:numpts))
292 if (rmiss .lt. -9999.0)
then
298 if (.NOT. bmpv(i))
then
304 call mkieee(rmiss, idrstmplv(8), 1)
315 if (ipack .eq. 0)
then
317 elseif (ipack .eq. 2)
then
320 elseif (ipack .eq. 31 .OR. ipack .eq. 32)
then
323 idrstmplv(17) = mod(ipack, 10)
324 elseif (ipack .eq. 40 .OR. ipack .eq. 41 .OR. &
325 ipack .eq. 40000 .OR. ipack .eq. 40010)
then
335 if (kpds(5) .eq. 61) idrsnum = 2
337 idrstmplv(2) = kptr(19)
338 idrstmplv(3) = kpds(22)
341 call addfield(cgrib, lcgrib, ipdsnum, ipdstmplv, 200, &
342 coordlist, numcoord, idrsnum, idrstmplv, 200, &
343 fldv, numpts, ibmap, bmpv, ierr)
344 if (ierr .ne. 0)
then
345 write(6, *)
' ERROR adding second GRIB2 field = ', ierr
350 call gribend(cgrib, lcgrib, lengrib, ierr)
351 if (ierr .ne. 0)
then
352 write(6, *)
' ERROR ending new GRIB2 message = ', ierr
356 call wryte(ifl2, lengrib, cgrib)
360 if (
allocated(cgribin))
deallocate(cgribin)
361 if (
allocated(cgrib))
deallocate(cgrib)
362 if (
allocated(fld))
deallocate(fld)
363 if (
allocated(fldv))
deallocate(fldv)
364 if (
allocated(coordlist))
deallocate(coordlist)
365 if (
allocated(bmp))
deallocate(bmp)
366 if (
allocated(bmpv))
deallocate(bmpv)
406subroutine gds2gdt(kgds,igds,igdstmpl,idefnum,ideflist,iret)
408 integer,
intent(in) :: kgds(*)
409 integer,
intent(out) :: igds(*),igdstmpl(*),ideflist(*)
410 integer,
intent(out) :: idefnum,iret
413 if (kgds(1).eq.0)
then
416 igds(2)=kgds(2)*kgds(3)
420 if (btest(kgds(6),6))
then
435 igdstmpl(12)=kgds(4)*1000
436 if (kgds(5).lt.0)
then
437 igdstmpl(13)=(360000+kgds(5))*1000
439 igdstmpl(13)=kgds(5)*1000
442 if (btest(kgds(6),7)) igdstmpl(14)=48
443 if (btest(kgds(6),3)) igdstmpl(14)=igdstmpl(14)+8
444 igdstmpl(15)=kgds(7)*1000
445 if (kgds(8).lt.0)
then
446 igdstmpl(16)=(360000+kgds(8))*1000
448 igdstmpl(16)=kgds(8)*1000
450 igdstmpl(17)=kgds(9)*1000
451 igdstmpl(18)=kgds(10)*1000
452 igdstmpl(19)=kgds(11)
453 if (kgds(20).ne.255)
then
456 if (kgds(2).eq.65535) idefnum=kgds(3)
457 if (kgds(3).eq.65535) idefnum=kgds(2)
460 ideflist(j)=kgds(21+j)
461 if (ideflist(j).gt.imax) imax=ideflist(j)
464 if (imax.gt.255) igds(3)=2
465 if (imax.gt.65535) igds(3)=3
466 if (imax.gt.16777215) igds(3)=4
471 elseif (kgds(1).eq.1)
then
474 igds(2)=kgds(2)*kgds(3)
478 if (btest(kgds(6),6))
then
491 igdstmpl(10)=kgds(4)*1000
492 if (kgds(5).lt.0)
then
493 igdstmpl(11)=(360000+kgds(5))*1000
495 igdstmpl(11)=kgds(5)*1000
498 if (btest(kgds(6),7)) igdstmpl(12)=48
499 if (btest(kgds(6),3)) igdstmpl(12)=igdstmpl(12)+8
500 igdstmpl(13)=kgds(9)*1000
501 igdstmpl(14)=kgds(7)*1000
502 if (kgds(8).lt.0)
then
503 igdstmpl(15)=(360000+kgds(8))*1000
505 igdstmpl(15)=kgds(8)*1000
507 igdstmpl(16)=kgds(11)
509 igdstmpl(18)=kgds(12)*1000
510 igdstmpl(19)=kgds(13)*1000
511 elseif (kgds(1).eq.3)
then
514 igds(2)=kgds(2)*kgds(3)
518 if (btest(kgds(6),6))
then
531 igdstmpl(10)=kgds(4)*1000
532 if (kgds(5).lt.0)
then
533 igdstmpl(11)=(360000+kgds(5))*1000
535 igdstmpl(11)=kgds(5)*1000
538 if (btest(kgds(6),7)) igdstmpl(12)=48
539 if (btest(kgds(6),3)) igdstmpl(12)=igdstmpl(12)+8
540 igdstmpl(13)=kgds(12)*1000
541 if (kgds(7).lt.0)
then
542 igdstmpl(14)=(360000+kgds(7))*1000
544 igdstmpl(14)=kgds(7)*1000
546 igdstmpl(15)=kgds(8)*1000
547 igdstmpl(16)=kgds(9)*1000
548 igdstmpl(17)=kgds(10)
549 igdstmpl(18)=kgds(11)
550 igdstmpl(19)=kgds(12)*1000
551 igdstmpl(20)=kgds(13)*1000
552 igdstmpl(21)=kgds(14)*1000
553 if (kgds(15).lt.0)
then
554 igdstmpl(22)=(360000+kgds(15))*1000
556 igdstmpl(22)=kgds(15)*1000
558 elseif (kgds(1).eq.4)
then
561 igds(2)=kgds(2)*kgds(3)
565 if (btest(kgds(6),6))
then
580 igdstmpl(12)=kgds(4)*1000
581 if (kgds(5).lt.0)
then
582 igdstmpl(13)=(360000+kgds(5))*1000
584 igdstmpl(13)=kgds(5)*1000
587 if (btest(kgds(6),7)) igdstmpl(14)=48
588 if (btest(kgds(6),3)) igdstmpl(14)=igdstmpl(14)+8
589 igdstmpl(15)=kgds(7)*1000
590 if (kgds(8).lt.0)
then
591 igdstmpl(16)=(360000+kgds(8))*1000
593 igdstmpl(16)=kgds(8)*1000
595 igdstmpl(17)=kgds(9)*1000
596 igdstmpl(18)=kgds(10)
597 igdstmpl(19)=kgds(11)
598 elseif (kgds(1).eq.5)
then
601 igds(2)=kgds(2)*kgds(3)
605 if (btest(kgds(6),6))
then
618 igdstmpl(10)=kgds(4)*1000
619 if (kgds(5).lt.0)
then
620 igdstmpl(11)=(360000+kgds(5))*1000
622 igdstmpl(11)=kgds(5)*1000
625 if (btest(kgds(6),7)) igdstmpl(12)=48
626 if (btest(kgds(6),3)) igdstmpl(12)=igdstmpl(12)+8
627 igdstmpl(13)=60000000
628 if (btest(kgds(10),7)) igdstmpl(13)=-60000000
629 if (kgds(7).lt.0)
then
630 igdstmpl(14)=(360000+kgds(7))*1000
632 igdstmpl(14)=kgds(7)*1000
634 igdstmpl(15)=kgds(8)*1000
635 igdstmpl(16)=kgds(9)*1000
636 igdstmpl(17)=kgds(10)
637 igdstmpl(18)=kgds(11)
638 elseif (kgds(1).eq.204)
then
641 igds(2)=kgds(2)*kgds(3)
645 if (btest(kgds(6),6))
then
663 if (btest(kgds(6),7)) igdstmpl(14)=48
664 if (btest(kgds(6),3)) igdstmpl(14)=igdstmpl(14)+8
669 igdstmpl(19)=kgds(11)
670 elseif (kgds(1).eq.203)
then
673 igds(2)=kgds(2)*kgds(3)
677 if (btest(kgds(6),6))
then
692 igdstmpl(12)=kgds(4)*1000
693 if (kgds(5).lt.0)
then
694 igdstmpl(13)=(360000+kgds(5))*1000
696 igdstmpl(13)=kgds(5)*1000
699 if (btest(kgds(6),7)) igdstmpl(14)=48
700 if (btest(kgds(6),3)) igdstmpl(14)=igdstmpl(14)+8
701 igdstmpl(15)=kgds(7)*1000
702 if (kgds(8).lt.0)
then
703 igdstmpl(16)=(360000+kgds(8))*1000
705 igdstmpl(16)=kgds(8)*1000
707 igdstmpl(17)=kgds(9)*1000
708 igdstmpl(18)=kgds(10)*1000
709 igdstmpl(19)=kgds(11)
710 elseif (kgds(1).eq.205)
then
713 igds(2)=kgds(2)*kgds(3)
717 if (btest(kgds(6),6))
then
732 igdstmpl(12)=kgds(4)*1000
733 if (kgds(5).lt.0)
then
734 igdstmpl(13)=(360000+kgds(5))*1000
736 igdstmpl(13)=kgds(5)*1000
739 if (btest(kgds(6),7)) igdstmpl(14)=48
740 if (btest(kgds(6),3)) igdstmpl(14)=igdstmpl(14)+8
741 igdstmpl(15)=kgds(7)*1000
742 if (kgds(8).lt.0)
then
743 igdstmpl(16)=(360000+kgds(8))*1000
745 igdstmpl(16)=kgds(8)*1000
747 igdstmpl(17)=kgds(9)*1000
748 igdstmpl(18)=kgds(10)*1000
749 igdstmpl(19)=kgds(11)
750 igdstmpl(20)=kgds(12)*1000
751 igdstmpl(21)=kgds(13)*1000
753 print *,
'gds2gdt: Unrecognized GRIB1 Grid type = ',kgds(1)
788subroutine pds2pdt(kpds,ipdsnum,ipdstmpl,numcoord,coordlist, &
794 integer,
intent(in) :: kpds(*)
795 integer,
intent(out) :: ipdstmpl(*)
796 real,
intent(out) :: coordlist(*)
797 integer,
intent(out) :: ipdsnum,numcoord,iret
799 integer :: idat(8),jdat(8)
807 if (kpds(1).eq.98) ecmwf=.true.
812 if ((kpds(2).eq.96 .AND. kpds(3).eq.45 .AND. &
813 kpds(16).eq.10) .AND. &
814 (kpds(19).eq.140 .AND. (kpds(5).ge.168 .AND. &
815 kpds(5).le.173)))
then
821 ipdstmpl(1),ipdstmpl(2))
832 if (kpds(13).eq.254) ipdstmpl(8)=13
834 call cnvlevel(kpds(6),kpds(7),ipdstmpl)
835 if (kpds(5).eq.168.or.kpds(5).eq.170.or. &
836 kpds(5).eq.172) ipdstmpl(16)=0
837 if (kpds(5).eq.169.or.kpds(5).eq.171.or. &
838 kpds(5).eq.173) ipdstmpl(16)=2
842 elseif (kpds(16).eq.0.or.kpds(16).eq.1.or.kpds(16).eq.10)
then
848 ipdstmpl(1),ipdstmpl(2))
853 if (kpds(16).eq.1)
then
863 if (kpds(13).eq.254) ipdstmpl(8)=13
869 call cnvlevel(kpds(6),kpds(7),ipdstmpl)
870 if (kpds(2).eq.96 .AND. kpds(3).eq.45 .AND. &
872 if (kpds(5).eq.174) ipdstmpl(10) = 10
873 if (kpds(5).eq.179) ipdstmpl(10) = 11
874 if (kpds(5).eq.180) ipdstmpl(10) = 12
876 elseif (kpds(16).ge.2.AND.kpds(16).le.5)
then
882 ipdstmpl(1),ipdstmpl(2))
893 if (kpds(13).eq.254) ipdstmpl(8)=13
895 call cnvlevel(kpds(6),kpds(7),ipdstmpl)
899 idat(1)=((kpds(21)-1)*100)+kpds(8)
906 if ( ipdstmpl(8).eq.0 )
then
908 elseif ( ipdstmpl(8).eq.1 )
then
910 elseif ( ipdstmpl(8).eq.2 )
then
912 elseif ( ipdstmpl(8).eq.10 )
then
914 elseif ( ipdstmpl(8).eq.11 )
then
916 elseif ( ipdstmpl(8).eq.12 )
then
917 rinc(2)=kpds(15) * 12
918 elseif ( ipdstmpl(8).eq.13 )
then
921 call w3movdat(rinc,idat,jdat)
929 ipdstmpl(23)=kpds(20)
930 if (kpds(16).eq.2)
then
932 elseif (kpds(16).eq.3)
then
934 elseif (kpds(16).eq.4)
then
936 elseif (kpds(16).eq.5)
then
940 if (kpds(19).eq.129 .AND. &
941 (kpds(5).eq.235 .or. kpds(5).eq.236 .or. &
942 kpds(5).eq.237 .or. kpds(5).eq.238 .or. &
943 kpds(5).eq.239 .or. kpds(5).eq.253 .or. &
944 kpds(5).eq.254 ))
then
947 ipdstmpl(26)=kpds(13)
948 if (kpds(13).eq.254) ipdstmpl(26)=13
949 ipdstmpl(27)=kpds(15)-kpds(14)
952 elseif (kpds(16).eq.7)
then
958 ipdstmpl(1),ipdstmpl(2))
969 if (kpds(13).eq.254) ipdstmpl(8)=13
970 ipdstmpl(9)= - kpds(14)
971 call cnvlevel(kpds(6),kpds(7),ipdstmpl)
975 idat(1)=((kpds(21)-1)*100)+kpds(8)
982 if ( ipdstmpl(8).eq.0 )
then
984 elseif ( ipdstmpl(8).eq.1 )
then
986 elseif ( ipdstmpl(8).eq.2 )
then
988 elseif ( ipdstmpl(8).eq.10 )
then
990 elseif ( ipdstmpl(8).eq.11 )
then
992 elseif ( ipdstmpl(8).eq.12 )
then
993 rinc(2)=kpds(15) * 12
994 elseif ( ipdstmpl(8).eq.13 )
then
997 call w3movdat(rinc,idat,jdat)
1000 ipdstmpl(18)=jdat(3)
1001 ipdstmpl(19)=jdat(5)
1002 ipdstmpl(20)=jdat(6)
1003 ipdstmpl(21)=jdat(7)
1005 ipdstmpl(23)=kpds(20)
1008 ipdstmpl(26)=kpds(13)
1009 if (kpds(13).eq.254) ipdstmpl(26)=13
1010 ipdstmpl(27)=kpds(15) + kpds(14)
1013 elseif (kpds(16).eq.51)
then
1019 ipdstmpl(1),ipdstmpl(2))
1029 ipdstmpl(8)=kpds(13)
1030 if (kpds(13).eq.254) ipdstmpl(8)=13
1031 ipdstmpl(9)=kpds(14)
1032 call cnvlevel(kpds(6),kpds(7),ipdstmpl)
1036 idat(1)=((kpds(21)-1)*100)+kpds(8)
1043 if ( ipdstmpl(8).eq.0 )
then
1045 elseif ( ipdstmpl(8).eq.1 )
then
1047 elseif ( ipdstmpl(8).eq.2 )
then
1049 elseif ( ipdstmpl(8).eq.10 )
then
1050 rinc(2)=kpds(15) * 3
1051 elseif ( ipdstmpl(8).eq.11 )
then
1052 rinc(2)=kpds(15) * 6
1053 elseif ( ipdstmpl(8).eq.12 )
then
1054 rinc(2)=kpds(15) * 12
1055 elseif ( ipdstmpl(8).eq.13 )
then
1058 call w3movdat(rinc,idat,jdat)
1059 ipdstmpl(16)=jdat(1)
1060 ipdstmpl(17)=jdat(2)
1061 ipdstmpl(18)=jdat(3)
1062 ipdstmpl(19)=jdat(5)
1063 ipdstmpl(20)=jdat(6)
1064 ipdstmpl(21)=jdat(7)
1066 ipdstmpl(23)=kpds(20)
1069 ipdstmpl(26)=kpds(13)
1070 if (kpds(13).eq.254) ipdstmpl(26)=13
1071 ipdstmpl(27)=kpds(15)-kpds(14)
1075 print *,
' Unrecognized Time Range Indicator = ',kpds(16)
1076 print *,
'pds2pdt: Couldn:t construct PDS Template '
1100 integer,
intent(in) :: ltype,lval
1101 integer,
intent(inout) :: ipdstmpl(*)
1110 if (ltype.eq.100)
then
1111 ipdstmpl(12)=lval*100
1112 elseif (ltype.eq.101)
then
1114 ipdstmpl(12)=(lval/256)*1000
1116 ipdstmpl(15)=mod(lval,256)*1000
1117 elseif (ltype.eq.102)
then
1119 elseif (ltype.eq.103)
then
1122 elseif (ltype.eq.104)
then
1124 ipdstmpl(12)=lval/256
1126 ipdstmpl(15)=mod(lval,256)
1127 elseif (ltype.eq.105)
then
1130 elseif (ltype.eq.106)
then
1132 ipdstmpl(12)=(lval/256)*100
1134 ipdstmpl(15)=mod(lval,256)*100
1135 elseif (ltype.eq.107)
then
1139 elseif (ltype.eq.108)
then
1142 ipdstmpl(12)=lval/256
1145 ipdstmpl(15)=mod(lval,256)
1146 elseif (ltype.eq.109)
then
1149 elseif (ltype.eq.110)
then
1151 ipdstmpl(12)=lval/256
1153 ipdstmpl(15)=mod(lval,256)
1154 elseif (ltype.eq.111)
then
1158 elseif (ltype.eq.112)
then
1161 ipdstmpl(12)=lval/256
1164 ipdstmpl(15)=mod(lval,256)
1165 elseif (ltype.eq.113)
then
1168 elseif (ltype.eq.114)
then
1170 ipdstmpl(12)=475+(lval/256)
1172 ipdstmpl(15)=475+mod(lval,256)
1173 elseif (ltype.eq.115)
then
1175 ipdstmpl(12)=lval*100
1176 elseif (ltype.eq.116)
then
1178 ipdstmpl(12)=(lval/256)*100
1180 ipdstmpl(15)=mod(lval,256)*100
1181 elseif (ltype.eq.117)
then
1185 if ( btest(lval,15) )
then
1186 ipdstmpl(12)=-1*mod(lval,32768)
1188 elseif (ltype.eq.119)
then
1192 elseif (ltype.eq.120)
then
1195 ipdstmpl(12)=lval/256
1198 ipdstmpl(15)=mod(lval,256)
1199 elseif (ltype.eq.121)
then
1201 ipdstmpl(12)=(1100+(lval/256))*100
1203 ipdstmpl(15)=(1100+mod(lval,256))*100
1204 elseif (ltype.eq.125)
then
1208 elseif (ltype.eq.126)
then
1211 elseif (ltype.eq.128)
then
1214 ipdstmpl(12)=1100+(lval/256)
1217 ipdstmpl(15)=1100+mod(lval,256)
1218 elseif (ltype.eq.141)
then
1220 ipdstmpl(12)=(lval/256)*100
1222 ipdstmpl(15)=(1100+mod(lval,256))*100
1223 elseif (ltype.eq.160)
then
1226 elseif (ltype.gt.99.AND.ltype.lt.200)
then
1227 print *,
'cnvlevel: GRIB1 Level ',ltype,
' not recognized.'
1229 elseif (ltype.eq.235)
then
1232 elseif (ltype.eq.236)
then
1234 ipdstmpl(12)=lval/256
1236 ipdstmpl(15)=mod(lval,256)
1237 elseif (ltype.ge.237.AND.ltype.le.239)
then
1276 ipdsnum,ipdstmpl,numcoord,coordlist, &
1281 integer,
intent(in) :: kpds(*),kens(*),kprob(*),kclust(*)
1282 integer,
intent(in) :: kmember(*)
1283 real,
intent(in) :: xprob(*)
1284 integer,
intent(out) :: ipdstmpl(*)
1285 real,
intent(out) :: coordlist(*)
1286 integer,
intent(out) :: ipdsnum,numcoord,iret
1288 integer :: idat(8),jdat(8)
1293 if (kens(2).eq.1.or.kens(2).eq.2.or.kens(2).eq.3)
then
1295 if (kpds(16).eq.0.or.kpds(16).eq.1.or.kpds(16).eq.10)
then
1307 ipdstmpl(8)=kpds(13)
1308 if (kpds(13).eq.254) ipdstmpl(8)=13
1312 ipdstmpl(9)=kpds(14)
1314 call cnvlevel(kpds(6),kpds(7),ipdstmpl)
1315 if (kens(2).eq.1)
then
1318 ipdstmpl(16)=kens(3)-1
1320 elseif (kens(2).eq.2)
then
1322 ipdstmpl(17)=kens(3)
1323 elseif (kens(2).eq.3)
then
1325 ipdstmpl(17)=kens(3)
1328 elseif (kpds(16).ge.2.AND.kpds(16).le.5)
then
1340 ipdstmpl(8)=kpds(13)
1341 if (kpds(13).eq.254) ipdstmpl(8)=13
1342 ipdstmpl(9)=kpds(14)
1343 call cnvlevel(kpds(6),kpds(7),ipdstmpl)
1345 if (kens(2).eq.1)
then
1348 ipdstmpl(16)=kens(3)-1
1350 elseif (kens(2).eq.2)
then
1352 ipdstmpl(17)=kens(3)
1353 elseif (kens(2).eq.3)
then
1355 ipdstmpl(17)=kens(3)
1361 idat(1)=((kpds(21)-1)*100)+kpds(8)
1368 if ( ipdstmpl(8).eq.0 )
then
1370 elseif ( ipdstmpl(8).eq.1 )
then
1372 elseif ( ipdstmpl(8).eq.2 )
then
1374 elseif ( ipdstmpl(8).eq.10 )
then
1375 rinc(2)=kpds(15) * 3
1376 elseif ( ipdstmpl(8).eq.11 )
then
1377 rinc(2)=kpds(15) * 6
1378 elseif ( ipdstmpl(8).eq.12 )
then
1379 rinc(2)=kpds(15) * 12
1380 elseif ( ipdstmpl(8).eq.13 )
then
1383 call w3movdat(rinc,idat,jdat)
1384 ipdstmpl(19)=jdat(1)
1385 ipdstmpl(20)=jdat(2)
1386 ipdstmpl(21)=jdat(3)
1387 ipdstmpl(22)=jdat(5)
1388 ipdstmpl(23)=jdat(6)
1389 ipdstmpl(24)=jdat(7)
1392 if (kpds(16).eq.2)
then
1394 if (kpds(5).eq.15) ipdstmpl(27)=2
1395 if (kpds(5).eq.16) ipdstmpl(27)=3
1396 elseif (kpds(16).eq.3)
then
1398 elseif (kpds(16).eq.4)
then
1400 elseif (kpds(16).eq.5)
then
1404 ipdstmpl(29)=kpds(13)
1405 if (kpds(13).eq.254) ipdstmpl(29)=13
1406 ipdstmpl(30)=kpds(15)-kpds(14)
1409 elseif (kpds(16).eq.51)
then
1421 ipdstmpl(8)=kpds(13)
1422 if (kpds(13).eq.254) ipdstmpl(8)=13
1423 ipdstmpl(9)=kpds(14)
1424 call cnvlevel(kpds(6),kpds(7),ipdstmpl)
1426 if (kens(2).eq.1)
then
1429 ipdstmpl(16)=kens(3)-1
1431 elseif (kens(2).eq.2)
then
1433 ipdstmpl(17)=kens(3)
1434 elseif (kens(2).eq.3)
then
1436 ipdstmpl(17)=kens(3)
1442 idat(1)=((kpds(21)-1)*100)+kpds(8)
1449 if ( ipdstmpl(8).eq.0 )
then
1451 elseif ( ipdstmpl(8).eq.1 )
then
1453 elseif ( ipdstmpl(8).eq.2 )
then
1455 elseif ( ipdstmpl(8).eq.10 )
then
1456 rinc(2)=kpds(15) * 3
1457 elseif ( ipdstmpl(8).eq.11 )
then
1458 rinc(2)=kpds(15) * 6
1459 elseif ( ipdstmpl(8).eq.12 )
then
1460 rinc(2)=kpds(15) * 12
1461 elseif ( ipdstmpl(8).eq.13 )
then
1464 call w3movdat(rinc,idat,jdat)
1465 ipdstmpl(19)=jdat(1)
1466 ipdstmpl(20)=jdat(2)
1467 ipdstmpl(21)=jdat(3)
1468 ipdstmpl(22)=jdat(5)
1469 ipdstmpl(23)=jdat(6)
1470 ipdstmpl(24)=jdat(7)
1475 ipdstmpl(29)=kpds(13)
1476 if (kpds(13).eq.254) ipdstmpl(29)=13
1477 ipdstmpl(30)=kpds(15)-kpds(14)
1481 print *,
' Unrecognized Time Range Ind for ensembles = ', &
1483 print *,
'pds2pdtens: Couldn:t construct PDS Template '
1487 elseif (kens(2).eq.5)
then
1488 if (kpds(5).eq.191.OR.kpds(5).eq.192)
then
1489 if (kpds(16).eq.0.or.kpds(16).eq.1.or.kpds(16).eq.10)
then
1501 ipdstmpl(8)=kpds(13)
1502 if (kpds(13).eq.254) ipdstmpl(8)=13
1506 ipdstmpl(9)=kpds(14)
1508 call cnvlevel(kpds(6),kpds(7),ipdstmpl)
1510 ipdstmpl(17)=kclust(1)
1511 ipdstmpl(18)=kprob(2)-1
1512 if (ipdstmpl(18).eq.0.OR.ipdstmpl(18).eq.2)
then
1514 ipdstmpl(20)=nint(xprob(1)*1000.0)
1519 if (ipdstmpl(18).eq.1.OR.ipdstmpl(18).eq.2)
then
1521 ipdstmpl(22)=nint(xprob(2)*1000.0)
1526 elseif (kpds(16).ge.2.AND.kpds(16).le.5)
then
1538 ipdstmpl(8)=kpds(13)
1539 if (kpds(13).eq.254) ipdstmpl(8)=13
1540 ipdstmpl(9)=kpds(14)
1541 call cnvlevel(kpds(6),kpds(7),ipdstmpl)
1544 ipdstmpl(17)=kclust(1)
1545 ipdstmpl(18)=kprob(2)-1
1546 if (ipdstmpl(18).eq.0.OR.ipdstmpl(18).eq.2)
then
1548 ipdstmpl(20)=nint(xprob(1)*1000.0)
1553 if (ipdstmpl(18).eq.1.OR.ipdstmpl(18).eq.2)
then
1555 ipdstmpl(22)=nint(xprob(2)*1000.0)
1563 idat(1)=((kpds(21)-1)*100)+kpds(8)
1570 if ( ipdstmpl(8).eq.0 )
then
1572 elseif ( ipdstmpl(8).eq.1 )
then
1574 elseif ( ipdstmpl(8).eq.2 )
then
1576 elseif ( ipdstmpl(8).eq.10 )
then
1577 rinc(2)=kpds(15) * 3
1578 elseif ( ipdstmpl(8).eq.11 )
then
1579 rinc(2)=kpds(15) * 6
1580 elseif ( ipdstmpl(8).eq.12 )
then
1581 rinc(2)=kpds(15) * 12
1582 elseif ( ipdstmpl(8).eq.13 )
then
1585 call w3movdat(rinc,idat,jdat)
1586 ipdstmpl(23)=jdat(1)
1587 ipdstmpl(24)=jdat(2)
1588 ipdstmpl(25)=jdat(3)
1589 ipdstmpl(26)=jdat(5)
1590 ipdstmpl(27)=jdat(6)
1591 ipdstmpl(28)=jdat(7)
1594 if (kpds(16).eq.2)
then
1596 if (kpds(5).eq.15) ipdstmpl(31)=2
1597 if (kpds(5).eq.16) ipdstmpl(31)=3
1598 elseif (kpds(16).eq.3)
then
1600 elseif (kpds(16).eq.4)
then
1602 elseif (kpds(16).eq.5)
then
1606 ipdstmpl(33)=kpds(13)
1607 if (kpds(13).eq.254) ipdstmpl(33)=13
1608 ipdstmpl(34)=kpds(15)-kpds(14)
1611 elseif (kpds(16).eq.51)
then
1623 ipdstmpl(8)=kpds(13)
1624 if (kpds(13).eq.254) ipdstmpl(8)=13
1625 ipdstmpl(9)=kpds(14)
1626 call cnvlevel(kpds(6),kpds(7),ipdstmpl)
1629 ipdstmpl(17)=kclust(1)
1630 ipdstmpl(18)=kprob(2)-1
1631 if (ipdstmpl(18).eq.0.OR.ipdstmpl(18).eq.2)
then
1633 ipdstmpl(20)=nint(xprob(1)*1000.0)
1638 if (ipdstmpl(18).eq.1.OR.ipdstmpl(18).eq.2)
then
1640 ipdstmpl(22)=nint(xprob(2)*1000.0)
1648 idat(1)=((kpds(21)-1)*100)+kpds(8)
1655 if ( ipdstmpl(8).eq.0 )
then
1657 elseif ( ipdstmpl(8).eq.1 )
then
1659 elseif ( ipdstmpl(8).eq.2 )
then
1661 elseif ( ipdstmpl(8).eq.10 )
then
1662 rinc(2)=kpds(15) * 3
1663 elseif ( ipdstmpl(8).eq.11 )
then
1664 rinc(2)=kpds(15) * 6
1665 elseif ( ipdstmpl(8).eq.12 )
then
1666 rinc(2)=kpds(15) * 12
1667 elseif ( ipdstmpl(8).eq.13 )
then
1670 call w3movdat(rinc,idat,jdat)
1671 ipdstmpl(23)=jdat(1)
1672 ipdstmpl(24)=jdat(2)
1673 ipdstmpl(25)=jdat(3)
1674 ipdstmpl(26)=jdat(5)
1675 ipdstmpl(27)=jdat(6)
1676 ipdstmpl(28)=jdat(7)
1681 ipdstmpl(33)=kpds(13)
1682 if (kpds(13).eq.254) ipdstmpl(33)=13
1683 ipdstmpl(34)=kpds(15)-kpds(14)
1687 print *,
' Unrecognized Time Range Ind for Probs = ', &
1689 print *,
'pds2pdtens: Couldn:t construct PDS Template '
1693 if (kpds(16).eq.0.or.kpds(16).eq.1.or.kpds(16).eq.10)
then
1705 ipdstmpl(8)=kpds(13)
1706 if (kpds(13).eq.254) ipdstmpl(8)=13
1710 ipdstmpl(9)=kpds(14)
1712 call cnvlevel(kpds(6),kpds(7),ipdstmpl)
1713 if (kens(4).eq.1)
then
1715 elseif (kens(4).eq.2)
then
1717 elseif (kens(4).eq.11)
then
1719 elseif (kens(4).eq.12)
then
1722 ipdstmpl(17)=kclust(1)
1723 elseif (kpds(16).ge.2.AND.kpds(16).le.5)
then
1735 ipdstmpl(8)=kpds(13)
1736 if (kpds(13).eq.254) ipdstmpl(8)=13
1737 ipdstmpl(9)=kpds(14)
1738 call cnvlevel(kpds(6),kpds(7),ipdstmpl)
1740 if (kens(4).eq.1)
then
1742 elseif (kens(4).eq.2)
then
1744 elseif (kens(4).eq.11)
then
1746 elseif (kens(4).eq.12)
then
1749 ipdstmpl(17)=kclust(1)
1753 idat(1)=((kpds(21)-1)*100)+kpds(8)
1760 if ( ipdstmpl(8).eq.0 )
then
1762 elseif ( ipdstmpl(8).eq.1 )
then
1764 elseif ( ipdstmpl(8).eq.2 )
then
1766 elseif ( ipdstmpl(8).eq.10 )
then
1767 rinc(2)=kpds(15) * 3
1768 elseif ( ipdstmpl(8).eq.11 )
then
1769 rinc(2)=kpds(15) * 6
1770 elseif ( ipdstmpl(8).eq.12 )
then
1771 rinc(2)=kpds(15) * 12
1772 elseif ( ipdstmpl(8).eq.13 )
then
1775 call w3movdat(rinc,idat,jdat)
1776 ipdstmpl(18)=jdat(1)
1777 ipdstmpl(19)=jdat(2)
1778 ipdstmpl(20)=jdat(3)
1779 ipdstmpl(21)=jdat(5)
1780 ipdstmpl(22)=jdat(6)
1781 ipdstmpl(23)=jdat(7)
1784 if (kpds(16).eq.2)
then
1786 if (kpds(5).eq.15) ipdstmpl(26)=2
1787 if (kpds(5).eq.16) ipdstmpl(26)=3
1788 elseif (kpds(16).eq.3)
then
1790 elseif (kpds(16).eq.4)
then
1792 elseif (kpds(16).eq.5)
then
1796 ipdstmpl(28)=kpds(13)
1797 if (kpds(13).eq.254) ipdstmpl(28)=13
1798 ipdstmpl(29)=kpds(15)-kpds(14)
1801 elseif (kpds(16).eq.51)
then
1813 ipdstmpl(8)=kpds(13)
1814 if (kpds(13).eq.254) ipdstmpl(8)=13
1815 ipdstmpl(9)=kpds(14)
1816 call cnvlevel(kpds(6),kpds(7),ipdstmpl)
1818 if (kens(4).eq.1)
then
1820 elseif (kens(4).eq.2)
then
1822 elseif (kens(4).eq.11)
then
1824 elseif (kens(4).eq.12)
then
1827 ipdstmpl(17)=kclust(1)
1831 idat(1)=((kpds(21)-1)*100)+kpds(8)
1838 if ( ipdstmpl(8).eq.0 )
then
1840 elseif ( ipdstmpl(8).eq.1 )
then
1842 elseif ( ipdstmpl(8).eq.2 )
then
1844 elseif ( ipdstmpl(8).eq.10 )
then
1845 rinc(2)=kpds(15) * 3
1846 elseif ( ipdstmpl(8).eq.11 )
then
1847 rinc(2)=kpds(15) * 6
1848 elseif ( ipdstmpl(8).eq.12 )
then
1849 rinc(2)=kpds(15) * 12
1850 elseif ( ipdstmpl(8).eq.13 )
then
1853 call w3movdat(rinc,idat,jdat)
1854 ipdstmpl(18)=jdat(1)
1855 ipdstmpl(19)=jdat(2)
1856 ipdstmpl(20)=jdat(3)
1857 ipdstmpl(21)=jdat(5)
1858 ipdstmpl(22)=jdat(6)
1859 ipdstmpl(23)=jdat(7)
1864 ipdstmpl(28)=kpds(13)
1865 if (kpds(13).eq.254) ipdstmpl(28)=13
1866 ipdstmpl(29)=kpds(15)-kpds(14)
1872 print *,
' Unrecognized Ensemble type = ',kens(2)
1873 print *,
'pds2pdtens: Couldn:t construct PDS Template '