Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-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
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

I have to say that the / works if i print to screen
but not when i print in a file .dat or .txt
 
Try:-

Code:
      write(50,'(A)') 'firstname'//CHAR(13)//CHAR(10)
      write(50,'(A)') 'lastname'
 
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??
 
How about writeline ...

In my opinion, it should not be a difficult problem to solve, but it is.

My suggestion is to do a Google search and try to find a source for gfortran and its commands with some working examples ...

 
I compiled with g77 and f77
and the result remains the same

In all fortran manuals i see,
slash / begins a new line!!
 
FOURe,

This is a Fortran forum, not a guess the answer quiz!
 
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

 
Use od in UNIX. See the actual bytes. Editors/viewers try to interpret the file contents and sometimes don't get it right. Newlines!

- Steve
 
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.
 
Try using MSword to display the dat file, change the dat extension to txt if necessary.
 
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?
 
Wordpad on windows works fine too.
Thanx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor