MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Reading Fortran Data file

  • To: mathgroup at
  • Subject: [mg100320] Re: Reading Fortran Data file
  • From: Szabolcs <szhorvat at>
  • Date: Mon, 1 Jun 2009 07:06:10 -0400 (EDT)
  • References: <gvtmic$gho$>

On May 31, 1:35 pm, christopher pike <mojoflowstu... at> wrote:
> Hi,
>   Have data fortran data file with numbers like 0.447562485933D-01.  =
> need all the digits, but mathematica seems to only read this as
> 0.0448062.
>   I can read it as a string and get
>     "0.448062494397D-01"
> but when I use ToExpression, I get
>    -1 + 0.448062 D
> So how can I read in all the digits.

Fortran's D notation counts as somewhat unusual these days, but the
more common E notation should work fine with Mathematica.  So just
change all Ds to Es with some program before reading the file.

For example, filter the file through the common tr utility:

Import["!tr D E < inputfile", "Table"]

(Of course one could read everything as a string, using "Text" in
Import, then do the replacement using StringReplace[textData, "D" ->
"E"], then use StringImport, but this might not be the best solution
when the file is big and one is low on memory.  A disadvantage of
Mathematica's way of processing data is that it needs to hold
everything in memory.)

  • Prev by Date: Re: Problems with V7
  • Next by Date: Re: Stopping NDSolve after a condition is met x times
  • Previous by thread: Re: Reading Fortran Data file
  • Next by thread: Re: Reading Fortran Data file