function ice_io_test ( )

%*****************************************************************************80
%
%% ice_io_test() tests ice_io().
%
%  Discussion:
%
%    We begin by creating a file.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    22 December 2022
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Russ Rew, Glenn Davis, Steve Emmerson, Harvey Davies, Ed Hartne,
%    The NETCDF User's Guide,
%    Unidata Program Center, March 2009.
%
  addpath ( '../ice_io' );

  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'ice_io_test():\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version );
  fprintf ( 1, '  Test ice_io().\n' );
%
%  Create 'hexahexa_2x2x2.nc'
%
  filename = 'hexahexa_2x2x2.nc';
  ice_io_test01 ( @hexahexa_2x2x2, filename );
%
%  Read 'hexahexa_2x2x2.nc'
%
  ice_io_test02 ( filename );
%
%  Create 'cyl248.nc'
%
  filename = 'cyl248.nc';
  ice_io_test01 ( @cyl248, filename );
%
%  Read 'cyl248.nc'
%
  ice_io_test02 ( filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'ice_io_test():\n' );
  fprintf ( 1, '  Normal end of execution.\n'  );
  fprintf ( 1, '\n' );
  timestamp ( );

  rmpath ( '../ice_io' );

  return
end
function ice_io_test01 ( data_function, filename )

%*****************************************************************************80
%
%% ICE_IO_TEST01 writes an ICE grid dataset to a NETCDF file.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    15 October 2010
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Russ Rew, Glenn Davis, Steve Emmerson, Harvey Davies, Ed Hartne,
%    The NETCDF User's Guide,
%    Unidata Program Center, March 2009.
%
%  Parameters:
%
%    Input, [] function DATA_FUNCTION, a function which defines the
%    data for an ice sheet grid.
%
%    Input, string FILENAME, the name of the file to be created.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'ICE_IO_TEST01:\n' );
  fprintf ( 1, '  Create an ICE grid dataset, print it,\n' );
  fprintf ( 1, '  and write it to an NETCDF file.\n' );
%
%  Get data defining a grid.
%
  [ dim, vertices, vertex_coordinate, vertex_label, edges, ...
    edge_vertex, edge_label, triangles, triangle_vertex, triangle_label, ...
    quadrilaterals, quadrilateral_vertex, quadrilateral_label, tetrahedrons, ...
    tetrahedron_vertex, tetrahedron_label, hexahedrons, hexahedron_vertex, ...
    hexahedron_label ] = data_function ( );
%
%  Print the data.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Data to be written to "%s":\n', filename );

  ice_print ( dim, vertices, vertex_coordinate, ...
    vertex_label, edges, edge_vertex, edge_label, triangles, triangle_vertex, ...
    triangle_label, quadrilaterals, quadrilateral_vertex, ...
    quadrilateral_label, tetrahedrons, tetrahedron_vertex, tetrahedron_label, ...
    hexahedrons, hexahedron_vertex, hexahedron_label );
%
%  Create the file.
%
  ice_write ( filename, dim, vertices, vertex_coordinate, ...
    vertex_label, edges, edge_vertex, edge_label, triangles, triangle_vertex, ...
    triangle_label, quadrilaterals, quadrilateral_vertex, ...
    quadrilateral_label, tetrahedrons, tetrahedron_vertex, tetrahedron_label, ...
    hexahedrons, hexahedron_vertex, hexahedron_label );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Created the file "%s"\n', filename );

  return
end
function ice_io_test02 ( filename )

%*****************************************************************************80
%
%% ICE_IO_TEST02 reads an ICE grid dataset from a NETCDF file.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    15 October 2010
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Russ Rew, Glenn Davis, Steve Emmerson, Harvey Davies, Ed Hartne,
%    The NETCDF User's Guide,
%    Unidata Program Center, March 2009.
%
%  Parameters:
%
%    Input, string FILENAME, the name of the file to be read.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'ICE_IO_TEST02:\n' );
  fprintf ( 1, '  Read an ICE grid dataset from a NETCDF file,\n');
  fprintf ( 1, '  and print the data.\n' );
%
%  Read the file
%
  [ dim, vertices, vertex_coordinate, vertex_label, edges, ...
    edge_vertex, edge_label, triangles, triangle_vertex, triangle_label, ...
    quadrilaterals, quadrilateral_vertex, quadrilateral_label, tetrahedrons, ...
    tetrahedron_vertex, tetrahedron_label, hexahedrons, hexahedron_vertex, ...
    hexahedron_label ] = ice_read ( filename );
%
%  Print the data.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Data from file "%s"\n', filename );

  ice_print ( dim, vertices, vertex_coordinate, ...
    vertex_label, edges, edge_vertex, edge_label, triangles, triangle_vertex, ...
    triangle_label, quadrilaterals, quadrilateral_vertex, ...
    quadrilateral_label, tetrahedrons, tetrahedron_vertex, tetrahedron_label, ...
    hexahedrons, hexahedron_vertex, hexahedron_label );

  return
end
function timestamp ( )

%*****************************************************************************80
%
%% timestamp() prints the current YMDHMS date as a timestamp.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    14 February 2003
%
%  Author:
%
%    John Burkardt
%
  t = now;
  c = datevec ( t );
  s = datestr ( c, 0 );
  fprintf ( 1, '%s\n', s );

  return
end

