Skip to content

Commit

Permalink
Separately count missing fields without a time dimension
Browse files Browse the repository at this point in the history
For files with an unlimited (time) dimension, provide two separate
counts:

(1) The number of missing fields with an unlimited (time) dimension

(2) The number of missing fields without an unlimited (time) dimension

Only (1) is considered in determining whether to report a final
difference in the field lists.

Resolves ESMCI/cime#3007
  • Loading branch information
billsacks committed Mar 22, 2019
1 parent c916a1e commit 7c9e51c
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 8 deletions.
96 changes: 93 additions & 3 deletions tools/cprnc/cprnc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@ program piocprnc
type(dim_t) :: dimoptions(12)
integer :: dimoptioncnt
integer :: nvars, ndiffs, nfilldiffs

! The following variables count the number of fields found on one file but not the
! other, only considering (a) fields with an unlimited (time) dimension, and (b) fields
! without an unlimited (time) dimension on a file that doesn't have an unlimited
! dimension.
integer :: num_not_found_on_file1, num_not_found_on_file2

! The following variables count the number of fields found on one file but not the
! other, only considering fields without an unlimited (time) dimension on a file that
! has an unlimited dimension.
integer :: num_not_found_on_file1_timeconst, num_not_found_on_file2_timeconst

integer :: num_sizes_differ
integer :: num_not_analyzed

Expand Down Expand Up @@ -90,8 +101,13 @@ program piocprnc

num_not_found_on_file1 = 0
num_not_found_on_file2 = 0
num_not_found_on_file1_timeconst = 0
num_not_found_on_file2_timeconst = 0
call match_vars( file(1), file(2), &
num_not_found_on_file1, num_not_found_on_file2)
num_not_found_on_file1 = num_not_found_on_file1, &
num_not_found_on_file2 = num_not_found_on_file2, &
num_not_found_on_file1_timeconst = num_not_found_on_file1_timeconst, &
num_not_found_on_file2_timeconst = num_not_found_on_file2_timeconst)
end if
call compare_vars(numcases, file, nvars, ndiffs, nfilldiffs, &
num_sizes_differ, num_not_analyzed)
Expand All @@ -114,15 +130,42 @@ program piocprnc
write(6,700) ' and ',num_sizes_differ,' had different dimension sizes'
write(6,700) ' A total number of ',num_sizes_differ + num_not_analyzed, &
' fields could not be analyzed'
write(6,700) ' A total number of ',num_not_found_on_file2,' fields on file 1 were not found on file 2.'
write(6,700) ' A total number of ',num_not_found_on_file1,' fields on file 2 were not found on file 1.'

call print_fields_not_found( &
filenum = 1, &
file_has_unlimited_dim = file(1)%has_unlimited_dim(), &
num_not_found = num_not_found_on_file2, &
num_not_found_timeconst = num_not_found_on_file2_timeconst)

call print_fields_not_found( &
filenum = 2, &
file_has_unlimited_dim = file(2)%has_unlimited_dim(), &
num_not_found = num_not_found_on_file1, &
num_not_found_timeconst = num_not_found_on_file1_timeconst)

if (nvars == 0 .or. ndiffs > 0 .or. nfilldiffs > 0 .or. &
num_sizes_differ > 0 .or. num_not_analyzed >= nvars) then
write(6,700) ' diff_test: the two files seem to be DIFFERENT '
else if (num_not_found_on_file1 > 0 .or. num_not_found_on_file2 > 0) then
! Note that we deliberately allow num_not_found_on_file1_timeconst or
! num_not_found_on_file2_timeconst to be > 0: those do NOT result in a
! "DIFFER" result.
!
! Ideally, we'd count those fields here, too. Doing so would catch more
! differences and would simplify the cprnc code. But this sometimes leads to
! problems when comparing restart vs. baseline files
! (https://github.com/ESMCI/cime/issues/3007). We could add a flag that you
! specify to not count these fields, but there are backwards compatibility
! issues with doing so. Eventually it could be good to count these absent
! fields as a DIFFER result, adding a flag that you can specify to not count
! them, then have cime specify this flag when doing the in-test comparison.
write(6,'(a)') ' diff_test: the two files DIFFER only in their field lists'
else
write(6,700) ' diff_test: the two files seem to be IDENTICAL '
if (num_not_found_on_file1_timeconst > 0 .or. &
num_not_found_on_file2_timeconst > 0) then
write(6,'(a)') ' (But note that there were differences in field lists just for time-constant fields.)'
end if
end if
end if
write(6,*) ' '
Expand Down Expand Up @@ -213,4 +256,51 @@ subroutine parsearg (arg, dimname, v1, v2)
return
end subroutine parsearg

subroutine print_fields_not_found(filenum, file_has_unlimited_dim, &
num_not_found, num_not_found_timeconst)
! Prints information about the number of fields in filenum not found on the other file

integer, intent(in) :: filenum ! file number for which we're printing this information
logical, intent(in) :: file_has_unlimited_dim ! whether this file has an unlimited dimension

! Number of fields in filenum but not on the other file, only considering (a) fields
! with an unlimited (time) dimension, and (b) fields without an unlimited (time)
! dimension on a file that doesn't have an unlimited dimension
integer, intent(in) :: num_not_found

! Number of fields in filenum but not on the other file, only considering fields
! without an unlimited (time) dimension on a file that has an unlimited dimension
integer, intent(in) :: num_not_found_timeconst

integer :: other_filenum

if (filenum == 1) then
other_filenum = 2
else if (filenum == 2) then
other_filenum = 1
else
stop 'Unexpected value for filenum'
end if

if (file_has_unlimited_dim) then
write(6,'(a,i6,a,i1,a,i1,a)') &
' A total number of ', num_not_found, &
' time-varying fields on file ', filenum, &
' were not found on file ', other_filenum, '.'
write(6,'(a,i6,a,i1,a,i1,a)') &
' A total number of ', num_not_found_timeconst, &
' time-constant fields on file ', filenum, &
' were not found on file ', other_filenum, '.'
else
write(6,'(a,i6,a,i1,a,i1,a)') &
' A total number of ', num_not_found, &
' fields on file ', filenum, &
' were not found on file ', other_filenum, '.'
if (num_not_found_timeconst > 0) then
stop 'Programming error: file has no unlimited dimension, but num_not_found_timeconst > 0'
end if
end if

end subroutine print_fields_not_found

end program piocprnc
35 changes: 30 additions & 5 deletions tools/cprnc/filestruct.F90
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,30 @@ end subroutine compare_dimensions


subroutine match_vars( file1, file2, &
num_not_found_on_file1, num_not_found_on_file2 )
num_not_found_on_file1, num_not_found_on_file2, &
num_not_found_on_file1_timeconst, num_not_found_on_file2_timeconst)
type(file_t), intent(inout) :: file1, file2

! Accumulates count of variables on file2 not found on file1
! Accumulates count of variables on file2 not found on file1; this only considers (a)
! fields with an unlimited (time) dimension, and (b) fields without an unlimited
! (time) dimension on a file that doesn't have an unlimited dimension.
integer, intent(inout) :: num_not_found_on_file1

! Accumulates count of variables on file1 not found on file2
! Accumulates count of variables on file1 not found on file2; this only considers (a)
! fields with an unlimited (time) dimension, and (b) fields without an unlimited
! (time) dimension on a file that doesn't have an unlimited dimension.
integer, intent(inout) :: num_not_found_on_file2

! Accumulates count of variables on file2 not found on file1; this only considers
! fields without an unlimited (time) dimension on a file that has an unlimited
! dimension.
integer, intent(inout) :: num_not_found_on_file1_timeconst

! Accumulates count of variables on file1 not found on file2; this only considers
! fields without an unlimited (time) dimension on a file that has an unlimited
! dimension.
integer, intent(inout) :: num_not_found_on_file2_timeconst

type(var_t), pointer :: varfile1(:),varfile2(:)

integer :: vs1, vs2, i, j
Expand All @@ -299,13 +314,23 @@ subroutine match_vars( file1, file2, &
do i=1,vs1
if(varfile1(i)%matchid<0) then
print *, 'Could not find match for file1 variable ',trim(varfile1(i)%name), ' in file2'
num_not_found_on_file2 = num_not_found_on_file2 + 1
if (file1%has_unlimited_dim() .and. &
.not. is_time_varying(varfile1(i), file1%has_unlimited_dim(), file1%unlimdimid)) then
num_not_found_on_file2_timeconst = num_not_found_on_file2_timeconst + 1
else
num_not_found_on_file2 = num_not_found_on_file2 + 1
end if
end if
end do
do i=1,vs2
if(varfile2(i)%matchid<0) then
print *, 'Could not find match for file2 variable ',trim(varfile2(i)%name), ' in file1'
num_not_found_on_file1 = num_not_found_on_file1 + 1
if (file2%has_unlimited_dim() .and. &
.not. is_time_varying(varfile2(i), file2%has_unlimited_dim(), file2%unlimdimid)) then
num_not_found_on_file1_timeconst = num_not_found_on_file1_timeconst + 1
else
num_not_found_on_file1 = num_not_found_on_file1 + 1
end if
end if
end do
end subroutine match_vars
Expand Down

0 comments on commit 7c9e51c

Please sign in to comment.