[4775] | 1 | subroutine fracnnei (src_size, dst_size, |
---|
| 2 | $ ld_srcmask, ld_dstmask, |
---|
| 3 | $ src_lon, src_lat, dst_lon, dst_lat, |
---|
| 4 | $ num_links, num_wgts, |
---|
| 5 | $ weights, src_addr, dst_addr) |
---|
| 6 | C**** |
---|
| 7 | C ***************************** |
---|
| 8 | C * OASIS ROUTINE - LEVEL 4 * |
---|
| 9 | C * ------------- ------- * |
---|
| 10 | C ***************************** |
---|
| 11 | C |
---|
| 12 | C**** *fracnnei* - SCRIP remapping |
---|
| 13 | C |
---|
| 14 | C Purpose: |
---|
| 15 | C ------- |
---|
| 16 | C Treatment of the tricky points in an interpolation |
---|
| 17 | C |
---|
| 18 | C Interface: |
---|
| 19 | C --------- |
---|
| 20 | C *CALL* * |
---|
| 21 | C |
---|
| 22 | C Called from: |
---|
| 23 | C ----------- |
---|
| 24 | C scriprmp |
---|
| 25 | C |
---|
| 26 | C Input: |
---|
| 27 | C ----- |
---|
| 28 | C src_size : source grid size (integer) |
---|
| 29 | C dst_size : target grid size (integer) |
---|
| 30 | C ld_srcmask : mask of the source grid |
---|
| 31 | C ld_dstmask : mask of the target grid |
---|
| 32 | C src_lon : longitudes of the source grid |
---|
| 33 | C src_lat : latitudes of the source grid |
---|
| 34 | C dst_lon : longitudes of the target grid |
---|
| 35 | C dst_lat : latitudes of the target grid |
---|
| 36 | C num_links : total number of links |
---|
| 37 | C num_wgts : number of weights for each link |
---|
| 38 | C InOut |
---|
| 39 | C ----- |
---|
| 40 | C weights : remapping weights |
---|
| 41 | C src_addr : remapping source addresses |
---|
| 42 | C dst_addr : remapping target addresses |
---|
| 43 | C |
---|
| 44 | C History: |
---|
| 45 | C ------- |
---|
| 46 | C Version Programmer Date Description |
---|
| 47 | C ------- ---------- ---- ----------- |
---|
| 48 | C 2.5 D.Declat 2002/08/20 adapted from S. Valcke ptmsq |
---|
| 49 | C 3.0 S. Valcke 2002/10/30 test and corrections |
---|
| 50 | C |
---|
| 51 | C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 52 | C* ---------------------------- Modules used ---------------------------- |
---|
| 53 | C |
---|
| 54 | use kinds_mod ! defines common data types |
---|
| 55 | use constants ! defines common constants |
---|
| 56 | use grids ! module containing grid information |
---|
| 57 | use remap_vars ! module containing remap information |
---|
| 58 | USE mod_oasis_flush |
---|
| 59 | C |
---|
| 60 | C* ---------------------------- Implicit -------------------------------- |
---|
| 61 | C |
---|
| 62 | implicit none |
---|
| 63 | C |
---|
| 64 | C* ---------------------------- Include files --------------------------- |
---|
| 65 | C |
---|
| 66 | |
---|
| 67 | C INCLUDE 'netcdf.inc' |
---|
| 68 | C |
---|
| 69 | C* ---------------------------- Intent In ------------------------------- |
---|
| 70 | C |
---|
| 71 | INTEGER (kind=int_kind) :: |
---|
| 72 | $ src_size, ! size of the source grid |
---|
| 73 | $ dst_size ! size of the destination grid |
---|
| 74 | C |
---|
| 75 | REAL (kind=dbl_kind) :: |
---|
| 76 | $ src_lat(src_size), src_lon(src_size), |
---|
| 77 | $ dst_lat(dst_size), dst_lon(dst_size) |
---|
| 78 | |
---|
| 79 | C |
---|
| 80 | LOGICAL :: |
---|
| 81 | $ ld_srcmask(src_size), ! source grid mask |
---|
| 82 | $ ld_dstmask(dst_size) ! target grid mask |
---|
| 83 | C |
---|
| 84 | INTEGER (kind=int_kind) :: |
---|
| 85 | $ num_links, ! number of links between src and tgt |
---|
| 86 | $ num_wgts ! number of weights |
---|
| 87 | |
---|
| 88 | C |
---|
| 89 | C* ---------------------------- Intent InOut ------------------------------ |
---|
| 90 | C |
---|
| 91 | REAL (kind=dbl_kind) :: |
---|
| 92 | $ weights(num_wgts, num_links) ! remapping weights |
---|
| 93 | C |
---|
| 94 | INTEGER (kind=int_kind) :: |
---|
| 95 | $ src_addr(num_links), ! remapping source addresses |
---|
| 96 | $ dst_addr(num_links) ! remapping target addresses |
---|
| 97 | C |
---|
| 98 | C* ---------------------------- Local declarations ---------------------- |
---|
| 99 | C |
---|
| 100 | C |
---|
| 101 | INTEGER (kind=int_kind) :: |
---|
| 102 | $ ila_nneiadd ! Nearest-neighbor address |
---|
| 103 | C |
---|
| 104 | INTEGER (kind=int_kind) :: |
---|
| 105 | $ ib_dst, ! INDEX loop for the distance grid |
---|
| 106 | $ ib_src, ! INDEX loop for the source grid |
---|
| 107 | $ ib_neigh, ! INDEX loop on the corresponding src pts |
---|
| 108 | $ ib_links ! INDEX loop for the links |
---|
| 109 | C |
---|
| 110 | INTEGER (kind=int_kind) :: |
---|
| 111 | $ nb_Vmm, ! number of Mtt points |
---|
| 112 | $ ntottotland, ! number of land points |
---|
| 113 | $ ntotland, ! number of land points |
---|
| 114 | $ ntotoce, ! number of oceanic points |
---|
| 115 | $ ntotngh ! number of corresponding source points |
---|
| 116 | C |
---|
| 117 | INTEGER (kind=int_kind) :: |
---|
| 118 | $ beg_links, ! begining of the serie of links |
---|
| 119 | $ nb_links ! number of links |
---|
| 120 | C |
---|
| 121 | REAL (kind=dbl_kind) :: |
---|
| 122 | $ coslat, ! cosinus of the latitude |
---|
| 123 | $ sinlat, ! sinus of the latitude |
---|
| 124 | $ coslon, ! cosinus of the longitude |
---|
| 125 | $ sinlon, ! sinus of the longitude |
---|
| 126 | $ distance, |
---|
| 127 | $ dist_min, |
---|
| 128 | $ arg |
---|
| 129 | C |
---|
| 130 | INTEGER (kind=int_kind) :: n, il |
---|
| 131 | C |
---|
| 132 | C* ---------------------------- Poema verses ---------------------------- |
---|
| 133 | C |
---|
| 134 | C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 135 | C |
---|
| 136 | C* 1. Initialization |
---|
| 137 | C -------------- |
---|
| 138 | C |
---|
| 139 | IF (nlogprt .GE. 2) THEN |
---|
| 140 | WRITE (UNIT = nulou,FMT = *) ' ' |
---|
| 141 | WRITE (UNIT = nulou,FMT = *) ' ' |
---|
| 142 | WRITE (UNIT = nulou,FMT = *) |
---|
| 143 | $ ' Entering ROUTINE fracnnei - Level 4' |
---|
| 144 | WRITE (UNIT = nulou,FMT = *) |
---|
| 145 | $ ' **************** *******' |
---|
| 146 | WRITE (UNIT = nulou,FMT = *) ' ' |
---|
| 147 | WRITE (UNIT = nulou,FMT = *) |
---|
| 148 | $ ' Treating the tricky points of the remapping' |
---|
| 149 | WRITE (UNIT = nulou,FMT = *) ' ' |
---|
| 150 | CALL OASIS_FLUSH_SCRIP(nulou) |
---|
| 151 | ENDIF |
---|
| 152 | C |
---|
| 153 | C *---------------------------------------------------------------------- |
---|
| 154 | C |
---|
| 155 | C* 2. Treating Vmm points V |
---|
| 156 | C ------------------- m m |
---|
| 157 | C The target point is a non-masked Valid point while the source points |
---|
| 158 | C are all masked points. Use of the non-masked nearest neighbours. |
---|
| 159 | C |
---|
| 160 | nb_Vmm = 0 |
---|
| 161 | ntottotland = 0 |
---|
| 162 | beg_links = 1 |
---|
| 163 | |
---|
| 164 | C* -- Loop all other the target points |
---|
| 165 | DO ib_dst = 1, dst_size |
---|
| 166 | C* -- If the point is a sea point |
---|
| 167 | IF (ld_dstmask(ib_dst)) THEN |
---|
| 168 | |
---|
| 169 | beg_links = 0 |
---|
| 170 | |
---|
| 171 | DO ib_links = 1, num_links |
---|
| 172 | IF (dst_addr(ib_links) .eq. ib_dst) THEN |
---|
| 173 | beg_links = ib_links |
---|
| 174 | exit |
---|
| 175 | ENDIF |
---|
| 176 | END DO |
---|
| 177 | |
---|
| 178 | IF (beg_links .ne. 0) THEN |
---|
| 179 | |
---|
| 180 | ntotland = 0 |
---|
| 181 | ntotoce = 0 |
---|
| 182 | ntotngh = 0 |
---|
| 183 | |
---|
| 184 | C* -- Find the number of associated src points to the non-masked tgt point |
---|
| 185 | nb_links = 1 |
---|
| 186 | DO il = beg_links+1, num_links |
---|
| 187 | IF (dst_addr(il) .eq. dst_addr(beg_links)) |
---|
| 188 | $ nb_links = nb_links + 1 |
---|
| 189 | END DO |
---|
| 190 | |
---|
| 191 | C* -- For each point on the src grid associated to the non-masked tgt point |
---|
| 192 | DO ib_neigh = 1, nb_links |
---|
| 193 | C |
---|
| 194 | ntotngh = ntotngh + 1 |
---|
| 195 | |
---|
| 196 | C* -- Check IF the point is a masked or non-masked point and treat it |
---|
| 197 | IF (.not. ld_srcmask(src_addr(beg_links+ib_neigh-1))) |
---|
| 198 | $ THEN |
---|
| 199 | ntotland = ntotland + 1 |
---|
| 200 | ntottotland = ntottotland + 1 |
---|
| 201 | ELSE IF (ld_srcmask(src_addr(beg_links+ib_neigh-1))) |
---|
| 202 | $ THEN |
---|
| 203 | ntotoce = ntotoce + 1 |
---|
| 204 | ELSE |
---|
| 205 | WRITE (nulou, *) 'Pb with ocean mask with Mtt 1' |
---|
| 206 | END IF |
---|
| 207 | |
---|
| 208 | END DO |
---|
| 209 | |
---|
| 210 | C* -- If all the src points are land, treat it ! |
---|
| 211 | IF (ntotland .EQ. ntotngh) THEN |
---|
| 212 | nb_Vmm = nb_Vmm + 1 |
---|
| 213 | WRITE(nulou,*) |
---|
| 214 | $ '************ Doing FRACNNEI for point', ib_dst |
---|
| 215 | |
---|
| 216 | C* -- Find the nearest neighbours and change weights and address |
---|
| 217 | |
---|
| 218 | coslat = cos(dst_lat(ib_dst)) |
---|
| 219 | sinlat = sin(dst_lat(ib_dst)) |
---|
| 220 | coslon = cos(dst_lon(ib_dst)) |
---|
| 221 | sinlon = sin(dst_lon(ib_dst)) |
---|
| 222 | |
---|
| 223 | dist_min = bignum |
---|
| 224 | ila_nneiadd = 0 |
---|
| 225 | DO ib_src = 1, src_size |
---|
| 226 | IF (ld_srcmask(ib_src)) THEN |
---|
| 227 | arg = |
---|
| 228 | & coslat*cos(src_lat(ib_src))* |
---|
| 229 | & (coslon*cos(src_lon(ib_src)) + |
---|
| 230 | & sinlon*sin(src_lon(ib_src)))+ |
---|
| 231 | & sinlat*sin(src_lat(ib_src)) |
---|
| 232 | IF (arg < -1.0d0) THEN |
---|
| 233 | arg = -1.0d0 |
---|
| 234 | ELSE IF (arg > 1.0d0) THEN |
---|
| 235 | arg = 1.0d0 |
---|
| 236 | END IF |
---|
| 237 | distance = acos(arg) |
---|
| 238 | IF (distance < dist_min) THEN |
---|
| 239 | ila_nneiadd = ib_src |
---|
| 240 | dist_min = distance |
---|
| 241 | ENDIF |
---|
| 242 | ENDIF |
---|
| 243 | END DO |
---|
| 244 | src_addr(beg_links) = ila_nneiadd |
---|
| 245 | weights(1,beg_links) = 1.0 |
---|
| 246 | WRITE(nulou,*) |
---|
| 247 | $ '*************** Nearest source neighbour is ', |
---|
| 248 | $ ila_nneiadd |
---|
| 249 | IF (nb_links > 1) then |
---|
| 250 | DO n=2, nb_links |
---|
| 251 | src_addr(beg_links+n-1)=0 |
---|
| 252 | weights(1,beg_links+n-1)=0.0 |
---|
| 253 | END DO |
---|
| 254 | END IF |
---|
| 255 | END IF |
---|
| 256 | END IF |
---|
| 257 | ENDIF |
---|
| 258 | END DO |
---|
| 259 | C |
---|
| 260 | C |
---|
| 261 | C *---------------------------------------------------------------------- |
---|
| 262 | C |
---|
| 263 | IF (nlogprt .GE. 2) THEN |
---|
| 264 | WRITE (UNIT = nulou,FMT = *) ' ' |
---|
| 265 | WRITE (UNIT = nulou,FMT = *) |
---|
| 266 | $ ' Leaving ROUTINE fracnnei - Level 4' |
---|
| 267 | WRITE (UNIT = nulou,FMT = *) ' ' |
---|
| 268 | CALL OASIS_FLUSH_SCRIP(nulou) |
---|
| 269 | ENDIF |
---|
| 270 | |
---|
| 271 | END SUBROUTINE fracnnei |
---|
| 272 | |
---|
| 273 | !*********************************************************************** |
---|
| 274 | |
---|
| 275 | |
---|