NCEPLIBS-g2 4.0.0
Loading...
Searching...
No Matches
cnv21.F90
Go to the documentation of this file.
1
4
19subroutine cnv21(ifl1,ifl2)
20
21 use grib_mod
22 use params
23 integer,intent(in) :: ifl1,ifl2
24
25 CHARACTER(len=1),allocatable,dimension(:) :: cgrib
26 type(gribfield) :: gfld
27 integer,dimension(200) :: jids,jpdt,jgdt
28 integer :: kpds(200),kgds(200),kens(200),kprob(2)
29 integer :: kclust(16),kmembr(80)
30 integer :: currlen=0
31 integer :: igds(5)=(/0,0,0,0,0/)
32 real :: xprob(2)
33 logical :: unpack=.true.
34 !
35 !
36 ifli1=0
37 jdisc=-1
38 jids=-9999
39 jpdt=-9999
40 jgdt=-9999
41 jpdtn=-1
42 jgdtn=-1
43 !
44 icount=0
45 jskp=0
46 do
47 call getgb2(ifl1,ifli1,jskp,jdisc,jids,jpdtn,jpdt,jgdtn,jgdt, &
48 unpack,jskp,gfld,iret)
49 if (iret.ne.0) then
50 if (iret.eq.99) exit
51 print *,' getgb2 error = ',iret
52 cycle
53 !call errexit(17)
54 endif
55 icount=icount+1
56 !
57 ! Ensure that cgrib array is large enough
58 !
59 newlen=4*gfld%ngrdpts
60 if (newlen.gt.currlen) then
61 if (allocated(cgrib)) deallocate(cgrib)
62 allocate(cgrib(newlen),stat=is)
63 currlen=newlen
64 endif
65 !
66 ! Construct GDS
67 !
68 igds(1)=gfld%griddef
69 igds(2)=gfld%ngrdpts
70 igds(3)=gfld%numoct_opt
71 igds(4)=gfld%interp_opt
72 igds(5)=gfld%igdtnum
73 if (.NOT. associated(gfld%list_opt)) &
74 allocate(gfld%list_opt(1))
75 call gdt2gds(igds,gfld%igdtmpl,gfld%num_opt,gfld%list_opt, &
76 kgds,igrid,iret)
77 if (iret.ne.0) then
78 print *,'cnv21: could not create gds'
79 cycle
80 endif
81 !print *,' SAGT: NCEP GRID: ',igrid
82 !
83 ! Construct PDS
84 !
85 call makepds(gfld%discipline,gfld%idsect,gfld%ipdtnum, &
86 gfld%ipdtmpl,gfld%ibmap,gfld%idrtnum, &
87 gfld%idrtmpl,kpds,iret)
88 if (iret.ne.0) then
89 print *,'cnv21: could not create pds in GRIB1'
90 cycle
91 endif
92 kpds(3)=igrid
93 !
94 ! Check for Coastal Ocean circulation and UKMET grib grid id.
95 ! ON 388 defined grid id 238 same as grid 244
96 ! If the process model is 45, and UK Met(74), the grid id is 2 or 45
97 ! If the process model is 121, the grid id is 238
98 ! If the process model is 123, the grid id is 244
99 !
100 if (kpds(1).eq.7.AND.kpds(2).eq.121) kpds(3)=238
101 if (kpds(1).eq.7.AND.kpds(2).eq.123) kpds(3)=244
102 if (kpds(1).eq.74) then
103 if (kpds(2).eq.45.AND.kpds(3).eq.2) kpds(3)=2
104 if (kpds(2).eq.15.AND.kpds(3).eq.45) kpds(3)=45
105 if (kpds(2).eq.45.AND.kpds(3).eq.45) kpds(3)=45
106 end if
107 !
108 ! Construct Ensemble info, if necessary
109 !
110 if ((gfld%ipdtnum.ge.1.AND.gfld%ipdtnum.le.6).OR. &
111 (gfld%ipdtnum.ge.9.AND.gfld%ipdtnum.le.14)) then
112 call makepdsens(gfld%ipdtnum,gfld%ipdtmpl,kpds,kens,kprob, &
113 xprob,kclust,kmembr,iret)
114 endif
115 !
116 ! If not using bit-map, must assign dummy bit-map
117 !
118 if (gfld%ibmap.ne.0 .AND. gfld%ibmap.ne.254) then
119 !gfld%bmap => dummy
120 if ((gfld%idrtnum.eq.2 .OR. gfld%idrtnum.eq.3) .AND. &
121 gfld%idrtmpl(7).ne.0) then ! convert missings to bitmap
122 allocate(gfld%bmap(gfld%ngrdpts))
123 kpds(4)=ior(kpds(4),64)
124 if (gfld%idrtmpl(7).eq.1) then
125 call rdieee(gfld%idrtmpl(8),rmiss1,1)
126 do i=1,gfld%ngrdpts
127 if (gfld%fld(i) .eq. rmiss1) then
128 gfld%bmap(i)=.false.
129 else
130 gfld%bmap(i)=.true.
131 endif
132 enddo
133 endif
134 if (gfld%idrtmpl(7).eq.2) then
135 call rdieee(gfld%idrtmpl(8),rmiss1,1)
136 call rdieee(gfld%idrtmpl(9),rmiss2,1)
137 do i=1,gfld%ngrdpts
138 if (gfld%fld(i).eq.rmiss1 .OR. &
139 gfld%fld(i).eq.rmiss2) then
140 gfld%bmap(i)=.false.
141 else
142 gfld%bmap(i)=.true.
143 endif
144 enddo
145 endif
146 endif
147 if ((gfld%idrtnum.eq.2 .OR. gfld%idrtnum.eq.3) .AND. &
148 gfld%idrtmpl(7).eq.0) then ! convert missings to bitmap
149 allocate(gfld%bmap(gfld%ngrdpts))
150 kpds(4)=ior(kpds(4),64)
151 call rdieee(gfld%idrtmpl(8),rmiss1,1)
152 if (rmiss1 .lt. -9999.0) then
153 rmiss1=rmiss1*10.0
154 else
155 rmiss1=-9999.0
156 endif
157 do i=1,gfld%ngrdpts
158 if (gfld%fld(i) .eq. rmiss1) then
159 gfld%bmap(i)=.false.
160 else
161 gfld%bmap(i)=.true.
162 endif
163 enddo
164 endif
165 endif
166 !
167 ! Pack and write GRIB 1 field
168 !
169 ibs=gfld%idrtmpl(2)
170 !print *,'SAGT:before putgbexn'
171 if (.NOT. associated(gfld%bmap)) allocate(gfld%bmap(1))
172 imug=0
173 call putgbexn(ifl2,gfld%ngrdpts,kpds,kgds,kens,kprob, &
174 xprob,kclust,kmembr,ibs,imug,gfld%bmap, &
175 gfld%fld,iret)
176 !print *,'SAGT:after putgbexn'
177 if (iret.ne.0) then
178 print *,' putgbexn error = ',iret
179 cycle
180 !call errexit(17)
181 endif
182
183 call gf_free(gfld)
184
185 enddo
186
187 if (allocated(cgrib)) deallocate(cgrib)
188
189 return
190end subroutine cnv21
191
264subroutine makepds(idisc,idsect,ipdsnum,ipdstmpl,ibmap, &
265 idrsnum,idrstmpl,kpds,iret)
266
267 use params
268
269 integer,intent(in) :: idsect(*),ipdstmpl(*),idrstmpl(*)
270 integer,intent(in) :: ipdsnum,idisc,idrsnum,ibmap
271 integer,intent(out) :: kpds(*)
272 integer,intent(out) :: iret
273
274 iret=0
275 ipos=0
276 kpds(1:24)=0
277 if ( (ipdsnum.lt.0).OR.(ipdsnum.gt.15) ) then
278 print *,'makepds: Don:t know GRIB2 PDT 4.',ipdsnum
279 iret=2
280 return
281 endif
282
283 kpds(1)=idsect(1)
284 kpds(2)=ipdstmpl(5)
285 kpds(3)=255
286 kpds(4)=128
287 if ( ibmap.ne.255 ) kpds(4)=kpds(4)+64
288 if ( ibmap.ge.1.AND.ibmap.le.253 ) then
289 print *,'makepds: Don:t know about predefined bit-map ',ibmap
290 iret=1
291 return
292 endif
293 call param_g2_to_g1(idisc,ipdstmpl(1),ipdstmpl(2),kpds(5), &
294 kpds(19))
295 !
296 ! Special parameters for ICAO WAFS (Max Icing, TP and CAT)
297 !
298 If (ipdstmpl(16).eq.2.and.ipdstmpl(1).eq.19.and. &
299 ipdstmpl(2).eq.20) kpds(5) = 169
300 If (ipdstmpl(16).eq.2.and.ipdstmpl(1).eq.19.and. &
301 ipdstmpl(2).eq.21) kpds(5) = 171
302 If (ipdstmpl(16).eq.2.and.ipdstmpl(1).eq.19.and. &
303 ipdstmpl(2).eq.22) kpds(5) = 173
304 !
305 ! Special parameters for NAM (NMMB)
306 !
307 If (idisc.eq.0.and.ipdstmpl(1).eq.2) then
308 if (ipdstmpl(2).eq.220) then
309 kpds(5) = 237
310 kpds(19) = 129
311 end if
312 if (ipdstmpl(2).eq.221) then
313 kpds(5) = 238
314 kpds(19) = 129
315 end if
316 if (ipdstmpl(2).eq.222) then
317 kpds(5) = 253
318 kpds(19) = 129
319 end if
320 if (ipdstmpl(2).eq.223) then
321 kpds(5) = 254
322 kpds(19) = 129
323 end if
324 endif
325 !
326 If (idisc.eq.0.and.ipdstmpl(2).eq.16 &
327 .and.ipdstmpl(3).eq.198) then
328 kpds(5) = 235
329 kpds(19) = 129
330 endif
331 !
332 If (idisc.eq.0.and.ipdstmpl(2).eq.7 &
333 .and.ipdstmpl(3).eq.199) then
334 kpds(5) = 236
335 kpds(19) = 129
336 endif
337 !
338 ! Special parameters for ICAO Height at CB Base and Top
339 ! in GRIB1 Table 140
340 !
341 If (ipdstmpl(1).eq.3.and.ipdstmpl(2).eq.3) then
342 If (ipdstmpl(10).eq.11) then
343 kpds(19) = 140
344 kpds(5) = 179
345 end if
346 If (ipdstmpl(10).eq.12) then
347 kpds(19) = 140
348 kpds(5) = 180
349 end if
350 end if
351 !
352 call levelcnv(ipdstmpl,kpds(6),kpds(7)) ! level
353 kpds(8)=mod(idsect(6),100)
354 if ( kpds(8).eq.0 ) kpds(8)=100
355 kpds(9)=idsect(7) ! Year
356 kpds(10)=idsect(8) ! Month
357 kpds(11)=idsect(9) ! Day
358 kpds(12)=idsect(10) ! Hour
359 if ( ipdstmpl(8).ne.13 ) then
360 kpds(13)=ipdstmpl(8) ! Time Unit
361 else
362 kpds(13)=254
363 endif
364 kpds(14)=ipdstmpl(9) ! P1
365 if ( ipdsnum.le.7 ) then ! P2
366 kpds(15)=0
367 kpds(16)=0
368 kpds(20)=0
369 if ( kpds(14).eq.0 ) kpds(16)=1
370 if ( kpds(14).gt.255 ) kpds(16)=10
371 if ( ipdstmpl(5).eq.77.OR.ipdstmpl(5).eq.81.OR. &
372 ipdstmpl(5).eq.96.OR.ipdstmpl(5).eq.80.OR. &
373 ipdstmpl(5).eq.82.OR.ipdstmpl(5).eq.120.OR. &
374 ipdstmpl(5).eq.47.OR.ipdstmpl(5).eq.11 ) then
375 kpds(16)=10
376 end if
377 if (ipdstmpl(5).eq.84.AND.kpds(5).eq.154)kpds(16) = 10
378 !
379 ! NOAA Wave Watch III and Coastal Ocean Circulation
380 ! and Alaska Waters Regional Wave Model
381 !
382 if ( ipdstmpl(5).eq.88.OR.ipdstmpl(5).eq.121 &
383 .OR.ipdstmpl(5).eq.122.OR.ipdstmpl(5).eq.123 &
384 .OR.ipdstmpl(5).eq.124.OR.ipdstmpl(5).eq.125 &
385 .OR.ipdstmpl(5).eq.131.OR.ipdstmpl(5).eq.45 &
386 .OR.ipdstmpl(5).eq.11 ) then
387 kpds(16) = 0
388 !
389 ! Level Surface set to 1
390 !
391 if (kpds(5).eq.80.OR.kpds(5).eq.82.OR. &
392 kpds(5).eq.88.OR.kpds(5).eq.49.OR. &
393 kpds(5).eq.50) kpds(7)=1 ! Level Surface
394 if (ipdstmpl(5).eq.122.OR.ipdstmpl(5).eq.124.OR. &
395 ipdstmpl(5).eq.131.OR.ipdstmpl(5).eq.123.OR. &
396 ipdstmpl(5).eq.125.OR.ipdstmpl(5).eq.88.OR. &
397 ipdstmpl(5).eq.121) kpds(7)=1
398 if (idsect(1).eq.54.AND.ipdstmpl(5).eq.45) kpds(16) = 10
399 endif
400 else
401 selectcase (ipdsnum)
402 case(8)
403 ipos=24
404 case(9)
405 ipos=31
406 case(10)
407 ipos=25
408 case(11)
409 ipos=27
410 case(12)
411 ipos=26
412 case(13)
413 ipos=40
414 case(14)
415 ipos=39
416 end select
417 kpds(15)=ipdstmpl(ipos+3)+kpds(14) ! P2
418 selectcase (ipdstmpl(ipos))
419 case (255)
420 kpds(16)=2
421 case (0)
422 kpds(16)=3
423 case (1)
424 kpds(16)=4
425 case (2)
426 kpds(16)=2
427 case (3)
428 kpds(16)=2
429 case (4)
430 kpds(16)=5
431 case (51)
432 kpds(16)=51
433 end select
434 kpds(20)=ipdstmpl(ipos-1)
435 endif
436 if (ipdstmpl(9) .ge. 252) then
437 if (ipdstmpl(ipos+3).eq.3) then
438 kpds(13)= 10 ! Forecast time unit is 3-hour
439 kpds(14)=ipdstmpl(9)/3 ! Time range P1
440 kpds(15)=ipdstmpl(ipos+3)/3+kpds(14) ! Time range P2
441 else if (ipdstmpl(ipos+3).eq.6) then
442 kpds(13)= 11 ! Forecast time unit is 6-hour
443 kpds(14)=ipdstmpl(9)/6 ! Time range P1
444 kpds(15)=ipdstmpl(ipos+3)/6+kpds(14) ! Time range P2
445 else if (ipdstmpl(ipos+3).eq.12) then
446 kpds(13)= 12 ! Forecast time unit is 12-hour
447 kpds(14)=ipdstmpl(9)/12 ! Time range P1
448 kpds(15)=ipdstmpl(ipos+3)/12+kpds(14) ! Time range P2
449 end if
450 end if
451 if (ipdsnum .eq. 8 .AND. ipdstmpl(9) .eq. 0) then
452 if (ipdstmpl(ipos+3).ge.252) then
453 kpds(13)= 10 ! Forecast time unit is hour
454 kpds(14)=ipdstmpl(9)/3 ! Time range P1
455 kpds(15)=ipdstmpl(ipos+3)/3+kpds(14) ! Time range P2
456 end if
457 end if
458 !
459 ! Checking total preciptation for 15-hr or 18-hr or 21-hr or 24-hr accumulation
460 ! after forecast hour F240
461 !
462 if (ipdstmpl(9) .ge. 240 )then
463 if ( ipdstmpl(ipos+3).eq.15 .OR. ipdstmpl(ipos+3).eq.18 &
464 .OR. ipdstmpl(ipos+3).eq.21 .OR. &
465 ipdstmpl(ipos+3).eq.24 ) then
466 kpds(13)= 10 ! Forecast time unit is 3-hour
467 kpds(14)=ipdstmpl(9)/3 ! Time range P1
468 kpds(15)=ipdstmpl(ipos+3)/3+kpds(14) ! Time range P2
469 end if
470 end if
471 !
472 ! Checking Unit of Time Range for FNMOC (APCP)
473 !
474 if (ipdstmpl(4).eq.58 .AND. ipdsnum.eq.11 .AND. &
475 (ipdstmpl(1).eq.1 .AND.ipdstmpl(2).eq.8) &
476 .AND. (ipdstmpl(10).eq.1)) then
477 if (ipdstmpl(9) .ge. 252) then
478 kpds(13)= 11 ! Forecast time unit is 6-hour
479 kpds(14)=ipdstmpl(9)/6 ! Time range P1
480 kpds(15)=ipdstmpl(ipos+3)/6+kpds(14) ! Time range P2
481 else
482 kpds(13)= 1 ! Forecast time unit is 1-hour
483 kpds(14)=ipdstmpl(9) ! Time range P1
484 end if
485 end if
486 !
487 ! Special case for FNMOC (TMAX and TMIN)
488 !
489 if (ipdstmpl(4).eq.58 .AND. ipdsnum.eq.11 .AND. &
490 (ipdstmpl(1).eq.0 &
491 .AND.ipdstmpl(2).eq.0).AND.(ipdstmpl(10).eq.103)) then
492 kpds(16) = 2
493 ! For Maximum Temperature
494 If (ipdstmpl(27).eq.2 .AND. ipdstmpl(1).eq.0 .AND. &
495 ipdstmpl(2).eq.0) kpds(5) = 15
496 ! For Minimum Temperature
497 If (ipdstmpl(27).eq.3 .AND. ipdstmpl(1).eq.0 .AND. &
498 ipdstmpl(2).eq.0) kpds(5) = 16
499 end if
500 !
501 ! Special case for WAFS (Mean/MAx IP,CTP and CAT)
502 !
503 if (ipdstmpl(5).eq.96.AND.((ipdstmpl(1).eq.19) &
504 .AND.(ipdstmpl(2).eq.20.or.ipdstmpl(2).eq.21.or. &
505 ipdstmpl(2).eq.22)).AND.(ipdstmpl(10).eq.100)) then
506 kpds(16) = 10
507 end if
508 !
509 kpds(17)=0
510 kpds(18)=1 ! GRIB edition
511 kpds(21)=(idsect(6)/100)+1 ! Century
512 if ( kpds(8).eq.100 ) kpds(21)=idsect(6)/100
513 kpds(22)=idrstmpl(3) ! Decimal scale factor
514 kpds(23)=idsect(2) ! Sub-center
515 return
516end subroutine makepds
517
533subroutine levelcnv(ipdstmpl,ltype,lval)
534 integer,intent(in) :: ipdstmpl(*)
535 integer,intent(out) :: ltype,lval
536
537 ltype=255
538 lval=0
539 ltype1=ipdstmpl(10)
540 ltype2=ipdstmpl(13)
541
542 if ( ltype1.eq.10.AND.ltype2.eq.255 ) then
543 ltype=200
544 lval=0
545 elseif ( ltype1.eq.11.AND.ltype2.eq.255 ) then
546 ltype=216
547 lval=0
548 elseif ( ltype1.eq.12.AND.ltype2.eq.255 ) then
549 ltype=217
550 lval=0
551 elseif ( ltype1.lt.100.AND.ltype2.eq.255 ) then
552 ltype=ltype1
553 lval=0
554 elseif ( ltype1.eq.1.AND.ltype2.eq.8 ) then
555 ltype=ltype1
556 lval=0
557 elseif ( ltype1.eq.10.AND.ltype2.eq.255 ) then
558 ltype=200
559 lval=0
560 elseif ( ltype1.eq.235.AND.ltype2.eq.255 ) then
561 ltype=235
562 rscal1=10.**(-ipdstmpl(11))
563 lval=nint(real(ipdstmpl(12))*rscal1)
564 elseif ( ltype1.ge.200.AND.ltype2.eq.255 ) then
565 ltype=ltype1
566 lval=0
567 elseif (ltype1.eq.100.AND.ltype2.eq.255 ) then
568 ltype=100
569 rscal1=10.**(-ipdstmpl(11))
570 lval=nint(real(ipdstmpl(12))*rscal1/100.)
571 elseif (ltype1.eq.100.AND.ltype2.eq.100 ) then
572 ltype=101
573 rscal1=10.**(-ipdstmpl(11))
574 lval1=nint(real(ipdstmpl(12))*rscal1/1000.)
575 rscal2=10.**(-ipdstmpl(14))
576 lval2=nint(real(ipdstmpl(15))*rscal2/1000.)
577 lval=(lval1*256)+lval2
578 elseif (ltype1.eq.101.AND.ltype2.eq.255 ) then
579 ltype=102
580 lval=0
581 elseif (ltype1.eq.102.AND.ltype2.eq.255 ) then
582 ltype=103
583 rscal1=10.**(-ipdstmpl(11))
584 lval=nint(real(ipdstmpl(12))*rscal1)
585 elseif (ltype1.eq.102.AND.ltype2.eq.102 ) then
586 ltype=104
587 rscal1=10.**(-ipdstmpl(11))
588 lval1=nint(real(ipdstmpl(12))*rscal1)
589 rscal2=10.**(-ipdstmpl(14))
590 lval2=nint(real(ipdstmpl(15))*rscal2)
591 lval=(lval1*256)+lval2
592 elseif (ltype1.eq.103.AND.ltype2.eq.255 ) then
593 ltype=105
594 rscal1=10.**(-ipdstmpl(11))
595 lval=nint(real(ipdstmpl(12))*rscal1)
596 elseif (ltype1.eq.103.AND.ltype2.eq.103 ) then
597 ltype=106
598 rscal1=10.**(-ipdstmpl(11))
599 lval1=nint(real(ipdstmpl(12))*rscal1/100.)
600 rscal2=10.**(-ipdstmpl(14))
601 lval2=nint(real(ipdstmpl(15))*rscal2/100.)
602 lval=(lval1*256)+lval2
603 elseif (ltype1.eq.104.AND.ltype2.eq.255 ) then
604 ltype=107
605 rscal1=10.**(-ipdstmpl(11))
606 lval=nint(real(ipdstmpl(12))*rscal1*10000.)
607 elseif (ltype1.eq.104.AND.ltype2.eq.104 ) then
608 ltype=108
609 rscal1=10.**(-ipdstmpl(11))
610 lval1=nint(real(ipdstmpl(12))*rscal1*100.)
611 rscal2=10.**(-ipdstmpl(14))
612 lval2=nint(real(ipdstmpl(15))*rscal2*100.)
613 lval=(lval1*256)+lval2
614 elseif (ltype1.eq.105.AND.ltype2.eq.255 ) then
615 ltype=109
616 lval=ipdstmpl(12)
617 elseif (ltype1.eq.105.AND.ltype2.eq.105 ) then
618 ltype=110
619 rscal1=10.**(-ipdstmpl(11))
620 lval1=nint(real(ipdstmpl(12))*rscal1)
621 rscal2=10.**(-ipdstmpl(14))
622 lval2=nint(real(ipdstmpl(15))*rscal2)
623 lval=(lval1*256)+lval2
624 elseif (ltype1.eq.106.AND.ltype2.eq.255 ) then
625 ltype=111
626 rscal1=10.**(-ipdstmpl(11))
627 lval=nint(real(ipdstmpl(12))*rscal1*100.)
628 elseif (ltype1.eq.106.AND.ltype2.eq.106 ) then
629 ltype=112
630 rscal1=10.**(-ipdstmpl(11))
631 lval1=nint(real(ipdstmpl(12))*rscal1*100.)
632 rscal2=10.**(-ipdstmpl(14))
633 lval2=nint(real(ipdstmpl(15))*rscal2*100.)
634 lval=(lval1*256)+lval2
635 elseif (ltype1.eq.107.AND.ltype2.eq.255 ) then
636 ltype=113
637 rscal1=10.**(-ipdstmpl(11))
638 lval=nint(real(ipdstmpl(12))*rscal1)
639 elseif (ltype1.eq.107.AND.ltype2.eq.107 ) then
640 ltype=114
641 rscal1=10.**(-ipdstmpl(11))
642 lval1=475-nint(real(ipdstmpl(12))*rscal1)
643 rscal2=10.**(-ipdstmpl(14))
644 lval2=475-nint(real(ipdstmpl(15))*rscal2)
645 lval=(lval1*256)+lval2
646 elseif (ltype1.eq.108.AND.ltype2.eq.255 ) then
647 ltype=115
648 rscal1=10.**(-ipdstmpl(11))
649 lval=nint(real(ipdstmpl(12))*rscal1/100.)
650 elseif (ltype1.eq.108.AND.ltype2.eq.108 ) then
651 ltype=116
652 rscal1=10.**(-ipdstmpl(11))
653 lval1=nint(real(ipdstmpl(12))*rscal1/100.)
654 rscal2=10.**(-ipdstmpl(14))
655 lval2=nint(real(ipdstmpl(15))*rscal2/100.)
656 lval=(lval1*256)+lval2
657 elseif (ltype1.eq.109.AND.ltype2.eq.255 ) then
658 ltype=117
659 rscal1=10.**(-ipdstmpl(11))
660 lval=nint(real(ipdstmpl(12))*rscal1*1000000000.)
661 elseif (ltype1.eq.111.AND.ltype2.eq.255 ) then
662 ltype=119
663 rscal1=10.**(-ipdstmpl(11))
664 lval=nint(real(ipdstmpl(12))*rscal1*10000.)
665 elseif (ltype1.eq.111.AND.ltype2.eq.111 ) then
666 ltype=120
667 rscal1=10.**(-ipdstmpl(11))
668 lval1=nint(real(ipdstmpl(12))*rscal1*100.)
669 rscal2=10.**(-ipdstmpl(14))
670 lval2=nint(real(ipdstmpl(15))*rscal2*100.)
671 lval=(lval1*256)+lval2
672 elseif (ltype1.eq.160.AND.ltype2.eq.255 ) then
673 ltype=160
674 rscal1=10.**(-ipdstmpl(11))
675 lval=nint(real(ipdstmpl(12))*rscal1)
676 elseif ((ltype1.ge.236.AND.ltype1.le.239).AND. &
677 (ltype2.ge.236.AND.ltype2.le.239)) then
678 ltype=ltype1
679 rscal1=10.**(-ipdstmpl(11))
680 lval1=nint(real(ipdstmpl(12))*rscal1)
681 rscal2=10.**(-ipdstmpl(14))
682 lval2=nint(real(ipdstmpl(15))*rscal2)
683 lval=(lval1*256)+lval2
684 else
685 print *,'levelcnv: GRIB2 Levels ',ltype1,ltype2, &
686 ' not recognized.'
687 ltype=255
688 endif
689
690 ! High resolution stuff
691 ! elseif (ltype.eq.121) then
692 ! ipdstmpl(10)=100
693 ! ipdstmpl(12)=(1100+(lval/256))*100
694 ! ipdstmpl(13)=100
695 ! ipdstmpl(15)=(1100+mod(lval,256))*100
696 ! elseif (ltype.eq.125) then
697 ! ipdstmpl(10)=103
698 ! ipdstmpl(11)=-2
699 ! ipdstmpl(12)=lval
700 ! elseif (ltype.eq.128) then
701 ! ipdstmpl(10)=104
702 ! ipdstmpl(11)=-3
703 ! ipdstmpl(12)=1100+(lval/256)
704 ! ipdstmpl(13)=104
705 ! ipdstmpl(14)=-3
706 ! ipdstmpl(15)=1100+mod(lval,256)
707 ! elseif (ltype.eq.141) then
708 ! ipdstmpl(10)=100
709 ! ipdstmpl(12)=(lval/256)*100
710 ! ipdstmpl(13)=100
711 ! ipdstmpl(15)=(1100+mod(lval,256))*100
712
713 return
714end subroutine levelcnv
715
766subroutine makepdsens(ipdsnum,ipdstmpl,kpds,kens,kprob, &
767 xprob,kclust,kmembr,iret)
768 use params
769
770 integer,intent(in) :: ipdstmpl(*)
771 integer,intent(in) :: ipdsnum
772 integer,intent(inout) :: kpds(*)
773 integer,intent(out) :: kens(5),kprob(2)
774 integer,intent(out) :: kclust(16),kmembr(80)
775 real,intent(out) :: xprob(2)
776 integer,intent(out) :: iret
777
778 iret=0
779 kpds(23)=2 ! subcenter = ensemble
780
781 kens(1:5)=0
782 kprob(1:2)=0
783 xprob(1:2)=0.
784 kclust(1:16)=0
785 kmembr(1:80)=0
786 !
787 ! Individual Ensemble Fcst
788 !
789 if (ipdsnum.eq.1.OR.ipdsnum.eq.11) then
790 kens(1)=1
791 selectcase (ipdstmpl(16))
792 case(0)
793 kens(2)=1
794 kens(3)=1
795 case(1)
796 kens(2)=1
797 kens(3)=2
798 case(2)
799 kens(2)=2
800 kens(3)=ipdstmpl(17)
801 case(3)
802 kens(2)=3
803 kens(3)=ipdstmpl(17)
804 case(4)
805 kens(2)=3
806 kens(3)=ipdstmpl(17)
807 case(192)
808 kens(2)=3
809 kens(3)=ipdstmpl(17)
810 end select
811 kens(4)=1
812 kens(5)=255
813 !
814 ! Probability Fcst
815 !
816 elseif (ipdsnum.eq.5.OR.ipdsnum.eq.9) then
817 kens(1)=1
818 kens(2)=5
819 kens(3)=0
820 kens(4)=0
821 kens(5)=255
822 kprob(1)=kpds(5)
823 kpds(5)=191
824 kprob(2)=ipdstmpl(18)+1
825 if (kprob(2).eq.1) then
826 rscale=10.**ipdstmpl(19)
827 xprob(1)=real(ipdstmpl(20))/rscale
828 xprob(2)=0.0
829 elseif (kprob(2).eq.2) then
830 xprob(1)=0.0
831 rscale=10.**ipdstmpl(21)
832 xprob(2)=real(ipdstmpl(22))/rscale
833 elseif (kprob(2).eq.3) then
834 rscale=10.**ipdstmpl(19)
835 xprob(1)=real(ipdstmpl(20))/rscale
836 rscale=10.**ipdstmpl(21)
837 xprob(2)=real(ipdstmpl(22))/rscale
838 endif
839 kclust(1)=ipdstmpl(17)
840 !
841 ! Derived Ensemble Fcst
842 !
843 elseif (ipdsnum.eq.2.OR.ipdsnum.eq.12) then
844 kens(1)=1
845 kens(2)=5
846 kens(3)=0
847 selectcase (ipdstmpl(16))
848 case(0)
849 kens(4)=1
850 case(1)
851 kens(4)=2
852 case(2)
853 kens(4)=11
854 case(3)
855 kens(4)=12
856 end select
857 !kens(5)=89
858 kens(5)=0
859 kclust(1)=ipdstmpl(17)
860 else
861 print *,'makepdsens: Don:t know GRIB2 PDT 4.',ipdsnum
862 iret=2
863 endif
864
865 return
866end subroutine makepdsens
867
906subroutine gdt2gds(igds,igdstmpl,idefnum,ideflist,kgds, &
907 igrid,iret)
908
909 !
910 integer,intent(in) :: idefnum
911 integer,intent(in) :: igds(*),igdstmpl(*),ideflist(*)
912 integer,intent(out) :: kgds(*),igrid,iret
913
914 integer :: kgds72(200),kgds71(200),idum(200),jdum(200)
915
916 iret=0
917 if (igds(5).eq.0) then ! Lat/Lon grid
918 kgds(1)=0
919 kgds(2)=igdstmpl(8) ! Ni
920 kgds(3)=igdstmpl(9) ! Nj
921 kgds(4)=igdstmpl(12)/1000 ! Lat of 1st grid point
922 kgds(5)=igdstmpl(13)/1000 ! Long of 1st grid point
923 kgds(6)=0 ! resolution and component flags
924 if (igdstmpl(1)==2) kgds(6)=64
925 if (btest(igdstmpl(14),4).OR.btest(igdstmpl(14),5)) &
926 kgds(6)=kgds(6)+128
927 if (btest(igdstmpl(14),3)) kgds(6)=kgds(6)+8
928 kgds(7)=igdstmpl(15)/1000 ! Lat of last grid point
929 kgds(8)=igdstmpl(16)/1000 ! Long of last grid point
930 kgds(9)=igdstmpl(17)/1000 ! Di
931 kgds(10)=igdstmpl(18)/1000 ! Dj
932 kgds(11)=igdstmpl(19) ! Scanning mode
933 kgds(12)=0
934 kgds(13)=0
935 kgds(14)=0
936 kgds(15)=0
937 kgds(16)=0
938 kgds(17)=0
939 kgds(18)=0
940 kgds(19)=0
941 kgds(20)=255
942 kgds(21)=0
943 kgds(22)=0
944 !
945 ! Process irreg grid stuff, if necessary
946 !
947 if (idefnum.ne.0) then
948 if (igdstmpl(8).eq.-1) then
949 kgds(2)=65535
950 kgds(9)=65535
951 endif
952 if (igdstmpl(9).eq.-1) then
953 kgds(3)=65535
954 kgds(10)=65535
955 endif
956 kgds(19)=0
957 kgds(20)=33
958 if (kgds(1).eq.1.OR.kgds(1).eq.3) kgds(20)=43
959 kgds(21)=igds(2) ! num of grid points
960 do j=1,idefnum
961 kgds(21+j)=ideflist(j)
962 enddo
963 endif
964 elseif (igds(5).eq.10) then ! Mercator grid
965 kgds(1)=1 ! Grid Definition Template number
966 kgds(2)=igdstmpl(8) ! Ni
967 kgds(3)=igdstmpl(9) ! Nj
968 kgds(4)=igdstmpl(10)/1000 ! Lat of 1st grid point
969 kgds(5)=igdstmpl(11)/1000 ! Long of 1st grid point
970 kgds(6)=0 ! resolution and component flags
971 if (igdstmpl(1)==2) kgds(6)=64
972 if (btest(igdstmpl(12),4).OR.btest(igdstmpl(12),5)) &
973 kgds(6)=kgds(6)+128
974 if (btest(igdstmpl(12),3)) kgds(6)=kgds(6)+8
975 kgds(7)=igdstmpl(14)/1000 ! Lat of last grid point
976 kgds(8)=igdstmpl(15)/1000 ! Long of last grid point
977 kgds(9)=igdstmpl(13)/1000 ! Lat intersects earth
978 kgds(10)=0
979 kgds(11)=igdstmpl(16) ! Scanning mode
980 kgds(12)=igdstmpl(18)/1000 ! Di
981 kgds(13)=igdstmpl(19)/1000 ! Dj
982 kgds(14)=0
983 kgds(15)=0
984 kgds(16)=0
985 kgds(17)=0
986 kgds(18)=0
987 kgds(19)=0
988 kgds(20)=255
989 kgds(21)=0
990 kgds(22)=0
991 elseif (igds(5).eq.30) then ! Lambert Conformal Grid
992 kgds(1)=3
993 kgds(2)=igdstmpl(8) ! Nx
994 kgds(3)=igdstmpl(9) ! Ny
995 kgds(4)=igdstmpl(10)/1000 ! Lat of 1st grid point
996 kgds(5)=igdstmpl(11)/1000 ! Long of 1st grid point
997 kgds(6)=0 ! resolution and component flags
998 if (igdstmpl(1)==2) kgds(6)=64
999 if (btest(igdstmpl(12),4).OR.btest(igdstmpl(12),5)) &
1000 kgds(6)=kgds(6)+128
1001 if (btest(igdstmpl(12),3)) kgds(6)=kgds(6)+8
1002 kgds(7)=igdstmpl(14)/1000 ! Lon of orientation
1003 kgds(8)=igdstmpl(15)/1000 ! Dx
1004 kgds(9)=igdstmpl(16)/1000 ! Dy
1005 kgds(10)=igdstmpl(17) ! Projection Center Flag
1006 kgds(11)=igdstmpl(18) ! Scanning mode
1007 kgds(12)=igdstmpl(19)/1000 ! Lat in 1
1008 kgds(13)=igdstmpl(20)/1000 ! Lat in 2
1009 kgds(14)=igdstmpl(21)/1000 ! Lat of S. Pole of projection
1010 kgds(15)=igdstmpl(22)/1000 ! Lon of S. Pole of projection
1011 kgds(16)=0
1012 kgds(17)=0
1013 kgds(18)=0
1014 kgds(19)=0
1015 kgds(20)=255
1016 kgds(21)=0
1017 kgds(22)=0
1018 elseif (igds(5).eq.40) then ! Gaussian Lat/Lon grid
1019 kgds(1)=4
1020 kgds(2)=igdstmpl(8) ! Ni
1021 kgds(3)=igdstmpl(9) ! Nj
1022 kgds(4)=igdstmpl(12)/1000 ! Lat of 1st grid point
1023 kgds(5)=igdstmpl(13)/1000 ! Long of 1st grid point
1024 kgds(6)=0 ! resolution and component flags
1025 if (igdstmpl(1)==2) kgds(6)=64
1026 if (btest(igdstmpl(14),4).OR.btest(igdstmpl(14),5)) &
1027 kgds(6)=kgds(6)+128
1028 if (btest(igdstmpl(14),3)) kgds(6)=kgds(6)+8
1029 kgds(7)=igdstmpl(15)/1000 ! Lat of last grid point
1030 kgds(8)=igdstmpl(16)/1000 ! Long of last grid point
1031 kgds(9)=igdstmpl(17)/1000 ! Di
1032 kgds(10)=igdstmpl(18) ! N - Number of parallels
1033 kgds(11)=igdstmpl(19) ! Scanning mode
1034 kgds(12)=0
1035 kgds(13)=0
1036 kgds(14)=0
1037 kgds(15)=0
1038 kgds(16)=0
1039 kgds(17)=0
1040 kgds(18)=0
1041 kgds(19)=0
1042 kgds(20)=255
1043 kgds(21)=0
1044 kgds(22)=0
1045 elseif (igds(5).eq.20) then ! Polar Stereographic Grid
1046 kgds(1)=5
1047 kgds(2)=igdstmpl(8) ! Nx
1048 kgds(3)=igdstmpl(9) ! Ny
1049 kgds(4)=igdstmpl(10)/1000 ! Lat of 1st grid point
1050 kgds(5)=igdstmpl(11)/1000 ! Long of 1st grid point
1051 kgds(6)=0 ! resolution and component flags
1052 if (igdstmpl(1)==2) kgds(6)=64
1053 if (btest(igdstmpl(12),4).OR.btest(igdstmpl(12),5)) &
1054 kgds(6)=kgds(6)+128
1055 if (btest(igdstmpl(12),3)) kgds(6)=kgds(6)+8
1056 kgds(7)=igdstmpl(14)/1000 ! Lon of orientation
1057 kgds(8)=igdstmpl(15)/1000 ! Dx
1058 kgds(9)=igdstmpl(16)/1000 ! Dy
1059 kgds(10)=igdstmpl(17) ! Projection Center Flag
1060 kgds(11)=igdstmpl(18) ! Scanning mode
1061 kgds(12)=0
1062 kgds(13)=0
1063 kgds(14)=0
1064 kgds(15)=0
1065 kgds(16)=0
1066 kgds(17)=0
1067 kgds(18)=0
1068 kgds(19)=0
1069 kgds(20)=255
1070 kgds(21)=0
1071 kgds(22)=0
1072 elseif (igds(5).eq.204) then ! Curvilinear Orthogonal
1073 kgds(1)=204
1074 kgds(2)=igdstmpl(8) ! Ni
1075 kgds(3)=igdstmpl(9) ! Nj
1076 kgds(4)=0
1077 kgds(5)=0
1078 kgds(6)=0 ! resolution and component flags
1079 if (igdstmpl(1)==2) kgds(6)=64
1080 if (btest(igdstmpl(14),4).OR.btest(igdstmpl(14),5)) &
1081 kgds(6)=kgds(6)+128
1082 if (btest(igdstmpl(14),3)) kgds(6)=kgds(6)+8
1083 kgds(7)=0
1084 kgds(8)=0
1085 kgds(9)=0
1086 kgds(10)=0
1087 kgds(11)=igdstmpl(19) ! Scanning mode
1088 kgds(12)=0
1089 kgds(13)=0
1090 kgds(14)=0
1091 kgds(15)=0
1092 kgds(16)=0
1093 kgds(17)=0
1094 kgds(18)=0
1095 kgds(19)=0
1096 kgds(20)=255
1097 kgds(21)=0
1098 kgds(22)=0
1099 !
1100 ! Process irreg grid stuff, if necessary
1101 !
1102 if (idefnum.ne.0) then
1103 if (igdstmpl(8).eq.-1) then
1104 kgds(2)=65535
1105 kgds(9)=65535
1106 endif
1107 if (igdstmpl(9).eq.-1) then
1108 kgds(3)=65535
1109 kgds(10)=65535
1110 endif
1111 kgds(19)=0
1112 kgds(20)=33
1113 if (kgds(1).eq.1.OR.kgds(1).eq.3) kgds(20)=43
1114 kgds(21)=igds(2) ! num of grid points
1115 do j=1,idefnum
1116 kgds(21+j)=ideflist(j)
1117 enddo
1118 endif
1119 elseif (igds(5).eq.32768) then ! Rotate Lat/Lon grid
1120 kgds(1)=203 ! Arakawa Staggerred E/B grid
1121 kgds(2)=igdstmpl(8) ! Ni
1122 kgds(3)=igdstmpl(9) ! Nj
1123 kgds(4)=igdstmpl(12)/1000 ! Lat of 1st grid point
1124 kgds(5)=igdstmpl(13)/1000 ! Lon of 1st grid point
1125 kgds(6)=0 ! resolution and component flags
1126 if (igdstmpl(1)==2) kgds(6)=64
1127 if (btest(igdstmpl(14),4).OR.btest(igdstmpl(14),5)) &
1128 kgds(6)=kgds(6)+128
1129 if (btest(igdstmpl(14),3)) kgds(6)=kgds(6)+8
1130 kgds(7)=igdstmpl(15)/1000 ! Lat of last grid point
1131 kgds(8)=igdstmpl(16)/1000 ! Lon of last grid point
1132 kgds(9)=igdstmpl(17)/1000 ! Di
1133 kgds(10)=igdstmpl(18)/1000 ! Dj
1134 kgds(11)=igdstmpl(19) ! Scanning mode
1135 kgds(12)=0
1136 kgds(13)=0
1137 kgds(14)=0
1138 kgds(15)=0
1139 kgds(16)=0
1140 kgds(17)=0
1141 kgds(18)=0
1142 kgds(19)=0
1143 kgds(20)=255
1144 kgds(21)=0
1145 kgds(22)=0
1146 !
1147 ! Process irreg grid stuff, if necessary
1148 !
1149 if (idefnum.ne.0) then
1150 if (igdstmpl(8).eq.-1) then
1151 kgds(2)=65535
1152 kgds(9)=65535
1153 endif
1154 if (igdstmpl(9).eq.-1) then
1155 kgds(3)=65535
1156 kgds(10)=65535
1157 endif
1158 kgds(19)=0
1159 kgds(20)=33
1160 if (kgds(1).eq.1.OR.kgds(1).eq.3) kgds(20)=43
1161 kgds(21)=igds(2) ! num of grid points
1162 do j=1,idefnum
1163 kgds(21+j)=ideflist(j)
1164 enddo
1165 endif
1166 elseif (igds(5).eq.32769) then ! Rotate Lat/Lon grid
1167 kgds(1)=205 ! Arakawa Staggerred for Non-E Stagger grid
1168 kgds(2)=igdstmpl(8) ! Ni
1169 kgds(3)=igdstmpl(9) ! Nj
1170 kgds(4)=igdstmpl(12)/1000 ! Lat of 1st grid point
1171 kgds(5)=igdstmpl(13)/1000 ! Lon of 1st grid point
1172 kgds(6)=0 ! resolution and component flags
1173 if (igdstmpl(1)==2) kgds(6)=64
1174 if (btest(igdstmpl(14),4).OR.btest(igdstmpl(14),5)) &
1175 kgds(6)=kgds(6)+128
1176 if (btest(igdstmpl(14),3)) kgds(6)=kgds(6)+8
1177 kgds(7)=igdstmpl(15)/1000 ! Lat of last grid point
1178 kgds(8)=igdstmpl(16)/1000 ! Lon of last grid point
1179 kgds(9)=igdstmpl(17)/1000 ! Di
1180 kgds(10)=igdstmpl(18)/1000 ! Dj
1181 kgds(11)=igdstmpl(19) ! Scanning mode
1182 kgds(12)=igdstmpl(20)/1000
1183 kgds(13)=igdstmpl(21)/1000
1184 kgds(14)=0
1185 kgds(15)=0
1186 kgds(16)=0
1187 kgds(17)=0
1188 kgds(18)=0
1189 kgds(19)=0
1190 kgds(20)=255
1191 kgds(21)=0
1192 kgds(22)=0
1193 else
1194 print *,'gdt2gds: Unrecognized GRIB2 GDT = 3.',igds(5)
1195 iret=1
1196 kgds(1:22)=0
1197 return
1198 endif
1199 !
1200 ! Can we determine NCEP grid number ?
1201 !
1202 igrid=255
1203 do j=254,1,-1
1204 !do j=225,225
1205 kgds71=0
1206 kgds72=0
1207 call w3fi71(j,kgds71,ierr)
1208 if (ierr.ne.0) cycle
1209 ! convert W to E for longitudes
1210 if (kgds71(3).eq.0) then ! lat/lon
1211 if (kgds71(7).lt.0) kgds71(7)=360000+kgds71(7)
1212 if (kgds71(10).lt.0) kgds71(10)=360000+kgds71(10)
1213 elseif (kgds71(3).eq.1) then ! mercator
1214 if (kgds71(7).lt.0) kgds71(7)=360000+kgds71(7)
1215 if (kgds71(10).lt.0) kgds71(10)=360000+kgds71(10)
1216 elseif (kgds71(3).eq.3) then ! lambert conformal
1217 if (kgds71(7).lt.0) kgds71(7)=360000+kgds71(7)
1218 if (kgds71(9).lt.0) kgds71(9)=360000+kgds71(9)
1219 if (kgds71(18).lt.0) kgds71(18)=360000+kgds71(18)
1220 elseif (kgds71(3).eq.4) then ! Guassian lat/lon
1221 if (kgds71(7).lt.0) kgds71(7)=360000+kgds71(7)
1222 if (kgds71(10).lt.0) kgds71(10)=360000+kgds71(10)
1223 elseif (kgds71(3).eq.5) then ! polar stereographic
1224 if (kgds71(7).lt.0) kgds71(7)=360000+kgds71(7)
1225 if (kgds71(9).lt.0) kgds71(9)=360000+kgds71(9)
1226 endif
1227 call r63w72(idum,kgds,jdum,kgds72)
1228 if (kgds72(3).eq.3) kgds72(14)=0 ! lambert conformal fix
1229 if (kgds72(3).eq.1) kgds72(15:18)=0 ! mercator fix
1230 if (kgds72(3).eq.5) kgds72(14:18)=0 ! polar str fix
1231 ! print *,' kgds71(',j,')= ', kgds71(1:30)
1232 ! print *,' kgds72 = ', kgds72(1:30)
1233 if (all(kgds71.eq.kgds72)) then
1234 igrid=j
1235 return
1236 endif
1237 enddo
1238
1239 return
1240end subroutine gdt2gds
1241
1381SUBROUTINE putgbexn(LUGB,KF,KPDS,KGDS,KENS, &
1382 KPROB,XPROB,KCLUST,KMEMBR,IBS,NBITS,LB,F,IRET)
1383
1384 INTEGER KPDS(200),KGDS(200),KENS(200)
1385 INTEGER KPROB(2),KCLUST(16),KMEMBR(80)
1386 REAL XPROB(2)
1387 LOGICAL*1 LB(KF)
1388 REAL F(KF)
1389 ! PARAMETER(MAXBIT=16)
1390 parameter(maxbit=24)
1391 INTEGER IBM(KF),IPDS(200),IGDS(200),IBDS(200)
1392 CHARACTER PDS(400),GRIB(1000+KF*(MAXBIT+1)/8)
1393
1394 ! GET W3FI72 PARAMETERS
1395 !print *,'SAGT: start putgbexn'
1396 CALL r63w72(kpds,kgds,ipds,igds)
1397 ibds=0
1398
1399 ! COUNT VALID DATA
1400 kbm=kf
1401 IF(ipds(7).NE.0) THEN
1402 kbm=0
1403 DO i=1,kf
1404 IF(lb(i)) THEN
1405 ibm(i)=1
1406 kbm=kbm+1
1407 ELSE
1408 ibm(i)=0
1409 ENDIF
1410 ENDDO
1411 IF(kbm.EQ.kf) ipds(7)=0
1412 ENDIF
1413
1414 ! GET NUMBER OF BITS AND ROUND DATA
1415 IF(nbits.GT.0) THEN
1416 nbit=nbits
1417 ELSE
1418 IF(kbm.EQ.0) THEN
1419 DO i=1,kf
1420 f(i)=0.
1421 ENDDO
1422 nbit=0
1423 ELSE
1424 !print *,'SAGT:',IPDS(7),IBS,IPDS(25),KF
1425 !print *,'SAGT:',count(ibm.eq.0),count(ibm.eq.1)
1426 CALL setbit(ipds(7),-ibs,ipds(25),kf,ibm,f,fmin,fmax,nbit)
1427 nbit=min(nbit,maxbit)
1428 ENDIF
1429 ENDIF
1430
1431 ! CREATE PRODUCT DEFINITION SECTION
1432 CALL w3fi68(ipds,pds)
1433 IF(ipds(24).EQ.2) THEN
1434 ilast=45
1435 IF (ipds(8).EQ.191.OR.ipds(8).EQ.192) ilast=55
1436 IF (kens(2).EQ.5) ilast=76
1437 IF (kens(2).EQ.5) ilast=86
1438 IF (kens(2).EQ.4) ilast=86
1439 CALL pdsens(kens,kprob,xprob,kclust,kmembr,ilast,pds)
1440 ENDIF
1441
1442 ! PACK AND WRITE GRIB DATA
1443 igflag=1
1444 igrid=kpds(3)
1445 if (igrid.ne.255) igflag=0
1446 !print *,minval(f(1:kf)),maxval(f(1:kf))
1447 !print *,nbit,kf
1448 !print *,(ipds(j),j=1,28)
1449 !write(6,fmt='(28z2)') (pds(j),j=1,28)
1450 !print *,(kgds(j),j=1,28)
1451 !print *,(igds(j),j=1,28)
1452 icomp=0
1453 CALL w3fi72(0,f,0,nbit,1,ipds,pds, &
1454 igflag,igrid,igds,icomp,0,ibm,kf,ibds, &
1455 kfo,grib,lgrib,iret)
1456 IF(iret.EQ.0) CALL wryte(lugb,lgrib,grib)
1457
1458 RETURN
1459END SUBROUTINE putgbexn
1460
1480SUBROUTINE setbit(IBM,IBS,IDS,LEN,MG,G,GMIN,GMAX,NBIT)
1481
1482 dimension mg(len),g(len)
1483
1484 ! ROUND FIELD AND DETERMINE EXTREMES WHERE BITMAP IS ON
1485 s=2.**ibs*10.**ids
1486 IF(ibm.EQ.0) THEN
1487 gmax=g(1)
1488 gmin=g(1)
1489 DO i=2,len
1490 gmax=max(gmax,g(i))
1491 gmin=min(gmin,g(i))
1492 ENDDO
1493 ELSE
1494 i1=1
1495 DO WHILE(i1.LE.len.AND.mg(i1).EQ.0)
1496 i1=i1+1
1497 ENDDO
1498 IF(i1.LE.len) THEN
1499 DO i=1,i1-1
1500 g(i)=0.
1501 ENDDO
1502 gmax=g(i1)
1503 gmin=g(i1)
1504 DO i=i1+1,len
1505 IF(mg(i).NE.0) THEN
1506 gmax=max(gmax,g(i))
1507 gmin=min(gmin,g(i))
1508 ELSE
1509 g(i)=0.
1510 ENDIF
1511 ENDDO
1512 ELSE
1513 DO i=1,len
1514 g(i)=0.
1515 ENDDO
1516 gmax=0.
1517 gmin=0.
1518 ENDIF
1519 ENDIF
1520
1521 ! COMPUTE NUMBER OF BITS
1522 nbit=log((gmax-gmin)*s+0.9)/log(2.)+1.
1523
1524 RETURN
1525END SUBROUTINE setbit
subroutine makepdsens(ipdsnum, ipdstmpl, kpds, kens, kprob, xprob, kclust, kmembr, iret)
This routine creates the GRIB1 NCEP Ensemble PDS extension information from appropriate information f...
Definition cnv21.F90:768
subroutine gdt2gds(igds, igdstmpl, idefnum, ideflist, kgds, igrid, iret)
This routine converts grid information from a GRIB2 Grid Description Section as well as its Grid Defi...
Definition cnv21.F90:908
subroutine putgbexn(lugb, kf, kpds, kgds, kens, kprob, xprob, kclust, kmembr, ibs, nbits, lb, f, iret)
Pack and write a grib message.
Definition cnv21.F90:1383
subroutine levelcnv(ipdstmpl, ltype, lval)
This routine converts Level/layer information from a GRIB2 Product Definition Template to GRIB1 Level...
Definition cnv21.F90:534
subroutine cnv21(ifl1, ifl2)
This subroutine converts every GRIB2 field in a file to a GRIB1 field.
Definition cnv21.F90:20
subroutine makepds(idisc, idsect, ipdsnum, ipdstmpl, ibmap, idrsnum, idrstmpl, kpds, iret)
This routine creates a GRIB1 PDS (Section 1) from appropriate information from a GRIB2 Product Defini...
Definition cnv21.F90:266
subroutine setbit(ibm, ibs, ids, len, mg, g, gmin, gmax, nbit)
The number of bits required to pack a given field for particular binary and decimal scalings is compu...
Definition cnv21.F90:1481
subroutine rdieee(rieee, a, num)
Copy array of 32-bit IEEE floating point values to local floating point representation.
Definition g2bytes.F90:637
subroutine getgb2(lugb, lugi, j, jdisc, jids, jpdtn, jpdt, jgdtn, jgdt, unpack, k, gfld, iret)
This is a legacy version of getgb2i2().
Definition g2getgb2.F90:64
subroutine gf_free(gfld)
Free memory that was used to store array values in derived type grib_mod::gribfield.
Definition g2gf.F90:585
This Fortran module contains the declaration of derived type gribfield.
Definition gribmod.F90:10
This Fortran Module contains info on all the available GRIB Parameters, and their GRIB1 and GRIB2 cod...
Definition params.F90:12
subroutine param_g2_to_g1(g2disc, g2cat, g2num, g1val, g1ver)
This subroutine returns the GRIB 1 parameter number for a given GRIB2 Discipline, Category and Parame...
Definition params.F90:1154