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!

help with FORMAT command

Status
Not open for further replies.

bob10a

Programmer
Mar 1, 2002
1
US
I want to do something like this:

100 FORMAT(1X,N(F6.2,1X),2X,N2X)
110 FORMAT(M(E10.4))

where N and M are values defined somewhere in the program by calculation, read, etc.
But it is not working. ANy
suggestions.
 
I believe that format statements are evaluated at compile time and hence what you want to do is not possible. If you know what the maximum value of N and M are and they are not too large, you could create all possible formats then use the assign statement, e.g.
Code:
101   FORMAT(1X,F6.2,1X,2X,2X)
102   FORMAT(1X,2(F6.2,1X),2X,4X)
      if (n.eq.1) then
        assign 101 to ifmt
      else if (n.eq.2) then
        assign 102 to ifmt
      endif
      write (1,ifmt) x
For format 110, you could just substitue M for the maximum value it could have.

Hope this helps.

CaKiwi
 
You may simply add &quot;< >&quot; to enclose N and M, i.e.

100 FORMAT(1X,<N>(F6.2,1X),2X,<N>2X)
110 FORMAT(<M>(E10.4))

Anthony
 
You may simply add &quot;< >&quot; to enclose N and M, i.e.

100 FORMAT(1X,<N>(F6.2,1X),2X,<N>2X)
110 FORMAT(<M>(E10.4))

Anthony
 
You could also write these values to a format string.

character(len=30) :: fmtStr
character(len=4) :: sN

integer :: N
.
.
.
.
write (sN, '(I4)') N

fmtStr = '(1X,'//sN//'(F6.2,1X),2X,'//sN//'(2X))'

write (6, fmtStr) data...

Hope this helps,

cpm
 
I would like to improve this post with my problem :
I use format command on Gfortran like this:
11 FORMAT(<MYVAR> E15.8)
MYVAR change dynamically in my program. I dont't know in advance its value.
But it doesn't not run on all fortran (on SUN and HP unix server)
Is this syntax specific to Gfortran ?
It's seems to belong to an extension module of gfortran, not standard fortran
If somebody have a solution to convert this syntax in o more standard formulation ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top