program count_grid c c============================================== c c read the country-code, and c count the number of the grid c c============================================== c c.......................................... c country_code.asc c c country_code.list c.......................................... character*5 ncols,nrows character*9 xllcorner,yllcorner character*8 cellsize character*12 nodata parameter( infile = 11, iofile = 12, nx =720, ny= 360 ) integer data(2000,4000),count,code c open(infile, file= 'country_code.asc', status='old') c c ------ read from country_code.asc file ------ c
read(infile,*) ncols,nc read(infile,*) nrows,nr read(infile,*) xllcorner,x0 read(infile,*) yllcorner,y0 read(infile,*) cellsize,s read(infile,*) nodata,znodata do j=1,nr read(infile,100) (data(i,j),i=1,nc) end do 100 format(720i4) c c ------ count grid ------ count =0 write(*,*) 'country_code ?' read(*,*) code do j =1 ,nr do i = 1, nc if(data(i,j) .eq. code) then count = count +1 end if end do end do close(infile) c c ------ write number of the country-code ------ write(*,*)'country_code:',code,' = ', count end