SUBROUTINE RIVER(IRIVER,JRIVER,EL,ET,D,DT,S,T,IMAX,JMAX,KMAX, + FRIVER,TRIVER,DEPMIX,TSTEP,DX,DY,H,DZ,IFAIL) C***BEGIN PROLOGUE RIVER C***DATE WRITTEN 910219 (YYMMDD) C***REVISION DATE 910219 (YYMMDD) C***AUTHOR C Jarle Berntsen, Institute of Marine Research, C Postboks 1870, C N-5024 Bergen-Nordnes, Norway C Email.. jarleb@imr.no C***PURPOSE RIVER computes new values of EL,ET,D,DT,S and T in C grid cell (IRIVER,JRIVER) as functions C of the flux, FRIVER, and the temperature, TRIVER, C of the river water. C C This version of RIVER is used to update the C datastructures used in the ECOM3D model. C C***DESCRIPTION C C The river enters the sea in grid cell (IRIVER,JRIVER). C The flux is FRIVER, the temperature is TRIVER and C the salinity is assumed to be 0. C C The added river water is first placed above C the sea water and we have to increase the water levels C EL and ET and the depths D and DT. C The river water is then mixed into the top layer(s) C down to the depth MIN(H(IRIVER,JRIVER),DEPMIX), and C new values of S and T in the top cell(s) are therefore C produced. C C C ON ENTRY C C IRIVER Integer. C The index of the sea cell in X-direction. C JRIVER Integer. C The index of the sea cell in Y-direction. C EL Real array of dimension (IMAX,JMAX). C The surface elevation as used in the external mode C of ECOM3D (m). C ET Real array of dimension (IMAX,JMAX). C The surface elevation as used in the internal mode C of ECOM3D (m). C D Real array of dimension (IMAX,JMAX). C The bottom depth + EL (m). C DT Real array of dimension (IMAX,JMAX). C The bottom depth + ET (m). C S Real array of dimension (IMAX,JMAX,KMAX). C The salinity of each cell (psu). C T Real array of dimension (IMAX,JMAX,KMAX). C The temperature of each cell (celsius). C IMAX Integer. C Number of cells in X-direction. C JMAX Integer. C Number of cells in Y-direction. C KMAX Integer. C Number of cells in Sigma-direction. C FRIVER Real. C The flux of the river in m**3/s. C TRIVER Real. C The temperature of the river water in Celsius. C DEPMIX Real. C The river water is mixed with the sea water C down to the depth MIN(H(IRIVER,JRIVER),DEPMIX) C TSTEP Real. C The timestep (s). C DX Real. C The width of a cell in X-direction (m). C DY Real. C The width of a cell in Y-direction (m). C H Real array of dimension (IMAX,JMAX). C The bottom depth (m). C DZ Real array of dimension KMAX. C The sigma coordinate thickness of the layers. C C ON RETURN C C EL EL(IRIVER,JRIVER) will be corrected. C ET ET(IRIVER,JRIVER) will be corrected. C D D(IRIVER,JRIVER) will be corrected. C DT DT(IRIVER,JRIVER) will be corrected. C S S(IRIVER,JRIVER,1) will be corrected. C T T(IRIVER,JRIVER,1) will be corrected. C C IFAIL Integer. C IFAIL is 0 on exit when EL,ET,D,DT,S and T C in the top layer of cell (IRIVER,JRIVER) C have been successfully computed. C IFAIL is 1 if IMAX, JMAX or KMAX <= 0, C or TSTEP, DX or DY <= 0 on entry. C IFAIL is 2 if IRIVER < 1 or IRIVER > IMAX C or JRIVER < 1 or JRIVER > JMAX. C IFAIL is 3 if H(IRIVER,JRIVER,1) <= 0 C on entry. C***ROUTINES CALLED-NONE C***END PROLOGUE RIVER C C Global variables. C INTEGER IRIVER,JRIVER,IMAX,JMAX,KMAX,IFAIL REAL EL(IMAX,JMAX),ET(IMAX,JMAX), + D(IMAX,JMAX),DT(IMAX,JMAX),S(IMAX,JMAX,KMAX), + T(IMAX,JMAX,KMAX),FRIVER,TRIVER,DEPMIX, + DX,DY,TSTEP,H(IMAX,JMAX),DZ(KMAX) C C Local variables C C TOTVOL Real. C Total volume of top cell after river water is added (m**3). C VOLSAL Real. C Volume of the sea water before adding river water (m**3). C VOLWAT Real. C Volume of river water (m**3). C ELOLD Real. C Water level before adding river water (m**3). C INTEGER NUMSIG,I REAL TOTVOL,VOLSAL,VOLWAT,ELOLD,DEPTH,DEPSIG,SIGMA C C***FIRST EXECUTABLE STATEMENT RIVER C IFAIL = 0 C C Test on legal input. C IF (IMAX.LE.0) THEN IFAIL = 1 RETURN ENDIF IF (JMAX.LE.0) THEN IFAIL = 1 RETURN ENDIF IF (KMAX.LE.0) THEN IFAIL = 1 RETURN ENDIF IF (TSTEP.LE.0.) THEN IFAIL = 1 RETURN ENDIF IF (DX.LE.0.) THEN IFAIL = 1 RETURN ENDIF IF (DY.LE.0.) THEN IFAIL = 1 RETURN ENDIF C IF (IRIVER.LT.1) THEN IFAIL = 2 RETURN ENDIF IF (IRIVER.GT.IMAX) THEN IFAIL = 2 RETURN ENDIF IF (JRIVER.LT.1) THEN IFAIL = 2 RETURN ENDIF IF (JRIVER.GT.JMAX) THEN IFAIL = 2 RETURN ENDIF C IF (H(IRIVER,JRIVER).LE.0.) THEN IFAIL = 3 RETURN ENDIF C ELOLD = EL(IRIVER,JRIVER) C C Compute the new water levels. C EL(IRIVER,JRIVER) = EL(IRIVER,JRIVER) + FRIVER*TSTEP/(DX*DY) ET(IRIVER,JRIVER) = ET(IRIVER,JRIVER) + FRIVER*TSTEP/(DX*DY) C C Adjust the dynamic depths connected to the cell. C D(IRIVER,JRIVER) = H(IRIVER,JRIVER) + EL(IRIVER,JRIVER) DT(IRIVER,JRIVER) = H(IRIVER,JRIVER) + ET(IRIVER,JRIVER) C C Compute the number of sigma layer for which S and T have C to be adjusted. C DEPTH = H(IRIVER,JRIVER) + EL(IRIVER,JRIVER) IF (DEPTH.LE.DEPMIX) THEN NUMSIG = KMAX-1 DEPSIG = DEPTH SIGMA = -1. ELSE NUMSIG = 1 DEPSIG = DZ(1)*DEPTH SIGMA = -DZ(1) 100 IF (DEPSIG.LT.DEPMIX) THEN NUMSIG = NUMSIG + 1 DEPSIG = DEPSIG + DZ(NUMSIG)*DEPTH SIGMA = SIGMA - DZ(NUMSIG) GO TO 100 ENDIF ENDIF C C Compute new salinity of the cell(s). C TOTVOL = DX*DY*DEPSIG VOLSAL = 0. DO 200 I = 1,NUMSIG VOLSAL = VOLSAL + S(IRIVER,JRIVER,I)*DX*DY* + (H(IRIVER,JRIVER) + ELOLD)*DZ(I) 200 CONTINUE C DO 250 I = 1,NUMSIG S(IRIVER,JRIVER,I) = VOLSAL/TOTVOL 250 CONTINUE C C Compute new temperature of the cell. C VOLWAT = TRIVER*FRIVER*TSTEP C DO 300 I = 1,NUMSIG VOLWAT = VOLWAT + T(IRIVER,JRIVER,I)*DX*DY* + (H(IRIVER,JRIVER) + ELOLD)*DZ(I) 300 CONTINUE C DO 350 I = 1,NUMSIG T(IRIVER,JRIVER,I) = VOLWAT/TOTVOL 350 CONTINUE C C***END RIVER C RETURN END C SUBROUTINE RIVERS(EL,ET,D,DT,S,T,IM,JM,KB, + TSTEP,DX,DY,H,DZ) C INTEGER IM,JM,KB REAL EL(IM,JM),ET(IM,JM),D(IM,JM),DT(IM,JM), + S(IM,JM,KB),T(IM,JM,KB),DX,DY,H(IM,JM), + TSTEP,DZ(KB) C INTEGER NUMC PARAMETER (NUMC=26) INTEGER ICOAST(2,NUMC),I,IFAIL REAL COASTF(NUMC),COASTD(NUMC),COASTT(NUMC) LOGICAL FIRST SAVE FIRST,ICOAST,COASTF,COASTD,COASTT DATA FIRST/.TRUE./ C C Define the river runoff paramters in all coastal C runoff cells. C IF (FIRST) THEN OPEN (75,FILE='rivers.dat') DO 10 I = 1,NUMC READ(75,*)ICOAST(1,I),ICOAST(2,I),COASTF(I), + COASTD(I),COASTT(I) write(*,*)ICOAST(1,I),ICOAST(2,I),COASTF(I), + COASTD(I),COASTT(I) 10 CONTINUE CLOSE(75) FIRST = .FALSE. ENDIF C C Add river water from all rivers C DO 100 I = 1,NUMC IFAIL = 0 CALL RIVER(ICOAST(1,I),ICOAST(2,I),EL,ET,D,DT,S,T,IM,JM,KB, + COASTF(I),COASTT(I),COASTD(I), + TSTEP,DX,DY,H,DZ,IFAIL) IF (IFAIL.NE.0) THEN WRITE(*,*)'ERROR IN RIVER',I,ICOAST(1,I),ICOAST(2,I) WRITE(*,*)IFAIL,TSTEP,DX,DY,IM,JM,KB WRITE(*,*)COASTF(I),COASTT(I),COASTD(I) STOP ENDIF 100 CONTINUE C RETURN END