- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Is there a variable in fortran that say if the program is running in linux or windows or mac?
링크가 복사됨
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Is there a variable in fortran that say if the program is running in linux or windows or mac?
There is no portable way. At compile time, if you invoke pre-processing, most systems have automatic defines which you could test, e.g. by #if defined .....
For example, if you run ifort -# somelittlefile.F, on linux, you should see which text strings are pre-defined for that system. On Windows ifort, a /Qfpp option will be required, as you can't invoke pre-processing by .F or .F90 suffix.
See the section about Predefined Preprocessor Symbols in the ifort help, where predefines including __linux __APPLE__ _WIN32 are discussed.
At run time, you could do something like
ierrorcode = system("uname -ps > uname.txt") and check what just got written to that file, as well as handling any error returned.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Is there a variable in fortran that say if the program is running in linux or windows or mac?
When you run on Windows, there are specificly namedenvironment variables used. Try examining
[cpp]OS=Windows_NT SystemRoot=C:WINDOWS windir=C:WINDOWS [/cpp]
Jim Dempsey
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
Since you cannot run the same executable on Linux and Windows, you can use the preprocessor symbols to "detect" the OS.