format reversion

Discussion about FORTRAN

e
I rediscovered this property of formats while thinking about the problem 
raised in the thread entitled "matrix manipulation" where extra work was 
required to convert data from a file in 9 columns into an array in 45 
columns. List directed formatting worked well to read data from multiple 
records into one row of an array. Given data in an explicit format in 9 
columns, it's also possible to read multiple records of data into one row of 
an array by re-using a single format. I'd forgotten or never learned the 
technical term for this - format reversion. See the example below:

---- start text ----
C:\Users\epc\temp>type x.f90
program foo
implicit none
integer m(10,9),n(2,45)
integer i,j,k

k=0
do i=1,10
  do j=1,9
    k=k+1
    m(i,j)=k
  end do
end do

open(10,file='foo.txt',form='formatted',status='replace')
do i=1,10
  write(10,'(99i4)') m(i,:)
end do

rewind(10)
do i=1,2
  read(10,'(9i4)') n(i,:)
  print *,n(i,:)
end do
close(10)

end program foo

C:\Users\epc\temp>c

C:\Users\epc\temp>g95 -Wall -fbounds-check x.f90

C:\Users\epc\temp>a
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 
29[break]
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 
71[break]
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90

C:\Users\epc\temp>type foo.txt
   1   2   3   4   5   6   7   8   9
  10  11  12  13  14  15  16  17  18
  19  20  21  22  23  24  25  26  27
  28  29  30  31  32  33  34  35  36
  37  38  39  40  41  42  43  44  45
  46  47  48  49  50  51  52  53  54
  55  56  57  58  59  60  61  62  63
  64  65  66  67  68  69  70  71  72
  73  74  75  76  77  78  79  80  81
  82  83  84  85  86  87  88  89  90                                            
nospamseesignature
[example elided]

Nothing particularly wrong or dangerous with format reversion that I'd
call out. The use you showed of it is pretty much its simplest form. I'd
say that form is quite common - yes, still today. I certainly use it
regularly.

There are trickier cases of format reversion than what you showed. In
particular, I've often taken advantage of the feature of using parens to
control exactly where the format reverts to; it doesn't always have to
be the beginning of the format. That's useful when you might have a
multi-line output and want the first line to be different from the
subsequent ones; perhaps it has a label/tag of some kind or is indented
differently.
                                            
dpb
...


Oh, indeedy, do!!!!

Some of the complex large code outputs found were mind-boggling to the 
new engineer right out of school asked to make modifications... :)