﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
680	Fix non-reproducible problem with -g or -gi options in ropp2bufr and eum2bufr	Ian Culverwell	Ian Culverwell	"The user can request GTS routing headers/trailers to be added to the BUFR file output from '''ropp2bufr''' and '''eum2bufr''' by using the {{{-g}}} or {{{-gi}}} options. ({{{-gi}}} adds a 10-byte leading size/type for GTS IP (FTP) transmission to the headers produced by {{{-g}}}.)

But this doesn't always work.  This is because subroutine {{{GetOptions}}} in '''ropp2bufr_mod.f90''' sets {{{RejTimeDiff = DefRejTimeDiff = 1430}}} if {{{-g}}} or {{{-gi}}} are invoked:
{{{
  IF ( GTShdrType /= NOhdrs .AND. &
       RejTimeDiff == 0 ) RejTimeDiff = DefRejTimeDiff
}}}

This can then cause the code to fall over in '''ropp2bufr_ec/mo.f90''' because
{{{
  IF ( RejTimeDiff > 0 ) THEN
    Offset = (/0,0,0,0,0,RejTimeDiff,0,0/)
    CALL DateTimeOffset ( DT8, ""-"", Offset )
    CALL TimeSince      ( DT8, MinRej, 1, Base=""JM2000"" )
    CALL MonthOfYear    ( DT8(IdxMonth), MonthName, 1 )
    WRITE ( outmsg, FMT=DTfmt1 ) DT8(IdxHour),   &
                                 DT8(IdxMinute), &
                                 DT8(IdxDay),    &
                                 MonthName(1:3), &
                                 DT8(IdxYear)
    CALL message ( msg_diag, "" Rejecting occultations older than ""// &
                             TRIM(outmsg) )
  ELSE
    MinRej = 0.0_dp
  END IF

...

      IF ( MinRej > 0.5_dp ) THEN
        DT8 = (/ROdata%DTocc%Year,   ROdata%DTocc%Month,  &
                ROdata%DTocc%Day,    0,                   &
                ROdata%DTocc%Hour,   ROdata%DTocc%Minute, &
                ROdata%DTocc%Second, 0/)
        CALL TimeSince ( DT8, MinObs, 1, Base=""JM2000"" )
        IF ( MinObs < MinRej ) THEN
          CALL message ( msg_warn, ""Occultation is too old for GTS ""// &
                                   ""- not encoded."" )
          CYCLE
        END IF
      END IF
}}}

The point is that {{{DT8}}} is not initialised before it is called by
{{{
    CALL DateTimeOffset ( DT8, ""-"", Offset )
}}}

We can therefore end up with {{{MinRej}}} failing the {{{IF ( MinRej > 0.5_dp ) THEN}}} test, so that the code fails with, for example:
{{{
 3: DT8 =  80147 7 19 0 23 49 0 1
 3: MinRej =  4.1101640629000015E+10
... (from ropp2bufr):   Rejecting occultations older than 23:49UT 19-Jul-****
INFO (from ropp2bufr):  Reading  ROPP data from ../data/ropp_test.nc
INFO (from ropp2bufr):  Encoding profile    1 : OC_20090817215807_META_G027_DMI_
 7.1: MinRej =  4.1101640629000015E+10
 7.1: MinObs =  5064358.1166666
 
WARNING (from ropp2bufr):  Occultation is too old for GTS - not encoded.
 
WARNING (from ropp2bufr):  No profiles were encoded or written to the BUFR file

*** Failed to generate a BUFR file from netCDF
}}}

Sometimes, however, it works, e.g.:
{{{
  3: DT8 =  -29499 -4 -29 0 -22 -57 -59 -999
 3: MinRej =  -1.6567136577999983E+10
... (from ropp2bufr):   Rejecting occultations older than **:**UT **-Apr-****
INFO (from ropp2bufr):  Reading  ROPP data from ../data/ropp_test.nc
INFO (from ropp2bufr):  Encoding profile    1 : OC_20090817215807_META_G027_DMI_
 7.1: MinRej =  -1.6567136577999983E+10
...
... (from EncodeBUFR):     Length of BUFR message :  14741 octets
DEBUG: [GTShdrARH] Lat=51 Lon=-4 A2=A
... (from EncodeBUFR):     Length of GTS bulletin :  14776 octets
... (from EncodeBUFR):   GTS bulletin header (IPH+ARH): 0001477600....001...IUTA14 EKMI 172158...
... (from EncodeBUFR):   No. of bytes written to file : 14786
... (from ropp2bufr):  Writing      8 bytes (for EOF) to bufr_test.bfr
INFO (from ropp2bufr):  Total of  14794 bytes written to bufr_test.bfr
INFO (from ropp2bufr):  Generated 1 GTS bulletin to bufr_test.bfr
}}}

It all depends how {{{DT8}}} is initialised.

A quick fix would be to switch off the setting of {{{RejTimeDiff > 0}}}  if {{{GTShdrType /= NOhdrs}}}.  A better fix would be to find out what {{{DT8}}} is supposed to be, and to set it accordingly.
"	task	closed	normal	11.0	ROPP(all)	9.0	fixed		olewis
