program GFEDv2
integer, parameter :: nlon = 360, nlat= 180
real lon(nlon),lat(nlat)

real   , dimension(:,:), allocatable 	:: carb,drybbc,veg,carb_mean
!integer, dimension(:,:), allocatable 	:: veg

character(len=240)	:: file_in(2)
integer i,j




allocate (carb(nlon,nlat),drybbc(nlon,nlat), veg(nlon,nlat),carb_mean(nlon,nlat))


do i=1,nlon
 lon(i)=-179.5+(i-1)*1.
enddo
do j=1,nlat
 lat(j)=89.5-(j-1)*1.
enddo
call gen_mean(nlon,nlat,carb_mean)



file_in(1)='./VEG.txt'
open(30, FILE=file_in(1), STATUS='old')
    do j=1,180
      read(30,'360(f12.0)') veg(:,j)	
      print*,'j=',j,veg(:,J)	   
    enddo
close(30)



file_in(2)='./C_2005_JD353.txt'

open(30, FILE=file_in(2), STATUS='old')
    do j=1,180
      read(30,'360(f12.4)') carb(:,j)	
      print*,'j=',j,carb(:,J)	   
    enddo
close(30)


!convert from carbon flux to dry-biomass-consumed
drybbc=carb/0.45  




open(30,file=trim(file_in(2))//'.gra',&
status='replace',access='direct',recl=nlon*nlat*4, convert='little_endian')        
write (30, REC=1) carb      
close (30)     	



end
subroutine gen_mean(nlon,nlat,carb_mean)
implicit none
integer nlon,nlat,i,j,nfile,icount
real, dimension(nlon,nlat) :: carb_mean,dummy
character*20 file_in(230)
data file_in/'C_2001_JD033.txt',&
'C_2001_JD025.txt',&
'C_2001_JD017.txt',&
'C_2001_JD009.txt',&
'C_2001_JD001.txt',&
'C_2001_JD145.txt',&
'C_2001_JD137.txt',&
'C_2001_JD129.txt',&
'C_2001_JD121.txt',&
'C_2001_JD113.txt',&
'C_2001_JD105.txt',&
'C_2001_JD097.txt',&
'C_2001_JD089.txt',&
'C_2001_JD081.txt',&
'C_2001_JD073.txt',&
'C_2001_JD065.txt',&
'C_2001_JD057.txt',&
'C_2001_JD049.txt',&
'C_2001_JD041.txt',&
'C_2001_JD249.txt',&
'C_2001_JD241.txt',&
'C_2001_JD233.txt',&
'C_2001_JD225.txt',&
'C_2001_JD217.txt',&
'C_2001_JD209.txt',&
'C_2001_JD201.txt',&
'C_2001_JD193.txt',&
'C_2001_JD185.txt',&
'C_2001_JD177.txt',&
'C_2001_JD169.txt',&
'C_2001_JD161.txt',&
'C_2001_JD153.txt',&
'C_2001_JD345.txt',&
'C_2001_JD337.txt',&
'C_2001_JD329.txt',&
'C_2001_JD321.txt',&
'C_2001_JD313.txt',&
'C_2001_JD305.txt',&
'C_2001_JD297.txt',&
'C_2001_JD289.txt',&
'C_2001_JD281.txt',&
'C_2001_JD273.txt',&
'C_2001_JD265.txt',&
'C_2001_JD257.txt',&
'C_2001_JD361.txt',&
'C_2001_JD353.txt',&
'C_2002_JD041.txt',&
'C_2002_JD033.txt',&
'C_2002_JD025.txt',&
'C_2002_JD017.txt',&
'C_2002_JD009.txt',&
'C_2002_JD001.txt',&
'C_2002_JD161.txt',&
'C_2002_JD153.txt',&
'C_2002_JD145.txt',&
'C_2002_JD137.txt',&
'C_2002_JD129.txt',&
'C_2002_JD121.txt',&
'C_2002_JD113.txt',&
'C_2002_JD105.txt',&
'C_2002_JD097.txt',&
'C_2002_JD089.txt',&
'C_2002_JD081.txt',&
'C_2002_JD073.txt',&
'C_2002_JD065.txt',&
'C_2002_JD057.txt',&
'C_2002_JD049.txt',&
'C_2002_JD273.txt',&
'C_2002_JD265.txt',&
'C_2002_JD257.txt',&
'C_2002_JD249.txt',&
'C_2002_JD241.txt',&
'C_2002_JD233.txt',&
'C_2002_JD225.txt',&
'C_2002_JD217.txt',&
'C_2002_JD209.txt',&
'C_2002_JD201.txt',&
'C_2002_JD193.txt',&
'C_2002_JD185.txt',&
'C_2002_JD177.txt',&
'C_2002_JD169.txt',&
'C_2002_JD361.txt',&
'C_2002_JD353.txt',&
'C_2002_JD345.txt',&
'C_2002_JD337.txt',&
'C_2002_JD329.txt',&
'C_2002_JD321.txt',&
'C_2002_JD313.txt',&
'C_2002_JD305.txt',&
'C_2002_JD297.txt',&
'C_2002_JD289.txt',&
'C_2002_JD281.txt',&
'C_2003_JD113.txt',&
'C_2003_JD105.txt',&
'C_2003_JD097.txt',&
'C_2003_JD089.txt',&
'C_2003_JD081.txt',&
'C_2003_JD073.txt',&
'C_2003_JD065.txt',&
'C_2003_JD057.txt',&
'C_2003_JD049.txt',&
'C_2003_JD041.txt',&
'C_2003_JD033.txt',&
'C_2003_JD025.txt',&
'C_2003_JD017.txt',&
'C_2003_JD009.txt',&
'C_2003_JD001.txt',&
'C_2003_JD225.txt',&
'C_2003_JD217.txt',&
'C_2003_JD209.txt',&
'C_2003_JD201.txt',&
'C_2003_JD193.txt',&
'C_2003_JD185.txt',&
'C_2003_JD177.txt',&
'C_2003_JD169.txt',&
'C_2003_JD161.txt',&
'C_2003_JD153.txt',&
'C_2003_JD145.txt',&
'C_2003_JD137.txt',&
'C_2003_JD129.txt',&
'C_2003_JD121.txt',&
'C_2003_JD345.txt',&
'C_2003_JD337.txt',&
'C_2003_JD329.txt',&
'C_2003_JD321.txt',&
'C_2003_JD313.txt',&
'C_2003_JD305.txt',&
'C_2003_JD297.txt',&
'C_2003_JD289.txt',&
'C_2003_JD281.txt',&
'C_2003_JD273.txt',&
'C_2003_JD265.txt',&
'C_2003_JD257.txt',&
'C_2003_JD249.txt',&
'C_2003_JD241.txt',&
'C_2003_JD233.txt',&
'C_2003_JD361.txt',&
'C_2003_JD353.txt',&
'C_2004_JD105.txt',&
'C_2004_JD097.txt',&
'C_2004_JD089.txt',&
'C_2004_JD081.txt',&
'C_2004_JD073.txt',&
'C_2004_JD065.txt',&
'C_2004_JD057.txt',&
'C_2004_JD049.txt',&
'C_2004_JD041.txt',&
'C_2004_JD033.txt',&
'C_2004_JD025.txt',&
'C_2004_JD017.txt',&
'C_2004_JD009.txt',&
'C_2004_JD001.txt',&
'C_2004_JD217.txt',&
'C_2004_JD209.txt',&
'C_2004_JD201.txt',&
'C_2004_JD193.txt',&
'C_2004_JD185.txt',&
'C_2004_JD177.txt',&
'C_2004_JD169.txt',&
'C_2004_JD161.txt',&
'C_2004_JD153.txt',&
'C_2004_JD145.txt',&
'C_2004_JD137.txt',&
'C_2004_JD129.txt',&
'C_2004_JD121.txt',&
'C_2004_JD113.txt',&
'C_2004_JD329.txt',&
'C_2004_JD321.txt',&
'C_2004_JD313.txt',&
'C_2004_JD305.txt',&
'C_2004_JD297.txt',&
'C_2004_JD289.txt',&
'C_2004_JD281.txt',&
'C_2004_JD273.txt',&
'C_2004_JD265.txt',&
'C_2004_JD257.txt',&
'C_2004_JD249.txt',&
'C_2004_JD241.txt',&
'C_2004_JD233.txt',&
'C_2004_JD225.txt',&
'C_2004_JD361.txt',&
'C_2004_JD353.txt',&
'C_2004_JD345.txt',&
'C_2004_JD337.txt',&
'C_2005_JD009.txt',&
'C_2005_JD001.txt',&
'C_2005_JD113.txt',&
'C_2005_JD105.txt',&
'C_2005_JD097.txt',&
'C_2005_JD089.txt',&
'C_2005_JD081.txt',&
'C_2005_JD073.txt',&
'C_2005_JD065.txt',&
'C_2005_JD057.txt',&
'C_2005_JD049.txt',&
'C_2005_JD041.txt',&
'C_2005_JD033.txt',&
'C_2005_JD025.txt',&
'C_2005_JD017.txt',&
'C_2005_JD233.txt',&
'C_2005_JD225.txt',&
'C_2005_JD217.txt',&
'C_2005_JD209.txt',&
'C_2005_JD201.txt',&
'C_2005_JD193.txt',&
'C_2005_JD185.txt',&
'C_2005_JD177.txt',&
'C_2005_JD169.txt',&
'C_2005_JD161.txt',&
'C_2005_JD153.txt',&
'C_2005_JD145.txt',&
'C_2005_JD137.txt',&
'C_2005_JD129.txt',&
'C_2005_JD121.txt',&
'C_2005_JD345.txt',&
'C_2005_JD337.txt',&
'C_2005_JD329.txt',&
'C_2005_JD321.txt',&
'C_2005_JD313.txt',&
'C_2005_JD305.txt',&
'C_2005_JD297.txt',&
'C_2005_JD289.txt',&
'C_2005_JD281.txt',&
'C_2005_JD273.txt',&
'C_2005_JD265.txt',&
'C_2005_JD257.txt',&
'C_2005_JD249.txt',&
'C_2005_JD241.txt',&
'C_2005_JD361.txt',&
'C_2005_JD353.txt'/

carb_mean=0.
icount=0
do nfile=1,230
   print*,'opening=',file_in(nfile)
   icount=icount+1
   open(30, FILE=file_in(nfile), STATUS='old')
     do j=1,180
      read(30,'360(f12.4)') carb(:,j)	
      print*,'j=',j,dummy(:,J)	   
    enddo
   close(30)
   carb_mean=carb_mean+dummy
enddo



integer nlon,nlat,i,j,nfile
real, dimension(nlon,nlat) :: carb_mean,dummy
character*20 file_in(230)
data file_in/'C_2001_JD033.txt',&
