c     commondata.f
c
c     Module for common information and frequently used functions
c
      MODULE commondata

      implicit none
      save

      real :: pi=3.1415926
      integer :: mx=180
      integer :: my=90
      integer :: maxi=33000
      integer :: ngmax=5500
      integer :: date(3),time(3)

      character(len=30) :: tmp_path='../out/' !change tmp path here
      character(len=30) :: in_path='../data/' !change input data path here
      character(len=30) :: out_path='../out/' !change output data path here
      character(len=30) :: mean_path='../mean/' !change hist r1 mean path here
      character(len=30) :: slp_mean_path='../lib/mean/SLP/'
      character(len=30) :: slp_std_path='../lib/std/SLP/'
      character(len=30) :: pt_mean_path='../lib/mean/Pt/'
      character(len=30) :: pt_std_path='../lib/std/Pt/'
      character(len=30) :: gt_mean_path='../lib/mean/trGt/'
      character(len=30) :: gt_std_path='../lib/std/trGt/'
      character(len=30) :: sur_path='../lib/surroundings/'
      character(len=30) :: lambda_path='../lib/lambda/'
      character(len=30) :: eof_path='../lib/eof/'
      character(len=30) :: coef_path='../lib/coef/'
      character(len=30) :: era_pc_path='../lib/eraint/'
      character(len=30) :: loc_path='../lib/locations/'

      character(len=30) :: latlon='LatLongGrid2x2_180x91.txt'
      character(len=30) :: loc(2)
      character(len=30) :: loc_sq(2)
      character(len=30) :: sur(3)
      character(len=30) :: boxcox(2)
      character(len=30) :: boxcox_sq(3)
      character(len=30) :: pt_eof(2)
      character(len=30) :: gt_eof(2)

      character(len=30) :: era_slp_mean(2)
      character(len=30) :: era_slp_std(2)
      character(len=30) :: era_pt_mean(2)
      character(len=30) :: era_pt_std(2)
      character(len=30) :: era_gt_mean(2)
      character(len=30) :: era_gt_std(2)
      
      character(len=3) :: seasons(4)
      character(len=4) :: area(13)

      real :: days(12)

      data loc /'180x89_','.txt'/
      data loc_sq /'LatLongGrid2x2_180x89_','.txt'/
      data sur /'Surroundings4ERAint_','180x89_','.txt'/
      data boxcox /'Gt_BoxCox_para_','.txt'/
      data boxcox_sq /'Gt_SQ_BoxCox_para_','_','.txt'/
      data pt_eof /'_Pt_','_EOFs'/
      data gt_eof /'_trGt_','_EOFs'/

      data era_slp_mean /'ERAintSLP_Mean1981-2000_','.txt'/
      data era_slp_std /'ERAintSLP_Std1981-2000_','.txt'/
      data era_pt_mean /'ERAint_SLP_Mean1981-2000_','.txt'/
      data era_pt_std /'ERAint_Pt_Std1981-2000_','.txt'/
      data era_gt_mean /'ERAint_trGt_Mean1981-2000_','.txt'/
      data era_gt_std /'ERAint_trGt_Std1981-2000_','.txt'/

      data seasons /'jfm','amj','jas','ond'/
      data area/'NIO','TSIO','TNA','TSA','WTNP','WTSP',
     & 'ETNP','ETSP','NA','NP','SA','SP','SIO'/

      data days /31,28,31,30,31,30,31,31,30,31,30,31/

      contains

      FUNCTION threesixty()

      real :: threesixty(12)
      integer :: i

      do i=1,12
      threesixty(i)=30
      enddo

      END FUNCTION threesixty

      FUNCTION ensmem(n)

      character(len=3) :: ensmem
      integer, intent(in) :: n

      if(n.le.9) then
         write(ensmem,'(i1)')n
      else if(n.le.99) then
         write(ensmem,'(i2)')n
      else
         write(ensmem,'(i3)')n
      endif
      ensmem=adjustl(ensmem)

      END FUNCTION ensmem

      FUNCTION leapday(year,caltype)

      integer :: leapday
      integer, intent(in) :: year,caltype

      leapday=0
      if(mod(year,4).eq.0.and.caltype.eq.1) then
         leapday=1
         if(mod(year,100).eq.0) then
            leapday=0
            if(mod(year,400).eq.0) then
               leapday=1
            endif
         endif
      endif

      END FUNCTION leapday

      END MODULE commondata
