Re: Read DOS or Unix files with the same fortran code



On 29 nov, 00:34, "tia...@xxxxxxxxx" <tia...@xxxxxxxxx> wrote:
On Nov 28, 11:58 pm, nos...@xxxxxxxxxxxxx (Richard Maine) wrote:



tia...@xxxxxxxxx <tia...@xxxxxxxxx> wrote:
I used Fortran to read/write ASCII files in FreeBSD, Solaris, and
Windows. There seems no problems. I suppose that the line-ending
difference between DOS and Unix sytles does not matter.

Then your experience is limitted. This kind of thing depends on the
particular compiler and its run-time libraries. I assure you that there
have existed compilers on those systems for which is *DOES* matter.

In fact, I'm somewhat surprised at the comment because in my experience
it very often matters. We have certainly helped many people in this
newsgroup who had problems with this.

In particular, although some (but not all) DOS compilers can handle the
Unix line endings, my experience is that very few Unix-based compilers
directly handle DOS line endings. The problem there is that a DOS text
file is also a valid Unix text file, but with a different
interpretation. On Unix, the CR character counts as part of the data
instead of part of the line terminator. If a Unix compiler handled DOS
text files, then that would mean there were legitimate Unix text files
that it could not handle correctly. Of course, there could be some kind
of selectable option, but it is hard to imagine how this could be made
to "just work" without user intervantion of some sort.

Depending on how you read the files, you might not notice the problem.
For example, if you always read fixed-length fields, then extra "junk"
at the end of each record might not matter.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain

I only used g77 in Cygwin (Windows XP) and FreeBSD, and Sun Studio
(f77) in Solaris. My text file is a NROW*NCOL numerical array, like:

1 11 111
2 22 222
3 33 333
...

The code I used is,
do i=1,nrow
read(fid,*,end=900) (data(i,j),j=1,ncol)
enddo

It works.

Cheers,
Tian
why you willn't use DOS2UNIX utility? This works fine for me :)
.



Relevant Pages

  • Re: Read DOS or Unix files with the same fortran code
    ... have existed compilers on those systems for which is *DOES* matter. ... although some DOS compilers can handle the ... Unix line endings, my experience is that very few Unix-based compilers ...
    (comp.lang.fortran)
  • Re: Read DOS or Unix files with the same fortran code
    ... have existed compilers on those systems for which is *DOES* matter. ... although some DOS compilers can handle the ... Unix line endings, my experience is that very few Unix-based compilers ...
    (comp.lang.fortran)
  • Re: Bug with compiler or am I just doing something illegal
    ... understand how it worked well as a cygwin program. ... native cygwin will output unix type files. ... a dos2unix command before it passes them to the compiler. ... This ensures the DOS version and the unix version are equivalent. ...
    (comp.lang.c)
  • Re: "Thinking in C++" ; which compiler?
    ... I don't know anything about Unix...does that matter? ... The first thing the installer asks is "Default text type: DOS or UNIX" ...
    (alt.comp.lang.learn.c-cpp)
  • Re: evb runtime problem
    ... > The same way code was compiled in Unix and DOS in the past. ... > compiler program and pass it some switches (including one which indicates ... >> the commandline some, ...
    (microsoft.public.windowsce.embedded.vb)