FAQ in Fortran Wiki
### Why does [[random_number]] return the same value each time I run my program? {: #random_seed } ### How do I produce a library? {: #libraries } To build a static library `libfoo.a` containing all modules and procedures in the `.f90` files in the current directory on Linux: % gfortran -c *.f90 % ar cr libfoo.a *.o The first command builds the object files and the second archives the object files into a static archive. To build a shared library `libfoo.so`: % gfortran -shared *.f90 -o libfoo.so -fPIC In both cases, other compiler flags such as `-O2` can be used. ### Why doesn't `u == 1.4D0` work? {: #fp-equality } See [[Floating point arithmetic]]. ### How do I read until the end of a file (EOF)? {: #eof } A common [[Fortran 95]] idiom for reading lines until the end of file is integer :: stat character(len=100) :: buf open(15, file='foo.txt') do read(fh, iostat=stat) buf if (stat /= 0) exit ! process buf end do close(15) {: lang=fortran } This example catches all conditions, not just the end of file. To specifically catch the EOF in [[Fortran 2003]] one can use the [[iso_fortran_env]] module and replace the `if` condition above with if (stat == iostat_end) exit {: lang=fortran } See also: [EOF idiom?](http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/149d94a68d30fba3) on [[comp lang fortran|comp.lang.fortran]]. ### How do I read a character without having to press enter? {: #getkey } There isn't a portable way to do this either in Fortran or C, in short, because the terminal controls when the input is sent to your program and by default it is buffered. You must request that the terminal send each key and the method for doing so is platform-dependent. [Clive Page's Fortran Resources](http://www.star.le.ac.uk/~cgp/fortran.html) has a section on "Reading single keystrokes from Fortran" which provides a couple of short C functions ([sys_keyin.c](http://www.star.le.ac.uk/~cgp/sys_keyin.c)) which can be called from Fortran to achive the desired behavior on most Unix systems. See also: [Get Key Function?](http://groups.google.com/groups?threadm=edf0a73b-ff05-4849-90f6-2aa93445d388@v35g2000pro.googlegroups.com) on [[comp lang fortran|comp.lang.fortran]]. ---------- ## See Also * [The Fortran FAQ](http://www.faqs.org/faqs/fortran-faq/)
AltStyle
によって変換されたページ
(->オリジナル)
/
アドレス:
モード:
デフォルト
音声ブラウザ
ルビ付き
配色反転
文字拡大
モバイル