[SciPy-User] writing data to binary for fortran

alan at ajackson.org alan at ajackson.org
Sat May 15 20:09:02 EDT 2010


A few years ago I was speaking with a colleague - a brilliant gentleman
in his late seventies who had done the blast wave modeling for the
Bikini Atoll tests on a slide rule - and I mentioned that for his
finite difference elastic wave equation modeling code he must use a lot
of double precision arithmetic. He looked very hurt, and replied "Oh
no, single precision is all you need if you know what you're doing".


>"Back in the day," double precision was MUCH slower than single precision arithmetic, so Fortran used single precision by default.  You used double precision only when absolutely necessary, and you had to call it explicitly.  Fortran even had separate "built-in" functions for single and double - eg., sin, dsin, log, dlog, etc. - that the user called explicitly.  (I haven't used Fortran for 20 years, but I think modern Fortran recognizes the type of argument, now.)
>
>Single and double precision are about the same speed on modern processors, and double is sometimes even faster than single on 64 bit processors (because of the ancillary data shuffling, I think).  However, Fortran is dragging nearly 60 years of history along with it, so I'm not surprised that it defaults to single precision.
>
>john
>
>
>
>On 5/12/2010 6:05 PM, Gideon wrote:Yea, that worked for me on my OS X machine.  Thanks so much.
>
>To be honest, in the 10 years I've been doing floating point
>calculations for ODEs and PDEs, I don't think I've ever used single
>precision arithmetic. So I am surprised it doesn't default to double
>precision.  Obviously, different people have different needs.
>
>On May 12, 4:21 pm, Neil Martinsen-Burrell <n... at wartburg.edu> wrote:
>  On 2010-05-12 14:58, Gideon wrote:
>
>    Tried both, but I got the same error in both cases.
>      
>If you want doubles in your file, you have to request them:
>
>F.writeReals(x, prec='d')
>
>makes everything work for me (Ubuntu 10.04, python 2.6.5, gfortran
>4.4.3).  Note that looking at the size of the file that you would expect
>to have for the data you are expecting to read would have demonstrated
>this: 10 doubles at eight bytes per double plus two 4-byte integers
>would have given you 88 bytes for the file, rather than the 48 that were
>being produced.
>
>I use fortranfile most heavily for reading files, rather than writing
>them, so I may have missed this opportunity, but do you think that the
>precision used in writeReals should be auto-detected from the data type
>that it is passed.  That is, would
>
>def writeReals(self, reals, prec=None):
>     if prec is None:
>         prec = reals.dtype.char
>     ...
>
>be better for your use?  That would have made your original code work as
>written.
>
>-Neil
>_______________________________________________
>SciPy-User mailing list
>SciPy-U... at scipy.orghttp://mail.scipy.org/mailman/listinfo/scipy-user
>
>--
>You received this message because you are subscribed to the Google Groups "SciPy-user" group.
>To post to this group, send email to scipy-user at googlegroups.com.
>To unsubscribe from this group, send email to scipy-user+unsubscribe at googlegroups.com.
>For more options, visit this group athttp://groups.google.com/group/scipy-user?hl=en.
>    _______________________________________________
>SciPy-User mailing list
>SciPy-User at scipy.org
>http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
>No virus found in this incoming message.
>Checked by AVG - www.avg.com 
>Version: 9.0.819 / Virus Database: 271.1.1/2869 - Release Date: 05/12/10 02:26:00
>
>  


-- 
-----------------------------------------------------------------------
| Alan K. Jackson            | To see a World in a Grain of Sand      |
| alan at ajackson.org          | And a Heaven in a Wild Flower,         |
| www.ajackson.org           | Hold Infinity in the palm of your hand |
| Houston, Texas             | And Eternity in an hour. - Blake       |
-----------------------------------------------------------------------



More information about the SciPy-User mailing list