source: LMDZ4/trunk/libf/phylmd/isccp_cloud_types.F @ 594

Last change on this file since 594 was 524, checked in by lmdzadmin, 20 years ago

Initial revision

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