From 2c9d1784d7c6f1c7e0b9d5c3f83ebca1a14cbd90 Mon Sep 17 00:00:00 2001 From: Carsten Lemmen Date: Wed, 16 Oct 2024 10:53:19 +0200 Subject: [PATCH] First test of fprettify --- concurrent_esmf_test.F90 | 108 +++++++------- multi_schism.F90 | 106 ++++++------- schism_driver_interfaces.F90 | 7 +- schism_pdaf.F90 | 280 +++++++++++++++++------------------ triple_schism.F90 | 114 +++++++------- 5 files changed, 304 insertions(+), 311 deletions(-) diff --git a/concurrent_esmf_test.F90 b/concurrent_esmf_test.F90 index 9731d37..560c83c 100644 --- a/concurrent_esmf_test.F90 +++ b/concurrent_esmf_test.F90 @@ -10,7 +10,7 @@ ! you may not use this file except in compliance with the License. ! You may obtain a copy of the License at ! -! http://www.apache.org/licenses/LICENSE-2.0 +! http://www.apache.org/licenses/LICENSE-2.0 ! ! Unless required by applicable law or agreed to in writing, software ! distributed under the License is distributed on an "AS IS" BASIS, @@ -33,38 +33,38 @@ program main use esmf use schism_esmf_cap, only: schismSetServices => SetServices - use atmosphere_cmi_esmf, only: atmosSetServices => SetServices + use atmosphere_cmi_esmf, only: atmosSetServices => SetServices implicit none interface function clockCreateFrmParam(filename, rc) use esmf - character(len=ESMF_MAXSTR), intent(in) :: filename - integer(ESMF_KIND_I4), intent(out) :: rc - type(ESMF_Clock) :: clockCreateFrmParam + character(len=ESMF_MAXSTR), intent(in) :: filename + integer(ESMF_KIND_I4), intent(out) :: rc + type(ESMF_Clock) :: clockCreateFrmParam end function clockCreateFrmParam end interface - type(ESMF_GridComp) :: schism_component - type(ESMF_GridComp) :: atmos_component + type(ESMF_GridComp) :: schism_component + type(ESMF_GridComp) :: atmos_component - type(ESMF_State) :: schism_import, schism_export - type(ESMF_State) :: atmos_import, atmos_export + type(ESMF_State) :: schism_import, schism_export + type(ESMF_State) :: atmos_import, atmos_export type(ESMF_TimeInterval) :: timestep - type(ESMF_Time) :: start_time, stop_time - type(ESMF_Clock) :: clock + type(ESMF_Time) :: start_time, stop_time + type(ESMF_Clock) :: clock - type(ESMF_Field) :: field,field_in,field_out - type(ESMF_RouteHandle) :: routehandle_air2sea, routehandle_sea2air - type(ESMF_Vm) :: vm + type(ESMF_Field) :: field, field_in, field_out + type(ESMF_RouteHandle) :: routehandle_air2sea, routehandle_sea2air + type(ESMF_Vm) :: vm - integer(ESMF_KIND_I4) :: rc, petCount, i, inum, localrc - integer, allocatable :: petlist_schism(:),petlist_atmos(:) + integer(ESMF_KIND_I4) :: rc, petCount, i, inum, localrc + integer, allocatable :: petlist_schism(:), petlist_atmos(:) real(ESMF_KIND_R8), pointer :: ptr1d(:) - logical :: isPresent - character(len=ESMF_MAXSTR) :: filename + logical :: isPresent + character(len=ESMF_MAXSTR) :: filename call ESMF_Initialize(defaultCalKind=ESMF_CALKIND_GREGORIAN, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) @@ -80,33 +80,33 @@ end function clockCreateFrmParam call ESMF_VMGet(vm, petCount=petCount, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - allocate(petlist_schism(max(1,petcount-1)), stat=localrc) + allocate (petlist_schism(max(1, petcount - 1)), stat=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - do i=1, max(1, petcount-1) - petlist_schism(i)=i-1 !0 based + do i = 1, max(1, petcount - 1) + petlist_schism(i) = i - 1 !0 based end do - allocate(petlist_atmos(1)) - petlist_atmos(1) = petcount-1 + allocate (petlist_atmos(1)) + petlist_atmos(1) = petcount - 1 ! Create both components on their respective parallel ! environment provided by each petList, then register ! the components entry points. schism_component = ESMF_GridCompCreate(name='schism_component', & - petList=petlist_schism, rc=localrc) + petList=petlist_schism, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) atmos_component = ESMF_GridCompCreate(name='atmosphere_component', & - petList=petlist_atmos, rc=localrc) + petList=petlist_atmos, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) call ESMF_GridCompSetServices(schism_component, & - schismSetServices, rc=localrc) + schismSetServices, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) call ESMF_GridCompSetServices(atmos_component, & - atmosSetServices, rc=localrc) + atmosSetServices, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) ! Create states for exchange of information between @@ -144,12 +144,12 @@ end function clockCreateFrmParam ! Initialize SCHISM call ESMF_GridCompInitialize(schism_component, & - importState=schism_import, & - exportState=schism_export, clock=clock, rc=localrc) + importState=schism_import, & + exportState=schism_export, clock=clock, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) call ESMF_GridCompInitialize(atmos_component, importState=atmos_import, & - exportState=atmos_export, clock=clock, rc=localrc) + exportState=atmos_export, clock=clock, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) ! Make sure that all states are reconciled across the @@ -163,36 +163,36 @@ end function clockCreateFrmParam ! Within the schism component, the following fields are ! defined for import and export (y-component not implemented yet) call ESMF_StateGet(schism_import, 'wind_x-velocity_in_10m_height', & - field=field_out, rc=localrc) + field=field_out, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - call ESMF_StateGet(atmos_export,'wind_x-velocity', & - field=field_in, rc=localrc) + call ESMF_StateGet(atmos_export, 'wind_x-velocity', & + field=field_in, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) ! Precompute the weights call ESMF_FieldRegridStore(field_in, field_out, & - regridMethod = ESMF_REGRIDMETHOD_BILINEAR, & - routehandle=routehandle_air2sea, unmappedaction=ESMF_UNMAPPEDACTION_IGNORE, & - rc=localrc) + regridMethod=ESMF_REGRIDMETHOD_BILINEAR, & + routehandle=routehandle_air2sea, unmappedaction=ESMF_UNMAPPEDACTION_IGNORE, & + rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) ! Loop over coupling timesteps until stopTime - do while ( .not. (ESMF_ClockIsStopTime(clock))) + do while (.not. (ESMF_ClockIsStopTime(clock))) !> Directly manipulate the fields from import and export !> states. In less basic applications, this should be !> handled by a mediator component. call ESMF_FieldRegrid(field_in, field_out, & - routeHandle=routehandle_air2sea, rc=localrc) + routeHandle=routehandle_air2sea, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) call ESMF_GridCompRun(atmos_component, importState=atmos_import, & - exportState=atmos_export, clock=clock, rc=localrc) + exportState=atmos_export, clock=clock, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) call ESMF_GridCompRun(schism_component, importState=schism_import, & - exportState=schism_export, clock=clock, rc=localrc) + exportState=schism_export, clock=clock, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) call ESMF_ClockAdvance(clock, rc=localrc) @@ -201,7 +201,7 @@ end function clockCreateFrmParam !> Clean up call ESMF_GridCompFinalize(schism_component, importState=schism_import, & - exportState=schism_export, clock=clock, rc=localrc) + exportState=schism_export, clock=clock, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) call ESMF_ClockDestroy(clock, rc=localrc) @@ -235,36 +235,36 @@ function clockCreateFrmParam(filename, rc) result(clock) implicit none character(len=ESMF_MAXSTR), intent(in) :: filename - integer(ESMF_KIND_I4), intent(out) :: rc - type(ESMF_Clock) :: clock + integer(ESMF_KIND_I4), intent(out) :: rc + type(ESMF_Clock) :: clock - logical :: isPresent + logical :: isPresent integer(ESMF_KIND_I4) :: unit, localrc - type(ESMF_Time) :: stopTime, startTime + type(ESMF_Time) :: stopTime, startTime type(ESMF_TimeInterval) :: timeStep - integer(ESMF_KIND_I4) :: start_year=2000, start_month=1, start_day=1 - integer(ESMF_KIND_I4) :: start_hour=0, rnday=2 !rnday in hours + integer(ESMF_KIND_I4) :: start_year = 2000, start_month = 1, start_day = 1 + integer(ESMF_KIND_I4) :: start_hour = 0, rnday = 2 !rnday in hours namelist /global/ start_year, start_month, start_day, start_hour, rnday - inquire(file=filename, exist=isPresent) + inquire (file=filename, exist=isPresent) if (isPresent) then call ESMF_UtilIOUnitGet(unit, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - open(unit, file=filename, iostat=localrc) + open (unit, file=filename, iostat=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - read(unit, nml=global, iostat=localrc) + read (unit, nml=global, iostat=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - close(unit) - endif + close (unit) + end if ! Set day as timestep temporarily to count later to stop time call ESMF_TimeSet(startTime, yy=start_year, mm=start_month, dd=start_day, & - h=start_hour, rc=localrc) + h=start_hour, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) call ESMF_TimeIntervalSet(timeStep, h=rnday, rc=localrc) @@ -277,7 +277,7 @@ function clockCreateFrmParam(filename, rc) result(clock) timeStep = timeStep / 24 clock = ESMF_ClockCreate(timeStep, startTime, stopTime=stopTime, & - name='main clock', rc=localrc) + name='main clock', rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) end function clockCreateFrmParam diff --git a/multi_schism.F90 b/multi_schism.F90 index 088c16a..ded2921 100644 --- a/multi_schism.F90 +++ b/multi_schism.F90 @@ -10,7 +10,7 @@ ! you may not use this file except in compliance with the License. ! You may obtain a copy of the License at ! -! http://www.apache.org/licenses/LICENSE-2.0 +! http://www.apache.org/licenses/LICENSE-2.0 ! ! Unless required by applicable law or agreed to in writing, software ! distributed under the License is distributed on an "AS IS" BASIS, @@ -38,22 +38,22 @@ program main implicit none type(ESMF_GridComp), allocatable :: schism_components(:) - type(ESMF_State), allocatable :: schism_imports(:), schism_exports(:) + type(ESMF_State), allocatable :: schism_imports(:), schism_exports(:) type(ESMF_TimeInterval) :: timestep - type(ESMF_Time) :: start_time, stop_time - type(ESMF_Clock) :: clock + type(ESMF_Time) :: start_time, stop_time + type(ESMF_Clock) :: clock - type(ESMF_Vm) :: vm - type(ESMF_Log) :: log + type(ESMF_Vm) :: vm + type(ESMF_Log) :: log - integer(ESMF_KIND_I4) :: petCountLocal, schismCount=8 - integer(ESMF_KIND_I4) :: rc, petCount, i, j, inum, localrc - integer(ESMF_KIND_I4), allocatable :: petlist(:) + integer(ESMF_KIND_I4) :: petCountLocal, schismCount = 8 + integer(ESMF_KIND_I4) :: rc, petCount, i, j, inum, localrc + integer(ESMF_KIND_I4), allocatable :: petlist(:) real(ESMF_KIND_R8), pointer :: ptr1d(:) - logical :: isPresent - character(len=ESMF_MAXSTR) :: filename='multi_schism.cfg', message - type(ESMF_Config) :: config + logical :: isPresent + character(len=ESMF_MAXSTR) :: filename = 'multi_schism.cfg', message + type(ESMF_Config) :: config type(ESMF_Config), allocatable :: configList(:) call ESMF_Initialize(defaultCalKind=ESMF_CALKIND_GREGORIAN, rc=localrc) @@ -74,7 +74,7 @@ program main _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) !Get config info (# of schism instances). Always specify - inquire(file=filename, exist=isPresent) + inquire (file=filename, exist=isPresent) if (isPresent) then config = ESMF_ConfigCreate(rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) @@ -83,51 +83,51 @@ program main _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) call ESMF_ConfigGetAttribute(config, value=schismCount, label='count:', & - !default: value used if label is not found - default=min(petCount,8), rc=localrc) + !default: value used if label is not found + default=min(petCount, 8), rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - endif + end if - if(schismCount>999 .or. schismCount<1) then - write(message, '(A,I3,A)') 'Number of instances ',schismCount, & + if (schismCount > 999 .or. schismCount < 1) then + write (message, '(A,I3,A)') 'Number of instances ', schismCount, & 'must be in the range [1,999]' call ESMF_LogWrite(trim(message), ESMF_LOGMSG_ERROR) localrc = ESMF_RC_VAL_OUTOFRANGE _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) elseif (schismCount > petCount) then - write(message, '(A)') 'Requested number of instances exceeds available PETs' + write (message, '(A)') 'Requested number of instances exceeds available PETs' call ESMF_LogWrite(trim(message), ESMF_LOGMSG_WARNING) - write(message, '(A,I3,A,I3)') 'Reduced from ',schismCount, ' to ', petCount + write (message, '(A,I3,A,I3)') 'Reduced from ', schismCount, ' to ', petCount call ESMF_LogWrite(trim(message), ESMF_LOGMSG_WARNING) schismCount = petCount else - write(message, '(A,I3)') 'Number of SCHISM instances ',schismCount + write (message, '(A,I3)') 'Number of SCHISM instances ', schismCount call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO) - endif + end if ! Create all components on their respective parallel ! environment provided by each petList - allocate(schism_components(schismCount), stat=localrc) + allocate (schism_components(schismCount), stat=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - allocate(configList(schismCount), stat=localrc) + allocate (configList(schismCount), stat=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) do i = 1, schismCount - petCountLocal = petCount/schismCount - allocate(petlist(petCountLocal), stat=localrc) + petCountLocal = petCount / schismCount + allocate (petlist(petCountLocal), stat=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - do j=1, petCountLocal - petList(j)=(i-1)*petCountLocal + j - 1 ! PET #; 0 based + do j = 1, petCountLocal + petList(j) = (i - 1) * petCountLocal + j - 1 ! PET #; 0 based end do - write(message, '(A,I3.3)') 'schism_', i + write (message, '(A,I3.3)') 'schism_', i !write(0, *) trim(message), 'list=', petList, 'petCount=', petCount, petCountLocal schism_components(i) = ESMF_GridCompCreate(name=trim(adjustl(message)), & - petList=petlist, rc=localrc) + petList=petlist, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) !configList(i) = ESMF_ConfigCreate(rc=localrc) @@ -139,34 +139,34 @@ program main ! label='schismInstance:', rc=localrc) call ESMF_AttributeSet(schism_components(i), name='input_directory', & - value=trim(message), rc=localrc) + value=trim(message), rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) !call ESMF_GridCompSet(schism_components(i), config=configList(i), rc=localrc) !_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - deallocate(petList) + deallocate (petList) end do ! loop over schismCount - write(message, '(A,I3,A)') 'Created ',schismCount,' instances of SCHISM' + write (message, '(A,I3,A)') 'Created ', schismCount, ' instances of SCHISM' - allocate(schism_exports(schismCount)) - allocate(schism_imports(schismCount)) + allocate (schism_exports(schismCount)) + allocate (schism_imports(schismCount)) do i = 1, schismCount call ESMF_GridCompSetServices(schism_components(i), & - schismSetServices, rc=localrc) + schismSetServices, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - write(message, '(A,I3.3)') 'schism_', i + write (message, '(A,I3.3)') 'schism_', i schism_exports(i) = ESMF_StateCreate( & - name='schismExport_'//trim(adjustl(message)), rc=localrc) + name='schismExport_'//trim(adjustl(message)), rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) schism_imports(i) = ESMF_StateCreate( & - name='schismImport_'//trim(adjustl(message)), rc=localrc) + name='schismImport_'//trim(adjustl(message)), rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) end do @@ -174,8 +174,8 @@ program main do i = 1, schismCount !Init phase 0 call ESMF_GridCompInitialize(schism_components(i), importState=schism_imports(i), & - exportState=schism_exports(i), phase=0, clock=clock, rc=localrc) - _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) + exportState=schism_exports(i), phase=0, clock=clock, rc=localrc) + _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) end do @@ -187,8 +187,8 @@ program main do i = 1, schismCount call ESMF_GridCompInitialize(schism_components(i), importState=schism_imports(i), & - exportState=schism_exports(i), phase=1, clock=clock, rc=localrc) - _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) + exportState=schism_exports(i), phase=1, clock=clock, rc=localrc) + _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) end do @@ -203,13 +203,13 @@ program main end do ! Loop over coupling timesteps until stopTime - do while ( .not. (ESMF_ClockIsStopTime(clock))) + do while (.not. (ESMF_ClockIsStopTime(clock))) - do i=1, schismCount + do i = 1, schismCount call ESMF_GridCompRun(schism_components(i), importState=schism_imports(i), & - exportState=schism_exports(i), clock=clock, rc=localrc) + exportState=schism_exports(i), clock=clock, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - enddo + end do call ESMF_ClockAdvance(clock, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) @@ -218,8 +218,8 @@ program main do i = 1, schismCount call ESMF_GridCompFinalize(schism_components(i), importState=schism_imports(i), & - exportState=schism_exports(i), clock=clock, rc=localrc) - _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) + exportState=schism_exports(i), clock=clock, rc=localrc) + _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) call ESMF_StateDestroy(schism_imports(i), rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) @@ -231,10 +231,10 @@ program main _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) end do - deallocate(schism_exports) - deallocate(schism_imports) - deallocate(schism_components) - deallocate(configList) + deallocate (schism_exports) + deallocate (schism_imports) + deallocate (schism_components) + deallocate (configList) call ESMF_ClockDestroy(clock, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) diff --git a/schism_driver_interfaces.F90 b/schism_driver_interfaces.F90 index dc00cc3..063cbd4 100644 --- a/schism_driver_interfaces.F90 +++ b/schism_driver_interfaces.F90 @@ -8,16 +8,14 @@ subroutine parallel_init(communicator) integer, optional :: communicator end subroutine parallel_init - subroutine parallel_finalize implicit none end subroutine parallel_finalize - - subroutine schism_init(indir,iths,ntime) + subroutine schism_init(indir, iths, ntime) implicit none character(len=*), intent(in) :: indir - integer, intent(out) :: iths,ntime + integer, intent(out) :: iths, ntime end subroutine schism_init subroutine schism_step(it) @@ -25,7 +23,6 @@ subroutine schism_step(it) integer, intent(in) :: it end subroutine schism_step - subroutine schism_finalize() implicit none end subroutine schism_finalize diff --git a/schism_pdaf.F90 b/schism_pdaf.F90 index fea339b..e57d0d9 100644 --- a/schism_pdaf.F90 +++ b/schism_pdaf.F90 @@ -12,7 +12,7 @@ ! you may not use this file except in compliance with the License. ! You may obtain a copy of the License at ! -! http://www.apache.org/licenses/LICENSE-2.0 +! http://www.apache.org/licenses/LICENSE-2.0 ! ! Unless required by applicable law or agreed to in writing, software ! distributed under the License is distributed on an "AS IS" BASIS, @@ -48,33 +48,33 @@ program main include 'mpif.h' type(ESMF_GridComp), allocatable :: schism_components(:) - type(ESMF_State), allocatable :: importStateList(:), exportStateList(:) + type(ESMF_State), allocatable :: importStateList(:), exportStateList(:) type(ESMF_TimeInterval) :: timestep - type(ESMF_Time) :: start_time, stop_time - type(ESMF_Clock) :: clock, childClock + type(ESMF_Time) :: start_time, stop_time + type(ESMF_Clock) :: clock, childClock - type(ESMF_Vm) :: vm - type(ESMF_Log) :: log + type(ESMF_Vm) :: vm + type(ESMF_Log) :: log - integer(ESMF_KIND_I4) :: petCountLocal, schismCount=8 - integer(ESMF_KIND_I4) :: rc, petCount, i, j, inum,localrc, ii - integer(ESMF_KIND_I4), allocatable :: petlist(:) + integer(ESMF_KIND_I4) :: petCountLocal, schismCount = 8 + integer(ESMF_KIND_I4) :: rc, petCount, i, j, inum, localrc, ii + integer(ESMF_KIND_I4), allocatable :: petlist(:) real(ESMF_KIND_R8), pointer :: ptr1d(:) - logical :: isPresent - character(len=ESMF_MAXSTR) :: filename='schism_pdaf.cfg', message, message2 - type(ESMF_Config) :: config + logical :: isPresent + character(len=ESMF_MAXSTR) :: filename = 'schism_pdaf.cfg', message, message2 + type(ESMF_Config) :: config type(ESMF_Config), allocatable :: configList(:) - integer(ESMF_KIND_I4) :: concurrentCount, ncohort,cohortIndex - integer(ESMF_KIND_I4) :: sequenceIndex + integer(ESMF_KIND_I4) :: concurrentCount, ncohort, cohortIndex + integer(ESMF_KIND_I4) :: sequenceIndex - integer(ESMF_KIND_I4) :: alarmCount=0, ringingAlarmCount=0 + integer(ESMF_KIND_I4) :: alarmCount = 0, ringingAlarmCount = 0 type(ESMF_Alarm), allocatable :: alarmList(:), ringingAlarmList(:) - logical :: hasAlarmRung = .false. - character(len=ESMF_MAXSTR) :: alarmName + logical :: hasAlarmRung = .false. + character(len=ESMF_MAXSTR) :: alarmName - integer(ESMF_KIND_I4) :: schism_dt,num_schism_dt_in_couple,runhours,num_obs_steps,it,unit,next_obs_step + integer(ESMF_KIND_I4) :: schism_dt, num_schism_dt_in_couple, runhours, num_obs_steps, it, unit, next_obs_step integer(ESMF_KIND_I4), allocatable :: list_obs_steps(:) real(ESMF_KIND_R8), allocatable :: list_obs_times(:) @@ -86,7 +86,7 @@ program main ! distribute_state_pdaf, & ! Routine to distribute a state vector to model fields ! prepoststep_ens ! User supplied pre/poststep routine - namelist /obs_info/list_obs_times + namelist /obs_info/ list_obs_times call ESMF_Initialize(defaultCalKind=ESMF_CALKIND_GREGORIAN, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) @@ -110,7 +110,7 @@ program main ! Get config for number of schism instances and size of cohorts ! A cohort is defined as the set of instances that run ! concurrently, i.e. on different petLists. - inquire(file=filename, exist=isPresent) + inquire (file=filename, exist=isPresent) if (isPresent) then config = ESMF_ConfigCreate(rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) @@ -119,49 +119,49 @@ program main _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) call ESMF_ConfigGetAttribute(config, value=schismCount, label='schism_count:', & - default=min(petCount,8), rc=localrc) + default=min(petCount, 8), rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) !Components in a cohort are run concurrently on differen PETs. Some components in different !cohorts share same PETs call ESMF_ConfigGetAttribute(config, value=concurrentCount, label='concurrent_count:', & - default=max(petCount/schismCount,1), rc=localrc) + default=max(petCount / schismCount, 1), rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) else - write(message,*)'Please supply .cfg' + write (message, *) 'Please supply .cfg' call ESMF_LogWrite(trim(message), ESMF_LOGMSG_ERROR) localrc = ESMF_RC_VAL_OUTOFRANGE _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - endif + end if - if (schismCount>999 .or. schismCount<1) then - write(message, '(A,I3,A)') 'Number of instances ', & + if (schismCount > 999 .or. schismCount < 1) then + write (message, '(A,I3,A)') 'Number of instances ', & schismCount, 'must be in the range [1,999]' call ESMF_LogWrite(trim(message), ESMF_LOGMSG_ERROR) localrc = ESMF_RC_VAL_OUTOFRANGE _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) elseif (concurrentCount > schismCount .or. concurrentCount < 1) then - write(message, '(A,I3,A,I3,A)') 'Number of cohorts ', & + write (message, '(A,I3,A,I3,A)') 'Number of cohorts ', & concurrentCount, 'must be in the range [1,', schismCount, ']' call ESMF_LogWrite(trim(message), ESMF_LOGMSG_ERROR) localrc = ESMF_RC_VAL_OUTOFRANGE _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - !elseif (petCount We distribute the schismCount instances on the concurrentCount !> to obtain the number of cohorts that run sequentially, !> and obtain ncohort=3 in our example - ncohort = ceiling(real(schismCount)/concurrentCount) - petCountLocal = petCount/concurrentCount + ncohort = ceiling(real(schismCount) / concurrentCount) + petCountLocal = petCount / concurrentCount - if(ncohort<1) then - write(message,*) 'ncohort<1:',ncohort + if (ncohort < 1) then + write (message, *) 'ncohort<1:', ncohort call ESMF_LogWrite(trim(message), ESMF_LOGMSG_ERROR) localrc = ESMF_RC_VAL_OUTOFRANGE _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - endif + end if !> Thus, we obtain the sets of instances that run concurrently: {1 4 7 10 13} !etc folowing column major @@ -198,26 +198,26 @@ program main ! Determine the sequence and concurrent index of each ! instance ! sequenceIndex = mod(i-1, concurrentCount) !local index in a cohort (0- based); task ID-1 in PDAF - sequenceIndex=(i-1)/ncohort + sequenceIndex = (i - 1) / ncohort - allocate(petlist(petCountLocal), stat=localrc) + allocate (petlist(petCountLocal), stat=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) ! Instances within the same cohort use different PET - do j=1, petCountLocal - petList(j)=sequenceIndex*petCountLocal+ j-1 !points to global PET # + do j = 1, petCountLocal + petList(j) = sequenceIndex * petCountLocal + j - 1 !points to global PET # end do !j ! write(0,*) 'Instance ', i, ' uses ', petCountLocal, ' PET in sequence ', sequenceIndex, 'list is ', petlist - write(message2, '(A,I3.3)') 'schism_', i + write (message2, '(A,I3.3)') 'schism_', i ! write(0, *) trim(message2), 'list=', petList, 'petCount=', petCount, petCountLocal schism_components(i) = ESMF_GridCompCreate(name=trim(adjustl(message2)), & - petList=petlist, rc=localrc) + petList=petlist, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - write(message, '(A,I3.3,A,I3.3,A,I6.6,A,I6.6,A,I6.6)') 'Instance schism_', i, & + write (message, '(A,I3.3,A,I3.3,A,I6.6,A,I6.6,A,I6.6)') 'Instance schism_', i, & ' with sequence number ', sequenceIndex, ' created on ', petCountLocal, & ' PET ', petList(1), '..', petList(petCountLocal) !,message2 call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO) @@ -234,107 +234,107 @@ program main call ESMF_AttributeSet(schism_components(i), name='input_directory', value=trim(message2), rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - deallocate(petList) + deallocate (petList) !call ESMF_GridCompSet(schism_components(i), config=configList(i), rc=localrc) !_SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) end do ! loop over schismCount - write(message, '(A,I3,A)') 'Created ',schismCount,' instances of SCHISM' + write (message, '(A,I3,A)') 'Created ', schismCount, ' instances of SCHISM' - allocate(exportStateList(schismCount)) - allocate(importStateList(schismCount)) + allocate (exportStateList(schismCount)) + allocate (importStateList(schismCount)) ! Create export states for all instances and register them - register_loop: do i = 1, schismCount + register_loop: do i = 1, schismCount call ESMF_GridCompSetServices(schism_components(i), & - schismSetServices, rc=localrc) + schismSetServices, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - write(message, '(A,I3.3)') 'schism_', i + write (message, '(A,I3.3)') 'schism_', i exportStateList(i) = ESMF_StateCreate( & - name='schismExport_'//trim(adjustl(message)), rc=localrc) - _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) + name='schismExport_'//trim(adjustl(message)), rc=localrc) + _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) importStateList(i) = ESMF_StateCreate( & - name='schismImport_'//trim(adjustl(message)), rc=localrc) + name='schismImport_'//trim(adjustl(message)), rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - enddo register_loop + end do register_loop !Get info on simulation period ! filename = './global.nml' ! clock = clockCreateFrmParam(filename, localrc) - call clockCreateFrmParam(clock,schism_dt,num_schism_dt_in_couple,runhours,num_obs_steps) + call clockCreateFrmParam(clock, schism_dt, num_schism_dt_in_couple, runhours, num_obs_steps) !Read in obs times - allocate(list_obs_steps(num_obs_steps),list_obs_times(num_obs_steps)) + allocate (list_obs_steps(num_obs_steps), list_obs_times(num_obs_steps)) call ESMF_UtilIOUnitGet(unit, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - open(unit, file='global.nml', iostat=localrc) + open (unit, file='global.nml', iostat=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - read(unit, nml=obs_info, iostat=localrc) + read (unit, nml=obs_info, iostat=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - close(unit) + close (unit) !Make sure the list is ascending - do i=1,num_obs_steps-1 - if(list_obs_times(i+1)<=list_obs_times(i).or.list_obs_times(i)<=0) then - write(message,*) 'Check obs times:',i,list_obs_times + do i = 1, num_obs_steps - 1 + if (list_obs_times(i + 1) <= list_obs_times(i) .or. list_obs_times(i) <= 0) then + write (message, *) 'Check obs times:', i, list_obs_times call ESMF_LogWrite(trim(message), ESMF_LOGMSG_ERROR) localrc = ESMF_RC_VAL_OUTOFRANGE _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - endif - enddo !i + end if + end do !i !Calculate SCHISM time steps for DA - list_obs_steps=nint(list_obs_times/schism_dt) - where(list_obs_steps<1) list_obs_steps=1 + list_obs_steps = nint(list_obs_times / schism_dt) + where (list_obs_steps < 1) list_obs_steps = 1 !Make sure obs steps are multiples of num_schism_dt_in_couple - do i=1,num_obs_steps - if(mod(list_obs_steps(i),num_schism_dt_in_couple)/=0) then - write(message,*) 'Obs steps must be divisible by num_schism_dt_in_couple:',i,list_obs_steps(i) + do i = 1, num_obs_steps + if (mod(list_obs_steps(i), num_schism_dt_in_couple) /= 0) then + write (message, *) 'Obs steps must be divisible by num_schism_dt_in_couple:', i, list_obs_steps(i) call ESMF_LogWrite(trim(message), ESMF_LOGMSG_ERROR) localrc = ESMF_RC_VAL_OUTOFRANGE _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - endif - enddo !i + end if + end do !i - write(message,*)'List of obs steps:',list_obs_steps + write (message, *) 'List of obs steps:', list_obs_steps call ESMF_LogWrite(trim(message), ESMF_LOGMSG_INFO) ! Initialize phase 0 and set attribute for calling init ! write(0, *) 'Before init0_loop, ESMF_GridCompInitialize' init0_loop: do i = 1, schismCount - call ESMF_GridCompInitialize(schism_components(i), importState= importStateList(i), & - exportState=exportStateList(i), phase=0, clock=clock, rc=localrc) + call ESMF_GridCompInitialize(schism_components(i), importState=importStateList(i), & + exportState=exportStateList(i), phase=0, clock=clock, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) !Put cohort index (0-based) into attribute to pass onto init P1 etc ! cohortIndex=(i-1)/concurrentCount - cohortIndex=mod(i-1,ncohort) ! correct this to match PDAF task-ID + cohortIndex = mod(i - 1, ncohort) ! correct this to match PDAF task-ID call ESMF_AttributeSet(schism_components(i), 'cohort_index', cohortIndex) - if(cohortIndex>ncohort-1) then - write(message,*) 'cohortIndex>ncohort-1:',cohortIndex,ncohort + if (cohortIndex > ncohort - 1) then + write (message, *) 'cohortIndex>ncohort-1:', cohortIndex, ncohort call ESMF_LogWrite(trim(message), ESMF_LOGMSG_ERROR) localrc = ESMF_RC_VAL_OUTOFRANGE _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - endif + end if call ESMF_AttributeSet(schism_components(i), name='ncohort', value=ncohort, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - call ESMF_AttributeSet(schism_components(i), name='runhours',value=runhours, rc=localrc) + call ESMF_AttributeSet(schism_components(i), name='runhours', value=runhours, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - call ESMF_AttributeSet(schism_components(i), name='schism_dt2',value=schism_dt, rc=localrc) + call ESMF_AttributeSet(schism_components(i), name='schism_dt2', value=schism_dt, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - enddo init0_loop + end do init0_loop ! Read some information on observation data availability and create ! a list of alarms for the times that new data is available and should be @@ -354,70 +354,70 @@ program main ! write(0, *) 'Before schism_init, ESMF_GridCompInitialize' init1_loop: do i = 1, schismCount - call ESMF_GridCompInitialize(schism_components(i), importState= importStateList(i), & - exportState=exportStateList(i), phase=1, clock=clock, rc=localrc) + call ESMF_GridCompInitialize(schism_components(i), importState=importStateList(i), & + exportState=exportStateList(i), phase=1, clock=clock, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - enddo init1_loop + end do init1_loop ! write(0, *) 'Before ESMF_StateReconcile' reconcile_loop: do i = 1, schismCount - call ESMF_StateReconcile( importStateList(i), vm=vm, rc=localrc) + call ESMF_StateReconcile(importStateList(i), vm=vm, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) call ESMF_StateReconcile(exportStateList(i), vm=vm, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - enddo reconcile_loop + end do reconcile_loop ! Init PDAF env #ifdef USE_PDAF ! write(0, *) 'Before init_parelle_pdaf' - call init_parallel_pdaf(0,1,schismCount,petCountLocal,concurrentCount) + call init_parallel_pdaf(0, 1, schismCount, petCountLocal, concurrentCount) ! write(0, *) 'Before init_pdaf' - call init_pdaf(schismCount,j) + call init_pdaf(schismCount, j) #endif - if(j/=0) then + if (j /= 0) then localrc = ESMF_RC_VAL_OUTOFRANGE _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - endif + end if ! Loop over coupling timesteps until stopTime - it=0 - next_obs_step=1 !init next obs step - do while ( .not. (ESMF_ClockIsStopTime(clock))) + it = 0 + next_obs_step = 1 !init next obs step + do while (.not. (ESMF_ClockIsStopTime(clock))) !new28: this is mostly to init analysis routines !call PDAF_get_state !call PDAF_get_state(it,time_PDAF, doexit, next_observation_pdaf, distribute_state_pdaf, prepoststep_ens, status_pdaf) - it=it+num_schism_dt_in_couple !SCHISM step # + it = it + num_schism_dt_in_couple !SCHISM step # do i = 1, schismCount !Check if it's analysis step in PDAF - if (it==list_obs_steps(next_obs_step)) then !DA step + if (it == list_obs_steps(next_obs_step)) then !DA step !Let Run know it's analysis step call ESMF_AttributeSet(schism_components(i), name='analysis_step', & - value=1, rc=localrc) + value=1, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) else call ESMF_AttributeSet(schism_components(i), name='analysis_step', & - value=0, rc=localrc) + value=0, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - endif !DA step + end if !DA step - call ESMF_GridCompRun(schism_components(i), importState= importStateList(i), & - exportState=exportStateList(i), clock=clock, rc=localrc) + call ESMF_GridCompRun(schism_components(i), importState=importStateList(i), & + exportState=exportStateList(i), clock=clock, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - enddo !i + end do !i - if (it==list_obs_steps(next_obs_step)) next_obs_step=min(num_obs_steps,next_obs_step+1) + if (it == list_obs_steps(next_obs_step)) next_obs_step = min(num_obs_steps, next_obs_step + 1) - call MPI_barrier(MPI_COMM_WORLD,ii) - if(ii/=MPI_SUCCESS) call MPI_abort(MPI_COMM_WORLD,0,j) + call MPI_barrier(MPI_COMM_WORLD, ii) + if (ii /= MPI_SUCCESS) call MPI_abort(MPI_COMM_WORLD, 0, j) ! Move PDAF_put_state here to match flexible mode ! Disable local filter for dev @@ -444,9 +444,8 @@ program main ! Can we add "call schism_save_state(cohortIndex)" here to update state_p? ! write(*,*) 'in schism_pdaf:',tr_el(1,1,1),myrank - ! DA step -! if (it==list_obs_steps(next_obs_step)) then ! DA step (update ens field)   +! if (it==list_obs_steps(next_obs_step)) then ! DA step (update ens field) ! time_PDAF=list_obs_steps(next_obs_step) ! write(*,*) 'Before PDAF_get_state in schism_pdaf!', it,next_obs_step,num_obs_steps,time_PDAF,doexit ! call PDAF_get_state(it,time_PDAF, doexit, next_observation_pdaf, distribute_state_pdaf, prepoststep_ens, status_pdaf) @@ -454,7 +453,6 @@ program main ! next_obs_step=min(num_obs_steps,next_obs_step+1) ! endif ! DA step - ! Advance coupling clock to next timestep call ESMF_ClockAdvance(clock, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) @@ -514,27 +512,27 @@ program main #ifdef USE_PDAF ! PDAF finalize - call finalize_pdaf() + call finalize_pdaf() #endif - do i = 1,schismCount - call ESMF_GridCompFinalize(schism_components(i), importState= importStateList(i), & - exportState=exportStateList(i), clock=clock, rc=localrc) - _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) + do i = 1, schismCount + call ESMF_GridCompFinalize(schism_components(i), importState=importStateList(i), & + exportState=exportStateList(i), clock=clock, rc=localrc) + _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - call ESMF_StateDestroy( importStateList(i), rc=localrc) - _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) + call ESMF_StateDestroy(importStateList(i), rc=localrc) + _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - call ESMF_StateDestroy(exportStateList(i), rc=localrc) - _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) + call ESMF_StateDestroy(exportStateList(i), rc=localrc) + _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - call ESMF_GridCompDestroy(schism_components(i), rc=localrc) - _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - enddo !i + call ESMF_GridCompDestroy(schism_components(i), rc=localrc) + _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) + end do !i - deallocate(exportStateList) - deallocate( importStateList) - deallocate(schism_components) + deallocate (exportStateList) + deallocate (importStateList) + deallocate (schism_components) ! deallocate(configList) call ESMF_ClockDestroy(clock, rc=localrc) @@ -544,43 +542,43 @@ program main end program main -subroutine clockCreateFrmParam(clock,schism_dt,num_schism_dt_in_couple,runhours,num_obs_steps) +subroutine clockCreateFrmParam(clock, schism_dt, num_schism_dt_in_couple, runhours, num_obs_steps) use esmf implicit none ! character(len=ESMF_MAXSTR), intent(in) :: filename ! integer(ESMF_KIND_I4), intent(out) :: rc - type(ESMF_Clock), intent(out) :: clock + type(ESMF_Clock), intent(out) :: clock !SCHISM dt (sec) must be int - integer(ESMF_KIND_I4), intent(out) :: schism_dt,num_schism_dt_in_couple,runhours,num_obs_steps + integer(ESMF_KIND_I4), intent(out) :: schism_dt, num_schism_dt_in_couple, runhours, num_obs_steps - logical :: isPresent - integer(ESMF_KIND_I4) :: unit, localrc,rc - type(ESMF_Time) :: stopTime, startTime + logical :: isPresent + integer(ESMF_KIND_I4) :: unit, localrc, rc + type(ESMF_Time) :: stopTime, startTime type(ESMF_TimeInterval) :: timeStep - integer(ESMF_KIND_I4) :: start_year=2000, start_month=1, start_day=1 - integer(ESMF_KIND_I4) :: start_hour=0, itmp - namelist /sim_time/ start_year,start_month,start_day,start_hour,runhours, & - &schism_dt,num_schism_dt_in_couple,num_obs_steps + integer(ESMF_KIND_I4) :: start_year = 2000, start_month = 1, start_day = 1 + integer(ESMF_KIND_I4) :: start_hour = 0, itmp + namelist /sim_time/ start_year, start_month, start_day, start_hour, runhours, & + &schism_dt, num_schism_dt_in_couple, num_obs_steps ! inquire(file='global.nml', exist=isPresent) ! if (isPresent) then call ESMF_UtilIOUnitGet(unit, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - open(unit, file='global.nml', iostat=localrc) + open (unit, file='global.nml', iostat=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - read(unit, nml=sim_time, iostat=localrc) + read (unit, nml=sim_time, iostat=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - close(unit) + close (unit) ! endif ! Set day as timestep temporarily to count later to stop time call ESMF_TimeSet(startTime, yy=start_year, mm=start_month, dd=start_day, & - h=start_hour, rc=localrc) + h=start_hour, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) !'h': hour @@ -594,12 +592,12 @@ subroutine clockCreateFrmParam(clock,schism_dt,num_schism_dt_in_couple,runhours, ! timeStep = timeStep / 24 !Set time interval in sec, used in ESMF main stepping - itmp=schism_dt*num_schism_dt_in_couple !has to be int + itmp = schism_dt * num_schism_dt_in_couple !has to be int call ESMF_TimeIntervalSet(timeStep, s=itmp, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) clock = ESMF_ClockCreate(timeStep, startTime, stopTime=stopTime, & - name='main clock', rc=localrc) + name='main clock', rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) end subroutine clockCreateFrmParam diff --git a/triple_schism.F90 b/triple_schism.F90 index ccdd1e9..5a4c68d 100644 --- a/triple_schism.F90 +++ b/triple_schism.F90 @@ -10,7 +10,7 @@ ! you may not use this file except in compliance with the License. ! You may obtain a copy of the License at ! -! http://www.apache.org/licenses/LICENSE-2.0 +! http://www.apache.org/licenses/LICENSE-2.0 ! ! Unless required by applicable law or agreed to in writing, software ! distributed under the License is distributed on an "AS IS" BASIS, @@ -34,33 +34,33 @@ program main use esmf use schism_esmf_util, only: clockCreateFrmParam use schism_esmf_cap, only: schismSetServices => SetServices - use atmosphere_cmi_esmf, only: atmosSetServices => SetServices + use atmosphere_cmi_esmf, only: atmosSetServices => SetServices implicit none type(ESMF_GridComp), allocatable :: schism_components(:) - type(ESMF_GridComp) :: atmos_component + type(ESMF_GridComp) :: atmos_component - type(ESMF_State), allocatable :: schism_imports(:), schism_exports(:) - type(ESMF_State) :: atmos_import, atmos_export + type(ESMF_State), allocatable :: schism_imports(:), schism_exports(:) + type(ESMF_State) :: atmos_import, atmos_export type(ESMF_TimeInterval) :: timestep - type(ESMF_Time) :: start_time, stop_time - type(ESMF_Clock) :: clock + type(ESMF_Time) :: start_time, stop_time + type(ESMF_Clock) :: clock - type(ESMF_Field) :: field, field_in - type(ESMF_Field), allocatable :: fields_out(:) + type(ESMF_Field) :: field, field_in + type(ESMF_Field), allocatable :: fields_out(:) - type(ESMF_RouteHandle) :: routehandle_sea2air - type(ESMF_RouteHandle), allocatable :: routehandles_air2sea(:) - type(ESMF_Vm) :: vm + type(ESMF_RouteHandle) :: routehandle_sea2air + type(ESMF_RouteHandle), allocatable :: routehandles_air2sea(:) + type(ESMF_Vm) :: vm - integer(ESMF_KIND_I4) :: petCountLocal, schismCount=3 - integer(ESMF_KIND_I4) :: rc, petCount, i, j, inum, localrc - integer(ESMF_KIND_I4), allocatable :: petlist(:) + integer(ESMF_KIND_I4) :: petCountLocal, schismCount = 3 + integer(ESMF_KIND_I4) :: rc, petCount, i, j, inum, localrc + integer(ESMF_KIND_I4), allocatable :: petlist(:) real(ESMF_KIND_R8), pointer :: ptr1d(:) - logical :: isPresent - character(len=ESMF_MAXSTR) :: filename, message + logical :: isPresent + character(len=ESMF_MAXSTR) :: filename, message call ESMF_Initialize(defaultCalKind=ESMF_CALKIND_GREGORIAN, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) @@ -78,35 +78,34 @@ program main ! Create all components on their respective parallel ! environment provided by each petList - allocate(schism_components(schismCount)) + allocate (schism_components(schismCount)) do i = 1, schismCount - petCountLocal = petCount/max(1, schismCount) - allocate(petlist(petCountLocal), stat=localrc) + petCountLocal = petCount / max(1, schismCount) + allocate (petlist(petCountLocal), stat=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - do j=1, petCountLocal - petList(j)=(i-1)*petCountLocal + j - 1 ! 0 based + do j = 1, petCountLocal + petList(j) = (i - 1) * petCountLocal + j - 1 ! 0 based end do - - write(message, '(A,I1)') 'schism_', i + write (message, '(A,I1)') 'schism_', i !write(0, *) trim(message), 'list=', petList, 'petCount=', petCount, petCountLocal schism_components(i) = ESMF_GridCompCreate(name=trim(message), & - petList=petlist, rc=localrc) + petList=petlist, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - deallocate(petList) + deallocate (petList) end do - allocate(schism_exports(schismCount)) - allocate(schism_imports(schismCount)) + allocate (schism_exports(schismCount)) + allocate (schism_imports(schismCount)) do i = 1, schismCount call ESMF_GridCompSetServices(schism_components(i), & - schismSetServices, rc=localrc) + schismSetServices, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) schism_exports(i) = ESMF_StateCreate(name='schism export state', rc=localrc) @@ -118,7 +117,7 @@ program main end do atmos_component = ESMF_GridCompCreate(name='atmosphere_1', & - petList=(/petCount - 1/), rc=localrc) + petList=(/petCount - 1/), rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) atmos_export = ESMF_StateCreate(name='atmos export state', rc=localrc) @@ -128,10 +127,9 @@ program main _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) call ESMF_GridCompSetServices(atmos_component, & - atmosSetServices, rc=localrc) + atmosSetServices, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - filename = './global.nml' clock = clockCreateFrmParam(filename, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) @@ -139,13 +137,13 @@ program main do i = 1, schismCount call ESMF_GridCompInitialize(schism_components(i), importState=schism_imports(i), & - exportState=schism_exports(i), clock=clock, rc=localrc) - _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) + exportState=schism_exports(i), clock=clock, rc=localrc) + _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) end do call ESMF_GridCompInitialize(atmos_component, importState=atmos_import, & - exportState=atmos_export, clock=clock, rc=localrc) + exportState=atmos_export, clock=clock, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) !Make sure that all states are reconciled across the @@ -165,45 +163,45 @@ program main ! Within the schism component, the following fields are ! defined for import and export (y-component not implemented yet) - call ESMF_StateGet(atmos_export,'wind_x-velocity', & - field=field_in, rc=localrc) + call ESMF_StateGet(atmos_export, 'wind_x-velocity', & + field=field_in, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - allocate(fields_out(schismCount)) - allocate(routehandles_air2sea(schismCount)) + allocate (fields_out(schismCount)) + allocate (routehandles_air2sea(schismCount)) do i = 1, schismCount call ESMF_StateGet(schism_imports(i), 'wind_x-velocity_in_10m_height', & - field=fields_out(i), rc=localrc) + field=fields_out(i), rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) ! Precompute the weights call ESMF_FieldRegridStore(field_in, fields_out(i), & - routehandle=routehandles_air2sea(i), rc=localrc) + routehandle=routehandles_air2sea(i), rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - enddo + end do ! Loop over coupling timesteps until stopTime - do while ( .not. (ESMF_ClockIsStopTime(clock))) + do while (.not. (ESMF_ClockIsStopTime(clock))) !> Directly manipulate the fields from import and export !> states. In less basic applications, this should be !> handled by a mediator component. - do i=1, schismCount + do i = 1, schismCount call ESMF_FieldRegrid(field_in, fields_out(i), & - routeHandle=routehandles_air2sea(i), rc=localrc) - _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - enddo + routeHandle=routehandles_air2sea(i), rc=localrc) + _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) + end do call ESMF_GridCompRun(atmos_component, importState=atmos_import, & - exportState=atmos_export, clock=clock, rc=localrc) + exportState=atmos_export, clock=clock, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - do i=1, schismCount + do i = 1, schismCount call ESMF_GridCompRun(schism_components(i), importState=schism_imports(i), & - exportState=schism_exports(i), clock=clock, rc=localrc) + exportState=schism_exports(i), clock=clock, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) - enddo + end do call ESMF_ClockAdvance(clock, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) @@ -211,14 +209,14 @@ program main ! Clean up - deallocate(fields_out) - deallocate(routehandles_air2sea) + deallocate (fields_out) + deallocate (routehandles_air2sea) do i = 1, schismCount call ESMF_GridCompFinalize(schism_components(i), importState=schism_imports(i), & - exportState=schism_exports(i), clock=clock, rc=localrc) - _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) + exportState=schism_exports(i), clock=clock, rc=localrc) + _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) call ESMF_StateDestroy(schism_imports(i), rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) @@ -229,9 +227,9 @@ program main call ESMF_GridCompDestroy(schism_components(i), rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc) end do - deallocate(schism_exports) - deallocate(schism_imports) - deallocate(schism_components) + deallocate (schism_exports) + deallocate (schism_imports) + deallocate (schism_components) call ESMF_ClockDestroy(clock, rc=localrc) _SCHISM_LOG_AND_FINALIZE_ON_ERROR_(rc)