program warp

integer,parameter                :: nx=360,ny=180
integer,dimension(nx,ny)         :: mask
real,dimension(nx,ny)            :: indat,newgrid,garea
character(len=90)                :: fin,fout


fin='miami_1deg_conform.txt'
open(14,file=fin,status='old')

do iy=1,ny
    read(14,*) indat(:nx,iy)
end do
close(14)

where(indat.lt.0.01) indat=0.01

fin='/raid1/gh/matt/glm/cellarea/cellarea.1deg.nohead.txt'
open(14,file=fin,status='old')

do iy=1,ny
    read(14,*) garea(:nx,iy)
end do
close(14)
garea=garea*1000.0*1000.0  !* convert km2 to m2

fin='/raid1/gh/matt/glm/glm.landmsk.142.txt'
open(14,file=fin,status='old')

do iy=1,ny
    read(14,*) mask(:nx,iy)
end do
close(14)


print *, sum(indat*garea,mask.eq.1)
stop

!* output of new carbon grid 360x180

fout='miami_1deg.txt'
open(15,file=fout,status='unknown')

do iy=1,ny 
  write(15,'(360(f8.2,1x))') indat(:nx,iy)
end do
close(15)

stop
end
