PROGRAM GRID C C 1. Generate horizontal and vertical grid C 2. Read bottom topog. & interpolate to grid - subroutine BATH C 3. Read temp. & sal. & interpolate to grid - subroutine TAND C 4. Read wind velocity & interpolate to grid - subroutine WIND C 5. Write grid & initial conditions for model - WRITE(40) C 6. Write data for MATLAB plot - WRITE(43,44,45,46) C---------------------------------------------------------------------- C NOTE: This is a simple version modified to run as is without any C external data and no in-program plotting. All f90 formats C were also removed (tested on Linux g77 compiler) C C T.E (March, 2003) C---------------------------------------------------------------------- C C**********************************************************************! C VERSION(7-25-88) ! C GENERAL CIRCULATION MODEL ! C ORTHOGONAL CURVILINEAR COORDINATE GRID GENERATOR ! C ECOM3D ! C ! C ! C THIS COMPUTER CODE COMPUTES AN ORTHOGONAL CURVILINEAR COORDINATE ! C GRID FOR USE WITH THE THREE DIMENSIONAL, TIME DEPENDENT, ! C PRIMITIVE EQUATION, CIRCULATION MODEL DEVELOPED BY GEORGE MELLOR ! C AND ME. A GRID AND INTERPOLATED BOTTOM TOPOGRAPHY ARE PROVIDED. ! C ! C THE GRID GENERATOR WAS WRITTEN BY JOHN WILKIN OF WOODS HOLE ! C OCEANOGRAPHIC INSTITUTION, WOODS HOLE, MASS 02543. ! C ! C ! C FOR DETAILS OF THE GOVERNING EQUATIONS AND SOLUTION ! C TECHNIQUES THE INTERESTED READER IS REFERRED TO: ! C ! C WILKIN, J.L. A COMPUTER PROGRAM FOR GENERATING TWO-DIMENSIONAL ! C ORTHOGONAL CURVILINEAR COORDINATE GRIDS. UNPUBLISHED REPORT,1987 ! C ! C IVES, D.C. AND R.M.ZACHARIAS, CONFORMAL MAPPING AND ORTHOGONAL ! C GRID GENERATION, PAPER NO. 87-2057, AIAA/SAE/ASME/ASEE 23RD ! C JOINT PROPULSION CONFERENCE, SAN DIEGO, CALIFORNIA, JUNE 1987. ! C ! C BLUMBERG, A.F. AND G.L. MELLOR, DIAGNOSTIC AND PROGNOSTIC ! C NUMERICAL CIRCULATION STUDIES OF THE SOUTH ATLANTIC BIGHT ! C J. GEOPHYS. RES., 88, 4579-4592, 1983. ! C ! C BLUMBERG, A.F. AND G.L. MELLOR, A DESCRIPTION OF A THREE ! C COASTAL OCEAN CIRCULATION MODEL, THREE DIMENSIONAL SHELF ! C MODELS, COASTAL AND ESTUARINE SCIENCES, 5, N.HEAPS, ED., ! C AMERICAN GEOPHYSICAL UNION, 1987. ! C ! C AND ! C ! C BLUMBERG, A.F. AND H.J. HERRING, CIRCULATION MODELING USING ! C ORTHOGONAL CURVILINEAR COORDINATES, THREE DIMENSIONAL MODELS ! C OF MARINE AND ESTUARINE DYNAMICS, J.C.J.NIHOUL AND B.M.JAMART ! C ED., ELSEVIER OCEANOGRAPHY SERIES, 45,1987. ! C ! C ! C ! C PLEASE DIRECT CRITICISMS, SUGGESTIONS AND REPORTS OF ERRORS TO ME! C ! C ALAN BLUMBERG ! C HYDROQUAL ! C Mahwah,NJ ! C 7/25/88 ! C ! C This version has been changed and extended by George Mellor ! C and Tal Ezer ! C**********************************************************************! C C C DOUBLE PRECISION VERSION C USES COMPLEX C C --- read model size (IM,JM,KB) ---- INCLUDE 'gridcom' C C********************************************************* PARAMETER ( L2=IM-1 , M2=JM-1 ) PARAMETER ( MM=M2/2 , LM=L2/2 ) PARAMETER ( KEP=10,NWRK=(KEP-2)*(2**(KEP+1))+KEP+5*L2+6*M2+49) PARAMETER ( LIJ=IM*JM ) C COMPLEX*16 Z(M2+L2+M2+L2) COMPLEX Z(M2+L2+M2+L2) DIMENSION XB(M2+L2+M2+L2),YB(M2+L2+M2+L2),WRK(M2+L2), 1 WXI(L2+1),WETA(M2+1),XINT(M2+L2),YINT(M2+L2), 2 X(0:L2,0:M2),Y(0:L2,0:M2),RHS(0:L2,0:M2),EWRK(NWRK) COMMON / XIEJ / SXI(0:L2),SETA(0:M2) C REAL KM,KH COMMON/OUT40/AZ(KB),ZZ(KB),DZ(KB),DZZ(KB),ALON(IM,JM),ALAT(IM,JM), 1 DX(IM,JM),DY(IM,JM),H(IM,JM),FSM(IM,JM),DUM(IM,JM), 2 DVM(IM,JM),ART(IM,JM),ARU(IM,JM),ARV(IM,JM),COR(IM,JM), 3 T(IM,JM,KB),S(IM,JM,KB),TMEAN(IM,JM,KB),SMEAN(IM,JM,KB), 4 RMEAN(IM,JM,KB),TBE(JM,KB),TBW(JM,KB),TBS(IM,KB), 5 SBE(JM,KB),SBW(JM,KB),SBS(IM,KB) CC DIMENSION UW(IM,JM),VW(IM,JM),WUSURF(IM,JM),WVSURF(IM,JM) DIMENSION LBL(20),DT(IM,JM),DS(IM,JM),ANG(IM,JM) DIMENSION ERRPLT(LM,MM),IVAR(LM,MM),ZD(LM,MM) CHARACTER*50 TITLE EQUIVALENCE (RHS,ERRPLT) EQUIVALENCE (X,ALON),(Y,ALAT) EXTERNAL COFX,COFY DATA PI/3.141593/,RAD/.01745329/,RE/6371.E3/,GRAV/9.807/ C C OPEN(6,FILE='printout',form='formatted') C C --- read parameter file (IGRID,IBATH,ITAND,IWIND) from rungrid INCLUDE 'params' C C --- SPECIFIED GRID INSTEAD OF CURVILINEAR GRID GENERATION C (ignore gridborder) IF(IGRID.EQ.0) THEN ASOUTH=32. ANORTH=39. AWEST=-77. AEAST=-71. C -- for matlab plot only WRITE(45,'(2F8.2)') AWEST,ASOUTH WRITE(45,'(2F8.2)') AWEST,ANORTH WRITE(45,'(2F8.2)') AEAST,ASOUTH WRITE(45,'(2F8.2)') AEAST,ANORTH DO I=1,IM DO J=1,JM ALON(I,J)=AWEST+I*(AEAST-AWEST)/IM ALAT(I,J)=ASOUTH+J*(ANORTH-ASOUTH)/JM ENDDO ENDDO GO TO 1100 ENDIF C C INITIALIZE VECTOR Z (COMPLEX) WITH CONTOUR OF PHYSICAL BOUNDARY N1 = M2 N2 = M2+L2 N3 = M2+L2+M2 N4 = M2+L2+M2+L2 N = M2+L2+M2+L2 C C --------------------------------------------------------------- C | input example: C | C | boundary #4 C | C | 18 17 16 15 14 13 C | C | 1 12 C | C | boundary #1 2 11 boundary #3 C | C | ^^ 3 10 C | || C | || 4 5 6 7 8 9 C | boundary #2 C | I direction ===> C | C --------------------------------------------------------------- C C========================== C Read input option and latitude of original point C IOPT=2 ORCOR=0. C========================== C OPTION 1 : C GENERATE BOUNDARY FROM MATH. EXPRESSION C IF(IOPT.EQ.1)THEN C DO 1 I=1,N1 1 CALL Z1(FLOAT(I)/FLOAT(N1),XB(I),YB(I),Z(I)) DO 2 I=N1+1,N2 2 CALL Z2(FLOAT(I-N1)/FLOAT(N2-N1),XB(I),YB(I),Z(I)) DO 3 I=N2+1,N3 3 CALL Z3(FLOAT(I-N2)/FLOAT(N3-N2),XB(I),YB(I),Z(I)) DO 4 I=N3+1,N4 4 CALL Z4(FLOAT(I-N3)/FLOAT(N4-N3),XB(I),YB(I),Z(I)) ELSE C========================= C OPTION 2 : C READ BOUNDARY FROM SUBROUTINE BORDER C CALL BORDER(IM,JM,X,Y) C c CALL PRXY (' X BF MERCATOR',0.0,X,L2+1,1 ,M2+1,1 ,0.) c CALL PRXY (' Y BF MERCATOR',0.0,Y,L2+1,1 ,M2+1,1 ,0.) C Stretch latitude as in Mercator projection DO I=0,L2 DO J=0,M2 Y(I,J)=alog(tan(0.5*rad*Y(I,J)+0.25*pi))/rad END DO END DO C C INSERT BOUNDARY VALUES OF GRID FOR DISPLAY DO 90 I=1,N1 XB(I)=X(0,N1-I) YB(I)=Y(0,N1-I) 90 Z(I)=CMPLX(XB(I),YB(I)) DO 91 I=N1+1,N2 XB(I)=X(I-N1,0) YB(I)=Y(I-N1,0) 91 Z(I)=CMPLX(XB(I),YB(I)) DO 92 I=N2+1,N3 XB(I)=X(L2,I-N2) YB(I)=Y(L2,I-N2) 92 Z(I)=CMPLX(XB(I),YB(I)) DO 93 I=N3+1,N4 XB(I)=X(N4-I,M2) YB(I)=Y(N4-I,M2) 93 Z(I)=CMPLX(XB(I),YB(I)) c CALL PRXY (' X BF MAPPING',0.0,X,L2+1,1 ,M2+1,1 ,0.) c CALL PRXY (' Y BF MAPPING',0.0,Y,L2+1,1 ,M2+1,1 ,0.) ENDIF C C MAP PHYSICAL BOUNDARY TO A RECTANGLE DO 11 K=1,9 CALL RECT(Z,N,N1,N2,N3,N4) C C CALCULATE DEPARTURE OF CONTOUR FROM RECTANGULAR ERROR = 0. DO 6 I=1,N1 6 ERROR = ERROR + ABS(DBLE(Z(I))-DBLE(Z(1))) DO 7 I=N1+1,N2 7 ERROR = ERROR + ABS(AIMAG(Z(I))-AIMAG(Z(N1+1))) DO 8 I=N2+1,N3 8 ERROR = ERROR + ABS(DBLE(Z(I))-DBLE(Z(N2+1))) DO 9 I=N3+1,N4 9 ERROR = ERROR + ABS(AIMAG(Z(I))-AIMAG(Z(N3+1))) ERROR = ERROR/FLOAT(N4) WRITE(6,10)K,ERROR 10 FORMAT(' RECTANGULARITY ERROR IN MAPPED CONTOUR AT', 1 ' ITERATION ',I2,' IS ',1PE10.4) 11 CONTINUE CC WRITE(6,'(1x,2F10.3)') (Z(I),I=1,N) C C CUBIC SPLINE INTERPOLATION OF MAPPING ON BOUNDARIES 3 AND 4 TO C MATCH DISTRIBUTION OF POINTS WITH THOSE ON BOUNDARIES 1 AND 2 C C BOUNDARY 3 DO 13 I=1,N3-N2 WETA(I) = AIMAG(Z(N2+I)) XINT(I) = XB(N2+I) 13 YINT(I) = YB(N2+I) CALL SPLINE(WETA,XINT,N3-N2,1.E+35,1.E+35,WRK) DO 14 I=1,N1-1 CALL SPLINT(WETA,XINT,WRK,N3-N2,AIMAG(Z(I)),XB(N3-I)) 14 CONTINUE CALL SPLINE(WETA,YINT,N3-N2,1.E+35,1.E+35,WRK) DO 15 I=1,N1-1 CALL SPLINT(WETA,YINT,WRK,N3-N2,AIMAG(Z(I)),YB(N3-I)) 15 CONTINUE C C BOUNDARY 4 DO 16 I=1,N4-N3 WXI(I) = REAL(Z(N4+1-I)) XINT(I) = XB(N4+1-I) 16 YINT(I) = YB(N4+1-I) CALL SPLINE(WXI,XINT,N4-N3,1.E+35,1.E+35,WRK) DO 17 I=1,N2-N1-1 CALL SPLINT(WXI,XINT,WRK,N4-N3,REAL(Z(N1+I)),XB(N4-I)) 17 CONTINUE CALL SPLINE(WXI,YINT,N4-N3,1.E+35,1.E+35,WRK) DO 18 I=1,N2-N1-1 CALL SPLINT(WXI,YINT,WRK,N4-N3,REAL(Z(N1+I)),YB(N4-I)) 18 CONTINUE C C STORE DISTRIBUTION OF XI,ETA POINTS ALONG BOUNDARIES (USED TO C COMPUTE COEFFICIENTS OF ELLIPTIC EQUATION) DO 20 I=0,L2 20 SXI(I) = REAL(Z(N1+I)) DO 21 I=0,M2-1 21 SETA(I) = AIMAG(Z(N1-I)) SETA(M2) = AIMAG(Z(N4)) C C SET BOUNDARY VALUES OF THE GRID DO 30 I=1,N1 X(0,N1-I) = XB(I) 30 Y(0,N1-I) = YB(I) DO 31 I=N1+1,N2 X(I-N1,0) = XB(I) 31 Y(I-N1,0) = YB(I) DO 32 I=N2+1,N3 X(L2,I-N2) = XB(I) 32 Y(L2,I-N2) = YB(I) DO 33 I=N3+1,N4 X(N4-I,M2) = XB(I) 33 Y(N4-I,M2) = YB(I) c CALL PRXY (' X BF SEPELI ',0.0,X,L2+1,1 ,M2+1,1 ,0.) c CALL PRXY (' Y BF SEPELI ',0.0,Y,L2+1,1 ,M2+1,1 ,0.) C C SET RIGHT HAND SIDE OF ELLIPTIC EQUATION TO ZERO DO 40 J=0,M2 DO 40 I=0,L2 40 RHS(I,J) = 0. C C SOLVE ELLIPTIC EQUATION TO FILL IN GRID EWRK(1)=NWRK CALL SEPELI(0,2,0.,FLOAT(L2),L2,1,WRK,WRK,WRK,WRK, 1 0.,FLOAT(M2),M2,1,WRK,WRK,WRK,WRK, 2 COFX,COFY,RHS,X,L2+1,EWRK,PERTRB,IERR) IF(IERR.NE.0)CALL CRASH(1,IERR) EWRK(1)=NWRK CALL SEPELI(0,2,0.,FLOAT(L2),L2,1,WRK,WRK,WRK,WRK, 1 0.,FLOAT(M2),M2,1,WRK,WRK,WRK,WRK, 2 COFX,COFY,RHS,Y,L2+1,EWRK,PERTRB,IERR) IF(IERR.NE.0)CALL CRASH(2,IERR) C C-- Restore stretched coordinate to latitude --------- C DO I=0,L2 DO J=0,M2 Y(I,J)=(-0.5*PI+2.*atan(exp(Y(I,J)*rad)))/rad END DO END DO C 1100 CONTINUE C C --- SET ARTIFICIAL BATHYMETRY (SEAMOUNT) C C DO I=1,IM DO J=1,JM H(I,J)= 4500.*(1.-0.9*EXP(-((ALON(I,J)-ALON(IM/2,J))**2+ & (ALAT(I,J)-ALAT(I,JM/2))**2)/ 4.0**2) ) IF(IBATH.EQ.1) H(I,J)= 0. END DO END DO C C******************************************************************* C READ REAL BATHYMETRY AND INTERPOLATE INTO GRID C******************************************************************* C IF(IBATH.EQ.1) CALL BATH C C MIN DEPTH (M) HMIN=10. C c CALL PRXY(' H BEFORE ',TIME,H,IM,1,JM,1,0.) DO 50 I=1,IM DO 50 J=1,JM FSM(I,J)=1. DUM(I,J)=1. DVM(I,J)=1. C IF(H(I,J).LT.HMIN)THEN H(I,J)=1. FSM(I,J)=0. DUM(I,J)=0. DVM(I,J)=0. ENDIF 50 CONTINUE C C----- special cases: remove singular points (isolated islands or lakes) DO 51 I=2,IM-1 DO 51 J=2,JM-1 FSM4=FSM(I,J-1)+FSM(I,J+1)+FSM(I-1,J)+FSM(I+1,J) IF(FSM(I,J).EQ.0.AND.FSM4.GT.2.) FSM(I,J)=1. IF(FSM(I,J).EQ.1.AND.FSM4.LT.2.) FSM(I,J)=0. 51 CONTINUE C DO 52 J=1,JM-1 DO 52 I=1,IM IF(FSM(I,J).EQ.0..AND.FSM(I,J+1).NE.0.) DVM(I,J+1)=0. 52 CONTINUE DO 53 J=1,JM DO 53 I=1,IM-1 IF(FSM(I,J).EQ.0..AND.FSM(I+1,J).NE.0.)DUM(I+1,J)=0. 53 CONTINUE C C SUBJECTIVE TOPOG. SMOOTHER - DH/H < 2*SLMIN C (smaller SLPMIN gives more smoothing) SLMIN=0.2 C SLMIN=0.1 CALL SLPMIN(H,IM,JM,FSM,SLMIN) C Laplasian filter CALL SMOOTH(H,FSM,IM,JM,1) DO 54 J=1,JM DO 54 I=1,IM IF(FSM(I,J).EQ.0.) H(I,J)=1. 54 CONTINUE C C CALC. DX DY AND MAX TIME STEP C DO 150 J=2,JM-1 DO 150 I=2,IM-1 DX(I,J)=0.5*RAD*RE*SQRT(((ALON(I+1,J)-ALON(I-1,J)) 1 *COS(ALAT(I,J)*RAD))**2+(ALAT(I+1,J)-ALAT(I-1,J))**2) DY(I,J)=0.5*RAD*RE*SQRT(((ALON(I,J+1)-ALON(I,J-1)) 1 *COS(ALAT(I,J)*RAD))**2+(ALAT(I,J+1)-ALAT(I,J-1))**2) 150 CONTINUE DO 152 I=1,IM DX(I,1)=DX(I,2) DY(I,1)=DY(I,2) DX(I,JM)=DX(I,JM-1) 152 DY(I,JM)=DY(I,JM-1) DO 153 J=1,JM DX(1,J)=DX(2,J) DY(1,J)=DY(2,J) DX(IM,J)=DX(IM-1,J) 153 DY(IM,J)=DY(IM-1,J) DO 154 J=1,JM DO 154 I=1,IM UMAX=1. CMAX=2*SQRT(GRAV*H(I,J))+UMAX DXY=1./SQRT(1./(DX(I,J)**2) + 1./(DY(I,J)**2)) DT(I,J)=DXY/CMAX 154 CONTINUE C DO 155 J=1,JM DO 155 I=1,IM ART(I,J)=DX(I,J)*DY(I,J) ARU(I,J)=.25*(DX(I,J)+DX(I-1,J))*(DY(I,J)+DY(I-1,J)) ARV(I,J)=.25*(DX(I,J)+DX(I,J-1))*(DY(I,J)+DY(I,J-1)) C COR(I,J)=2.*7.29E-5*SIN(ALAT(I,J)*RAD) C 155 CONTINUE C TIME=0. CALL PRXY(' H ',TIME,H,IM,ISKP,JM,JSKP,0.) CALL PRXY('LON',TIME,ALON,IM,ISKP,JM,JSKP,0.) CALL PRXY('LAT',TIME,ALAT,IM,ISKP,JM,JSKP,0.) CALL PRXY('FSM',TIME,FSM,IM,ISKP,JM,JSKP,0.) C CALL PRXY('DUM',TIME,DUM,IM,ISKP,JM,JSKP,0.) C CALL PRXY('DVM',TIME,DVM,IM,ISKP,JM,JSKP,0.) C CALL PRXY('ART',TIME,ART,IM,ISKP,JM,JSKP,0.) C CALL PRXY('ARU',TIME,ARU,IM,ISKP,JM,JSKP,0.) C CALL PRXY('ARV',TIME,ARV,IM,ISKP,JM,JSKP,0.) C CALL PRXY('COR',TIME,COR,IM,ISKP,JM,JSKP,1.E-7) CALL PRXY(' DX ',TIME,DX,IM,ISKP,JM,JSKP,0.) CALL PRXY(' DY ',TIME,DY,IM,ISKP,JM,JSKP,0.) CALL PRXY(' CFL-DT ',TIME,DT,IM,ISKP,JM,JSKP,0.) C C******************************************************************* C GENERATE VERCTCAL GRID, C******************************************************************* C CALL DEPTH(AZ,ZZ,DZ,DZZ,KB) WRITE(6,'('' K Z ZZ DZ DZZ '')') WRITE(6,'(1X,I5,4F10.4)') (K,AZ(K),ZZ(K),DZ(K),DZZ(K),K=1,KB) C C --- SET ARTIFICIAL TEMP., SAL. & DENSITY C IF(ITAND.EQ.0) THEN DO I=1,IM DO J=1,JM DO K=1,KB S(I,J,K)=35. T(I,J,K)=5.+15.*EXP(ZZ(K)*H(I,J)/1000.) SMEAN(I,J,K)=35. TMEAN(I,J,K)=5.+15.*EXP(ZZ(K)*H(I,J)/1000.) END DO END DO END DO CALL DENS(S,T,RMEAN,FSM,ZZ,H,IM,JM,KB) ELSE C C******************************************************************* C READ TEMP. AND SAL. FROM FILE AND INTERPOLATE INTO GRID C******************************************************************* C CALL TANDS ENDIF C C --- boundary fields TBS,TBN,TBE,TBW should now be calc. in pom C CALL PRXYZ ('T ',TIME,T ,6,IM,ISKP,JM,JSKP,KB,0.01) CALL PRXYZ ('S ',TIME,S ,6,IM,ISKP,JM,JSKP,KB,0.01) CALL PRXYZ ('RMEAN-1.0',TIME,RMEAN,6,IM,ISKP,JM,JSKP,KB,1.E-5) C C C C CHECK ORTHOGONALITY BY EVALUATING DX/DXI*DX/DETA+DY/DXI*DY/DETA C EVERYWHERE. NORMALIZE WITH RESPECT TO LOCAL GRID CELL AREA. C STORE RESULT IN ERRPLT. C DO 80 J=2,JM-1 C DO 80 I=2,JM-1 C80 ERRPLT(I,J) = ((X(I+1,J)-X(I-1,J))* C 1 (X(I,J+1)-X(I,J-1))+ C 2 (Y(I+1,J)-Y(I-1,J))* C 3 (Y(I,J+1)-Y(I,J-1)))/ C 4 ( DX(I,J)*DY(I,J))*100. C C WRITE(6,108) C 108 FORMAT(//' ORTHOGONALARITY ERROR ANALYSIS IN PERCENT'//) C CALL PRXY('ORTH.ERROR ',TIME,ERRPLT,IM,ISKP,JM,JSKP,0.) C do i=1,im do j=1,jm C --- for IWIND=0 one may specify wind (m/s) here instead of data UW(i,j)=0. VW(i,j)=0. WUSURF(i,j)=0. WVSURF(i,j)=0. C --- calc. tilting angle of curvilinear grid if(j.eq.jm) then DLON=(ALON(I,J)-ALON(I,J-1))*COS(ALAT(I,J)*RAD) DLAT=ALAT(I,J)-ALAT(I,J-1) else DLON=(ALON(I,J+1)-ALON(I,J))*COS(ALAT(I,J)*RAD) DLAT=ALAT(I,J+1)-ALAT(I,J) endif DLNT=(DLON**2+DLAT**2)**.5 ANG(I,J)=ASIN(DLON/DLNT) end do end do C C C C******************************************************************* C READ WIND VELOCITY FROM FILE AND INTERPOLATE INTO GRID C******************************************************************* C C for monthly data use do loop example C do mon=1,12 C IF(IWIND.EQ.1) CALL WIND(UW,VW,IM,JM) C C --- RHOair/RHOwater RWA=1.226e-3/1.025 C DO I=1,IM DO J=1,JM C --- transfer coordinates to model grid direction BETA=ANG(I,J) WUSURF(I,J)=UW(I,J)*COS(BETA)-VW(I,J)*SIN(BETA) WVSURF(I,J)=UW(I,J)*SIN(BETA)+VW(I,J)*COS(BETA) C --- calculate wind stress in model units from wind velocity C --- note: sign opposite to wind vector SPD=SQRT(UW(I,J)**2+VW(I,J)**2) CD=(7.5E-4+6.7E-5*SPD) WUSURF(I,J)=-1.*RWA*CD*SPD*WUSURF(I,J) WVSURF(I,J)=-1.*RWA*CD*SPD*WVSURF(I,J) END DO END DO C CALL PRXY('ANG(RAD)',0.,ANG ,IM,ISKP,JM,JSKP,0.001) CALL PRXY(' U-VEL(X,Y)',0., UW ,IM,ISKP,JM,JSKP,0.01) CALL PRXY(' V-VEL(X,Y)',0., VW ,IM,ISKP,JM,JSKP,0.01) CALL PRXY('WUSURF ON GRID',0.,WUSURF,IM,ISKP,JM,JSKP,1.E-5) CALL PRXY('WVSURF ON GRID',0.,WVSURF,IM,ISKP,JM,JSKP,1.E-5) C C WRITE WIND STRESS FOR MODEL FORCING C cc WRITE(30) WUSURF,WVSURF C end do c C******************************************************************* C WRITE INITIAL CONDITION FILE FOR POM C******************************************************************* C C (NOTE: variables names are as in pom98.f) C C WRITE(40) KB,AZ,ZZ,DZ,DZZ,IM,JM,ALON,ALAT,DX,DY,H,FSM, C 1 DUM,DVM,ART,ARU,ARV,COR,T,S,TMEAN,SMEAN,RMEAN C C IC FOR POM2K: write only necessary fields and calc. others C in subroutine "file2ic" in pom2k.f. (T.E. Dec2004) C C **** FORMATTED OUTPUT **** var name in pom2k.f C--- 1D --- WRITE(40,'('' Z '')') WRITE(40,'(8E12.5)') AZ ! Z WRITE(40,'('' ZZ '')') WRITE(40,'(8E12.5)') ZZ WRITE(40,'('' DZ '')') WRITE(40,'(8E12.5)') DZ WRITE(40,'('' DZZ'')') WRITE(40,'(8E12.5)') DZZ C--- 2D --- WRITE(40,'(''ALON '')') WRITE(40,'(8E12.5)') ALON ! east_e WRITE(40,'(''ALAT '')') WRITE(40,'(8E12.5)') ALAT ! north_e WRITE(40,'('' H '')') WRITE(40,'(8E12.5)') H C--- 3D --- WRITE(40,'('' T '')') WRITE(40,'(8E12.5)') T ! tclim WRITE(40,'('' S '')') WRITE(40,'(8E12.5)') S ! sclim WRITE(40,'(''RMEAN'')') WRITE(40,'(8E12.5)') RMEAN C--- CONSTANT WIND STRESS WRITE(40,'(''WUSUR'')') WRITE(40,'(8E12.5)') WUSURF WRITE(40,'(''WVSUR'')') WRITE(40,'(8E12.5)') WVSURF c C******************************************************************* C WRITE GRID & IC FOR PLOTTING WITH MATLAB C (files 43, 44, 45, 46, 47) C******************************************************************* C WRITE(43,'(3I4,16F8.4)') IM,JM,KB,(AZ(K),K=1,KB) DO 221 I=1,IM DO 221 J=1,JM WRITE(44,'(2I4,2F9.3,F8.2,16F7.2)') 1 I,J,ALON(I,J),ALAT(I,J),H(I,J),(T(I,J,K),K=1,KB) WRITE(46,'(2I4,4F10.4)') 1 I,J,ALON(I,J),ALAT(I,J),UW(I,J),VW(I,J) WRITE(47,'(2I4,4F10.4)') 1 I,J,ALON(I,J),ALAT(I,J),DX(I,J)*0.001,DY(I,J)*0.001 221 CONTINUE C C-----------------------------------------------------------C C STOP END C C ------------------------------------------------------------------ SUBROUTINE TANDS C c This program reads Temperature & Salinity of the N. Atl. at c 1x1 DEG. GRID ( LEVITUS ANNUAL CLIM.) INCLUDE 'gridcom' PARAMETER( KS=33) COMMON/OUT40/Z(KB),ZZ(KB),DZ(KB),DZZ(KB),ALON(IM,JM),ALAT(IM,JM), 1 DX(IM,JM),DY(IM,JM),H(IM,JM),FSM(IM,JM),DUM(IM,JM), 2 DVM(IM,JM),ART(IM,JM),ARU(IM,JM),ARV(IM,JM),COR(IM,JM), 3 T(IM,JM,KB),S(IM,JM,KB),TMEAN(IM,JM,KB),SMEAN(IM,JM,KB), 4 RMEAN(IM,JM,KB),TBE(JM,KB),TBW(JM,KB),TBS(IM,KB), 5 SBE(JM,KB),SBW(JM,KB),SBS(IM,KB) DIMENSION ZS(KS),TB(IM,JM,KS),SB(IM,JM,KS) DIMENSION TAA(KS),SAA(KS),AREA(KS) C LEVITUS VERTICAL LEVELS DATA ZS /0.,10.,20.,30.,50.,75.,100.,125.,150.,200., 2 250.,300.,400.,500.,600.,700.,800.,900.,1000.,1100., 3 1200.,1300.,1400.,1500.,1750.,2000.,2500.,3000.,3500.,4000., 4 4500.,5000.,5500./ data n1,n2,n3,n4,n5/1,3,6,11,15/ C C DO 10 I=1,IM DO 10 J=1,JM DO 10 K=1,KB S(I,J,K)=0. T(I,J,K)=0. SB(I,J,K)=0. TB(I,J,K)=0. 10 CONTINUE C C MAPLEV reads and spreads 1 deg X 1 deg and 33 level data on C the curvilinear 33 level grid. C ZTOSIG places the 33 level data on the KB level sigma coordinate C grid. C C levitus CALL MAPLEV(11,ZS,TB,SB,IM,JM,KS) C WRITE(6,'('' DEPTH AREA TAVE SAVE'')') DO 20 K=1,KS TAA(K)=0. SAA(K)=0. AREA(K)=0. 20 CONTINUE DO 75 K=1,KS P=1.025*ZS(k) DO 70 J=1,JM DO 70 I=1,IM IF(TB(I,J,K).EQ.0.) GOTO 70 c c --- convert to POTENTIAL TEMPERATURE c TB(I,J,K)=POTEM(TB(I,J,K),SB(I,J,K),P) c IF((ZS(K)+1.001).LT.H(I,J)) THEN TAA(K)=TAA(K)+TB(I,J,K)*ART(I,J) SAA(K)=SAA(K)+SB(I,J,K)*ART(I,J) AREA(K)=AREA(K)+ART(I,J) c ENDIF 70 CONTINUE c c --- calc. area averaged values & save them in TB,SB c TAA(K)=TAA(K)/AREA(K) SAA(K)=SAA(K)/AREA(K) WRITE(6,'(1X,F10.3,E12.3,2F10.3)') ZS(K),AREA(K),TAA(K),SAA(K) 75 CONTINUE c c --- T,S are the 3D IC fields interp. to SIG grid c CALL ZTOSIG(ZS,TB,ZZ,H,T,IM,JM,KS,KB) CALL ZTOSIG(ZS,SB,ZZ,H,S,IM,JM,KS,KB) C DO 80 K=1,KS DO 80 I=1,IM DO 80 J=1,JM TB(I,J,K)=TAA(K) SB(I,J,K)=SAA(K) 80 CONTINUE c c --- calc. area avr. density RMEAN (func(z) on sig. layers) c CALL ZTOSIG(ZS,TB,ZZ,H,TMEAN,IM,JM,KS,KB) CALL ZTOSIG(ZS,SB,ZZ,H,SMEAN,IM,JM,KS,KB) CALL DENS(SMEAN,TMEAN,RMEAN,FSM,ZZ,H,IM,JM,KB) C DO 99 I=1,IM DO 99 J=1,JM DO 99 K=1,KB TMEAN(I,J,K)=T(I,J,K) SMEAN(I,J,K)=S(I,J,K) 99 CONTINUE C RETURN END C C ------------------------------------------------------------------ SUBROUTINE MAPLEV(NU,ZS,TB,SB,IMM,JMM,KS) C read levitus N. Atlantic clim (1x1 deg. 79W-70W,31N-40N) C INCLUDE 'gridcom' C --- data grid PARAMETER(IS=10,JS=10) COMMON/OUT40/Z(KB),ZZ(KB),DZ(KB),DZZ(KB),ALON(IM,JM),ALAT(IM,JM), 1 DX(IM,JM),DY(IM,JM),H(IM,JM),FSM(IM,JM),DUM(IM,JM), 2 DVM(IM,JM),ART(IM,JM),ARU(IM,JM),ARV(IM,JM),COR(IM,JM), 3 T(IM,JM,KB),S(IM,JM,KB),TMEAN(IM,JM,KB),SMEAN(IM,JM,KB), 4 RMEAN(IM,JM,KB),TBE(JM,KB),TBW(JM,KB),TBS(IM,KB), 5 SBE(JM,KB),SBW(JM,KB),SBS(IM,KB) DIMENSION ZS(KS),TB(IMM,JMM,KS),SB(IMM,JMM,KS),TPS(IM,JM) DIMENSION BLON(IS,JS),BLAT(IS,JS),TS(IS,JS),FTS(IS,JS) DIMENSION TTB(IS,JS,KS),SSB(IS,JS,KS) CHARACTER*10 TTSS(2) CHARACTER*6 TIT DATA TTSS /'TEMP. DATA','SAL. DATA '/ data k1,k2,k3,k4,k5/1,8,16,24,33/ C ---- south-western most data point of input data wlon=-79. slat=31. C C WRITE(6,'(//)') C C read LON/LAT of data C READ(NU,'(A6)') TIT DO 101 J=JS,1,-1 101 READ(NU,'(10F7.2)') (BLON(I,J),I=1,IS) READ(NU,'(A6)') TIT DO 102 J=JS,1,-1 102 READ(NU,'(10F7.2)') (BLAT(I,J),I=1,IS) C C read T,S data on 33 levels (land=-100) C DO 104 K=1,KS READ(NU,'(A6)') TIT DO 103 J=JS,1,-1 103 READ(NU,'(10F7.2)') (TTB(I,J,K),I=1,IS) READ(NU,'(A6)') TIT DO 104 J=JS,1,-1 104 READ(NU,'(10F7.2)') (SSB(I,J,K),I=1,IS) C DO 10 ITS=1,2 DO 10 K=1,KS DO I=1,IS DO J=1,JS IF(ITS.EQ.1)TS(I,J)=TTB(I,J,K) IF(ITS.EQ.2)TS(I,J)=SSB(I,J,K) END DO END DO C C put latitudal mean value on land points, C to eliminate bound. prob. when interp. to model grid. C DO 60 J=1,JS TSAV=0. ISAV=0 DO 58 I=1,IS IF(TS(I,J).GT.0.) THEN ISAV=ISAV+1 TSAV=TSAV+TS(I,J) ENDIF 58 CONTINUE IF(ISAV.NE.0) THEN TSAV=TSAV/ISAV ELSE c --- if no data available at this latitude, put value of deepest point TSAV=TS(10,2) ENDIF DO 59 I=1,IS IF(TS(I,J).LT.0.) TS(I,J)=TSAV 59 CONTINUE 60 CONTINUE CALL PRXY(' TS ',ZS(K),TS,IS,1,JS,1,0.01) C c WRITE(6,61) k,ZS(K),TSAV c61 format(2X,'LEVEL K= ',I3,' DEPTH Z= ',F8.0,' TAV= ',F8.2) C c ********* find data points and interpolate horizontally****** c c TPS=1. do 30 i=1,im do 30 j=1,jm IF(H(I,J).LE.1.)GO TO 30 x=alon(i,j) y=alat(i,j) ii=(x-wlon)+1 jj=(y-slat)+1 c x1=wlon+(II-1) y1=slat+(JJ-1) f1=ts(ii,jj) c x2=x1 y2=y1+1. f2=ts(ii,jj+1) c x3=x1+1. y3=y1+1. f3=ts(ii+1,jj+1) c x4=x1+1. y4=y1 f4=ts(ii+1,jj) C CALL BLINT(x1,x2,x3,x4,y1,y2,y3,y4,f1,f2,f3,f4,x,y,f) C IF(ITS.EQ.1)TB(I,J,K)=f*FSM(I,J) IF(ITS.EQ.2)SB(I,J,K)=f*FSM(I,J) c 30 CONTINUE 10 CONTINUE C C WRITE(12) BLON,BLAT,TTB,SSB C IF(2.GT.1) STOP C RETURN END C C C ------------------------------------------------------------------ SUBROUTINE WIND(UW,VW,IMM,JMM) C C read wind velocity climatology (1x1 deg. 79W-70W,31N-40N) C and interpolate to model grid C INCLUDE 'gridcom' C --- data grid PARAMETER(IS=10,JS=10) COMMON/OUT40/Z(KB),ZZ(KB),DZ(KB),DZZ(KB),ALON(IM,JM),ALAT(IM,JM), 1 DX(IM,JM),DY(IM,JM),H(IM,JM),FSM(IM,JM),DUM(IM,JM), 2 DVM(IM,JM),ART(IM,JM),ARU(IM,JM),ARV(IM,JM),COR(IM,JM), 3 T(IM,JM,KB),S(IM,JM,KB),TMEAN(IM,JM,KB),SMEAN(IM,JM,KB), 4 RMEAN(IM,JM,KB),TBE(JM,KB),TBW(JM,KB),TBS(IM,KB), 5 SBE(JM,KB),SBW(JM,KB),SBS(IM,KB) DIMENSION BLON(IS,JS),BLAT(IS,JS),TS(IS,JS),FTS(IS,JS) DIMENSION UUB(IS,JS),VVB(IS,JS),UW(IMM,JMM),VW(IMM,JMM) CHARACTER*6 TIT C ---- south-western most data point of input data wlon=-79. slat=31. C C WRITE(6,'(//)') C C read LON/LAT of data C READ(12,'(A6)') TIT DO 101 J=JS,1,-1 101 READ(12,'(10F7.2)') (BLON(I,J),I=1,IS) READ(12,'(A6)') TIT DO 102 J=JS,1,-1 102 READ(12,'(10F7.2)') (BLAT(I,J),I=1,IS) C C read U,V data (land=-100) C READ(12,'(A6)') TIT DO 103 J=JS,1,-1 103 READ(12,'(10F7.2)') (UUB(I,J),I=1,IS) READ(12,'(A6)') TIT DO 104 J=JS,1,-1 104 READ(12,'(10F7.2)') (VVB(I,J),I=1,IS) C DO 10 ITS=1,2 DO I=1,IS DO J=1,JS IF(ITS.EQ.1)TS(I,J)=UUB(I,J) IF(ITS.EQ.2)TS(I,J)=VVB(I,J) END DO END DO C C put latitudal mean value on land points, C to eliminate bound. prob. when interp. to model grid. C DO 60 J=1,JS TSAV=0. ISAV=0 DO 58 I=1,IS IF(TS(I,J).GT.-99.) THEN ISAV=ISAV+1 TSAV=TSAV+TS(I,J) ENDIF 58 CONTINUE IF(ISAV.NE.0) THEN TSAV=TSAV/ISAV ELSE c --- if no data available at this latitude TSAV=0. ENDIF DO 59 I=1,IS IF(TS(I,J).LT.-99.) TS(I,J)=TSAV 59 CONTINUE 60 CONTINUE CALL PRXY(' UV ',1.*ITS,TS,IS,1,JS,1,0.01) C c ********* find data points and interpolate horizontally****** c c TPS=1. do 30 i=1,im do 30 j=1,jm IF(H(I,J).LE.1.)GO TO 30 x=alon(i,j) y=alat(i,j) ii=(x-wlon)+1 jj=(y-slat)+1 c x1=wlon+(II-1) y1=slat+(JJ-1) f1=ts(ii,jj) c x2=x1 y2=y1+1. f2=ts(ii,jj+1) c x3=x1+1. y3=y1+1. f3=ts(ii+1,jj+1) c x4=x1+1. y4=y1 f4=ts(ii+1,jj) C CALL BLINT(x1,x2,x3,x4,y1,y2,y3,y4,f1,f2,f3,f4,x,y,f) C IF(ITS.EQ.1)UW(I,J)=f*FSM(I,J) IF(ITS.EQ.2)VW(I,J)=f*FSM(I,J) c 30 CONTINUE 10 CONTINUE C RETURN END C ------------------------------------------------------------------ SUBROUTINE ZTOSIG(ZS,TB,ZZ,H,T,IM,JM,KS,KB) C C VERTICAL INTERPOLATION C DIMENSION ZS(KS),TB(IM,JM,KS),ZZ(KB),H(IM,JM),T(IM,JM,KB), 1 TIN(KS),TOUT(KB),ZZH(KB) DO 40 I=1,IM DO 40 J=1,JM IF(H(I,J).LE.1.0)GO TO 40 C IF(H(I,J).LT.1.00001)GO TO 40 C-- special interp on z-lev for cases of no data because H smoothing DO 45 K=1,KS TIN(K)=TB(I,J,K) IF(ZS(K).LE.H(I,J).AND.TIN(K).LT.0.01)THEN TMAX=AMAX1(TB(I-1,J,K),TB(I+1,J,K),TB(I,J-1,K),TB(I,J+1,K)) TIN(K)=TMAX ENDIF IF(TIN(K).LT.0.01.AND.K.NE.1)TIN(K)=TIN(K-1) 45 CONTINUE C DO 50 K=1,KB 50 ZZH(K)=-ZZ(K)*H(I,J) C C VERTICAL SPLINE INTERP. CALL SPLINC(ZS,TIN,KS ,2.e30,2.e30,ZZH,TOUT,KB) C IPR=IM/2 JPR=JM/2 IPR=11 JPR=18 IF(I.EQ.IPR.AND.J.EQ.JPR) THEN WRITE(6,'(//,'' Data interpolated from z to sigma grid at I,J ='' 1 ,I5,'','',I5)') IPR,JPR WRITE(6,'('' H ='',F10.1)') H(IPR,JPR) WRITE(6,'(1X,I5,4F10.4)') (K,ZS(K),TIN(K),ZZH(K),TOUT(K),K=1,KB) WRITE(6,'(1X,I5,2F10.4)') (K,ZS(K),TIN(K),K=KB+1,KS) ENDIF C DO K=1,KB T(I,J,K)=TOUT(K) END DO C 40 CONTINUE C RETURN END C C ------------------------------------------------------------------ C SUBROUTINE DEPTH(Z,ZZ,DZ,DZZ,KB) CC DIMENSION Z(KB),ZZ(KB),DZ(KB),DZZ(KB) KBM1=KB-1 KL1=4 KL2=KB-2 C*********************************************************************** C THIS SUBROUTINE ESTABLISHES THE VERTICAL RESOLUTION WITH LOG C DISTRIBUTIONS AT THE TOP AND BOTTOM AND A LINEAR DISTRIBUTION C BETWEEN. CHOOSE KL1 AND KL2. THE DEFAULT KL1 = .3*KB AND KL2 = KB-2 C YIELDS A LOG DISTRIBUTION AT THE TOP AND NONE AT THE BOTTOM. C*********************************************************************** BB=FLOAT(KL2-KL1)+4. CC=FLOAT(KL1)-2. DEL1=2.0/BB/EXP(.693147*FLOAT(KL1-2)) DEL2=2.0/BB/EXP(.693147*FLOAT(KB-KL2-1)) Z(1)=0.0 ZZ(1)=-DEL1/2.0 DO 3 K=2,KL1 Z(K)=-DEL1*EXP(.693147*FLOAT(K-2)) 3 ZZ(K)=-DEL1*EXP(.693147*(FLOAT(K)-1.50)) DO 4 K=KL1,KL2 Z(K)=-(FLOAT(K)-CC)/BB 4 ZZ(K)=-(FLOAT(K)-CC+0.50)/BB DO 5 K=KL2,KBM1 Z(K)=(1.0-DEL2*EXP(.693147*FLOAT(KB-K-1)))*(-1.0) 5 ZZ(K)=(1.0-DEL2*EXP(.693147*(FLOAT(KB-K)-1.50)))*(-1.0) Z(KB)=-1.0 ZZ(KBM1)=-1.0*(1.0-DEL2/2.0) ZZ(KB)=-1.0*(1.0+DEL2/2.0) DO 6 K=1,KBM1 DZ(K)=Z(K)-Z(K+1) 6 DZZ(K)=ZZ(K)-ZZ(K+1) RETURN END C FUNCTION POTEM(T,S,P) C*********************************************************************** C C POTENTIAL TEMPERATURE FUNCTION C BASED ON FOFONOFF AND FROESE (1958) AS SHOWN IN "THE SEA" VOL. 1, C PAGE 17, TABLE IV C INPUT IS TEMPERATURE, SALINITY, PRESSURE (OR DEPTH) C UNITS ARE DEG.C., PPT, DBARS (OR METERS) C C*********************************************************************** CC B1=-1.60E-5*P B2=1.014E-5*P*T T2=T*T T3=T2*T B3=-1.27E-7*P*T2 B4=2.7E-9*P*T3 B5=1.322E-6*P*S B6=-2.62E-8*P*S*T S2=S*S P2=P*P B7=4.1E-9*P*S2 B8=9.14E-9*P2 B9=-2.77E-10*P2*T B10=9.5E-13*P2*T2 B11=-1.557E-13*P2*P POTEM=B1+B2+B3+B4+B5+B6+B7+B8+B9+B10+B11 POTEM=T-POTEM RETURN END C C ------------------------------------------------------------------ SUBROUTINE DENS(S,T,RHO,FSM,ZZ,H,IM,JM,KB) DIMENSION S(IM,JM,KB),T(IM,JM,KB),RHO(IM,JM,KB),FSM(IM,JM), 1 ZZ(KB),H(IM,JM) C C C THIS SUBROUTINE COMPUTES DENSITY-1.0 C T = POTENTIAL TEMPERATURE C GRAV=9.807 DO 1 K=1,KB-1 DO 1 J=1,JM DO 1 I=1,IM TR=T(I,J,K) SR=S(I,J,K) C Here, the (approximate) pressure is in units of bars. P=-GRAV*1.025*ZZ(K)*H(I,J)*0.01 C RHOR = 999.842594 + 6.793952E-2*TR 1 - 9.095290E-3*TR**2 + 1.001685E-4*TR**3 2 - 1.120083E-6*TR**4 + 6.536332E-9*TR**5 C RHOR = RHOR + (0.824493 - 4.0899E-3*TR 1 + 7.6438E-5*TR**2 - 8.2467E-7*TR**3 2 + 5.3875E-9*TR**4) * SR 3 + (-5.72466E-3 + 1.0227E-4*TR 4 - 1.6546E-6*TR**2) *(ABS(SR))**1.5 5 + 4.8314E-4 * SR**2 C CR =1449.1+.0821*P+4.55*TR-.045*TR**2+1.34*(SR-35.) RHOR=RHOR + 1.E5*P/CR**2*(1.-2.0*P/CR**2) C RHO(I,J,K)=(RHOR-1000.)*1.E-3*FSM(I,J) 1 CONTINUE C DO 3 J=1,JM DO 3 I=1,IM 3 RHO(I,J,KB)=0.E0 RETURN END C C ------------------------------------------------------------------ SUBROUTINE BORDER(IMm,JMm,X,Y) C C------------------------------------------------------------------------ C A FEW POINTS OF THE BORDER ARE SPECIFIED IN DATA STATEMENTS. C THE REMAINING POINTS ARE INTERPOLATED C------------------------------------------------------------------------ INCLUDE 'gridcom' C PARAMETER (NT=6,NB=2,NL=3,NR=3) PARAMETER (Nn=10) REAL LFTX,LFTY DIMENSION ITOP(Nn), IBOT(Nn), & TOPX(Nn),TOPY(Nn),BOTX(Nn),BOTY(Nn), & JRHT(Nn), JLFT(Nn), & RHTX(Nn),RHTY(Nn),LFTX(Nn),LFTY(Nn) DIMENSION RITOP(Nn),RIBOT(Nn),RJLFT(Nn),RJRHT(Nn), & RI(IM),RJ(JM) C --- Fix an old elusive bug (original code gave error if IM