- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there a variable in fortran that say if the program is running in linux or windows or mac?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Since you cannot run the same executable on Linux and Windows, you can use the preprocessor symbols to "detect" the OS.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page