LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-06-2011, 08:07 AM   #1
parekhharsh_j
LQ Newbie
 
Registered: Jun 2011
Posts: 20

Rep: Reputation: Disabled
gfortran produces word wraped file


This is a simple program to print 2 array in column
However when TRY.txt file was opened in Notepad a "word wrap" feature was ON.
As a result I am not able to load TRY.txt file in other software packages.
When I compiled the same program in Silverfrost.
The problem was solved and I got proper arranged 2 arrays.
Is there a way to circumvent the problem in gfortran

Code:
program try
implicit none
integer::x(10),y(10),n
do n=1,10
x(n)=n
y(n)=n+10
enddo
OPEN(10,FILE="TRY.txt",STATUS='REPLACE')
DO n=1,10
write(10,'(1x,I2,1x,I2)')x(n),y(n)
enddo
close(10)
end program try

PHP Code:
 1 11
  2 12
  3 13
  4 14
  5 15
  6 16
  7 17
  8 18
  9 19
 10 20 
 
Old 07-07-2011, 01:05 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
The wrap feature does not depend on the Fortran compiler. If you tell Fortran to write data on the same line, it will do flawlessly. Anyway, your code does not produce long lines of output. Can you explain where the wrapped lines come from? Maybe I misunderstood your post.
 
Old 07-07-2011, 06:44 AM   #3
parekhharsh_j
LQ Newbie
 
Registered: Jun 2011
Posts: 20

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by colucix View Post
The wrap feature does not depend on the Fortran compiler. If you tell Fortran to write data on the same line, it will do flawlessly. Anyway, your code does not produce long lines of output. Can you explain where the wrapped lines come from? Maybe I misunderstood your post.
I have attached two files. One file produced in gfortran named TRY_gfortran.txt and other produced in silverfrost is named TRY_silverfrost.txt. Please try to open in Notepad only. As I have observed word wrap features is not recognisable in other text editor software and both output will look same. However if you open in Notepad you'll see that file name TRY_gfortran.txt produces long lines of output while output of other file will give you output as two exact cloumns.
Thanks a lot.
Attached Files
File Type: txt TRY_gfortran.txt (70 Bytes, 10 views)
File Type: txt TRY_silverfrost.txt (80 Bytes, 9 views)

Last edited by parekhharsh_j; 07-07-2011 at 07:05 AM.
 
Old 07-07-2011, 06:50 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Running the file command on both the files, you can see the actual difference:
Code:
$ file TRY_*
TRY_gfortran.txt:    ASCII text
TRY_silverfrost.txt: ASCII text, with CRLF line terminators
This means that the second one has windows line terminators, whereas the first one has UNIX line terminators. Notepad is known to not interpret the UNIX newline character, so that it puts the whole thing on a single line. If you want to correctly open the first file in Notepad, you can try (under Linux):
Code:
unix2dos TRY_gfortran.txt
This basically converts the line terminator, that is \n is transformed to \r\n. Hope this helps.
 
1 members found this post helpful.
Old 07-07-2011, 07:00 AM   #5
parekhharsh_j
LQ Newbie
 
Registered: Jun 2011
Posts: 20

Original Poster
Rep: Reputation: Disabled
Now, since I have to run Fortran program in UNIX. Is there a way to produce a file in UNIX with(CRLF line terminator) which are then recognisable in windows? Like any modification in Fortran programming ?

Last edited by parekhharsh_j; 07-07-2011 at 07:04 AM.
 
Old 07-07-2011, 07:13 AM   #6
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Yes. You can explicitly put a carriage return at the end of the line by means of the ACHAR function. Since the decimal number of carriage return in the ASCII table is 13, you can do something like:
Code:
WRITE(10,'(1x,I2,1x,I2,A)') x(n), y(n), ACHAR(13)
and the trick is done!
 
1 members found this post helpful.
Old 07-07-2011, 07:22 AM   #7
parekhharsh_j
LQ Newbie
 
Registered: Jun 2011
Posts: 20

Original Poster
Rep: Reputation: Disabled
Bingo!!
I do not quite understand the significance of ACHAR(13). But trick surely worked.
 
Old 07-07-2011, 07:28 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
The function ACHAR(i) accepts an integer value i, and returns the character at that position in the ASCII character set. Useful to print out hidden control characters!
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Does gfortran has issue working with the file as I/P and O/P ?? parekhharsh_j Linux - Newbie 6 06-17-2011 08:39 AM
bash shell script read file word by word part 2 justina Programming 7 01-25-2011 01:19 PM
[SOLVED] bash shell script read file word by word. justina Programming 15 01-22-2011 10:12 AM
redirect stdout to file produces blank file kissaki Linux - Software 5 01-06-2009 03:28 AM
[SOLVED] find a word in a file, and change a word beneath it ?? vikas027 Programming 10 02-14-2008 09:46 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration