updated top-level README and version_decl for V4.5 (#1847)
[WRF.git] / phys / module_irrigation.F
blobea3729c59ff03048d5d7667ebdb07ddae3cfa740
1 MODULE module_irrigation
2 CONTAINS
4 SUBROUTINE irrigation_on(julian_in,irr_start_julianday,irr_end_julianday,irr_on,xtime,gmt,irr_start_hour,end_hour)
5  IMPLICIT NONE
6  REAL, INTENT(IN) :: julian_in, xtime, gmt
7  INTEGER, INTENT(IN) :: irr_start_julianday, irr_end_julianday, irr_start_hour, end_hour
8  INTEGER :: irr_on_time, irr_on_day, tloc, xt24
9  INTEGER, INTENT(OUT):: irr_on
11  irr_on_day = 0
12  irr_on_time = 0
13  irr_on = 0
15  xt24=mod(xtime,1440.)
16  tloc=floor(gmt+xt24/60.)
17  if(tloc.lt.0) tloc=tloc+24
19  IF(irr_start_julianday .lt. irr_end_julianday) THEN
20    IF((julian_in.GE.irr_start_julianday .AND. julian_in.LT.irr_end_julianday))  THEN
21       irr_on_day=1
22    END IF
23  ELSE
24    IF(.NOT. (julian_in.GE.irr_start_julianday .AND. julian_in.LT.irr_end_julianday))  THEN
25       irr_on_day = 1
26    END IF
27  END IF 
29  IF(irr_start_hour .lt. end_hour) THEN
30    IF((tloc.GE.irr_start_hour .AND. tloc.LT.end_hour))  THEN
31       irr_on_time=1
32    END IF
33  ELSE
34    IF(.NOT. (tloc.GE.irr_start_hour .AND. tloc.LT.end_hour))  THEN
35       irr_on_time = 1
36    END IF
37  END IF
38  IF (irr_on_time.EQ.1 .and. irr_on_day.EQ.1)  irr_on = 1
40 RETURN
41 END SUBROUTINE irrigation_on
43 SUBROUTINE irr_calc_phase(irr_ph,phase,irr_rand_field_val,i,j,IRRIGATION,irr_freq)
44   IMPLICIT NONE
45   INTEGER :: irr_ph,irr_freq
46   REAL, INTENT(OUT) :: phase
47   REAL, OPTIONAL::   IRRIGATION
48   INTEGER, OPTIONAL     :: i,j
50   INTEGER, INTENT(INOUT) :: irr_rand_field_val
51    IF(irr_ph .EQ. 1)phase=modulo(int(i*j*IRRIGATION),irr_freq)
52    IF(irr_ph .EQ. 0)phase=0 
53    IF(irr_ph .EQ. 2)phase=irr_rand_field_val
54  RETURN
55 END SUBROUTINE irr_calc_phase
58   SUBROUTINE drip_irrigation( julian_in                               & 
59      &          ,irrigation,sf_surf_irr_scheme, irr_daily_amount      &    
60      &          ,irr_start_hour,irr_num_hours,irr_start_julianday     & 
61      &          ,irr_end_julianday,irr_freq,irr_ph                    & 
62      &          ,i,j,RAINBL,IRRIGATION_CHANNEL,gmt,xtime,dt,irr_rand_field_val )
63    IMPLICIT NONE
64  !declarations
65    REAL:: dt,xtime,gmt
66    INTEGER :: j,i,tloc, jmonth,timing,end_hour,irr_day, sf_surf_irr_scheme,irr_start_hour,irr_num_hours,irr_start_julianday,irr_end_julianday,irr_freq,irr_ph,irr_on
67    REAL :: constants_irrigation,phase
68    REAL, INTENT(INOUT) :: IRRIGATION_CHANNEL
69    REAL, INTENT(INOUT) :: RAINBL
70    REAL, INTENT(IN)::  IRRIGATION
71    REAL::  irr_daily_amount
72    REAL, INTENT(IN) :: julian_in
73    INTEGER, INTENT(INOUT) :: irr_rand_field_val
74   IRRIGATION_CHANNEL=0.
75   IF(RAINBL.LE.0.01 .AND. IRRIGATION.GE.0.001) THEN
76    end_hour=irr_start_hour+irr_num_hours   
77    if(end_hour.gt.23) end_hour=end_hour-24
78    constants_irrigation=irr_freq*irr_daily_amount*0.000277778*0.01/irr_num_hours  ! hours in second:1/3600=0.000277778 
79    phase=0.
80    timing=modulo((int(julian_in)-irr_start_julianday),irr_freq)
81    CALL irr_calc_phase(irr_ph,phase,irr_rand_field_val,i,j,IRRIGATION,irr_freq)
82    CALL irrigation_on(julian_in,irr_start_julianday,irr_end_julianday,irr_on,xtime,gmt,irr_start_hour,end_hour)
83    PRINT*,irr_on
84    IRRIGATION_CHANNEL=0.
85    IF ( irr_on.EQ.1 .AND. timing.EQ.0.  ) THEN
86        IF(irr_ph.EQ.0) THEN
87           RAINBL =RAINBL +dt*IRRIGATION*constants_irrigation
88           IRRIGATION_CHANNEL=0.
89        ELSE
90           IF(timing.EQ.int(phase)) THEN
91            RAINBL =RAINBL +dt*IRRIGATION*constants_irrigation
92           ELSE
93            IRRIGATION_CHANNEL=0.
94           ENDIF
95        ENDIF
96    ENDIF
97  ENDIF
98 RETURN
99 END SUBROUTINE drip_irrigation
103 SUBROUTINE channel_irrigation(  julian_in                             & !ARI
104      &          ,irrigation,sf_surf_irr_scheme, irr_daily_amount      & !ARI   
105      &          ,irr_start_hour,irr_num_hours,irr_start_julianday     & !ARI
106      &          ,irr_end_julianday,irr_freq,irr_ph                    &
107      &          ,i,j,RAINBL,IRRIGATION_CHANNEL,gmt,xtime,dt,irr_rand_field_val )
108    IMPLICIT NONE
109  !declarations
110    REAL:: dt,xtime,gmt
111    INTEGER :: j,i,tloc, jmonth,timing,end_hour, irr_on, irr_day, sf_surf_irr_scheme,irr_start_hour,irr_num_hours,irr_start_julianday,irr_end_julianday,irr_freq,irr_ph
112    REAL :: constants_irrigation,phase
113    REAL, INTENT(INOUT) :: IRRIGATION_CHANNEL
114    REAL, INTENT(INOUT) :: RAINBL
115    REAL, INTENT(IN)::  IRRIGATION
116    REAL::  irr_daily_amount
117    REAL, INTENT(IN) :: julian_in
118    INTEGER, INTENT(INOUT) :: irr_rand_field_val
119   IRRIGATION_CHANNEL=0.
120   IF(RAINBL.LE.0.01 .AND. IRRIGATION.GE.0.001) THEN
121    end_hour=irr_start_hour+irr_num_hours
122    if(end_hour.gt.23) end_hour=end_hour-24
123    constants_irrigation=irr_freq*irr_daily_amount*0.000277778*0.01/irr_num_hours  ! hours in second:1/3600=0.000277778 
124    phase=0.
125    timing=modulo((int(julian_in)-irr_start_julianday),irr_freq)
126    CALL irr_calc_phase(irr_ph,phase,irr_rand_field_val,i,j,IRRIGATION,irr_freq)
127    CALL irrigation_on(julian_in,irr_start_julianday,irr_end_julianday,irr_on,xtime,gmt,irr_start_hour,end_hour)
128    IRRIGATION_CHANNEL=0.
129    IF ( irr_on.eq.1 .AND. timing.EQ.0.  ) THEN
130      IF(irr_ph.EQ.0) THEN
131              IRRIGATION_CHANNEL=dt*IRRIGATION*constants_irrigation
132      ELSE
133              IF(timing.EQ.int(phase)) THEN
134                   IRRIGATION_CHANNEL=dt*IRRIGATION*constants_irrigation
135              ELSE
136                   IRRIGATION_CHANNEL=0.
137              ENDIF
138      ENDIF
139    ELSE
140      IRRIGATION_CHANNEL=0.
141    ENDIF
142  ENDIF
143 RETURN
144 END SUBROUTINE channel_irrigation
147 SUBROUTINE sprinkler_irrigation(  julian_in                                           &
148      &          ,irrigation, irr_daily_amount,rho,dz8w                                &    
149      &          ,irr_start_hour,irr_num_hours,irr_start_julianday,irr_end_julianday   &
150      &          ,irr_freq,irr_ph,qr_curr                                              &
151      &          ,gmt,xtime,dt,irr_rand_field_val                                      &
152      &          ,ids,ide, jds,jde                                                     & ! domain dims
153      &          ,ims,ime, jms,jme, kms,kme                                            & ! memory dims
154      &          ,its,ite, jts,jte               ) ! tile   dims
155                                                            
157    IMPLICIT NONE
158    INTEGER,      INTENT(IN   )    :: ids,ide, jds,jde,  &
159                                      ims,ime, jms,jme, kms,kme, &
160                                      its,ite, jts,jte 
162    REAL,  DIMENSION( ims:ime , jms:jme ), INTENT(IN),OPTIONAL:: irrigation !ARI
163    REAL,  INTENT(IN)::  irr_daily_amount, xtime, gmt, julian_in
164    INTEGER, INTENT(IN ),OPTIONAL::  irr_start_hour, irr_num_hours,irr_start_julianday,irr_freq,irr_ph,irr_end_julianday
165    INTEGER  :: end_hour,a,b,irr_day,timing,irr_on
166    REAL :: constants_irrigation,tloc,irr_start,phase
167    INTEGER, DIMENSION( ims:ime , jms:jme ), INTENT(INOUT):: irr_rand_field_val
168    REAL, DIMENSION( ims:ime , kms:kme , jms:jme ),              &
169          INTENT(IN   ) ::                                       &
170                                                            rho, &
171                                                           dz8w
172    REAL, DIMENSION( ims:ime , kms:kme , jms:jme ),              &
173          INTENT(INOUT) ::                                       &
174                                                         qr_curr
175    REAL, INTENT(IN   ) :: dt
176    end_hour=irr_start_hour+irr_num_hours
177    if(end_hour.gt.23) end_hour=end_hour-24
178    CALL irrigation_on(julian_in,irr_start_julianday,irr_end_julianday,irr_on,xtime,gmt,irr_start_hour,end_hour)
181    timing=modulo((int(julian_in)),irr_freq)
182    DO a=its, ite
183      DO b=jts,jte
185       constants_irrigation=irr_freq*irr_daily_amount/(irr_num_hours*3600*rho(a,kms,b)*dz8w(a,kms,b)*100)
186       IF (irrigation(a,b).GE.0.1 .AND. irr_on.eq.1 ) THEN
187         CALL irr_calc_phase(irr_ph,phase,irr_rand_field_val(a,b),a,b,irrigation(a,b),irr_freq)
188         IF(irr_ph.EQ.0) THEN
189               qr_curr(a,kms,b)=qr_curr(a,kms,b)+irrigation(a,b)*constants_irrigation*dt
190         ELSE
191               IF(timing.EQ.int(phase))  THEN
192                    qr_curr(a,kms,b)=qr_curr(a,kms,b)+irrigation(a,b)*constants_irrigation*dt
193               END IF
194         END IF
195       END IF
196     END DO
197    END DO
199 RETURN
201 END SUBROUTINE sprinkler_irrigation
202 END MODULE module_irrigation