FieldBundleWrite.F90 Source File


This file depends on

sourcefile~~fieldbundlewrite.f90~~EfferentGraph sourcefile~fieldbundlewrite.f90 FieldBundleWrite.F90 sourcefile~clientmanager.f90 ClientManager.F90 sourcefile~fieldbundlewrite.f90->sourcefile~clientmanager.f90 sourcefile~griddedio.f90 GriddedIO.F90 sourcefile~fieldbundlewrite.f90->sourcefile~griddedio.f90 sourcefile~griddedioitem.f90 GriddedIOitem.F90 sourcefile~fieldbundlewrite.f90->sourcefile~griddedioitem.f90 sourcefile~mapl_exceptionhandling.f90 MAPL_ExceptionHandling.F90 sourcefile~fieldbundlewrite.f90->sourcefile~mapl_exceptionhandling.f90 sourcefile~mapl_timemethods.f90 MAPL_TimeMethods.F90 sourcefile~fieldbundlewrite.f90->sourcefile~mapl_timemethods.f90 sourcefile~mapl_verticalmethods.f90 MAPL_VerticalMethods.F90 sourcefile~fieldbundlewrite.f90->sourcefile~mapl_verticalmethods.f90 sourcefile~pfio.f90 pFIO.F90 sourcefile~fieldbundlewrite.f90->sourcefile~pfio.f90

Files dependent on this one

sourcefile~~fieldbundlewrite.f90~~AfferentGraph sourcefile~fieldbundlewrite.f90 FieldBundleWrite.F90 sourcefile~mapl.f90 MAPL.F90 sourcefile~mapl.f90->sourcefile~fieldbundlewrite.f90 sourcefile~mapl_bundleio_test.f90 mapl_bundleio_test.F90 sourcefile~mapl_bundleio_test.f90->sourcefile~fieldbundlewrite.f90 sourcefile~regrid_util.f90 Regrid_Util.F90 sourcefile~regrid_util.f90->sourcefile~fieldbundlewrite.f90 sourcefile~regrid_util.f90->sourcefile~mapl.f90 sourcefile~capdriver.f90 CapDriver.F90 sourcefile~capdriver.f90->sourcefile~mapl.f90 sourcefile~extdataroot_gridcomp.f90 ExtDataRoot_GridComp.F90 sourcefile~capdriver.f90->sourcefile~extdataroot_gridcomp.f90 sourcefile~comp_testing_driver.f90 Comp_Testing_Driver.F90 sourcefile~comp_testing_driver.f90->sourcefile~mapl.f90 sourcefile~extdatadriver.f90 ExtDataDriver.F90 sourcefile~extdatadriver.f90->sourcefile~mapl.f90 sourcefile~extdatadrivergridcomp.f90 ExtDataDriverGridComp.F90 sourcefile~extdatadriver.f90->sourcefile~extdatadrivergridcomp.f90 sourcefile~extdatadrivermod.f90 ExtDataDriverMod.F90 sourcefile~extdatadriver.f90->sourcefile~extdatadrivermod.f90 sourcefile~extdatadriver.f90->sourcefile~extdataroot_gridcomp.f90 sourcefile~extdatadrivergridcomp.f90->sourcefile~mapl.f90 sourcefile~extdatadrivermod.f90->sourcefile~mapl.f90 sourcefile~extdatadrivermod.f90->sourcefile~extdatadrivergridcomp.f90 sourcefile~extdatadrivermod.f90->sourcefile~extdataroot_gridcomp.f90 sourcefile~extdataroot_gridcomp.f90->sourcefile~mapl.f90 sourcefile~varspecdescription.f90 VarspecDescription.F90 sourcefile~extdataroot_gridcomp.f90->sourcefile~varspecdescription.f90 sourcefile~mapl_demo_fargparse.f90 MAPL_demo_fargparse.F90 sourcefile~mapl_demo_fargparse.f90->sourcefile~mapl.f90 sourcefile~pfio_mapl_demo.f90 pfio_MAPL_demo.F90 sourcefile~pfio_mapl_demo.f90->sourcefile~mapl.f90 sourcefile~time_ave_util.f90 time_ave_util.F90 sourcefile~time_ave_util.f90->sourcefile~mapl.f90 sourcefile~varspecdescription.f90->sourcefile~mapl.f90

Source Code

#include "MAPL_Generic.h"
module MAPL_ESMFFieldBundleWrite
   use ESMF
   use pFIO
   use MAPL_GriddedIOMod
   use MAPL_TimeDataMod
   use MAPL_GriddedIOitemVectorMod
   use MAPL_GriddedIOitemMod
   use MAPL_VerticalDataMod
   use pFIO_ClientManagerMod, only: o_Clients
   use MAPL_ExceptionHandling
   implicit none
   private

   public :: FieldBundleWriter
   public :: MAPL_write_bundle
   type :: FieldBundleWriter
      private
      type(MAPL_GriddedIO) :: cfio
      character(:), allocatable :: file_name
      contains
         procedure :: create_from_bundle
         procedure :: write_to_file
         procedure :: start_new_file
   end type
   interface MAPL_Write_Bundle
      module procedure Write_bundle_single_time
   end interface

   contains

      subroutine write_bundle_single_time(bundle,clock,output_file,nbits_to_keep,deflate,quantize_algorithm,quantize_level,rc)
         type(ESMF_FieldBundle), intent(inout) :: bundle
         type(ESMF_Clock), intent(inout) :: clock
         character(len=*), intent(in) :: output_file
         integer, optional, intent(in)  :: nbits_to_keep
         integer, optional, intent(in)  :: deflate
         integer, optional, intent(in)  :: quantize_algorithm
         integer, optional, intent(in)  :: quantize_level
         integer, optional, intent(out) :: rc

         integer :: status

         type(FieldBundleWriter) :: newWriter

         call newWriter%create_from_bundle(bundle,clock,output_file=output_File,n_steps=1,time_interval=0,nbits_to_keep=nbits_to_keep,deflate=deflate,quantize_algorithm=quantize_algorithm,quantize_level=quantize_level,rc=status)
         _VERIFY(status)
         call newWriter%write_to_file(rc=status)
         _VERIFY(status)
         _RETURN(_SUCCESS)
      end subroutine write_bundle_single_time

      subroutine create_from_bundle(this,bundle,clock,output_file,vertical_data,n_steps,time_interval,nbits_to_keep,deflate,quantize_algorithm,quantize_level,rc)
         class(FieldBundleWRiter), intent(inout) :: this
         type(ESMF_FieldBundle), intent(inout) :: bundle
         type(ESMF_Clock), intent(inout) :: clock
         character(len=*), optional, intent(in) :: output_file
         type(VerticalData), optional, intent(inout) :: vertical_data
         integer, optional, intent(in)  :: n_steps
         integer, optional, intent(in)  :: time_interval
         integer, optional, intent(in)  :: nbits_to_keep
         integer, optional, intent(in)  :: deflate
         integer, optional, intent(in)  :: quantize_algorithm
         integer, optional, intent(in)  :: quantize_level
         integer, optional, intent(out) :: rc

         type(TimeData) :: time_info
         integer :: num_fields,i,file_steps,collection_id,status
         character(ESMF_MAXSTR), allocatable :: field_names(:)
         type(GriddedIOItemVector) :: items
         type(GriddedIOItem) :: item
         type(ESMF_TimeInterval) :: offset
         integer :: time_interval_

         call ESMF_TimeIntervalSet(offset,s=0,rc=status)
         _VERIFY(status)
         if (present(n_steps)) then
            file_steps = n_steps
         else
            file_steps = 1
         end if
         if (present(time_interval)) then
            time_interval_=time_interval
         else
            time_interval_=0
         end if

         call this%cfio%set_param(nbits_to_keep=nbits_to_keep,deflation=deflate,quantize_algorithm=quantize_algorithm,quantize_level=quantize_level)
         time_info = TimeData(clock,file_steps,time_interval_,offset)
         call ESMF_FieldBundleGet(bundle, fieldCount=num_fields,rc=status)
         _VERIFY(status)
         allocate(field_names(num_fields),stat=status)
         _VERIFY(status)
         call ESMF_FieldBundleGet(bundle, fieldNameList=field_names,rc=status)
         _VERIFY(status)
         do i=1,num_fields
            item%itemType=ItemTypeScalar
            item%xname = trim(field_names(i))
            call items%push_back(item)
         enddo
         if (present(vertical_data)) then
            call this%cfio%createFileMetadata(items,bundle,time_info,vdata=vertical_data,rc=status)
            _VERIFY(status)
         else
            call this%cfio%createFileMetadata(items,bundle,time_info,rc=status)
            _VERIFY(status)
         end if
         if (present(output_file)) this%file_name = output_file
         collection_id = o_clients%add_data_collection(this%cfio%metadata)
         call this%cfio%set_param(write_collection_id=collection_id)
         _RETURN(_SUCCESS)

      end subroutine create_from_bundle

      subroutine write_to_file(this,rc)
         class(FieldBundleWriter), intent(inout) :: this
         integer, optional, intent(out) :: rc

         integer :: status

         call this%cfio%bundlepost(this%file_name,oClients=o_clients,rc=status)
         _VERIFY(status)
         call o_Clients%done_collective_stage(_RC)
         call o_Clients%wait()
         _RETURN(_SUCCESS)

      end subroutine write_to_file

      subroutine start_new_file(this,filename,rc)
         class(fieldBundleWriter),intent(inout) :: this
         character(len=*), intent(in) :: filename
         integer, optional, intent(out) :: rc

         integer :: status

         this%file_name=filename
         call this%cfio%modifyTime(oClients=o_clients,_RC)
         _RETURN(_SUCCESS)
      end subroutine start_new_file

end module MAPL_ESMFFieldBundleWrite