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