c *********************************************************************** subroutine interdp(yy,zz,m,y,z,n,opt) c interpolation soubroutine. input values: y(n) at z(n). c output values: yy(m) at zz(m). options: 1 -> lineal; 2 -> logarithmic c jul 2011: malv+fgg Adapted to LMD-MGCM c *********************************************************************** implicit none integer n,m,i,j,opt real*8 zz(m),yy(m),z(n),y(n), zmin,zzmin,zmax,zzmax ! write (*,*) ' d interpolating ' call mindp (z,n,zmin) call mindp (zz,m,zzmin) call maxdp (z,n,zmax) call maxdp (zz,m,zzmax) if(zzmin.lt.zmin)then write (*,*) 'from d interp: new variable out of limits' write (*,*) zzmin,'must be .ge. ',zmin stop ! elseif(zzmax.gt.zmax)then ! write (*,*) 'from interp: new variable out of limits' ! write (*,*) zzmax, 'must be .le. ',zmax ! stop end if do 1,i=1,m do 2,j=1,n-1 if(zz(i).ge.z(j).and.zz(i).lt.z(j+1)) goto 3 2 continue c in this case (zz(m).eq.z(n)) and j leaves the loop with j=n-1+1=n if(opt.eq.1)then yy(i)=y(n-1)+(y(n)-y(n-1))*(zz(i)-z(n-1))/(z(n)-z(n-1)) elseif(opt.eq.2)then if(y(n).eq.0.0d0.or.y(n-1).eq.0.0d0)then yy(i)=0.0d0 else yy(i)=dexp(dlog(y(n-1))+dlog(y(n)/y(n-1))* @ (zz(i)-z(n-1))/(z(n)-z(n-1))) end if else write (*,*) @ ' from d interp error: opt must be 1 or 2, opt= ',opt end if goto 1 3 continue if(opt.eq.1)then yy(i)=y(j)+(y(j+1)-y(j))*(zz(i)-z(j))/(z(j+1)-z(j)) ! write (*,*) ' ' ! write (*,*) ' z(j),z(j+1) =', z(j),z(j+1) ! write (*,*) ' t(j),t(j+1) =', y(j),y(j+1) ! write (*,*) ' zz, tt = ', zz(i), yy(i) elseif(opt.eq.2)then if(y(j+1).eq.0.0d0.or.y(j).eq.0.0d0)then yy(i)=0.0d0 else yy(i)=dexp(dlog(y(j))+dlog(y(j+1)/y(j))* @ (zz(i)-z(j))/(z(j+1)-z(j))) end if else write (*,*) ' from interp error: opt must be 1 or 2, opt= ', @ opt end if 1 continue return end