build_surf Subroutine

private subroutine build_surf(surf, tab)

Creates an object OBJ_SURF from an array

Arguments

Type IntentOptional Attributes Name
type(OBJ_SURF), intent(inout) :: surf

resulting object OBJ_SURF

real(kind=R8), intent(in), dimension(1:surf%xres, 1:surf%yres) :: tab

Calls

proc~~build_surf~~CallsGraph proc~build_surf build_surf proc~unit2iuc unit2IUc proc~build_surf->proc~unit2iuc proc~unit2iuf unit2IUf proc~unit2iuc->proc~unit2iuf

Called by

proc~~build_surf~~CalledByGraph proc~build_surf build_surf proc~write_surf write_surf proc~write_surf->proc~build_surf program~test_surfile test_surfile program~test_surfile->proc~write_surf

Source Code

   subroutine build_surf(surf, tab)
   !! Creates an object [[OBJ_SURF]] from an array
   implicit none
   type(OBJ_SURF), intent(inout) :: surf  !! *resulting object ```OBJ_SURF```*
   real(kind=R8), dimension(1:surf%xres, 1:surf%yres), intent(in) :: tab

      integer(kind=I4)   :: i, j, k, nx, ny
      real(kind=R8)      :: max_n, min_t, max_t, mil_t, amp_t, unit_x, unit_y, unit_z

      nx = surf%xres
      ny = surf%yres

      surf%nofpoints = nx*ny

      unit_x = unit2IUc(surf%dx_unit)
      unit_y = unit2IUc(surf%dy_unit)
      unit_z = unit2IUc(surf%dz_unit)

      if (allocated(surf%val)) deallocate(surf%val)
      allocate(surf%val(1:surf%nofpoints))

      min_t = minval( tab(1:nx, 1:ny) )/unit_z
      max_t = maxval( tab(1:nx, 1:ny) )/unit_z

      mil_t = 0.5_R8*(min_t +max_t) ! middle of the range
      amp_t = max_t -min_t          ! range amplitude

      surf%ZOffset = mil_t

      max_n = 0.5*huge(1)     ! the heights are integers, allowed to span
                              ! half the positive integer range.
      surf%dz = amp_t/max_n   ! subsequent dz

      k = 0
      do j = 1, ny
      do i = 1, nx
         k = k +1
         surf%val(k) = nint( (tab(i, j)/unit_z -surf%ZOffset)/surf%dz ) !
      enddo
      enddo
      surf%zmin = minval(surf%val)
      surf%zmax = maxval(surf%val)

   return
   endsubroutine build_surf