ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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.
Last edited by parekhharsh_j; 07-07-2011 at 07:05 AM.
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.
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.
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:
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!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.