0
votes

I have a Fortran program in which I use a format staement for writing like

WRITE (12,'(A72,1X,A,1X,I6.6)') ALINE,SFFIX(1:NUM),LINENO

which works fine. However when I write a character string `fmtt' like

WRITE (fmtt,'(a)') trim(adjustl(sttr(2)))

where string 'sttr (2)is '(A72,1X,A,1X,I6.6) ' ` , which I confirm by printing fmtt like

WRITE(*,'(a)')fmtt

When I use string fmtt as format in a write statement like

WRITE (12, fmtt) ALINE,SFFIX(1:NUM),LINENO

I get error message

forrtl : info(58) format syntax error at or near  '(A72,1X,A,1X,I6.6) '

Though I am not an expert I expected it to work as format is supposed to be a character string. Where am I wrong? I wanted to do this to make format dependent on user input. Thanking you.

1
Can you post a minimal example and state your compiler version? From the information you've provided so far I can't see anything wrong. - Raul Laasner
Not you are not using a "format statement", you are using a "format string". I must second the request for a compilable example. - Vladimir F

1 Answers

0
votes

Probably the single quotation marks ' ' are making problem. Following code is working fine.

implicit none
character(len=30) :: fmtt
fmtt = '(A72,1X,A,1X,I6.6)'
write(*,fmtt)"first_character","second_character",230
stop
end

Note that print*,fmtt give the output without single quotes. I follow the method given in http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap05/format.html . Hopefully this will help you.