Read_TestHarness_Config Subroutine

public subroutine Read_TestHarness_Config(srcPath, configFname, returnrc)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: srcPath
character(len=*), intent(in) :: configFname
integer, intent(out) :: returnrc

Source Code

  subroutine Read_TestHarness_Config(srcPath, configFname, returnrc)
!
! !ARGUMENTS:
  character(len=*), intent(in)  :: srcPath
  character(len=*), intent(in)  :: configFname
  integer,          intent(out) :: returnrc

! actual arguments through globals
!    har structure

!
! !DESCRIPTION:
! Routine opens the top level config file "test_harness.rc", which specifies the
! test class, the reporting style, and depending on how the ESMF_TESTEXHAUSTIVE
! flag is set, extracts the list of files containing the problem descriptor
! strings.
!
! Upon completion, the routine returns the values to a public record
!       har%configPath              path to configuration files
!       har%topFname                top level configuration filename
!       har%testClass               Problem Descriptor Test Class
!       har%reportType              Output Report type
!       har%numRecords              number of problem descriptor filenames
!       har%rcrd(k)%filename        kth problem descriptor filename
!===============================================================================

  ! local ESMF types
  type(ESMF_Config)      :: localcf

  ! local parameters
  character(THARN_MAXSTR), parameter :: test_class_name   = "test_class:"
  character(THARN_MAXSTR), parameter :: setup_report_name = "setup_report:"
  character(THARN_MAXSTR), parameter :: test_report_name  = "test_report:"


  ! local character strings
  character(THARN_MAXSTR) :: ltag, ltmp
  character(THARN_MAXSTR) :: filename

  ! local integer variables
  integer :: kfile, ncolumns
  integer :: localrc
  integer :: allocRcToTest

  ! local  logical
  logical :: flag = .true.

  ! initialize return code
  returnrc = ESMF_RC_NOT_IMPL
  localrc = ESMF_RC_NOT_IMPL

  ! save config path for summary report
  har%configPath = adjustL(srcPath)

  ! save top level filename for summary report
  har%topFname = adjustL(configFname)

  !-----------------------------------------------------------------------------
  ! create config handle and load the testing harness config file
  !-----------------------------------------------------------------------------
  localcf = ESMF_ConfigCreate(rc=localrc)
  if( ESMF_LogFoundError(localrc, msg="cannot create config object",            &
                            rcToReturn=returnrc) ) return

  !call ESMF_ConfigLoadFile(localcf, trim(adjustL(test_harness_name)),          &
  !         rc=localrc )

  filename = trim(srcPath) // "/" // trim(configFname)
  call ESMF_ConfigLoadFile (localcf, trim(filename), rc=localrc)
  if( ESMF_LogFoundError(localrc, msg="cannot load config file " //             &
      trim(configFname), rcToReturn=returnrc) ) return

  !-----------------------------------------------------------------------------
  ! find and read the test class
  !-----------------------------------------------------------------------------
  call ESMF_ConfigFindLabel(localcf, trim(adjustL(test_class_name)), rc=localrc)
  if( ESMF_LogFoundError(localrc, msg="cannot find config label " //            &
      trim(adjustL(test_class_name)),rcToReturn=returnrc) ) return

  call ESMF_ConfigGetAttribute(localcf, ltmp, rc=localrc )
  har%testClass = trim(adjustL( ltmp ))
  if( ESMF_LogFoundError(localrc, msg="cannot get value for label " //          &
      trim(adjustL(test_class_name)),rcToReturn=returnrc) ) return

  !-----------------------------------------------------------------------------
  ! if the class is not supported, then post an error
  !-----------------------------------------------------------------------------
  if ( trim(adjustL(har%testClass)) /= 'ARRAY'        .and.                    &
       trim(adjustL(har%testClass)) /= 'ARRAYBUNDLE'  .and.                    &
       trim(adjustL(har%testClass)) /= 'FIELD'        .and.                    &
       trim(adjustL(har%testClass)) /= 'FIELDBUNDLE' .and.                     &
       trim(adjustL(har%testClass)) /= 'GRID'   .and.                          &
       trim(adjustL(har%testClass)) /= 'REGRID' ) then
     call ESMF_LogSetError( ESMF_FAILURE,msg="class name not of valid type "//  &
          trim(adjustL(har%testClass)), rcToReturn=returnrc)
     return
  endif

  !-----------------------------------------------------------------------------
  ! determine type of test report and toggle setup report
  !-----------------------------------------------------------------------------

  call ESMF_ConfigFindLabel(localcf,trim(adjustL(setup_report_name)),rc=localrc)
  if( ESMF_LogFoundError(localrc,msg="cannot find config label " //             &
      trim(adjustL(setup_report_name)), rcToReturn=returnrc) ) return

  call ESMF_ConfigGetAttribute(localcf, ltmp, rc=localrc)
  har%setupReportType = trim(adjustL( ltmp ))
  if( ESMF_LogFoundError(localrc,  msg="cannot get value for label " //         &
      trim(adjustL(setup_report_name)), rcToReturn=returnrc) ) return

  if((har%setupReportType /= "TRUE").and.(har%setupReportType /= "FALSE")) then
     call ESMF_LogSetError( ESMF_FAILURE, msg="setup report flag " //           &
          "improperly set " // trim(har%setupReportType), rcToReturn=returnrc)
     return
  endif

  !-----------------------------------------------------------------------------
  ! read test report flag
  ! test_report: FULL  - full report presenting both success and failure configs
  ! test_report: FAILURE - report only failure configurations
  ! test_report: SUCCESS - report only successful configurations
  ! test_report: NONE - no report
  !-----------------------------------------------------------------------------
  call ESMF_ConfigFindLabel(localcf,trim(adjustL(test_report_name)),rc=localrc )
  if( ESMF_LogFoundError(localrc, msg="cannot find config label " //            &
      trim(adjustL(test_report_name)), rcToReturn=returnrc) ) return

  call ESMF_ConfigGetAttribute(localcf, ltmp, rc=localrc )
  har%reportType = trim(adjustL( ltmp ))
  if( ESMF_LogFoundError(localrc, msg="cannot get value for label " //          &
      trim(adjustL(test_report_name)), rcToReturn=returnrc) ) return

  if ( har%reportType /= "FULL" .and. har%reportType /= "FAILURE" .and.        &
       har%reportType /= "SUCCESS" .and. har%reportType /= "NONE" ) then
     call ESMF_LogSetError( ESMF_FAILURE, msg="report flag improperly set" //   &
          trim(har%reportType), rcToReturn=returnrc)
     return
  endif

  !-----------------------------------------------------------------------------
  ! based on whether exhaustive or nonexhaustive tests are to be run,  find
  ! and load the problem descriptor file names
  !-----------------------------------------------------------------------------
!#ifdef ESMF_TESTEXHAUSTIVE
! ltag = 'exhaustive::'
! if(localPet == rootPet)  print *, "running exhaustive tests"
!#else
  ltag = 'nonexhaustive::'
  if(localPet == rootPet)  print *, "running nonexhaustive tests"
!#endif
  call ESMF_ConfigFindLabel(localcf, trim(adjustL(ltag)), rc=localrc )
  if( ESMF_LogFoundError(localrc, msg="cannot find config label " //            &
      trim(adjustL(ltag)), rcToReturn=returnrc) ) return

  ! determine the number of entries
  call ESMF_ConfigGetDim(localcf, har%numRecords, ncolumns,                    &
       label=trim(adjustL(ltag)), rc=localrc)
  if( ESMF_LogFoundError(localrc, msg="cannot find the size of the table " //   &
      trim(adjustL(ltag)), rcToReturn=returnrc) ) return

  ! if there are no entries post an error
  if ( har%numRecords .le. 0 ) then
     call ESMF_LogSetError( ESMF_FAILURE, msg="no problem descriptor files "//  &
          "specified", rcToReturn=returnrc)
     return
  endif

  !-----------------------------------------------------------------------------
  ! find the problem descriptor file names and read them
  !-----------------------------------------------------------------------------
  call ESMF_ConfigFindLabel(localcf, trim(adjustL(ltag)), rc=localrc)
  if( ESMF_LogFoundError(localrc, msg="cannot find table label of " //          &
      trim(adjustL(ltag)), rcToReturn=returnrc) ) return

  !-----------------------------------------------------------------------------
  ! allocate space to hold problem descriptor filenames and advance through the
  ! table extracting the problem descriptor filenames
  !-----------------------------------------------------------------------------
  allocate( har%rcrd(har%numRecords), stat=allocRcToTest )
  if (ESMF_LogFoundAllocError(allocRcToTest, msg="rcrd type "//                 &
     " in Read_TestHarness_Config", rcToReturn=returnrc)) then
  endif


  do kfile=1,har%numRecords
     ! advance to new line in table
     call ESMF_ConfigNextLine(localcf, tableEnd=flag, rc=localrc)
     if( ESMF_LogFoundError(localrc, msg="cannot advance to next line of " //   &
         "table " // trim(adjustL(ltag)), rcToReturn=returnrc) ) return

     ! retrieve the problem descriptor filenames
     call ESMF_ConfigGetAttribute(localcf, ltmp, rc=localrc)
     if( ESMF_LogFoundError(localrc, msg="cannot get descriptor filename in "// &
         trim(adjustL(ltag)), rcToReturn=returnrc) ) return

     filename = trim(srcPath) // "/" // trim(adjustL(ltmp))
     har%rcrd(kfile)%filename  = trim(filename)
  enddo   ! file

  !-----------------------------------------------------------------------------
  ! clean up CF
  !-----------------------------------------------------------------------------
  call ESMF_ConfigDestroy(localcf, rc=localrc)
  if( ESMF_LogFoundError(localrc, msg="cannot destroy config file " //          &
      trim(configFname), rcToReturn=returnrc) ) return

  ! if I've gotten this far without an error, then the routine has succeeded.
  returnrc = ESMF_SUCCESS

!===============================================================================
  end subroutine Read_TestHarness_Config