! KAL -- This routine interpolates horizontal mercator fields to a NERSC model ! KAL ! KAL -- Usable/Inital version: 31.01.2007 - Knut Lisæter program vremap_mercator use mod_xc use mod_za use mod_sigma use mod_grid, only: hycbathy => depths, hyclon => plon , hyclat => plat, & get_grid use mod_hycomfile_io use m_parse_blkdat use m_layer_remapV2 use m_layer_mixV1 use m_pbavg_from_ssh use m_rotate2 implicit none real, dimension(:,:), allocatable :: & rtmp,dens, dp, & ubavg, vbavg, ssh, psikk, thkk, pbavg, intup real, dimension(:,:,:), allocatable :: & oldtemp, oldsaln, newint, newtemp, newsaln, & oldutot, oldvtot, newutot, newvtot real, allocatable :: newdens(:), oldint(:), dp0k(:), oldint2(:) integer, dimension(:,:), allocatable :: & ip, maxk integer :: thflag, kapflg integer :: newkdm,oldkdm, oldkdm2 character(len=8) :: c8 character(len=80) :: template integer :: k,idummy,ios,kold,i,j,fnd integer :: ios2, itime real :: amin, amax,rdummy, bmin, bmax, zlev, thbase logical :: lmaxk #if defined (IARGC) integer*4, external :: iargc #endif type(hycomfile) :: hfile if (iargc()==1) then call getarg(1,template) fnd=max(index(template,'.a'),index(template,'.b')) if (fnd<=0) then print *,'error in restart template (input)' call exit(1) end if template=template(1:fnd-1) else print *,'usage: vremap_mercator restart_template' call exit(1) endif ! Get HYCOM lon lat and depths ! Initialize Arrai IO call xcspmd() call zaiost() call get_grid() allocate(ubavg(idm,jdm)) allocate(vbavg(idm,jdm)) allocate(ssh(idm,jdm)) allocate(intup(idm,jdm)) allocate(psikk(idm,jdm)) allocate(thkk(idm,jdm)) allocate(pbavg(idm,jdm)) allocate(ip (idm,jdm)) allocate(rtmp (idm,jdm)) print *,'hyc lon:',minval(hyclon),maxval(hyclon) print *,'hyc lat:',minval(hyclat),maxval(hyclat) ! Get thflag,kapflg,kdm from blkdat file call parse_blkdat('kdm ','integer',rdummy,newkdm) call parse_blkdat('thflag','integer',rdummy,thflag) call parse_blkdat('kapflg','integer',rdummy,kapflg) call parse_blkdat('thbase','real',thbase,idummy) ! Get densities from blkdat file allocate(newdens(newkdm)) do k=1,newkdm call parse_blkdat('sigma ','real',newdens(k),idummy,imatch=k) end do ! Go through horizontally interpolated mercator files -- ! get oldkdm from highest temperature level entry in .b file open(10,file='merchint.b') oldkdm=1 ios2=0 do while (ios2==0) read(10,104,iostat=ios2) c8,k,zlev,bmin,bmax if (trim(c8)=='temp'.and.ios2==0) oldkdm=max(oldkdm,k) end do close(10) print *,'oldkdm=',oldkdm ! Read mercator 3D fields - only temp/saln now allocate(oldtemp(idm,jdm,oldkdm)) allocate(oldsaln(idm,jdm,oldkdm)) allocate(oldutot(idm,jdm,oldkdm)) allocate(oldvtot(idm,jdm,oldkdm)) allocate(maxk (idm,jdm)) allocate(oldint (oldkdm)) allocate(oldint2(oldkdm)) open(99,file='merchint.b') call zaiopf('merchint.a','old',99) maxk=0 ios=0 lmaxk=.false. do while (ios==0) read(99,104,iostat=ios) c8,k,zlev,bmin,bmax if (ios==0) then !print *,'k is ',k if(k>0) oldint(k)=zlev call zaiord(rtmp,ip,.false.,amin,amax,99) !plon if (trim(c8)=='temp') then !print *,'temp match',k oldtemp(:,:,k)=rtmp elseif (trim(c8)=='saln') then !print *,'saln match',k oldsaln(:,:,k)=rtmp elseif (trim(c8)=='utot') then !print *,'uvel match',k oldutot(:,:,k)=rtmp elseif (trim(c8)=='vtot') then !print *,'vvel match',k oldvtot(:,:,k)=rtmp elseif (trim(c8)=='ubavg') then !print *,'vbavg match',k ubavg=rtmp elseif (trim(c8)=='vbavg') then !print *,'vbavg match',k vbavg=rtmp elseif (trim(c8)=='ssh') then !print *,'ssh match',k ssh=rtmp elseif (trim(c8)=='maxk') then lmaxk=.true. maxk=nint(rtmp) !print *,'got maxk' end if end if end do !print *,'end' close(99) call zaiocl(99) !stop ! if (.not. lmaxk) then print *,'Can not get maxk from files' print *, '(vremap_mercator)' call exit(1) end if !Set up new layers allocate(newint (idm,jdm,newkdm)) allocate(newtemp(idm,jdm,newkdm)) allocate(newsaln(idm,jdm,newkdm)) allocate(newutot(idm,jdm,newkdm)) allocate(newvtot(idm,jdm,newkdm)) allocate(dens (idm,jdm)) allocate(dp (idm,jdm)) ! Cycle through-create new interfaces print *,'WARN WARN WARN' print *,'WARN WARN WARN' print *,'WARN WARN WARN' print *,'WARN WARN WARN' print *,'WARN WARN WARN' print *,'dp0k set specifically in p_vremap_mercator.F90' allocate(dp0k(newkdm)) dp0k=10. newint=0. do j=1,jdm do i=1,idm if (maxk(i,j)>0) then !print *,i,j oldkdm2=maxk(i,j) ! TODO - calc newdp0 ! call layer_remapV2(oldint(1:oldkdm2),oldtemp(i,j,1:oldkdm2), & oldsaln(i,j,1:oldkdm2),oldkdm2, & newdens,newint(i,j,:),dp0k,newkdm,thflag,.false.) where (newint(i,j,:)>hycbathy(i,j)) newint(i,j,:)=hycbathy(i,j) where (newint(i,j,:)0) then oldkdm2=maxk(i,j) ! Temporary - adheres to hycom bathymetry oldint2=oldint oldint2=min(oldint2,hycbathy(i,j)) if (oldkdm2