3 IMPLICIT LOGICAL(L,O,G), CHARACTER*8(C,H,Y)
5 PARAMETER(JSUP = 9,JSEC0= 3,JSEC1= 40,JSEC2= 64 ,JSEC3= 4,
6 1 JSEC4= 2,JELEM=80000,JSUBS=400,JCVAL=150 ,JBUFL=512000,
8 2 JBPW = 64,JTAB =1000,JCTAB=120,JCTST=1800,JCTEXT=1200,
10 2 JBPW = 32,JTAB =1000,JCTAB=120,JCTST=1800,JCTEXT=1200,
12 3 JWORK=4096000,JKEY=46,JBYTE=2048000)
14 PARAMETER (KELEM=40000)
15 PARAMETER (KVALS=4096000)
17 DIMENSION KBUFF(JBUFL)
18 DIMENSION KBUFR(JBUFL)
19 DIMENSION KSUP(JSUP) ,KSEC0(JSEC0),KSEC1(JSEC1)
20 DIMENSION KSEC2(JSEC2),KSEC3(JSEC3),KSEC4(JSEC4)
21 DIMENSION KEY (JKEY),KREQ(2)
24 REAL*8 VALUES(KVALS),VALUE(KVALS)
29 DIMENSION KTDLST(JELEM),KTDEXP(JELEM),KRQ(KELEM)
30 DIMENSION KDATA(200),KBOXR(JELEM*4)
33 CHARACTER*256 CFIN,COUT,CARG(4)
34 CHARACTER*64 CNAMES(KELEM),CBOXN(JELEM*4)
35 CHARACTER*24 CUNITS(KELEM),CBOXU(JELEM*4)
36 CHARACTER*80 CVALS(kelem)
37 CHARACTER*80 CVAL(kelem)
40 C ------------------------------------------------------------------
41 C* 1. INITIALIZE CONSTANTS AND VARIABLES.
42 C -----------------------------------
45 C MISSING VALUE INDICATOR
58 ict = 0 ! report counter
59 open(3,file='littler',status='unknown',form='formatted')
60 open(12,file='flist',status='old',form='formatted')
62 read(12,'(a256)',end=988,err=987) cfin
64 c determine fm number of the data based on file name
66 iln = index(cfin,'_') - 1
67 if (cfin(1:iln) .eq. 'temp') then
69 elseif (cfin(1:iln) .eq. 'pilot') then
71 elseif (cfin(1:iln) .eq. 'airep') then
73 elseif (cfin(1:iln) .eq. 'acars') then
75 elseif (cfin(1:iln) .eq. 'ship') then
77 elseif (cfin(1:iln) .eq. 'buoy') then
79 elseif (cfin(1:iln) .eq. 'synop') then
81 elseif (cfin(1:iln) .eq. 'aws') then
83 elseif (cfin(1:iln) .eq. 'satob') then
85 elseif (cfin(1:iln) .eq. 'satem') then
88 write(6,*) 'Observation type ',cfin(1:iln),' is not supported.
96 c write(6,*) 'Processing FM-',ifm,' from file ',cfin(1:iln)
98 C SET REQUEST FOR PARTIAL EXPANSION
109 C* 1.2 OPEN FILE CONTAINING BUFR DATA.
110 C -------------------------------
114 CALL PBOPEN(IUNIT,CFIN(1:ILN),'R',IRET)
115 write(6,*) 'opening ',cfin(1:iln)
116 IF(IRET.EQ.-1) STOP 'OPEN FAILED'
117 IF(IRET.EQ.-2) STOP 'INVALID FILE NAME'
118 IF(IRET.EQ.-3) STOP 'INVALID OPEN MODE SPECIFIED'
123 C -----------------------------------------------------------------
124 C* 2. SET REQUEST FOR EXPANSION.
125 C --------------------------
130 c WRITE(*,'(A,$)') ' DO YOU WANT TO PRINT( Y/N ) : '
133 c WRITE(*,'(A,$)') ' CODE TABLES TO BE PRINTED ( Y/N ) : '
135 c WRITE(*,'(A,$)') ' RECORD NUMBER TO START FROM : '
142 C* 2.1 SET REQUEST FOR PARTIAL EXPANSION.
143 C ----------------------------------
147 CALL BUSRQ(KREQ,KRQL,KRQ,RQV,KERR)
149 C SET VARIABLE TO PACK BIG VALUES AS MISSING VALUE INDICATOR
154 CALL BUPRQ(KPMISS,KPRUS,KOKEY)
156 C -----------------------------------------------------------------
157 C* 3. READ BUFR MESSAGE.
165 CALL PBBUFR(IUNIT,KBUFF,JBYTE,KBUFL,IRET)
167 PRINT*,'NUMBER OF SUBSETS ',IOBS
168 PRINT*,'NUMBER OF MESSAGES ',N
169 CALL PBCLOSE(IUNIT,IRET)
172 IF(IRET.EQ.-2) STOP 'FILE HANDLING PROBLEM'
173 IF(IRET.EQ.-3) STOP 'ARRAY TOO SMALL FOR PRODUCT'
176 PRINT*,'----------------------------------',N,' ',KBUFL
178 IF(N.LT.NR) GO TO 300
180 C -----------------------------------------------------------------
181 C* 4. EXPAND BUFR MESSAGE.
182 C --------------------
185 CALL BUS012(KBUFL,KBUFF,KSUP,KSEC0,KSEC1,KSEC2,KERR)
187 PRINT*,'ERROR IN BUS012: ',KERR
188 PRINT*,' BUFR MESSAGE NUMBER ',N,' CORRUPTED.'
194 IF(KEL.GT.JELEM) KEL=JELEM
196 CALL BUFREX(KBUFL,KBUFF,KSUP,KSEC0 ,KSEC1,KSEC2 ,KSEC3 ,KSEC4,
197 1 KEL,CNAMES,CUNITS,KVALS,VALUES,CVALS,IERR)
200 IF(IERR.EQ.39) GO TO 300
209 CALL BUSEL(KTDLEN,KTDLST,KTDEXL,KTDEXP,KERR)
210 IF(KERR.NE.0) CALL EXIT(2)
217 c write(6,*) 'date = ',iyr,imo,idy,ihr,imn
220 C* 4.1 PRINT CONTENT OF EXPANDED DATA.
221 C -------------------------------
224 IF(.NOT.OPRT) GO TO 500
225 IF(.NOT.OSEC3) GO TO 450
227 C* 4.2 PRINT SECTION ZERO OF BUFR MESSAGE.
228 C -----------------------------------
234 C* 4.3 PRINT SECTION ONE OF BUFR MESSAGE.
235 C -----------------------------------
241 C* 4.4 PRINT SECTION TWO OF BUFR MESSAGE.
242 C -----------------------------------
245 C* 4.5 PRINT SECTION 3 OF BUFR MESSAGE.
246 C -----------------------------------
249 C FIRST GET DATA DESCRIPTORS
251 CALL BUSEL(KTDLEN,KTDLST,KTDEXL,KTDEXP,KERR)
252 C IF(KERR.NE.0) CALL EXIT(2)
257 CALL BUPRS3(KSEC3,KTDLEN,KTDLST,KTDEXL,KTDEXP,KEL,CNAMES)
260 c write(6,*) 'ktdexl = ',ktdexl
262 c write(6,*) jj,' ksup = ',ksup(jj)
264 c write(6,*) 'kel = ', KVALS/KSUP(6)
265 c write(6,*) 'jelem = ',jelem
266 c write(6,*) 'KVALS = ',kvals
268 do ij = 1, ksup(6) ! loop over reports
271 c write(6,*) 'sta = ',ij,' val = ',values(jj),' cnames = ',
273 c write(6,*) 'sta = ',ij,' ktdexp = ',ktdexp(kj),' cunits = ',
275 c write(6,789) ij,ktdexp(kj),values(jj),cunits(kj),cnames(kj)
278 789 format (i6,i8,f20.6,1x,a20,a80)
279 call wlittler (values,kvals,ktdexp,jelem,ktdexl,kel,ksup(6),
282 C* 4.6 PRINT SECTION 4 (DATA).
283 C -----------------------
293 c CALL BUPRT(ICODE,IST,IEND,KEL,CNAMES,CUNITS,CVALS,
294 c 1 KVALS,VALUES,KSUP,KSEC1,IERR)
296 C -----------------------------------------------------------------
297 C* 5. COLLECT DATA FOR REPACKING.
298 C ---------------------------
305 C -----------------------------------------------------------------
310 987 write(6,*) 'error reading flist'
312 988 write(6,*) 'end of file in flist'
314 c-------------------------------------------------------
315 subroutine wlittler (v,kvals,kt,jelem,ktdexl,kel,nsta,
316 & ict,iunit,ifm,cvals)
317 parameter (xmis = -888888., mkx=300)
320 real p(mkx), z(mkx), t(mkx), td(mkx), spd(mkx), dir(mkx)
322 character ctime*12, ch2*2, ch3*3, ch4*4
323 character*80 cvals(kel)
324 character*40 id, name, platform, source
330 if (ifm .eq. 12) then
331 platform = 'FM-12 SYNOP '
333 else if (ifm .eq. 13) then
334 platform = 'FM-13 SHIP '
336 else if (ifm .eq. 15) then
337 platform = 'FM-15 METAR '
339 else if (ifm .eq. 32) then
340 platform = 'FM-32 PILOT '
342 else if (ifm .eq. 35) then
343 platform = 'FM-35 TEMP '
345 else if (ifm .eq. 88) then
346 platform = 'FM-88 SATOB '
348 else if (ifm .eq. 96) then
349 platform = 'FM-96 AIREP '
355 call initzero(p, z, t, td, spd, dir,
356 & slp, psfc, elev ,lat, lon, xmis, kx)
360 c write(6,*) i,kt(k),v(j)
361 if (kt(k) .eq. 1001) then
362 write(ch2,'(i2.2)') int(v(j))
365 if (kt(k) .eq. 1002) then
366 write(ch3,'(i3.3)') int(v(j))
369 if (kt(k) .eq. 1006) then ! aircraft
371 ml = int(v(j)) - m*1000
372 id(1:ml) = cvals(m)(1:ml)
375 if (kt(k) .eq. 1006) then ! satellite not implemented by kma
376 write(ch2,'(i2.2)') int(v(j))
379 if (kt(k) .eq. 1011) then
381 ml = int(v(j)) - m*1000
382 id(1:ml) = cvals(m)(1:ml)
383 elev = 0. ! watch out for Great Lakes
385 if (kt(k) .eq. 4001) then
386 write(ch4,'(i4.4)') int(v(j))
389 if (kt(k) .eq. 4002) then
390 write(ch2,'(i2.2)') int(v(j))
393 if (kt(k) .eq. 4003) then
394 write(ch2,'(i2.2)') int(v(j))
397 if (kt(k) .eq. 4004) then
398 write(ch2,'(i2.2)') int(v(j))
401 if (kt(k) .eq. 4005) then
402 write(ch2,'(i2.2)') int(v(j))
405 if (kt(k) .eq. 5001) lat = verifi(v(j),-90.,90.,xmis)
406 if (kt(k) .eq. 6001) lon = verifi(v(j),-180.,180.,xmis)
407 if (kt(k) .eq. 5002) lat = verifi(v(j),-90.,90.,xmis)
408 if (kt(k) .eq. 6002) lon = verifi(v(j),-180.,180.,xmis)
409 if (kt(k) .eq. 7001) elev = verifi(v(j),-200.,9100.,xmis)
410 if (kt(k) .eq. 7030) elev = verifi(v(j),-200.,9100.,xmis)
411 if (kt(k) .eq. 7004) then
413 p(kx) = verifi(v(j),100.,110000.,xmis)
415 if (kt(k) .eq. 10004) then
416 psfc = verifi(v(j),100.,1100.,xmis)
417 if (psfc .gt. 0.) psfc = psfc * 100.
419 z(1) = elev ! for sfc stations,
422 if (kt(k) .eq. 10051) then
423 slp = verifi(v(j),100.,1100.,xmis)
424 if (slp .gt. 0.) slp = slp * 100.
426 if (kt(k) .eq. 7002) then
428 z(kx) = verifi(v(j),-200.,55000.,xmis) ! m
430 if (kt(k) .eq. 10009) z(kx) = verifi(v(j),-200.,55000.,xmis) ! gpm
431 if (kt(k) .eq. 11011) dir(1) = verifi(v(j),0.,360.,xmis) ! 10m
432 if (kt(k) .eq. 11012) spd(1) = verifi(v(j),0.,200.,xmis) ! 10m
433 if (kt(k) .eq. 11001) dir(kx) = verifi(v(j),0.,360.,xmis)
434 if (kt(k) .eq. 11002) spd(kx) = verifi(v(j),0.,200.,xmis)
435 if (kt(k) .eq. 12004) t(1) = verifi(v(j),0.,360.,xmis) ! 2m
436 if (kt(k) .eq. 12006) td(1) = verifi (v(j),0.,360.,xmis) ! 2m
437 if (kt(k) .eq. 12001) t(kx) = verifi(v(j),0.,360.,xmis) ! aircraft temp
438 if (kt(k) .eq. 12101) t(kx) = verifi(v(j),0.,360.,xmis)
439 if (kt(k) .eq. 12003) td(kx) = verifi (v(j),0.,360.,xmis) ! aircraft td
440 if (kt(k) .eq. 12103) td(kx) = verifi (v(j),0.,360.,xmis)
442 if (lat .eq. xmis .or. lon .eq. xmis) then
446 if (is_sound .and. z(1) .eq. elev) then
449 if (is_sound .and. (ifm .ne. 96 .and. ifm .ne. 88 )) then
450 call cmprsnd (p, z, t, td, spd, dir, kx, xmis)
452 call write_obs (p, z,
454 & slp, psfc, elev ,lat, lon,
456 & id, name, platform, source,
457 & is_sound, bogus, ict, iunit)
460 c-------------------------------------
461 SUBROUTINE write_obs ( p, z, t, td, spd, dir,
462 & slp, psfc, ter, xlat, xlon, cdate, kx,
463 & string1, string2, string3, string4, is_sound, bogus,
466 dimension p(kx), z(kx),t(kx),td(kx),spd(kx),dir(kx)
468 character *20 date_char
469 character *40 string1, string2 , string3 , string4
470 CHARACTER *84 rpt_format
471 CHARACTER *22 meas_format
472 CHARACTER *14 end_format
473 character cdate*12, cmin*4
474 logical is_sound,bogus
476 rpt_format = ' ( 2f20.5 , 2a40 , '
477 * // ' 2a40 , 1f20.5 , 5i10 , 3L10 , '
478 * // ' 2i10 , a20 , 13( f13.5 , i7 ) ) '
479 meas_format = ' ( 10( f13.5 , i7 ) ) '
480 end_format = ' ( 3 ( i7 ) ) '
482 date_char(17:20)='0000'
484 date_char(7:18) = cdate
486 WRITE ( UNIT = iunit, ERR = 19, FMT = rpt_format )
487 * xlat,xlon, string1 , string2 ,
488 * string3, string4, ter, kx*6, 0, 0, iseq_num, 0,
489 * is_sound,bogus,.false.,
490 * -888888, -888888, date_char,
491 * slp,0,-888888.,0, -888888.,0, -888888.,0, psfc,0,
493 * -888888.,0, -888888.,0, -888888.,0, -888888.,0,
495 * -888888.,0, -888888.,0
498 WRITE ( UNIT = iunit , ERR = 19 , FMT = meas_format )
499 * p(k), 0, z(k),0, t(k),0, td(k),0,
500 * spd(k),0, dir(k),0,
501 * -888888.,0, -888888.,0,-888888.,0, -888888.,0
503 WRITE ( UNIT = iunit , ERR = 19 , FMT = meas_format )
504 * -777777.,0, -777777.,0,float(kx),0,
505 * -888888.,0, -888888.,0, -888888.,0,
506 * -888888.,0, -888888.,0, -888888.,0,
508 WRITE ( UNIT = iunit , ERR = 19 , FMT = end_format ) kx, 0, 0
512 print *,'troubles writing little_r observation'
515 c------------------------------------------
516 subroutine subdat (ccyymmddhh, dh, idate)
517 INTEGER ccyymmddhh,ccyy,mmddhh,mm,dd,hh,dh
520 ccyy = ccyymmddhh / 1000000
521 mmddhh = MOD ( ccyymmddhh , 1000000 )
523 dd = MOD ( mmddhh , 10000 ) / 100
524 hh = MOD ( mmddhh , 100 )
527 10 IF ( hh .LT. 0 ) THEN
529 CALL change_date ( ccyy, mm, dd, -1 )
530 ELSEIF ( hh .GT. 23 ) THEN
532 CALL change_date ( ccyy, mm, dd, 1 )
534 WRITE (cmin,'(I4.4,3I2.2)') ccyy,mm,dd,hh
535 read (cmin,'(i10)') idate
541 SUBROUTINE change_date ( ccyy, mm, dd, delta )
542 INTEGER ccyy, mm, dd, delta
544 DATA mmday/31,28,31,30,31,30,31,31,30,31,30,31/
547 IF ( MOD(ccyy,4) .EQ. 0 ) THEN
548 IF ( MOD(ccyy,400) .EQ. 0 ) THEN
550 ELSEIF ( MOD(ccyy,100) .NE. 0 ) THEN
556 IF ( dd .EQ. 0 ) THEN
558 IF ( mm .EQ. 0 ) THEN
563 ELSEIF ( dd .GT. mmday(mm) ) THEN
566 IF ( mm .GT. 12 ) THEN
573 c-----------------------------------------------------------------
574 subroutine jdate (iyr, jday, ihr, jtime)
577 data mon/31,28,31,30,31,30,31,31,30,31,30,31/
578 write(tmp,'(i4)') iyr
579 read(tmp,'(2x,i2)') jyr
580 if (mod(jyr,4) .eq. 0) mon(2) = 29
584 if (jday .le. m ) go to 10
588 idy = jday - ( m - mon(i))
592 write(tmp,'(4(i2.2))') jyr, i, idy, ihr
593 read(tmp,'(i8)') jtime
595 c-----------------------------------------------------------------
596 real function verifi (x,xmin,xmax,xmis)
598 if (x .lt. xmin .or. x .gt. xmax) then
604 c-----------------------------------------------------------------
605 subroutine initzero(p, z, t, td, spd, dir,
606 & slp, psfc, elev ,lat, lon, xmis, kx)
607 real p(kx), z(kx), t(kx), td(kx), spd(kx), dir(kx)
608 real slp, psfc, elev, lat, lon, xmis
624 c-----------------------------------------------------------------
625 subroutine cmprsnd (p, z, t, td, spd, dir, kx, xmis)
626 c kma files have levels with all missing data, so delete them
627 real p(kx), z(kx), t(kx), td(kx), spd(kx), dir(kx)
631 c write(6,*) 'begin loop, il = ',il,' ih = ',ih
633 if (p(k) .eq. xmis .and. z(k) .eq. xmis .and. t(k) .eq. xmis
634 & .and. td(k) .eq. xmis .and. spd(k) .eq. xmis .and.
635 & dir(k) .eq. xmis) go to 20
650 if ( il .eq. 1 .and. ih .eq. 1 ) then
651 kx = 1 ! if all levels are missing, return just one.