Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

newline character doesnt work?

Status
Not open for further replies.

TheKKK

Mechanical
Mar 22, 2009
21
0
0
GR
I use gfortran on cygwin and in a simple code like:

Code:
      program test
      open(50,file='test.dat')
      write(50,'(A)') 'firstname'
      write(50,'(A)') 'lastname'
      close(50)
      end

i get:

firstnamelastname

instead of

firstname
lastname

i also tried
Code:
      write(50,'(A/)') 'firstname'
      write(50,'(A/)') 'lastname'
and
Code:
      write(50,'(A)',ADVANCE='YES') 'firstname'
      write(50,'(A)') 'lastname'
with no results.

What can be the problem??



 
Replies continue below

Recommended for you

None of these worked...

The // is a concatenation operator
and writeln (or writenl) is not recognized by my compiler
 
"The // is a concatenation operator"

yes it is! it is needed to concatenate char(13) which is carriage return and char(10) which is linefeed to the end of the line, as is the case for text files in MS Dos and Windows.


"writeln (or writenl) is not recognized by my compiler"

because neither is Fortran !



What are you using to view the output file with??
 
I compiled with g77 and f77
and the result remains the same

In all fortran manuals i see,
slash / begins a new line!!
 
program test
Code:
      open(50,file='test.dat')
      write(6 ,FMT='(I3,/)') 111
      WRITE(6 ,FMT='(I3,/)') 222
      write(50,FMT='(I3,/)') 111
      WRITE(50,FMT='(I3,/)') 222
      close(50)
      end
In the above, at the screen i see:
111
222
but in the dat file i see:
111222

 
Thank you TheKKK,

Notepad will not recognise a "unix" formatted file with just a linefeed character (char(10) as above) at the end of each line as a delimiter. Notepad being Microsoft expects to see a carriage return followed by a linefeed (char(13 and char(10)), to signify a new line.

If you use an editor like PFE32 it will recognise and distinguish between MS or unix text files , (displaying the file format in a box), I'm sure there are other editors that will do likewise.

Gfortran on cygwin means it has been ported from linux to run on windows, that's probably your problem. Try using the windows version of g95 instead, it works fine.
 
johnhors:

I only have a version of Fortran77 complier installed on my computer.

Now, I can say that you had an answer to the question and/or problem, but there was a file reading issue getting in the way -- you recognized what the issue was ...

In my opinion, with computer work, there is always something that gets in one's way no matter how simple and obvious the problem is -- there is always more to it than it should be ...

Thanks!

 
Thank you very much

but since i dont want to use microsoft editor like MSword u mentioned..

Do u know an editor i can call with cygwin that will display the result correctly?
 
Status
Not open for further replies.
Back
Top