program count_grid
c
c=================================================
c
c read the country-code, and
c count the number of the grid
c
c country and country-code are from the table
c=================================================
c..........................................
c country_code.asc
c country_code
c
c country_code.list
c..........................................
character*28 country(6)
parameter( infile = 11, iofile = 12, nc = 720, nr= 360 )
parameter(infile2 = 13)
integer data(2000,4000),count(10),code(10),region(10)
c
c ------ read from country_code.asc file ------
open(infile, file= 'region_code2.asc', status='old')
c
do j=1,nr
read(infile,*) (data(i,j),i=1,nc)
end do
c
c ------ read from country-code-table file ------
open(infile2,file='region_code2', status='old')
c read(infile2,*)
do n =1, 6
read(infile2,200) code(n), country(n), region(n)
end do
200 format(i4,a28,i8)
close(infile2)
c
c ------ count grid ------
do n=1,6
count(n) =0
end do
do n=1,6
do j =1 ,nr
do i = 1, nc
if(data(i,j) .eq. code(n)) then
count(n) = count(n) +1
end if
end do
end do
end do
c
close(infile)
c
open(iofile, file='region_code2.txt', status='new')
do n =1, 6
write(iofile,300) code(n),country(n),region(n),count(n)
end do
300 format(i4,a28,i8,i8)
close(iofile)
end