C**********************************************************                  NIKOS.2     
C             SUBROUTINE NIKOSRAD                                            NIKOS.3     
C**********************************************************                  NIKOS.4     
       SUBROUTINE NIKOSRAD(PR,T,H2O,O3,alat,HTLW,HTSW,DOY,CF,IC,             NIKOS.5     
     $     RFLUXES,SWALB,ALON)                                               NIKOS.6     
C                                                                            NIKOS.7     
C No aerosols                                                                NIKOS.8     
c Morcrette SW combined with Nikos LW scheme                                 NIKOS.9     
C Piers 27-1-98                                                              NIKOS.10    
C                                                                            NIKOS.11    
C P  Pressure on Full levels(Pa) level 1 is ground                           NIKOS.12    
C T Temperature on Full levels(K) level 1 is ground                          NIKOS.13    
C H2O water vapour mmr on full levels level 1 is ground                      NIKOS.14    
C O3 ozone mmr on full levels level 1 is ground                              NIKOS.15    
C DOY Julian Day wanted (real)                                               NIKOS.16    
C NLEV number of levels                                                      NIKOS.17    
C ALAT Latitude in degrees                                                   NIKOS.18    
C ALON longitude in degrees                                                  NIKOS.19    
C HTLW Output: lomgwave Heating Rate full levels etc (K/day)                 NIKOS.20    
C HTSW Output: shortwave heating rate (K/DAY)                                NIKOS.21    
C RFLUXES  Array to hold fluxes at top and bottom of atmosphere              NIKOS.22    
C     1st index - flux 1=SW, 2=LW                                            NIKOS.23    
C     2nd index - Direction 1=DN, 2=UP                                       NIKOS.24    
C     3rd index - Where 1=TOP, 2=SURFACE                                     NIKOS.25    
C SWALB SW albedo                                                            NIKOS.26    
C CF   CF(*,1) CLOUD fractions and CF(*,2) CLOUD LWP(g/m^2)                  NIKOS.27    
C  Index 1-deep convective, 2-high,3-mid,4-low                               NIKOS.28    
C IC   IC(*,1) cloud start level, IC(*,2) cloud stop level                   NIKOS.29    
C  level 1 is ground                                                         NIKOS.30    
C  same index as cloud                                                       NIKOS.31    
                                                                             NIKOS.32    
C                 -----------                                                NIKOS.33    
C  Driving program for the extended atmospheric radiation scheme of          NIKOS.34    
C              Lacis and Hansen and Nikos Christidis.                        NIKOS.35    
C                                                                            NIKOS.36    
C                                                                            NIKOS.37    
C***********************************************************************     PARRAY.2     
C*                                                                     *     PARRAY.3     
C*                         P A R R A Y                                 *     PARRAY.4     
C*                                                                     *     PARRAY.5     
C***********************************************************************     PARRAY.6     
C-----------------------------------------------------------------------     PARRAY.7     
C In this part of the code the user can set the dimensions of arrays         PARRAY.8     
C used for the calculations, by setting the values in the paramter           PARRAY.9     
C statements                                                                 PARRAY.10    
C-----------------------------------------------------------------------     PARRAY.11    
                                                                             PARRAY.12    
      INTEGER MXGAS,MXLEV,MXBAND,MXCL                                        PARRAY.13    
                                                                             PARRAY.14    
      PARAMETER(MXGAS=8)     ! Maximum number of gases                       PARRAY.15    
                                                                             PARRAY.16    
      PARAMETER(MXLEV=5)     ! Maximum number of levels in the               NETCDF.37    
                             ! atmosphere (not including the surface)        PARRAY.18    
                                                                             PARRAY.19    
      PARAMETER(MXBAND=9)    ! Maximum number of spectral bands (not         PARRAY.20    
                             ! including the whole spectrum, 0-3000cm-1)     PARRAY.21    
                                                                             PARRAY.22    
      PARAMETER(MXCL=3)      ! Maximum number of cloud types                 PARRAY.23    
                                                                             PARRAY.24    
C-----------------------------------------------------------------------     PARRAY.25    
C                                                                            RADLW.2     
C  Switches for long wave radiation scheme                                   RADLW.3     
C                                                                            RADLW.4     
      COMMON/RADLW/LLBLM,GAS(MXGAS),VMRCO2,VMRCH4,VMRN2O,VMRHALO             RADLW.5     
      LOGICAL LLBLM                                                          RADLW.6     
      INTEGER GAS                                                            RADLW.7     
      REAL VMRCO2,VMRCH4,VMRN2O,VMRHALO                                      RADLW.8     
C                                                                            RADLW.9     
C                                                                            PARAM1.2     
C     Determines model resolution                                            PARAM1.3     
C                                                                            PARAM1.4     
      PARAMETER(NN=21,MM=21,NHEM=2,NL=5,MOCT=1,MG=64,JG=16,NWJ2=121          NETCDF.35    
     P         ,NCRAY=64,JGL=JG,NTRAC=1,NLEVRF=1)                            NETCDF.36    
                                                                             PARAM1.7     
C                                                                            PARAM1.8     
C                                                                            PARAM2.2     
C     Sets basic constants, especially those needed for array dimensions     PARAM2.3     
C                                                                            PARAM2.4     
      PARAMETER(MH=2,PI=3.14159265359,PI2=2.0*PI                             PARAM2.5     
     +,NNP=NN+1,MGPP=MG+2,JGP=JG+1,JGG=JG*NHEM,JGGP=JGG+1,MJP=NWJ2+NWJ2      PARAM2.6     
     +,NLM=NL-1,NLP=NL+1,NLPP=NL+2,NLA=NL+3,NLB=NL+4,NL2=NL*NL               PARAM2.7     
     +,IDA=(MG+MG+MG)/2+1,IDB=NWJ2*NL,IDC=IDB+IDB,IDD=MGPP*NL                PARAM2.8     
     +,IDE=NL2*NN,IDF=NCRAY*(MG+1),IDG=JG*NL,IDH=JG*MG                       PARAM2.9     
     +,IDI=NNP/2,IDJ=IDI*IDI,IDK=NL*IDI,IDL=MGPP/2,IDM=NNP/2,IDN=IDM*NL      PARAM2.10    
     +,NWW=1+(MM-1)/MOCT)                                                    PARAM2.11    
      PARAMETER(IGA=NWJ2*NHEM,IGB=IDB*NHEM,IGC=MGPP*NHEM,IGD=IDD*NHEM        PARAM2.12    
     +,IGG=IDG*NHEM,IGL=IDL*NHEM,IGM=IDM*NHEM,IGN=IDN*NHEM                   PARAM2.13    
     +,IGO=IGA+IGA,IGP=IGB+IGB,NFTWG=(5+NTRAC)*NL+3                          PARAM2.14    
     +,NFTGW=(6+3*NTRAC)*NL+2,NFTGD=(3+NTRAC)*NL,NLTR=NL*NTRAC)              PARAM2.15    
C     Number of 2D (surface) output fields. This value is                    PARAM2.16    
C     Doubled due to averaged and instantaneous fields.                      PARAM2.17    
      PARAMETER (N2DFLD=21,NGRPAD=N2DFLD*2*IGC)                              PARAM2.18    
C                                                                            PARAM2.19    
C                                                                            BLANK.2     
C     Basic planetary parameters for run plus information about              BLANK.3     
C     vertical grid structure                                                BLANK.4     
C                                                                            BLANK.5     
C     Note that RD and GASCON are identical and CPD is set from RD,AKAP.     BLANK.6     
      COMMON        SQ(NNP),RSQ(NNP),SIGMAH(NLM),SIGMA(NL)                   BLANK.7     
     +              ,T01S2(NLM),T0(NL),ALPHA(NL),DSIGMA(NL),RDSIG(NL)        BLANK.8     
     +              ,TKP(NL),C(NL2),SQH(NNP)                                 BLANK.9     
     +              ,MF,MFP,JZF,NF,NFP                                       BLANK.10    
     +              ,AKAP,GA,GASCON,RADEA,WW,P0,PFAC,EZ,AIOCT                BLANK.11    
     +              ,RD,RV,CPD,CLATNT                                        BLANK.12    
     +              ,LRSTRT,LSHORT,LTVEC,LSTRETCH                            BLANK.13    
     +              ,LFLUX                                                   BLANK.14    
     +              ,LBALAN,LRESTIJ                                          BLANK.15    
     +              ,LCLIM, LPERPET, L22L,LOROG ,LCSFCT                      BLANK.16    
     +              ,LNOISE                                                  BLANK.17    
      COMPLEX EZ,AIOCT                                                       BLANK.18    
      LOGICAL LRSTRT,LSHORT,LTVEC,LSTRETCH,LBALAN,LRESTIJ                    BLANK.19    
     +       ,LFLUX,LNOISE                                                   BLANK.20    
     +       ,LCLIM, LPERPET, L22L,LOROG,LCSFCT                              BLANK.21    
C                                                                            BLANK.22    
      PARAMETER (NRLEV=MXLEV+1)                                              NIKOS.43    
      REAL PR(NRLEV),T(NRLEV),H2O(NRLEV),O3(NRLEV),alat                      NIKOS.44    
      real htlw(nrlev),htsw(nrlev),swalb,DOY,alon                            NIKOS.45    
      REAL CF(4,2)     !cloud fractions,lwps                                 NIKOS.46    
c clouds in order of convective,high,mid,low                                 NIKOS.47    
c ie convective has index of 1 with low cloud index of 4                     NIKOS.48    
      INTEGER IC(4,2)   ! cloud positions                                    NIKOS.49    
      REAL RFLUXES(2,2,2)                                                    NIKOS.50    
      LOGICAL LDIUR                                                          NIKOS.51    
********************************************************************         NIKOS.52    
C Morcrette                                                                  NIKOS.53    
      REAL FLS(nrlev+1)                                                      NIKOS.54    
      REAL SWDP(NRLEV),pclfr(nrlev),pqlwp(nrlev)                             NIKOS.55    
C Nikos                                                                      NIKOS.56    
      INTEGER CKD, IFIRST                                                    NIKOS.57    
      DATA IFIRST/1/                                                         NIKOS.58    
      REAL PRES(0:MXLEV),TEMP(0:MXLEV),MMR(MXGAS,0:MXLEV)                    NIKOS.59    
      INTEGER CL(0:MXCL)                                                     NIKOS.60    
      REAL ACL(0:MXCL),LWCCL(MXCL),BASCL(0:MXCL),TOPCL(0:MXCL)               NIKOS.61    
C Pressure at flux levels                                                    NIKOS.62    
      REAL PFLUX(0:MXLEV)                                                    NIKOS.63    
                                                                             NIKOS.64    
C------------------                                                          NIKOS.65    
C Output Variables                                                           NIKOS.66    
C------------------                                                          NIKOS.67    
                                                                             NIKOS.68    
      REAL FUP(0:MXLEV),FDWN(0:MXLEV),FNET(0:MXLEV)                          NIKOS.69    
      REAL PDP(MXLEV)                                                        NIKOS.70    
C********************************************************************        NIKOS.71    
C                                                                            NIKOS.72    
C long wave radiation namelist                                               NIKOS.73    
      NAMELIST/INRADLW/LLBLM,GAS,VMRCO2,VMRCH4,VMRN2O,                       NIKOS.74    
     :             VMRHALO                                                   NIKOS.75    
      LLBLM=.TRUE.                                                           NIKOS.76    
C                                                                            NIKOS.77    
C    Setup for LW scheme                                                     NIKOS.78    
      NLEV=NRLEV-1                                                           NIKOS.79    
      CKD=1           ! water vapour continium                               NIKOS.80    
      IF (CKD.EQ.1.AND.IFIRST.EQ.1)THEN                                      NIKOS.81    
          WRITE (2,*)'Water Vapour Continuum On'                             NIKOS.82    
      ELSEIF(CKD.EQ.0.AND.IFIRST.EQ.1)THEN                                   NIKOS.83    
          WRITE (2,*)'Water Vapour Continuum Off'                            NIKOS.84    
      ENDIF                                                                  NIKOS.85    
      IF (NL.NE.MXLEV)THEN                                                   NIKOS.86    
        WRITE(*,*)'JOB ABORTED! NL= ',NL,' MXLEV= ',MXLEV                    NIKOS.87    
        CALL ABORT                                                           NIKOS.88    
      ENDIF                                                                  NIKOS.89    
C set up default values.                                                     NIKOS.90    
      IF (IFIRST.EQ.1) THEN                                                  NIKOS.91    
       IFIRST=0                                                              NIKOS.92    
       IF(LLBLM)THEN                                                         NIKOS.93    
        PRINT *,'Transmittance tables created by lblm'                       NIKOS.94    
       ELSE                                                                  NIKOS.95    
        PRINT *,'Transmittance tables created by nbm'                        NIKOS.96    
       ENDIF                                                                 NIKOS.97    
C                                                                            NIKOS.98    
C  absorber index   Gas   yes(1)/no (0)  vol. mixing ratio  C                NIKOS.99    
C                                                           C                NIKOS.100   
C      1            H2O      1           by model           C                NIKOS.101   
C      2            CO2      1           358ppmv            C                NIKOS.102   
C      3            O3       1           by model           C                NIKOS.103   
C      4            CH4      0           1.72ppmv           C                NIKOS.104   
C      5            N2O      0           312ppbv            C                NIKOS.105   
C      6          CO2(minor) 0           358ppmv            C                NIKOS.106   
C      7          O3(minor)  0           by model           C                NIKOS.107   
C      8          Halocarbon 0           797x10-14          C                NIKOS.108   
C                                                                            NIKOS.109   
       GAS(1)=1                                                              NIKOS.110   
       GAS(2)=1                                                              NIKOS.111   
       GAS(3)=1                                                              NIKOS.112   
       GAS(4)=0                                                              NIKOS.113   
       GAS(5)=0                                                              NIKOS.114   
       GAS(6)=0                                                              NIKOS.115   
       GAS(7)=0                                                              NIKOS.116   
       GAS(8)=0                                                              NIKOS.117   
C run time is 7% quicker with gasses 4-8 switched off (over 12 days)         NIKOS.118   
       VMRCO2=358.0E-6                                                       NIKOS.119   
       VMRCH4=1.72E-6                                                        NIKOS.120   
       VMRN2O=312.0E-9                                                       NIKOS.121   
       VMRHALO=7.97E-12                                                      NIKOS.122   
C READ namelists, overwrite defaults and write them out                      NIKOS.123   
       READ(7,INRADLW)                                                       NIKOS.124   
       WRITE(2,INRADLW)                                                      NIKOS.125   
      ENDIF                                                                  NIKOS.126   
      DO LHT=1,NRLEV                                                         NIKOS.127   
C MMR is mass mixing ratio of gases                                          NIKOS.128   
c       PCLD(LHT)=0.0      ! set SW cloud opotical depth                     NIKOS.129   
        PCLFR(LHT)=0.0      ! set SW cloud fraction                          NIKOS.130   
        PQLWP(LHT)=0.0      ! set SW cloud lwp                               NIKOS.131   
        MMR(1,LHT-1)=H2O(LHT)                                                NIKOS.132   
        MMR(2,LHT-1)=VMRCO2*(44.011/28.964)                                  NIKOS.133   
        MMR(3,LHT-1)=O3(LHT)                                                 NIKOS.134   
        MMR(4,LHT-1)=VMRCH4*(16.043/28.964)                                  NIKOS.135   
        MMR(5,LHT-1)=VMRN2O*(44.014/28.964)                                  NIKOS.136   
        MMR(6,LHT-1)=MMR(2,LHT-1)                                            NIKOS.137   
        MMR(7,LHT-1)=MMR(3,LHT-1)                                            NIKOS.138   
        MMR(8,LHT-1)=VMRHALO*(125.5/28.964)                                  NIKOS.139   
        PRES(LHT-1)=PR(LHT)                                                  NIKOS.140   
        TEMP(LHT-1)=T(LHT)                                                   NIKOS.141   
      ENDDO                                                                  NIKOS.142   
C Calculate pressures at flux levels                                         NIKOS.143   
                                                                             NIKOS.144   
      PFLUX(0)=PRES(0)/100.0                                                 NIKOS.145   
      DO ILAY=1,NLEV-1                                                       NIKOS.146   
         PFLUX(ILAY)=(PRES(ILAY)+PRES(ILAY+1))/200.0                         NIKOS.147   
      END DO                                                                 NIKOS.148   
      PFLUX(NLEV)=PRES(NLEV)/200.0                                           NIKOS.149   
      PDP(1)=0.5*(2*PRES(0)-PRES(1)-PRES(2))                                 NIKOS.150   
      DO ILAY=2,NLEV-1                                                       NIKOS.151   
         PDP(ILAY)=0.5*(PRES(ILAY-1)-PRES(ILAY+1))                           NIKOS.152   
      ENDDO                                                                  NIKOS.153   
      PDP(NLEV)=0.5*PRES(NLEV-1)                                             NIKOS.154   
                                                                             NIKOS.155   
C       GO TO 456    ! skip clouds                                           NIKOS.156   
C clouds                                                                     NIKOS.157   
      DO ICL=1,3     !low=1,3=high                                           NIKOS.158   
         CL(ICL)=0                                                           NIKOS.159   
         ICLIC=5-ICL !for ic 4=low,2=high,1=convective                       NIKOS.160   
                                                                             NIKOS.161   
C         IF (IC(ICLIC,1).GT.1) THEN                                         NIKOS.162   
         IF (CF(ICLIC,1).GT.0.0) THEN                                        NIKOS.163   
C Cloud present                                                              NIKOS.164   
           CL(ICL)=1                                                         NIKOS.165   
C single level cloud                                                         NIKOS.166   
           LEV=IC(ICLIC,1)                                                   NIKOS.167   
           BASCL(ICL)=PR(IC(ICLIC,1))                                        NIKOS.168   
           TOPCL(ICL)=PR(IC(ICLIC,1))                                        NIKOS.169   
           ACL(ICL)=CF(ICLIC,1)                                              NIKOS.170   
C cloud LWP is 1% super saturation in g/m^2                                  NIKOS.171   
           CF(ICLIC,2)=0.01*SVP(T(LEV))/PR(LEV)*                             NIKOS.172   
     $          622*PDP(LEV-1)/GA                                            NIKOS.173   
c           CF(ICLIC,2)=CF(ICLIC,2)*REAL(ICL)                                NIKOS.174   
           LWCCL(ICL)=CF(ICLIC,2)/1000.0  ! g- Kg convert                    NIKOS.175   
c sw cloud optical depth                                                     NIKOS.176   
c           PCLD(IC(ICLIC,1))=1.5*CF(ICLIC,2)/10.0*ACL(ICL)                  NIKOS.177   
           PCLFR(IC(ICLIC,1))=CF(ICLIC,1)                                    NIKOS.178   
           PQLWP(IC(ICLIC,1))=CF(ICLIC,2)                                    NIKOS.179   
        ENDIF                                                                NIKOS.180   
      ENDDO                                                                  NIKOS.181   
c convective cloud                                                           NIKOS.182   
      CL(0)=0                                                                NIKOS.183   
C      IF (IC(1,1).GT.1) THEN                                                NIKOS.184   
       IF (CF(1,1).gt.0.0) THEN                                              NIKOS.185   
         CL(0)=1                                                             NIKOS.186   
         ACL(0)=CF(1,1)                                                      NIKOS.187   
C         LEV=(IC(1,1)+IC(1,2))/2                                            NIKOS.188   
         LEV=IC(1,1)                                                         NIKOS.189   
C cloud LWP is 2% super saturation in g/m^2                                  NIKOS.190   
         CF(1,2)=0.01*SVP(T(LEV))/PR(LEV)*                                   NIKOS.191   
     $          622*PDP(LEV-1)/GA                                            NIKOS.192   
         ALWP=CF(1,2)                                                        NIKOS.193   
         BASCL(0)=PR(IC(1,1))                                                NIKOS.194   
         TOPCL(0)=PR(IC(1,2))                                                NIKOS.195   
c quarter cloud except in bottom level                                       NIKOS.196   
         DO ICL=IC(1,1)+1,IC(1,2)                                            NIKOS.197   
c            PCLD(ICL)=1.5* LWP/10.0* ACL(0)                                 NIKOS.198   
            PCLFR(ICL)=0.25*CF(1,1)                                          NIKOS.199   
            PQLWP(ICL)=ALWP                                                  NIKOS.200   
         ENDDO                                                               NIKOS.201   
            PCLFR(IC(1,1))=CF(1,1)                                           NIKOS.202   
            PQLWP(IC(1,1))=ALWP                                              NIKOS.203   
       ENDIF                                                                 NIKOS.204   
c      print *,'cloud cl ',cl                                                NIKOS.205   
c      print *,'cloud acl ',acl                                              NIKOS.206   
c      print *,'cloud bascl ',bascl                                          NIKOS.207   
c      print *,'cloud topcl ',topcl                                          NIKOS.208   
c       print *,'cloud lwccl ',lwccl                                         NIKOS.209   
c      print *,'cloud pcld ',pcld                                            NIKOS.210   
c         print *, 'l ',alwp                                                 NIKOS.211   
c       print *,pclfr                                                        NIKOS.212   
c       print *,pqlwp                                                        NIKOS.213   
                                                                             NIKOS.214   
 456   CONTINUE                                                              NIKOS.215   
C                                                                            NIKOS.216   
C call nikos LW scheme                                                       NIKOS.217   
      CALL IRRAD(GAS,CKD,NLEV,PRES,PFLUX,TEMP,MMR,CL,ACL,LWCCL,              NIKOS.218   
     $          BASCL,TOPCL,FUP,FDWN,FNET,PDP,LLBLM,GA)                      NIKOS.219   
                                                                             NIKOS.220   
C Setup SW code                                                              NIKOS.221   
      SOLC=1376.0     ! solar constant                                       NIKOS.222   
C      SOLC=1320.0     ! 4 % taken off!                                      NIKOS.223   
                                                                             NIKOS.224   
      LDIUR=.FALSE.   !Diurnally averaged if false                           NIKOS.225   
C                                                                            NIKOS.226   
       YCLOCK=3.14159      !time of day in radians                           NIKOS.227   
C       YCLOCK= (DOY-REAL(INT(DOY))*2.*3.14159                               NIKOS.228   
C                                                                            NIKOS.229   
      CALL SOLANG(LDIUR,DOY,YCLOCK,ALAT,ALON,AMU0,RDAYL,CDISSEM)             NIKOS.230   
C                                                                            NIKOS.231   
c call to L+H                                                                NIKOS.232   
                                                                             NIKOS.233   
      ZSCT=SOLC*CDISSEM   ! Solar const * earth-sun distance                 NIKOS.234   
      PSOL=ZSCT*RDAYL     ! * fractional day length                          NIKOS.235   
                                                                             NIKOS.236   
c CALL SW scheme                                                             NIKOS.237   
      ZCARDI=MMR(2,1)                                                        NIKOS.238   
      CALL RADSW(T,H2O,O3,PCLFR,PQLWP,AMU0,                                  NIKOS.239   
     :              ZCARDI,PSOL,SWDP,PFLUX,SWALB,FLS,GA,GASCON)              NIKOS.240   
                                                                             NIKOS.241   
C WORKS OUT FLUXES                                                           NIKOS.242   
C SW                                                                         NIKOS.243   
      RFLUXES(1,1,1)=PSOL*AMU0   ! SW down top                               NIKOS.244   
      RFLUXES(1,1,2)=FLS(1)/(1.0-SWALB)   ! SW down bottom                   NIKOS.245   
      RFLUXES(1,2,1)=RFLUXES(1,1,1)-FLS(NRLEV+1)  ! SW up top                NIKOS.246   
      RFLUXES(1,2,2)=RFLUXES(1,1,2)*SWALB   ! SW up bottom                   NIKOS.247   
C LW                                                                         NIKOS.248   
      RFLUXES(2,1,1)=FDWN(NLEV)   ! LW down top                              NIKOS.249   
      RFLUXES(2,1,2)=FDWN(0)       ! LW down bottom                          NIKOS.250   
      RFLUXES(2,2,1)=FUP(NLEV)       ! LW up top                             NIKOS.251   
      RFLUXES(2,2,2)=FUP(0)   ! LW up bottom                                 NIKOS.252   
                                                                             NIKOS.253   
C OUTPUT                                                                     NIKOS.254   
                                                                             NIKOS.255   
      GRCP=(GA/CPD)*24*3600 ! g/Cp *24*3600                                  NIKOS.256   
                                                                             NIKOS.257   
C Calculate heating rates                                                    NIKOS.258   
                                                                             NIKOS.259   
      DO LHT=2,NRLEV                                                         NIKOS.260   
         HTSW(LHT)=GRCP*(FLS(LHT+1)-FLS(LHT))/SWDP(LHT)                      NIKOS.261   
         HTLW(LHT)=-GRCP*(FNET(LHT-1)-FNET(LHT-2))/SWDP(LHT)                 NIKOS.262   
      END DO                                                                 NIKOS.263   
c      WRITE(63,2010)'UPWARD FLUX (Wm-2)','DOWNWARD FLUX (Wm-2)',            NIKOS.264   
c     $              'NET FLUX (Wm-2)', ' SW NET FLUX (Wm-2)'                NIKOS.265   
c 2010 FORMAT(11X,A18,5X,A20,5X,A15,5x,A24)                                  NIKOS.266   
c      WRITE(63,*)                                                           NIKOS.267   
c                                                                            NIKOS.268   
c      DO ILAY=NLEV,0,-1                                                     NIKOS.269   
c         WRITE(63,2013)PFLUX(ILAY),FUP(ILAY),                               NIKOS.270   
c     $        FDWN(ILAY),FNET(ILAY),FLS(ILAY+1)                             NIKOS.271   
c     $                                                                      NIKOS.272   
c 2013    FORMAT(2X,F10.3,5X,F10.5,10X,F10.5,10X,F10.5,10X,F10.5)            NIKOS.273   
c      END DO                                                                NIKOS.274   
c                                                                            NIKOS.275   
c      WRITE(63,2023)'PRESSURE (MB)','HEATING RATES: SW (K/DAY)'             NIKOS.276   
c     $     ,'LW (K/DAY)'                                                    NIKOS.277   
c 2023 FORMAT(1X,A18,1X,A30,x,A10)                                           NIKOS.278   
c      DO LHT=NRLEV,1,-1                                                     NIKOS.279   
c         WRITE(63,2020) PR(LHT)/100.0,HTSW(LHT),HTLW(LHT)                   NIKOS.280   
c 2020    FORMAT(5X,F10.3,X,E12.5,X,E12.5)                                   NIKOS.281   
c      END DO                                                                NIKOS.282   
                                                                             NIKOS.283   
                                                                             NIKOS.284   
      RETURN                                                                 NIKOS.285   
      END                                                                    NIKOS.286   
                                                                             NIKOS.287   
      SUBROUTINE SOLANG (LDIUR,DOY,YCLOCK,ALAT,alon,                         NIKOS.288   
     :     AMU0,RDAYL,CDISSEM)                                               NIKOS.289   
C**********************************************************                  NIKOS.290   
C             SUBROUTINE SOLANG                                              NIKOS.291   
C**********************************************************                  NIKOS.292   
C Pm.M. deF   27-1-98                                                        NIKOS.293   
C inputs                                                                     NIKOS.294   
C LDIUR  ! Logical for diurnal average                                       NIKOS.295   
C DOY    ! Julian day of year                                                NIKOS.296   
C YCLOCK !                                                                   NIKOS.297   
C ALAT   ! Latitude in degrees                                               NIKOS.298   
C ALON   ! Longitude in degrees                                              NIKOS.299   
C outputs                                                                    NIKOS.300   
C AMU0   ! Cosine of solar zenith angle                                      NIKOS.301   
C RDAYL  ! Fractional day length                                             NIKOS.302   
C CDISSEM  ! Suns relative distance as a fraction                            NIKOS.303   
                                                                             NIKOS.304   
C**** *SOLANG* - FOR SOLAR ZENITH ANGLE AND RELATIVE DAYLENGTH.              NIKOS.305   
C                                                                            NIKOS.306   
C     PURPOSE.                                                               NIKOS.307   
C     --------                                                               NIKOS.308   
C                                                                            NIKOS.309   
C          THIS ROUTINE GIVES DIFFERENT RESULTS DEPENDING ON A LOGICAL       NIKOS.310   
C     SWITCH. IF LDIUR IS TRUE ONE OBTAINS ACTUAL SOLAR ZENITH ANGLES        NIKOS.311   
C     AND VALUES OF ONE OR ZERO DEPENDING ON THE SIGN OF THE FORMER. IF      NIKOS.312   
C     LDIUR IS FALSE ONE GETS THE SAME ANSWERS AT ALL POINTS, I.E. MEAN      NIKOS.313   
C     VALUE OF THE DAYTIME SOLAR ZENITH ANGLE AND RELATIVE LENGTH OF         NIKOS.314   
C     THE DAY.                                                               NIKOS.315   
C                                                                            NIKOS.316   
C   LDIUR .... true: sun at time, false: diurnally averaged                  NIKOS.317   
C                                                                            NIKOS.318   
C     ----------                                                             NIKOS.319   
C                                                                            NIKOS.320   
      REAL DOY,ALAT,RDAYL,AMU0,YCLOCK,ALON,XLON                              NIKOS.321   
C                                                                            NIKOS.322   
      REAL XLAT,YTIME,YEARL,API,ZC1YT,ZS1YT,ZC2YT,ZS2YT,CDISSEM              NIKOS.323   
      INTEGER JDAY                                                           NIKOS.324   
                                                                             NIKOS.325   
      REAL ZMU0(128),ZRDAYL(128)                                             NIKOS.326   
      LOGICAL LDIUR,LO                                                       NIKOS.327   
      REAL ZCDIS(5),ZCEQT(5),ZCDEC(5)                                        NIKOS.328   
      DATA ZCDIS/+1.000110,+0.034221,+0.001280,+0.000719,+0.000077/          NIKOS.329   
      DATA CRAE/+0.1277E-02/                                                 NIKOS.330   
      DATA ZCDEC/+0.006918,-0.399912,+0.070257,-0.006758,+0.000907/          NIKOS.331   
      DATA ZCEQT/+0.000075,+0.001868,-0.032077,-0.014615,-0.040849/          NIKOS.332   
                                                                             NIKOS.333   
                                                                             NIKOS.334   
      YEARL=360.0   ! 360 DAY YEAR                                           NIKOS.335   
      API=2.0*ASIN(1.0)                                                      NIKOS.336   
      XLAT=API*alat/180.0                                                    NIKOS.337   
      XLON=API*ALON/180.0                                                    NIKOS.338   
      JDAY=INT(DOY)                                                          NIKOS.339   
      YTIME = (REAL(JDAY-1)+YCLOCK/2./API)/YEARL*2.*API                      NIKOS.340   
C                                                                            NIKOS.341   
C diurnal cycle part                                                         NIKOS.342   
C                                                                            NIKOS.343   
C*    COMPUTATIONAL CONSTANTS.                                               NIKOS.344   
C     ------------- ----------                                               NIKOS.345   
C                                                                            NIKOS.346   
      ZC1YT=COS(YTIME)                                                       NIKOS.347   
      ZS1YT=SIN(YTIME)                                                       NIKOS.348   
      ZC2YT=ZC1YT**2-ZS1YT**2                                                NIKOS.349   
      ZS2YT=2.*ZS1YT*ZC1YT                                                   NIKOS.350   
      CDISSEM=ZCDIS(1)+ZCDIS(2)*ZC1YT+ZCDIS(3)*ZS1YT+ZCDIS(4)*ZC2YT          NIKOS.351   
     *       +ZCDIS(5)*ZS2YT                                                 NIKOS.352   
C                                                                            NIKOS.353   
      ZCRAE=CRAE*(CRAE+2.)                                                   NIKOS.354   
C     ------------------------------------------------------------------     NIKOS.355   
C*         2.     SOLAR ANGLE AND OZONE/AEROSOL PARAMETERS COMPUTATIONS.     NIKOS.356   
C                 ----- ----- --- ------------- ---------- -------------     NIKOS.357   
C                                                                            NIKOS.358   
 200  CONTINUE                                                               NIKOS.359   
C                                                                            NIKOS.360   
C*         2.1     INTRODUCE THE LATITUDE DEPENDENCY.                        NIKOS.361   
      ZSIN = SIN(XLAT)                                                       NIKOS.362   
      ZSQCST = SQRT(1.0-ZSIN**2)                                             NIKOS.363   
      ZDECLI=ZCDEC(1)+ZCDEC(2)*ZC1YT+ZCDEC(3)*ZS1YT+ZCDEC(4)*ZC2YT           NIKOS.364   
     *       +ZCDEC(5)*ZS2YT                                                 NIKOS.365   
      ZEQTIM=ZCEQT(1)+ZCEQT(2)*ZC1YT+ZCEQT(3)*ZS1YT+ZCEQT(4)*ZC2YT           NIKOS.366   
     *       +ZCEQT(5)*ZS2YT                                                 NIKOS.367   
      ZZEN1=SIN(ZDECLI)                                                      NIKOS.368   
      ZZEN2=COS(ZDECLI)*COS(YCLOCK+ZEQTIM)                                   NIKOS.369   
      ZZEN3=COS(ZDECLI)*SIN(YCLOCK+ZEQTIM)                                   NIKOS.370   
C                                                                            NIKOS.371   
      ZTIM1 = ZZEN1 * ZSIN                                                   NIKOS.372   
      ZTIM2 =-ZZEN2 * ZSQCST                                                 NIKOS.373   
      ZTIM3 = ZZEN3 * ZSQCST                                                 NIKOS.374   
C                                                                            NIKOS.375   
C     ---------------------------------------------------------------        NIKOS.376   
C*         2.     COMPUTATIONS IF DIURNAL CYCLE "ON".                        NIKOS.377   
C                 ------------ -- ------- ----- -----                        NIKOS.378   
C                                                                            NIKOS.379   
c      COSLON=1.0                                                            NIKOS.380   
c      SINLON=0.0                                                            NIKOS.381   
      COSLON=COS(XLON)                                                       NIKOS.382   
      SINLON=SIN(XLON)                                                       NIKOS.383   
      IF(LDIUR) THEN                                                         NIKOS.384   
        AMU0=ZTIM1+ZTIM2*COSLON+ZTIM3*SINLON                                 NIKOS.385   
        IF(AMU0.GE.0.)THEN                                                   NIKOS.386   
          AMU0=AMU0                                                          NIKOS.387   
          RDAYL=1.0                                                          NIKOS.388   
        ELSE                                                                 NIKOS.389   
          AMU0=0.0                                                           NIKOS.390   
          RDAYL=0.0                                                          NIKOS.391   
        ENDIF                                                                NIKOS.392   
C                 ------------------------------------                       NIKOS.393   
C*         3.     COMPUTATIONS IF DIURNAL CYCLE "OFF".                       NIKOS.394   
C                 ------------ -- ------- ----- ------                       NIKOS.395   
      ELSE                                                                   NIKOS.396   
        DO 301 JLON=1,128                                                    NIKOS.397   
          ZL=2.*API*(JLON-1.)/128.                                           NIKOS.398   
          ZMU0(JLON)=ZTIM1+ZTIM2*COS(ZL)+ZTIM3*SIN(ZL)                       NIKOS.399   
          IF(ZMU0(JLON).GE.0.)THEN                                           NIKOS.400   
            ZMU0(JLON)=ZMU0(JLON)                                            NIKOS.401   
            ZRDAYL(JLON)=1.0                                                 NIKOS.402   
          ELSE                                                               NIKOS.403   
            ZMU0(JLON)=0.0                                                   NIKOS.404   
            ZRDAYL(JLON)=0.0                                                 NIKOS.405   
          ENDIF                                                              NIKOS.406   
  301   CONTINUE                                                             NIKOS.407   
        ZS1=SIGMA2(128,ZMU0(1),1)                                            NIKOS.408   
        ZS2=SIGMA2(128,ZRDAYL(1),1)                                          NIKOS.409   
        IF(ZS2.NE.0.) THEN                                                   NIKOS.410   
          ZS1=ZS1/ZS2                                                        NIKOS.411   
          ZS2=ZS2/128.                                                       NIKOS.412   
        END IF                                                               NIKOS.413   
        AMU0=ZS1                                                             NIKOS.414   
        RDAYL=ZS2                                                            NIKOS.415   
      END IF                                                                 NIKOS.416   
C                                                                            NIKOS.417   
      AMU0=CRAE/(SQRT(AMU0**2+ZCRAE)-AMU0)                                   NIKOS.418   
                                                                             NIKOS.419   
      RETURN                                                                 NIKOS.420   
      END                                                                    NIKOS.421   
C*************************************                                       NIKOS.422   
C   FUNCTION SIGMA2                                                          NIKOS.423   
C*************************************                                       NIKOS.424   
C                                                                            NIKOS.425   
       REAL FUNCTION SIGMA2(N, SX, INCX)                                     NIKOS.426   
C                                                                            NIKOS.427   
       INTEGER N, INCX, I                                                    NIKOS.428   
       REAL SX(N*INCX)                                                       NIKOS.429   
C                                                                            NIKOS.430   
       SIGMA2 = 0.                                                           NIKOS.431   
       DO 1 I=1,N                                                            NIKOS.432   
          SIGMA2 = SIGMA2 + SX(I*INCX)                                       NIKOS.433   
 1     CONTINUE                                                              NIKOS.434   
C                                                                            NIKOS.435   
       END                                                                   NIKOS.436   
c*************************************                                       NIKOS.437   
      REAL FUNCTION SVP(T)                                                   NIKOS.438   
                                                                             NIKOS.439   
C Calculates the saturation vapour pressure given T, using Murray's          NIKOS.440   
C formulae. If t < 253 K assume saturation w.r.t. ice                        NIKOS.441   
C SVP returned in Pascals                                                    NIKOS.442   
                                                                             NIKOS.443   
      IMPLICIT NONE                                                          NIKOS.444   
                                                                             NIKOS.445   
      REAL T                                                                 NIKOS.446   
                                                                             NIKOS.447   
      IF(T.GE.253.0)THEN                                                     NIKOS.448   
        SVP=611*EXP(17.27*(T-273.16)/(T-35.86))                              NIKOS.449   
      ELSE                                                                   NIKOS.450   
        SVP=611*EXP(21.87*(T-273.16)/(T-7.66))                               NIKOS.451   
      ENDIF                                                                  NIKOS.452   
                                                                             NIKOS.453   
      END                                                                    NIKOS.454   
                                                                             NIKOS.455   
