|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
arctica
Joined: 10 Sep 2006 Posts: 105 Location: United Kingdom
|
Posted: Wed Apr 21, 2021 3:16 pm Post subject: Reading header |
|
|
Hello,
Just a quick query. How do you read a header, store the values in variables (first 6 lines) and the rest of the data are z values:
ncols 120
nrows 120
xllcorner -5.000000
yllcorner -5.000000
cellsize 0.0166666675
NODATA_value -9999.000000
8.278781 7.810413 7.679254 7.670572 7.507757 7.489618 7.549579 7.712960 7.627653 6.931419 5.598992 4.097134 2.129512 0.308146 -1.081559 -1.578681 -1.929566 -2.209486 -1.927538 -0.758010 1.033233 2.433419 2.993177 2.734593 etc
From the header info, it will be possible to generate an X, Y, Z array to work from, for processing etc.
I'm sure this is a simple one, thanks for any pointers.
Thanks
Lester |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Wed Apr 21, 2021 4:59 pm Post subject: |
|
|
Modify to suit:
Code: | program readzvals
implicit none
integer :: ncols,nrows,i
real :: xllc,yllc,cellsize,nodata_value
real, allocatable, dimension(:,:) :: z
character(len=12) :: name
read(*,'(A5,1x,I3)')name,ncols
read(*,'(A5,1x,I3)')name,nrows
read(*,'(A9,1x,F9.6)')name,xllc
read(*,'(A9,1x,F9.6)')name,yllc
read(*,'(A8,1x,F11.6)')name,cellsize
read(*,'(A12,1x,F12.6)')name,nodata_value
print *,nrows,' rows and ',ncols,' columns'
allocate(z(nrows,ncols))
read(*,*)(z(i,:),i=1,nrows)
print *,z(4,4)
end program |
Compile and link:
Code: | ftn95 readz.f90 /link |
Put your data into a file, say, 'hdr.txt'.
Run the program:
Code: | R:\lang>readz < hdr.txt
6 rows and 4 columns
-1.57868 |
|
|
Back to top |
|
|
arctica
Joined: 10 Sep 2006 Posts: 105 Location: United Kingdom
|
Posted: Sat Apr 24, 2021 2:24 pm Post subject: Re: |
|
|
Many thanks
mecej4 wrote: | Modify to suit:
Code: | program readzvals
implicit none
integer :: ncols,nrows,i
real :: xllc,yllc,cellsize,nodata_value
real, allocatable, dimension(:,:) :: z
character(len=12) :: name
read(*,'(A5,1x,I3)')name,ncols
read(*,'(A5,1x,I3)')name,nrows
read(*,'(A9,1x,F9.6)')name,xllc
read(*,'(A9,1x,F9.6)')name,yllc
read(*,'(A8,1x,F11.6)')name,cellsize
read(*,'(A12,1x,F12.6)')name,nodata_value
print *,nrows,' rows and ',ncols,' columns'
allocate(z(nrows,ncols))
read(*,*)(z(i,:),i=1,nrows)
print *,z(4,4)
end program |
Compile and link:
Code: | ftn95 readz.f90 /link |
Put your data into a file, say, 'hdr.txt'.
Run the program:
Code: | R:\lang>readz < hdr.txt
6 rows and 4 columns
-1.57868 |
|
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|