For Programmers: Free Programming Magazines  


Home > Archive > Fortran > March 2007 > Need help with fortran file output









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Need help with fortran file output
zcai886@gmail.com

2007-03-16, 4:31 am

Hi everyone,

I am coding with fortran 95 for outputting the data. Is there any
output format in fortran would allow me to read the data in other
softwares (prefer readable by Matlab or excel)?
Thanks for help.

Terence

2007-03-16, 4:31 am

Ant ascii format.
Format(132A1) is an example.
But Matlib and Excel expect rather specific formatting, even if they
also use ascii.


Beliavsky

2007-03-16, 4:31 am

On Mar 15, 7:26 pm, zcai...@gmail.com wrote:
> Hi everyone,
>
> I am coding with fortran 95 for outputting the data. Is there any
> output format in fortran would allow me to read the data in other
> softwares (prefer readable by Matlab or excel)?
> Thanks for help.


Most software used to analyze data can read CSV (comma-separated
value) files, which are easy to create in Fortran. For example, if
each row of data should contain a single integer followed by floats,
you could write

write (some_unit,"(i0,1000(:,',',f0.6))") i,x(i,:)

Especially on Windows, the file written should have the ".csv"
extension, in which case Excel will display it properly.

Michael Prager

2007-03-16, 7:07 pm

zcai886@gmail.com wrote:

> I am coding with fortran 95 for outputting the data. Is there any
> output format in fortran would allow me to read the data in other
> softwares (prefer readable by Matlab or excel)?


If you want to read structured data into R

http://www.r-project.org/

you can find a set of subroutines (For2R) to help you. They are
part of the X2R software written by colleagues and me.

http://cran.r-project.org/


--
Mike Prager, NOAA, Beaufort, NC
Address spam-trapped; remove color to reply.
* Opinions expressed are personal and not represented otherwise.
* Any use of tradenames does not constitute a NOAA endorsement.
Michael Prager

2007-03-16, 7:07 pm

OOPS! The frames got me. The second URL has been corrected
below.

Mike


Michael Prager <Mike.Prager.indigo@noaa.gov> wrote:

> zcai886@gmail.com wrote:
>
>
> If you want to read structured data into R
>
> http://www.r-project.org/
>
> you can find a set of subroutines (For2R) to help you. They are
> part of the X2R software written by colleagues and me.
>


http://cran.r-project.org/contrib/extra/x2r/
Charles Russell

2007-03-16, 7:07 pm

zcai886@gmail.com wrote:
> Hi everyone,
>
> I am coding with fortran 95 for outputting the data. Is there any
> output format in fortran would allow me to read the data in other
> softwares (prefer readable by Matlab or excel)?
> Thanks for help.


Look at the import options for the other software. Usually you can
choose field separators or field widths for your own convenience. I
often simply write(*,*) and then choose space as field separator, though
this won't work if you have any fields with internal spaces.
Beliavsky

2007-03-16, 7:07 pm

On Mar 16, 12:30 pm, Charles Russell <NOS...@bellsouth.net> wrote:
> zcai...@gmail.com wrote:
>
>
> Look at the import options for the other software. Usually you can
> choose field separators or field widths for your own convenience. I
> often simply write(*,*) and then choose space as field separator, though
> this won't work if you have any fields with internal spaces.


Compilers differ in how many items they will write using write (*,*).
For example, the output of

write (*,*) (i,i=1,10)

fills one line in g95 and gfortran but two lines with Intel Visual
Fortran. List-directed output should probably be avoided when the
output will be read by another program.



glen herrmannsfeldt

2007-03-16, 7:07 pm

Beliavsky wrote:

(snip)

> write (*,*) (i,i=1,10)


> fills one line in g95 and gfortran but two lines with Intel Visual
> Fortran. List-directed output should probably be avoided when the
> output will be read by another program.


Only for programs that are sensitive to the number of items
on a line. It should be fine, for example, for Fortran list
directed input, and also for list directed input in other
languages.

-- glen

Richard Maine

2007-03-16, 7:07 pm

glen herrmannsfeldt <gah@ugcs.caltech.edu> wrote:

> Beliavsky wrote:
>
>
>
> Only for programs that are sensitive to the number of items
> on a line. It should be fine, for example, for Fortran list
> directed input, and also for list directed input in other
> languages.


Well... for the "other languages", that would depend on how they defined
it. I'm not aware of any universal, language-independent definition
guaranteeing that any such thing will always act like the Fortran one
does.

It isn't even always guaranteed to work for Fortran. I'd have to check
the details of the exceptional cases. The simplest stuff is ok, but
there are cases of character data that aren't, as I recall.

I'd stick with Beliavsky's advice here for safety.

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







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com