HistoryCollection.F90 Source File


This file depends on

sourcefile~~historycollection.f90~~EfferentGraph sourcefile~historycollection.f90 HistoryCollection.F90 sourcefile~filemetadata.f90 FileMetadata.F90 sourcefile~historycollection.f90->sourcefile~filemetadata.f90 sourcefile~mapl_exceptionhandling.f90 MAPL_ExceptionHandling.F90 sourcefile~historycollection.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~netcdf4_fileformatter.f90 NetCDF4_FileFormatter.F90 sourcefile~historycollection.f90->sourcefile~netcdf4_fileformatter.f90 sourcefile~pfio_constants.f90 pFIO_Constants.F90 sourcefile~historycollection.f90->sourcefile~pfio_constants.f90 sourcefile~pfio_utilities.f90 pFIO_Utilities.F90 sourcefile~historycollection.f90->sourcefile~pfio_utilities.f90 sourcefile~stringvariablemap.f90 StringVariableMap.F90 sourcefile~historycollection.f90->sourcefile~stringvariablemap.f90 sourcefile~filemetadata.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~filemetadata.f90->sourcefile~pfio_constants.f90 sourcefile~filemetadata.f90->sourcefile~pfio_utilities.f90 sourcefile~filemetadata.f90->sourcefile~stringvariablemap.f90 sourcefile~attribute.f90 Attribute.F90 sourcefile~filemetadata.f90->sourcefile~attribute.f90 sourcefile~coordinatevariable.f90 CoordinateVariable.F90 sourcefile~filemetadata.f90->sourcefile~coordinatevariable.f90 sourcefile~keywordenforcer.f90 KeywordEnforcer.F90 sourcefile~filemetadata.f90->sourcefile~keywordenforcer.f90 sourcefile~stringintegermaputil.f90 StringIntegerMapUtil.F90 sourcefile~filemetadata.f90->sourcefile~stringintegermaputil.f90 sourcefile~stringvectorutil.f90 StringVectorUtil.F90 sourcefile~filemetadata.f90->sourcefile~stringvectorutil.f90 sourcefile~unlimitedentity.f90 UnlimitedEntity.F90 sourcefile~filemetadata.f90->sourcefile~unlimitedentity.f90 sourcefile~variable.f90 Variable.F90 sourcefile~filemetadata.f90->sourcefile~variable.f90 sourcefile~errorhandling.f90 ErrorHandling.F90 sourcefile~mapl_exceptionhandling.f90->sourcefile~errorhandling.f90 sourcefile~mapl_throw.f90 MAPL_Throw.F90 sourcefile~mapl_exceptionhandling.f90->sourcefile~mapl_throw.f90 sourcefile~netcdf4_fileformatter.f90->sourcefile~filemetadata.f90 sourcefile~netcdf4_fileformatter.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~netcdf4_fileformatter.f90->sourcefile~pfio_constants.f90 sourcefile~netcdf4_fileformatter.f90->sourcefile~stringvariablemap.f90 sourcefile~netcdf4_fileformatter.f90->sourcefile~attribute.f90 sourcefile~netcdf4_fileformatter.f90->sourcefile~coordinatevariable.f90 sourcefile~netcdf4_fileformatter.f90->sourcefile~keywordenforcer.f90 sourcefile~netcdf_supplement.f90 NetCDF_Supplement.F90 sourcefile~netcdf4_fileformatter.f90->sourcefile~netcdf_supplement.f90 sourcefile~netcdf4_fileformatter.f90->sourcefile~unlimitedentity.f90 sourcefile~netcdf4_fileformatter.f90->sourcefile~variable.f90 sourcefile~pfio_utilities.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~pfio_utilities.f90->sourcefile~pfio_constants.f90 sourcefile~stringvariablemap.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~stringvariablemap.f90->sourcefile~pfio_utilities.f90 sourcefile~stringvariablemap.f90->sourcefile~coordinatevariable.f90 sourcefile~stringvariablemap.f90->sourcefile~variable.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~mapl_exceptionhandling.f90 sourcefile~coordinatevariable.f90->sourcefile~pfio_constants.f90 sourcefile~coordinatevariable.f90->sourcefile~pfio_utilities.f90 sourcefile~coordinatevariable.f90->sourcefile~keywordenforcer.f90 sourcefile~coordinatevariable.f90->sourcefile~variable.f90 sourcefile~errorhandling.f90->sourcefile~mapl_throw.f90 sourcefile~stringintegermaputil.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~stringintegermaputil.f90->sourcefile~pfio_utilities.f90 sourcefile~stringvectorutil.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~stringvectorutil.f90->sourcefile~pfio_utilities.f90 sourcefile~stringvectorutil.f90->sourcefile~attribute.f90 sourcefile~unlimitedentity.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~unlimitedentity.f90->sourcefile~pfio_constants.f90 sourcefile~unlimitedentity.f90->sourcefile~pfio_utilities.f90 sourcefile~variable.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~variable.f90->sourcefile~pfio_constants.f90 sourcefile~variable.f90->sourcefile~pfio_utilities.f90 sourcefile~variable.f90->sourcefile~attribute.f90 sourcefile~variable.f90->sourcefile~keywordenforcer.f90 sourcefile~variable.f90->sourcefile~stringvectorutil.f90 sourcefile~variable.f90->sourcefile~unlimitedentity.f90

Files dependent on this one

sourcefile~~historycollection.f90~~AfferentGraph sourcefile~historycollection.f90 HistoryCollection.F90 sourcefile~multicommserver.f90 MultiCommServer.F90 sourcefile~multicommserver.f90->sourcefile~historycollection.f90 sourcefile~serverthread.f90 ServerThread.F90 sourcefile~multicommserver.f90->sourcefile~serverthread.f90 sourcefile~multigroupserver.f90 MultiGroupServer.F90 sourcefile~multigroupserver.f90->sourcefile~historycollection.f90 sourcefile~multigroupserver.f90->sourcefile~serverthread.f90 sourcefile~multilayerserver.f90 MultiLayerServer.F90 sourcefile~multilayerserver.f90->sourcefile~historycollection.f90 sourcefile~multilayerserver.f90->sourcefile~serverthread.f90 sourcefile~serverthread.f90->sourcefile~historycollection.f90 sourcefile~baseserver.f90 BaseServer.F90 sourcefile~baseserver.f90->sourcefile~serverthread.f90 sourcefile~directoryservice.f90 DirectoryService.F90 sourcefile~directoryservice.f90->sourcefile~serverthread.f90 sourcefile~mockserverthread.f90 MockServerThread.F90 sourcefile~mockserverthread.f90->sourcefile~serverthread.f90 sourcefile~mpiserver.f90 MpiServer.F90 sourcefile~mpiserver.f90->sourcefile~serverthread.f90 sourcefile~openmpserver.f90 OpenMPServer.F90 sourcefile~openmpserver.f90->sourcefile~serverthread.f90 sourcefile~pfio.f90 pFIO.F90 sourcefile~pfio.f90->sourcefile~multicommserver.f90 sourcefile~pfio.f90->sourcefile~multigroupserver.f90 sourcefile~pfio.f90->sourcefile~multilayerserver.f90 sourcefile~pfio.f90->sourcefile~serverthread.f90 sourcefile~serverthreadvector.f90 ServerThreadVector.F90 sourcefile~serverthreadvector.f90->sourcefile~serverthread.f90 sourcefile~test_serverthread.pf Test_ServerThread.pf sourcefile~test_serverthread.pf->sourcefile~serverthread.f90 sourcefile~test_simplesocket.pf Test_SimpleSocket.pf sourcefile~test_simplesocket.pf->sourcefile~serverthread.f90

Source Code

#include "MAPL_ErrLog.h"
#include "unused_dummy.H"

module pFIO_HistoryCollectionMod
  use MAPL_ExceptionHandling
  use gFTL_StringIntegerMap
  use pFIO_NetCDF4_FileFormatterMod
  use pFIO_StringNetCDF4_FileFormatterMapMod
  use pFIO_FileMetadataMod
  use pFIO_StringVariableMapMod
  use pFIO_ConstantsMod
  implicit none
  private

  public :: HistoryCollection
  public :: new_HistoryCollection

  type :: HistoryCollection
    type (Filemetadata) :: fmd
    type (StringNetCDF4_FileFormatterMap) :: formatters

  contains
    procedure :: find => find_
    procedure :: ModifyMetadata
    procedure :: ReplaceMetadata
    procedure :: clear
  end type HistoryCollection

  interface HistoryCollection
    module procedure new_HistoryCollection
  end interface HistoryCollection

contains

  function new_HistoryCollection(fmd) result(collection)
    type (HistoryCollection) :: collection
    type (FilemetaData), intent(in) :: fmd

    collection%fmd = fmd
    collection%formatters = StringNetCDF4_FileFormatterMap()

  end function new_HistoryCollection

  function find_(this, file_name,rc) result(formatter)
    class (HistoryCollection), target, intent(inout) :: this
    character(len=*), intent(in) :: file_name
    integer,optional,intent(out) :: rc

    type (NetCDF4_FileFormatter), pointer :: formatter
    type (NetCDF4_FileFormatter) :: fm

    type(StringNetCDF4_FileFormatterMapIterator) :: iter
    integer :: status
    character(len=*), parameter :: Iam = "HistoryCollection::find()"
    logical :: f_exist

    iter = this%formatters%find(trim(file_name))
    if (iter == this%formatters%end()) then
       inquire(file=file_name, exist=f_exist)
       if(.not. f_exist) then
         call fm%create(trim(file_name),rc=status)
         _VERIFY(status)
         call fm%write(this%fmd, rc=status)
         _VERIFY(status)
       else
          call fm%open(trim(file_name), pFIO_WRITE, _RC)
       endif
       call this%formatters%insert( trim(file_name),fm)
       iter = this%formatters%find(trim(file_name))
    end if
    formatter => iter%value()
    _RETURN(_SUCCESS)
   end function find_

  subroutine  ModifyMetadata(this,var_map,rc)
    class (HistoryCollection), target, intent(inout) :: this
    type (StringVariableMap), target, intent(in) :: var_map
    integer, optional, intent(out) :: rc

    type(StringVariableMapIterator) :: iter
    integer :: status
    character(len=*), parameter :: Iam = "HistoryCollection::ModifyMetadata()"

    iter = var_map%ftn_begin()
    do while (iter /= var_map%ftn_end())
       call iter%next()

       call this%fmd%modify_variable(iter%first(), iter%second(), _RC)
    enddo

    _RETURN(_SUCCESS)
  end subroutine ModifyMetadata

  subroutine  ReplaceMetadata(this, fmd,rc)
    class (HistoryCollection), intent(inout) :: this
    type (FileMetadata), intent(in) :: fmd
    integer, optional, intent(out) :: rc

    character(len=*), parameter :: Iam = "HistoryCollection::ReplaceMetadata()"

    this%fmd = fmd

    _RETURN(_SUCCESS)
  end subroutine ReplaceMetadata

  subroutine clear(this, rc)
    class (HistoryCollection), target, intent(inout) :: this
    integer, optional, intent(out) :: rc

    type(NetCDF4_FileFormatter), pointer :: f_ptr
    type(StringNetCDF4_FileFormatterMapIterator) :: iter
    character(:),pointer :: file_name
    integer :: status

    iter = this%formatters%begin()
    do while (iter /= this%formatters%end())
      file_name => iter%key()
      f_ptr => this%formatters%at(file_name)
      call f_ptr%close(rc=status)
      _VERIFY(status)
      ! remove the files
      call this%formatters%erase(iter)
      iter = this%formatters%begin()
    enddo
    _RETURN(_SUCCESS)
  end subroutine clear

end module pFIO_HistoryCollectionMod


module pFIO_HistoryCollectionVectorMod
   use pFIO_HistoryCollectionMod

   ! Create a map (associative array) between names and pFIO_Attributes.

#define _type type (HistoryCollection)
#define _vector HistoryCollectionVector
#define _iterator HistoryCollectionVectorIterator

#include "templates/vector.inc"

end module pFIO_HistoryCollectionVectorMod

module pFIO_HistoryCollectionVectorUtilMod
   use pFIO_FileMetadataMod
   use pFIO_HistoryCollectionMod
   use pFIO_HistoryCollectionVectorMod
   use pFIO_UtilitiesMod
   implicit none
   private

   public:: HistoryCollectionVector_serialize
   public:: HistoryCollectionVector_deserialize

contains

  subroutine HistoryCollectionVector_serialize(histVec,buffer)
     type (HistoryCollectionVector),intent(in) :: histVec
     integer, allocatable,intent(inout) :: buffer(:)
     integer, allocatable :: tmp(:)
     type (HistoryCollection),pointer :: hist_ptr
     integer :: n, i

     if (allocated(buffer)) deallocate(buffer)
     allocate(buffer(0))

     n = histVec%size()
     do i = 1, n
        hist_ptr=>histVec%at(i)
        call hist_ptr%fmd%serialize(tmp)
        buffer = [buffer,tmp]
     enddo

  end subroutine

  subroutine HistoryCollectionVector_deserialize(buffer, histVec)
     type (HistoryCollectionVector),intent(inout) :: histVec
     integer, intent(in) :: buffer(:)
     type (HistoryCollection) :: hist
     type (FileMetadata) :: fmd
     integer :: n, length, fmd_len

     length = size(buffer)
     n=1
     fmd = FileMetadata()
     histVec = HistoryCollectionVector()
     do while (n < length)
       hist = HistoryCollection(fmd)
       call FileMetadata_deserialize(buffer(n:), hist%fmd)
       call histVec%push_back(hist)
       call deserialize_intrinsic(buffer(n:),fmd_len)
       n = n + fmd_len
     enddo
  end subroutine

end module pFIO_HistoryCollectionVectorUtilMod