|
Prev: the g0 edit descriptor
Next: bug with ifort + openmp : allocatable array not allocated after allocation
From: Isliguezze on 4 Jul 2008 08:24 Hi! How do I print matrix in FORTRAN 77? I have a quadratic matrix D(n, n) and I do print it this way: do i = 1, n write(*, '(1x, 1000g10.5)') (D(i, j), j = 1, n) enddo But I don't know what does it mean. Actually what is 1000 constant for (before the g letter)? If I reduce it to < n, it does not work properly.
From: dpb on 4 Jul 2008 08:45 Isliguezze wrote: > Hi! How do I print matrix in FORTRAN 77? I have a quadratic matrix > D(n, n) and I do print it this way: > > do i = 1, n > write(*, '(1x, 1000g10.5)') (D(i, j), j = 1, n) > enddo > > But I don't know what does it mean. Actually what is 1000 constant for > (before the g letter)? If I reduce it to < n, it does not work > properly. Well, the last observation should be a clue... :) Look up FORMAT statement in Fortran reference manual...one I happen to have that I know is OpenWatcom for which the documentation can be found at www.openwatcom.org In short, the number before the G is the repeat specifier--how many times the format will be used. If it is less than n, the size of the number of elements, the Format statement will be exhausted and a new record will be started. --
From: Kurt Kallblad on 4 Jul 2008 09:14 "Isliguezze" <isliguezze(a)gmail.com> wrote in message news:d3de1da9-7d92-4076-98af-a0cf18383067(a)34g2000hsh.googlegroups.com... > Hi! How do I print matrix in FORTRAN 77? I have a quadratic > matrix > D(n, n) and I do print it this way: > > do i = 1, n > write(*, '(1x, 1000g10.5)') (D(i, j), j = 1, n) > enddo > > But I don't know what does it mean. Actually what is 1000 > constant > for before the g letter)? If I reduce it to < n, it does not > work > properly. The length of a record is in this case given by the output list and will be 1 + n*10 characters. To use 1000 is an old "trick" to enable different long records. Fortran standard does not allow a variabel instead of 1000. 1000 means that you can write up to 1000 matrix element on one line. For more than 1000 elements in each row, a new line will start for element 1001. However, there might be system limits that break this behavior, 100001 characters is a long record. Fortran 77 standard does not allow a variabel instead of 1000, some compilers accept <n>g10.5 as an extension to the standard but then you get problem if you want to move your program. In Fortran 77 you can use a variable format: character*13 fmt write(fmt, '(a,i4,a)') '(1x,', n, '10.5)' ... write(*, fmt) (D(i, j), j = 1, n Another thing, are you sure that your matrix has the first index addressing the rows. Best regards Kurt
From: Richard Maine on 4 Jul 2008 13:04
Isliguezze <isliguezze(a)gmail.com> wrote: .... > write(*, '(1x, 1000g10.5)') (D(i, j), j = 1, n) .... > Actually what is 1000 constant for... > If I reduce it to < n, it does not work properly. Others have adequately answered your question for now, but for future reference, allow me to note that "does not work properly" is inadequate description. This case happened to be trivial enough for people to diagnose anyway, but in general, you need to be far more precise, preferreably giving a sample of the results and contrasting that with what you expected. In fact, if one actually gave a precise description of the results here instead of just "did not work properly", I'd think it would be hard not to see what the value was doing. The process of writing the precise description would give you the answer. -- Richard Maine | Good judgement comes from experience; email: last name at domain . net | experience comes from bad judgement. domain: summertriangle | -- Mark Twain |