TABLE OF CONTENTS


ABINIT/write_var_netcdf [ Functions ]

[ Top ] [ Functions ]

NAME

 write_var_netcdf

FUNCTION

 Write the history into a netcdf dataset

COPYRIGHT

 Copyright (C) 1998-2017 ABINIT group (DCA, XG, GMR)
 This file is distributed under the terms of the
 GNU General Public License, see ~abinit/COPYING
 or http://www.gnu.org/copyleft/gpl.txt .
 For the initials of contributors,
 see ~abinit/doc/developers/contributors.txt .

INPUTS

 arr_int
 arr_real
 marr
 narr
 typevar
 varname

OUTPUT

  (only writing)

PARENTS

      prttagm,prttagm_images

CHILDREN

SOURCE

 36 #if defined HAVE_CONFIG_H
 37 #include "config.h"
 38 #endif
 39 
 40 #include "abi_common.h"
 41 
 42 subroutine write_var_netcdf(arr_int,arr_real,marr,narr,ncid,typevar,varname)
 43 
 44  use defs_basis
 45  use m_profiling_abi
 46  use m_errors 
 47 #if defined HAVE_NETCDF
 48  use netcdf
 49 #endif
 50 
 51 !This section has been created automatically by the script Abilint (TD).
 52 !Do not modify the following lines by hand.
 53 #undef ABI_FUNC
 54 #define ABI_FUNC 'write_var_netcdf'
 55 !End of the abilint section
 56 
 57 implicit none
 58 
 59 !Arguments ------------------------------------
 60 !scalars
 61  integer,intent(in) :: narr,marr,ncid
 62  character(len=*),intent(in) :: varname
 63  character(len=3),intent(in) :: typevar
 64 !arrays
 65  integer,intent(in) :: arr_int(marr)
 66  real(dp),intent(in) :: arr_real(marr)
 67 
 68 !Local variables-------------------------------
 69 !scalars
 70  integer :: var_id,var_type,vardim_id,ncerr
 71  !character(len=500) :: msg
 72 
 73 ! *************************************************************************
 74 
 75  !write(std_out,*)"about to write varname: ",trim(varname)
 76 
 77 #if defined HAVE_NETCDF
 78  if (ncid>0) then
 79 !  ### Put the file in definition mode
 80    ncerr=nf90_redef(ncid)
 81    if (ncerr/=NF90_NOERR.and.ncerr/=NF90_EINDEFINE) then
 82      NCF_CHECK_MSG(ncerr,'nf90_redef')
 83    end if
 84 !  ### Define the dimensions
 85    if (narr==1)then
 86      ncerr=nf90_inq_dimid(ncid,'one',vardim_id)
 87      NCF_CHECK_MSG(ncerr,'nf90_inq_varid')
 88    else
 89      ncerr=nf90_def_dim(ncid,trim(varname),narr,vardim_id)
 90      NCF_CHECK_MSG(ncerr,'nf90_def_dim')
 91    end if
 92 !  ### Define the variables
 93    if (typevar=='INT') then
 94      var_type=NF90_INT
 95    else if (typevar=='DPR') then
 96      var_type=NF90_DOUBLE
 97    end if
 98    ncerr=nf90_def_var(ncid, trim(varname), var_type, vardim_id, var_id)
 99    NCF_CHECK_MSG(ncerr,'nf90_def_var')
100 !  ### Put the file in data mode
101    ncerr=nf90_enddef(ncid)
102    if (ncerr/=NF90_NOERR.and.ncerr/=NF90_ENOTINDEFINE) then
103      NCF_CHECK_MSG(ncerr,'nf90_enddef')
104    end if
105 !  ### Write variables into the dataset
106    if (typevar=='INT') then
107      ncerr=nf90_put_var(ncid,var_id,arr_int,start=(/1/),count=(/narr/))
108    else if (typevar=='DPR') then
109      ncerr=nf90_put_var(ncid,var_id,arr_real,start=(/1/),count=(/narr/))
110    end if
111    NCF_CHECK_MSG(ncerr,'nf90_put_var')
112  end if
113 #endif
114 
115 end subroutine write_var_netcdf