TABLE OF CONTENTS


ABINIT/m_nctk [ Modules ]

[ Top ] [ Modules ]

NAME

 m_nctk

FUNCTION

  Tools and wrappers for NETCDF-IO.

COPYRIGHT

  Copyright (C) 2008-2018 ABINIT group (MG)
  This file is distributed under the terms of the
  GNU General Public License, see ~abinit/COPYING
  or http://www.gnu.org/copyleft/gpl.txt .

TODO

   Remove create_nc_file, write_var_netcdf, the output of OUT.nc is dangereous
     because we can create too many dimensions and get
    nf90_def_dim - NetCDF library returned:   NetCDF: NC_MAX_DIMS exceeded
   Moreover the multiple calls to redef render the IO very inefficient
   That part should be rationalized!

PARENTS

SOURCE

26 #if defined HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29 
30 #include "abi_common.h"
31 
32 MODULE m_nctk
33 
34  use defs_basis
35  use m_abicore
36  use m_build_info
37  use m_errors
38  use iso_c_binding
39  use m_xmpi
40 #ifdef HAVE_NETCDF
41  use netcdf
42 #endif
43 
44  use m_fstrings,  only : itoa, sjoin, lstrip, char_count, strcat, endswith, startswith, ltoa
45  use m_io_tools,  only : pick_aname, delete_file, file_exists
46 
47  implicit none
48 
49  private

ABINIT/write_eig [ Functions ]

[ Top ] [ Functions ]

NAME

 write_eig

FUNCTION

 Write the eigenvalues band by band and k point by k point
 in a NetCDF file format

INPUTS

 filname = Filename of the file where the history will be stored

OUTPUT

  (only writing)

PARENTS

      clnup1

CHILDREN

      ab_define_var

SOURCE

3083 subroutine write_eig(eigen,filename,kptns,mband,nband,nkpt,nsppol)
3084 
3085 
3086 !This section has been created automatically by the script Abilint (TD).
3087 !Do not modify the following lines by hand.
3088 #undef ABI_FUNC
3089 #define ABI_FUNC 'write_eig'
3090 !End of the abilint section
3091 
3092 implicit none
3093 
3094 !Arguments ------------------------------------
3095 !scalars
3096  character(len=fnlen),intent(in) :: filename
3097  integer,intent(in) :: nkpt,nsppol,mband
3098 !arrays
3099  integer,intent(in) :: nband(nkpt*nsppol)
3100  real(dp),intent(in) :: eigen(mband*nkpt*nsppol)
3101  real(dp),intent(in) :: kptns(3,nkpt)
3102 
3103 !Local variables-------------------------------
3104 !scalars
3105  integer :: ncerr,ncid,ii
3106  integer :: xyz_id,nkpt_id,mband_id,nsppol_id
3107  integer :: eig_id,kpt_id,nbk_id,nbk
3108  integer :: ikpt,isppol,nband_k,band_index
3109  real(dp):: convrt
3110 !arrays
3111  integer :: dimEIG(3),dimKPT(2),dimNBK(2)
3112  integer :: count2(2),start2(2)
3113  integer :: count3(3),start3(3)
3114  real(dp):: band(mband)
3115 
3116 ! *********************************************************************
3117 
3118 #if defined HAVE_NETCDF
3119 
3120  convrt=1.0_dp
3121 
3122 !1. Create netCDF file
3123  ncerr = nf90_create(path=trim(filename),cmode=NF90_CLOBBER, ncid=ncid)
3124  NCF_CHECK_MSG(ncerr," create netcdf EIG file")
3125 
3126 !2. Define dimensions
3127  ncerr = nf90_def_dim(ncid,"xyz",3,xyz_id)
3128  NCF_CHECK_MSG(ncerr," define dimension xyz")
3129 
3130  ncerr = nf90_def_dim(ncid,"mband",mband,mband_id)
3131  NCF_CHECK_MSG(ncerr," define dimension mband")
3132 
3133  ncerr = nf90_def_dim(ncid,"nkpt",nkpt,nkpt_id)
3134  NCF_CHECK_MSG(ncerr," define dimension nkpt")
3135 
3136  ncerr = nf90_def_dim(ncid,"nsppol",nsppol,nsppol_id)
3137  NCF_CHECK_MSG(ncerr," define dimension nsppol")
3138 
3139 !Dimensions for EIGENVALUES
3140  dimEIG = (/ mband_id, nkpt_id, nsppol_id /)
3141 !Dimensions for kpoint positions
3142  dimKPT = (/ xyz_id, nkpt_id /)
3143 !Dimensions for number kpoints per band and spin
3144 !dimNBK = (/ nkpt_id, nsppol_id /)
3145  dimNBK = (/ nkpt_id, nsppol_id /)
3146 
3147 !3. Define variables
3148 
3149  call ab_define_var(ncid, dimEIG, eig_id, NF90_DOUBLE,&
3150 & "Eigenvalues",&
3151 & "Values of eigenvalues",&
3152 & "Hartree")
3153  call ab_define_var(ncid, dimKPT, kpt_id, NF90_DOUBLE,"Kptns",&
3154 & "Positions of K-points in reciprocal space",&
3155 & "Dimensionless")
3156  call ab_define_var(ncid, dimNBK, nbk_id, NF90_INT,"NBandK",&
3157 & "Number of bands per kpoint and Spin",&
3158 & "Dimensionless")
3159 
3160 !4. End define mode
3161  ncerr = nf90_enddef(ncid)
3162  NCF_CHECK_MSG(ncerr," end define mode")
3163 
3164 !5 Write kpoint positions
3165  do ikpt=1,nkpt
3166    start2 = (/ 1, ikpt /)
3167    count2 = (/ 3, 1 /)
3168    ncerr = nf90_put_var(ncid, kpt_id,&
3169 &   kptns(1:3,ikpt),&
3170 &   start = start2,&
3171 &   count = count2)
3172    NCF_CHECK_MSG(ncerr," write variable kptns")
3173  end do
3174 
3175 
3176 !6 Write eigenvalues
3177  band_index=0
3178  do isppol=1,nsppol
3179    do ikpt=1,nkpt
3180      nband_k=nband(ikpt+(isppol-1)*nkpt)
3181      start3 = (/ 1, ikpt, isppol /)
3182      count3 = (/ mband, 1, 1 /)
3183      band(:)=zero
3184      do ii=1,nband_k
3185        band(ii)=eigen(band_index+ii)
3186      end do
3187      ncerr = nf90_put_var(ncid, eig_id,&
3188 &     band,&
3189 &     start = start3,&
3190 &     count = count3)
3191      NCF_CHECK_MSG(ncerr," write variable band")
3192 
3193      band_index=band_index+nband_k
3194    end do
3195  end do
3196 
3197 !6 Write Number of bands per kpoint and Spin
3198 
3199  do isppol=1,nsppol
3200    do ikpt=1,nkpt
3201      start2 = (/ ikpt, 1 /)
3202      count2 = (/ 1, 1 /)
3203      nbk=nband(ikpt+(isppol-1)*nkpt)
3204      ncerr = nf90_put_var(ncid, nbk_id,&
3205 &     nbk,&
3206 &     start = start2)
3207      NCF_CHECK_MSG(ncerr," write variable nband")
3208    end do
3209  end do
3210 
3211 !7 Close file
3212 
3213  ncerr = nf90_close(ncid)
3214  NCF_CHECK_MSG(ncerr," close netcdf EIG file")
3215 #endif
3216 
3217 end subroutine write_eig

m_nctk/ab_define_var [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

 ab_define_var

FUNCTION

 Write the definition of a variable, including units and mnemonics

INPUTS

 ncid = Identifier of the netcdf dataset
 var_dim_id = Identifier of the Dimensions
 var_id     = Identifier of the variable
 var_mnemo  = String of mnemonics
 var_name   = String with the name of the variable
 var_type   = NetCDF type of variable (NF90_DOUBLE, etc)
 var_units  = String of units

OUTPUT

  (only writing)

PARENTS

      m_abihist,m_bse_io,m_effective_potential,write_eig

CHILDREN

SOURCE

1415 subroutine ab_define_var(ncid, var_dim_id, var_id, var_type, var_name, var_mnemo, var_units)
1416 
1417 
1418 !This section has been created automatically by the script Abilint (TD).
1419 !Do not modify the following lines by hand.
1420 #undef ABI_FUNC
1421 #define ABI_FUNC 'ab_define_var'
1422 !End of the abilint section
1423 
1424  implicit none
1425 
1426 !Arguments ------------------------------------
1427 !scalars
1428  integer, intent(in) :: ncid
1429  integer, intent(out) :: var_id
1430  character(len=*), intent(in) :: var_mnemo,var_units,var_name
1431  integer,intent(in) :: var_type
1432 !arrays
1433  integer,intent(in) :: var_dim_id(:)
1434 
1435 !Local variables-------------------------------
1436 !scalars
1437  integer :: ncerr
1438 
1439 ! *************************************************************************
1440 
1441 #ifdef HAVE_NETCDF
1442  ncerr = nf90_def_var(ncid, trim(var_name), var_type, var_dim_id, var_id)
1443  NCF_CHECK_MSG(ncerr," define variable "//trim(var_name))
1444 
1445  ncerr = nf90_put_att(ncid, var_id,  "units",trim(var_units))
1446  NCF_CHECK_MSG(ncerr," define attribute for "//trim(var_name))
1447 
1448  ncerr = nf90_put_att(ncid, var_id,  "mnemonics", trim(var_mnemo))
1449  NCF_CHECK_MSG(ncerr," define attribute for "//trim(var_name))
1450 #endif
1451 
1452 end subroutine ab_define_var

m_nctk/bail_if_ncerr [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  bail_if_ncerr

FUNCTION

INPUTS

  ncerr=Netcdf error
  line=line number of the file where problem occurred
  file=name of the f90 file containing the caller

SOURCE

677 logical function bail_if_ncerr(ncerr, file, line) result(bail)
678 
679 
680 !This section has been created automatically by the script Abilint (TD).
681 !Do not modify the following lines by hand.
682 #undef ABI_FUNC
683 #define ABI_FUNC 'bail_if_ncerr'
684 !End of the abilint section
685 
686   implicit none
687 
688 !This section has been created automatically by the script Abilint (TD).
689 !Do not modify the following lines by hand.
690 #undef ABI_FUNC
691 #define ABI_FUNC 'str2xtype'
692 !End of the abilint section
693 
694 !Arguments ------------------------------------
695  integer,intent(in) :: ncerr
696  character(len=*),optional,intent(in) :: file
697  integer,optional,intent(in) :: line
698 
699 ! *********************************************************************
700 
701  bail = (ncerr /= nf90_noerr)
702 
703  if (bail) then
704    einfo%ncerr = ncerr
705    einfo%file = "Subroutine Unknown"; if (present(file)) einfo%file = file
706    einfo%line = 0; if (present(line)) einfo%line = line
707    ! Append Netcdf string to user-defined message.
708    write(einfo%msg,'(2a)')'NetCDF library raised: ',trim(nf90_strerror(ncerr))
709  end if
710 
711 end function bail_if_ncerr

m_nctk/collect_datar [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  collect_datar

FUNCTION

 Collect a real-space MPI-FFT distributed array on each proc.

INPUTS

  ngfft(18)=contain all needed information about 3D FFT (see NOTES at beginning of scfcv)
  cplex=1 if real array, 2 for complex
  nfft=Number of FFT points treated by this MPI proc
  nspden=Second dimension of rhor
  rhor(cplex*nfft,nspden)=Array in real space (MPI-FFT distributed)
  fftn3_distrib(n3)=rank of the processors which own fft planes in 3rd dimension.
  fftn3_local(n3)=local i3 indices
  comm_fft=MPI-FFT communicator
  [master]=MPI rank, Optional. If present, the global array is available only on master node.

OUTPUT

   rhor_glob(cplex*nfft_tot,nspden)=Global array

PARENTS

      m_nctk

CHILDREN

SOURCE

2552 subroutine collect_datar(ngfft,cplex,nfft,nspden,rhor,comm_fft,fftn3_distrib,ffti3_local,rhor_glob,master)
2553 
2554 
2555 !This section has been created automatically by the script Abilint (TD).
2556 !Do not modify the following lines by hand.
2557 #undef ABI_FUNC
2558 #define ABI_FUNC 'collect_datar'
2559 !End of the abilint section
2560 
2561  implicit none
2562 
2563 !Arguments ------------------------------------
2564 !scalars
2565  integer,intent(in) :: cplex,nfft,nspden,comm_fft
2566  integer,optional,intent(in) :: master
2567 !arrays
2568  integer,intent(in) :: ngfft(18)
2569  integer,intent(in) :: fftn3_distrib(ngfft(3)),ffti3_local(ngfft(3))
2570  real(dp),intent(in) :: rhor(cplex*nfft,nspden)
2571  real(dp),intent(out) :: rhor_glob(cplex*product(ngfft(1:3)),nspden)
2572 
2573 !Local variables-------------------------------
2574  integer :: ispden,i1,i2,i3,me_fft,i3_local,my_fftbase,glob_fftbase
2575  integer :: n1,n2,n3,ierr,nfft_tot
2576 
2577 ! *************************************************************************
2578 
2579  nfft_tot = product(ngfft(1:3)); me_fft = xmpi_comm_rank(comm_fft)
2580  n1 = ngfft(1); n2 = ngfft(2); n3 = ngfft(3)
2581 
2582  if (nfft_tot == nfft) then
2583    ! full rhor on each node, just do a copy
2584    rhor_glob = rhor
2585  else
2586    ! if MPI-FFT we have to gather the global array on each node.
2587    rhor_glob = zero
2588    do ispden=1,nspden
2589      do i3=1,n3
2590        if (me_fft == fftn3_distrib(i3)) then
2591          i3_local = ffti3_local(i3)
2592          do i2=1,n2
2593            my_fftbase =   cplex * ( (i2-1)*n1 + (i3_local-1)*n1*n2 )
2594            glob_fftbase = cplex * ( (i2-1)*n1 + (i3-1)*n1*n2 )
2595            do i1=1,cplex * n1
2596              rhor_glob(i1+glob_fftbase,ispden) = rhor(i1+my_fftbase,ispden)
2597            end do
2598          end do
2599        end if
2600      end do
2601    end do
2602    if (present(master)) then
2603      call xmpi_sum_master(rhor_glob,master,comm_fft,ierr)
2604    else
2605      call xmpi_sum(rhor_glob,comm_fft,ierr)
2606    end if
2607  end if
2608 
2609 end subroutine collect_datar

m_nctk/create_nc_file [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

 create_nc_file

FUNCTION

 Create an NetCDF file including a dimension one definition

INPUTS

OUTPUT

 TODO:
  Remove

PARENTS

      outvars

CHILDREN

SOURCE

2924 subroutine create_nc_file (filename,ncid)
2925 
2926 
2927 !This section has been created automatically by the script Abilint (TD).
2928 !Do not modify the following lines by hand.
2929 #undef ABI_FUNC
2930 #define ABI_FUNC 'create_nc_file'
2931 !End of the abilint section
2932 
2933 implicit none
2934 
2935 !Arguments ------------------------------------
2936 !scalars
2937  integer,intent(out) :: ncid
2938 !arrays
2939 character(len=*),intent(in) :: filename
2940 
2941 !Local variables-------------------------------
2942 #if defined HAVE_NETCDF
2943 integer :: one_id
2944 integer :: ncerr
2945 #endif
2946 
2947 ! *************************************************************************
2948 
2949  ncid = 0
2950 #if defined HAVE_NETCDF
2951 !Create the NetCDF file
2952  ncerr=nf90_create(path=filename,cmode=NF90_CLOBBER,ncid=ncid)
2953  NCF_CHECK_MSG(ncerr, sjoin('Error while creating:', filename))
2954  ncerr=nf90_def_dim(ncid,'one',1,one_id)
2955  NCF_CHECK_MSG(ncerr,'nf90_def_dim')
2956 #endif
2957 
2958  end subroutine create_nc_file

m_nctk/distrib_datar [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  distrib_datar

FUNCTION

 distribute a real-space MPI-FFT

INPUTS

  ngfft(18)=contain all needed information about 3D FFT (see NOTES at beginning of scfcv)
  cplex=1 if real array, 2 for complex
  nfft=Number of FFT points treated by this MPI proc
  nspden=Second dimension of rhor
  rhor_glob(cplex*nfft_tot,nspden)=Global array
  master=The rank of the node that owns the global array.
  comm_fft=MPI-FFT communicator
  fftn3_distrib(n3)=rank of the processors which own fft planes in 3rd dimension.
  fftn3_local(n3)=local i3 indices

OUTPUT

  rhor(cplex*nfft,nspden)=Array in real space (MPI-FFT distributed)

PARENTS

      m_nctk

CHILDREN

SOURCE

2642 subroutine distrib_datar(ngfft,cplex,nfft,nspden,rhor_glob,master,comm_fft,fftn3_distrib,ffti3_local,rhor)
2643 
2644 
2645 !This section has been created automatically by the script Abilint (TD).
2646 !Do not modify the following lines by hand.
2647 #undef ABI_FUNC
2648 #define ABI_FUNC 'distrib_datar'
2649 !End of the abilint section
2650 
2651  implicit none
2652 
2653 !Arguments ------------------------------------
2654 !scalars
2655  integer,intent(in) :: cplex,nfft,nspden,comm_fft,master
2656 !arrays
2657  integer,intent(in) :: ngfft(18)
2658  integer,intent(in) :: fftn3_distrib(ngfft(3)),ffti3_local(ngfft(3))
2659  real(dp),intent(out) :: rhor(cplex*nfft,nspden)
2660  real(dp),intent(inout) :: rhor_glob(cplex*product(ngfft(1:3)),nspden)
2661 
2662 !Local variables-------------------------------
2663  integer :: ispden,i1,i2,i3,me_fft,i3_local,my_fftbase,glob_fftbase
2664  integer :: n1,n2,n3,ierr,nfft_tot
2665 
2666 ! *************************************************************************
2667 
2668  nfft_tot = product(ngfft(1:3)); me_fft = xmpi_comm_rank(comm_fft)
2669  n1 = ngfft(1); n2 = ngfft(2); n3 = ngfft(3)
2670 
2671  if (nfft_tot == nfft) then
2672    ! full rhor on each node, just do a copy
2673    rhor = rhor_glob
2674  else
2675    ! if MPI-FFT we have to gather the global array on each node.
2676    call xmpi_bcast(rhor_glob,master,comm_fft,ierr)
2677    do ispden=1,nspden
2678      do i3=1,n3
2679        if (me_fft == fftn3_distrib(i3)) then
2680          i3_local = ffti3_local(i3)
2681          do i2=1,n2
2682            my_fftbase =   cplex * ( (i2-1)*n1 + (i3_local-1)*n1*n2 )
2683            glob_fftbase = cplex * ( (i2-1)*n1 + (i3-1)*n1*n2 )
2684            do i1=1,cplex * n1
2685              rhor(i1+my_fftbase,ispden) = rhor_glob(i1+glob_fftbase,ispden)
2686            end do
2687          end do
2688        end if
2689      end do
2690    end do
2691  end if
2692 
2693 end subroutine distrib_datar

m_nctk/ncfdim_t [ Types ]

[ Top ] [ m_nctk ] [ Types ]

NAME

 nctkdim_t

FUNCTION

  Stores the name and the value of a netcdf dimension

SOURCE

112  type,public :: nctkdim_t
113    character(len=nctk_slen) :: name   ! name of the dimension.
114    integer :: value                   ! value of the dimension.
115    !integer :: id
116  end type nctkdim_t

m_nctk/nctk_add_etsf_header [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_add_etsf_header

FUNCTION

   Add the etsf-io header to a file associated to a netcdf file handler.

INPUTS

  ncid=Netcdf file identifier.
  * version = the number of version to be created.
  * title = (optional) a title for the file (80 characters max).
  * history = (optional) the first line of history (1024 characters max).
  * with_etsf_header = (optional) if true, will create a header
                       as defined in the ETSF specifications (default is .true.).
                       When value is .false., arguments title, history and version
                       are ignored.

PARENTS

SOURCE

932 integer function nctk_add_etsf_header(ncid, title, history) result(ncerr)
933 
934 
935 !This section has been created automatically by the script Abilint (TD).
936 !Do not modify the following lines by hand.
937 #undef ABI_FUNC
938 #define ABI_FUNC 'nctk_add_etsf_header'
939 !End of the abilint section
940 
941  implicit none
942 
943 !Arguments ------------------------------------
944  integer,intent(in) :: ncid
945  character(len=*),optional,intent(in) :: title,history
946 
947 !Local variables-------------------------------
948  !integer :: ncerr
949  character(len=*), parameter :: file_format = "ETSF Nanoquanta"
950  character(len=*), parameter :: conventions = "http://www.etsf.eu/fileformats/"
951  real :: format_version = 3.3 ! Real is not a good choice for a version!
952 
953 ! *********************************************************************
954 
955  ncerr = nctk_set_defmode(ncid)
956  if (ncerr /= nf90_noerr) return
957 
958  ! The file format
959  ncerr = nf90_put_att(ncid, NF90_GLOBAL, "file_format", file_format)
960  if (ncerr /= nf90_noerr) return
961 
962  ! The version
963  ncerr = nf90_put_att(ncid, NF90_GLOBAL, "file_format_version", format_version)
964  if (ncerr /= nf90_noerr) return
965 
966  ! The conventions
967  ncerr = nf90_put_att(ncid, NF90_GLOBAL, "Conventions", conventions)
968  if (ncerr /= nf90_noerr) return
969 
970  ! The history if present
971  if (present(history)) then
972    ncerr = nf90_put_att(ncid, NF90_GLOBAL, "history", history(1:min(1024, len(history))))
973    if (ncerr /= nf90_noerr) return
974  end if
975 
976  ! The title if present
977  if (present(title)) then
978    ncerr = nf90_put_att(ncid, NF90_GLOBAL, "title", title(1:min(80, len(title))))
979    if (ncerr /= nf90_noerr) return
980  end if
981 
982  ! These are extensions not in the standard.
983  ! Add info on the code that produced this file
984  ncerr = nf90_put_att(ncid, NF90_GLOBAL, "code", "Abinit")
985  if (ncerr /= nf90_noerr) return
986 
987  ncerr = nf90_put_att(ncid, NF90_GLOBAL, "code_version", ABINIT_VERSION)
988  if (ncerr /= nf90_noerr) return
989 
990 end function nctk_add_etsf_header

m_nctk/nctk_def_array_list [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_def_array_list

FUNCTION

  Define list of arrays with a given type, Return immediately if error

INPUTS

  ncid=Netcdf identifier.
  nctk_arrays(:)=List of array descriptors.
  [defmode]=If True, the nc file is set in define mode (default=False)

PARENTS

CHILDREN

SOURCE

1759 integer function nctk_def_array_list(ncid, nctk_arrays, defmode) result(ncerr)
1760 
1761 
1762 !This section has been created automatically by the script Abilint (TD).
1763 !Do not modify the following lines by hand.
1764 #undef ABI_FUNC
1765 #define ABI_FUNC 'nctk_def_array_list'
1766 !End of the abilint section
1767 
1768  implicit none
1769 
1770 !Arguments ------------------------------------
1771 !scalars
1772  integer,intent(in) :: ncid
1773  logical,optional,intent(in) :: defmode
1774 !arrays
1775  type(nctkarr_t),intent(in) :: nctk_arrays(:)
1776 
1777 !Local variables-------------------------------
1778 !scalars
1779  integer :: ia
1780 
1781 ! *********************************************************************
1782 
1783  ncerr = nf90_noerr
1784  if (present(defmode)) then
1785    if (defmode) then
1786      NCF_CHECK(nctk_set_defmode(ncid))
1787    end if
1788  end if
1789 
1790  do ia=1,size(nctk_arrays)
1791    NCF_CHECK(nctk_def_one_array(ncid, nctk_arrays(ia)))
1792  end do
1793 
1794 end function nctk_def_array_list

m_nctk/nctk_def_basedims [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_def_basedims

FUNCTION

  Define the basic dimensions used in ETSF-IO files.

INPUTS

  ncid=Netcdf identifier.
  [defmode]=If True, the nc file is set in define mode (default=False)

PARENTS

      m_dfpt_io,m_dfptdb,m_header,m_phonons

CHILDREN

SOURCE

1346 integer function nctk_def_basedims(ncid, defmode) result(ncerr)
1347 
1348 
1349 !This section has been created automatically by the script Abilint (TD).
1350 !Do not modify the following lines by hand.
1351 #undef ABI_FUNC
1352 #define ABI_FUNC 'nctk_def_basedims'
1353 !End of the abilint section
1354 
1355  implicit none
1356 
1357 !Arguments ------------------------------------
1358  integer,intent(in) :: ncid
1359  logical,optional,intent(in) :: defmode
1360 
1361 ! *********************************************************************
1362 
1363  ncerr = nf90_noerr
1364 
1365  if (present(defmode)) then
1366    if (defmode) then
1367      NCF_CHECK(nctk_set_defmode(ncid))
1368    end if
1369  end if
1370 
1371  ! Basic ETSF-IO dimensions that should be always present in the file.
1372  ncerr = nctk_def_dims(ncid, [&
1373    nctkdim_t("complex", 2), nctkdim_t("symbol_length", 2), nctkdim_t("character_string_length", etsfio_charlen),&
1374    nctkdim_t("number_of_cartesian_directions", 3), nctkdim_t("number_of_reduced_dimensions", 3),&
1375    nctkdim_t("number_of_vectors", 3)])
1376  NCF_CHECK(ncerr)
1377 
1378  ! Useful integers.
1379  ncerr = nctk_def_dims(ncid, [&
1380    nctkdim_t("one", 1), nctkdim_t("two", 2), nctkdim_t("three", 3), &
1381    nctkdim_t("four", 4), nctkdim_t("five", 5), nctkdim_t("six", 6), &
1382    nctkdim_t("seven", 7), nctkdim_t("eight", 8), nctkdim_t("nine", 9), nctkdim_t("ten", 10)])
1383  NCF_CHECK(ncerr)
1384 
1385 end function nctk_def_basedims

m_nctk/nctk_def_dim_list [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_def_dim_list

FUNCTION

  Define list of dimensions variables and write their values.
  Return immediately if error

INPUTS

  ncid=Netcdf identifier.
  dimnames(:)=List of strings with the name of the dimensions
  values(:)=List of integer scalars
  [defmode]=If True, the nc file is set in define mode (default=False)

PARENTS

CHILDREN

SOURCE

1238 integer function nctk_def_dim_list(ncid, nctkdims, defmode) result(ncerr)
1239 
1240 
1241 !This section has been created automatically by the script Abilint (TD).
1242 !Do not modify the following lines by hand.
1243 #undef ABI_FUNC
1244 #define ABI_FUNC 'nctk_def_dim_list'
1245 !End of the abilint section
1246 
1247  implicit none
1248 
1249 !Arguments ------------------------------------
1250 !scalars
1251  integer,intent(in) :: ncid
1252  logical,optional,intent(in) :: defmode
1253 !arrays
1254  type(nctkdim_t),intent(in) :: nctkdims(:)
1255 
1256 !Local variables-------------------------------
1257 !scalars
1258  integer :: ii
1259 
1260 ! *********************************************************************
1261 
1262  ncerr = nf90_noerr
1263  if (present(defmode)) then
1264    if (defmode) then
1265      NCF_CHECK(nctk_set_defmode(ncid))
1266    end if
1267  end if
1268 
1269  do ii=1,size(nctkdims)
1270    ncerr = nctk_def_one_dim(ncid, nctkdims(ii))
1271    if (ncerr /= nf90_noerr) return
1272  end do
1273 
1274 end function nctk_def_dim_list

m_nctk/nctk_def_dpscalars [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_def_dpscalars

FUNCTION

  Define list of double precision **scalar** variables. Return immediately if error

INPUTS

  ncid=Netcdf identifier.
  varnames(:)=List of strings with the name of the variables
  [defmode]=If True, the nc file is set in define mode (default=False)

PARENTS

CHILDREN

SOURCE

1595 integer function nctk_def_dpscalars(ncid, varnames, defmode) result(ncerr)
1596 
1597 
1598 !This section has been created automatically by the script Abilint (TD).
1599 !Do not modify the following lines by hand.
1600 #undef ABI_FUNC
1601 #define ABI_FUNC 'nctk_def_dpscalars'
1602 !End of the abilint section
1603 
1604  implicit none
1605 
1606 !Arguments ------------------------------------
1607 !scalars
1608  integer,intent(in) :: ncid
1609  logical,optional,intent(in) :: defmode
1610 !arrays
1611  character(len=*),intent(in) :: varnames(:)
1612 
1613 ! *********************************************************************
1614 
1615  if (present(defmode)) then
1616    ncerr = nctk_def_scalars_type(ncid, varnames, nf90_double, defmode=defmode)
1617  else
1618    ncerr = nctk_def_scalars_type(ncid, varnames, nf90_double)
1619  end if
1620 
1621 end function nctk_def_dpscalars

m_nctk/nctk_def_iscalars [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_def_iscalars

FUNCTION

  Define list of integer **scalar** variables. Return immediately if error

INPUTS

  ncid=Netcdf identifier.
  varnames(:)=List of strings with the name of the variables
  [defmode]=If True, the nc file is set in define mode (default=False)

PARENTS

CHILDREN

SOURCE

1548 integer function nctk_def_iscalars(ncid, varnames, defmode) result(ncerr)
1549 
1550 
1551 !This section has been created automatically by the script Abilint (TD).
1552 !Do not modify the following lines by hand.
1553 #undef ABI_FUNC
1554 #define ABI_FUNC 'nctk_def_iscalars'
1555 !End of the abilint section
1556 
1557  implicit none
1558 
1559 !Arguments ------------------------------------
1560 !scalars
1561  integer,intent(in) :: ncid
1562  logical,optional,intent(in) :: defmode
1563 !arrays
1564  character(len=*),intent(in) :: varnames(:)
1565 
1566 ! *********************************************************************
1567 
1568  if (present(defmode)) then
1569    ncerr = nctk_def_scalars_type(ncid, varnames, nf90_int, defmode=defmode)
1570  else
1571    ncerr = nctk_def_scalars_type(ncid, varnames, nf90_int)
1572  end if
1573 
1574 end function nctk_def_iscalars

m_nctk/nctk_def_one_array [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_def_one_array

FUNCTION

  Define list of arrays with a given type, Return immediately if error

INPUTS

  ncid=Netcdf identifier.
  nctk_array=Array descriptor.
  [defmode]=If True, the nc file is set in define mode (default=False)

PARENTS

CHILDREN

SOURCE

1643 integer function nctk_def_one_array(ncid, nctk_array, defmode, varid) result(ncerr)
1644 
1645 
1646 !This section has been created automatically by the script Abilint (TD).
1647 !Do not modify the following lines by hand.
1648 #undef ABI_FUNC
1649 #define ABI_FUNC 'nctk_def_one_array'
1650 !End of the abilint section
1651 
1652  implicit none
1653 
1654 !Arguments ------------------------------------
1655 !scalars
1656  integer,intent(in) :: ncid
1657  logical,optional,intent(in) :: defmode
1658  integer,optional,intent(out) :: varid
1659  type(nctkarr_t),intent(in) :: nctk_array
1660 
1661 !Local variables-------------------------------
1662 !scalars
1663  integer :: ii,xtype,prev,cnt,nn,vid
1664  character(len=500) :: msg
1665 !arrays
1666  integer :: dimids(NF90_MAX_DIMS),dimvals(NF90_MAX_DIMS)
1667  character(len=nctk_slen) :: sarr(NF90_MAX_DIMS), string
1668  type(nctkvar_t) :: var
1669 
1670 ! *********************************************************************
1671 
1672  ncerr = nf90_noerr
1673  if (present(defmode)) then
1674    if (defmode) then
1675      NCF_CHECK(nctk_set_defmode(ncid))
1676    end if
1677  end if
1678 
1679  xtype = str2xtype(nctk_array%dtype)
1680 
1681  ! Build array of strings with the dimensions.
1682  string = nctk_array%shape_str
1683  nn = char_count(string, ",")
1684  ABI_CHECK(nn <= NF90_MAX_DIMS, "Too many dimensions!")
1685 
1686  if (nn == 0) then
1687    cnt = 1
1688    sarr(1) = lstrip(string)
1689  else
1690    prev = 0; cnt = 0
1691    do ii=1,len_trim(string)
1692      if (string(ii:ii) == ",") then
1693        cnt = cnt + 1
1694        sarr(cnt) = lstrip(string(prev+1:ii-1))
1695        prev = ii
1696      end if
1697    end do
1698    cnt = cnt + 1
1699    sarr(cnt) = lstrip(string(prev+1:ii-1))
1700  end if
1701 
1702  ! Get dimids
1703  do ii=1,cnt
1704    !write(std_out,*)trim(sarr(ii))
1705    NCF_CHECK_MSG(nf90_inq_dimid(ncid, sarr(ii), dimids(ii)), sarr(ii))
1706    NCF_CHECK(nf90_inquire_dimension(ncid, dimids(ii), len=dimvals(ii)))
1707  end do
1708 
1709  ! Check if dimension already exists.
1710  ! Variable already exists. Check if type and dimensions agree
1711  if (nf90_inq_varid(ncid, nctk_array%name, vid) == nf90_noerr)  then
1712    call var_from_id(ncid, vid, var)
1713    if (.not. (var%xtype == xtype .and. var%ndims == cnt)) then
1714       write(msg,"(4a,2(2(a,i0),a))")&
1715         "variable ",trim(nctk_array%name)," already exists with a different definition:",ch10,&
1716         "In file:     xtype = ",var%xtype,", ndims = ",var%ndims,ch10,&
1717         "From caller: xtype = ",xtype,", ndims = ",cnt,ch10
1718       MSG_ERROR(msg)
1719    end if
1720    if (any(dimvals(1:cnt) /= var%dimlens(1:var%ndims))) then
1721       write(msg,"(4a,2(3a))")&
1722         "variable ",trim(nctk_array%name)," already exists but with different shape.",ch10,&
1723         "In file:     dims = ",trim(ltoa(var%dimlens(:var%ndims))),ch10,&
1724         "From caller  dims = ",trim(ltoa(dimvals(:cnt))),ch10
1725       MSG_ERROR(msg)
1726    end if
1727    if (present(varid)) varid = vid
1728    return
1729  end if
1730 
1731  ! Define variable since it doesn't exist.
1732  ncerr = nf90_def_var(ncid, nctk_array%name, xtype, dimids(1:cnt), vid)
1733  NCF_CHECK(ncerr)
1734 
1735  if (present(varid)) varid = vid
1736 
1737 end function nctk_def_one_array

m_nctk/nctk_def_one_dim [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_def_one_dim

FUNCTION

  Define list of dimensions variables and write their values.
  Return immediately if error

INPUTS

  ncid=Netcdf identifier.
  dimnames(:)=List of strings with the name of the dimensions
  values(:)=List of integer scalars
  [defmode]=If True, the nc file is set in define mode (default=False)

PARENTS

CHILDREN

SOURCE

1166 integer function nctk_def_one_dim(ncid, nctkdim, defmode) result(ncerr)
1167 
1168 
1169 !This section has been created automatically by the script Abilint (TD).
1170 !Do not modify the following lines by hand.
1171 #undef ABI_FUNC
1172 #define ABI_FUNC 'nctk_def_one_dim'
1173 !End of the abilint section
1174 
1175  implicit none
1176 
1177 !Arguments ------------------------------------
1178 !scalars
1179  integer,intent(in) :: ncid
1180  logical,optional,intent(in) :: defmode
1181 !arrays
1182  type(nctkdim_t),intent(in) :: nctkdim
1183 
1184 !Local variables-------------------------------
1185  integer :: dimid,dimlen
1186  character(len=500) :: msg
1187 ! *********************************************************************
1188 
1189  ncerr = nf90_noerr
1190 
1191  if (present(defmode)) then
1192    if (defmode) then
1193      NCF_CHECK(nctk_set_defmode(ncid))
1194    end if
1195  end if
1196 
1197  ! if dimension already exists, test whether it has the same value else define new dim.
1198  ncerr = nf90_inq_dimid(ncid,  nctkdim%name, dimid)
1199 
1200  if (ncerr == nf90_noerr) then
1201    NCF_CHECK(nf90_inquire_dimension(ncid, dimid, len=dimlen))
1202    if (dimlen /= nctkdim%value) then
1203      write(msg, "(2a,2(a,i0))")&
1204         "dimension already exists with a different value",ch10,&
1205         "file = ", dimlen, "; write = ", nctkdim%value
1206      MSG_ERROR(msg)
1207    end if
1208  else
1209    ncerr = nf90_def_dim(ncid, nctkdim%name, nctkdim%value, dimid)
1210    NCF_CHECK(ncerr)
1211  end if
1212 
1213 end function nctk_def_one_dim

m_nctk/nctk_def_scalars_type [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_def_scalars_type

FUNCTION

  Define list of **scalar** variables with a given type, Return immediately if error

INPUTS

  ncid=Netcdf identifier.
  varnames(:)=List of strings with the name of the variables
  xtype=Type of the variables
  [defmode]=If True, the nc file is set in define mode (default=False)

PARENTS

CHILDREN

SOURCE

1474 integer function nctk_def_scalars_type(ncid, varnames, xtype, defmode) result(ncerr)
1475 
1476 
1477 !This section has been created automatically by the script Abilint (TD).
1478 !Do not modify the following lines by hand.
1479 #undef ABI_FUNC
1480 #define ABI_FUNC 'nctk_def_scalars_type'
1481 !End of the abilint section
1482 
1483  implicit none
1484 
1485 !Arguments ------------------------------------
1486 !scalars
1487  integer,intent(in) :: ncid,xtype
1488  logical,optional,intent(in) :: defmode
1489 !arrays
1490  character(len=*),intent(in) :: varnames(:)
1491 
1492 !Local variables-------------------------------
1493 !scalars
1494  integer :: ii,varid
1495  type(nctkvar_t) :: var
1496 
1497 ! *********************************************************************
1498 
1499  ncerr = nf90_noerr
1500  if (present(defmode)) then
1501    if (defmode) then
1502      NCF_CHECK(nctk_set_defmode(ncid))
1503    end if
1504  end if
1505 
1506  ! Special case where dimension is null
1507 
1508  do ii=1,size(varnames)
1509 
1510    if (nf90_inq_varid(ncid, varnames(ii), varid) == nf90_noerr)  then
1511        ! Variable already exists. Check if type and dimensions agree
1512        call var_from_id(ncid, varid, var)
1513 
1514        if (.not. (var%xtype == xtype .and. var%ndims == 0)) then
1515          MSG_ERROR("variable already exists with a different definition.")
1516        else
1517          cycle ! Dimension matches, skip definition.
1518        end if
1519 
1520    else
1521      ! Define variable since it doesn't exist.
1522      ncerr = nf90_def_var(ncid, varnames(ii), xtype, varid)
1523      NCF_CHECK(ncerr)
1524    end if
1525  end do
1526 
1527 end function nctk_def_scalars_type

m_nctk/nctk_defnwrite_dpvars [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_defnwrite_dpvars

FUNCTION

  Define list of real(dp) **scalar** variables and write their values.
  Return immediately if error

INPUTS

  ncid=Netcdf identifier.
  varnames(:)=List of strings with the name of the variables
  values(:)=List of integer scalars

PARENTS

CHILDREN

SOURCE

1999 integer function nctk_defnwrite_dpvars(ncid, varnames, values) result(ncerr)
2000 
2001 
2002 !This section has been created automatically by the script Abilint (TD).
2003 !Do not modify the following lines by hand.
2004 #undef ABI_FUNC
2005 #define ABI_FUNC 'nctk_defnwrite_dpvars'
2006 !End of the abilint section
2007 
2008  implicit none
2009 
2010 !Arguments ------------------------------------
2011 !scalars
2012  integer,intent(in) :: ncid
2013 !arrays
2014  real(dp),intent(in) :: values(:)
2015  character(len=*),intent(in) :: varnames(:)
2016 
2017 !Local variables-------------------------------
2018 !scalars
2019  integer :: ii,varid
2020 !arrays
2021 
2022 ! *********************************************************************
2023  ncerr = nf90_noerr
2024 
2025  ABI_CHECK(size(varnames) == size(values), "Different size in varnames, values")
2026 
2027  ncerr = nctk_def_dpscalars(ncid, varnames, defmode=.True.)
2028  NCF_CHECK(ncerr)
2029 
2030  NCF_CHECK(nctk_set_datamode(ncid))
2031  do ii=1,size(varnames)
2032    !write(std_out,*)varnames(ii)
2033    varid = nctk_idname(ncid, varnames(ii))
2034    NCF_CHECK(nf90_put_var(ncid, varid, values(ii)))
2035  end do
2036 
2037 end function nctk_defnwrite_dpvars

m_nctk/nctk_defnwrite_ivars [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_defnwrite_ivars

FUNCTION

  Define list of integer **scalar** variables and write their values.
  Return immediately if error

INPUTS

  ncid=Netcdf identifier.
  varnames(:)=List of strings with the name of the variables
  values(:)=List of integer scalars

PARENTS

CHILDREN

SOURCE

1942 integer function nctk_defnwrite_ivars(ncid, varnames, values) result(ncerr)
1943 
1944 
1945 !This section has been created automatically by the script Abilint (TD).
1946 !Do not modify the following lines by hand.
1947 #undef ABI_FUNC
1948 #define ABI_FUNC 'nctk_defnwrite_ivars'
1949 !End of the abilint section
1950 
1951  implicit none
1952 
1953 !Arguments ------------------------------------
1954 !scalars
1955  integer,intent(in) :: ncid
1956 !arrays
1957  integer,intent(in) :: values(:)
1958  character(len=*),intent(in) :: varnames(:)
1959 
1960 !Local variables-------------------------------
1961 !scalars
1962  integer :: ii,varid
1963 
1964 ! *********************************************************************
1965 
1966  ABI_CHECK(size(varnames) == size(values), "Different size in varnames, values")
1967 
1968  ncerr = nctk_def_iscalars(ncid, varnames, defmode=.True.)
1969  NCF_CHECK(ncerr)
1970 
1971  NCF_CHECK(nctk_set_datamode(ncid))
1972  do ii=1,size(varnames)
1973    varid = nctk_idname(ncid, varnames(ii))
1974    NCF_CHECK(nf90_put_var(ncid, varid, values(ii)))
1975  end do
1976 
1977 end function nctk_defnwrite_ivars

m_nctk/nctk_defwrite_nonana_terms [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

 nctk_defwrite_nonana_terms

FUNCTION

  Write phonon frequencies and displacements for q-->0 in the presence of non-analytical behaviour.

INPUTS

  ncid=netcdf file id.
  iphl2=Index of the q-point to be written to file
  nph2l=Number of qpoints.
  qph2l(3,nph2l)=List of phonon wavevector directions along which the non-analytical correction
    to the Gamma-point phonon frequencies will be calculated
    The direction is in CARTESIAN COORDINATES
  natom=Number of atoms
  phfrq(3*natom)=Phonon frequencies in Ha
  cart_displ(2,3*natom,3*natom)=displacements in CARTESIAN coordinates.

OUTPUT

  Only writing.

PARENTS

      anaddb,m_ifc

CHILDREN

SOURCE

2843 subroutine nctk_defwrite_nonana_terms(ncid, iphl2, nph2l, qph2l, natom, phfrq, cart_displ, mode)
2844 
2845 
2846 !This section has been created automatically by the script Abilint (TD).
2847 !Do not modify the following lines by hand.
2848 #undef ABI_FUNC
2849 #define ABI_FUNC 'nctk_defwrite_nonana_terms'
2850 !End of the abilint section
2851 
2852  implicit none
2853 
2854 !Arguments ------------------------------------
2855 !scalars
2856  integer,intent(in) :: ncid,iphl2,nph2l,natom
2857  character(len=*),intent(in) :: mode
2858 !arrays
2859  real(dp),intent(in) :: qph2l(3, nph2l)
2860  real(dp),intent(in) :: phfrq(3*natom)
2861  real(dp),intent(in) :: cart_displ(2,3*natom,3*natom)
2862 
2863 !Local variables-------------------------------
2864 !scalars
2865  integer :: ncerr, na_phmodes_varid, na_phdispl_varid
2866 
2867 ! *************************************************************************
2868 
2869  select case (mode)
2870  case ("define")
2871    !NCF_CHECK(nctk_def_basedims(ncid, defmode=.True.))
2872    ncerr = nctk_def_dims(ncid, [nctkdim_t("number_of_non_analytical_directions", nph2l)], defmode=.True.)
2873    NCF_CHECK(ncerr)
2874 
2875    ncerr = nctk_def_arrays(ncid, [&
2876    nctkarr_t('non_analytical_directions', "dp", "number_of_cartesian_directions, number_of_non_analytical_directions"),&
2877    nctkarr_t('non_analytical_phonon_modes', "dp", "number_of_phonon_modes, number_of_non_analytical_directions"),&
2878    nctkarr_t('non_analytical_phdispl_cart', "dp", &
2879    "two, number_of_phonon_modes, number_of_phonon_modes, number_of_non_analytical_directions")])
2880    NCF_CHECK(ncerr)
2881 
2882    NCF_CHECK(nctk_set_datamode(ncid))
2883    NCF_CHECK(nf90_put_var(ncid, nctk_idname(ncid, "non_analytical_directions"), qph2l))
2884 
2885  case ("write")
2886 
2887    NCF_CHECK(nf90_inq_varid(ncid, "non_analytical_phonon_modes", na_phmodes_varid))
2888    NCF_CHECK(nf90_put_var(ncid,na_phmodes_varid,phfrq*Ha_eV,start=[1, iphl2], count=[3*natom, 1]))
2889    NCF_CHECK(nf90_inq_varid(ncid, "non_analytical_phdispl_cart", na_phdispl_varid))
2890    ncerr = nf90_put_var(ncid,na_phdispl_varid,cart_displ*Bohr_Ang,&
2891    start=[1,1,1,iphl2], count=[2,3*natom,3*natom, 1])
2892    NCF_CHECK(ncerr)
2893 
2894  case default
2895    MSG_ERROR(sjoin("Wrong value for mode", mode))
2896  end select
2897 
2898 end subroutine nctk_defwrite_nonana_terms

m_nctk/nctk_fort_or_ncfile [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_fort_or_ncfile

FUNCTION

  Return the iomode used to perform IO operations on filename.
  If filename does not exist, a similar file with extension `.nc` is tried
  and iomode is set to IO_MODE_ETSF if the file exists.
  This trick is used to run the Abinit test suite in netcdf mode without changing the input files.
  The modification (if any) is logged to std_out.

SIDE EFFECTS

  filename=Tentative filename in input. Changed to netcdf file if input filename does not exist
   and a file with netcdf extension is found.

OUTPUT

  iomode=Flag selecting the IO library. Set to IO_MODE_ETSF if netcdf file, else IO_MODE_MPI
    if MPI supports it, finally IO_MODE_FORTRAN
  errmsg=String with error message. Use `if (len_trim(errmsg) /= 0) MSG_ERROR(errmsg)`
    to handle possible errors in the caller.

PARENTS

      conducti_nc,optic

CHILDREN

SOURCE

415 subroutine nctk_fort_or_ncfile(filename, iomode, errmsg)
416 
417 
418 !This section has been created automatically by the script Abilint (TD).
419 !Do not modify the following lines by hand.
420 #undef ABI_FUNC
421 #define ABI_FUNC 'nctk_fort_or_ncfile'
422 !End of the abilint section
423 
424  character(len=*),intent(inout) :: filename
425  character(len=*),intent(out) :: errmsg
426  integer,intent(out) :: iomode
427 
428 ! *********************************************************************
429   errmsg = ""
430 
431  ! Default value
432 #ifdef HAVE_MPI_IO
433  iomode = IO_MODE_MPI
434 #else
435  iomode = IO_MODE_FORTRAN
436 #endif
437 
438  !  Checking the existence of data file
439  if (.not.file_exists(filename)) then
440    ! Trick needed to run Abinit test suite in netcdf mode.
441    if (file_exists(nctk_ncify(filename))) then
442      write(std_out,"(3a)")"- File: ",trim(filename)," does not exist but found netcdf file with similar name."
443      filename = nctk_ncify(filename); iomode = IO_MODE_ETSF
444    end if
445    if (.not. file_exists(filename)) then
446      errmsg = 'Missing file: '//trim(filename)
447    end if
448  end if
449 
450 end subroutine nctk_fort_or_ncfile

m_nctk/nctk_get_dim [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_get_dim

FUNCTION

  Get the value of a dimension from its name.

INPUTS

  ncid=Netcdf identifier.
  dimname=Name of the dimension.
  [datamode]=If True, the nc file is set in data mode (default=False)

OUTPUT

  dimlen=Value of the dimension.

PARENTS

CHILDREN

SOURCE

2132 integer function nctk_get_dim(ncid, dimname, dimlen, datamode) result(ncerr)
2133 
2134 
2135 !This section has been created automatically by the script Abilint (TD).
2136 !Do not modify the following lines by hand.
2137 #undef ABI_FUNC
2138 #define ABI_FUNC 'nctk_get_dim'
2139 !End of the abilint section
2140 
2141  implicit none
2142 
2143 !Arguments ------------------------------------
2144 !scalars
2145  integer,intent(in) :: ncid
2146  character(len=*),intent(in) :: dimname
2147  integer,intent(out) :: dimlen
2148  logical,optional,intent(in) :: datamode
2149 
2150 !Local variables-------------------------------
2151 !scalars
2152  integer :: dimid
2153 
2154 ! *********************************************************************
2155 
2156  ncerr = nf90_noerr
2157 
2158  if (present(datamode)) then
2159    if (datamode) then
2160      NCF_CHECK(nctk_set_datamode(ncid))
2161    end if
2162  end if
2163 
2164  NCF_CHECK(nf90_inq_dimid(ncid, dimname, dimid))
2165  NCF_CHECK(nf90_inquire_dimension(ncid, dimid, len=dimlen))
2166 
2167 end function nctk_get_dim

m_nctk/nctk_idname [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_idname

FUNCTION

  Return the nc identifier from the name of the variable

PARENTS

SOURCE

266 integer function nctk_idname(ncid, varname) result(varid)
267 
268 
269 !This section has been created automatically by the script Abilint (TD).
270 !Do not modify the following lines by hand.
271 #undef ABI_FUNC
272 #define ABI_FUNC 'nctk_idname'
273 !End of the abilint section
274 
275  implicit none
276 
277 !Arguments ------------------------------------
278  integer,intent(in) :: ncid
279  character(len=*),intent(in) :: varname
280 
281 !Local variables-------------------------------
282 !scalars
283  integer :: ncerr
284  character(len=1000) :: msg
285 
286 ! *********************************************************************
287 
288 #ifdef HAVE_NETCDF
289  ! nctk_idname must be available outside CPP blocks due to a bug in abilint.
290  ncerr = nf90_inq_varid(ncid, varname, varid)
291 
292  if (ncerr /= nf90_noerr) then
293    write(msg,'(5a)')&
294      "NetCDF library returned: ",trim(nf90_strerror(ncerr)),ch10,&
295      "while trying to get the ncid of variable: ",trim(varname)
296    MSG_ERROR(msg)
297  end if
298 #else
299  MSG_ERROR("Netcdf support is not activated")
300  write(std_out,*)ncid,varname
301 #endif
302 
303 end function nctk_idname

m_nctk/nctk_ncify [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_ncify

FUNCTION

  Append ".nc" to ipath if ipath does not end with ".nc"

SOURCE

317 function nctk_ncify(ipath) result(opath)
318 
319 
320 !This section has been created automatically by the script Abilint (TD).
321 !Do not modify the following lines by hand.
322 #undef ABI_FUNC
323 #define ABI_FUNC 'nctk_ncify'
324 !End of the abilint section
325 
326  character(len=fnlen),intent(in) :: ipath
327  character(len=fnlen) :: opath
328 
329 ! *********************************************************************
330 
331  if (.not. endswith(ipath, ".nc")) then
332    opath = trim(ipath)//'.nc'
333  else
334    opath = ipath
335  end if
336 
337 end function nctk_ncify

m_nctk/nctk_open_create [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_open_create

FUNCTION

  Create and open the netcdf file. Return exis status.

INPUTS

  path=Name of the file
  comm=MPI communicator.

OUTPUT

  ncid=Netcdf identifier.

PARENTS

SOURCE

795 integer function nctk_open_create(ncid, path, comm) result(ncerr)
796 
797 
798 !This section has been created automatically by the script Abilint (TD).
799 !Do not modify the following lines by hand.
800 #undef ABI_FUNC
801 #define ABI_FUNC 'nctk_open_create'
802 !End of the abilint section
803 
804  implicit none
805 
806 !Arguments ------------------------------------
807  integer,intent(out) :: ncid
808  integer,intent(in) :: comm
809  character(len=*),intent(in) :: path
810 
811 ! *********************************************************************
812 
813  ! Always use mpiio mode (i.e. hdf5) if available so that one perform parallel parallel IO
814  if (nctk_has_mpiio) then
815    ncerr = nf90_einval
816 #ifdef HAVE_NETCDF_MPI
817    call wrtout(std_out, sjoin("Creating HDf5 file: ", path), "COLL")
818    ! Believe it or not, I have to use xmpi_comm_self even in sequential to avoid weird SIGSEV in the MPI layer!
819    ncerr = nf90_create(path, cmode=ior(ior(nf90_netcdf4, nf90_mpiio), nf90_write), ncid=ncid, &
820      comm=comm, info=xmpio_info)
821 #endif
822  else
823    ncerr = nf90_create(path, ior(nf90_clobber, nf90_write), ncid)
824    if (xmpi_comm_size(comm) > 1) then
825      MSG_WARNING("netcdf without MPI-IO support with nprocs > 1!")
826    end if
827  end if
828  NCF_CHECK(ncerr)
829 
830  ! Write etsf_header: file format, version and conventions.
831  NCF_CHECK(nf90_put_att(ncid, NF90_GLOBAL, "file_format", etsfio_file_format))
832  NCF_CHECK(nf90_put_att(ncid, NF90_GLOBAL, "file_format_version", etsfio_version))
833  NCF_CHECK(nf90_put_att(ncid, NF90_GLOBAL, "Conventions", etsfio_conventions))
834 
835  ! Add info on the code that produced this file. These are extensions not in the standard.
836  NCF_CHECK(nf90_put_att(ncid, NF90_GLOBAL, "code", "Abinit"))
837  NCF_CHECK(nf90_put_att(ncid, NF90_GLOBAL, "abinit_version", abinit_version))
838 
839  ! Define the basic dimensions used in ETSF-IO files.
840  NCF_CHECK(nctk_def_basedims(ncid, defmode=.True.))
841 
842 end function nctk_open_create

m_nctk/nctk_open_modify [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_open_modfy

FUNCTION

   Open an already existent netcdf file for modifications. Return exit status.

INPUTS

  path=File name.
  comm=MPI communicator.

OUTPUT

  ncid=Netcdf identifier.

PARENTS

SOURCE

865 integer function nctk_open_modify(ncid, path, comm) result(ncerr)
866 
867 
868 !This section has been created automatically by the script Abilint (TD).
869 !Do not modify the following lines by hand.
870 #undef ABI_FUNC
871 #define ABI_FUNC 'nctk_open_modify'
872 !End of the abilint section
873 
874  implicit none
875 
876 !Arguments ------------------------------------
877  integer,intent(out) :: ncid
878  integer,intent(in) :: comm
879  character(len=*),intent(in) :: path
880 
881 !Local variables-------------------------------
882 
883 ! *********************************************************************
884 
885  if (.not. nctk_has_mpiio .and. xmpi_comm_size(comm) > 1) then
886    MSG_ERROR("netcdf without MPI-IO support with nprocs > 1!")
887  end if
888 
889  !if (xmpi_comm_size(comm) > 1) then
890  if (xmpi_comm_size(comm) > 1 .or. nctk_has_mpiio) then
891 #ifdef HAVE_NETCDF_MPI
892    ncerr = nf90_open_par(path, cmode=ior(ior(nf90_netcdf4, nf90_mpiio), nf90_write), &
893      comm=comm, info=xmpio_info, ncid=ncid)
894    NCF_CHECK_MSG(ncerr, sjoin("nf90_open_par: ", path))
895 #else
896    MSG_ERROR("nprocs > 1 but netcdf does not support MPI-IO")
897 #endif
898  else
899    ncerr = nf90_open(path, nf90_write, ncid)
900    NCF_CHECK_MSG(ncerr, sjoin("nf90_open: ", path))
901  end if
902 
903  ! Set file in define mode.
904  ncerr = nctk_set_defmode(ncid)
905 
906 end function nctk_open_modify

m_nctk/nctk_open_read [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_open_read

FUNCTION

   Open a netcdf file in read-only mode. Return exit status.

INPUTS

  ncid=Netcdf identifier.
  comm=MPI communicator.

PARENTS

SOURCE

731 integer function nctk_open_read(ncid, path, comm) result(ncerr)
732 
733 
734 !This section has been created automatically by the script Abilint (TD).
735 !Do not modify the following lines by hand.
736 #undef ABI_FUNC
737 #define ABI_FUNC 'nctk_open_read'
738 !End of the abilint section
739 
740  implicit none
741 
742 !Arguments ------------------------------------
743  integer,intent(out) :: ncid
744  integer,intent(in) :: comm
745  character(len=*),intent(in) :: path
746 
747 !Local variables-------------------------------
748  integer :: nprocs
749 
750 ! *********************************************************************
751  nprocs = xmpi_comm_size(comm)
752 
753  ! Enforce netcdf4 only if the communicator contains more than one processor.
754  if (nctk_has_mpiio .and. nprocs > 1) then
755 #ifdef HAVE_NETCDF_MPI
756    ncerr = nf90_open(path, mode=ior(ior(nf90_netcdf4, nf90_mpiio), nf90_nowrite),&
757                      comm=comm, info=xmpio_info, ncid=ncid)
758 #else
759    ncerr = nf90_einval
760    MSG_WARNING("Netcdf without MPI support. Cannot open file, will abort in caller")
761 #endif
762    NCF_CHECK_MSG(ncerr, sjoin("opening file:", path))
763  else
764    ncerr = nf90_open(path, mode=nf90_nowrite, ncid=ncid)
765    NCF_CHECK_MSG(ncerr, sjoin("opening file:", path))
766    if (nprocs > 1) then
767      ncerr = nf90_einval
768      MSG_WARNING("netcdf without MPI-IO support with nprocs > 1! Will abort in the caller")
769    end if
770  endif
771 
772 end function nctk_open_read

m_nctk/nctk_read_datar [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

 nctk_read_datar

FUNCTION

  Read an array in real space in netcdf format

INPUTS

  path=Filename
  varname=Name of the variable to read.
  ngfft(18)=information about 3D FFT
  cplex=1 for real arrays (e.g. GS rhor), 2 for complex array.
  nfft=number of points in the real space FFT mesh treated by this MPI proc
  nspden=number of spin-density components
  comm_fft=MPI communicator (used only if MPI-FFT).
  fftn3_distrib(n3)=rank of the processors which own fft planes in 3rd dimension.
  ffti3_local(n3)=local index for 3d dimension
  datar(cplex*nfft,nspden)= array in real space.

OUTPUT

  Only writing

PARENTS

CHILDREN

SOURCE

2415 integer function nctk_read_datar(path,varname,ngfft,cplex,nfft,nspden,&
2416    comm_fft,fftn3_distrib,ffti3_local,datar) result(ncerr)
2417 
2418 
2419 !This section has been created automatically by the script Abilint (TD).
2420 !Do not modify the following lines by hand.
2421 #undef ABI_FUNC
2422 #define ABI_FUNC 'nctk_read_datar'
2423 !End of the abilint section
2424 
2425  implicit none
2426 
2427 !Arguments ------------------------------------
2428 !scalars
2429  integer,intent(in) :: cplex,nfft,nspden,comm_fft
2430  character(len=*),intent(in) :: path,varname
2431 !arrays
2432  integer,intent(in) :: ngfft(18),fftn3_distrib(ngfft(3)),ffti3_local(ngfft(3))
2433  real(dp),intent(out) :: datar(cplex*nfft,nspden)
2434 
2435 !Local variables-------------------------------
2436 !scalars
2437  integer,parameter :: master=0
2438  integer :: ncid,varid,i3,nproc_fft,me_fft,i3_glob,n1,n2,n3,ispden
2439  logical :: ionode
2440 !arrays
2441  real(dp),allocatable :: glob_datar(:,:)
2442 
2443 ! *************************************************************************
2444 
2445  nproc_fft = xmpi_comm_size(comm_fft); me_fft = xmpi_comm_rank(comm_fft)
2446  n1 = ngfft(1); n2 = ngfft(2); n3 = ngfft(3)
2447 
2448  ! TODO: Be careful here because we should always create with HDF5 if available
2449  ! to avoid problems if we have to reread with nproc_fft > 1 and MPI-IO
2450  ionode = .True.
2451  if (nproc_fft == 1) then
2452    ncerr = nf90_open(path, mode=nf90_nowrite, ncid=ncid)
2453  else
2454    if (nctk_has_mpiio) then
2455      !write(std_out,*)"open_par: ",trim(path)
2456      !ncerr = nf90_open_par(path, nf90_nowrite,
2457      ! Don't know why but the format is not autodected!
2458      ncerr = nf90_einval
2459 #ifdef HAVE_NETCDF_MPI
2460      ncerr = nf90_open(path, mode=ior(ior(nf90_netcdf4, nf90_mpiio), nf90_nowrite),&
2461                        comm=comm_fft, info=xmpio_info, ncid=ncid)
2462 #endif
2463    else
2464      ! MPI-FFT without MPI-support. Only master does IO
2465      ionode = (me_fft == master); ncerr = nf90_noerr
2466      if (ionode) ncerr = nf90_open(path, nf90_nowrite, ncid)
2467    end if
2468  end if
2469  NCF_CHECK_MSG(ncerr, sjoin("opening file: ",path))
2470 
2471  NCF_CHECK(nf90_inq_varid(ncid, varname, varid))
2472  !write(std_out,*)"about to read varname, ngfft, cplex, nfft, nspden:", trim(varname), ngfft(:3), cplex,nfft,nspden
2473 
2474  ! netcdf array has shape [cplex, n1, n2, n3, nspden]
2475  if (nproc_fft == 1) then
2476    ! No MPI-FFT --> easy
2477    NCF_CHECK(nf90_get_var(ncid, varid, datar, start=[1,1,1,1], count=[cplex, n1, n2, n3, nspden]))
2478    NCF_CHECK(nf90_close(ncid))
2479 
2480  else
2481    ! Handle data distribution.
2482    ABI_CHECK(mod(ngfft(3), nproc_fft) == 0, "assuming mod(n3, nproc_fft) == 0")
2483 
2484    i3_glob = -1
2485    do i3=1,ngfft(3)
2486      if (fftn3_distrib(i3) == me_fft) then
2487         i3_glob = i3
2488         exit
2489      end if
2490    end do
2491    ABI_CHECK(i3_glob > 0, "negative i3_glob")
2492 
2493    if (nctk_has_mpiio) then
2494      ! Use parallel IO with collective calls.
2495      ncerr = nf90_einval
2496      NCF_CHECK(nctk_set_collective(ncid, varid))
2497 
2498      do ispden=1,nspden
2499        ncerr = nf90_get_var(ncid, varid, datar(:,ispden), start=[1,1,1,i3_glob,ispden], &
2500                 count=[cplex,ngfft(1),ngfft(2),ngfft(3)/nproc_fft,1])
2501        NCF_CHECK(ncerr)
2502      end do
2503    else
2504      ! MPI-FFT without MPI-IO. Master read and broadcast (requires more memory and communication)
2505      ABI_MALLOC(glob_datar, (cplex*product(ngfft(1:3)), nspden))
2506      if (ionode) then
2507        NCF_CHECK(nf90_get_var(ncid, varid, glob_datar, start=[1,1,1,1,1], count=[cplex,n1,n2,n3,nspden]))
2508      end if
2509 
2510      call distrib_datar(ngfft,cplex,nfft,nspden,glob_datar,master,comm_fft,fftn3_distrib,ffti3_local,datar)
2511      ABI_FREE(glob_datar)
2512    end if
2513 
2514    if (ionode) then
2515      NCF_CHECK(nf90_close(ncid))
2516    end if
2517  end if
2518 
2519 end function nctk_read_datar

m_nctk/nctk_set_atomic_units [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_set_atomic_units

FUNCTION

  Set the attributes "units" to "atomic units" and "scale_to_atomic_units" to one.

INPUTS

  ncid=Netcdf identifier.
  varname=Name of the variable

PARENTS

CHILDREN

SOURCE

1296 integer function nctk_set_atomic_units(ncid, varname) result(ncerr)
1297 
1298 
1299 !This section has been created automatically by the script Abilint (TD).
1300 !Do not modify the following lines by hand.
1301 #undef ABI_FUNC
1302 #define ABI_FUNC 'nctk_set_atomic_units'
1303 !End of the abilint section
1304 
1305  implicit none
1306 
1307 !Arguments ------------------------------------
1308  integer,intent(in) :: ncid
1309  character(len=*),intent(in) :: varname
1310 
1311 !Local variables-------------------------------
1312 !scalars
1313  integer :: varid
1314 
1315 ! *********************************************************************
1316 
1317  ncerr = nf90_noerr
1318 
1319  varid = nctk_idname(ncid, varname)
1320  NCF_CHECK(nf90_put_att(ncid, varid, "units", "atomic units"))
1321  NCF_CHECK(nf90_put_att(ncid, varid, "scale_to_atomic_units", one))
1322 
1323 end function nctk_set_atomic_units

m_nctk/nctk_set_collective [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_set_collective

FUNCTION

  Use collective IO for the given netcdf variable. Return exit status.

INPUTS

  ncid=Netcdf file identifier.
  varid=Netcdf variable identifier.

PARENTS

SOURCE

1119 integer function nctk_set_collective(ncid, varid) result(ncerr)
1120 
1121 
1122 !This section has been created automatically by the script Abilint (TD).
1123 !Do not modify the following lines by hand.
1124 #undef ABI_FUNC
1125 #define ABI_FUNC 'nctk_set_collective'
1126 !End of the abilint section
1127 
1128  implicit none
1129 
1130 !Arguments ------------------------------------
1131  integer,intent(in) :: ncid,varid
1132 
1133 ! *********************************************************************
1134 
1135   ncerr = nf90_einval
1136 #ifdef HAVE_NETCDF_MPI
1137   ncerr = nf90_var_par_access(ncid, varid, nf90_collective)
1138 #else
1139   MSG_ERROR("nctk_set_collective should not be called if NETCDF does not support MPI-IO")
1140   ABI_UNUSED((/ncid, varid/))
1141 #endif
1142 
1143 end function nctk_set_collective

m_nctk/nctk_set_datamode [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_set_datamode

FUNCTION

  Set the file in data mode. Return exit status

INPUTS

  ncid=Netcdf identifier.
  [reserve]

OUTPUT

  ncerr=Exit status

PARENTS

SOURCE

1056 integer function nctk_set_datamode(ncid, reserve) result(ncerr)
1057 
1058 
1059 !This section has been created automatically by the script Abilint (TD).
1060 !Do not modify the following lines by hand.
1061 #undef ABI_FUNC
1062 #define ABI_FUNC 'nctk_set_datamode'
1063 !End of the abilint section
1064 
1065  implicit none
1066 
1067 !Arguments ------------------------------------
1068  integer,intent(in) :: ncid
1069  logical,intent(in),optional :: reserve
1070 
1071 !Local variables-------------------------------
1072 !scalars
1073  logical :: do_reserve
1074 
1075 ! *********************************************************************
1076 
1077  do_reserve = .False.; if (present(reserve)) do_reserve = reserve
1078 
1079  ncerr = nf90_enddef(ncid)
1080 
1081  ! Use same trick as in etsf_io
1082  ! neded otherwise netcdf complains if the file is already in def mode.
1083  if (ncerr /= nf90_noerr .and. ncerr /= -38) then
1084    NCF_CHECK(ncerr)
1085  else
1086    ncerr = nf90_noerr
1087  end if
1088 
1089  return
1090 
1091  ! TODO
1092  if (do_reserve) then
1093    ncerr = nf90_enddef(ncid)
1094    !ncerr = nf90__enddef(ncid)
1095  else
1096    ncerr = nf90_enddef(ncid)
1097  end if
1098 
1099 end function nctk_set_datamode

m_nctk/nctk_set_defmode [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_set_defmode

FUNCTION

   Set the file in define mode, return exit status.

INPUTS

  ncid=Netcdf identifier.

PARENTS

SOURCE

1009 integer function nctk_set_defmode(ncid) result(ncerr)
1010 
1011 
1012 !This section has been created automatically by the script Abilint (TD).
1013 !Do not modify the following lines by hand.
1014 #undef ABI_FUNC
1015 #define ABI_FUNC 'nctk_set_defmode'
1016 !End of the abilint section
1017 
1018  implicit none
1019 
1020 !Arguments ------------------------------------
1021  integer,intent(in) :: ncid
1022 
1023 ! *********************************************************************
1024 
1025  ncerr = nf90_redef(ncid)
1026  ! Use same trick as in etsf_io
1027  if (ncerr /= nf90_noerr .and. ncerr /= -39) then
1028    NCF_CHECK(ncerr)
1029  else
1030    ncerr = nf90_noerr
1031  end if
1032 
1033 end function nctk_set_defmode

m_nctk/nctk_string_from_occopt [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_string_from_occopt

FUNCTION

SOURCE

351 pure function nctk_string_from_occopt(occopt) result(smearing)
352 
353 
354 !This section has been created automatically by the script Abilint (TD).
355 !Do not modify the following lines by hand.
356 #undef ABI_FUNC
357 #define ABI_FUNC 'nctk_string_from_occopt'
358 !End of the abilint section
359 
360  integer,intent(in) :: occopt
361  character(len=etsfio_charlen) :: smearing
362 
363 ! *********************************************************************
364 
365  select case (occopt)
366  case (3)
367    smearing = "Fermi-Dirac"
368  case (4)
369    smearing = "cold smearing of N. Marzari with minimization of the bump"
370  case (5)
371    smearing = "cold smearing of N. Marzari with monotonic function in the tail"
372  case (6)
373    smearing = "Methfessel and Paxton"
374  case (7)
375    smearing = "gaussian"
376  case (8)
377    smearing = "uniform"
378  case default
379    smearing = "none"
380  end select
381 
382 end function nctk_string_from_occopt

m_nctk/nctk_test_mpiio [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_test_mpiio

FUNCTION

  Test at run-time whether the netcdf library supports parallel IO and
  set the value of the module variable `nctk_has_mpiio`.
  This is a COLLECTIVE routine that should be called by all processors
  in MPI_COMM_WORLD at the beginning of the calculation

PARENTS

      abinit

CHILDREN

SOURCE

534 subroutine nctk_test_mpiio()
535 
536 
537 !This section has been created automatically by the script Abilint (TD).
538 !Do not modify the following lines by hand.
539 #undef ABI_FUNC
540 #define ABI_FUNC 'nctk_test_mpiio'
541 !End of the abilint section
542 
543  implicit none
544 
545 !Local variables-------------------------------
546 !scalars
547 #ifdef HAVE_NETCDF_MPI
548  integer,parameter :: master=0
549  integer :: ierr,ncid,ncerr
550  character(len=500) :: msg
551  character(len=fnlen) :: apath
552 #endif
553 
554 ! *********************************************************************
555 
556  nctk_has_mpiio = .False.
557 
558 #ifdef HAVE_NETCDF_MPI
559  if (xmpi_comm_rank(xmpi_world) == master) then
560    ! Try to open a file with hdf5.
561    apath = pick_aname()
562    ncerr = nf90_create(apath, cmode=ior(ior(nf90_netcdf4, nf90_mpiio), nf90_write), ncid=ncid, &
563      comm=xmpi_comm_self, info=xmpio_info)
564 
565    if (ncerr == nf90_noerr) then
566      nctk_has_mpiio = .True.
567      call wrtout(std_out,"Netcdf library supports MPI-IO", "COLL")
568    else if (ncerr == nf90_enopar) then
569      ! This is the value returned by the C function ifndef USE_PARALLEL
570      MSG_WARNING(sjoin("netcdf lib does not support MPI-IO and: ", nf90_strerror(ncerr)))
571      nctk_has_mpiio = .False.
572    else
573      ! Maybe something wrong in the low-level layer!
574      MSG_WARNING(sjoin("Strange, netcdf seems to support MPI-IO but: ", nf90_strerror(ncerr)))
575      nctk_has_mpiio = .False.
576    end if
577 
578    ncerr = nf90_close(ncid)
579    call delete_file(apath, ierr)
580  end if
581 
582  ! Master broadcast nctk_has_mpiio
583  call xmpi_bcast(nctk_has_mpiio,master,xmpi_world,ierr)
584 
585  if (.not. nctk_has_mpiio) then
586    write(msg,"(5a)")&
587       "The netcdf library does not support parallel IO, see message above",ch10,&
588       "Abinit won't be able to produce files in parallel e.g. when paral_kgb==1 is used.",ch10,&
589       "Action: install a netcdf4+HDF5 library with MPI-IO support."
590    MSG_WARNING(msg)
591  end if
592 #endif
593 
594 #ifdef HAVE_NETCDF_DEFAULT
595  if (.not. nctk_has_mpiio) then
596    MSG_ERROR("--netcdf-default is on but netcdf library does not support MPI-IO. Aborting now")
597  end if
598 #endif
599 
600 end subroutine nctk_test_mpiio

m_nctk/nctk_try_fort_or_ncfile [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_try_fort_or_ncfile

FUNCTION

  If filename does not exist, a similar file with extension `.nc` is tried
  This trick is used to run the Abinit test suite in netcdf mode without changing the input files.
  The modification (if any) is logged to unit (Default: std_out)

SIDE EFFECTS

  filename=Tentative filename in input. Changed to netcdf file if input filename does not exist
   and a file with netcdf extension is found.

OUTPUT

  errmsg=String with error message if return value /= 0

PARENTS

CHILDREN

SOURCE

477 integer function nctk_try_fort_or_ncfile(filename, errmsg, unit) result(ierr)
478 
479 
480 !This section has been created automatically by the script Abilint (TD).
481 !Do not modify the following lines by hand.
482 #undef ABI_FUNC
483 #define ABI_FUNC 'nctk_try_fort_or_ncfile'
484 !End of the abilint section
485 
486  character(len=*),intent(inout) :: filename
487  character(len=*),intent(out) :: errmsg
488  integer,optional,intent(in) :: unit
489 
490 !Local variables-------------------------------
491 !scalars
492  integer :: unt
493 
494 ! *********************************************************************
495 
496  unt = std_out; if (present(unit)) unt = unit
497  ierr = 0; errmsg = ""
498 
499  if (.not.file_exists(filename)) then
500    ! Try netcdf exists.
501    if (file_exists(nctk_ncify(filename))) then
502      if (unt /= dev_null) then
503        write(unt,"(3a)")"- File: ",trim(filename)," does not exist but found netcdf file with similar name."
504      end if
505      filename = nctk_ncify(filename)
506    end if
507    if (.not. file_exists(filename)) then
508      ierr = 1; errmsg = 'Missing file: '//trim(filename)
509    end if
510  end if
511 
512 end function nctk_try_fort_or_ncfile

m_nctk/nctk_write_datar [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

 nctk_write_datar

FUNCTION

  Write an array in real space in netcdf format

INPUTS

  path=Filename
  varname=Name of the variable to write.
  ngfft(18)=information about 3D FFT
  cplex=1 for real arrays (e.g. GS rhor), 2 for complex array.
  nfft=number of points in the real space FFT mesh treated by this MPI proc
  nspden=number of spin-density components
  comm_fft=MPI communicator (used only if MPI-FFT).
  fftn3_distrib(n3)=rank of the processors which own fft planes in 3rd dimension.
  ffti3_local(n3)=local index for 3d dimension
  datar(cplex*nfft,nspden)= array in real space.
  [action]

OUTPUT

  Only writing

PARENTS

CHILDREN

SOURCE

2201 integer function nctk_write_datar(varname,path,ngfft,cplex,nfft,nspden,&
2202    comm_fft,fftn3_distrib,ffti3_local,datar,action) result(ncerr)
2203 
2204 
2205 !This section has been created automatically by the script Abilint (TD).
2206 !Do not modify the following lines by hand.
2207 #undef ABI_FUNC
2208 #define ABI_FUNC 'nctk_write_datar'
2209 !End of the abilint section
2210 
2211  implicit none
2212 
2213 !Arguments ------------------------------------
2214 !scalars
2215  integer,intent(in) :: cplex,nfft,nspden,comm_fft
2216  character(len=*),intent(in) :: path,varname
2217  character(len=*),optional,intent(in) :: action
2218 !arrays
2219  integer,intent(in) :: ngfft(18),fftn3_distrib(ngfft(3)),ffti3_local(ngfft(3))
2220  real(dp),target,intent(in) :: datar(cplex*nfft,nspden)
2221 
2222 !Local variables-------------------------------
2223 !scalars
2224  integer,parameter :: master=0
2225  integer :: ncid,varid,i3,nproc_fft,me_fft,i3_glob,n1,n2,n3,ispden
2226  logical :: ionode
2227  character(len=nctk_slen) :: cplex_name,my_action
2228  !character(len=500) :: msg
2229 !arrays
2230  real(dp),allocatable :: glob_datar(:,:)
2231 
2232 ! *************************************************************************
2233 
2234  ! FIXME: Default should be open but this enters into conflict with the abi_estf stuff!
2235  ! if we are using MPI-IO since file is not open with HDF5.
2236  !my_action = "create"; if (present(action)) my_action = action
2237  my_action = "open"; if (present(action)) my_action = action
2238 
2239  nproc_fft = xmpi_comm_size(comm_fft); me_fft = xmpi_comm_rank(comm_fft)
2240  n1 = ngfft(1); n2 = ngfft(2); n3 = ngfft(3)
2241 
2242  ! TODO: Be careful here because we should always create with HDF5 if available
2243  ! to avoid problems if we have to reread with nproc_fft > 1 and MPI-IO
2244  ionode = .True.; ncerr = nf90_noerr
2245  if (nproc_fft == 1) then
2246    select case(my_action)
2247    case ("open")
2248      ncerr = nf90_open(path, mode=nf90_write, ncid=ncid)
2249    case ("create")
2250      !ncerr = nf90_create(path, cmode=nf90_clobber, ncid=ncid)
2251      ncerr = nctk_open_create(ncid, path, comm_fft)
2252    case default
2253      MSG_ERROR(sjoin("Wrong action: ", my_action))
2254    end select
2255 
2256  else
2257    if (nctk_has_mpiio) then
2258      call wrtout(std_out, strcat("nctk_write_datar: using MPI-IO to write ", varname, path), "COLL")
2259 
2260      ncerr = nf90_einval
2261 #ifdef HAVE_NETCDF_MPI
2262      select case(my_action)
2263      case ("open")
2264        ncerr = nf90_open(path, mode=nf90_write, comm=comm_fft, info=xmpio_info, ncid=ncid)
2265      case ("create")
2266        ncerr = nf90_create(path, cmode=ior(ior(nf90_netcdf4, nf90_mpiio), nf90_write), &
2267          comm=comm_fft, info=xmpio_info, ncid=ncid)
2268      case default
2269        MSG_ERROR(strcat("Wrong action:", my_action))
2270      end select
2271 #endif
2272    else
2273      ! MPI-FFT without MPI-support. Only master does IO
2274      ionode = (me_fft == master)
2275      if (ionode) then
2276        select case(my_action)
2277        case ("open")
2278          ncerr = nf90_open(path, mode=nf90_write, ncid=ncid)
2279        case ("create")
2280          ncerr = nf90_create(path, cmode=nf90_clobber, ncid=ncid)
2281        case default
2282          MSG_ERROR(strcat("Wrong action:", my_action))
2283        end select
2284      end if
2285    end if
2286  end if
2287  NCF_CHECK_MSG(ncerr, sjoin("opening file:", path))
2288 
2289  if (ionode) then
2290    ! Define dims and variables
2291    !write(std_out,*)"defing dims",trim(varname)," in file: ",path
2292    cplex_name = strcat("real_or_complex_", varname)
2293    ncerr = nctk_def_dims(ncid, [&
2294      nctkdim_t(cplex_name, cplex),&
2295      nctkdim_t("number_of_grid_points_vector1", n1),&
2296      nctkdim_t("number_of_grid_points_vector2", n2),&
2297      nctkdim_t("number_of_grid_points_vector3", n3),&
2298      nctkdim_t("number_of_components", nspden)], defmode=.True.)
2299    NCF_CHECK(ncerr)
2300 
2301    ncerr = nctk_def_one_array(ncid, nctkarr_t(name=varname, dtype="dp", shape_str=strcat(cplex_name, &
2302 ", number_of_grid_points_vector1, number_of_grid_points_vector2, number_of_grid_points_vector3, number_of_components")),&
2303    varid=varid)
2304 
2305    ! Add attributes
2306    varid = nctk_idname(ncid, varname)
2307    NCF_CHECK(nf90_put_att(ncid, varid, "units", "atomic units"))
2308    NCF_CHECK(nf90_put_att(ncid, varid, "scale_to_atomic_units", one))
2309  end if
2310 
2311  if (nproc_fft == 1) then
2312    ! no MPI-FFT --> write data directly.
2313    varid = nctk_idname(ncid, varname)
2314    NCF_CHECK(nctk_set_datamode(ncid))
2315    NCF_CHECK(nf90_put_var(ncid, varid, datar, start=[1,1,1,1,1], count=[cplex, n1, n2, n3, nspden]))
2316    NCF_CHECK(nf90_close(ncid))
2317 
2318  else
2319    ! Must handle data distribution.
2320    ABI_CHECK(mod(n3, nproc_fft) == 0, "assuming mod(n3, nproc_fft) == 0")
2321 
2322    i3_glob = -1
2323    do i3=1,ngfft(3)
2324      if (fftn3_distrib(i3) == me_fft) then
2325         i3_glob = i3
2326         exit
2327      end if
2328    end do
2329    ABI_CHECK(i3_glob > 0, "negative i3_glob")
2330 
2331    !do i3=i3_glob,ngfft(3)
2332    !  if (fftn3_distrib(i3) /= me_fft) exit
2333    !  !assert all(ffn3_distrib(i3_glob:i3_glob -1 + ngfft(3) / nproc_fft) == me_fft)
2334    !end do
2335    !i3_glob = i3- 1
2336    !print*,"i3_glob",i3_glob
2337 
2338    if (ionode) then
2339      NCF_CHECK(nf90_enddef(ncid))
2340    end if
2341 
2342    ! Array on disk has shape [cplex, n1, n2, n3, nspden]
2343    if (nctk_has_mpiio) then
2344      ! Use collective IO.
2345      ncerr = nf90_einval
2346      NCF_CHECK(nctk_set_collective(ncid, varid))
2347 
2348      do ispden=1,nspden
2349        ncerr = nf90_put_var(ncid, varid, datar(:,ispden), start=[1,1,1,i3_glob,ispden], &
2350                 count=[cplex,n1,n2,n3/nproc_fft,1])
2351        NCF_CHECK(ncerr)
2352      end do
2353    else
2354      ! MPI-FFT without MPI-IO. Collect data (requires more memory and communication)
2355      ABI_MALLOC(glob_datar, (cplex*product(ngfft(1:3)), nspden))
2356      call collect_datar(ngfft,cplex,nfft,nspden,datar,comm_fft,fftn3_distrib,ffti3_local,glob_datar,master=master)
2357 
2358      if (ionode) then
2359        ! Write global array.
2360        NCF_CHECK(nf90_put_var(ncid, varid, glob_datar, start=[1,1,1,1,1], count=[cplex,n1,n2,n3,nspden]))
2361      end if
2362      ABI_FREE(glob_datar)
2363    end if
2364 
2365    if (ionode) then
2366      NCF_CHECK(nf90_close(ncid))
2367    end if
2368  end if
2369 
2370  !ok = .True.
2371  ! Sequential IO
2372  !do rank=0,nproc_fft-1
2373  !  if (rank == me_fft) then
2374  !     ncerr = nf90_open(path, mode=nf90_write, ncid=ncid)
2375  !     do ispden=1,nspden
2376  !       ncerr = nf90_put_var(ncid, varid, datar(1:,ispden), start=[1,1,1,i3_glob,ispden], &
2377  !                count=[cplex,ngfft(1),ngfft(2),ngfft(3)/nproc_fft,1])
2378  !     end do
2379  !     ncerr = nf90_close(ncid)
2380  !  end if
2381  !  call xmpi_barrier(comm_fft)
2382  !end do
2383 
2384 end function nctk_write_datar

m_nctk/nctk_write_dpscalars [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_write_dpscalars

FUNCTION

  Write a list of **scalar** real(dp) variables. Return immediately if error

INPUTS

  ncid=Netcdf identifier.
  varnames(:)=List of strings with the name of the variables
  values(:)=List of real(dp) scalars
  [datamode]=If True, the nc file is set in data mode (default=False)

PARENTS

CHILDREN

SOURCE

1880 integer function nctk_write_dpscalars(ncid, varnames, values, datamode) result(ncerr)
1881 
1882 
1883 !This section has been created automatically by the script Abilint (TD).
1884 !Do not modify the following lines by hand.
1885 #undef ABI_FUNC
1886 #define ABI_FUNC 'nctk_write_dpscalars'
1887 !End of the abilint section
1888 
1889  implicit none
1890 
1891 !Arguments ------------------------------------
1892 !scalars
1893  integer,intent(in) :: ncid
1894  logical,optional,intent(in) :: datamode
1895 !arrays
1896  real(dp),intent(in) :: values(:)
1897  character(len=*),intent(in) :: varnames(:)
1898 
1899 !Local variables-------------------------------
1900 !scalars
1901  integer :: ii,varid
1902 
1903 ! *********************************************************************
1904 
1905  ncerr = nf90_noerr
1906 
1907  ABI_CHECK(size(varnames) == size(values), "Different size in varnames, values")
1908 
1909  if (present(datamode)) then
1910    if (datamode) then
1911      NCF_CHECK(nctk_set_datamode(ncid))
1912    end if
1913  end if
1914 
1915  do ii=1,size(varnames)
1916    NCF_CHECK(nf90_inq_varid(ncid, varnames(ii), varid))
1917    NCF_CHECK(nf90_put_var(ncid, varid, values(ii)))
1918  end do
1919 
1920 end function nctk_write_dpscalars

m_nctk/nctk_write_ibz [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_write_ibz

FUNCTION

  Write the list of the k-points in the IBZ with the corresponding weights in Netcdf format.
  Mainly used for passing data to AbiPy. This routine should be called by master only.

INPUTS

  fname=File name
  kpoints(:,:)=List of k-points
  weights(:)=K-point weights

OUTPUT

  ncerr=Exit status

PARENTS

CHILDREN

SOURCE

2062 integer function nctk_write_ibz(fname, kpoints, weights) result(ncerr)
2063 
2064 
2065 !This section has been created automatically by the script Abilint (TD).
2066 !Do not modify the following lines by hand.
2067 #undef ABI_FUNC
2068 #define ABI_FUNC 'nctk_write_ibz'
2069 !End of the abilint section
2070 
2071  implicit none
2072 
2073 !Arguments ------------------------------------
2074 !scalars
2075  character(len=*),intent(in) :: fname
2076 !arrays
2077  real(dp),intent(in) :: kpoints(:,:),weights(:)
2078 
2079 !Local variables-------------------------------
2080 !scalars
2081  integer :: nkpts,ncid
2082 
2083 ! *********************************************************************
2084 
2085  ABI_CHECK(size(kpoints, dim=2) == size(weights), "size(kpoints, dim=2) != size(weights)")
2086  nkpts = size(kpoints, dim=2)
2087 
2088  NCF_CHECK_MSG(nctk_open_create(ncid, fname, xmpi_comm_self), sjoin("Creating:", fname))
2089 
2090  ncerr = nctk_def_dims(ncid, [ &
2091    nctkdim_t("number_of_reduced_dimensions",3), nctkdim_t("number_of_kpoints", nkpts)], defmode=.True.)
2092  NCF_CHECK(ncerr)
2093 
2094  ncerr = nctk_def_array_list(ncid, [&
2095    nctkarr_t('reduced_coordinates_of_kpoints', "dp", "number_of_reduced_dimensions, number_of_kpoints"),&
2096    nctkarr_t('kpoint_weights', "dp", "number_of_kpoints")])
2097  NCF_CHECK(ncerr)
2098 
2099  NCF_CHECK(nctk_set_datamode(ncid))
2100 
2101  ncerr = nf90_put_var(ncid, nctk_idname(ncid, 'reduced_coordinates_of_kpoints'), kpoints)
2102  NCF_CHECK(ncerr)
2103 
2104  NCF_CHECK(nf90_put_var(ncid, nctk_idname(ncid, 'kpoint_weights'), weights))
2105 
2106  NCF_CHECK(nf90_close(ncid))
2107 
2108 end function nctk_write_ibz

m_nctk/nctk_write_iscalars [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  nctk_write_iscalars

FUNCTION

  Write a list of **scalar** integer variables. Return immediately if error

INPUTS

  ncid=Netcdf identifier.
  varnames(:)=List of strings with the name of the variables
  values(:)=List of integer scalars
  [datamode]=If True, the nc file is set in data mode (default=False)

OUTPUT

  ncerr=Exit status

PARENTS

CHILDREN

SOURCE

1819 integer function nctk_write_iscalars(ncid, varnames, values, datamode) result(ncerr)
1820 
1821 
1822 !This section has been created automatically by the script Abilint (TD).
1823 !Do not modify the following lines by hand.
1824 #undef ABI_FUNC
1825 #define ABI_FUNC 'nctk_write_iscalars'
1826 !End of the abilint section
1827 
1828  implicit none
1829 
1830 !Arguments ------------------------------------
1831 !scalars
1832  integer,intent(in) :: ncid
1833  logical,optional,intent(in) :: datamode
1834 !arrays
1835  integer,intent(in) :: values(:)
1836  character(len=*),intent(in) :: varnames(:)
1837 
1838 !Local variables-------------------------------
1839 !scalars
1840  integer :: ii,varid
1841 
1842 ! *********************************************************************
1843 
1844  ABI_CHECK(size(varnames) == size(values), "Different size in varnames, values")
1845 
1846  ncerr = nf90_noerr
1847  if (present(datamode)) then
1848    if (datamode) then
1849      NCF_CHECK(nctk_set_datamode(ncid))
1850    end if
1851  end if
1852 
1853  do ii=1,size(varnames)
1854    NCF_CHECK(nf90_inq_varid(ncid, varnames(ii), varid))
1855    NCF_CHECK(nf90_put_var(ncid, varid, values(ii)))
1856  end do
1857 
1858 end function nctk_write_iscalars

m_nctk/nctkarr_t [ Types ]

[ Top ] [ m_nctk ] [ Types ]

NAME

 nctkarr_t

FUNCTION

  Stores the name and the shape of a netcdf array

SOURCE

128  type,public :: nctkarr_t
129    character(len=nctk_slen) :: name        ! name of the array.
130    character(len=4) :: dtype               ! string specifying the type.
131    character(len=nctk_slen) :: shape_str   ! string with the shape. e.g. "dim1, dim2" for [dim1, dim2] array.
132  end type nctkarr_t

m_nctk/nctkerr_t [ Types ]

[ Top ] [ m_nctk ] [ Types ]

NAME

 nctkerr_t

FUNCTION

SOURCE

89  type,private :: nctkerr_t
90 #ifdef HAVE_NETCDF
91    integer :: ncerr = nf90_noerr
92 #else
93    integer :: ncerr = 0
94 #endif
95    integer :: line = 0
96    character(len=fnlen) :: file = "Dummy File"
97    character(len=2048) :: msg="No error detected"
98  end type nctkerr_t

m_nctk/nctkvar_t [ Structures ]

[ Top ] [ m_nctk ] [ Structures ]

NAME

  nctkvar_t

FUNCTION

  This structure stores variable information, such as
  name, NetCDF id, type, shape and dimensions. It contains the following elements:

SOURCE

145  type nctkvar_t
146 
147    integer :: id
148    ! the id used by NetCDF to access this variable.
149 
150    integer :: xtype
151    ! the type of the variable
152 
153    integer :: ndims
154    ! the number of dimensions (0 for scalar variable).
155 
156    integer :: natts
157    ! The number of attributes associated to the variable
158 
159    character(len=nctk_slen) :: name
160    ! the variable name.
161 
162    character(len=nctk_slen) :: dimnames(nctk_max_dims)
163    ! the name corresponding to each dimension
164    ! Only if array variable, only (1:ndims) are relevent
165 
166    integer :: dimids(nctk_max_dims) = -1
167    ! The id of the dimensions. only (1:ndims) are relevent
168 
169    integer :: dimlens(nctk_max_dims) = 0
170    ! the size for each dimension if array variable, only (1:ndims) are relevent
171 
172    !character(len=nctk_slen) :: dimnames(nctk_max_dims)
173    !character(len=nctk_slen), pointer :: ncattnames(:)
174    ! * ncattnames: the name corresponding to all associated attributes
175 
176  end type nctkvar_t

m_nctk/str2xtype [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  str2xtype

FUNCTION

  Return the netcdf type from a string. Possible values:
    c or ch   for NF90_CHAR
    i or int  for NF90_INT
   sp         for NF90_FLOAT
   dp         for NF90_DOUBLE

SOURCE

618 integer function str2xtype(string) result(xtype)
619 
620 
621 !This section has been created automatically by the script Abilint (TD).
622 !Do not modify the following lines by hand.
623 #undef ABI_FUNC
624 #define ABI_FUNC 'str2xtype'
625 !End of the abilint section
626 
627   implicit none
628 
629 !This section has been created automatically by the script Abilint (TD).
630 !Do not modify the following lines by hand.
631 #undef ABI_FUNC
632 #define ABI_FUNC 'str2xtype'
633 !End of the abilint section
634 
635 !Arguments ------------------------------------
636  character(len=*),intent(in) :: string
637 
638 ! *********************************************************************
639 
640  !Type  FORTRAN API Mnemonic    Bits
641  !byte      NF90_BYTE           8
642  !char      NF90_CHAR           8
643  !short     NF90_SHORT          16
644  !int       NF90_INT            32
645  !float     NF90_FLOAT          32
646  !double    NF90_DOUBLE         64
647 
648  select case (string)
649  case ("c", "ch", "char")
650    xtype = NF90_CHAR
651  case ("i", "int")
652    xtype = NF90_INT
653  case ("sp")
654    xtype = NF90_FLOAT
655  case ("dp")
656    xtype = NF90_DOUBLE
657  case default
658    MSG_ERROR(sjoin("Invalid string type:", string))
659  end select
660 
661 end function str2xtype

m_nctk/var_from_id [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  var_from_id

FUNCTION

  Initialize a nctkvar_t object from the variable id

INPUTS

  ncid=NC file handle
  varid=Variable ID

OUTPUT

  var<nctkvar_t>=Info on the variable.

PARENTS

      m_nctk

CHILDREN

SOURCE

2719 subroutine var_from_id(ncid, varid, var)
2720 
2721 
2722 !This section has been created automatically by the script Abilint (TD).
2723 !Do not modify the following lines by hand.
2724 #undef ABI_FUNC
2725 #define ABI_FUNC 'var_from_id'
2726 !End of the abilint section
2727 
2728  implicit none
2729 
2730 !Arguments ------------------------------------
2731  integer, intent(in) :: ncid, varid
2732  type(nctkvar_t), intent(out) :: var
2733 
2734 !Local variables-------------------------------
2735 !scalars
2736  integer :: ii, ncerr
2737  !character(len=NF90_MAX_NAME) :: ncname
2738 
2739 ! *********************************************************************
2740 
2741  ! Get info about the variable.
2742  var%id = varid
2743  ncerr = nf90_inquire_variable(ncid, var%id, &
2744    name=var%name, xtype=var%xtype, ndims=var%ndims, dimids=var%dimids, natts=var%natts)
2745  NCF_CHECK(ncerr)
2746 
2747  ! Get info about dimensions.
2748  if (var%ndims > 0) then
2749    do ii=1,var%ndims
2750      ncerr = nf90_inquire_dimension(ncid, var%dimids(ii), len=var%dimlens(ii), name=var%dimnames(ii))
2751      NCF_CHECK(ncerr)
2752    end do
2753  end if
2754 
2755  ! Get the number of attributes and their names.
2756  !if (var%natts > 0) then
2757  !   do ii=1,var%natts
2758  !      ncerr = nf90_inq_attname(ncid, var%id, ii, var%attnames(ii))
2759  !   end do
2760  !end if
2761 
2762 end subroutine var_from_id

m_nctk/var_from_name [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

  var_from_name

FUNCTION

  Initialize a nctkvar_t object from the variable name

INPUTS

  ncid=NC file handle
  name=Variable name

OUTPUT

  var<nctkvar_t>=Info on the variable.

PARENTS

CHILDREN

SOURCE

2787 subroutine var_from_name(ncid, name, var)
2788 
2789 
2790 !This section has been created automatically by the script Abilint (TD).
2791 !Do not modify the following lines by hand.
2792 #undef ABI_FUNC
2793 #define ABI_FUNC 'var_from_name'
2794 !End of the abilint section
2795 
2796  implicit none
2797 
2798 !Arguments ------------------------------------
2799  integer, intent(in) :: ncid
2800  character(len=*),intent(in) :: name
2801  type(nctkvar_t), intent(out) :: var
2802 
2803 !Local variables-------------------------------
2804 !scalars
2805  integer :: varid
2806 
2807 ! *********************************************************************
2808 
2809  varid = nctk_idname(ncid, name)
2810  call var_from_id(ncid, varid, var)
2811 
2812 end subroutine var_from_name

m_nctk/write_var_netcdf [ Functions ]

[ Top ] [ m_nctk ] [ Functions ]

NAME

 write_var_netcdf

FUNCTION

 Write variable into a netcdf dataset

 TODO:
  Remove!

INPUTS

 arr_int
 arr_real
 marr
 narr
 typevar
 varname

OUTPUT

  (only writing)

PARENTS

      prttagm,prttagm_images

CHILDREN

SOURCE

2990 subroutine write_var_netcdf(arr_int,arr_real,marr,narr,ncid,typevar,varname)
2991 
2992 
2993 !This section has been created automatically by the script Abilint (TD).
2994 !Do not modify the following lines by hand.
2995 #undef ABI_FUNC
2996 #define ABI_FUNC 'write_var_netcdf'
2997 !End of the abilint section
2998 
2999 implicit none
3000 
3001 !Arguments ------------------------------------
3002 !scalars
3003  integer,intent(in) :: narr,marr,ncid
3004  character(len=*),intent(in) :: varname
3005  character(len=3),intent(in) :: typevar
3006 !arrays
3007  integer,intent(in) :: arr_int(marr)
3008  real(dp),intent(in) :: arr_real(marr)
3009 
3010 !Local variables-------------------------------
3011 !scalars
3012  integer :: var_id,var_type,vardim_id,ncerr
3013  !character(len=500) :: msg
3014 
3015 ! *************************************************************************
3016 
3017  !write(std_out,*)"about to write varname: ",trim(varname)
3018 
3019 #if defined HAVE_NETCDF
3020  if (ncid>0) then
3021 !  ### Put the file in definition mode
3022    ncerr=nf90_redef(ncid)
3023    if (ncerr/=NF90_NOERR.and.ncerr/=NF90_EINDEFINE) then
3024      NCF_CHECK_MSG(ncerr,'nf90_redef')
3025    end if
3026 !  ### Define the dimensions
3027    if (narr==1)then
3028      ncerr=nf90_inq_dimid(ncid,'one',vardim_id)
3029      NCF_CHECK_MSG(ncerr,'nf90_inq_varid')
3030    else
3031      ncerr=nf90_def_dim(ncid,trim(varname),narr,vardim_id)
3032      NCF_CHECK_MSG(ncerr,'nf90_def_dim')
3033    end if
3034 !  ### Define the variables
3035    if (typevar=='INT') then
3036      var_type=NF90_INT
3037    else if (typevar=='DPR') then
3038      var_type=NF90_DOUBLE
3039    end if
3040    ncerr=nf90_def_var(ncid, trim(varname), var_type, vardim_id, var_id)
3041    NCF_CHECK_MSG(ncerr,'nf90_def_var')
3042 !  ### Put the file in data mode
3043    ncerr=nf90_enddef(ncid)
3044    if (ncerr/=NF90_NOERR.and.ncerr/=NF90_ENOTINDEFINE) then
3045      NCF_CHECK_MSG(ncerr,'nf90_enddef')
3046    end if
3047 !  ### Write variables into the dataset
3048    if (typevar=='INT') then
3049      ncerr=nf90_put_var(ncid,var_id,arr_int,start=(/1/),count=(/narr/))
3050    else if (typevar=='DPR') then
3051      ncerr=nf90_put_var(ncid,var_id,arr_real,start=(/1/),count=(/narr/))
3052    end if
3053    NCF_CHECK_MSG(ncerr,'nf90_put_var')
3054  end if
3055 #endif
3056 
3057 end subroutine write_var_netcdf