This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: character arrays in format tags (bug?)



On Jan 28, 2008, at 8:24 PM, Tobias Schlüter wrote:

This is a bug, can you please file a bug report in http:// gcc.gnu.org/bugzilla so that it doesn't get lost?

Yes; filed @ http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35009 -- my second bug today! And second bug... ever. heh.


You have two options: use a large enough number in the format string, or, if such a number doesn't exist, use an internal write to create the format string and then use that format string, say
charater*4 :: f
write(f, "(i2,'i3')") num
write(6, f) variable(1:num)

I think the internal write scheme may work (my actual output is more complicated). I have a short example working similar to yours, which had problems with parentheses on my system:


      program testcase
      character(6) :: f
      integer num,var(3)
      num=2
      var(1)=1
      var(2)=2
      var(3)=3
      write(f,"(A,i0,'i3',A)") '(',num,')'   ! ugly but works
      write(6,*) f
      write(6,f) var(1:num)
      end

outputs:

nell:~/work/bit barnes$ gfortran -Wall -o t.x testcase.f ; ./t.x
 (2i3)
  1  2


I had never (intentionally, knowingly) made use of internal writes before. Thanks for the tip!


-Brian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]