      SUBROUTINE INI_NETCDF                                                  MYNETCDF.2     
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    
C                                                                            BATS.2     
C     Constant arrays and variables associated with time and vertical        BATS.3     
C     differencing. Also counters.                                           BATS.4     
C                                                                            BATS.5     
      COMMON/BATS/  BM1(IDE),AK(NNP),AQ(NL2),G(NL2),TAU(NL2)                 BATS.6     
     +              ,KOUNT,KITS,KSTART,KTOTAL,KRUN,BEGDAY,ITSPD              BATS.7     
     +              ,DELT,DELT2,CV,CG,CT,CQ,PNU,PNU2,PNU21                   BATS.8     
     +              ,NTRACO,CTRA(NTRAC),KOLOUR(NTRAC),RGG(NL2)               BATS.9     
     +              ,BEGDOY,DOY                                              BATS.10    
C                                                                            BATS.11    
C                                                                            OUTCON.2     
C     Switches counters and constants controlling type and frequency of      OUTCON.3     
C     model output                                                           OUTCON.4     
C                                                                            OUTCON.5     
      COMMON/OUTCON/RNTAPE,NCOEFF,NLAT,INLAT,INSPC                           OUTCON.6     
     +              ,RNTAPO                                                  OUTCON.7     
     +              ,KOUNTP,KOUNTE,KOUNTH,KOUNTR                             OUTCON.8     
     +              ,KOUTP,KOUTE,KOUTH,KOUTR,DAY                             OUTCON.9     
     +              ,SQR2,RSQR2,EAM1,EAM2,TOUT1,TOUT2,RMG                    OUTCON.10    
     +              ,LSPO(NL),LGPO(NL)                                       OUTCON.11    
     $              ,LSHIST,LMINIH                                           OUTCON.12    
      LOGICAL LSHIST,LMINIH                                                  OUTCON.13    
      LOGICAL LSPO,LGPO                                                      OUTCON.14    
C                                                                            OUTCON.15    
C                                                                            LEGAU.2     
C     Legendre polynomials and information about gaussian latitudes          LEGAU.3     
C                                                                            LEGAU.4     
      COMMON/LEGAU/ ALPJ(MJP),DALPJ(MJP)                                     LEGAU.5     
     +              ,ALP(NWJ2,2,JGL),DALP(NWJ2,2,JGL)                        LEGAU.6     
     +              ,RLP(NWJ2,2,JGL),RDLP(NWJ2,2,JGL)                        LEGAU.7     
     +              ,SI(JGG),CS(JGG),SISQ(JGG),CSSQ(JGG),SECSQ(JGG)          LEGAU.8     
     +              ,ALAT(JGG),GWT(JGG),AW(JGG),JH,JL,JINC                   LEGAU.9     
C                                                                            LEGAU.10    
c                                                                            NETDATA.2     
      integer nmaxdims,nall                                                  NETDATA.3     
      parameter(nmaxdims=4,nall=10)                                          NETDATA.4     
      integer ndim,nvar,natts(nall),nattsvar(nall),                          NETDATA.5     
     :        vdims(nall),vadims(nmaxdims,nall),                             NETDATA.6     
     :        ndims(nall)                                                    NETDATA.7     
      character*200 dimname(nall),varname(nall),                             NETDATA.8     
     :              attdimname(2,nmaxdims,nall),                             NETDATA.9     
     :              attvarname(2,nmaxdims,nall)                              NETDATA.10    
      integer nc1,iddim1(nall),idvar1(nall)                                  NETDATA.11    
      common/netcdfvars/nc1,iddim1,idvar1                                    NETDATA.12    
c                                                                            NETDATA.13    
c                                                                            MYNETCDF.10    
      real xcoord(mg),ycoord(jg*nhem),zcoord(nl),tcoord(10000)               MYNETCDF.11    
      character*200 fname1                                                   MYNETCDF.12    
c                                                                            MYNETCDF.13    
      do i=1,mg                                                              MYNETCDF.14    
         xcoord(i)=(i-1)*360.0/real(mg)                                      MYNETCDF.15    
      end do                                                                 MYNETCDF.16    
c                                                                            MYNETCDF.17    
      do j=1,jg*nhem                                                         MYNETCDF.18    
         ycoord(j)=alat(j)                                                   MYNETCDF.19    
      end do                                                                 MYNETCDF.20    
c                                                                            MYNETCDF.21    
      do l=1,nl                                                              MYNETCDF.22    
         zcoord(l)=1000.0*sigma(l)                                           MYNETCDF.23    
      end do                                                                 MYNETCDF.24    
c                                                                            MYNETCDF.25    
      itime=(ktotal-kstart)/kountp+1                                         MYNETCDF.26    
      print*,' Number of output times = ',itime                              MYNETCDF.27    
      do i=1,itime                                                           MYNETCDF.28    
         tcoord(i)=i                                                         MYNETCDF.29    
      end do                                                                 MYNETCDF.30    
c                                                                            MYNETCDF.31    
      call setup_nc(mg,jg*nhem,nl,itime,                                     MYNETCDF.32    
     :              nmaxdims,nall,                                           MYNETCDF.33    
     :              ndim,nvar,natts,nattsvar,vdims,                          MYNETCDF.34    
     :              vadims,ndims,                                            MYNETCDF.35    
     :              dimname,varname,attdimname,                              MYNETCDF.36    
     :              attvarname)                                              MYNETCDF.37    
c                                                                            MYNETCDF.38    
c changing to my directory structure - marc 12/3/03                          MARC.1     
c      fname1='/home/swsvalde/igcm.nc'                                       MARC.2     
      fname1='/home/marc/igcm.nc'                                            MARC.3     
      ifname1=lnsig(fname1)                                                  MYNETCDF.40    
c                                                                            MYNETCDF.41    
      call ininc(fname1(1:ifname1),                                          MYNETCDF.42    
     :           nmaxdims,ndim,nvar,                                         MYNETCDF.43    
     :           natts,nattsvar,                                             MYNETCDF.44    
     :           vdims,vadims,ndims,                                         MYNETCDF.45    
     :           dimname,varname,                                            MYNETCDF.46    
     :           attdimname,attvarname,                                      MYNETCDF.47    
     :           nc1,iddim1,idvar1)                                          MYNETCDF.48    
c                                                                            MYNETCDF.49    
      print*,' ready to write rest '                                         MYNETCDF.50    
c                                                                            MYNETCDF.51    
      call writedim(nc1,iddim1(1),xcoord)                                    MYNETCDF.52    
      call writedim(nc1,iddim1(2),ycoord)                                    MYNETCDF.53    
      call writedim(nc1,iddim1(3),zcoord)                                    MYNETCDF.54    
      call writedim(nc1,iddim1(4),tcoord)                                    MYNETCDF.55    
c                                                                            MYNETCDF.56    
      print*,' Finished writing dimensions '                                 MYNETCDF.57    
c                                                                            MYNETCDF.58    
      return                                                                 MYNETCDF.59    
      end                                                                    MYNETCDF.60    
c                                                                            MYNETCDF.61    
      SUBROUTINE END_NETCDF                                                  MYNETCDF.62    
c                                                                            NETDATA.2     
      integer nmaxdims,nall                                                  NETDATA.3     
      parameter(nmaxdims=4,nall=10)                                          NETDATA.4     
      integer ndim,nvar,natts(nall),nattsvar(nall),                          NETDATA.5     
     :        vdims(nall),vadims(nmaxdims,nall),                             NETDATA.6     
     :        ndims(nall)                                                    NETDATA.7     
      character*200 dimname(nall),varname(nall),                             NETDATA.8     
     :              attdimname(2,nmaxdims,nall),                             NETDATA.9     
     :              attvarname(2,nmaxdims,nall)                              NETDATA.10    
      integer nc1,iddim1(nall),idvar1(nall)                                  NETDATA.11    
      common/netcdfvars/nc1,iddim1,idvar1                                    NETDATA.12    
c                                                                            NETDATA.13    
c                                                                            MYNETCDF.64    
      print*,' calling netcdf '                                              MYNETCDF.65    
      call closenc(nc1)                                                      MYNETCDF.66    
c                                                                            MYNETCDF.67    
      return                                                                 MYNETCDF.68    
      end                                                                    MYNETCDF.69    
c                                                                            MYNETCDF.70    
      subroutine setup_nc(nlon,nlat,nl,ntime,                                MYNETCDF.71    
     :                 nmaxdims,nall,                                        MYNETCDF.72    
     :                 ndim,nvar,natts,nattsvar,vdims,                       MYNETCDF.73    
     :                 vadims,ndims,                                         MYNETCDF.74    
     :                 dimname,varname,attdimname,                           MYNETCDF.75    
     :                 attvarname)                                           MYNETCDF.76    
      implicit none                                                          MYNETCDF.77    
      integer nlon,nlat,nl,ntime,nmaxdims,nall                               MYNETCDF.78    
      integer ndim,nvar,natts(nall),nattsvar(nall),                          MYNETCDF.79    
     :        vdims(nall),vadims(nmaxdims,nall),                             MYNETCDF.80    
     :        ndims(nall)                                                    MYNETCDF.81    
      character*200 dimname(nall),varname(nall),                             MYNETCDF.82    
     :              attdimname(2,nmaxdims,nall),                             MYNETCDF.83    
     :              attvarname(2,nmaxdims,nall)                              MYNETCDF.84    
c                                                                            MYNETCDF.85    
      integer loc_dim                                                        MYNETCDF.86    
c                                                                            MYNETCDF.87    
c     This sets up a file similar to .pc files                               MYNETCDF.88    
c                                                                            MYNETCDF.89    
      ndim=0                                                                 MYNETCDF.90    
c                                                                            MYNETCDF.91    
      ndim=ndim+1                                                            MYNETCDF.92    
      dimname(ndim)='longitude'                                              MYNETCDF.93    
      ndims(ndim)=nlon                                                       MYNETCDF.94    
      natts(ndim)=2                                                          MYNETCDF.95    
      attdimname(1,1,ndim)='long_name'                                       MYNETCDF.96    
      attdimname(2,1,ndim)='longitude'                                       MYNETCDF.97    
      attdimname(1,2,ndim)='units'                                           MYNETCDF.98    
      attdimname(2,2,ndim)='degrees_east'                                    MYNETCDF.99    
c                                                                            MYNETCDF.100   
      ndim=ndim+1                                                            MYNETCDF.101   
      dimname(ndim)='latitude'                                               MYNETCDF.102   
      ndims(ndim)=nlat                                                       MYNETCDF.103   
      natts(ndim)=2                                                          MYNETCDF.104   
      attdimname(1,1,ndim)='long_name'                                       MYNETCDF.105   
      attdimname(2,1,ndim)='latitude'                                        MYNETCDF.106   
      attdimname(1,2,ndim)='units'                                           MYNETCDF.107   
      attdimname(2,2,ndim)='degrees_north'                                   MYNETCDF.108   
c                                                                            MYNETCDF.109   
      ndim=ndim+1                                                            MYNETCDF.110   
      dimname(ndim)='p'                                                      MYNETCDF.111   
      ndims(ndim)=nl                                                         MYNETCDF.112   
      natts(ndim)=2                                                          MYNETCDF.113   
      attdimname(1,1,ndim)='units'                                           MYNETCDF.114   
      attdimname(2,1,ndim)='mb'                                              MYNETCDF.115   
      attdimname(1,2,ndim)='positive'                                        MYNETCDF.116   
      attdimname(2,2,ndim)='down'                                            MYNETCDF.117   
c                                                                            MYNETCDF.118   
      ndim=ndim+1                                                            MYNETCDF.119   
      dimname(ndim)='time'                                                   MYNETCDF.120   
      ndims(ndim)=ntime                                                      MYNETCDF.121   
      natts(ndim)=2                                                          MYNETCDF.122   
      attdimname(1,1,ndim)='long_name'                                       MYNETCDF.123   
      attdimname(2,1,ndim)='time'                                            MYNETCDF.124   
      attdimname(1,2,ndim)='units'                                           MYNETCDF.125   
      attdimname(2,2,ndim)='days or months'                                  MYNETCDF.126   
c                                                                            MYNETCDF.127   
      nvar=1                                                                 MYNETCDF.128   
      varname(nvar)='zonal_wind'                                             MYNETCDF.129   
      vdims(nvar)=4                                                          MYNETCDF.130   
      vadims(1,nvar)=loc_dim('longitude',dimname,nall)                       MYNETCDF.131   
      vadims(2,nvar)=loc_dim('latitude',dimname,nall)                        MYNETCDF.132   
      vadims(3,nvar)=loc_dim('p',dimname,nall)                               MYNETCDF.133   
      vadims(4,nvar)=loc_dim('time',dimname,nall)                            MYNETCDF.134   
      nattsvar(nvar)=2                                                       MYNETCDF.135   
      attvarname(1,1,nvar)='long_name'                                       MYNETCDF.136   
      attvarname(2,1,nvar)=                                                  MYNETCDF.137   
     :   'Zonal Wind'                                                        MYNETCDF.138   
      attvarname(1,2,nvar)='units'                                           MYNETCDF.139   
      attvarname(2,2,nvar)='ms-1'                                            MYNETCDF.140   
c                                                                            MYNETCDF.141   
      nvar=nvar+1                                                            MYNETCDF.142   
      varname(nvar)='temp'                                                   MYNETCDF.143   
      vdims(nvar)=4                                                          MYNETCDF.144   
      vadims(1,nvar)=loc_dim('longitude',dimname,nall)                       MYNETCDF.145   
      vadims(2,nvar)=loc_dim('latitude',dimname,nall)                        MYNETCDF.146   
      vadims(3,nvar)=loc_dim('p',dimname,nall)                               MYNETCDF.147   
      vadims(4,nvar)=loc_dim('time',dimname,nall)                            MYNETCDF.148   
      nattsvar(nvar)=2                                                       MYNETCDF.149   
      attvarname(1,1,nvar)='long_name'                                       MYNETCDF.150   
      attvarname(2,1,nvar)=                                                  MYNETCDF.151   
     :   'Temperature'                                                       MYNETCDF.152   
      attvarname(1,2,nvar)='units'                                           MYNETCDF.153   
      attvarname(2,2,nvar)='K'                                               MYNETCDF.154   
c                                                                            MYNETCDF.155   
      nvar=nvar+1                                                            MYNETCDF.156   
      varname(nvar)='convrain'                                               MYNETCDF.157   
      vdims(nvar)=3                                                          MYNETCDF.158   
      vadims(1,nvar)=loc_dim('longitude',dimname,nall)                       MYNETCDF.159   
      vadims(2,nvar)=loc_dim('latitude',dimname,nall)                        MYNETCDF.160   
      vadims(3,nvar)=loc_dim('time',dimname,nall)                            MYNETCDF.161   
      nattsvar(nvar)=2                                                       MYNETCDF.162   
      attvarname(1,1,nvar)='long_name'                                       MYNETCDF.163   
      attvarname(2,1,nvar)=                                                  MYNETCDF.164   
     :   'Convective Rainfall'                                               MYNETCDF.165   
      attvarname(1,2,nvar)='units'                                           MYNETCDF.166   
      attvarname(2,2,nvar)='unknown'                                         MYNETCDF.167   
c                                                                            MYNETCDF.168   
      nvar=nvar+1                                                            MYNETCDF.169   
      varname(nvar)='lscalerain'                                             MYNETCDF.170   
      vdims(nvar)=3                                                          MYNETCDF.171   
      vadims(1,nvar)=loc_dim('longitude',dimname,nall)                       MYNETCDF.172   
      vadims(2,nvar)=loc_dim('latitude',dimname,nall)                        MYNETCDF.173   
      vadims(3,nvar)=loc_dim('time',dimname,nall)                            MYNETCDF.174   
      nattsvar(nvar)=2                                                       MYNETCDF.175   
      attvarname(1,1,nvar)='long_name'                                       MYNETCDF.176   
      attvarname(2,1,nvar)=                                                  MYNETCDF.177   
     :   'Large Scale Rainfall'                                              MYNETCDF.178   
      attvarname(1,2,nvar)='units'                                           MYNETCDF.179   
      attvarname(2,2,nvar)='unknown'                                         MYNETCDF.180   
c                                                                            MYNETCDF.181   
      return                                                                 MYNETCDF.182   
      end                                                                    MYNETCDF.183   
c                                                                            MYNETCDF.184   
      subroutine netout2                                                     MYNETCDF.185   
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    
      PARAMETER(RAD=180./PI)                                                 MYNETCDF.188   
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    
C                                                                            BATS.2     
C     Constant arrays and variables associated with time and vertical        BATS.3     
C     differencing. Also counters.                                           BATS.4     
C                                                                            BATS.5     
      COMMON/BATS/  BM1(IDE),AK(NNP),AQ(NL2),G(NL2),TAU(NL2)                 BATS.6     
     +              ,KOUNT,KITS,KSTART,KTOTAL,KRUN,BEGDAY,ITSPD              BATS.7     
     +              ,DELT,DELT2,CV,CG,CT,CQ,PNU,PNU2,PNU21                   BATS.8     
     +              ,NTRACO,CTRA(NTRAC),KOLOUR(NTRAC),RGG(NL2)               BATS.9     
     +              ,BEGDOY,DOY                                              BATS.10    
C                                                                            BATS.11    
C                                                                            GRIDPP.2     
C     Array ordering in GRIDP must correspond to that in SPECTR.             GRIDPP.3     
C     Real arrays: multi-level arrays are 2-dimensional.                     GRIDPP.4     
C     the variables have been renamed to coincide with                       GRIDPP.5     
C     variable names in bgcm5 DGRMLT                                         GRIDPP.6     
C                                                                            GRIDPP.7     
C swapped round VLNG and UNLG to check                                       GRIDPP.8     
      COMMON/GRIDP/ CHIG(IGC,NL),SFG(IGC,NL),UG(IGC,NL),VG(IGC,NL)           GRIDPP.9     
     :              ,TTVD(IGC,NL),QTVD(IGC,NL),TG(IGC,NL)                    GRIDPP.10    
     :              ,TRAG(IGC,NL,NTRAC)                                      GRIDPP.11    
     :              ,PLG(IGC),TYBL(IGC),TXBL(IGC)                            GRIDPP.12    
     :              ,SPG(IGC),VPG(IGC),TTRD(IGC,NL)                          GRIDPP.13    
     :              ,TNLG(IGC,NL),TRANLG(IGC,NL,NTRAC),UNLG(IGC,NL)          GRIDPP.14    
     :              ,VNLG(IGC,NL),TTLR(IGC,NL),UTRAG(IGC,NL,NTRAC)           GRIDPP.15    
     :              ,TTCR(IGC,NL),VTRAG(IGC,NL,NTRAC)                        GRIDPP.16    
     :              ,UTVD(IGC,NL),VTVD(IGC,NL)                               GRIDPP.17    
     :         ,ASSBL(IGC),ASHBL(IGC),ASLBL(IGC),ARRCR(IGC),ARRLR(IGC)       GRIDPP.18    
     :         ,arflux(igc,6),asfld(igc,6),acld(igc,4)                       GRIDPP.19    
     :         ,SSBL(IGC),SHBL(IGC),SLBL(IGC),RRCR(IGC),RRLR(IGC)            GRIDPP.20    
     :         ,rflux(igc,6),sfld(igc,6),cld(igc,4)                          GRIDPP.21    
C                                                                            GRIDPP.22    
C                                                                            LEGAU.2     
C     Legendre polynomials and information about gaussian latitudes          LEGAU.3     
C                                                                            LEGAU.4     
      COMMON/LEGAU/ ALPJ(MJP),DALPJ(MJP)                                     LEGAU.5     
     +              ,ALP(NWJ2,2,JGL),DALP(NWJ2,2,JGL)                        LEGAU.6     
     +              ,RLP(NWJ2,2,JGL),RDLP(NWJ2,2,JGL)                        LEGAU.7     
     +              ,SI(JGG),CS(JGG),SISQ(JGG),CSSQ(JGG),SECSQ(JGG)          LEGAU.8     
     +              ,ALAT(JGG),GWT(JGG),AW(JGG),JH,JL,JINC                   LEGAU.9     
C                                                                            LEGAU.10    
C                                                                            OUTCON.2     
C     Switches counters and constants controlling type and frequency of      OUTCON.3     
C     model output                                                           OUTCON.4     
C                                                                            OUTCON.5     
      COMMON/OUTCON/RNTAPE,NCOEFF,NLAT,INLAT,INSPC                           OUTCON.6     
     +              ,RNTAPO                                                  OUTCON.7     
     +              ,KOUNTP,KOUNTE,KOUNTH,KOUNTR                             OUTCON.8     
     +              ,KOUTP,KOUTE,KOUTH,KOUTR,DAY                             OUTCON.9     
     +              ,SQR2,RSQR2,EAM1,EAM2,TOUT1,TOUT2,RMG                    OUTCON.10    
     +              ,LSPO(NL),LGPO(NL)                                       OUTCON.11    
     $              ,LSHIST,LMINIH                                           OUTCON.12    
      LOGICAL LSHIST,LMINIH                                                  OUTCON.13    
      LOGICAL LSPO,LGPO                                                      OUTCON.14    
C                                                                            OUTCON.15    
c                                                                            NETDATA.2     
      integer nmaxdims,nall                                                  NETDATA.3     
      parameter(nmaxdims=4,nall=10)                                          NETDATA.4     
      integer ndim,nvar,natts(nall),nattsvar(nall),                          NETDATA.5     
     :        vdims(nall),vadims(nmaxdims,nall),                             NETDATA.6     
     :        ndims(nall)                                                    NETDATA.7     
      character*200 dimname(nall),varname(nall),                             NETDATA.8     
     :              attdimname(2,nmaxdims,nall),                             NETDATA.9     
     :              attvarname(2,nmaxdims,nall)                              NETDATA.10    
      integer nc1,iddim1(nall),idvar1(nall)                                  NETDATA.11    
      common/netcdfvars/nc1,iddim1,idvar1                                    NETDATA.12    
c                                                                            NETDATA.13    
      REAL LUG(MG+1,JGG),LTG(MG+1,JGG)                                       MYNETCDF.195   
      CHARACTER*14 TEXT1                                                     MYNETCDF.196   
c                                                                            MYNETCDF.197   
      INTEGER INETCOUNT                                                      MYNETCDF.198   
      SAVE INETCOUNT                                                         MYNETCDF.199   
      DATA INETCOUNT/0/                                                      MYNETCDF.200   
c                                                                            MYNETCDF.201   
      INETCOUNT=INETCOUNT+1                                                  MYNETCDF.202   
c                                                                            MYNETCDF.203   
      rewind 24                                                              MYNETCDF.204   
      do j=1,jg                                                              MYNETCDF.205   
         sec=alat(j)/rad                                                     MYNETCDF.206   
         sec=cv/cos(sec)                                                     MYNETCDF.207   
                                                                             MYNETCDF.208   
         read(24)assbl,ashbl,aslbl,arrcr,arrlr,                              MYNETCDF.209   
     :           arflux,asfld,acld,                                          MYNETCDF.210   
     :           ssbl,shbl,slbl,rrcr,rrlr,                                   MYNETCDF.211   
     :           rflux,sfld,cld                                              MYNETCDF.212   
         do ihem=1,nhem                                                      MYNETCDF.213   
            iof=(ihem-1)*mgpp                                                MYNETCDF.214   
            if (ihem.eq.1) then                                              MYNETCDF.215   
               jj=j                                                          MYNETCDF.216   
            else                                                             MYNETCDF.217   
               jj=jggp-j                                                     MYNETCDF.218   
            end if                                                           MYNETCDF.219   
            do i=1,mg                                                        MYNETCDF.220   
               lug(i,jj)=rrcr(i+iof)                                         MYNETCDF.221   
            end do                                                           MYNETCDF.222   
            lug(mg+1,jj)=lug(1,jj)                                           MYNETCDF.223   
            do i=1,mg                                                        MYNETCDF.224   
               ltg(i,jj)=rrlr(i+iof)                                         MYNETCDF.225   
            end do                                                           MYNETCDF.226   
            ltg(mg+1,jj)=ltg(1,jj)                                           MYNETCDF.227   
         end do                                                              MYNETCDF.228   
      end do                                                                 MYNETCDF.229   
      rewind 24                                                              MYNETCDF.230   
c                                                                            MYNETCDF.231   
      call writevar2(nc1,idvar1(3),lug,                                      MYNETCDF.232   
     :                     1,mg,1,jgg,inetcount,inetcount,0,0)               MYNETCDF.233   
      call writevar2(nc1,idvar1(4),ltg,                                      MYNETCDF.234   
     :                     1,mg,1,jgg,inetcount,inetcount,0,0)               MYNETCDF.235   
c                                                                            MYNETCDF.236   
      return                                                                 MYNETCDF.237   
      end                                                                    MYNETCDF.238   
