module model_info
  implicit none
  real(8), save :: dx=0.0D0, dy=0.0D0, dz=0.0D0
  integer, parameter :: plb1=0, plb2=0, plb3=0 !物理空間下限
  integer, save :: pub1, pub2, pub3 !物理空間上限
  integer, save :: margin_1, margin_2, margin_3 !のりしろ
  integer, save :: lb_axis1=1, lb_axis2=1, lb_axis3=1 !実際の配列の下限
  integer, save :: ub_axis1=1, ub_axis2=1, ub_axis3=1 !実際の配列の上限
  real(8), save :: x_minimum=0.0D0
  real(8), save :: y_minimum=0.0D0
  real(8), save :: z_minimum=0.0D0
  

contains
  subroutine set_grid_num_x( pub1_in )
    integer, intent(in) :: pub1_in

    pub1 = pub1_in

  end subroutine set_grid_num_x
  
  subroutine set_grid_num_y( pub2_in )
    integer, intent(in) :: pub2_in

    pub2 = pub2_in

  end subroutine set_grid_num_y

  subroutine set_grid_num_z( pub3_in )
    integer, intent(in) :: pub3_in

    pub3 = pub3_in

  end subroutine set_grid_num_z


!-----------------------
!  SET margin
!
! 計算上必要なのりしろの幅を指定する。
! たとえば2階微分の計算にはのりしろが2つは必要でしょう。
!--
  subroutine set_margin_x(margin_1_in)
    integer, intent(in) :: margin_1_in

    margin_1 = margin_1_in

       lb_axis1 = plb1 - margin_1
       ub_axis1 = pub1 + margin_1

  end subroutine set_margin_x

  subroutine set_margin_y(margin_2_in)
    integer, intent(in) :: margin_2_in

    margin_2 = margin_2_in

       lb_axis2 = plb2 - margin_2
       ub_axis2 = pub2 + margin_2

  end subroutine set_margin_y

  subroutine set_margin_z(margin_3_in)
    integer, intent(in) :: margin_3_in

    margin_3 = margin_3_in
       
       lb_axis3 = plb3 - margin_3
       ub_axis3 = pub3 + margin_3

  end subroutine set_margin_z

!--
!  SET grid interval "dx, dy, dz"
!--
  subroutine gms_set_interval_x(dx_in)
    real(8), intent(in) :: dx_in

    dx = dx_in

  end subroutine gms_set_interval_x

  subroutine gms_set_interval_y(dy_in)
    real(8), intent(in) :: dy_in

    dy = dy_in

  end subroutine gms_set_interval_y

  subroutine gms_set_interval_z(dz_in)
    real(8), intent(in) :: dz_in

    dz = dz_in

  end subroutine gms_set_interval_z

!----------------------------
!
! 実空間での座標最小値の設定

  subroutine  set_real_min_x(xmin_in)
    real(8), intent(in) :: xmin_in

    x_minimum = xmin_in

  end subroutine set_real_min_x

  subroutine  set_real_min_y(ymin_in)
    real(8), intent(in) :: ymin_in

    y_minimum = ymin_in

  end subroutine set_real_min_y

  subroutine  set_real_min_z(zmin_in)
    real(8), intent(in) :: zmin_in

    z_minimum = zmin_in

  end subroutine set_real_min_z


!================
! model parameterを出力してくれる。
! うっかりさん向け
!================
  subroutine dump_gms_modelparm
    write(*,*) "dx=", dx, "dy=", dy, "dz=", dz
    write(*,*) "xmin=", x_minimum, "ymin=", y_minimum, "zmin=", z_minimum
    write(*,*) "xmax=", x_minimum + dx * pub1, "ymax=", y_minimum + dy * pub2, "zmax=", z_minimum + dz * pub3
    write(*,*) "nx=", pub1, "ny=", pub2, "nz=", pub3
  end subroutine dump_gms_modelparm



end module model_info

