Creates an object OBJ_SURF from an array
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(OBJ_SURF), | intent(inout) | :: | surf |
resulting object |
||
real(kind=R8), | intent(in), | dimension(1:surf%xres, 1:surf%yres) | :: | tab |
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