Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fortran output format 1

Status
Not open for further replies.

hamedpar

Programmer
Jun 13, 2009
8
IR
i would like to write a txt in this format:

{{{ 1 2 3 4 5 .... }}}

for example a(i)=1 2 3 4 .... N
but N is variable and differ each time

this is part of my program but it seems to be wrong :

write(430,44) (b(i),i=1,N) !N<50
44 format(' {{{ ',50F6.3,'}}}')

after runing program it doesnot write }}} at the end. it only writes it when N==50. but N is variable and every time has an amount for axample 10 23 36 .
please help me writing in this format.
 
Code:
[COLOR=#2e8b57][b]integer[/b][/color] :: i, N
[COLOR=#2e8b57][b]real[/b][/color], [COLOR=#2e8b57][b]dimension[/b][/color]([COLOR=#ff00ff]5[/color]) :: b [COLOR=#804040][b]=[/b][/color] ([COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]10[/color], [COLOR=#ff00ff]23[/color], [COLOR=#ff00ff]36[/color], [COLOR=#ff00ff]40[/color], [COLOR=#ff00ff]50[/color][COLOR=#804040][b]/[/b][/color]) 

N[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]3[/color]

[COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'{{{'[/color], (b(i),i[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color],N), [COLOR=#ff00ff]'}}}'[/color]

[COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color], [COLOR=#804040][b]fmt[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]10[/color], [COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) [COLOR=#ff00ff]'{{{'[/color]
[COLOR=#804040][b]do[/b][/color] i [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]1[/color], N
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color], [COLOR=#804040][b]fmt[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]20[/color], [COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) [COLOR=#ff00ff]' '[/color], b(i)
[COLOR=#804040][b]end do[/b][/color]
[COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color], [COLOR=#804040][b]fmt[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]10[/color]) [COLOR=#ff00ff]'}}}'[/color]

[COLOR=#6a5acd]10[/color] [COLOR=#804040][b]format[/b][/color](a3)
[COLOR=#6a5acd]20[/color] [COLOR=#804040][b]format[/b][/color](A[COLOR=#008080]f6.3[/color])

[COLOR=#a020f0]end[/color]
Output:
Code:
 {{{ 10. 23. 36. }}}
{{{ 10.000 23.000 36.000}}}
 
when i want to write it into a file it shows error(format/variable-type mismach).it does not work correctly.like this:


open(44,file='C:\IM.txt')
write(44, fmt=10, advance='no') '{{{'
do i = 1, N
write(44, fmt=20, advance='no') ' ', b(i)
end do
write(44, fmt=10) '}}}'
10 format(a3)
20 format(Af6.3)
 
This works for me good
format02.f90
Code:
[COLOR=#2e8b57][b]integer[/b][/color] :: i, N
[COLOR=#2e8b57][b]real[/b][/color], [COLOR=#2e8b57][b]dimension[/b][/color]([COLOR=#ff00ff]5[/color]) :: b [COLOR=#804040][b]=[/b][/color] ([COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]10[/color], [COLOR=#ff00ff]23[/color], [COLOR=#ff00ff]36[/color], [COLOR=#ff00ff]40[/color], [COLOR=#ff00ff]50[/color][COLOR=#804040][b]/[/b][/color]) 

N[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]3[/color]

[COLOR=#804040][b]open[/b][/color]([COLOR=#ff00ff]44[/color],[COLOR=#804040][b]file[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'IM.txt'[/color])
[COLOR=#804040][b]write[/b][/color]([COLOR=#ff00ff]44[/color], [COLOR=#804040][b]fmt[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]10[/color], [COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) [COLOR=#ff00ff]'{{{'[/color]
[COLOR=#804040][b]do[/b][/color] i [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]1[/color], N
  [COLOR=#804040][b]write[/b][/color]([COLOR=#ff00ff]44[/color], [COLOR=#804040][b]fmt[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]20[/color], [COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) [COLOR=#ff00ff]' '[/color], b(i)
[COLOR=#804040][b]end do[/b][/color]
[COLOR=#804040][b]write[/b][/color]([COLOR=#ff00ff]44[/color], [COLOR=#804040][b]fmt[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]10[/color]) [COLOR=#ff00ff]'}}}'[/color]
[COLOR=#804040][b]close[/b][/color]([COLOR=#ff00ff]44[/color])
[COLOR=#0000ff]! formats[/color]
[COLOR=#6a5acd]10[/color] [COLOR=#804040][b]format[/b][/color](a3)
[COLOR=#6a5acd]20[/color] [COLOR=#804040][b]format[/b][/color](a[COLOR=#008080]f6.3[/color]) 
[COLOR=#a020f0]end[/color]
Compiling and running
Code:
$ g95 format02.f90 -o format02
$ format02
Result file IM.txt
Code:
{{{ 10.000 23.000 36.000}}}
Try it.
 
i am using fortran 90.it has problems on "format(af6.3) ".
 
try to write the in format a1 and f6.3 separated -so:
Code:
20 format(a1 f6.3)
 
or separate a1 anf f6.3 by comma:
Code:
20 format(a1, f6.3)

or write the space in the format
Code:
20 format(' ', f6.3)
and then in the loop write only the array element
Code:
write(44, fmt=20, advance='no') b(i)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top