t_ncfile Derived Type

type, public :: t_ncfile


Inherited by

type~~t_ncfile~~InheritedByGraph type~t_ncfile t_ncfile type~t_boundaryfromfile t_boundaryFromFile type~t_boundaryfromfile->type~t_ncfile nc type~t_hmap_axisnb t_hmap_axisNB type~t_hmap_axisnb->type~t_ncfile nc

Components

Type Visibility Attributes Name Initial
integer, public :: nc_id
integer, public :: ioError
logical, public :: isopen
character(len=1), public :: rwo_mode
character(len=255), public :: Filename

Type-Bound Procedures

procedure, public :: openfile => ncfile_openfile

  • public subroutine ncfile_openfile(sf)

    open netcdf file

    Arguments

    Type IntentOptional Attributes Name
    class(t_ncfile), intent(inout) :: sf

    self

procedure, public :: closefile => ncfile_closefile

  • public subroutine ncfile_closefile(sf)

    close netcdf file

    Arguments

    Type IntentOptional Attributes Name
    class(t_ncfile), intent(inout) :: sf

    self

procedure, public :: var_exists => ncfile_var_exists

  • public function ncfile_var_exists(sf, varname_in) result(exists)

    check if variable name exists (also including groups separated with "/")

    Arguments

    Type IntentOptional Attributes Name
    class(t_ncfile), intent(inout) :: sf

    self

    character(len=*), intent(in) :: varname_in

    name of the variable (can include "/" for groups)

    Return Value logical

procedure, public :: get_var_ndims => ncfile_get_var_ndims

  • public function ncfile_get_var_ndims(sf, varname_in) result(ndims_out)

    get the number of dimensions of a variable

    Arguments

    Type IntentOptional Attributes Name
    class(t_ncfile), intent(inout) :: sf

    self

    character(len=*), intent(in) :: varname_in

    name of the variable (can include "/" for groups)

    Return Value integer

procedure, public :: get_var_dims => ncfile_get_var_dims

  • public function ncfile_get_var_dims(sf, varname_in, ndims_in, transpose_in) result(dims_out)

    get the size of a ulti-dimensional array for all dimensions ndims

    Arguments

    Type IntentOptional Attributes Name
    class(t_ncfile), intent(inout) :: sf

    self

    character(len=*), intent(in) :: varname_in

    name of the multi-dimensional array (can include "/" for groups)

    integer, intent(in) :: ndims_in

    number of dimensions in the array

    logical, intent(in), optional :: transpose_in

    transpose the data array, default is true, because of fortran ordering

    Return Value integer, (ndims_in)

    size of each dimension of the array

procedure, public :: get_scalar => ncfile_get_scalar

  • public subroutine ncfile_get_scalar(sf, varname_in, intout, realout)

    get integer or real scalar (depends on optional argument) abort if variable does not exist. USE var_exists for checking

    Arguments

    Type IntentOptional Attributes Name
    class(t_ncfile), intent(inout) :: sf

    self

    character(len=*), intent(in) :: varname_in

    name of the variable (can include "/" for groups)

    integer, intent(out), optional :: intout

    choose for integer out

    real(kind=wp), intent(out), optional :: realout

    choose for real(wp) out (double)

procedure, public :: get_array => ncfile_get_array

  • public subroutine ncfile_get_array(sf, varname_in, transpose_in, intout_1d, realout_1d, intout_2d, realout_2d, intout_3d, realout_3d, intout_4d, realout_4d)

    get integer or real array of dimension 1d,2d,3d,4d (depends on optional argument) netcdf call get_var knows type and dimensions directly from argument abort if variable does not exist. USE var_exists for checking

    Arguments

    Type IntentOptional Attributes Name
    class(t_ncfile), intent(inout) :: sf

    self

    character(len=*), intent(in) :: varname_in

    name of the variable (can include "/" for groups)

    logical, intent(in), optional :: transpose_in

    transpose the data array, default is true, because of fortran ordering

    integer, intent(out), optional :: intout_1d(:)

    choose for integer out 1d array

    real(kind=wp), intent(out), optional :: realout_1d(:)

    choose for real(wp) out (double) 1d array

    integer, intent(out), optional :: intout_2d(:,:)

    choose for integer out 2d array

    real(kind=wp), intent(out), optional :: realout_2d(:,:)

    choose for real(wp) out (double) 2d array

    integer, intent(out), optional :: intout_3d(:,:,:)

    choose for integer out 3d array

    real(kind=wp), intent(out), optional :: realout_3d(:,:,:)

    choose for real(wp) out (double) 3d array

    integer, intent(out), optional :: intout_4d(:,:,:,:)

    choose for integer out 4d array

    real(kind=wp), intent(out), optional :: realout_4d(:,:,:,:)

    choose for real(wp) out (double) 4darray

procedure, public :: def_dim => ncfile_def_dim

  • public subroutine ncfile_def_dim(sf, dimname_in, dimlen, dimid)

    define a dimension to the netCDF file

    Arguments

    Type IntentOptional Attributes Name
    class(t_ncfile), intent(inout) :: sf

    self

    character(len=*), intent(in) :: dimname_in

    name of the dimension

    integer, intent(in) :: dimlen

    length of the dimension

    integer, intent(out) :: dimid

    id of the dimension

procedure, public :: end_def_mode => ncfile_end_def_mode

  • public subroutine ncfile_end_def_mode(sf)

    after creating a new file and making all definitions, one has to call end_def_mode

    Arguments

    Type IntentOptional Attributes Name
    class(t_ncfile), intent(inout) :: sf

    self

procedure, public :: put_scalar => ncfile_put_scalar

  • public subroutine ncfile_put_scalar(sf, varname_in, def_put_mode, int_in, real_in)

    define and put a scalar value to the netCDF file

    Arguments

    Type IntentOptional Attributes Name
    class(t_ncfile), intent(inout) :: sf

    self

    character(len=*), intent(in) :: varname_in

    name of the variable

    integer, intent(in) :: def_put_mode

    1:"def" or 2:"put" mode

    integer, intent(in), optional :: int_in

    scalar integer input

    real(kind=wp), intent(in), optional :: real_in

    scalar double input

procedure, public :: put_attr_char => ncfile_put_attributes_char

  • public subroutine ncfile_put_attributes_char(sf, varname_in, n_attr, attrs_names, attr_values)

    Arguments

    Type IntentOptional Attributes Name
    class(t_ncfile), intent(inout) :: sf

    self

    character(len=*), intent(in) :: varname_in

    name of the variable

    integer, intent(in) :: n_attr

    number of attributes

    character(len=*), intent(in) :: attrs_names(:)

    Array of attribute names

    character(len=*), intent(in) :: attr_values(:)

    double input

procedure, public :: put_char => ncfile_put_char

  • public subroutine ncfile_put_char(sf, varname_in, dimid, def_put_mode, char_in)

    define and put a char to the netCDF file as a string NOTE: This is only used for naming coordinate directions with a single character

    Arguments

    Type IntentOptional Attributes Name
    class(t_ncfile), intent(inout) :: sf

    self

    character(len=*), intent(in) :: varname_in

    name of the variable

    integer, intent(in) :: dimid

    ids of dimensions, must be created before by put_dim

    integer, intent(in) :: def_put_mode

    1:"def" or 2:"put" mode

    character(len=*), intent(in) :: char_in

    double input

procedure, public :: put_array => ncfile_put_array

  • public subroutine ncfile_put_array(sf, varname_in, ndims_var, dims, dimids, def_put_mode, transpose_in, int_in, real_in)

    define and put an array value to the netCDF file

    Arguments

    Type IntentOptional Attributes Name
    class(t_ncfile), intent(inout) :: sf

    self

    character(len=*), intent(in) :: varname_in

    name of the variable

    integer, intent(in) :: ndims_var

    number of dimensions

    integer, intent(in) :: dims(1:ndims_var)

    number of dimensions

    integer, intent(in) :: dimids(1:ndims_var)

    ids of dimensions, must be created before by put_dim

    integer, intent(in) :: def_put_mode

    1:"def" or 2:"put" mode

    logical, intent(in), optional :: transpose_in

    transpose the data array, default is true, because of fortran ordering

    integer, intent(in), optional :: int_in(PRODUCT(dims))

    integer input

    real(kind=wp), intent(in), optional :: real_in(PRODUCT(dims))

    double input

procedure, public :: enter_groups => ncfile_enter_groups

  • public subroutine ncfile_enter_groups(sf, varname_in, grpid, varname, exists)

    if variable name contains "/", these are interpreted as groups/subgroups. split the varname at first occurence of "/" to get the first group name on the file level. Then get the group id. repeat until no "/" is found anymore. output the final groupid and the variable name without the group names.

    Arguments

    Type IntentOptional Attributes Name
    class(t_ncfile), intent(inout) :: sf

    self

    character(len=*), intent(in) :: varname_in

    name of the variable (can include "/" for groups)

    integer, intent(out) :: grpid

    id of the last group found

    character(len=255), intent(out) :: varname

    name of the variable without groups

    logical, intent(out) :: exists

procedure, public :: handle_error => ncfile_handle_error

  • public subroutine ncfile_handle_error(sf, errmsg)

    netcdf error handling via sf%ioError variable

    Arguments

    Type IntentOptional Attributes Name
    class(t_ncfile), intent(inout) :: sf

    self

    character(len=*), intent(in) :: errmsg

procedure, public :: free => ncfile_free

  • public subroutine ncfile_free(sf)

    closes file and frees variable

    Arguments

    Type IntentOptional Attributes Name
    class(t_ncfile), intent(inout) :: sf

    self

Source Code

TYPE :: t_ncfile
  INTEGER  :: nc_id
  INTEGER  :: ioError
  LOGICAL  :: isopen
  CHARACTER(LEN=1)  :: rwo_mode
  CHARACTER(LEN=255) :: Filename
  CONTAINS
  PROCEDURE :: openfile       => ncfile_openfile
  PROCEDURE :: closefile      => ncfile_closefile
  PROCEDURE :: var_exists     => ncfile_var_exists
  PROCEDURE :: get_var_ndims  => ncfile_get_var_ndims
  PROCEDURE :: get_var_dims   => ncfile_get_var_dims
  PROCEDURE :: get_scalar     => ncfile_get_scalar
  PROCEDURE :: get_array      => ncfile_get_array
  PROCEDURE :: def_dim        => ncfile_def_dim
  PROCEDURE :: end_def_mode   => ncfile_end_def_mode
  PROCEDURE :: put_scalar     => ncfile_put_scalar
  PROCEDURE :: put_attr_char  => ncfile_put_attributes_char
  PROCEDURE :: put_char     => ncfile_put_char
  PROCEDURE :: put_array      => ncfile_put_array
  PROCEDURE :: enter_groups   => ncfile_enter_groups
  PROCEDURE :: handle_error   => ncfile_handle_error
  PROCEDURE :: free   => ncfile_free

END TYPE t_ncfile