! $Id: ropp_apps_compare.f90 2197 2009-06-23 09:11:17Z idculv $ PROGRAM ropp_apps_compare !****p* Programs/ropp_apps_compare * ! ! NAME ! ropp_apps_compare - Compares two ROPP nc files for meaningful differences. ! ! SYNOPSIS ! ropp_apps_compare file1.nc file2.nc ['test_name'] ['comments'] ! ! DESCRIPTION ! Compares two ROPP nc files. ! Used by test scripts to compare output. ! ! INPUTS ! ROPP netcdf files file1.nc and file2.nc. ! ! OUTPUT ! Checks whether the elements of the ROPP files are 'similar'. ! Writes (to stdout and a summary file) an overall PASS/FAIL ! ! NOTES ! The various thresholds for defining differences as significant ! are subject to change, depending on experience with this routine. ! ! SEE ALSO ! ropp_io/ropp/ropp_io_fields_compare.f90 ! ! AUTHOR ! Met Office, Exeter, UK. ! Any comments on this software should be given via the ROM SAF ! Helpdesk at http://www.romsaf.org ! ! COPYRIGHT ! (c) EUMETSAT. All rights reserved. ! For further details please refer to the file COPYRIGHT ! which you should have received as part of this distribution. ! !**** USE messages USE ropp_io_types, ONLY: ROprof USE ropp_io, ONLY: ropp_io_read, ropp_io_nrec USE ropp_io_test IMPLICIT NONE ! Input variables CHARACTER(LEN=256) :: file_in1, file_in2 ! I/P file names CHARACTER(LEN=256) :: test_name='' ! Name of test CHARACTER(LEN=256) :: comment='' ! Optional comments ! Local variables TYPE(ROprof) :: prof1 ! RO profile from file1.nc TYPE(ROprof) :: prof2 ! RO profile from file2.nc INTEGER :: narg ! No. of command line arguments INTEGER :: i_prof ! Profile loop counter INTEGER :: n_prof1, n_prof2 ! No. of profiles, profile loop counter CHARACTER(LEN=4) :: sprof, snprof ! STRING(profile counters, no. profs) INTEGER :: iostatus ! I/O status INTEGER :: idiff, idiff_old ! Difference counters CHARACTER(LEN=4) :: sdiff ! STRING(difference counter) LOGICAL :: exists ! File exists flag LOGICAL :: bg, GEOref, & ! The substructures of Lev1a, Lev1b, & ! ROprof to be compared Lev2a, Lev2b, & Lev2c, Lev2d LOGICAL :: spectra_local=.FALSE. ! True for spectra test LOGICAL :: tdry_local=.FALSE. ! Relax tdry tolerances for occ and rs tests INTEGER :: i ! Loop counter CHARACTER(LEN=256) :: com ! Loop comment ! Some compilers may need the following declaration to be commented out INTEGER :: IARGC ! ------------------------------------------------------------------------------ ! 0. Set routine for error messages ! ------------------------------------------------------------------------------ CALL message_set_routine('ropp_apps_compare') CALL message(msg_noin, '') CALL message(msg_noin, & '----------------------------------------------------------------------') CALL message(msg_noin, & ' ROPP APPS File Comparison Tool ') CALL message(msg_noin, & '----------------------------------------------------------------------') CALL message(msg_noin, '') msg_MODE = NormalMode ! msg_MODE = VerboseMode ! Uncomment this to allow diagnostic messages ! ------------------------------------------------------------------------------ ! 1. Read data ! ------------------------------------------------------------------------------ ! 1.1 Read instructions ! --------------------- narg = IARGC() IF (narg < 2) THEN CALL ropp_io_success(.FALSE., test_name, comment) CALL message ( msg_fatal, 'ropp_apps_compare needs at least two arguments' ) ENDIF file_in1 = ' ' ! no default for 1st input file name CALL GETARG ( 1, file_in1 ) file_in2 = ' ' ! no default for 2nd input file name CALL GETARG ( 2, file_in2 ) IF (narg >= 3) CALL GETARG ( 3, test_name ) IF (narg >= 4) THEN ! Allow comments with spaces DO i=4,narg CALL GETARG ( i, com ) comment = TRIM(ADJUSTL(comment)) // ' ' // TRIM(ADJUSTL(com)) ENDDO ENDIF CALL message ( msg_info, 'Comparing ' // & TRIM(ADJUSTL(file_in1)) // ' and ' // & TRIM(ADJUSTL(file_in2)) // ': ' ) CALL message ( msg_cont, 'the results of running test ' // & TRIM(ADJUSTL(test_name)) // & ' (' // TRIM(ADJUSTL(comment)) // ')' ) ! 1.2 Specify the ROprof substructures that are to be compared ! ------------------------------------------------------------ SELECT CASE (test_name) CASE ('t_apps_tph_1', 't_apps_pblh_1') bg = .FALSE. ; GEOref = .FALSE. Lev1a = .FALSE. ; Lev1b = .FALSE. Lev2a = .FALSE. ; Lev2b = .FALSE. Lev2c = .TRUE. ; Lev2d = .FALSE. CASE DEFAULT bg = .FALSE. ; GEOref = .FALSE. Lev1a = .FALSE. ; Lev1b = .FALSE. Lev2a = .FALSE. ; Lev2b = .FALSE. Lev2c = .FALSE. ; Lev2d = .FALSE. END SELECT ! 1.3 Read number of profiles from 1st file ! ----------------------------------------- INQUIRE ( FILE=file_in1, EXIST=exists ) IF ( .NOT. exists ) THEN CALL ropp_io_success(.FALSE., test_name, comment) CALL message ( msg_fatal, 'Input netCDF file ' // TRIM(ADJUSTL(file_in1)) // ' not found' ) ENDIF n_prof1 = ropp_io_nrec(file_in1) ! 1.4 Read number of profiles from 2nd file ! ----------------------------------------- INQUIRE ( FILE=file_in2, EXIST=exists ) IF ( .NOT. exists ) THEN CALL ropp_io_success(.FALSE., test_name, comment) CALL message ( msg_error, 'Input netCDF file ' // TRIM(ADJUSTL(file_in2)) // ' not found' ) ENDIF n_prof2 = ropp_io_nrec(file_in2) IF ( n_prof1 /= n_prof2 ) & CALL message( msg_fatal, 'Different number of profiles in ' // & TRIM(ADJUSTL(file_in1)) // ' and ' // & TRIM(ADJUSTL(file_in2)) ) ! 1.5 Start looping over profiles ! ------------------------------- idiff = 0 ! Initialise difference counter WRITE ( snprof, FMT='(I4)' ) n_prof1 CALL message ( msg_diag, 'Both files contain ' // & TRIM(ADJUSTL(snprof)) // ' profile(s)' ) profs: DO i_prof=1,n_prof1 WRITE ( sprof, FMT='(I4)' ) i_prof ! 1.6 Read profiles from 1st file ! ------------------------------- CALL ropp_io_read ( prof1, FILE=file_in1, REC=i_prof, IERR=iostatus) IF ( iostatus > 0 ) THEN CALL ropp_io_success(.FALSE., test_name, comment) CALL message ( msg_fatal, 'I/O error while reading profile ' // sprof // & ' from file ' //file_in1 ) ENDIF ! 1.7 Read profiles from 2nd file ! ------------------------------- CALL ropp_io_read ( prof2, FILE=file_in2, REC=i_prof, IERR=iostatus ) IF ( iostatus > 0 ) THEN CALL ropp_io_success(.FALSE., test_name, comment) CALL message ( msg_fatal, 'I/O error while reading profile ' // sprof // & ' from file ' //file_in2 ) ENDIF ! 1.8 Compare the profiles ! ------------------------ idiff_old = idiff CALL ropp_io_fields_compare(prof1, prof2, idiff, sprof, & bg, GEOref, Lev1a, Lev1b, Lev2a, Lev2b, Lev2c, Lev2d, & spectra=spectra_local, tdry=tdry_local) IF ( idiff > idiff_old ) & CALL message ( msg_info, 'Differences occurred in profile ' // & TRIM(ADJUSTL(sprof)) ) END DO profs ! ------------------------------------------------------------------------------ ! 3. Summarise the differences ! ------------------------------------------------------------------------------ IF (idiff > 0) THEN WRITE (sdiff, FMT='(I4)') idiff CALL message ( msg_info, TRIM(ADJUSTL(sdiff)) // ' elements of ' // & TRIM(ADJUSTL(file_in1)) // ' and ' // & TRIM(ADJUSTL(file_in2)) // ' differ significantly' ) CALL ropp_io_success(.FALSE., test_name, comment) ELSE CALL message ( msg_diag, 'No significant differences between ' // & TRIM(ADJUSTL(file_in1)) // ' and ' // & TRIM(ADJUSTL(file_in2)) ) CALL ropp_io_success(.TRUE., test_name, comment) ENDIF END PROGRAM ropp_apps_compare