Test_NetCDF4_FileFormatter.pf Source File


This file depends on

sourcefile~~test_netcdf4_fileformatter.pf~~EfferentGraph sourcefile~test_netcdf4_fileformatter.pf Test_NetCDF4_FileFormatter.pf sourcefile~filemetadata.f90 FileMetadata.F90 sourcefile~test_netcdf4_fileformatter.pf->sourcefile~filemetadata.f90 sourcefile~netcdf4_fileformatter.f90 NetCDF4_FileFormatter.F90 sourcefile~test_netcdf4_fileformatter.pf->sourcefile~netcdf4_fileformatter.f90 sourcefile~pfio_constants.f90 pFIO_Constants.F90 sourcefile~test_netcdf4_fileformatter.pf->sourcefile~pfio_constants.f90 sourcefile~variable.f90 Variable.F90 sourcefile~test_netcdf4_fileformatter.pf->sourcefile~variable.f90 sourcefile~filemetadata.f90->sourcefile~pfio_constants.f90 sourcefile~filemetadata.f90->sourcefile~variable.f90 sourcefile~attribute.f90 Attribute.F90 sourcefile~filemetadata.f90->sourcefile~attribute.f90 sourcefile~coordinatevariable.f90 CoordinateVariable.F90 sourcefile~filemetadata.f90->sourcefile~coordinatevariable.f90 sourcefile~mapl_exceptionhandling.f90 MAPL_ExceptionHandling.F90 sourcefile~filemetadata.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~mapl_keywordenforcer.f90 MAPL_KeywordEnforcer.F90 sourcefile~filemetadata.f90->sourcefile~mapl_keywordenforcer.f90 sourcefile~pfio_utilities.f90 pFIO_Utilities.F90 sourcefile~filemetadata.f90->sourcefile~pfio_utilities.f90 sourcefile~stringintegermaputil.f90 StringIntegerMapUtil.F90 sourcefile~filemetadata.f90->sourcefile~stringintegermaputil.f90 sourcefile~stringvariablemap.f90 StringVariableMap.F90 sourcefile~filemetadata.f90->sourcefile~stringvariablemap.f90 sourcefile~stringvectorutil.f90 StringVectorUtil.F90 sourcefile~filemetadata.f90->sourcefile~stringvectorutil.f90 sourcefile~unlimitedentity.f90 UnlimitedEntity.F90 sourcefile~filemetadata.f90->sourcefile~unlimitedentity.f90 sourcefile~netcdf4_fileformatter.f90->sourcefile~filemetadata.f90 sourcefile~netcdf4_fileformatter.f90->sourcefile~pfio_constants.f90 sourcefile~netcdf4_fileformatter.f90->sourcefile~variable.f90 sourcefile~netcdf4_fileformatter.f90->sourcefile~attribute.f90 sourcefile~netcdf4_fileformatter.f90->sourcefile~coordinatevariable.f90 sourcefile~netcdf4_fileformatter.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~netcdf4_fileformatter.f90->sourcefile~mapl_keywordenforcer.f90 sourcefile~netcdf_supplement.f90 NetCDF_Supplement.F90 sourcefile~netcdf4_fileformatter.f90->sourcefile~netcdf_supplement.f90 sourcefile~netcdf4_fileformatter.f90->sourcefile~stringvariablemap.f90 sourcefile~netcdf4_fileformatter.f90->sourcefile~unlimitedentity.f90 sourcefile~variable.f90->sourcefile~pfio_constants.f90 sourcefile~variable.f90->sourcefile~attribute.f90 sourcefile~variable.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~variable.f90->sourcefile~mapl_keywordenforcer.f90 sourcefile~variable.f90->sourcefile~pfio_utilities.f90 sourcefile~variable.f90->sourcefile~stringvectorutil.f90 sourcefile~variable.f90->sourcefile~unlimitedentity.f90 sourcefile~attribute.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~attribute.f90->sourcefile~pfio_utilities.f90 sourcefile~attribute.f90->sourcefile~unlimitedentity.f90 sourcefile~coordinatevariable.f90->sourcefile~pfio_constants.f90 sourcefile~coordinatevariable.f90->sourcefile~variable.f90 sourcefile~coordinatevariable.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~coordinatevariable.f90->sourcefile~mapl_keywordenforcer.f90 sourcefile~coordinatevariable.f90->sourcefile~pfio_utilities.f90 sourcefile~mapl_errorhandling.f90 MAPL_ErrorHandling.F90 sourcefile~mapl_exceptionhandling.f90->sourcefile~mapl_errorhandling.f90 sourcefile~mapl_throw.f90 MAPL_Throw.F90 sourcefile~mapl_exceptionhandling.f90->sourcefile~mapl_throw.f90 sourcefile~pfio_utilities.f90->sourcefile~pfio_constants.f90 sourcefile~pfio_utilities.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~stringintegermaputil.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~stringintegermaputil.f90->sourcefile~pfio_utilities.f90 sourcefile~stringvariablemap.f90->sourcefile~variable.f90 sourcefile~stringvariablemap.f90->sourcefile~coordinatevariable.f90 sourcefile~stringvariablemap.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~stringvariablemap.f90->sourcefile~pfio_utilities.f90 sourcefile~stringvectorutil.f90->sourcefile~attribute.f90 sourcefile~stringvectorutil.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~stringvectorutil.f90->sourcefile~pfio_utilities.f90 sourcefile~unlimitedentity.f90->sourcefile~pfio_constants.f90 sourcefile~unlimitedentity.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~unlimitedentity.f90->sourcefile~pfio_utilities.f90 sourcefile~mapl_errorhandling.f90->sourcefile~mapl_throw.f90

Source Code

module Test_NetCDF4_FileFormatter
   use pfunit
   use pFIO_NetCDF4_FileFormatterMod
   use pFIO_FileMetadataMod
   use pFIO_VariableMod
   use pFIO_ConstantsMod
   use netcdf
   implicit none


contains

   @before
   subroutine setup()
   end subroutine setup

   @after
   subroutine tearDown()
      integer :: unit

      open(newunit=unit, file='test.nc', status='old')
      close(unit, status='delete')
      
   end subroutine tearDown

   @test
   subroutine test_write_read_trivial()
      type (NetCDF4_FileFormatter) :: formatter
      type (FileMetadata) :: cf_expected
      type (FileMetadata) :: cf_found
      integer :: status

      call cf_expected%add_dimension('x',1)

      call formatter%create('test.nc', rc=status)
      @assertEqual(NF90_NOERR, status)
      call formatter%write(cf_expected, rc=status)
      @assertEqual(0, NF90_NOERR)
      call formatter%close(rc=status)
      @assertEqual(0, NF90_NOERR)

      call formatter%open('test.nc', mode=NF90_NOWRITE, rc=status)
      @assertEqual(0, NF90_NOERR)
      cf_found = formatter%read(rc=status)
      call formatter%close(rc=status)
      @assertEqual(0, NF90_NOERR)

      @assertTrue(cf_expected == cf_found)

   end subroutine test_write_read_trivial

   @test
   subroutine test_write_read_simple_variable()
      type (NetCDF4_FileFormatter) :: formatter
      type (FileMetadata) :: cf_expected
      type (FileMetadata) :: cf_found
      integer :: status

      call cf_expected%add_dimension('x',1)
      call cf_expected%add_dimension('y',2)
      call cf_expected%add_variable('var', Variable(type=pFIO_INT32, dimensions='x,y'))

      call formatter%create('test.nc', rc=status)
      @assertEqual(NF90_NOERR, status)
      call formatter%write(cf_expected, rc=status)
      @assertEqual(0, NF90_NOERR)
      call formatter%close(rc=status)
      @assertEqual(0, NF90_NOERR)

      call formatter%open('test.nc', mode=NF90_NOWRITE, rc=status)
      @assertEqual(0, NF90_NOERR)
      cf_found = formatter%read(rc=status)
      call formatter%close(rc=status)
      @assertEqual(0, NF90_NOERR)

      @assertTrue(cf_expected == cf_found)

   end subroutine test_write_read_simple_variable

   @test
   subroutine test_write_read_simple_attribute()
      type (NetCDF4_FileFormatter) :: formatter
      type (FileMetadata) :: cf_expected
      type (FileMetadata) :: cf_found
      integer :: status

      call cf_expected%add_dimension('x',1)
      call cf_expected%add_dimension('y',2)
      call cf_expected%add_attribute('attr', [1,2])

      call formatter%create('test.nc', rc=status)
      @assertEqual(NF90_NOERR, status)
      call formatter%write(cf_expected, rc=status)
      @assertEqual(0, NF90_NOERR)
      call formatter%close(rc=status)
      @assertEqual(0, NF90_NOERR)

      call formatter%open('test.nc', mode=NF90_NOWRITE, rc=status)
      @assertEqual(0, NF90_NOERR)
      cf_found = formatter%read(rc=status)
      call formatter%close(rc=status)
      @assertEqual(0, NF90_NOERR)

      @assertTrue(cf_expected == cf_found)

   end subroutine test_write_read_simple_attribute

   @test
   subroutine test_write_read_variable_attribute()
      type (NetCDF4_FileFormatter) :: formatter
      type (FileMetadata) :: cf_expected
      type (FileMetadata) :: cf_found
      type (Variable) :: v
      integer :: status

      call cf_expected%add_dimension('x',1)
      call cf_expected%add_dimension('y',2)

      v = Variable(type=pFIO_INT32, dimensions='x,y')
      call v%add_attribute('attr', [1.,2.,3.])
      call cf_expected%add_variable('var', v)

      call formatter%create('test.nc', rc=status)
      @assertEqual(NF90_NOERR, status)
      call formatter%write(cf_expected, rc=status)
      @assertEqual(0, NF90_NOERR)
      call formatter%close(rc=status)
      @assertEqual(0, NF90_NOERR)

      call formatter%open('test.nc', mode=NF90_NOWRITE, rc=status)
      @assertEqual(0, NF90_NOERR)
      cf_found = formatter%read(rc=status)
      call formatter%close(rc=status)
      @assertEqual(0, NF90_NOERR)

      @assertTrue(cf_expected == cf_found)

   end subroutine test_write_read_variable_attribute

   @test
   subroutine test_add_variable()
      type (NetCDF4_FileFormatter) :: formatter
      type (FileMetadata) :: cf_expected
      type (FileMetadata) :: cf_found
      type (Variable) :: v,v1
      integer :: status

      call cf_expected%add_dimension('x',1)
      call cf_expected%add_dimension('y',2)

      v = Variable(type=pFIO_INT32, dimensions='x,y')
      call v%add_attribute('attr', [1.,2.,3.])
      call cf_expected%add_variable('var', v)

      call formatter%create('test.nc', rc=status)
      @assertEqual(NF90_NOERR, status)
      call formatter%write(cf_expected, rc=status)
      @assertEqual(0, NF90_NOERR)
      call formatter%close(rc=status)
      @assertEqual(0, NF90_NOERR)

      call formatter%open('test.nc', mode=NF90_WRITE, rc=status)
      @assertEqual(NF90_NOERR, status)
      v1 = Variable(type=pFIO_INT32, dimensions='x,y')
      call cf_expected%add_variable('new_var', v1)
      call formatter%add_variable(cf_expected,'new_var', rc=status)
      call formatter%close(rc=status)
      @assertEqual(0, NF90_NOERR)

      call formatter%open('test.nc', mode=NF90_NOWRITE, rc=status)
      @assertEqual(0, NF90_NOERR)
      cf_found = formatter%read(rc=status)
      call formatter%close(rc=status)
      @assertEqual(0, NF90_NOERR)

      @assertTrue(cf_expected == cf_found)

   end subroutine test_add_variable

end module Test_NetCDF4_FileFormatter