[4] | 1 | subroutine CellTest(time_tra, ic, jc, kc, v_x, v_y, v_E, xtracer, & |
---|
| 2 | ytracer, E_k, im, jm, km, fx, fy, fz) |
---|
| 3 | |
---|
| 4 | |
---|
| 5 | |
---|
| 6 | !! Find the cell origin index for the previous time_tra step |
---|
| 7 | use module3d_phy |
---|
| 8 | use tracer_vars |
---|
| 9 | implicit none |
---|
| 10 | |
---|
| 11 | integer, intent(IN) :: time_tra |
---|
| 12 | integer, intent(IN) :: ic, jc, kc |
---|
| 13 | real, intent(IN) :: v_x, v_y, v_E |
---|
| 14 | real, intent(IN) :: xtracer, ytracer |
---|
| 15 | real, intent(INOUT) :: E_k |
---|
| 16 | integer, intent(OUT) :: im, jm, km |
---|
| 17 | real, intent(OUT) :: fx, fy, fz |
---|
| 18 | |
---|
| 19 | integer :: kk ! indice vertical pour definition de E, mais on veut conserver la valeur de k |
---|
| 20 | ! real,dimension(nz) :: E ! vertical coordinate in ice, scaled to H zeta |
---|
| 21 | |
---|
| 22 | E(1)=0. |
---|
| 23 | E(NZ)=1. |
---|
| 24 | do KK=1,NZ |
---|
| 25 | if ((KK.ne.1).and.(KK.ne.NZ)) E(KK)=(KK-1.)/(NZ-1.) |
---|
| 26 | end do |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | if(v_x>0.0) then |
---|
| 30 | im = ic-1 |
---|
| 31 | do |
---|
| 32 | if(xtracer>=xgrid(im) .and. xtracer<=xgrid(im+1)) exit |
---|
| 33 | !! PRINT *,"CellTest(x-): Multiple decrement required (",ic,",",jc,",",kc,")" |
---|
| 34 | im = im-1 |
---|
| 35 | if(im<1) then |
---|
| 36 | print *,"CellTest(x-;",time_tra,"): Out-of_range decrement (",ic,",",jc,",",kc,")", v_x |
---|
| 37 | ! STOP |
---|
| 38 | im =ic |
---|
| 39 | exit |
---|
| 40 | end if |
---|
| 41 | end do |
---|
| 42 | else |
---|
| 43 | im = ic |
---|
| 44 | do |
---|
| 45 | if(xtracer>=xgrid(im) .and. xtracer<=xgrid(im+1)) exit |
---|
| 46 | !! PRINT *,"CellTest(x+): Multiple increment required (",ic,",",jc,",",kc,")" |
---|
| 47 | im = im+1 |
---|
| 48 | if(im==nx-1) then |
---|
| 49 | print *,"CellTest(x+;",time_tra,"): Out-of_range increment (",ic,",",jc,",",kc,")", v_x |
---|
| 50 | ! STOP |
---|
| 51 | im = ic -1 |
---|
| 52 | exit |
---|
| 53 | end if |
---|
| 54 | end do |
---|
| 55 | end if |
---|
| 56 | |
---|
| 57 | fx = abs(xtracer-xgrid(im))/dx |
---|
| 58 | if (fx>1.00) fx = fx - aint(fx) |
---|
| 59 | |
---|
| 60 | ! if((fx>1.0).or.(fx<0.0)) THEN |
---|
| 61 | ! PRINT *,"Cell test(!!!)", ic,jc, kc,im, fx |
---|
| 62 | ! END IF |
---|
| 63 | !---------------------------------------------------------------------------------- |
---|
| 64 | |
---|
| 65 | if(v_y>0.0) then |
---|
| 66 | jm = jc -1 |
---|
| 67 | do |
---|
| 68 | if(ytracer>=ygrid(jm) .and. ytracer<=ygrid(jm+1)) exit |
---|
| 69 | !! PRINT *,"CellTest(y-): Multiple decrement required (",ic,",",jc,",",kc,")" |
---|
| 70 | jm = jm-1 |
---|
| 71 | if(jm<1) then |
---|
| 72 | print *,"CellTest(y-;",time_tra,"): Out-of_range decrement (",ic,",",jc,",",kc,")", v_y |
---|
| 73 | ! STOP |
---|
| 74 | jm =jc |
---|
| 75 | exit |
---|
| 76 | end if |
---|
| 77 | end do |
---|
| 78 | else |
---|
| 79 | jm = jc |
---|
| 80 | do |
---|
| 81 | if(ytracer>=ygrid(jm) .and. ytracer<=ygrid(jm+1)) exit |
---|
| 82 | !! PRINT *,"CellTest(y+): Multiple increment required (",ic,",",jc,",",kc,")" |
---|
| 83 | jm = jm+1 |
---|
| 84 | if(jm==ny-1) then |
---|
| 85 | print *,"CellTest(y+;",time_tra,"): Out-of-range increment (",ic,",",jc,",",kc,")", v_y |
---|
| 86 | ! print*, ytracer, ygrid(jm) |
---|
| 87 | print*, uybar(ic,jc), uybar(ic,jc+1), flotmy(ic,jc), flotmy(ic, jc+1) |
---|
| 88 | print *, uy(ic,jc,:) |
---|
| 89 | print *, uy(ic,jc+1,:) |
---|
| 90 | print*, gzmy(ic, jc), gzmy(ic,jc+1) |
---|
| 91 | ! STOP |
---|
| 92 | jm = jc-1 |
---|
| 93 | exit |
---|
| 94 | end if |
---|
| 95 | end do |
---|
| 96 | end if |
---|
| 97 | |
---|
| 98 | fy = abs(ytracer-ygrid(jm))/dy |
---|
| 99 | if (fy>1.00) fy = fy - aint(fy) |
---|
| 100 | |
---|
| 101 | ! if((fy>1.0).or.(fy<0.0)) THEN |
---|
| 102 | ! PRINT *,"Cell test(!!!)", ic,jc,kc,im,jm, fy |
---|
| 103 | ! END IF |
---|
| 104 | |
---|
| 105 | !------------------------------------------------------------------------------- |
---|
| 106 | |
---|
| 107 | !! Note that v_E is "velocity" in E coordinate system which is |
---|
| 108 | !! positive DOWN |
---|
| 109 | ! also note that in Catritz code k=1 for surface |
---|
| 110 | |
---|
| 111 | |
---|
| 112 | if(E_k < E(1)) then |
---|
| 113 | E_k = E(1) |
---|
| 114 | km=1 |
---|
| 115 | |
---|
| 116 | else if(E_k > E(nz)) then |
---|
| 117 | E_k = E(nz) |
---|
| 118 | km=nz-1 |
---|
| 119 | |
---|
| 120 | else ! this used to be a loop on its own, now shortcuts if E_k is special |
---|
| 121 | |
---|
| 122 | if(v_E>=0.0) then !! Downward flow of ice in E system |
---|
| 123 | if (kc==1) then |
---|
| 124 | !! No action, pending tactical discussion with GKCC |
---|
| 125 | km = 1 |
---|
| 126 | else |
---|
| 127 | km=kc - 1 |
---|
| 128 | do |
---|
| 129 | if( (E_k >= E(km)) .and. (E_k <= E(km+1)) ) exit |
---|
| 130 | km = km - 1 |
---|
| 131 | if(km==0) then |
---|
| 132 | print *,"CellTest(z+;",time_tra,"): Out-of-range increment (",ic,",",jc,",",kc,")", v_E |
---|
| 133 | ! STOP |
---|
| 134 | km = kc |
---|
| 135 | exit |
---|
| 136 | end if |
---|
| 137 | end do |
---|
| 138 | end if |
---|
| 139 | else !! Upward flow of ice in E system |
---|
| 140 | if(kc==nz) then |
---|
| 141 | ! this is incomplete: ice comes from below, cannot use above layer, fix in interpolate |
---|
| 142 | km = kc-1 |
---|
| 143 | else |
---|
| 144 | km = kc |
---|
| 145 | do |
---|
| 146 | if( (E_k >= E(km)) .and. (E_k <= E(km+1)) ) exit |
---|
| 147 | !! PRINT *,"CellTest(z,",time_tra,"): Decrementing km=",km |
---|
| 148 | km = km + 1 |
---|
| 149 | if(km==nz) then |
---|
| 150 | print *,"CellTest(z-;",time_tra,"): Out-of-range decrement (",ic,",",jc,",",kc,")", v_E |
---|
| 151 | ! STOP |
---|
| 152 | km = kc-1 |
---|
| 153 | exit |
---|
| 154 | end if |
---|
| 155 | end do |
---|
| 156 | end if |
---|
| 157 | |
---|
| 158 | end if ! velocity direction |
---|
| 159 | |
---|
| 160 | fz = abs((E_k-E(km))/(E(km+1)-E(km))) |
---|
| 161 | if (fz>1.00) fz = fz - aint(fz) |
---|
| 162 | |
---|
| 163 | end if |
---|
| 164 | |
---|
| 165 | end subroutine CellTest |
---|
| 166 | !=========================================================================== |
---|