Oasis3 4.0.2
pmrho.f
Go to the documentation of this file.
00001       SUBROUTINE pmrho (prho, kto, kwg,
00002      $                  p2xi, p2xs, p2yi, p2ys,
00003      $                  px1, py1, kmsk1, kngx, kngy, cdper, kper,
00004      $                  kvma1, kmsz2, kvmsz2)
00005 C****
00006 C               *****************************
00007 C               * OASIS ROUTINE  -  LEVEL 3 *
00008 C               * -------------     ------- *
00009 C               *****************************
00010 C
00011 C**** *pmrho* - Calculate weights and adresses at one location 
00012 C     
00013 C     Purpose:
00014 C     -------
00015 C     At one target grid location, gives the kwg closest neighbours 
00016 C     adresses kto in source grid and their weight prho, which is function of
00017 C     the surface intersection (if no overlap, weight is zero).
00018 C
00019 C     N.B: Note that the search is done ONLY over unmasked points. 
00020 C 
00021 C**   Interface:
00022 C     ---------
00023 C       *CALL*  *pmrho(prho, kto, kwg,
00024 C                      p2xi, p2xs, p2yi, p2ys,
00025 C                      px1, py1, kmsk1, kngx, kngy, cdper, kper,
00026 C                      kvma1, kmsz2, kvmsz2)* 
00027 C
00028 C     Input:
00029 C     -----
00030 C                kwg   : maximum number of overlapped neighbors
00031 C                p2xi  : the inf longitude of the target grid square
00032 C                p2xs  : the sup longitude of the target grid square
00033 C                p2yi  : the inf latitude of the target grid square
00034 C                p2ys  : the sup latitude of the target grid square
00035 C                px1   : longitudes for source grid (real 2D)
00036 C                py1   : latitudes for source grid (real 2D)
00037 C                kmsk1 : the mask for source grid (integer 2D)
00038 C                kngx  : number of longitudes for source grid
00039 C                kngy  : number of latitudes for source grid
00040 C                kvma1 : the value of the mask for source grid
00041 C                cdper : source grid periodicity 
00042 C                kper  : number of overlapped points for source grid
00043 C     Output:
00044 C     ------
00045 C                prho  : the neighbors weights 
00046 C                kto   : the neighbors adresses in the source grid 
00047 C                kmsz2 : number of source grid neighbors (integer 2D)
00048 C
00049 C     Workspace:
00050 C     ---------
00051 C     None
00052 C
00053 C     External:
00054 C     --------
00055 C     pmesh, pminm
00056 C
00057 C     References:
00058 C     ----------
00059 C     O. Thual, Simple ocean-atmosphere interpolation. 
00060 C               Part A: The method, EPICOA 0629 (1992)
00061 C               Part B: Software implementation, EPICOA 0630 (1992)
00062 C     See also OASIS manual (1995)
00063 C
00064 C     History:
00065 C     -------
00066 C       Version   Programmer     Date      Description
00067 C       -------   ----------     ----      ----------- 
00068 C       1.1       O. Thual       93/04/15  created 
00069 C       2.0       L. Terray      95/10/01  modified: new structure
00070 C       2.3       L. Terray      99/09/15  changed periodicity variable
00071 C
00072 C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00073 C
00074 C* ---------------------------- Include files ---------------------------
00075 C
00076       USE mod_kinds_oasis
00077       USE mod_unit
00078 C
00079 C* ---------------------------- Argument declarations -------------------
00080 C
00081       REAL (kind=ip_realwp_p) px1(kngx,kngy), py1(kngx,kngy)
00082       REAL (kind=ip_realwp_p) prho(kwg)
00083       INTEGER (kind=ip_intwp_p) kmsk1(kngx,kngy)
00084       INTEGER (kind=ip_intwp_p) kto(kwg)
00085       CHARACTER*8 cdper
00086 C
00087 C* ---------------------------- Poema verses ----------------------------
00088 C
00089 C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
00090 C
00091 C*    1. Various initializations
00092 C        -----------------------
00093 C 
00094       ivma1 = kvma1
00095       ing = kngx * kngy
00096 C
00097 C   
00098 C*    2. Neighbors (mesh) determination
00099 C        -------------------------------
00100 C* Checks
00101 C     
00102       IF (kwg .GT. ing) THEN
00103           WRITE(UNIT = nulou,FMT = *) 
00104      $        'WARNING in pmrho -- kwg = ',kwg,' .gt. ing = ',ing
00105           WRITE(UNIT = nulou,FMT = *) 
00106      $        ' Number of searched neighbors greater '
00107           WRITE(UNIT = nulou,FMT = *) 
00108      $        ' than number of grid points '
00109           iwg = ing
00110           WRITE(UNIT = nulou,FMT = *)  'We set  iwg = ing = ',iwg
00111         ELSE
00112           iwg = kwg
00113       ENDIF
00114 C
00115 C* zero the weights and set adresses to one
00116 C
00117       CALL szero(prho,iwg)
00118       DO 210 ji = 1, iwg
00119         kto(ji) = 1
00120  210  CONTINUE
00121 C
00122 C* Loop on all the points of source grid  
00123 C
00124       iwco = 0
00125       DO 220 jy = 1, kngy
00126         DO 230 jx = 1, kngx
00127 C
00128 C* If it is an unmasked point
00129 C
00130           IF (kmsk1(jx,jy) .NE. ivma1) THEN
00131 C
00132 C* Calculate its grid square longitude and latitude extrema
00133 C
00134               CALL pmesh (jx, jy, px1, py1, kngx, kngy, cdper, kper,
00135      $                    z1xi, z1xs, z1yi, z1ys)
00136 C
00137 C* Determine the intersection with the current target grid square
00138 C
00139               CALL pminm (iflag, zsurf,
00140      $                    p2xi, p2xs, p2yi, p2ys,
00141      $                    z1xi, z1xs, z1yi, z1ys)
00142 C
00143 C* If intersection is not empty
00144 C
00145               IF (iflag .EQ. 1) THEN
00146                   iwco = iwco +1
00147 C
00148 C* Check dimensions
00149 C
00150                   IF (iwco .GT. iwg) THEN 
00151                       WRITE(UNIT = nulou,FMT = *)  
00152      $                    ' WARNING: not enough neighbours space'
00153                       WRITE(UNIT = nulou,FMT = *) 
00154      $                    ' ******* '
00155                       WRITE(UNIT = nulou,FMT = *) 
00156      $                    ' In pmrho : iwco = ',iwco,'.gt.iwg = ',iwg
00157                       CALL HALTE('STOP in pmrho')
00158                     ELSE
00159 C
00160 C* Get index adress and surface overlap for neighbor number iwco
00161 C
00162                       kto(iwco) = jx + (jy-1) * kngx
00163                       prho(iwco) = zsurf
00164                   ENDIF
00165               ENDIF
00166           ENDIF
00167  230    CONTINUE 
00168  220  CONTINUE
00169 C
00170 C
00171 C*    3. Weight function
00172 C        ---------------
00173 C
00174 C* Sum of the surface values
00175 C
00176       zsum = 0.
00177       DO 310 jwg = 1, iwg
00178         zsum = zsum + prho(jwg)
00179  310  CONTINUE
00180 C
00181 C* Normalization
00182 C
00183       zthres = 1.e-6
00184 C
00185 C* If no intersection is found, point is masked in overlapping array
00186 C
00187       IF (iwco .EQ. 0) THEN
00188           kmsz2 = kvmsz2
00189 C
00190 C* If at least one intersection is found
00191 C     
00192         ELSE
00193           kmsz2 = iwco
00194 C
00195 C* If under threshold
00196 C   
00197           IF (zsum .LT. zthres) THEN
00198               DO 320 jwg = 1, iwg
00199                 prho(jwg) = 1. / float(iwco)
00200  320          CONTINUE
00201 C
00202 C* If above threshold, normalize
00203 C
00204             ELSE
00205               DO 330 jwg = 1, iwg
00206                 prho(jwg) = prho(jwg) / zsum
00207  330          CONTINUE
00208           ENDIF
00209       ENDIF
00210 C
00211 C* End of routine
00212 C
00213       RETURN 
00214       END
 All Data Structures Namespaces Files Functions Variables Defines