!c Description:
!c  NetCDF ファイルの次元, 変数定義
!c
!c Current Code Owner: 
!c   sugiyama@gfd-dennou.org
!c
!c Histry: 
!c   Version    Date          Comment
!c   -------    ----------    --------
!c   1.0        2003-02-06    作成
!c
!c Copyright (C) SUGIYAMA Ko-ichiro, 2003, All rights reserved

module interface_netcdf_def
  interface netcdf_def
     subroutine netcdf_def_dim(ncid, name, len, dimid)
       integer, intent(in)       :: ncid
       integer, intent(in)       :: len
       integer, intent(in)       :: dimid
       character(*), intent(in) :: name
     end subroutine netcdf_def_dim

     subroutine netcdf_def_var(ncid, name, long_name, units, type, dimid)
       integer, intent(in)       :: ncid
       integer, intent(in)       :: type 
       integer, intent(in)       :: dimid
       character(*), intent(in) :: name
       character(*), intent(in) :: units
       character(*), intent(in) :: long_name
     end subroutine netcdf_def_var

  end interface
end module interface_netcdf_def


subroutine netcdf_def_dim(ncid, name, len, dimid)
  use netcdf
  use interface_netcdf_err

  implicit none
  integer, intent(in)       :: ncid
  integer, intent(in)       :: len
  integer, intent(out)      :: dimid
  character(*), intent(in) :: name

  integer                   :: status


  status = nf90_def_dim(ncid, name, len, dimid)
  if(status /= nf90_noerr) call netcdf_err(status)

end subroutine netcdf_def_dim


subroutine netcdf_def_var(ncid, name, long_name, units, type, dimid)
  use netcdf
  use interface_netcdf_err

  implicit none  
  integer, intent(in)       :: ncid
  integer, intent(in)       :: type 
  integer, intent(in)       :: dimid
  character(*), intent(in) :: name
  character(*), intent(in) :: units
  character(*), intent(in) :: long_name

  integer                   :: varid
  integer                   :: status


  status = nf90_def_var(ncid, name, type, dimid, varid)
  if(status /= nf90_noerr) call netcdf_err(status)
  status = nf90_put_att(ncid, varid, 'long_name', long_name)
  if(status /= nf90_noerr) call netcdf_err(status)
  status = nf90_put_att(ncid, varid, 'units', units)
  if(status /= nf90_noerr) call netcdf_err(status)

end subroutine netcdf_def_var






