main Subroutine

subroutine main()

Arguments

None

Calls

proc~~main~2~~CallsGraph proc~main~2 main ESMF_CalendarSetDefault ESMF_CalendarSetDefault proc~main~2->ESMF_CalendarSetDefault ESMF_ClockCreate ESMF_ClockCreate proc~main~2->ESMF_ClockCreate ESMF_ClockSet ESMF_ClockSet proc~main~2->ESMF_ClockSet ESMF_Finalize ESMF_Finalize proc~main~2->ESMF_Finalize ESMF_Initialize ESMF_Initialize proc~main~2->ESMF_Initialize ESMF_VMBarrier ESMF_VMBarrier proc~main~2->ESMF_VMBarrier ESMF_VMGet ESMF_VMGet proc~main~2->ESMF_VMGet at at proc~main~2->at esmf_fieldbundlecreate esmf_fieldbundlecreate proc~main~2->esmf_fieldbundlecreate esmf_fieldbundleset esmf_fieldbundleset proc~main~2->esmf_fieldbundleset interface~mapl_am_i_root MAPL_Am_I_Root proc~main~2->interface~mapl_am_i_root interface~mapl_assert MAPL_Assert proc~main~2->interface~mapl_assert interface~mapl_getnodeinfo MAPL_GetNodeInfo proc~main~2->interface~mapl_getnodeinfo mpi_barrier mpi_barrier proc~main~2->mpi_barrier none~create_from_bundle FieldBundleWriter%create_from_bundle proc~main~2->none~create_from_bundle none~finalize~10 ServerManager%finalize proc~main~2->none~finalize~10 none~initialize~10 ServerManager%initialize proc~main~2->none~initialize~10 none~reduce~2 DistributedProfiler%reduce proc~main~2->none~reduce~2 none~start_new_file FieldBundleWriter%start_new_file proc~main~2->none~start_new_file none~start~84 DistributedProfiler%start proc~main~2->none~start~84 none~write_to_file FieldBundleWriter%write_to_file proc~main~2->none~write_to_file proc~generate_report~2 generate_report proc~main~2->proc~generate_report~2 proc~get_file_levels~2 get_file_levels proc~main~2->proc~get_file_levels~2 proc~get_file_times~2 get_file_times proc~main~2->proc~get_file_times~2 proc~has_level~2 regrid_support%has_level proc~main~2->proc~has_level~2 proc~mapl_finalize MAPL_Finalize proc~main~2->proc~mapl_finalize proc~mapl_initialize MAPL_Initialize proc~main~2->proc~mapl_initialize proc~mapl_read_bundle MAPL_read_bundle proc~main~2->proc~mapl_read_bundle proc~mapl_verify MAPL_Verify proc~main~2->proc~mapl_verify proc~process_command_line~3 regrid_support%process_command_line proc~main~2->proc~process_command_line~3

Called by

proc~~main~2~~CalledByGraph proc~main~2 main program~regrid_util Regrid_Util program~regrid_util->proc~main~2

Source Code

    subroutine main()

   type(regrid_support), target :: support

   type(ESMF_VM)       :: vm             ! ESMF Virtual Machine

   character(len=ESMF_MAXPATHLEN) ::  Filename,OutputFile

   integer :: myPET   ! The local PET number
   integer :: nPET    ! The total number of PETs you are running on

   integer :: status, rc

   type(ESMF_FieldBundle) :: bundle
   type(ESMF_Time) :: time
   type(ESMF_Time), allocatable :: tSeries(:)
   type(ESMF_TimeInterval) :: timeInterval
   type(ESMF_Clock) :: clock


   logical :: fileCreated,file_exists

   integer :: tsteps,i,j,tint
   type(VerticalData) :: vertical_data

   type(FieldBundleWriter) :: newWriter
   logical :: writer_created, has_vertical_level
   type(ServerManager) :: io_server


   call ESMF_Initialize (LogKindFlag=ESMF_LOGKIND_NONE, vm=vm, _RC)
   call ESMF_VMGet(vm, localPET=myPET, petCount=nPet)
   call MAPL_Initialize(_RC)
   call MAPL_GetNodeInfo (comm=MPI_COMM_WORLD, _RC)
   call ESMF_CalendarSetDefault ( ESMF_CALKIND_GREGORIAN, _RC )

   call support%process_command_line(_RC)

   t_prof=DistributedProfiler('Regrid_Util',MpiTimerGauge(),MPI_COMM_WORLD)
   call t_prof%start(_RC)

   call io_server%initialize(mpi_comm_world)

   filename = support%filenames%at(1)
   if (allocated(tSeries)) deallocate(tSeries)
   call get_file_times(filename,support%itime,support%allTimes,tseries,timeInterval,tint,tsteps,_RC)
   has_vertical_level = support%has_level(_RC)
   if (has_vertical_level) then
      call get_file_levels(filename,vertical_data,_RC)
   end if

   Clock = ESMF_ClockCreate ( name="Eric", timeStep=TimeInterval, &
                               startTime=tSeries(1), _RC )

   bundle=ESMF_FieldBundleCreate(name="cfio_bundle",_RC)
   call ESMF_FieldBundleSet(bundle,grid=support%new_grid,_RC)

   writer_created=.false.
   do j=1,support%filenames%size()

      filename = support%filenames%at(j)
      if (j>1) then
         if (allocated(tSeries)) deallocate(tSeries)
         call get_file_times(filename,support%itime,support%allTimes,tseries,timeInterval,tint,tsteps,_RC)
      end if
      outputfile = support%outputfiles%at(j)

      inquire(file=trim(outputfile),exist=file_exists)
      _ASSERT(.not.file_exists,"output file already exists: exiting!")

      fileCreated=.false.
      do i=1,tsteps

         call t_prof%start("Read")
         if (mapl_am_i_root()) write(*,*)'processing timestep from '//trim(filename)
         time = tSeries(i)
         if (support%onlyvars) then
            call MAPL_Read_bundle(bundle,trim(filename),time=time,regrid_method=support%regridMethod,only_vars=support%vars,file_weights=support%use_weights, _RC)
         else
            call MAPL_Read_bundle(bundle,trim(filename),time=time,regrid_method=support%regridMethod,file_weights=support%use_weights, _RC)
         end if
         call t_prof%stop("Read")

         call MPI_BARRIER(MPI_COMM_WORLD,STATUS)
         _VERIFY(status)

         call t_prof%start("write")

         if (mapl_am_I_root()) write(*,*) "moving on to writing "//trim(outputfile)

         call ESMF_ClockSet(clock,currtime=time,_RC)
         if (.not. writer_created) then
            call newWriter%create_from_bundle(bundle,clock,n_steps=tsteps,time_interval=tint,nbits_to_keep=support%shave,deflate=support%deflate,vertical_data=vertical_data,quantize_algorithm=support%quantize_algorithm,quantize_level=support%quantize_level,zstandard_level=support%zstandard_level,_RC)
            writer_created=.true.
         end if

         if (.not.fileCreated) then
            call newWriter%start_new_file(outputFile,_RC)
            fileCreated=.true.
         end if
         call newWriter%write_to_file(_RC)
         call t_prof%stop("write")

      end do
   enddo
!   All done
!   --------
   call ESMF_VMBarrier(VM,_RC)

   call io_server%finalize()
   call t_prof%stop()
   call t_prof%reduce()
   call t_prof%finalize()
   call generate_report()
   call MAPL_Finalize(_RC)
   call ESMF_Finalize ( _RC )

   end subroutine main