2

Is there a way to write an array in one line (without do-loop) (in fortran) and have it being tab-delimited?

I have tried the following two versions without success.. (the first writes just one number and the second writes them all padding with spaces)

real       :: var(10)
var = 1
write(*,'(10(t1,f7.2))')
write(*,'(t1,10f7.2)')

I have looked here without finding out howto. (although it gave some info).

1
  • 1
    There are ways to do what you want (and someone with time may write an answer or find another link), but I'll note that the "tabbing" that comes with the T edit descriptor has nothing to do with ASCII tab characters. You can add the latter as text. Commented Nov 4, 2016 at 8:51

2 Answers 2

4
real :: var(10)
var=1
write(*,"(10(f7.2,a))") (var(i),achar(9),i=1,10)
Sign up to request clarification or add additional context in comments.

7 Comments

Or if your compiler supports the F2008 unlimited repeat count feature: real :: var(10) var = 1. write (*,"(*(f7.2,:,a))") (var(i),achar(9),i=1,size(var)) Note the colon - this prevents a trailing tab. (That's a F77 feature.) Can't see how to get a line break in that code!
@steve Just in retirement and already working on stackoverflow anyway ?
Sorry Steve but I don't understand how you could avoid the last tab with ":" ; for me, this works only for elements within the format itself. But achar(9) belongs to the variables being written => 10 tabs are expected !
Maybe to avoid the last tab : character(20) :: form ; form="(999(f7.2,:,'"//achar(9)//"'))" ; write(*,form) var
@FrancoisJacq not retired yet - but soon. You're right that the last tab would not be avoided with the code I gave, but it really shouldn't matter.
|
1

The original answer is 100% correct for the question, but a more generic answer I made based on a csv format string Steve Lionel gave on the Intel Fortran forums (I can't seem to find that post right now) is the following:

tsvFormat = '(*(G0.6,:,"'//achar(9)//'"))'
write(*, tsvFormat) ValueArr, moreRealValues, 64.0, maybeAnIntegerArrayToo, string 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.