Fortran formated output for floating point numbers

与世无争的帅哥 提交于 2019-11-28 11:53:28

问题


Is there a way in Fortran to write float numbers as 17,3 and not 17.3, changing the dot to a comma?

I have some large data sets wirtten to a .csv by a subroutine, and i want to do some Excel on it. The german version of Excel uses . as a seperator in floating point numbers. I know i can use the import feature to handle it, or use Nodepad++ to search and replace . with ,. But i do generate lots of these files, and the subroutine will be used by others, so an Excel ready file would be nice.


回答1:


If you're just writing a line or two you can add the decimal edit descriptor dc to your output format. Here's a simple example

write(*,'(dc,f12.3)') 12.3

which produces

12,300

If you want to write to a file, add the clause

decimal = 'comma'

to your open statement, for example:

open(6,decimal='comma')

Of course, here I'm (re-)opening stdout to write commas rather than points.



来源:https://stackoverflow.com/questions/21117216/fortran-formated-output-for-floating-point-numbers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!