Skip to content

Commit

Permalink
Merge pull request #2 from odav/develop
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
odav authored Nov 6, 2024
2 parents d4c0d08 + ebfbbc4 commit 4e944de
Show file tree
Hide file tree
Showing 183 changed files with 2,767 additions and 2,881 deletions.
122 changes: 88 additions & 34 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,50 @@ on:
- '*.*.*'

workflow_dispatch:
inputs:
rev:
description: 'tag, branch, or SHA to check out'
required: true
default: 'develop'

permissions:
contents: write
packages: write
pull-requests: write

jobs:

version:
name: Version
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: '${{ github.event.inputs.rev }}'
fetch-tags: true
fetch-depth: 0
- name: Get SWAT+ version
id: get_version
run: |
V=`git describe --tags`
echo $V
echo $V >v.txt
cat v.txt
echo ${{ github.event.release.tag_name }}
echo ${GITHUB_REF#refs/*/}
- name: upload
uses: actions/upload-artifact@v4
with:
name: release_tag
path: v.txt


build:
runs-on: ${{ matrix.os }}
if: endsWith(github.event.base_ref, 'main') == true
needs:
- version
# if: endsWith(github.event.base_ref, 'main') == true

strategy:
fail-fast: false
Expand All @@ -38,7 +72,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
# with:
with:
ref: '${{ github.event.inputs.rev }}'
# fetch-tags: true
# fetch-depth: 0

Expand All @@ -49,13 +84,19 @@ jobs:
compiler: ${{ matrix.toolchain.compiler }}
version: ${{ matrix.toolchain.version }}

- name: Download version
uses: actions/download-artifact@v4
with:
name: release_tag

- name: Build SWAT+
id: build_exe
run: |
echo ${{ env.FC }}
cmake --version
RELEASE_VERSION=${GITHUB_REF#refs/*/}
# RELEASE_VERSION=${GITHUB_REF#refs/*/}
RELEASE_VERSION=`cat v.txt`
os="$RUNNER_OS"
if [ "$RUNNER_OS" == "Linux" ]; then
Expand Down Expand Up @@ -83,7 +124,7 @@ jobs:
fi
# compile
cmake --build build
cmake --build build -j 4
exebase=`basename -s .exe build/swatplus-*`
exez="${exebase}.zip"
Expand Down Expand Up @@ -114,7 +155,7 @@ jobs:
dest: ${{ steps.build_exe.outputs.exez }}

- name: upload
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: sp-${{ steps.build_exe.outputs.os }}
path: ${{ steps.build_exe.outputs.exez }}
Expand All @@ -127,35 +168,48 @@ jobs:
- build

steps:
- name: Download Linux
uses: actions/download-artifact@v2
with:
name: sp-Linux

- name: Download Windows
uses: actions/download-artifact@v2
with:
name: sp-Windows

- name: Download macOS
uses: actions/download-artifact@v2
with:
name: sp-macOS

- name: Release
uses: softprops/action-gh-release@v2
with:
token: ${{ github.token }}
tag_name: ${{ github.event.release.tag_name }}
prerelease: false
draft: false
name: ${{ github.event.release.tag_name }}
files: swatplus-*
generate_release_notes: true
body: |
<details>
- name: Download Linux
uses: actions/download-artifact@v4
with:
name: sp-Linux

- name: Download Windows
uses: actions/download-artifact@v4
with:
name: sp-Windows

- name: Download macOS
uses: actions/download-artifact@v4
with:
name: sp-macOS

- name: Download version
uses: actions/download-artifact@v4
with:
name: release_tag

- name: Read version
id: read_ver
run: |
RELEASE_VERSION=`cat v.txt`
echo "rv=$RELEASE_VERSION" >> $GITHUB_OUTPUT
- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
token: ${{ github.token }}
# tag_name: ${{ github.event.release.tag_name }}
prerelease: false
draft: false
# name: ${{ github.event.release.tag_name }}
name: ${{ steps.read_ver.outputs.rv }}
files: swatplus-*
generate_release_notes: true
body: |
<details>
<summary>Autogenerated Changelog</summary>
... changelog ...
</details>
... changelog ...
</details>
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ CMakeCache.txt
Resources/R*
src/main.f90
ford.md
/.vs/SWAT_PLUS_DEV
/.vs/SWAT_PLUS_DEV
/.vscode
25 changes: 12 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ if (UNIX)
set(fdialect "-free -fpe0 -traceback -diag-disable=10448")
set(fdebug "-warn all")
set(frelease "-O")
set(FFC "ifo")
set(FFC "ifo")
link_libraries("-static")
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL IntelLLVM)
set(fdialect "-free -fpe0 -traceback")
set(fdebug "-warn all -O0")
set(frelease "-O")
set(FFC "ifx")
set(FFC "ifx")
link_libraries("-static")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES GNU)
set(fdialect "-fcheck=all -ffpe-trap=invalid,zero,overflow,underflow -fimplicit-none -ffree-line-length-none -fbacktrace -finit-local-zero -fno-unsafe-math-optimizations -frounding-math -fsignaling-nans")
set(fdebug "-Wall")
set(frelease "-O")
set(FFC "gcc")
set(fdialect "-fcheck=all -ffpe-trap=invalid,zero,overflow,underflow -fimplicit-none -ffree-line-length-none -fbacktrace -finit-local-zero -fno-unsafe-math-optimizations -frounding-math -fsignaling-nans")
set(fdebug "-Wall")
set(frelease "-O")
set(FFC "gnu")
if(NOT APPLE)
link_libraries("-static")
endif()
Expand All @@ -66,18 +66,18 @@ elseif(WIN32)
elseif(CMAKE_Fortran_COMPILER_ID MATCHES GNU)
set(fdialect "-fcheck=all -ffpe-trap=invalid,zero,overflow,underflow -fimplicit-none -ffree-line-length-none -fbacktrace -finit-local-zero -fno-unsafe-math-optimizations -frounding-math -fsignaling-nans")
set(fdebug "-Wall ")
set(FFC "gcc")
set(FFC "gnu")
set(frelease "-O")
endif()
endif()

string(TOLOWER ${CMAKE_HOST_SYSTEM_PROCESSOR} ARCH)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(AR "${FFC}-lin_${ARCH}")
set(AR "lin_${ARCH}")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(AR "${FFC}-win_${ARCH}")
set(AR "win_${ARCH}")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(AR "${FFC}-mac_${ARCH}")
set(AR "mac_${ARCH}")
else()
set(AR "unknown")
endif()
Expand All @@ -92,9 +92,9 @@ endif()

# SWAT Version number
set(SWAT_VERSION ${TAG})
set(SWATPLUS_EXE "swatplus-${SWAT_VERSION}-${AR}${TY}")
set(SWATPLUS_EXE "swatplus-${SWAT_VERSION}-${FFC}-${AR}${TY}")

# Enable this to 'TRUE' to see the fortran command on compile
# Set this to 'TRUE' to see the fortran command on compile
set(CMAKE_VERBOSE_MAKEFILE FALSE)

set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${fdialect}")
Expand All @@ -111,7 +111,6 @@ set(CMAKE_Fortran_FLAGS_RELEASE "${frelease}")

if(EXISTS "${PROJECT_SOURCE_DIR}/src/main.f90.in")
string(TIMESTAMP ISO "%Y-%m-%d %H:%M:%S")
# string(TIMESTAMP TODAY "%b %d %Y") # e.g. produces Dec 7 2023
string(TIMESTAMP TODAY "%Y-%m-%d") # e.g. produces 2023-12-07
string(TIMESTAMP YEAR "%Y")

Expand Down
41 changes: 38 additions & 3 deletions src/actions.f90
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ subroutine actions (ob_cur, ob_num, idtbl)
integer :: imallo = 0
integer :: idmd = 0
integer :: irec = 0
integer :: iplt = 0
integer :: num_plts_cur = 0
real :: hiad1 = 0. ! |
real :: biomass = 0. ! |
real :: frt_kg = 0.
Expand All @@ -88,7 +90,7 @@ subroutine actions (ob_cur, ob_num, idtbl)
real :: cn_prev = 0.
real :: stor_m3 = 0.
character(len=1) :: action = "" ! |
character(len=25) :: lu_prev = "" ! |
character(len=40) :: lu_prev = "" ! |

do iac = 1, d_tbl%acts
action = "n"
Expand Down Expand Up @@ -398,12 +400,13 @@ subroutine actions (ob_cur, ob_num, idtbl)
harveff = d_tbl%act(iac)%const
call mgt_harvresidue (j, harveff)
case ("tree")
call mgt_harvbiomass (j, ipl, iharvop)
case ("tuber")
call mgt_harvtuber (j, ipl, iharvop)
case ("peanuts")
call mgt_harvtuber (j, ipl, iharvop)
case ("stripper")
call mgt_harvgrain (j, ipl, iharvop)
call mgt_harvbiomass (j, ipl, iharvop)
case ("picker")
call mgt_harvgrain (j, ipl, iharvop)
end select
Expand Down Expand Up @@ -886,7 +889,10 @@ subroutine actions (ob_cur, ob_num, idtbl)
case ("lu_change")
j = d_tbl%act(iac)%ob_num
if (j == 0) j = ob_cur
if (d_tbl%lu_chg_mx(iac) <= Int(d_tbl%act(iac)%const2)) then
d_tbl%lu_chg_mx(iac) = d_tbl%lu_chg_mx(iac) + 1
ilu = d_tbl%act_typ(iac)
hru(j)%land_use_mgt = ilu
hru(j)%dbs%land_use_mgt = ilu
lu_prev = hru(j)%land_use_mgt_c
hru(j)%land_use_mgt_c = d_tbl%act(iac)%file_pointer
Expand All @@ -902,6 +908,27 @@ subroutine actions (ob_cur, ob_num, idtbl)
write (3612,*) j, time%yrc, time%mo, time%day_mo, " LU_CHANGE ", &
lu_prev, hru(j)%land_use_mgt_c, " 0 0"

!! add new plants in simulation for yield output
do ipl = 1, pcom(j)%npl
if (basin_plants == 0) then
plts_bsn(1) = pcom(j)%pl(ipl)
basin_plants = 1
else
num_plts_cur = basin_plants
do iplt = 1, num_plts_cur
if (pcom(j)%pl(ipl) == plts_bsn(iplt)) exit
if (iplt == basin_plants) then
plts_bsn(iplt+1) = pcom(j)%pl(ipl)
bsn_crop_yld(iplt+1) = bsn_crop_yld_z
bsn_crop_yld_aa(iplt+1) = bsn_crop_yld_z
basin_plants = basin_plants + 1
pcom(j)%plcur(ipl)%bsn_num = basin_plants
end if
end do
end if
end do
!pcom(j)%dtbl(idtbl)%num_actions(iac) = pcom(j)%dtbl(idtbl)%num_actions(iac) + 1
end if
!land use change - contouring
case ("p_factor")
j = d_tbl%act(iac)%ob_num
Expand Down Expand Up @@ -1033,7 +1060,8 @@ subroutine actions (ob_cur, ob_num, idtbl)

do istr = 1, db_mx%grassop_db
if (d_tbl%act(iac)%file_pointer == grwaterway_db(istr)%name) then
istr1 = istr
!istr1 = istr
hru(j)%lumv%grwat_i = 1
exit
end if
end do
Expand All @@ -1045,6 +1073,13 @@ subroutine actions (ob_cur, ob_num, idtbl)
write (3612,*) j, time%yrc, time%mo, time%day_mo, " GRASSWW_INSTALL ", &
sdr(istr)%name, sdr(istr1)%name, " 0 0"

!install grass waterways
case ("grassww_uninstall")
j = d_tbl%act(iac)%ob_num
if (j == 0) j = ob_cur
hru(j)%lumv%grwat_i = 0
write (3612,*) j, time%yrc, time%mo, time%day_mo, " GRASSWW_UNINSTALL ", &
sdr(istr)%name, sdr(istr1)%name, " 0 0"
!user defined bmp reductions
case ("user_def_bmp")
j = d_tbl%act(iac)%ob_num
Expand Down
2 changes: 1 addition & 1 deletion src/allocate_parms.f90
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ subroutine allocate_parms

!! By Zhang for C/N cycling
!! ============================
call zero0
call zero1
call zero2
Expand Down
2 changes: 1 addition & 1 deletion src/aqu_cs_output.f90
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ subroutine aqu_cs_output(iaq) !rtb cs
(acsb_d(iaq)%cs(ics)%srbd,ics=1,cs_db%num_cs)
if (pco%csvout == "y") then
write (6061,'(*(G0.3,:","))') time%day, time%mo, time%day_mo, time%yrc, iaq, ob(iob)%gis_id, &
(acsb_d(iaq)%cs(ics)%csgw,ics=1,cs_db%num_cs), &
(acsb_d(iaq)%cs(ics)%csgw,ics=1,cs_db%num_cs), &
(acsb_d(iaq)%cs(ics)%rchrg,ics=1,cs_db%num_cs), &
(acsb_d(iaq)%cs(ics)%seep,ics=1,cs_db%num_cs), &
(acsb_d(iaq)%cs(ics)%irr,ics=1,cs_db%num_cs), &
Expand Down
2 changes: 1 addition & 1 deletion src/aqu_salt_output.f90
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ subroutine aqu_salt_output(iaq)
asaltb_d(iaq)%salt(1)%diss
if (pco%csvout == "y") then
write (5061,'(*(G0.3,:","))') time%day, time%mo, time%day_mo, time%yrc, iaq, ob(iob)%gis_id, &
(asaltb_d(iaq)%salt(isalt)%saltgw,isalt=1,cs_db%num_salts), &
(asaltb_d(iaq)%salt(isalt)%saltgw,isalt=1,cs_db%num_salts), &
(asaltb_d(iaq)%salt(isalt)%rchrg,isalt=1,cs_db%num_salts), &
(asaltb_d(iaq)%salt(isalt)%seep,isalt=1,cs_db%num_salts), &
(asaltb_d(iaq)%salt(isalt)%irr,isalt=1,cs_db%num_salts), &
Expand Down
Loading

0 comments on commit 4e944de

Please sign in to comment.