program archv2data2d use mod_plot ! HYCOM plot array interface use mod_za ! HYCOM array I/O interface c c --- hycom/micom 2-d diagnostic field extractor c real, allocatable, dimension (:,:) :: & uflux,vflux,vort,strmf,ubaro_,vbaro_, & depth1, depthu,depthv,dpu,dpv, util1,work real, allocatable, dimension (:,:,:) :: & utilk,pw c common/conrng/ amn,amx c character flnm*240,frmt*80 logical smooth,mthin,icegln,lperiod c logical plot4(4) real qq4(4),qc4(4) c logical ltheta integer artype,iexpt,iversn,kkin,yrflag,mxlflg double precision time3(3) c real, parameter :: flag = 2.0**100 c c --- 'lhycom' -- hycom (vs micom) input file c --- 'trcout' -- tracer input logical lhycom,trcout data lhycom/.true. /, trcout/.false./ c real tenm,onem,temcm,onecm,onemm data tenm/10./,onem/1./,tencm/.1/,onecm/.01/,onemm/.001/ c logical initl data initl /.true. / real thref,spcifh data thref/1.e-3/,spcifh/3990./ character blank*40 data blank/' '/ logical insitu data insitu/.true./ real depth_m, t_deg c integer fdate(4), verfhour integer surflg c real pot2pot0 cdbgz real, parameter :: emnp_min=-4000.0 c call xcspmd call zaiost lp=6 film=onemm c c --- read model data c --- 'flnm ' = name of file containing the actual data c --- 'frmt ' = output format or type (HYCOM, BINARY, netCDF) c --- see horout for more details on frmt c --- 'iexpt ' = experiment number x10 (000=from archive file) c --- 'yrflag' = days in year flag (0=360J16,1=366J16,2=366J01,3=actual) c --- 'idm ' = longitudinal array size c --- 'jdm ' = latitudinal array size c --- 'kdm ' = number of layers read (*,'(a)') flnm write (lp,'(2a)') ' input file: ',trim(flnm) call flush(lp) read (*,'(a)') frmt write (lp,'(2a)') 'output type: ',trim(frmt) call flush(lp) C get date information c c --- 'yyyy ' = year c --- 'month ' = month c --- 'day ' = day c --- 'hour ' = hour c --- 'verfhr' = verification hour c call blkini(fdate(1),'yyyy ') call blkini(fdate(2),'month ') call blkini(fdate(3),'day ') call blkini(fdate(4),'hour ') call blkini(verfhour,'verfhr') call blkini(iexpt, 'iexpt ') call blkini(yrflag,'yrflag') call blkini(ii, 'idm ') call blkini(jj, 'jdm ') call blkini(kk, 'kdm ') if (ii.ne.idm .or. jj.ne.jdm) then write(lp,*) write(lp,*) 'error - wrong idm or jdm (should be:', & idm,jdm,')' write(lp,*) call flush(lp) stop 9 endif c c --- 'thbase' = reference density (sigma units) call blkinr(thbase, & 'thbase','("blkinr: ",a6," =",f11.4," sig")') c c --- 'surflg' =number of surface heat flux fields [1,3,4] call blkini(surflg,'surflg') if(surflg.lt.1.or.surflg.gt.4.or.surflg.eq.2) then write(lp,*) write(lp,*) 'error - wrong surflg (should be: 1|3|4 ' write(lp,*) call flush(lp) stop 9 endif c c --- 'smooth' = smooth fields before output c --- 'mthin ' = mask thin layers from output call blkinl(smooth,'smooth') call blkinl(mthin, 'mthin ') c c --- 'iorign' = i-origin of sampled subregion c --- 'jorign' = j-origin of sampled subregion c --- 'idmp ' = i-extent of sampled subregion (<=idm; 0 implies idm) c --- 'jdmp ' = j-extent of sampled subregion (<=jdm; 0 implies jdm) call blkini(iorign,'iorign') call blkini(jorign,'jorign') call blkini(ii, 'idmp ') call blkini(jj, 'jdmp ') if (ii.eq.0) then ii=idm endif if (jj.eq.0) then jj=jdm endif c --- 'iorign,jorign' denote the origin of the subgrid to be extracted c --- from the full history grid (dimensioned idm x jdm). c --- The size of the subgrid is determined by ii,jj. write (lp,'(2(a,i5),9x,2(a,i5))') 'extracting i =',iorign, & ' ...',iorign+ii-1,'j =',jorign,' ...',jorign+jj-1 call flush(lp) c c --- array allocation c call plot_alloc c allocate( uflux(ii,jj) ) allocate( vflux(ii,jj) ) allocate( vort(ii,jj) ) allocate( ubaro_(ii,jj) ) allocate( vbaro_(ii,jj) ) allocate( strmf(ii,jj) ) allocate( depth1(ii,jj) ) allocate( depthu(ii,jj) ) allocate( depthv(ii,jj) ) allocate( dpu(ii,jj) ) allocate( dpv(ii,jj) ) allocate( util1(ii,jj) ) allocate( work(ii,jj) ) c allocate( utilk(ii,jj,kk) ) allocate( pw(ii,jj,kk) ) c dpthfil = 'regional.depth' c do j=1,jj do i=1,ii p(i,j,1)=0. enddo enddo c c --- read the archive file. c if (lhycom) then call getdat(flnm,time3,artype,initl,icegln,trcout,surflg, & iexpt,iversn,yrflag,kkin) ! hycom input time = time3(3) else call getdtm(flnm,time,initl, thbase) ! micom input artype = 1 iversn = 10 endif c if (artype.eq.3) then smooth = .false. mthin = .false. endif c write(lp,'(/a,2f8.2/a,2f8.2)') & 'sub-domain longitude range = ', & minval(plon(:,:)),maxval(plon(:,:)), & 'sub-domain latitude range = ', & minval(plat(:,:)),maxval(plat(:,:)) c lperiod = maxval(plon(:,:))-minval(plon(:,:)) .gt. 350.0 if (lperiod) then write(lp,'(/a/)') 'sub-domain assumed to be periodic' else write(lp,'(/a/)') 'sub-domain assumed to be non-periodic' endif call flush(lp) c call bigrid(depths) call flush(lp) c c --- check that bathymetry is consistent with this archive. c --- only possible with hycom .[ab] file input. c if (iversn.ge.20) then ibad = 0 do j= 1,jj do i= 1,ii if (ip(i,j).eq.1) then if (srfht(i,j).gt.2.0**99) then ibad = ibad + 1 ! topo sea, srfht land endif else if (srfht(i,j).lt.2.0**99) then ibad = ibad + 1 ! topo land, srfht sea endif endif enddo !i enddo !j if (ibad.ne.0) then write(lp,*) write(lp,*) 'error - wrong bathymetry for this archive file' write(lp,*) 'number of mismatches = ',ibad write(lp,*) call flush(lp) c stop 9 endif !ibad.ne.0 endif !iversn.ge.20 c c --- cover islands with thin film of water for stream functions do 23 j=1,jj1 do 23 i=1,ii1 23 depth1(i,j)=depths(i,j) c call sbmerg(depth1,film) c call bigrd1(depth1) c do 3 k=1,kkin do 3 j=1,jj do 3 i=1,ii c c --- convert baroclinic to total velocities by adding barotropic component if (k.eq.1) then if (iu(i,j).eq.1 .and. artype.eq.1) then umix(i,j)=umix(i,j)+ubaro(i,j) elseif (iu(i,j).ne.1) then umix(i,j)=0. end if if (iv(i,j).eq.1 .and. artype.eq.1) then vmix(i,j)=vmix(i,j)+vbaro(i,j) elseif (iv(i,j).ne.1) then vmix(i,j)=0. end if endif if (iu(i,j).eq.1 .and. artype.eq.1) then u(i,j,2*k)=u(i,j,2*k)+ubaro(i,j) elseif (iu(i,j).ne.1) then u(i,j,2*k)=0. end if if (iv(i,j).eq.1 .and. artype.eq.1) then v(i,j,2*k)=v(i,j,2*k)+vbaro(i,j) elseif (iv(i,j).ne.1) then v(i,j,2*k)=0. end if c c --- convert layer thickness to meters if (depths(i,j).gt.0.) then dp(i,j,k)=dp(i,j,k)/9806. p(i,j,k+1)=p(i,j,k)+dp(i,j,k) th3d(i,j,2*k)=th3d(i,j,2*k)+thbase else saln(i,j,2*k)=flag temp(i,j,2*k)=flag th3d(i,j,2*k)=flag ke( i,j,2*k)=flag dp(i,j,k)=flag p(i,j,k+1)=flag if (depths(i,j).eq.film) p(i,j,k+1)=film endif 3 continue c c --- interface vertical velocity from continuity equation do j= 1,jj do i= 1,ii depthu(i,j) = min(depths(i,j),depths(i-1,j)) ! depths(0,j) is ok depthv(i,j) = min(depths(i,j),depths(i,j-1)) ! depths(i,0) is ok enddo enddo do j= 1,jj-1 do i= 1,ii-1 if (ip(i,j).eq.1) then pwk = (ubaro(i+1,j)*depthu(i+1,j)- & ubaro(i ,j)*depthu(i, j) )/scpx(i,j) + & (vbaro(i,j+1)*depthv(i,j+1)- & vbaro(i,j )*depthv(i,j ) )/scpy(i,j) pw(i,j,kkin) = pwk endif enddo enddo do k= 1,kkin do j= 1,jj do i= 1,ii if (iu(i,j).eq.1 .and. i.gt.1) then dpu(i,j)=max(0., & min(depthu(i,j),.5*(p(i,j,k+1)+p(i-1,j,k+1)))- & min(depthu(i,j),.5*(p(i,j,k )+p(i-1,j,k )))) else dpu(i,j) = 0.0 endif if (iv(i,j).eq.1 .and. j.gt.1) then dpv(i,j)=max(0., & min(depthv(i,j),.5*(p(i,j,k+1)+p(i,j-1,k+1)))- & min(depthv(i,j),.5*(p(i,j,k )+p(i,j-1,k )))) else dpv(i,j) = 0.0 endif enddo enddo do j= 2,jj-1 pw(1, j,k) = flag do i= 2,ii-1 if (ip(i,j).eq.1) then pwk = (u(i+1,j,2*k)*dpu(i+1,j)- & u(i ,j,2*k)*dpu(i, j) )/scpx(i,j) + & (v(i,j+1,2*k)*dpv(i,j+1)- & v(i,j ,2*k)*dpv(i,j ) )/scpy(i,j) if (k.eq.1) then pw(i,j,k) = pwk - & pw(i,j,kkin)*dp(i,j,k)/depths(i,j) else pw(i,j,k) = pw(i,j,k-1) + pwk - & pw(i,j,kkin)*dp(i,j,k)/depths(i,j) endif else pw(i,j,k) = flag endif enddo pw(ii,j,k) = flag enddo do i= 1,ii pw(i, 1,k) = flag pw(i,jj,k) = flag enddo enddo if (smooth) then do k= 1,kkin call psmoo(pw(1,1,k),work) enddo endif c ccc x=thrufl(107,209,122,212,'(Drake Passage)') ccc x=thrufl(41,199,44,201,'(Florida Straits)') ccc x=thrufl(63,76,69,94,'(Indonesia)') c do 7 j=1,jj do 7 i=1,ii if (depths(i,j).gt.0.) then srfht( i,j)=srfht( i,j)/(thref*98.06) ! cm dpbl( i,j)=dpbl( i,j)/9806. ! m dpmixl(i,j)=dpmixl(i,j)/9806. ! m thmix( i,j)=thmix( i,j)+thbase ! SigmaT if (artype.ne.3) then ttrend(i,j)=surflx(i,j)*thref*8.64E4 & /spcifh/dpbl(i,j) ! deg/day strend(i,j)=salflx(i,j)*thref*8.64E4 & /dpbl(i,j) ! psu/day emnp( i,j)=salflx(i,j)*thref*8.64E7 cdbgz & /max(saln(i,j,2),1.) c & /saln(i,j,2) ! mm/day & /10. ! cm/day else ! std.dev, archive ttrend(i,j)=flag strend(i,j)=flag emnp( i,j)=salflx(i,j)*thref*8.64E7 & /35.00 ! mm/day & /10. ! cm/day endif cdbgz if (emnp( i,j)