diff --git a/src/tocgrib/CMakeLists.txt b/src/tocgrib/CMakeLists.txt index 6b06d243..45781853 100644 --- a/src/tocgrib/CMakeLists.txt +++ b/src/tocgrib/CMakeLists.txt @@ -3,6 +3,7 @@ # # Mark Potts, Kyle Gerheiser +# Set compiler flags. if(CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel)$") set(CMAKE_Fortran_FLAGS "-g -assume noold_ldout_format -axCORE-AVX2 ${CMAKE_Fortran_FLAGS}") set(CMAKE_Fortran_FLAGS_RELEASE "-O2 ${CMAKE_Fortran_FLAGS}") @@ -11,12 +12,15 @@ elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^(GNU)$") set(CMAKE_Fortran_FLAGS_RELEASE "-O2 ${CMAKE_Fortran_FLAGS}") endif() -set(fortran_src makwmo.f mkfldsep.f tocgrib.f) +# This is the Fortran source code. +set(fortran_src makwmo.F90 mkfldsep.F90 tocgrib.F90) +# Build the executable. set(exe_name tocgrib) add_executable(${exe_name} ${fortran_src}) target_link_libraries(${exe_name} PRIVATE w3emc::w3emc_4 bacio::${bacio_name}) +# Install the utility. install(TARGETS ${exe_name} RUNTIME DESTINATION bin) # If doxygen documentation is enabled, build it. diff --git a/src/tocgrib/makwmo.F90 b/src/tocgrib/makwmo.F90 new file mode 100755 index 00000000..f2b57e43 --- /dev/null +++ b/src/tocgrib/makwmo.F90 @@ -0,0 +1,74 @@ +!> @file +!> @brief Format the wmo header. +!> @author Farley @date 84-07-06 + +!> Forms the wmo header for a given bulletin. +!> +!> ### Program History Log +!> Date | Programmer | Comments +!> -----|------------|--------- +!> 84-07-06 | Farley | Original author +!> 94-10-10 | R. E. Jones | changes for cray +!> 95-10-18 | R. E. Jones | add parameter kwbx to call +!> 98-06-16 | Gilbert | Changed argument list to pass in day and hour instead of the old O.N. 84 date word. +!> 2003-03-28 | Gilbert | Removed equivalences. +!> +!> @param[in] bulhed ttaaii bulletin header ft10 +!> @param[in] iday day of month +!> @param[in] ihour hour of day. +!> @param[in] kwbx 4 characters (kwbc to kwbq) +!> @param[out] header complete wmo header in ascii +!> +!> @author Farley @date 84-07-06 +SUBROUTINE MAKWMO (BULHED,IDAY,IHOUR,KWBX,HEADER) + ! + CHARACTER * 6 BULHED + CHARACTER * 1 HEADER (*) + CHARACTER * 1 WMOHDR (21) + CHARACTER * 4 KWBX + CHARACTER * 2 CTEMP + !$ 1. CREATE WMO HEADER. + !$ 1.1 CONVERT BULHED FROM EBCDIC TO ASCII. + ! WRITE (6,FMT='('' MADE IT TO MAKWMO'')') + ! + DO I = 1,6 + WMOHDR(I) = BULHED(I:I) + END DO + WMOHDR(7)=char(32) ! ASCII BLANK + ! + ! MOVE KWBX INTO WMO HEADER + ! + DO I = 1,4 + WMOHDR(I+7) = KWBX(I:I) + END DO + WMOHDR(12)=char(32) ! ASCII BLANK + ! + !$ 1.2 PICK OFF THE DAY OF MONTH (YY) + !$ AND CONVERT TO ASCII. + ! + write(ctemp,fmt='(I2.2)') IDAY + WMOHDR(13)=ctemp(1:1) + WMOHDR(14)=ctemp(2:2) + ! + !$ 1.3 PICK OFF THE HOUR(GG) AND CONVERT TO ASCII. + ! + write(ctemp,fmt='(I2.2)') IHOUR + WMOHDR(15)=ctemp(1:1) + WMOHDR(16)=ctemp(2:2) + ! + ! 1.4 FIL IN REST OF HEADER + ! + WMOHDR(17)=char(48) ! ASCII "0" + WMOHDR(18)=char(48) ! ASCII "0" + WMOHDR(19)=char(13) ! ASCII CR = '\r' + WMOHDR(20)=char(13) ! ASCII CR = '\r' + WMOHDR(21)=char(10) ! ASCII LF = '\n' + ! + !$ 2. MOVE WMOHDR TO OUTPUT FIELD. + ! + DO I = 1,21 + HEADER(I) = WMOHDR(I) + end do + ! + RETURN +END SUBROUTINE MAKWMO diff --git a/src/tocgrib/makwmo.f b/src/tocgrib/makwmo.f deleted file mode 100755 index 36f1a32e..00000000 --- a/src/tocgrib/makwmo.f +++ /dev/null @@ -1,74 +0,0 @@ -!> @file -!> @brief Format the wmo header. -!> @author Farley @date 84-07-06 - -!> Forms the wmo header for a given bulletin. -!> -!> ### Program History Log -!> Date | Programmer | Comments -!> -----|------------|--------- -!> 84-07-06 | Farley | Original author -!> 94-10-10 | R. E. Jones | changes for cray -!> 95-10-18 | R. E. Jones | add parameter kwbx to call -!> 98-06-16 | Gilbert | Changed argument list to pass in day and hour instead of the old O.N. 84 date word. -!> 2003-03-28 | Gilbert | Removed equivalences. -!> -!> @param[in] bulhed ttaaii bulletin header ft10 -!> @param[in] iday day of month -!> @param[in] ihour hour of day. -!> @param[in] kwbx 4 characters (kwbc to kwbq) -!> @param[out] header complete wmo header in ascii -!> -!> @author Farley @date 84-07-06 - SUBROUTINE MAKWMO (BULHED,IDAY,IHOUR,KWBX,HEADER) -! - CHARACTER * 6 BULHED - CHARACTER * 1 HEADER (*) - CHARACTER * 1 WMOHDR (21) - CHARACTER * 4 KWBX - CHARACTER * 2 CTEMP -!$ 1. CREATE WMO HEADER. -!$ 1.1 CONVERT BULHED FROM EBCDIC TO ASCII. -! WRITE (6,FMT='('' MADE IT TO MAKWMO'')') -! - DO I = 1,6 - WMOHDR(I) = BULHED(I:I) - END DO - WMOHDR(7)=char(32) ! ASCII BLANK -! -! MOVE KWBX INTO WMO HEADER -! - DO I = 1,4 - WMOHDR(I+7) = KWBX(I:I) - END DO - WMOHDR(12)=char(32) ! ASCII BLANK -! -!$ 1.2 PICK OFF THE DAY OF MONTH (YY) -!$ AND CONVERT TO ASCII. -! - write(ctemp,fmt='(I2.2)') IDAY - WMOHDR(13)=ctemp(1:1) - WMOHDR(14)=ctemp(2:2) -! -!$ 1.3 PICK OFF THE HOUR(GG) AND CONVERT TO ASCII. -! - write(ctemp,fmt='(I2.2)') IHOUR - WMOHDR(15)=ctemp(1:1) - WMOHDR(16)=ctemp(2:2) -! -! 1.4 FIL IN REST OF HEADER -! - WMOHDR(17)=char(48) ! ASCII "0" - WMOHDR(18)=char(48) ! ASCII "0" - WMOHDR(19)=char(13) ! ASCII CR = '\r' - WMOHDR(20)=char(13) ! ASCII CR = '\r' - WMOHDR(21)=char(10) ! ASCII LF = '\n' -! -!$ 2. MOVE WMOHDR TO OUTPUT FIELD. -! - DO 200 I = 1,21 - HEADER(I) = WMOHDR(I) - 200 CONTINUE -! - RETURN - END diff --git a/src/tocgrib/mkfldsep.f b/src/tocgrib/mkfldsep.F90 similarity index 62% rename from src/tocgrib/mkfldsep.f rename to src/tocgrib/mkfldsep.F90 index 0773991a..d953469b 100755 --- a/src/tocgrib/mkfldsep.f +++ b/src/tocgrib/mkfldsep.F90 @@ -53,44 +53,44 @@ !> @param[out] lenout Integer length of the flag field separator block. !> !> @author Gilbert @date 2002-09-16 - subroutine mkfldsep(csep,iopt,lenin,lenbull,lenout) -! - character*(*),intent(out) :: csep - integer,intent(in) :: iopt,lenin,lenbull - integer,intent(out) :: lenout -! - character(len=4),parameter :: cstar='****',clb='####' -! - if (iopt.eq.1) then - if ( lenin .le. 18 .and. lenbull .le. 999999 ) then - ! Create OPTION 1 separator block - csep(1:4)=clb - csep(5:7)='018' - write(csep(8:13),fmt='(I6.6)') lenbull - csep(14:17)=clb - csep(18:18)=char(10) - lenout=18 - else ! Create OPTION 1a separator block - nnn=lenin - if ( nnn.lt.23 ) nnn=23 - csep(1:4)=clb - write(csep(5:7),fmt='(I3.3)') nnn - write(csep(8:18),fmt='(I11.11)') lenbull - csep(19:nnn-5)='0' - csep(nnn-4:nnn-1)=clb - csep(nnn:nnn)=char(10) - lenout=nnn - endif - elseif (iopt.eq.2) then ! Create OPTION 2 separator block - csep(1:4)=cstar - write(csep(5:14),fmt='(I10.10)') lenbull - csep(15:18)=cstar - csep(19:19)=char(10) - lenout=19 - else - print *,"mkfldsep: Option ",iopt," not recognized." - csep(1:lenin)=' ' - endif -! - return - end +subroutine mkfldsep(csep,iopt,lenin,lenbull,lenout) + ! + character*(*),intent(out) :: csep + integer,intent(in) :: iopt,lenin,lenbull + integer,intent(out) :: lenout + ! + character(len=4),parameter :: cstar='****',clb='####' + ! + if (iopt.eq.1) then + if ( lenin .le. 18 .and. lenbull .le. 999999 ) then + ! Create OPTION 1 separator block + csep(1:4)=clb + csep(5:7)='018' + write(csep(8:13),fmt='(I6.6)') lenbull + csep(14:17)=clb + csep(18:18)=char(10) + lenout=18 + else ! Create OPTION 1a separator block + nnn=lenin + if ( nnn.lt.23 ) nnn=23 + csep(1:4)=clb + write(csep(5:7),fmt='(I3.3)') nnn + write(csep(8:18),fmt='(I11.11)') lenbull + csep(19:nnn-5)='0' + csep(nnn-4:nnn-1)=clb + csep(nnn:nnn)=char(10) + lenout=nnn + endif + elseif (iopt.eq.2) then ! Create OPTION 2 separator block + csep(1:4)=cstar + write(csep(5:14),fmt='(I10.10)') lenbull + csep(15:18)=cstar + csep(19:19)=char(10) + lenout=19 + else + print *,"mkfldsep: Option ",iopt," not recognized." + csep(1:lenin)=' ' + endif + ! + return +end subroutine mkfldsep diff --git a/src/tocgrib/tocgrib.F90 b/src/tocgrib/tocgrib.F90 new file mode 100755 index 00000000..bdfc0380 --- /dev/null +++ b/src/tocgrib/tocgrib.F90 @@ -0,0 +1,250 @@ +!> @file +!> @brief Create new GRIB2 file from exiting GRIB2 file. +!> @author Gilbert @date 2003-03-28 + +!> Program reads selected GRIB fields from a file, adds a TOC Flag Field +!> separator block and WMO Header in front of each GRIB field, and +!> writes them out to a new file. The output file is in the format +!> required for TOC's FTP Input Service, which can be used to +!> disseminate the GRIB bulletins. This service is described at +!> http://weather.gov/tg/ftpingest.html. +!> +!> ### Program History Log +!> Date | Programmer | Comments +!> -----|------------|--------- +!> 2003-03-28 | Gilbert | Initial +!> 2012-10-22 | Vuong | changed variable envvar to character*6 +!> 2016-10-15 | Vuong | increased length of file name to 200 characters +!> +!> ### Input Files +!> - 5 list of grib fields and associated wmo headers. +!> - 11 input grib file. +!> - 31 corresponding input grib index file. +!> - parm pass in 4 characters 'kwbx' with parm field +!> +!> ### Output Files (Including Scratch Files) +!> - 6 standard fortran print file +!> - 51 output grib bulletin file in toc format +!> +!> @return +!> - 0 Successful run +!> - 10 Error opening input GRIB data file +!> - 20 Error opening output GRIB transmission file +!> - 19 Error reading control card file - all bulletins missing +!> - 30 Some BULLETINS ARE MISSING +!> +!> @author Gilbert @date 2003-03-28 +PROGRAM tocgrib + PARAMETER (MXSIZ3=1000000) + + INTEGER DUM + INTEGER JGDS(200) + INTEGER MPDS(200) + INTEGER KGDS(200) + INTEGER KPDS(200) + INTEGER MAPNUM + INTEGER NBITS + INTEGER NBUL + INTEGER NPARM + INTEGER PUNUM + INTEGER,dimension(28) :: HEXPDS + + CHARACTER * 6 BULHED + CHARACTER * 100 CPARM + CHARACTER * 20 DESC + CHARACTER * 3 EOML + CHARACTER * 1 GRIB(MXSIZ3) + CHARACTER * 200 fileb,filei,fileo + CHARACTER * 6 envvar + CHARACTER * 4 KWBX + CHARACTER * 1 PDS(28) + CHARACTER * 1 PDSL(28) + CHARACTER * 1 CSEP(80) + CHARACTER * 132 TITLE + integer,parameter :: lenhead=21 + CHARACTER * 1 WMOHDR(lenhead) + + LOGICAL IW3PDS + + HEXPDS=0 + LUGB=11 + LUGI=31 + LUGO=51 + + ! GET PARM FIELD WITH UP TO 100 CHARACTERS + ! Parm field should contain the originating center part of + ! the WMO Header. + CPARM = ' ' + KWBX = 'KWBC' + CALL W3AS00(NPARM,CPARM,IER) + IF (IER.EQ.0) THEN + IF (NPARM.EQ.0.OR.CPARM(1:4).EQ.' ') THEN + PRINT *,'THERE IS A PARM FIELD BUT IT IS EMPTY' + PRINT *,'OR BLANK, I WILL USE THE DEFAULT KWBC' + ELSE + KWBX(1:4) = CPARM(1:4) + END IF + ELSE IF (IER.EQ.2.OR.IER.EQ.3) THEN + PRINT *,'W3AS00 ERROR = ',IER + PRINT *,'THERE IS NO PARM FIELD, I USED DEFAULT KWBC' + ELSE + PRINT *,'W3AS00 ERROR = ',IER + END IF + PRINT *,'NPARM = ',NPARM + PRINT *,'CPARM = ',CPARM(1:4) + PRINT *,'KWBX = ',KWBX(1:4) + + ! Read GRIB data and index file names from the FORTnn + ! environment variables, and open the files. + envvar='FORT ' + write(envvar(5:6),fmt='(I2)') lugb + call getenv(envvar,fileb) + write(envvar(5:6),fmt='(I2)') lugi + call getenv(envvar,filei) + + call baopenr(lugb,fileb,iret1) + if ( iret1 .ne. 0 ) then + write(6,fmt='(" Error opening GRIB file: ", A200)') fileb + write(6,fmt='(" baopenr error = ",I5)') iret1 + stop 10 + endif + + ! Open GRIB index file. If doesn't open, use just the data + ! file. + call baopenr(lugi,filei,iret2) + if ( iret2 .ne. 0 ) then + lugi=0 + endif + + ! Read output GRIB bulletin file name from FORTnn + ! environment variable, and open file. + write(envvar(5:6),fmt='(I2)') lugo + call getenv(envvar,fileo) + call baopenw(lugo,fileo,iret1) + if ( iret1 .ne. 0 ) then + write(6,fmt='(" Error opening GRIB file: ",A200)') fileo + write(6,fmt='(" baopenw error = ",I5)') iret1 + stop 20 + endif + + IRET = 0 + iopt=2 + insize=19 + NBUL = 0 + + ! loop through input control records. + nrec = 0 + foreachelement: do + + READ (*,66,iostat=ios) (HEXPDS(J),J=1,12), & + (HEXPDS(J),J=17,20), PUNUM, DESC +66 FORMAT(3(2X,4Z2.2),3X,4Z2.2,6X,I3,1X,A20) + if ( ios .ne. 0 ) then + write(6,fmt='(" Error reading PDS from input file. iostat = ", i5)') ios + exit + endif + PDS=char(HEXPDS) + + ! exit loop, if no more bulletins in input cards + IF ( mova2i(pds(1)) .EQ. 255) exit + + nrec = nrec + 1 + WRITE(6,FMT='(/,''***********************************'', ''********************************************'')') + print *,'Start new record no. = ',nrec + WRITE (6,FMT='('' INPUT PDS, PUNUM'', '' & DESC...DESIRED GRIB MAPS LISTED ON FOLLOWING '', ' // & + ' ''LINES...'',/,4X,3(2X,4z2.2),3X,4z2.2,6X,I3,1X, A20)') (HEXPDS(J),J=1,12), & + (HEXPDS(J),J=17,20), PUNUM, DESC + + ! Read WNO Header associated with this element + READ (*,iostat=ios,FMT='(4X,I3,2X,I2,2X,A6,1X,I3,24X,A3)') & + MAPNUM,NBITS, BULHED, DUM, EOML + WRITE (6,FMT='(4X,I3,2X,I2,2X,A6,1X,I3,24X,A3)') & + MAPNUM,NBITS, BULHED, DUM, EOML + if ( ios .ne. 0 ) then + write(6,fmt='(" Error reading PDS from input file. iostat =", i6)') ios + endif + + ! Set up 25 word PDS array of GRIB field to read + JREW = 0 + JGDS = -1 + MPDS = -1 + MPDS(3) = mova2i(PDS(7)) + MPDS(5) = mova2i(PDS(9)) + MPDS(6) = mova2i(PDS(10)) + MPDS(7) = mova2i(PDS(11)) * 256 + mova2i(PDS(12)) + MPDS(14) = mova2i(PDS(19)) + MPDS(15) = mova2i(PDS(20)) + + ! Read and return packed GRIB field + CALL GETGBP(LUGB,LUGI,MXSIZ3,JREW,MPDS,JGDS, & + itot,KREW,KPDS,KGDS,GRIB,IRET) + IF (IRET.NE.0) THEN + IF (IRET.LT.96) PRINT *,'GETGB-W3FI63: ERROR = ',IRET + IF (IRET.EQ.96) PRINT *,'GETGB: ERROR READING INDEX FILE' + IF (IRET.EQ.97) PRINT *,'GETGB: ERROR READING GRIB FILE' + IF (IRET.EQ.98) THEN + PRINT *,'GETGB ERROR: NUM. OF DATA POINTS GREATER THAN JF' + END IF + IF (IRET.EQ.99) PRINT *,'GETGB ERROR: REQUEST NOT FOUND' + IF (IRET.GT.99) PRINT *,'GETGB ERROR = ',IRET + cycle + END IF + PRINT *,'RECORD NO. OF GRIB RECORD IN INPUT FILE = ',KREW + + ! COMPARE RECORD (GRIB) TO CONTROL CARD (PDS), THEY SHOULD MATCH + PDSL(1:28)=GRIB(9:36) + KEY = 2 + IF (.NOT.IW3PDS(PDSL,PDS,KEY)) THEN + PRINT 2900, nrec,(mova2i(PDSL(j)),j=1,28), & + (mova2i(PDS(j)),j=1,28) +2900 FORMAT ( 1X,I4,' (PDS) IN RECORD DOES NOT MATCH (PDS) IN ', 'CONTROL CARD ',/,7(1X,4Z2.2), /,7(1X,4Z2.2)) + cycle + END IF + + ! Print PDS + PRINT 2, (mova2i(PDSL(J)),J=1,28) +2 FORMAT (' PDS = ',7(4Z2.2,1X)) + + ! Construct and print Description of GRIB field + CALL W3FP11 (GRIB,PDSL,TITLE,IER) + IF (IER.NE.0) PRINT *,'W3FP11 ERROR = ',IER + PRINT *,TITLE(1:86) + + PRINT *,' Size of GRIB Field = ',ITOT + + ! MAKE Flag Field Separator block + call mkfldsep(csep,iopt,insize,itot+lenhead,lenout) + + ! MAKE WMO HEADER + ! Get system date and time + CALL MAKWMO (BULHED,KPDS(10),KPDS(11),KWBX,WMOHDR) + + ! write out Separator block, Abbreviated WMO Heading, + ! and GRIB field to output file. + call wryte(lugo,lenout,csep) + call wryte(lugo,lenhead,WMOHDR) + call wryte(lugo,itot,grib) + nbul=nbul+1 + enddo foreachelement + + ! CLOSING SECTION + IF (NBUL .EQ. 0 ) THEN + WRITE (6,FMT='('' SOMETHING WRONG WITH DATA CARDS...'', ''NOTHING WAS PROCESSED'')') + stop 19 + ELSE + CALL BACLOSE (LUGB,iret) + CALL BACLOSE (LUGI,iret) + CALL BACLOSE (LUGO,iret) + WRITE (6,FMT='(//,'' ******** RECAP OF THIS EXECUTION '', ''********'',/,5X,''READ '',I6,'' INDIVIDUAL IDS'', ' // & + ' /,5X,''WROTE '',I6,'' BULLETINS OUT FOR TRANSMISSION'', //)') nrec, NBUL + ENDIF + + ! TEST TO SEE IF ANY BULLETINS MISSING + MBUL = nrec - NBUL + IF (MBUL.NE.0) THEN + PRINT *,'BULLETINS MISSING = ',MBUL + stop 30 + END IF + + STOP +END PROGRAM tocgrib diff --git a/src/tocgrib/tocgrib.f b/src/tocgrib/tocgrib.f deleted file mode 100755 index 984d1381..00000000 --- a/src/tocgrib/tocgrib.f +++ /dev/null @@ -1,287 +0,0 @@ -!> @file -!> @brief Create new GRIB2 file from exiting GRIB2 file. -!> @author Gilbert @date 2003-03-28 - -!> Program reads selected GRIB fields from a file, adds a TOC Flag Field -!> separator block and WMO Header in front of each GRIB field, and -!> writes them out to a new file. The output file is in the format -!> required for TOC's FTP Input Service, which can be used to -!> disseminate the GRIB bulletins. This service is described at -!> http://weather.gov/tg/ftpingest.html. -!> -!> ### Program History Log -!> Date | Programmer | Comments -!> -----|------------|--------- -!> 2003-03-28 | Gilbert | Initial -!> 2012-10-22 | Vuong | changed variable envvar to character*6 -!> 2016-10-15 | Vuong | increased length of file name to 200 characters -!> -!> ### Input Files -!> - 5 list of grib fields and associated wmo headers. -!> - 11 input grib file. -!> - 31 corresponding input grib index file. -!> - parm pass in 4 characters 'kwbx' with parm field -!> -!> ### Output Files (Including Scratch Files) -!> - 6 standard fortran print file -!> - 51 output grib bulletin file in toc format -!> -!> @return -!> - 0 Successful run -!> - 10 Error opening input GRIB data file -!> - 20 Error opening output GRIB transmission file -!> - 19 Error reading control card file - all bulletins missing -!> - 30 Some BULLETINS ARE MISSING -!> -!> @author Gilbert @date 2003-03-28 - PROGRAM tocgrib - PARAMETER (MXSIZ3=1000000) -! - INTEGER DUM - INTEGER JGDS(200) - INTEGER MPDS(200) - INTEGER,dimension(8):: ITIME=(/0,0,0,-500,0,0,0,0/) - INTEGER KGDS(200) - INTEGER KPDS(200) - INTEGER MAPNUM - INTEGER NBITS - INTEGER NBUL - INTEGER NPARM - INTEGER PUNUM - INTEGER,dimension(28) :: HEXPDS -! INTEGER :: HEXPDS(28)/28*0/ -! - CHARACTER * 6 BULHED - CHARACTER * 100 CPARM - CHARACTER * 20 DESC - CHARACTER * 3 EOML - CHARACTER * 1 GRIB(MXSIZ3) - CHARACTER * 200 fileb,filei,fileo - CHARACTER * 6 envvar - CHARACTER * 4 KWBX - CHARACTER * 1 PDS(28) - CHARACTER * 1 PDSL(28) - CHARACTER * 1 CSEP(80) - CHARACTER * 132 TITLE - integer,parameter :: lenhead=21 - CHARACTER * 1 WMOHDR(lenhead) -! - LOGICAL IW3PDS -! - HEXPDS=0 -! CALL W3TAGB('tocgrib',2002,0916,0083,'NP11') - LUGB=11 - LUGI=31 - LUGO=51 -! -! GET PARM FIELD WITH UP TO 100 CHARACTERS -! Parm field should contain the originating center part of -! the WMO Header. -! - CPARM = ' ' - KWBX = 'KWBC' - CALL W3AS00(NPARM,CPARM,IER) - IF (IER.EQ.0) THEN - IF (NPARM.EQ.0.OR.CPARM(1:4).EQ.' ') THEN - PRINT *,'THERE IS A PARM FIELD BUT IT IS EMPTY' - PRINT *,'OR BLANK, I WILL USE THE DEFAULT KWBC' - ELSE - KWBX(1:4) = CPARM(1:4) - END IF - ELSE IF (IER.EQ.2.OR.IER.EQ.3) THEN - PRINT *,'W3AS00 ERROR = ',IER - PRINT *,'THERE IS NO PARM FIELD, I USED DEFAULT KWBC' - ELSE - PRINT *,'W3AS00 ERROR = ',IER - END IF - PRINT *,'NPARM = ',NPARM - PRINT *,'CPARM = ',CPARM(1:4) - PRINT *,'KWBX = ',KWBX(1:4) -! -! Read GRIB data and index file names from the FORTnn -! environment variables, and open the files. -! - envvar='FORT ' - write(envvar(5:6),fmt='(I2)') lugb - call getenv(envvar,fileb) - write(envvar(5:6),fmt='(I2)') lugi - call getenv(envvar,filei) - - call baopenr(lugb,fileb,iret1) - if ( iret1 .ne. 0 ) then - write(6,fmt='(" Error opening GRIB file: ",A200)') fileb - write(6,fmt='(" baopenr error = ",I5)') iret1 - stop 10 - endif -! -! Open GRIB index file. If doesn't open, use just the data -! file. -! - call baopenr(lugi,filei,iret2) - if ( iret2 .ne. 0 ) then - lugi=0 - endif - -! -! Read output GRIB bulletin file name from FORTnn -! environment variable, and open file. -! - write(envvar(5:6),fmt='(I2)') lugo - call getenv(envvar,fileo) - call baopenw(lugo,fileo,iret1) - if ( iret1 .ne. 0 ) then - write(6,fmt='(" Error opening GRIB file: ",A200)') fileo - write(6,fmt='(" baopenw error = ",I5)') iret1 - stop 20 - endif - - IRET = 0 - iopt=2 - insize=19 - NBUL = 0 -! -! loop through input control records. -! - nrec = 0 - foreachelement: do - - READ (*,66,iostat=ios) (HEXPDS(J),J=1,12), - & (HEXPDS(J),J=17,20), PUNUM, DESC - 66 FORMAT(3(2X,4Z2.2),3X,4Z2.2,6X,I3,1X,A20) - if ( ios .ne. 0 ) then - write(6,fmt='(" Error reading PDS from input file. iostat = " - * ,i5)') ios - exit - endif - PDS=char(HEXPDS) -! -! exit loop, if no more bulletins in input cards -! - IF ( mova2i(pds(1)) .EQ. 255) exit -! - nrec = nrec + 1 - WRITE(6,FMT='(/,''***********************************'', - & ''********************************************'')') - print *,'Start new record no. = ',nrec - WRITE (6,FMT='('' INPUT PDS, PUNUM'', - & '' & DESC...DESIRED GRIB MAPS LISTED ON FOLLOWING '', - & ''LINES...'',/,4X,3(2X,4z2.2),3X,4z2.2,6X,I3,1X, - & A20)') (HEXPDS(J),J=1,12), - & (HEXPDS(J),J=17,20), PUNUM, DESC - -! -! Read WNO Header associated with this element -! - READ (*,iostat=ios,FMT='(4X,I3,2X,I2,2X,A6,1X,I3,24X,A3)') - & MAPNUM,NBITS, BULHED, DUM, EOML - WRITE (6,FMT='(4X,I3,2X,I2,2X,A6,1X,I3,24X,A3)') - & MAPNUM,NBITS, BULHED, DUM, EOML - if ( ios .ne. 0 ) then - write(6,fmt='(" Error reading PDS from input file. iostat =" - * ,i6)') ios - endif -! -! Set up 25 word PDS array of GRIB field to read -! - JREW = 0 - JGDS = -1 - MPDS = -1 - MPDS(3) = mova2i(PDS(7)) - MPDS(5) = mova2i(PDS(9)) - MPDS(6) = mova2i(PDS(10)) - MPDS(7) = mova2i(PDS(11)) * 256 + mova2i(PDS(12)) - MPDS(14) = mova2i(PDS(19)) - MPDS(15) = mova2i(PDS(20)) -! -! Read and return packed GRIB field -! - CALL GETGBP(LUGB,LUGI,MXSIZ3,JREW,MPDS,JGDS, - & itot,KREW,KPDS,KGDS,GRIB,IRET) - IF (IRET.NE.0) THEN - IF (IRET.LT.96) PRINT *,'GETGB-W3FI63: ERROR = ',IRET - IF (IRET.EQ.96) PRINT *,'GETGB: ERROR READING INDEX FILE' - IF (IRET.EQ.97) PRINT *,'GETGB: ERROR READING GRIB FILE' - IF (IRET.EQ.98) THEN - PRINT *,'GETGB ERROR: NUM. OF DATA POINTS GREATER THAN JF' - END IF - IF (IRET.EQ.99) PRINT *,'GETGB ERROR: REQUEST NOT FOUND' - IF (IRET.GT.99) PRINT *,'GETGB ERROR = ',IRET - cycle - END IF - PRINT *,'RECORD NO. OF GRIB RECORD IN INPUT FILE = ',KREW -! -! COMPARE RECORD (GRIB) TO CONTROL CARD (PDS), THEY SHOULD MATCH -! - PDSL(1:28)=GRIB(9:36) - KEY = 2 - IF (.NOT.IW3PDS(PDSL,PDS,KEY)) THEN - PRINT 2900, nrec,(mova2i(PDSL(j)),j=1,28), - & (mova2i(PDS(j)),j=1,28) -2900 FORMAT ( 1X,I4,' (PDS) IN RECORD DOES NOT MATCH (PDS) IN ', - & 'CONTROL CARD ',/,7(1X,4Z2.2), /,7(1X,4Z2.2)) - cycle - END IF -! -! Print PDS -! - PRINT 2, (mova2i(PDSL(J)),J=1,28) - 2 FORMAT (' PDS = ',7(4Z2.2,1X)) -! -! Construct and print Description of GRIB field -! - CALL W3FP11 (GRIB,PDSL,TITLE,IER) - IF (IER.NE.0) PRINT *,'W3FP11 ERROR = ',IER - PRINT *,TITLE(1:86) -! -! - PRINT *,' Size of GRIB Field = ',ITOT -! -! MAKE Flag Field Separator block -! - call mkfldsep(csep,iopt,insize,itot+lenhead,lenout) -! -! MAKE WMO HEADER -! -! Get system date and time -! call w3utcdat(itime) - CALL MAKWMO (BULHED,KPDS(10),KPDS(11),KWBX,WMOHDR) -! -! write out Separator block, Abbreviated WMO Heading, -! and GRIB field to output file. -! - call wryte(lugo,lenout,csep) - call wryte(lugo,lenhead,WMOHDR) - call wryte(lugo,itot,grib) - nbul=nbul+1 -! - enddo foreachelement -! -!* CLOSING SECTION -! - IF (NBUL .EQ. 0 ) THEN - WRITE (6,FMT='('' SOMETHING WRONG WITH DATA CARDS...'', - & ''NOTHING WAS PROCESSED'')') -! CALL W3TAGE('tocgrib') - stop 19 - ELSE - CALL BACLOSE (LUGB,iret) - CALL BACLOSE (LUGI,iret) - CALL BACLOSE (LUGO,iret) - WRITE (6,FMT='(//,'' ******** RECAP OF THIS EXECUTION '', - & ''********'',/,5X,''READ '',I6,'' INDIVIDUAL IDS'', - & /,5X,''WROTE '',I6,'' BULLETINS OUT FOR TRANSMISSION'', - & //)') nrec, NBUL - ENDIF -! -! TEST TO SEE IF ANY BULLETINS MISSING -! - MBUL = nrec - NBUL - IF (MBUL.NE.0) THEN - PRINT *,'BULLETINS MISSING = ',MBUL -! CALL W3TAGE('tocgrib') - stop 30 - END IF -! -! CALL W3TAGE('tocgrib') - STOP - END