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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New line in Direct Access Formatted file in fortran

Status
Not open for further replies.

nikhill

Technical User
Mar 4, 2010
3
US
Hello,

I am trying to write a file as direct access formatted file: The code for this is:
Code:
              open(unit=9,file='chk.dat',form='formatted',
     +             access='DIRECT',RECL=200)


              write(9,326,REC=NF), (X(I),I=1,11),F,NF

 326          format(11f15.6,1PD18.10,i8)

The output file however contains all the lines written by the above code in a single line(the write command is called multiple times). I have also tried several formats such as:
Code:
 format(/,11f15.6,1PD18.10,i8)

 format(11f15.6,1PD18.10,i8,/)

 format(11f15.6,1PD18.10,i8,2A1)
But nothing works. Can someone help me in inserting a new line after each write operation ?? Thanks.

Nikhil
 
I think the problem is because it is direct access, the / does not generate linefeeds. You could try
Code:
character*1 LF
LF = char(10)
              write(9,326,REC=NF), (X(I),I=1,11),F,NF, LF

 326          format(11f15.6,1PD18.10,i8,A)
 
Hi,

Thank You..That worked !!

However when I read the same using the read statement, i have a new problem.

My read statement is like this:
Code:
            read(chkwrite,327,REC=last_line),
     +           (X(j),j=1,N),F,nfev,LF

 327        format(11D15.6,1PD18.10,I6,A)

the values are read correctly. But when I assign these values to another variable, it does not work and only 0.00000 gets saved into the other variable.
Code:
if(nfev.eq.1) then
      hist(nfev,2,job) = F
endif

When i print the 'hist' array to check the value of F, it prints the following
F = 0.00000000.

this is a simple assignment but somehow does not work. Does anyone have an idea why this is happening.

the declarations of variables are:
Code:
real*8 f
double precision hist(a,b+2,c)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top