Skip to content

Commit

Permalink
clean up DriverAddComp statements
Browse files Browse the repository at this point in the history
* reduce lines required to add each component or reporting
on an unfound component by adding "found_comp" logical. This
allows a single error statement to be used for each possible
"not found" error
  • Loading branch information
DeniseWorthen committed Apr 17, 2021
1 parent ae01a66 commit 6f7ea44
Showing 1 changed file with 54 additions and 90 deletions.
144 changes: 54 additions & 90 deletions src/module_EARTH_GRID_COMP.F90
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ subroutine SetModelServices(driver, rc)
integer :: petListBounds(2)
integer :: componentCount
type(NUOPC_FreeFormat) :: attrFF, fdFF
logical :: found_comp
#ifdef CMEPS
logical :: read_restart
character(ESMF_MAXSTR) :: cvalue
Expand Down Expand Up @@ -362,138 +363,101 @@ subroutine SetModelServices(driver, rc)
petList(j-petListBounds(1)+1) = j ! PETs are 0 based
enddo

if (trim(model) == "fv3") then
found_comp = .false.
#ifdef FRONT_FV3
if (trim(model) == "fv3") then
call NUOPC_DriverAddComp(driver, trim(prefix), FV3_SS, &
petList=petList, comp=comp, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=trim(name)//":"//__FILE__)) return ! bail out
#else
write (msg, *) "Model '", trim(model), "' was requested, "// &
"but is not available in the executable!"
call ESMF_LogSetError(ESMF_RC_NOT_VALID, msg=msg, line=__LINE__, &
file=__FILE__, rcToReturn=rc)
return ! bail out
if (ChkErr(rc,__LINE__,u_FILE_u)) return
found_comp = .true.
end if
#endif
elseif (trim(model) == "datm") then
#ifdef FRONT_DATM
if (trim(model) == "datm") then
call NUOPC_DriverAddComp(driver, trim(prefix), DATM_SS, &
petList=petList, comp=comp, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=trim(name)//":"//__FILE__)) return ! bail out
#else
write (msg, *) "Model '", trim(model), "' was requested, "// &
"but is not available in the executable!"
call ESMF_LogSetError(ESMF_RC_NOT_VALID, msg=msg, line=__LINE__, &
file=__FILE__, rcToReturn=rc)
return ! bail out
if (ChkErr(rc,__LINE__,u_FILE_u)) return
found_comp = .true.
end if
#endif
elseif (trim(model) == "hycom") then
#ifdef FRONT_HYCOM
if (trim(model) == "hycom") then
call NUOPC_DriverAddComp(driver, trim(prefix), HYCOM_SS, &
petList=petList, comp=comp, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=trim(name)//":"//__FILE__)) return ! bail out
#else
write (msg, *) "Model '", trim(model), "' was requested, "// &
"but is not available in the executable!"
call ESMF_LogSetError(ESMF_RC_NOT_VALID, msg=msg, line=__LINE__, &
file=__FILE__, rcToReturn=rc)
return ! bail out
if (ChkErr(rc,__LINE__,u_FILE_u)) return
found_comp = .true.
end if
#endif
elseif (trim(model) == "mom6") then
#ifdef FRONT_MOM6
if (trim(model) == "mom6") then
call NUOPC_DriverAddComp(driver, trim(prefix), MOM6_SS, &
petList=petList, comp=comp, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=trim(name)//":"//__FILE__)) return ! bail out
#else
write (msg, *) "Model '", trim(model), "' was requested, "// &
"but is not available in the executable!"
call ESMF_LogSetError(ESMF_RC_NOT_VALID, msg=msg, line=__LINE__, &
file=__FILE__, rcToReturn=rc)
return ! bail out
if (ChkErr(rc,__LINE__,u_FILE_u)) return
found_comp = .true.
end if
#endif
elseif (trim(model) == "cice6") then
#ifdef FRONT_CICE6
if (trim(model) == "cice6") then
call NUOPC_DriverAddComp(driver, trim(prefix), CICE6_SS, &
petList=petList, comp=comp, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=trim(name)//":"//__FILE__)) return ! bail out
#else
write (msg, *) "Model '", trim(model), "' was requested, "// &
"but is not available in the executable!"
call ESMF_LogSetError(ESMF_RC_NOT_VALID, msg=msg, line=__LINE__, &
file=__FILE__, rcToReturn=rc)
return ! bail out
if (ChkErr(rc,__LINE__,u_FILE_u)) return
found_comp = .true.
end if
#endif
elseif (trim(model) == "ww3") then
#ifdef FRONT_WW3
if (trim(model) == "ww3") then
call NUOPC_DriverAddComp(driver, trim(prefix), WW3_SS, &
petList=petList, comp=comp, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=trim(name)//":"//__FILE__)) return ! bail out
#else
write (msg, *) "Model '", trim(model), "' was requested, "// &
"but is not available in the executable!"
call ESMF_LogSetError(ESMF_RC_NOT_VALID, msg=msg, line=__LINE__, &
file=__FILE__, rcToReturn=rc)
return ! bail out
if (ChkErr(rc,__LINE__,u_FILE_u)) return
found_comp = .true.
end if
#endif
elseif (trim(model) == "noah") then
#ifdef FRONT_NOAH
if (trim(model) == "noah") then
call NUOPC_DriverAddComp(driver, trim(prefix), NOAH_SS, &
petList=petList, comp=comp, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=trim(name)//":"//__FILE__)) return ! bail out
#else
write (msg, *) "Model '", trim(model), "' was requested, "// &
"but is not available in the executable!"
call ESMF_LogSetError(ESMF_RC_NOT_VALID, msg=msg, line=__LINE__, &
file=__FILE__, rcToReturn=rc)
return ! bail out
if (ChkErr(rc,__LINE__,u_FILE_u)) return
found_comp = .true.
end if
#endif
elseif (trim(model) == "lis") then
#ifdef FRONT_LIS
if (trim(model) == "lis") then
call NUOPC_DriverAddComp(driver, trim(prefix), LIS_SS, &
petList=petList, comp=comp, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=trim(name)//":"//__FILE__)) return ! bail out
#else
write (msg, *) "Model '", trim(model), "' was requested, "// &
"but is not available in the executable!"
call ESMF_LogSetError(ESMF_RC_NOT_VALID, msg=msg, line=__LINE__, &
file=__FILE__, rcToReturn=rc)
return ! bail out
if (ChkErr(rc,__LINE__,u_FILE_u)) return
found_comp = .true.
end if
#endif
#ifdef FRONT_IPE
if (trim(model) == "ipe") then
call NUOPC_DriverAddComp(driver, trim(prefix), IPE_SS, &
petList=petList, comp=comp, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
found_comp = .true.
end if
#endif
elseif (trim(model) == "gsdchem") then
#ifdef FRONT_GSDCHEM
if (trim(model) == "gsdchem") then
call NUOPC_DriverAddComp(driver, trim(prefix), GSDCHEM_SS, &
petList=petList, comp=comp, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=trim(name)//":"//__FILE__)) return ! bail out
#else
write (msg, *) "Model '", trim(model), "' was requested, "// &
"but is not available in the executable!"
call ESMF_LogSetError(ESMF_RC_NOT_VALID, msg=msg, line=__LINE__, &
file=__FILE__, rcToReturn=rc)
return ! bail out
if (ChkErr(rc,__LINE__,u_FILE_u)) return
found_comp = .true.
end if
#endif
elseif (trim(model) == "cmeps") then
#ifdef FRONT_CMEPS
if (trim(model) == "cmeps") then
med_id = i+1
call NUOPC_DriverAddComp(driver, trim(prefix), MED_SS, &
petList=petList, comp=comp, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, file=trim(name)//":"//__FILE__)) return ! bail out
if (ChkErr(rc,__LINE__,u_FILE_u)) return
found_comp = .true.
end if
#endif
else
! Error condition: unknown model requested
write (msg, *) "The requested model '", trim(model), &
"' is an invalid choice!"
call ESMF_LogSetError(ESMF_RC_NOT_VALID, msg=msg, line=__LINE__, &
if (.not. found_comp) then
write(msg,*) 'No component ',trim(model),' found'
call ESMF_LogSetError(ESMF_RC_NOT_VALID, msg=msgstr, line=__LINE__, &
file=__FILE__, rcToReturn=rc)
return ! bail out
return
endif

! read and ingest free format component attributes
Expand Down

0 comments on commit 6f7ea44

Please sign in to comment.