×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

newline character doesnt work?

newline character doesnt work?

newline character doesnt work?

(OP)
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??



 

RE: newline character doesnt work?

(OP)
I have to say that the / works if i print to screen
but not when i print in a file .dat or .txt

RE: newline character doesnt work?

Try:-

CODE

      write(50,'(A)') 'firstname'//CHAR(13)//CHAR(10)
      write(50,'(A)') 'lastname'
 

RE: newline character doesnt work?

How about if you try writeln instead of write.

If I am not mistaken, it should work for you -- please check it out ...

http://www.engineering-4e.com

RE: newline character doesnt work?

(OP)
None of these worked...

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

RE: newline character doesnt work?

"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??

RE: newline character doesnt work?

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 ...

http://www.engineering-4e.com

RE: newline character doesnt work?

(OP)
I compiled with g77 and f77
and the result remains the same

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

RE: newline character doesnt work?

FOURe,

This is a Fortran forum, not a guess the answer quiz!
 

RE: newline character doesnt work?

(OP)
      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

 

RE: newline character doesnt work?

TheKK,

With what are you viewing the file "test.dat" ?

RE: newline character doesnt work?

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

RE: newline character doesnt work?

(OP)
I see the dat file with a notepad

RE: newline character doesnt work?

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.
 

RE: newline character doesnt work?

Try using MSword to display the dat file, change the dat extension to txt if necessary.

RE: newline character doesnt work?

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!

http://www.engineering-4e.com

RE: newline character doesnt work?

(OP)
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?

RE: newline character doesnt work?

(OP)
Wordpad on windows works fine too.
Thanx

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close