home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / fortran / 3009 < prev    next >
Encoding:
Internet Message Format  |  1992-08-13  |  2.8 KB

  1. Path: sparky!uunet!haven.umd.edu!mimsy!afterlife!adm!aos!lapoint
  2. From: lapoint@adios.brl.mil (Claude LaPointe )
  3. Newsgroups: comp.lang.fortran
  4. Subject: RE:  STORAGE OF ARRAYS IN FORTRAN
  5. Message-ID: <977@aos.brl.mil>
  6. Date: 13 Aug 92 13:49:43 GMT
  7. Sender: news@aos.brl.mil
  8. Lines: 66
  9. Nntp-Posting-Host: adios.brl.mil
  10.  
  11.  
  12. jlg@cochiti.lanl.gov (Jim Giles) writes:
  13.  
  14.   > In article <976@aos.brl.mil>, lapoint@adios.brl.mil (Claude LaPointe ) writes:
  15.   > |> [...]
  16.   > |> The idea that the 1st subscript corresponds to columns, the second to
  17.   > |> rows, the 3rd to planes, the 4th... OOPS! no more analogies,
  18.   > |> is merely conventional and has nothing to do with storage.
  19.   > |>
  20.   > |> Most FORTRAN types accept the convention that the 1st runs down
  21.   > |> the column; the 2nd, across the row, ....
  22.   >
  23.   > I use the convention that the first index is the column number, the second
  24.   > the row number etc. simply because it simplifies I/O requests in Fortran:
  25.   >
  26.   >       REAL A(2,3)
  27.   >       ...
  28.   >       write(*,'(2F10.5)') A
  29.   >       ...
  30.   >
  31.   > This code fragment will write out the values of A's components in the
  32.   > order:
  33.   >
  34.   >       A(1,1)  A(2,1)
  35.   >       A(1,2)  A(2,2)
  36.   >       A(1,3)  A(2,3)
  37.   >
  38.   > Any other order of I/O would require implied do-loops or some other
  39.   > looping mechanism.  Note, this convention does not hamper users in C, or
  40.   > Pascal, etc. because they don't have built-in syntax for reading/writing
  41.   > whole arrays anyway - so you must always use loops in those languages.
  42.   > Of course, if your language uses row-major, pragmatic considerations
  43.   > may force row-major I/O as well (at least on large arrays) because of
  44.   > the cost of striding.
  45.  
  46.  
  47. Most FORTRAN people make the other interpretation, that the 1st subscript
  48. is the row number and runs down the column. This is the choice, for instance,
  49. of Balfour and Marwick's textbook, and even of the Cray FORTRAN reference
  50. manual, volume 1.
  51.  
  52.  
  53. Nevertheless, jlg's choice and rational make sense. Note that he interprets
  54. the 1st subscript as the column number, that is, it runs across the row.
  55.  
  56.  
  57. My only point was, and is, that the storage sequence, being linear,
  58. does not enforce or even prefer either view. Even concerns of stride
  59. in various machines, although important, are independent of the picture
  60. one uses to interpret what each subscript does. In standard FORTRAN, at
  61. least, the storage sequence merely runs out the 1st subscript before
  62. incrementing the 2nd one, as follows:
  63.  
  64.    linear_subscript = (value_of_2nd_subscript-1) * size_of_1st_dimension
  65.                       + value_of_1st_subscript
  66.  
  67. Clearly, my expression is not the most general one, even for only 2
  68. dimensions. It assumes something of the form
  69.  
  70.    DIMENSION ARRAY(2,3)
  71.  
  72. rather than of form
  73.  
  74.    DIMENSION ARRAY(-17:-16,-1:1)
  75.  
  76. which would result in "offset" terms in the linear_subscript expression.
  77.