What I have to do in my code to obtain some like this:
d b theta2 yinf/theta2
8.0000000000000000 0.10000000000000001 2.2362553308691373 1.7887089836339782
Short answer, you have to do formatted I/O. @HighPerformanceMark and @johncampbell gave good suggestions in the comments and you can find much more detailed info in the Fortran Standards or in your compiler docs, whichever it is. I'll not dive deep into this theme (will let you free for doing your research).
But I'll adress your specific issue - correctly spacing your header tags to match the data's output lengths - with a simple proposal (that, again, do not supress the proper definition of a set of i/o formatting rules that fit your needs). From the old Oracle compiler docs:
Unformatted I/O is used to transfer binary information to or from
memory locations without changing its internal representation. Each
execution of an unformatted I/O statement causes a single logical
record to be read or written. Since internal representation varies
with different architectures, unformatted I/O is limited in its
portability.
You can use unformatted I/O to write data out temporarily, or to write
data out quickly for subsequent input to another FORTRAN program
running on a machine with the same architecture.
Basically, I am putting your header strings inside an array with a defined length (in this case, I'm considering 26 because this is the length of the unformatted outuput sample you provided, but you should adjust it if you decide to a different record length). The reason to do so is that Fortran adds trail blanks into the right of the character variables by default, so in effect they get them left justified.
write(12, '(4a26)') [character(26) :: 'd', 'b', 'theta2', 'yinf / theta2']
Up to now, you are getting this output:
d b theta2 yinf/theta2
8.0000000000000000 0.10000000000000001 2.2362553308691373 1.7887089836339782
The leading and trailing blanks on the real values were put there by the compiler specific unformatted output, to take account of negative sign, exponents and other stuff. The only way to get rid of them is by doing formatted i/o.
Just for completness, if you really want the default unformatted output to be left aligned like the header, you could write then to string variables, align, then write to file. I will not enter on this because, as far as I know, data transfer to an internal file demands formatted, so you should not rely on this working everywhere (I couldn't find this restriction on the Fortran Standard, but all compiler doc pages I know state this).
The closest thing you could get with formatted write is:
character(26) :: recs(4)
! (...)
write(recs, '(4g26.17)') bb(i), cc(i), theta2, yinf(i) / theta2
write(12, '(4a26)') adjustl(recs)
That would result into this:
d b theta2 yinf/theta2
8.0000000000000000 0.10000000000000001 2.2362553308691373 1.7887089836339782
Another option, but less reliable, is:
write(12, '(t1,g0,t27,g0,t53,g0,t79,g0)') bb(i), cc(i), theta2, yinf(i) / theta2
That will produce this with gfortran 8.0
:
d b theta2 yinf/theta2
8.0000000000000000 0.10000000000000001 2.2362553308691373 1.7887089836339782
But this with ifort 18.0
d b theta2 yinf/theta2
8.000000000000000 .1000000000000000 2.236255330869137 1.788708983633978