      program changeRES

c
c     change resolution from 2.5 min to 30 min(0.5 degree)
c           and put  0 in do data grid
c

      integer i,j,ii,jj,imax, jmax
      integer iiS,iiN,jjS,jjN
      parameter(imax=360, jmax=143)
      integer igrid, jgrid
      parameter(igrid=24, jgrid=24)
      integer data1(imax*igrid, jmax*igrid),data2(imax*2,jmax*2)
      integer data0(720,100)

      open(10,file='glp90agi.bil',access="direct",recl=4*imax*igrid)
c      open(10,file='glp95agi.bil',access="direct",recl=4*imax*igrid)

      do j=1,jmax*jgrid
          read(10,rec=j) (data1(i,j), i=1,imax*igrid)
      end do

      close(10)


c     ------  2.5' => 30'  ------

          do jj=1,jmax*2
            do ii=1,imax*2           
              data2(ii,jj)=0
              do j= 1+12*(jj-1),12*jj
                do i= 1+12*(ii-1), 12*ii
                  data2(ii,jj)= data2(ii,jj)+ data1(i,j)
                end do
              end do
            end do
          end do



          open(11, file='glp90agi.asc',status='new')  
c          open(11, file='glp95agi.asc',status='new')  

c     ------  put 0 in no data grid (North-edge)  ------
          do jjN=1,5*2
            do iiN=1,imax*2             
              data0(iiN,jjN) =0
            end do
          end do
          do jjN=1,5*2
            write(11,*) (data0(iiN,jjN),iiN=1,imax*2)
          end do


c     ------  putting data  ------
          do jj=1,jmax*2
              write(11,*) (data2(ii,jj),ii=1,imax*2)
          end do


c     ------   put 0 in no data grid (South-edge)   ------
          do jjS=1,32*2
            do iiS=a,imax*2
              data0(iiS,jjS) =0
            end do
          end do
          do jjS=1,32*2
            write(11,*) (data0(iiS,jjS),iiS=1,imax*2)
          end do
          close(11)
      stop
      end


