In a previous article, smurray444 <smurray@gmail.com> wrote:
>Hi there,
>I have a global dataset (text file) where for every 105 values
>(currently
>formatted as a continuous string), the 1st represents longitude, the
>2nd =
>latitude, the 3rd is a 'spinup' value which can be ignored, and the
>4th to
>105th values are hydrological runoff values for the years 1901 to
>2002.
>I've been trying to create a table where longitude values are listed
>along
>the top row (x-axis) and latitude values are listed in the far left
>column
>(y-axis), with the corresponding runoff values for each year located
>in a
>given grid - therefore there will be 102 grids created (one for each
>year).
>The longitude values are currently not ordered and will need to be
>sorted
>(low to high) into position along the x-axis.
>As I am relatively new to Fortran, despite spending a lot of time on
>this,
>I've been having problems getting off the ground. Therefore I would be
>grateful for any help or Fortran (77 or 90) code which will aid my
>progress
>with this.
>Thanks very much,
>smurray444
If the numbers are in fixed format (i.e. the fields are
the same for each line) - then use fixed format
e.g. 3f5.1,102f6.2 ... whatever the format happens to be.
The main thing is to get the fields right. An i/p decimal
point will override the format spec.
If data are numbers only and separated by commas (or
maybe spaces)
then (WATCOM FORTRAN77)
dimension values(105)
c I'm just guessin 1000 will be more than enough length
open( ..., form='formatted',status='old',recl=1000)
10 read( ,*)values
To order, you have to store all the lines; one possiblity
is:
PARAMETER(NLINES=999) !e.g. file has 999 locations
c assume lines < 1001 chars long
character*1000 alines(NLINES),bline,cline
do i=2,NLINES
do j=1,i-1
bline=alines(i)
read(bline,'(...)')blong
cline=alines(j)
read(cline,'(...)')clong
if(blong.lt.clong)then
alines(i)=cline
alines(j)=bline
endif
enddo
enddo
c then re-read from alines - which is now in order
Something like that is what I would do - no black boxes.
Chris