home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!haven.umd.edu!mimsy!afterlife!adm!aos!lapoint
- From: lapoint@adios.brl.mil (Claude LaPointe )
- Newsgroups: comp.lang.fortran
- Subject: RE: STORAGE OF ARRAYS IN FORTRAN
- Message-ID: <977@aos.brl.mil>
- Date: 13 Aug 92 13:49:43 GMT
- Sender: news@aos.brl.mil
- Lines: 66
- Nntp-Posting-Host: adios.brl.mil
-
-
- jlg@cochiti.lanl.gov (Jim Giles) writes:
-
- > In article <976@aos.brl.mil>, lapoint@adios.brl.mil (Claude LaPointe ) writes:
- > |> [...]
- > |> The idea that the 1st subscript corresponds to columns, the second to
- > |> rows, the 3rd to planes, the 4th... OOPS! no more analogies,
- > |> is merely conventional and has nothing to do with storage.
- > |>
- > |> Most FORTRAN types accept the convention that the 1st runs down
- > |> the column; the 2nd, across the row, ....
- >
- > I use the convention that the first index is the column number, the second
- > the row number etc. simply because it simplifies I/O requests in Fortran:
- >
- > REAL A(2,3)
- > ...
- > write(*,'(2F10.5)') A
- > ...
- >
- > This code fragment will write out the values of A's components in the
- > order:
- >
- > A(1,1) A(2,1)
- > A(1,2) A(2,2)
- > A(1,3) A(2,3)
- >
- > Any other order of I/O would require implied do-loops or some other
- > looping mechanism. Note, this convention does not hamper users in C, or
- > Pascal, etc. because they don't have built-in syntax for reading/writing
- > whole arrays anyway - so you must always use loops in those languages.
- > Of course, if your language uses row-major, pragmatic considerations
- > may force row-major I/O as well (at least on large arrays) because of
- > the cost of striding.
-
-
- Most FORTRAN people make the other interpretation, that the 1st subscript
- is the row number and runs down the column. This is the choice, for instance,
- of Balfour and Marwick's textbook, and even of the Cray FORTRAN reference
- manual, volume 1.
-
-
- Nevertheless, jlg's choice and rational make sense. Note that he interprets
- the 1st subscript as the column number, that is, it runs across the row.
-
-
- My only point was, and is, that the storage sequence, being linear,
- does not enforce or even prefer either view. Even concerns of stride
- in various machines, although important, are independent of the picture
- one uses to interpret what each subscript does. In standard FORTRAN, at
- least, the storage sequence merely runs out the 1st subscript before
- incrementing the 2nd one, as follows:
-
- linear_subscript = (value_of_2nd_subscript-1) * size_of_1st_dimension
- + value_of_1st_subscript
-
- Clearly, my expression is not the most general one, even for only 2
- dimensions. It assumes something of the form
-
- DIMENSION ARRAY(2,3)
-
- rather than of form
-
- DIMENSION ARRAY(-17:-16,-1:1)
-
- which would result in "offset" terms in the linear_subscript expression.
-