source: LMDZ.3.3/branches/rel-LF/libf/phylmd/isccp_cloud_types.F @ 466

Last change on this file since 466 was 466, checked in by (none), 21 years ago

This commit was manufactured by cvs2svn to create branch 'rel-LF'.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 53.6 KB
Line 
1      SUBROUTINE ISCCP_CLOUD_TYPES(
2     &     debug,
3     &     debugcol,
4     &     npoints,
5     &     sunlit,
6     &     nlev,
7     &     ncol,
8     &     seed,
9     &     pfull,
10     &     phalf,
11     &     qv,
12     &     cc,
13     &     conv,
14     &     dtau_s,
15     &     dtau_c,
16     &     top_height,
17     &     overlap,
18     &     tautab,
19     &     invtau,
20     &     skt,
21     &     emsfc_lw,
22     &     at,dem_s,dem_c,
23     &     fq_isccp,
24     &     totalcldarea,
25     &     meanptop,
26     &     meantaucld,
27     &     boxtau,
28     &     boxptop
29     &)
30       
31!$Id: isccp_cloud_types.F 466 2003-08-06 14:50:49Z None $
32
33! Copyright Steve Klein and Mark Webb 2002 - all rights reserved.
34!
35! This code is available without charge with the following conditions:
36!
37!  1. The code is available for scientific purposes and is not for
38!     commercial use.
39!  2. Any improvements you make to the code should be made available
40!     to the to the authors for incorporation into a future release.
41!  3. The code should not be used in any way that brings the authors
42!     or their employers into disrepute.
43
44      implicit none
45
46!     NOTE:   the maximum number of levels and columns is set by
47!             the following parameter statement
48
49      INTEGER ncolprint
50     
51!     -----
52!     Input
53!     -----
54
55      INTEGER npoints                   !  number of model points in the horizontal
56c      PARAMETER(npoints=6722)
57      INTEGER nlev                      !  number of model levels in column
58      INTEGER ncol                      !  number of subcolumns
59
60      INTEGER sunlit(npoints)           !  1 for day points, 0 for night time
61
62      INTEGER seed(npoints)             !  seed value for random number generator
63c                                       !  ( see Numerical Recipes Chapter 7)
64c                                       !  It is recommended that the seed is set
65c                                       !  to a different value for each model
66c                                       !  gridbox it is called on, as it is
67c                                       !  possible that the choice of the samec
68c                                       !  seed value every time may introduce some
69c                                       !  statistical bias in the results, particularly
70c                                       !  for low values of NCOL.
71c
72      REAL pfull(npoints,nlev)          !  pressure of full model levels (Pascals)
73c                                        !  pfull(npoints,1)    is    top level of model
74c                                        !  pfull(npoints,nlev) is bottom level of model
75
76      REAL phalf(npoints,nlev+1)        !  pressure of half model levels (Pascals)
77c                                        !  phalf(npoints,1)    is    top       of model
78c                                        !  phalf(npoints,nlev+1) is the surface pressure
79
80      REAL qv(npoints,nlev)             !  water vapor specific humidity (kg vapor/ kg air)
81c                                        !         on full model levels
82
83      REAL cc(npoints,nlev)             !  input cloud cover in each model level (fraction)
84c                                        !  NOTE:  This is the HORIZONTAL area of each
85c                                        !         grid box covered by clouds
86
87      REAL conv(npoints,nlev)           !  input convective cloud cover in each model level (fraction)
88c                                        !  NOTE:  This is the HORIZONTAL area of each
89c                                        !         grid box covered by convective clouds
90
91      REAL dtau_s(npoints,nlev)         !  mean 0.67 micron optical depth of stratiform
92c                                       !  clouds in each model level
93c                                        !  NOTE:  this the cloud optical depth of only the
94c                                        !         cloudy part of the grid box, it is not weighted
95c                                        !         with the 0 cloud optical depth of the clear
96c                                        !         part of the grid box
97
98      REAL dtau_c(npoints,nlev)         !  mean 0.67 micron optical depth of convective
99c                                       !  clouds in each
100c                                        !  model level.  Same note applies as in dtau_s.
101
102      INTEGER overlap                   !  overlap type
103                                       
104!  1=max
105                                       
106!  2=rand
107!  3=max/rand
108
109      INTEGER top_height                !  1 = adjust top height using both a computed
110c                                        !  infrared brightness temperature and the visible
111c                                       !  optical depth to adjust cloud top pressure. Note
112c                                       !  that this calculation is most appropriate to compare
113c                                       !  to ISCCP data during sunlit hours.
114c                                        !  2 = do not adjust top height, that is cloud top
115c                                        !  pressure is the actual cloud top pressure
116c                                        !  in the model
117c                                       !  3 = adjust top height using only the computed
118c                                       !  infrared brightness temperature. Note that this
119c                                       !  calculation is most appropriate to compare to ISCCP
120c                                       !  IR only algortihm (i.e. you can compare to nighttime
121c                                       !  ISCCP data with this option)
122
123      REAL tautab(0:255)                !  ISCCP table for converting count value to
124c                                        !  optical thickness
125
126      INTEGER invtau(-20:45000)         !  ISCCP table for converting optical thickness
127c                                        !  to count value
128!
129!     The following input variables are used only if top_height = 1 or top_height = 3
130!
131      REAL skt(npoints)                 !  skin Temperature (K)
132      REAL emsfc_lw                     !  10.5 micron emissivity of surface (fraction)                                           
133      REAL at(npoints,nlev)                   !  temperature in each model level (K)
134      REAL dem_s(npoints,nlev)                !  10.5 micron longwave emissivity of stratiform
135c                                       !  clouds in each
136c                                        !  model level.  Same note applies as in dtau_s.
137      REAL dem_c(npoints,nlev)                  !  10.5 micron longwave emissivity of convective
138c                                       !  clouds in each
139c                                        !  model level.  Same note applies as in dtau_s.
140cIM reg.dyn BEG
141      REAL t1, t2
142!     REAL w(npoints)                   !vertical wind at 500 hPa
143!     LOGICAL pct_ocean(npoints)        !TRUE if oceanic point, FALSE otherway
144!     INTEGER iw(npoints) , nw
145!     REAL wmin, pas_w
146!     INTEGER k, l, iwmx
147!     PARAMETER(wmin=-100.,pas_w=10.,iwmx=30)
148!     REAL fq_dynreg(7,7,iwmx)
149!     REAL nfq_dynreg(7,7,iwmx)
150!     LOGICAL pctj(7,7,iwmx)
151cIM reg.dyn END
152!     ------
153!     Output
154!     ------
155
156      REAL fq_isccp(npoints,7,7)        !  the fraction of the model grid box covered by
157c                                        !  each of the 49 ISCCP D level cloud types
158
159      REAL totalcldarea(npoints)        !  the fraction of model grid box columns
160c                                        !  with cloud somewhere in them.  This should
161c                                       !  equal the sum over all entries of fq_isccp
162       
163       
164c      ! The following three means are averages over the cloudy areas only.  If no
165c      ! clouds are in grid box all three quantities should equal zero.
166                                       
167      REAL meanptop(npoints)            !  mean cloud top pressure (mb) - linear averaging
168c                                        !  in cloud top pressure.
169                                       
170      REAL meantaucld(npoints)          !  mean optical thickness
171c                                        !  linear averaging in albedo performed.
172     
173      REAL boxtau(npoints,ncol)         !  optical thickness in each column
174     
175      REAL boxptop(npoints,ncol)        !  cloud top pressure (mb) in each column
176                                       
177                                                                                                                       
178!
179!     ------
180!     Working variables added when program updated to mimic Mark Webb's PV-Wave code
181!     ------
182
183      REAL frac_out(npoints,ncol,nlev) ! boxes gridbox divided up into
184c                                       ! Equivalent of BOX in original version, but
185c                                       ! indexed by column then row, rather than
186c                                       ! by row then column
187
188      REAL tca(npoints,0:nlev) ! total cloud cover in each model level (fraction)
189c                                        ! with extra layer of zeroes on top
190c                                        ! in this version this just contains the values input
191c                                        ! from cc but with an extra level
192      REAL cca(npoints,nlev)         ! convective cloud cover in each model level (fraction)
193c                                        ! from conv
194
195      REAL threshold(npoints,ncol)   ! pointer to position in gridbox
196      REAL maxocc(npoints,ncol)      ! Flag for max overlapped conv cld
197      REAL maxosc(npoints,ncol)      ! Flag for max overlapped strat cld
198
199      REAL boxpos(npoints,ncol)      ! ordered pointer to position in gridbox
200
201      REAL threshold_min(npoints,ncol) ! minimum value to define range in with new threshold
202c                                        ! is chosen
203
204      REAL dem(npoints,ncol),bb(npoints)     !  working variables for 10.5 micron longwave
205c                                       !  emissivity in part of
206c                                       !  gridbox under consideration
207
208      REAL ran(npoints)                 ! vector of random numbers
209      REAL ptrop(npoints)
210      REAL attrop(npoints)
211      REAL attropmin (npoints)
212      REAL atmax(npoints)
213      REAL atmin(npoints)
214      REAL btcmin(npoints)
215      REAL transmax(npoints)
216
217      INTEGER i,j,ilev,ibox,itrop(npoints)
218      INTEGER ipres(npoints)
219      INTEGER itau(npoints),ilev2
220      INTEGER acc(nlev,ncol)
221      INTEGER match(npoints,nlev-1)
222      INTEGER nmatch(npoints)
223      INTEGER levmatch(npoints,ncol)
224     
225c      !variables needed for water vapor continuum absorption
226      real fluxtop_clrsky(npoints),trans_layers_above_clrsky(npoints)
227      real taumin(npoints)
228      real dem_wv(npoints,nlev), wtmair, wtmh20, Navo, grav, pstd, t0
229      real press(npoints), dpress(npoints), atmden(npoints)
230      real rvh20(npoints), wk(npoints), rhoave(npoints)
231      real rh20s(npoints), rfrgn(npoints)
232      real tmpexp(npoints),tauwv(npoints)
233     
234      character*1 cchar(6),cchar_realtops(6)
235      integer icycle
236      REAL tau(npoints,ncol)
237      LOGICAL box_cloudy(npoints,ncol)
238      REAL tb(npoints,ncol)
239      REAL ptop(npoints,ncol)
240      REAL emcld(npoints,ncol)
241      REAL fluxtop(npoints,ncol)
242      REAL trans_layers_above(npoints,ncol)
243      real isccp_taumin,fluxtopinit(npoints),tauir(npoints)
244      real meanalbedocld(npoints)
245      REAL albedocld(npoints,ncol)
246      real boxarea
247      integer debug       ! set to non-zero value to print out inputs
248c                         ! with step debug
249      integer debugcol    ! set to non-zero value to print out column
250c                         ! decomposition with step debugcol
251
252      integer index1(npoints),num1,jj
253      real rec2p13,tauchk
254
255      character*10 ftn09
256     
257      DATA isccp_taumin / 0.3 /
258      DATA cchar / ' ','-','1','+','I','+'/
259      DATA cchar_realtops / ' ',' ','1','1','I','I'/
260
261      tauchk = -1.*log(0.9999999)
262      rec2p13=1./2.13
263
264      ncolprint=0
265
266cIM
267c     PRINT*,' isccp_cloud_types npoints=',npoints
268c
269c      if ( debug.ne.0 ) then
270c          j=1
271c          write(6,'(a10)') 'j='
272c          write(6,'(8I10)') j
273c          write(6,'(a10)') 'debug='
274c          write(6,'(8I10)') debug
275c          write(6,'(a10)') 'debugcol='
276c          write(6,'(8I10)') debugcol
277c          write(6,'(a10)') 'npoints='
278c          write(6,'(8I10)') npoints
279c          write(6,'(a10)') 'nlev='
280c          write(6,'(8I10)') nlev
281c          write(6,'(a10)') 'ncol='
282c          write(6,'(8I10)') ncol
283           write(6,'(a10)') 'top_height='
284           write(6,'(8I10)') top_height
285           write(6,'(a10)') 'overlap='
286           write(6,'(8I10)') overlap
287c          write(6,'(a10)') 'emsfc_lw='
288c          write(6,'(8f10.2)') emsfc_lw
289c          write(6,'(a10)') 'tautab='
290c          write(6,'(8f10.2)') tautab
291c          write(6,'(a10)') 'invtau(1:100)='
292c          write(6,'(8i10)') (invtau(i),i=1,100)
293c         do j=1,npoints,debug
294c          write(6,'(a10)') 'j='
295c          write(6,'(8I10)') j
296c          write(6,'(a10)') 'sunlit='
297c          write(6,'(8I10)') sunlit(j)
298c          write(6,'(a10)') 'seed='
299c          write(6,'(8I10)') seed(j)
300c          write(6,'(a10)') 'pfull='
301c          write(6,'(8f10.2)') (pfull(j,i),i=1,nlev)
302c          write(6,'(a10)') 'phalf='
303c          write(6,'(8f10.2)') (phalf(j,i),i=1,nlev+1)
304c          write(6,'(a10)') 'qv='
305c          write(6,'(8f10.3)') (qv(j,i),i=1,nlev)
306c          write(6,'(a10)') 'cc='
307c          write(6,'(8f10.3)') (cc(j,i),i=1,nlev)
308c          write(6,'(a10)') 'conv='
309c          write(6,'(8f10.2)') (conv(j,i),i=1,nlev)
310c          write(6,'(a10)') 'dtau_s='
311c          write(6,'(8g12.5)') (dtau_s(j,i),i=1,nlev)
312c          write(6,'(a10)') 'dtau_c='
313c          write(6,'(8f10.2)') (dtau_c(j,i),i=1,nlev)
314c          write(6,'(a10)') 'skt='
315c          write(6,'(8f10.2)') skt(j)
316c          write(6,'(a10)') 'at='
317c          write(6,'(8f10.2)') (at(j,i),i=1,nlev)
318c          write(6,'(a10)') 'dem_s='
319c          write(6,'(8f10.3)') (dem_s(j,i),i=1,nlev)
320c          write(6,'(a10)') 'dem_c='
321c          write(6,'(8f10.2)') (dem_c(j,i),i=1,nlev)
322c         enddo
323c      endif
324
325!     ---------------------------------------------------!
326
327!     assign 2d tca array using 1d input array cc
328
329      do j=1,npoints
330        tca(j,0)=0
331      enddo
332 
333      do ilev=1,nlev
334        do j=1,npoints
335          tca(j,ilev)=cc(j,ilev)
336        enddo
337      enddo
338
339!     assign 2d cca array using 1d input array conv
340
341      do ilev=1,nlev
342cIM pas besoin        do ibox=1,ncol
343          do j=1,npoints
344            cca(j,ilev)=conv(j,ilev)
345          enddo
346cIM        enddo
347      enddo
348
349cIM
350!     do j=1, iwmx
351!     do l=1, 7
352!     do k=1, 7
353!       fq_dynreg(k,l,j) =0.
354!       nfq_dynreg(k,l,j) =0.
355!      enddo !k
356!     enddo !l
357!     enddo !j
358cIM
359cIM
360c      if (ncolprint.ne.0) then
361c       do j=1,npoints,1000
362c        write(6,'(a10)') 'j='
363c        write(6,'(8I10)') j
364c        write (6,'(a)') 'seed:'
365c        write (6,'(I3.2)') seed(j)
366
367c        write (6,'(a)') 'tca_pp_rev:'
368c        write (6,'(8f5.2)')
369c     &   ((tca(j,ilev)),
370c     &      ilev=1,nlev)
371
372c        write (6,'(a)') 'cca_pp_rev:'
373c        write (6,'(8f5.2)')
374c     &   ((cca(j,ilev),ibox=1,ncolprint),ilev=1,nlev)
375c       enddo
376c      endif
377
378      if (top_height .eq. 1 .or. top_height .eq. 3) then
379
380      do j=1,npoints
381          ptrop(j)=5000.
382          atmin(j) = 400.
383          attropmin(j) = 400.
384          atmax(j) = 0.
385          attrop(j) = 120.
386          itrop(j) = 1
387      enddo
388
389      do 12 ilev=1,nlev
390        do j=1,npoints
391         if (pfull(j,ilev) .lt. 40000. .and.
392     &          pfull(j,ilev) .gt.  5000. .and.
393     &          at(j,ilev) .lt. attropmin(j)) then
394                ptrop(j) = pfull(j,ilev)
395                attropmin(j) = at(j,ilev)
396                attrop(j) = attropmin(j)
397                itrop(j)=ilev
398           end if
399           if (at(j,ilev) .gt. atmax(j)) atmax(j)=at(j,ilev)
400           if (at(j,ilev) .lt. atmin(j)) atmin(j)=at(j,ilev)
401        enddo
40212    continue
403
404      end if
405
406!     -----------------------------------------------------!
407
408!     ---------------------------------------------------!
409
410cIM
411c     do 13 ilev=1,nlev
412cnum1=0
413c       do j=1,npoints
414c           if (cc(j,ilev) .lt. 0. .or. cc(j,ilev) .gt. 1.) then
415c       num1=num1+1
416c       index1(num1)=j
417c           end if
418c       enddo
419c       do jj=1,num1   
420c       j=index1(jj)
421c               write(6,*)  ' error = cloud fraction less than zero'
422c       write(6,*) ' or '
423c               write(6,*)  ' error = cloud fraction greater than 1'
424c       write(6,*) 'value at point ',j,' is ',cc(j,ilev)
425c       write(6,*) 'level ',ilev
426c               STOP
427c       enddo
428cnum1=0
429c       do j=1,npoints
430c           if (conv(j,ilev) .lt. 0. .or. conv(j,ilev) .gt. 1.) then
431c       num1=num1+1
432c       index1(num1)=j
433c           end if
434c       enddo
435c       do jj=1,num1   
436c       j=index1(jj)
437c               write(6,*) 
438c    &           ' error = convective cloud fraction less than zero'
439c       write(6,*) ' or '
440c               write(6,*) 
441c    &           ' error = convective cloud fraction greater than 1'
442c       write(6,*) 'value at point ',j,' is ',conv(j,ilev)
443c       write(6,*) 'level ',ilev
444c               STOP
445c       enddo
446
447cnum1=0
448c       do j=1,npoints
449c           if (dtau_s(j,ilev) .lt. 0.) then
450c       num1=num1+1
451c       index1(num1)=j
452c           end if
453c       enddo
454c       do jj=1,num1   
455c       j=index1(jj)
456c               write(6,*) 
457c    &           ' error = stratiform cloud opt. depth less than zero'
458c       write(6,*) 'value at point ',j,' is ',dtau_s(j,ilev)
459c       write(6,*) 'level ',ilev
460c               STOP
461c       enddo
462cnum1=0
463c       do j=1,npoints
464c           if (dtau_c(j,ilev) .lt. 0.) then
465c       num1=num1+1
466c       index1(num1)=j
467c           end if
468c       enddo
469c       do jj=1,num1   
470c       j=index1(jj)
471c               write(6,*) 
472c    &           ' error = convective cloud opt. depth less than zero'
473c       write(6,*) 'value at point ',j,' is ',dtau_c(j,ilev)
474c       write(6,*) 'level ',ilev
475c               STOP
476c       enddo
477
478cnum1=0
479c       do j=1,npoints
480c           if (dem_s(j,ilev) .lt. 0. .or. dem_s(j,ilev) .gt. 1.) then
481c       num1=num1+1
482c       index1(num1)=j
483c           end if
484c       enddo
485c       do jj=1,num1   
486c       j=index1(jj)
487c               write(6,*) 
488c    &           ' error = stratiform cloud emissivity less than zero'
489c       write(6,*)'or'
490c               write(6,*) 
491c    &           ' error = stratiform cloud emissivity greater than 1'
492c       write(6,*) 'value at point ',j,' is ',dem_s(j,ilev)
493c       write(6,*) 'level ',ilev
494c               STOP
495c       enddo
496
497cnum1=0
498c       do j=1,npoints
499c           if (dem_c(j,ilev) .lt. 0. .or. dem_c(j,ilev) .gt. 1.) then
500c       num1=num1+1
501c       index1(num1)=j
502c           end if
503c       enddo
504c       do jj=1,num1   
505c       j=index1(jj)
506c               write(6,*) 
507c    &           ' error = convective cloud emissivity less than zero'
508c       write(6,*)'or'
509c               write(6,*) 
510c    &           ' error = convective cloud emissivity greater than 1'
511c               write (6,*)
512c    &          'j=',j,'ilev=',ilev,'dem_c(j,ilev) =',dem_c(j,ilev)
513c               STOP
514c       enddo
515c13    continue
516
517
518      do ibox=1,ncol
519        do j=1,npoints
520          boxpos(j,ibox)=(ibox-.5)/ncol
521        enddo
522      enddo
523
524!     ---------------------------------------------------!
525!     Initialise working variables
526!     ---------------------------------------------------!
527
528!     Initialised frac_out to zero
529
530      do ibox=1,ncol
531        do ilev=1,nlev
532          do j=1,npoints
533            frac_out(j,ibox,ilev)=0.0
534          enddo
535        enddo
536      enddo
537
538cIM
539c      if (ncolprint.ne.0) then
540c        write (6,'(a)') 'frac_out_pp_rev:'
541c          do j=1,npoints,1000
542c          write(6,'(a10)') 'j='
543c          write(6,'(8I10)') j
544c          write (6,'(8f5.2)')
545c     &     ((frac_out(j,ibox,ilev),ibox=1,ncolprint),ilev=1,nlev)
546
547c          enddo
548c        write (6,'(a)') 'ncol:'
549c        write (6,'(I3)') ncol
550c      endif
551c      if (ncolprint.ne.0) then
552c        write (6,'(a)') 'last_frac_pp:'
553c          do j=1,npoints,1000
554c          write(6,'(a10)') 'j='
555c          write(6,'(8I10)') j
556c          write (6,'(8f5.2)') (tca(j,0))
557c          enddo
558c      endif
559
560!     ---------------------------------------------------!
561!     ALLOCATE CLOUD INTO BOXES, FOR NCOLUMNS, NLEVELS
562!     frac_out is the array that contains the information
563!     where 0 is no cloud, 1 is a stratiform cloud and 2 is a
564!     convective cloud
565     
566      !loop over vertical levels
567      DO 200 ilev = 1,nlev
568                                 
569!     Initialise threshold
570
571        IF (ilev.eq.1) then
572            ! If max overlap
573            IF (overlap.eq.1) then
574              ! select pixels spread evenly
575              ! across the gridbox
576              DO ibox=1,ncol
577                do j=1,npoints
578                  threshold(j,ibox)=boxpos(j,ibox)
579                enddo
580              enddo
581            ELSE
582              DO ibox=1,ncol
583                call ran0_vec(npoints,seed,ran)
584                ! select random pixels from the non-convective
585                ! part the gridbox ( some will be converted into
586                ! convective pixels below )
587                do j=1,npoints
588                  threshold(j,ibox)=
589     &            cca(j,ilev)+(1-cca(j,ilev))*ran(j)
590                enddo
591              enddo
592            ENDIF
593cIM
594c            IF (ncolprint.ne.0) then
595c              write (6,'(a)') 'threshold_nsf2:'
596c                do j=1,npoints,1000
597c                write(6,'(a10)') 'j='
598c                write(6,'(8I10)') j
599c                write (6,'(8f5.2)') (threshold(j,ibox),ibox=1,ncolprint)
600c                enddo
601c            ENDIF
602        ENDIF
603
604c        IF (ncolprint.ne.0) then
605c            write (6,'(a)') 'ilev:'
606c            write (6,'(I2)') ilev
607c        ENDIF
608
609        DO ibox=1,ncol
610
611          ! All versions
612          do j=1,npoints
613            if (boxpos(j,ibox).le.cca(j,ilev)) then
614cIM REAL           maxocc(j,ibox) = 1
615              maxocc(j,ibox) = 1.0
616            else
617cIM REAL           maxocc(j,ibox) = 0
618              maxocc(j,ibox) = 0.0
619            end if
620          enddo
621
622          ! Max overlap
623          if (overlap.eq.1) then
624            do j=1,npoints
625              threshold_min(j,ibox)=cca(j,ilev)
626cIM REAL           maxosc(j,ibox)=1
627              maxosc(j,ibox)=1.0
628            enddo
629          endif
630
631          ! Random overlap
632          if (overlap.eq.2) then
633            do j=1,npoints
634              threshold_min(j,ibox)=cca(j,ilev)
635cIM REAL           maxosc(j,ibox)=0
636              maxosc(j,ibox)=0.0
637            enddo
638          endif
639
640          ! Max/Random overlap
641          if (overlap.eq.3) then
642            do j=1,npoints
643              threshold_min(j,ibox)=max(cca(j,ilev),
644     &          min(tca(j,ilev-1),tca(j,ilev)))
645              if (threshold(j,ibox)
646     &          .lt.min(tca(j,ilev-1),tca(j,ilev))
647     &          .and.(threshold(j,ibox).gt.cca(j,ilev))) then
648cIM REAL                maxosc(j,ibox)= 1
649                   maxosc(j,ibox)= 1.0
650              else
651cIM REAL                 maxosc(j,ibox)= 0
652                   maxosc(j,ibox)= 0.0
653              end if
654            enddo
655          endif
656   
657          ! Reset threshold
658
659cIM pas besoin..memes val. de ran!     
660c         call ran0_vec(npoints,seed,ran)
661           
662          do j=1,npoints
663            threshold(j,ibox)=
664              !if max overlapped conv cloud
665     &        maxocc(j,ibox) * (                                       
666     &            boxpos(j,ibox)                                               
667     &        ) +                                                     
668              !else
669     &        (1-maxocc(j,ibox)) * (                                   
670                  !if max overlapped strat cloud
671     &            (maxosc(j,ibox)) * (                                 
672                      !threshold=boxpos
673     &                threshold(j,ibox)                                       
674     &            ) +                                                 
675                  !else
676     &            (1-maxosc(j,ibox)) * (                               
677                      !threshold_min=random[thrmin,1]
678     &                threshold_min(j,ibox)+
679     &                  (1-threshold_min(j,ibox))*ran(j) 
680     &           )
681     &        )
682          enddo
683
684        ENDDO ! ibox
685
686!          Fill frac_out with 1's where tca is greater than the threshold
687
688           DO ibox=1,ncol
689             do j=1,npoints
690               if (tca(j,ilev).gt.threshold(j,ibox)) then
691cIM REAL             frac_out(j,ibox,ilev)=1
692               frac_out(j,ibox,ilev)=1.0
693               else
694cIM REAL             frac_out(j,ibox,ilev)=0
695               frac_out(j,ibox,ilev)=0.0
696               end if               
697             enddo
698           ENDDO
699
700!          Code to partition boxes into startiform and convective parts
701!          goes here
702
703           DO ibox=1,ncol
704             do j=1,npoints
705                if (threshold(j,ibox).le.cca(j,ilev)) then
706                    ! = 2 IF threshold le cca(j)
707cIM REAL                  frac_out(j,ibox,ilev) = 2
708                    frac_out(j,ibox,ilev) = 2.0
709                else
710                    ! = the same IF NOT threshold le cca(j)
711                    frac_out(j,ibox,ilev) = frac_out(j,ibox,ilev)
712                end if
713             enddo
714           ENDDO
715
716!         Set last_frac to tca at this level, so as to be tca
717!         from last level next time round
718
719cIM
720c          if (ncolprint.ne.0) then
721
722c            do j=1,npoints ,1000
723c            write(6,'(a10)') 'j='
724c            write(6,'(8I10)') j
725c            write (6,'(a)') 'last_frac:'
726c            write (6,'(8f5.2)') (tca(j,ilev-1))
727   
728c            write (6,'(a)') 'cca:'
729c            write (6,'(8f5.2)') (cca(j,ilev),ibox=1,ncolprint)
730   
731c            write (6,'(a)') 'max_overlap_cc:'
732c            write (6,'(8f5.2)') (maxocc(j,ibox),ibox=1,ncolprint)
733   
734c            write (6,'(a)') 'max_overlap_sc:'
735c            write (6,'(8f5.2)') (maxosc(j,ibox),ibox=1,ncolprint)
736   
737c            write (6,'(a)') 'threshold_min_nsf2:'
738c            write (6,'(8f5.2)') (threshold_min(j,ibox),ibox=1,ncolprint)
739   
740c            write (6,'(a)') 'threshold_nsf2:'
741c            write (6,'(8f5.2)') (threshold(j,ibox),ibox=1,ncolprint)
742   
743c            write (6,'(a)') 'frac_out_pp_rev:'
744c            write (6,'(8f5.2)')
745c     &       ((frac_out(j,ibox,ilev2),ibox=1,ncolprint),ilev2=1,nlev)
746c           enddo
747c          endif
748
749200   CONTINUE    !loop over nlev
750
751!
752!     ---------------------------------------------------!
753
754     
755!
756!     ---------------------------------------------------!
757!     COMPUTE CLOUD OPTICAL DEPTH FOR EACH COLUMN and
758!     put into vector tau
759 
760      !initialize tau and albedocld to zero
761      do 15 ibox=1,ncol
762        do j=1,npoints
763            tau(j,ibox)=0.
764            albedocld(j,ibox)=0.
765            boxtau(j,ibox)=0.
766            boxptop(j,ibox)=0.
767            box_cloudy(j,ibox)=.false.
768        enddo
76915    continue
770
771      !compute total cloud optical depth for each column     
772      do ilev=1,nlev
773            !increment tau for each of the boxes
774            do ibox=1,ncol
775              do j=1,npoints
776cIM REAL              if (frac_out(j,ibox,ilev).eq.1) then
777                 if (frac_out(j,ibox,ilev).eq.1.0) then
778                        tau(j,ibox)=tau(j,ibox)
779     &                     + dtau_s(j,ilev)
780                 endif
781cIM REAL              if (frac_out(j,ibox,ilev).eq.2) then
782                 if (frac_out(j,ibox,ilev).eq.2.0) then
783                        tau(j,ibox)=tau(j,ibox)
784     &                     + dtau_c(j,ilev)
785                 end if
786              enddo
787            enddo ! ibox
788      enddo ! ilev
789cIM
790c          if (ncolprint.ne.0) then
791
792c              do j=1,npoints ,1000
793c                write(6,'(a10)') 'j='
794c                write(6,'(8I10)') j
795c                write(6,'(i2,1X,8(f7.2,1X))')
796c     &          ilev,
797c     &          (tau(j,ibox),ibox=1,ncolprint)
798c              enddo
799c          endif
800!
801!     ---------------------------------------------------!
802
803
804
805!     
806!     ---------------------------------------------------!
807!     COMPUTE INFRARED BRIGHTNESS TEMPERUATRES
808!     AND CLOUD TOP TEMPERATURE SATELLITE SHOULD SEE
809!
810!     again this is only done if top_height = 1 or 3
811!
812!     fluxtop is the 10.5 micron radiance at the top of the
813!              atmosphere
814!     trans_layers_above is the total transmissivity in the layers
815!             above the current layer
816!     fluxtop_clrsky(j) and trans_layers_above_clrsky(j) are the clear
817!             sky versions of these quantities.
818
819      if (top_height .eq. 1 .or. top_height .eq. 3) then
820
821
822        !----------------------------------------------------------------------
823        !   
824        !             DO CLEAR SKY RADIANCE CALCULATION FIRST
825        !
826        !compute water vapor continuum emissivity
827        !this treatment follows Schwarkzopf and Ramasamy
828        !JGR 1999,vol 104, pages 9467-9499.
829        !the emissivity is calculated at a wavenumber of 955 cm-1,
830        !or 10.47 microns
831        wtmair = 28.9644
832        wtmh20 = 18.01534
833        Navo = 6.023E+23
834        grav = 9.806650E+02
835        pstd = 1.013250E+06
836        t0 = 296.
837cIM
838c        if (ncolprint .ne. 0)
839c     &         write(6,*)  'ilev   pw (kg/m2)   tauwv(j)      dem_wv'
840        do 125 ilev=1,nlev
841          do j=1,npoints
842               !press and dpress are dyne/cm2 = Pascals *10
843               press(j) = pfull(j,ilev)*10.
844               dpress(j) = (phalf(j,ilev+1)-phalf(j,ilev))*10
845               !atmden = g/cm2 = kg/m2 / 10
846               atmden(j) = dpress(j)/grav
847               rvh20(j) = qv(j,ilev)*wtmair/wtmh20
848               wk(j) = rvh20(j)*Navo*atmden(j)/wtmair
849               rhoave(j) = (press(j)/pstd)*(t0/at(j,ilev))
850               rh20s(j) = rvh20(j)*rhoave(j)
851               rfrgn(j) = rhoave(j)-rh20s(j)
852               tmpexp(j) = exp(-0.02*(at(j,ilev)-t0))
853               tauwv(j) = wk(j)*1.e-20*(
854     &           (0.0224697*rh20s(j)*tmpexp(j)) +
855     &                (3.41817e-7*rfrgn(j)) )*0.98
856               dem_wv(j,ilev) = 1. - exp( -1. * tauwv(j))
857          enddo
858cIM
859c               if (ncolprint .ne. 0) then
860c               do j=1,npoints ,1000
861c               write(6,'(a10)') 'j='
862c               write(6,'(8I10)') j
863c               write(6,'(i2,1X,3(f8.3,3X))') ilev,
864c     &           qv(j,ilev)*(phalf(j,ilev+1)-phalf(j,ilev))/(grav/100.),
865c     &           tauwv(j),dem_wv(j,ilev)
866c               enddo
867c              endif
868125     continue
869
870        !initialize variables
871        do j=1,npoints
872          fluxtop_clrsky(j) = 0.
873          trans_layers_above_clrsky(j)=1.
874        enddo
875
876        do ilev=1,nlev
877          do j=1,npoints
878 
879            ! Black body emission at temperature of the layer
880
881                bb(j)=1 / ( exp(1307.27/at(j,ilev)) - 1. )
882                !bb(j)= 5.67e-8*at(j,ilev)**4
883
884                ! increase TOA flux by flux emitted from layer
885                ! times total transmittance in layers above
886
887                fluxtop_clrsky(j) = fluxtop_clrsky(j)
888     &            + dem_wv(j,ilev)*bb(j)*trans_layers_above_clrsky(j)
889           
890                ! update trans_layers_above with transmissivity
891                ! from this layer for next time around loop
892
893                trans_layers_above_clrsky(j)=
894     &            trans_layers_above_clrsky(j)*(1.-dem_wv(j,ilev))
895                   
896
897          enddo
898cIM 
899c            if (ncolprint.ne.0) then
900c             do j=1,npoints ,1000
901c              write(6,'(a10)') 'j='
902c              write(6,'(8I10)') j
903c              write (6,'(a)') 'ilev:'
904c              write (6,'(I2)') ilev
905   
906c              write (6,'(a)')
907c     &        'emiss_layer,100.*bb(j),100.*f,total_trans:'
908c              write (6,'(4(f7.2,1X))') dem_wv(j,ilev),100.*bb(j),
909c     &             100.*fluxtop_clrsky(j),trans_layers_above_clrsky(j)
910c             enddo   
911c            endif
912
913        enddo   !loop over level
914       
915        do j=1,npoints
916          !add in surface emission
917          bb(j)=1/( exp(1307.27/skt(j)) - 1. )
918          !bb(j)=5.67e-8*skt(j)**4
919
920          fluxtop_clrsky(j) = fluxtop_clrsky(j) + emsfc_lw * bb(j)
921     &     * trans_layers_above_clrsky(j)
922        enddo
923
924cIM
925c        if (ncolprint.ne.0) then
926c        do j=1,npoints ,1000
927c          write(6,'(a10)') 'j='
928c          write(6,'(8I10)') j
929c          write (6,'(a)') 'id:'
930c          write (6,'(a)') 'surface'
931
932c          write (6,'(a)') 'emsfc,100.*bb(j),100.*f,total_trans:'
933c          write (6,'(4(f7.2,1X))') emsfc_lw,100.*bb(j),
934c     &      100.*fluxtop_clrsky(j),
935c     &       trans_layers_above_clrsky(j)
936c        enddo
937c       endif
938   
939
940        !
941        !           END OF CLEAR SKY CALCULATION
942        !
943        !----------------------------------------------------------------
944
945
946cIM
947c        if (ncolprint.ne.0) then
948
949c        do j=1,npoints ,1000
950c            write(6,'(a10)') 'j='
951c            write(6,'(8I10)') j
952c            write (6,'(a)') 'ts:'
953c            write (6,'(8f7.2)') (skt(j),ibox=1,ncolprint)
954   
955c            write (6,'(a)') 'ta_rev:'
956c            write (6,'(8f7.2)')
957c     &       ((at(j,ilev2),ibox=1,ncolprint),ilev2=1,nlev)
958
959c        enddo
960c        endif
961        !loop over columns
962        do ibox=1,ncol
963          do j=1,npoints
964            fluxtop(j,ibox)=0.
965            trans_layers_above(j,ibox)=1.
966          enddo
967        enddo
968
969        do ilev=1,nlev
970              do j=1,npoints
971                ! Black body emission at temperature of the layer
972
973                bb(j)=1 / ( exp(1307.27/at(j,ilev)) - 1. )
974                !bb(j)= 5.67e-8*at(j,ilev)**4
975              enddo
976
977            do ibox=1,ncol
978              do j=1,npoints
979
980                ! emissivity for point in this layer
981cIM REAL             if (frac_out(j,ibox,ilev).eq.1) then
982                if (frac_out(j,ibox,ilev).eq.1.0) then
983                dem(j,ibox)= 1. -
984     &             ( (1. - dem_wv(j,ilev)) * (1. -  dem_s(j,ilev)) )
985cIM REAL             else if (frac_out(j,ibox,ilev).eq.2) then
986                else if (frac_out(j,ibox,ilev).eq.2.0) then
987                dem(j,ibox)= 1. -
988     &             ( (1. - dem_wv(j,ilev)) * (1. -  dem_c(j,ilev)) )
989                else
990                dem(j,ibox)=  dem_wv(j,ilev)
991                end if
992               
993
994                ! increase TOA flux by flux emitted from layer
995                ! times total transmittance in layers above
996
997                fluxtop(j,ibox) = fluxtop(j,ibox)
998     &            + dem(j,ibox) * bb(j)
999     &            * trans_layers_above(j,ibox)
1000           
1001                ! update trans_layers_above with transmissivity
1002                ! from this layer for next time around loop
1003
1004                trans_layers_above(j,ibox)=
1005     &            trans_layers_above(j,ibox)*(1.-dem(j,ibox))
1006
1007              enddo ! j
1008            enddo ! ibox
1009
1010cIM
1011c            if (ncolprint.ne.0) then
1012c              do j=1,npoints,1000
1013c              write (6,'(a)') 'ilev:'
1014c              write (6,'(I2)') ilev
1015   
1016c              write(6,'(a10)') 'j='
1017c              write(6,'(8I10)') j
1018c              write (6,'(a)') 'emiss_layer:'
1019c              write (6,'(8f7.2)') (dem(j,ibox),ibox=1,ncolprint)
1020       
1021c              write (6,'(a)') '100.*bb(j):'
1022c              write (6,'(8f7.2)') (100.*bb(j),ibox=1,ncolprint)
1023       
1024c              write (6,'(a)') '100.*f:'
1025c              write (6,'(8f7.2)')
1026c     &         (100.*fluxtop(j,ibox),ibox=1,ncolprint)
1027       
1028c              write (6,'(a)') 'total_trans:'
1029c              write (6,'(8f7.2)')
1030c     &          (trans_layers_above(j,ibox),ibox=1,ncolprint)
1031c             enddo
1032c          endif
1033
1034        enddo ! ilev
1035
1036
1037          do j=1,npoints
1038            !add in surface emission
1039            bb(j)=1/( exp(1307.27/skt(j)) - 1. )
1040            !bb(j)=5.67e-8*skt(j)**4
1041          end do
1042
1043        do ibox=1,ncol
1044          do j=1,npoints
1045
1046            !add in surface emission
1047
1048            fluxtop(j,ibox) = fluxtop(j,ibox)
1049     &         + emsfc_lw * bb(j)
1050     &         * trans_layers_above(j,ibox)
1051           
1052          end do
1053        end do
1054
1055cIM
1056c        if (ncolprint.ne.0) then
1057
1058c          do j=1,npoints ,1000
1059c          write(6,'(a10)') 'j='
1060c          write(6,'(8I10)') j
1061c          write (6,'(a)') 'id:'
1062c          write (6,'(a)') 'surface'
1063
1064c          write (6,'(a)') 'emiss_layer:'
1065c          write (6,'(8f7.2)') (dem(1,ibox),ibox=1,ncolprint)
1066   
1067c          write (6,'(a)') '100.*bb(j):'
1068c          write (6,'(8f7.2)') (100.*bb(j),ibox=1,ncolprint)
1069   
1070c          write (6,'(a)') '100.*f:'
1071c          write (6,'(8f7.2)') (100.*fluxtop(j,ibox),ibox=1,ncolprint)
1072c          end do
1073c       endif
1074   
1075        !now that you have the top of atmosphere radiance account
1076        !for ISCCP procedures to determine cloud top temperature
1077
1078        !account for partially transmitting cloud recompute flux
1079        !ISCCP would see assuming a single layer cloud
1080        !note choice here of 2.13, as it is primarily ice
1081        !clouds which have partial emissivity and need the
1082        !adjustment performed in this section
1083        !
1084        !If it turns out that the cloud brightness temperature
1085        !is greater than 260K, then the liquid cloud conversion
1086        !factor of 2.56 is used.
1087        !
1088        !Note that this is discussed on pages 85-87 of
1089        !the ISCCP D level documentation (Rossow et al. 1996)
1090           
1091          do j=1,npoints 
1092            !compute minimum brightness temperature and optical depth
1093            btcmin(j) = 1. /  ( exp(1307.27/(attrop(j)-5.)) - 1. )
1094          enddo
1095        do ibox=1,ncol
1096          do j=1,npoints 
1097            transmax(j) = (fluxtop(j,ibox)-btcmin(j))
1098     &                /(fluxtop_clrsky(j)-btcmin(j))
1099            !note that the initial setting of tauir(j) is needed so that
1100            !tauir(j) has a realistic value should the next if block be
1101            !bypassed
1102            tauir(j) = tau(j,ibox) * rec2p13
1103            taumin(j) = -1. * log(max(min(transmax(j),0.9999999),0.001))
1104
1105          enddo
1106
1107          if (top_height .eq. 1) then
1108            do j=1,npoints 
1109              if (transmax(j) .gt. 0.001 .and.
1110     &          transmax(j) .le. 0.9999999) then
1111                fluxtopinit(j) = fluxtop(j,ibox)
1112                tauir(j) = tau(j,ibox) *rec2p13
1113              endif
1114            enddo
1115            do icycle=1,2
1116              do j=1,npoints 
1117                if (tau(j,ibox) .gt. (tauchk            )) then
1118                if (transmax(j) .gt. 0.001 .and.
1119     &            transmax(j) .le. 0.9999999) then
1120                  emcld(j,ibox) = 1. - exp(-1. * tauir(j)  )
1121                  fluxtop(j,ibox) = fluxtopinit(j) -   
1122     &              ((1.-emcld(j,ibox))*fluxtop_clrsky(j))
1123                  fluxtop(j,ibox)=max(1.E-06,
1124     &              (fluxtop(j,ibox)/emcld(j,ibox)))
1125                  tb(j,ibox)= 1307.27
1126     &              / (log(1. + (1./fluxtop(j,ibox))))
1127                  if (tb(j,ibox) .gt. 260.) then
1128                    tauir(j) = tau(j,ibox) / 2.56
1129                  end if                         
1130                end if
1131                end if
1132              enddo
1133            enddo
1134               
1135          endif
1136       
1137          do j=1,npoints
1138            if (tau(j,ibox) .gt. (tauchk            )) then
1139                !cloudy box
1140                tb(j,ibox)= 1307.27/ (log(1. + (1./fluxtop(j,ibox))))
1141                if (top_height.eq.1.and.tauir(j).lt.taumin(j)) then
1142                         tb(j,ibox) = attrop(j) - 5.
1143                         tau(j,ibox) = 2.13*taumin(j)
1144                end if
1145            else
1146                !clear sky brightness temperature
1147                tb(j,ibox) = 1307.27/(log(1.+(1./fluxtop_clrsky(j))))
1148            end if
1149          enddo ! j
1150        enddo ! ibox
1151
1152cIM
1153c        if (ncolprint.ne.0) then
1154
1155c          do j=1,npoints,1000
1156c          write(6,'(a10)') 'j='
1157c          write(6,'(8I10)') j
1158
1159c          write (6,'(a)') 'attrop:'
1160c          write (6,'(8f7.2)') (attrop(j))
1161   
1162c          write (6,'(a)') 'btcmin:'
1163c          write (6,'(8f7.2)') (btcmin(j))
1164   
1165c          write (6,'(a)') 'fluxtop_clrsky*100:'
1166c          write (6,'(8f7.2)')
1167c     &      (100.*fluxtop_clrsky(j))
1168
1169c          write (6,'(a)') '100.*f_adj:'
1170c          write (6,'(8f7.2)') (100.*fluxtop(j,ibox),ibox=1,ncolprint)
1171   
1172c          write (6,'(a)') 'transmax:'
1173c          write (6,'(8f7.2)') (transmax(ibox),ibox=1,ncolprint)
1174   
1175c          write (6,'(a)') 'tau:'
1176c          write (6,'(8f7.2)') (tau(j,ibox),ibox=1,ncolprint)
1177   
1178c          write (6,'(a)') 'emcld:'
1179c          write (6,'(8f7.2)') (emcld(j,ibox),ibox=1,ncolprint)
1180   
1181c          write (6,'(a)') 'total_trans:'
1182c          write (6,'(8f7.2)')
1183c     &   (trans_layers_above(j,ibox),ibox=1,ncolprint)
1184   
1185c          write (6,'(a)') 'total_emiss:'
1186c          write (6,'(8f7.2)')
1187c     &   (1.0-trans_layers_above(j,ibox),ibox=1,ncolprint)
1188   
1189c          write (6,'(a)') 'total_trans:'
1190c          write (6,'(8f7.2)')
1191c     &   (trans_layers_above(j,ibox),ibox=1,ncolprint)
1192   
1193c          write (6,'(a)') 'ppout:'
1194c          write (6,'(8f7.2)') (tb(j,ibox),ibox=1,ncolprint)
1195c          enddo ! j
1196c       endif
1197
1198      end if
1199
1200!     ---------------------------------------------------!
1201
1202!     
1203!     ---------------------------------------------------!
1204!     DETERMINE CLOUD TOP PRESSURE
1205!
1206!     again the 2 methods differ according to whether
1207!     or not you use the physical cloud top pressure (top_height = 2)
1208!     or the radiatively determined cloud top pressure (top_height = 1 or 3)
1209!
1210
1211      !compute cloud top pressure
1212      do 30 ibox=1,ncol
1213        !segregate according to optical thickness
1214        if (top_height .eq. 1 .or. top_height .eq. 3) then 
1215          !find level whose temperature
1216          !most closely matches brightness temperature
1217          do j=1,npoints
1218            nmatch(j)=0
1219          enddo
1220          do 29 ilev=1,nlev-1
1221            !cdir nodep
1222            do j=1,npoints
1223              if ((at(j,ilev)   .ge. tb(j,ibox) .and.
1224     &          at(j,ilev+1) .lt. tb(j,ibox)) .or.
1225     &          (at(j,ilev) .le. tb(j,ibox) .and.
1226     &          at(j,ilev+1) .gt. tb(j,ibox))) then
1227   
1228                nmatch(j)=nmatch(j)+1
1229                if(abs(at(j,ilev)-tb(j,ibox)) .lt.
1230     &            abs(at(j,ilev+1)-tb(j,ibox))) then
1231                  match(j,nmatch(j))=ilev
1232                else
1233                  match(j,nmatch(j))=ilev+1
1234                end if
1235              end if                       
1236            enddo
123729        continue
1238
1239          do j=1,npoints
1240            if (nmatch(j) .ge. 1) then
1241              ptop(j,ibox)=pfull(j,match(j,nmatch(j)))
1242              levmatch(j,ibox)=match(j,nmatch(j))   
1243            else
1244              if (tb(j,ibox) .lt. atmin(j)) then
1245                ptop(j,ibox)=ptrop(j)
1246                levmatch(j,ibox)=itrop(j)
1247              end if
1248              if (tb(j,ibox) .gt. atmax(j)) then
1249                ptop(j,ibox)=pfull(j,nlev)
1250                levmatch(j,ibox)=nlev
1251              end if                               
1252            end if
1253          enddo ! j
1254
1255        else ! if (top_height .eq. 1 .or. top_height .eq. 3)
1256 
1257          do j=1,npoints     
1258            ptop(j,ibox)=0.
1259          enddo
1260          do ilev=1,nlev
1261            do j=1,npoints     
1262              if ((ptop(j,ibox) .eq. 0. )
1263cIM  &           .and.(frac_out(j,ibox,ilev) .ne. 0)) then
1264     &           .and.(frac_out(j,ibox,ilev) .ne. 0.0)) then
1265                ptop(j,ibox)=pfull(j,ilev)
1266                levmatch(j,ibox)=ilev
1267              end if
1268            end do
1269          end do
1270        end if                           
1271         
1272        do j=1,npoints
1273          if (tau(j,ibox) .le. (tauchk            )) then
1274            ptop(j,ibox)=0.
1275            levmatch(j,ibox)=0     
1276          endif
1277        enddo
1278
127930    continue
1280             
1281!
1282!
1283!     ---------------------------------------------------!
1284
1285
1286!     
1287!     ---------------------------------------------------!
1288!     DETERMINE ISCCP CLOUD TYPE FREQUENCIES
1289!
1290!     Now that ptop and tau have been determined,
1291!     determine amount of each of the 49 ISCCP cloud
1292!     types
1293!
1294!     Also compute grid box mean cloud top pressure and
1295!     optical thickness.  The mean cloud top pressure and
1296!     optical thickness are averages over the cloudy
1297!     area only. The mean cloud top pressure is a linear
1298!     average of the cloud top pressures.  The mean cloud
1299!     optical thickness is computed by converting optical
1300!     thickness to an albedo, averaging in albedo units,
1301!     then converting the average albedo back to a mean
1302!     optical thickness. 
1303!
1304
1305      !compute isccp frequencies
1306
1307      !reset frequencies
1308      do 38 ilev=1,7
1309      do 38 ilev2=1,7
1310        do j=1,npoints !
1311             fq_isccp(j,ilev,ilev2)=0.
1312        enddo
131338    continue
1314
1315      !reset variables need for averaging cloud properties
1316      do j=1,npoints
1317        totalcldarea(j) = 0.
1318        meanalbedocld(j) = 0.
1319        meanptop(j) = 0.
1320        meantaucld(j) = 0.
1321      enddo ! j
1322
1323      boxarea = 1./real(ncol)
1324     
1325              !determine optical depth category
1326cIM       do 39 j=1,npoints
1327cIM       do ibox=1,ncol
1328        do 39 ibox=1,ncol
1329          do j=1,npoints
1330
1331cIM
1332c         CALL CPU_time(t1)
1333cIM
1334
1335          if (tau(j,ibox) .gt. (tauchk            )
1336     &      .and. ptop(j,ibox) .gt. 0.) then
1337              box_cloudy(j,ibox)=.true.
1338          endif
1339
1340cIM
1341c         CALL CPU_time(t2)
1342c         print*,'IF tau t2 - t1',t2 - t1
1343
1344c         CALL CPU_time(t1)
1345cIM
1346
1347          if (box_cloudy(j,ibox)) then
1348
1349              ! totalcldarea always diagnosed day or night
1350              totalcldarea(j) = totalcldarea(j) + boxarea
1351
1352              if (sunlit(j).eq.1) then
1353
1354                ! tau diagnostics only with sunlight
1355
1356                boxtau(j,ibox) = tau(j,ibox)
1357
1358                !convert optical thickness to albedo
1359                albedocld(j,ibox)
1360     &            =real(invtau(min(nint(100.*tau(j,ibox)),45000)))
1361           
1362                !contribute to averaging
1363                meanalbedocld(j) = meanalbedocld(j)
1364     &            +albedocld(j,ibox)*boxarea
1365
1366            endif
1367
1368          endif
1369         
1370cIM
1371c         CALL CPU_time(t2)
1372c         print*,'IF box_cloudy t2 - t1',t2 - t1
1373         
1374c         CALL CPU_time(t1)
1375cIM BEG
1376cIM           !convert ptop to millibars
1377              ptop(j,ibox)=ptop(j,ibox) / 100.
1378           
1379cIM           !save for output cloud top pressure and optical thickness
1380              boxptop(j,ibox) = ptop(j,ibox)
1381cIM END
1382
1383cIM BEG
1384              !reset itau(j), ipres(j)
1385              itau(j) = 0
1386              ipres(j) = 0
1387
1388              if (tau(j,ibox) .lt. isccp_taumin) then
1389                  itau(j)=1
1390              else if (tau(j,ibox) .ge. isccp_taumin
1391     &                                   
1392     &          .and. tau(j,ibox) .lt. 1.3) then
1393                itau(j)=2
1394              else if (tau(j,ibox) .ge. 1.3
1395     &          .and. tau(j,ibox) .lt. 3.6) then
1396                itau(j)=3
1397              else if (tau(j,ibox) .ge. 3.6
1398     &          .and. tau(j,ibox) .lt. 9.4) then
1399                  itau(j)=4
1400              else if (tau(j,ibox) .ge. 9.4
1401     &          .and. tau(j,ibox) .lt. 23.) then
1402                  itau(j)=5
1403              else if (tau(j,ibox) .ge. 23.
1404     &          .and. tau(j,ibox) .lt. 60.) then
1405                  itau(j)=6
1406              else if (tau(j,ibox) .ge. 60.) then
1407                  itau(j)=7
1408              end if
1409
1410              !determine cloud top pressure category
1411              if (    ptop(j,ibox) .gt. 0. 
1412     &          .and.ptop(j,ibox) .lt. 180.) then
1413                  ipres(j)=1
1414              else if(ptop(j,ibox) .ge. 180.
1415     &          .and.ptop(j,ibox) .lt. 310.) then
1416                  ipres(j)=2
1417              else if(ptop(j,ibox) .ge. 310.
1418     &          .and.ptop(j,ibox) .lt. 440.) then
1419                  ipres(j)=3
1420              else if(ptop(j,ibox) .ge. 440.
1421     &          .and.ptop(j,ibox) .lt. 560.) then
1422                  ipres(j)=4
1423              else if(ptop(j,ibox) .ge. 560.
1424     &          .and.ptop(j,ibox) .lt. 680.) then
1425                  ipres(j)=5
1426              else if(ptop(j,ibox) .ge. 680.
1427     &          .and.ptop(j,ibox) .lt. 800.) then
1428                  ipres(j)=6
1429              else if(ptop(j,ibox) .ge. 800.) then
1430                  ipres(j)=7
1431              end if
1432cIM END
1433
1434          if (sunlit(j).eq.1 .or. top_height .eq. 3) then
1435
1436cIM         !convert ptop to millibars
1437cIM           ptop(j,ibox)=ptop(j,ibox) / 100.
1438           
1439cIM         !save for output cloud top pressure and optical thickness
1440cIM             boxptop(j,ibox) = ptop(j,ibox)
1441   
1442            if (box_cloudy(j,ibox)) then
1443           
1444              meanptop(j) = meanptop(j) + ptop(j,ibox)*boxarea
1445
1446cIM             !reset itau(j), ipres(j)
1447cIM           itau(j) = 0
1448cIM           ipres(j) = 0
1449
1450c             if (tau(j,ibox) .lt. isccp_taumin) then
1451c                 itau(j)=1
1452c             else if (tau(j,ibox) .ge. isccp_taumin
1453c    &                                   
1454c    &          .and. tau(j,ibox) .lt. 1.3) then
1455c               itau(j)=2
1456c             else if (tau(j,ibox) .ge. 1.3
1457c    &          .and. tau(j,ibox) .lt. 3.6) then
1458c               itau(j)=3
1459c             else if (tau(j,ibox) .ge. 3.6
1460c    &          .and. tau(j,ibox) .lt. 9.4) then
1461c                 itau(j)=4
1462c             else if (tau(j,ibox) .ge. 9.4
1463c    &          .and. tau(j,ibox) .lt. 23.) then
1464c                 itau(j)=5
1465c             else if (tau(j,ibox) .ge. 23.
1466c    &          .and. tau(j,ibox) .lt. 60.) then
1467c                 itau(j)=6
1468c             else if (tau(j,ibox) .ge. 60.) then
1469c                 itau(j)=7
1470c             end if
1471
1472c             !determine cloud top pressure category
1473c             if (    ptop(j,ibox) .gt. 0. 
1474c    &          .and.ptop(j,ibox) .lt. 180.) then
1475c                 ipres(j)=1
1476c             else if(ptop(j,ibox) .ge. 180.
1477c    &          .and.ptop(j,ibox) .lt. 310.) then
1478c                 ipres(j)=2
1479c             else if(ptop(j,ibox) .ge. 310.
1480c    &          .and.ptop(j,ibox) .lt. 440.) then
1481c                 ipres(j)=3
1482c            else if(ptop(j,ibox) .ge. 440.
1483c    &          .and.ptop(j,ibox) .lt. 560.) then
1484c                 ipres(j)=4
1485c             else if(ptop(j,ibox) .ge. 560.
1486c    &          .and.ptop(j,ibox) .lt. 680.) then
1487c                 ipres(j)=5
1488c             else if(ptop(j,ibox) .ge. 680.
1489c    &          .and.ptop(j,ibox) .lt. 800.) then
1490c                 ipres(j)=6
1491c             else if(ptop(j,ibox) .ge. 800.) then
1492c                 ipres(j)=7
1493c             end if
1494
1495              !update frequencies
1496              if(ipres(j) .gt. 0.and.itau(j) .gt. 0) then
1497              fq_isccp(j,itau(j),ipres(j))=
1498     &          fq_isccp(j,itau(j),ipres(j))+ boxarea
1499              end if
1500
1501cIM calcul stats regime dynamique BEG
1502!             iw(j) = int((w(j)-wmin)/pas_w) +1
1503!             pctj(itau(j),ipres(j),iw(j))=.FALSE.
1504!             !update frequencies W500
1505!             if (pct_ocean(j)) then
1506!             if (ipres(j) .gt. 0.and.itau(j) .gt. 0) then
1507!             if (iw(j) .gt. int(wmin).and.iw(j) .le. iwmx) then
1508c             print*,' ISCCP iw=',iw(j),j
1509!             fq_dynreg(itau(j),ipres(j),iw(j))=
1510!    &          fq_dynreg(itau(j),ipres(j),iw(j))+
1511!    &          boxarea
1512c    &          fq_isccp(j,itau(j),ipres(j))
1513!             pctj(itau(j),ipres(j),iw(j))=.TRUE.
1514c             nfq_dynreg(itau(j),ipres(j),iw(j))=
1515c    &          nfq_dynreg(itau(j),ipres(j),iw(j))+1.
1516!              end if
1517!             end if
1518!             end if
1519cIM calcul stats regime dynamique END
1520            end if !IM boxcloudy
1521
1522          end if !IM sunlit
1523                       
1524cIM
1525c         CALL CPU_time(t2)
1526c         print*,'IF sunlit boxcloudy t2 - t1',t2 - t1
1527cIM
1528        enddo !IM ibox/j
1529
1530
1531cIM ajout stats s/ W500 BEG
1532cIM ajout stats s/ W500 END
1533
1534c             if(j.EQ.6722) then
1535c             print*,' ISCCP',w(j),iw(j),ipres(j),itau(j)
1536c             endif
1537
1538!     if (pct_ocean(j)) then
1539!     if (ipres(j) .gt. 0.and.itau(j) .gt. 0) then
1540!     if (iw(j) .gt. int(wmin).and.iw(j) .le. iwmx) then
1541!     if(pctj(itau(j),ipres(j),iw(j))) THEN
1542!         nfq_dynreg(itau(j),ipres(j),iw(j))=
1543!    &    nfq_dynreg(itau(j),ipres(j),iw(j))+1.
1544c         if(itau(j).EQ.4.AND.ipres(j).EQ.2.AND.
1545c    &    iw(j).EQ.10) then
1546c         PRINT*,' isccp AVANT',
1547c    &    nfq_dynreg(itau(j),ipres(j),iw(j)),
1548c    &    fq_dynreg(itau(j),ipres(j),iw(j))
1549c         endif
1550!     endif
1551!     endif
1552!     endif
1553!     endif
155439    continue !IM j/ibox
1555     
1556      !compute mean cloud properties
1557      do j=1,npoints
1558        if (totalcldarea(j) .gt. 0.) then
1559          meanptop(j) = meanptop(j) / totalcldarea(j)
1560          if (sunlit(j).eq.1) then
1561            meanalbedocld(j) = meanalbedocld(j) / totalcldarea(j)
1562            meantaucld(j) = tautab(min(255,max(1,nint(meanalbedocld(j)))))
1563          end if
1564        end if
1565      enddo ! j
1566!
1567cIM ajout stats s/ W500 BEG
1568!     do nw = 1, iwmx
1569!     do l = 1, 7
1570!     do k = 1, 7
1571!       if (nfq_dynreg(k,l,nw).GT.0.) then
1572!       fq_dynreg(k,l,nw) = fq_dynreg(k,l,nw)/nfq_dynreg(k,l,nw)
1573c        if(k.EQ.4.AND.l.EQ.2.AND.nw.EQ.10) then
1574c        print*,' isccp APRES',nfq_dynreg(k,l,nw),
1575c    &   fq_dynreg(k,l,nw)
1576c        endif
1577!       else
1578!        if(fq_dynreg(k,l,nw).NE.0.) then
1579!        print*,'nfq_dynreg = 0 tau,pc,nw',k,l,nw,fq_dynreg(k,l,nw)
1580!        endif
1581c        fq_dynreg(k,l,nw) = -1.E+20
1582c        nfq_dynreg(k,l,nw) = 1.E+20
1583!       end if
1584!     enddo !k
1585!     enddo !l
1586!     enddo !nw
1587cIM ajout stats s/ W500 END
1588!     ---------------------------------------------------!
1589
1590!     ---------------------------------------------------!
1591!     OPTIONAL PRINTOUT OF DATA TO CHECK PROGRAM
1592!
1593!cIM
1594c      if (debugcol.ne.0) then
1595!     
1596c         do j=1,npoints,debugcol
1597
1598c            !produce character output
1599c            do ilev=1,nlev
1600c              do ibox=1,ncol
1601c                   acc(ilev,ibox)=0
1602c              enddo
1603c            enddo
1604
1605c            do ilev=1,nlev
1606c              do ibox=1,ncol
1607c                   acc(ilev,ibox)=frac_out(j,ibox,ilev)*2
1608c                   if (levmatch(j,ibox) .eq. ilev)
1609c     &                 acc(ilev,ibox)=acc(ilev,ibox)+1
1610c              enddo
1611c            enddo
1612
1613             !print test
1614
1615c          write(ftn09,11) j
1616c11        format('ftn09.',i4.4)
1617c         open(9, FILE=ftn09, FORM='FORMATTED')
1618
1619c             write(9,'(a1)') ' '
1620c                    write(9,'(10i5)')
1621c     &                  (ilev,ilev=5,nlev,5)
1622c             write(9,'(a1)') ' '
1623             
1624c             do ibox=1,ncol
1625c               write(9,'(40(a1),1x,40(a1))')
1626c     &           (cchar_realtops(acc(ilev,ibox)+1),ilev=1,nlev)
1627c     &           ,(cchar(acc(ilev,ibox)+1),ilev=1,nlev)
1628c             end do
1629c            close(9)
1630c
1631cIM
1632c             if (ncolprint.ne.0) then
1633c               write(6,'(a1)') ' '
1634c                    write(6,'(a2,1X,5(a7,1X),a50)')
1635c     &                  'ilev',
1636c     &                  'pfull','at',
1637c     &                  'cc*100','dem_s','dtau_s',
1638c     &                  'cchar'
1639
1640!               do 4012 ilev=1,nlev
1641!                    write(6,'(60i2)') (box(i,ilev),i=1,ncolprint)
1642!                   write(6,'(i2,1X,5(f7.2,1X),50(a1))')
1643!     &                  ilev,
1644!     &                  pfull(j,ilev)/100.,at(j,ilev),
1645!     &                  cc(j,ilev)*100.0,dem_s(j,ilev),dtau_s(j,ilev)
1646!     &                  ,(cchar(acc(ilev,ibox)+1),ibox=1,ncolprint)
1647!4012           continue
1648c               write (6,'(a)') 'skt(j):'
1649c               write (6,'(8f7.2)') skt(j)
1650                                     
1651c               write (6,'(8I7)') (ibox,ibox=1,ncolprint)
1652             
1653c               write (6,'(a)') 'tau:'
1654c               write (6,'(8f7.2)') (tau(j,ibox),ibox=1,ncolprint)
1655   
1656c               write (6,'(a)') 'tb:'
1657c               write (6,'(8f7.2)') (tb(j,ibox),ibox=1,ncolprint)
1658   
1659c               write (6,'(a)') 'ptop:'
1660c               write (6,'(8f7.2)') (ptop(j,ibox),ibox=1,ncolprint)
1661c             endif
1662   
1663c        enddo
1664       
1665c      end if
1666
1667      return
1668      end
Note: See TracBrowser for help on using the repository browser.