[Dart-dev] DART/branches Revision: 12380
dart at ucar.edu
dart at ucar.edu
Thu Jan 25 17:02:06 MST 2018
nancy at ucar.edu
2018-01-25 17:02:05 -0700 (Thu, 25 Jan 2018)
85
removed some debug statements, moved the array_dump code
into the utilities module.
Modified: DART/branches/recam/assimilation_code/modules/utilities/utilities_mod.f90
===================================================================
--- DART/branches/recam/assimilation_code/modules/utilities/utilities_mod.f90 2018-01-25 22:35:21 UTC (rev 12379)
+++ DART/branches/recam/assimilation_code/modules/utilities/utilities_mod.f90 2018-01-26 00:02:05 UTC (rev 12380)
@@ -203,7 +203,8 @@
scalar, &
string_to_real, &
string_to_integer, &
- string_to_logical
+ string_to_logical, &
+ array_dump
! this routine is either in the null_mpi_utilities_mod.f90, or in
! the mpi_utilities_mod.f90 file, but it is not a module subroutine.
@@ -227,6 +228,12 @@
module procedure to_scalar_int8
end interface
+interface array_dump
+ module procedure array_1d_dump
+ module procedure array_2d_dump
+ module procedure array_3d_dump
+end interface
+
! version controlled file description for error handling, do not edit
character(len=256), parameter :: source = &
"$URL$"
@@ -2314,7 +2321,144 @@
end function string_to_logical
+!-----------------------------------------------------------------------
+!> dump the contents of a 1d array with a max of N items per line.
+!> optional arguments allow the caller to restrict the output to
+!> no more than X items, to write to an open file unit, and to
+!> write a text label before the numerical dump.
+!>
+subroutine array_1d_dump(array, nper_line, max_items, funit, label)
+real(r8), intent(in) :: array(:)
+integer, intent(in), optional :: nper_line
+integer, intent(in), optional :: max_items
+integer, intent(in), optional :: funit
+character(len=*), intent(in), optional :: label
+
+integer :: i, per_line, ounit, asize_i
+logical :: has_label
+
+! set defaults and override if arguments are present
+
+per_line = 4
+if (present(nper_line)) per_line = nper_line
+
+asize_i = size(array)
+if (present(max_items)) asize_i = min(asize_i, max_items)
+
+ounit = 0
+if (present(funit)) ounit = funit
+
+has_label = .false.
+if (present(label)) has_label = .true.
+
+! output section
+
+if (has_label) write(ounit, *) trim(label)
+
+do i=1, asize_i, per_line
+ write(ounit, *) i, ' : ', array(i:min(asize_i,i+per_line-1))
+enddo
+
+end subroutine array_1d_dump
+
+!-----------------------------------------------------------------------
+!> dump the contents of a 2d array with a max of N items per line.
+!> optional arguments allow the caller to restrict the output to
+!> no more than X items, to write to an open file unit, and to
+!> write a text label before the numerical dump.
+!>
+
+subroutine array_2d_dump(array, nper_line, max_i_items, max_j_items, funit, label)
+real(r8), intent(in) :: array(:,:)
+integer, intent(in), optional :: nper_line
+integer, intent(in), optional :: max_i_items
+integer, intent(in), optional :: max_j_items
+integer, intent(in), optional :: funit
+character(len=*), intent(in), optional :: label
+
+integer :: i, j, per_line, ounit, asize_i, asize_j
+logical :: has_label
+
+! set defaults and override if arguments are present
+
+per_line = 4
+if (present(nper_line)) per_line = nper_line
+
+asize_i = size(array, 1)
+asize_j = size(array, 2)
+if (present(max_i_items)) asize_i = min(asize_i, max_i_items)
+if (present(max_j_items)) asize_j = min(asize_j, max_j_items)
+
+ounit = 0
More information about the Dart-dev
mailing list