Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Variable to know Linux or Windows

Zorrilla__David
초급자
1,012 조회수

Is there a variable in fortran that say if the program is running in linux or windows or mac?

0 포인트
3 응답
TimP
명예로운 기여자 III
1,012 조회수
Quoting - zorro68

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.

0 포인트
jimdempseyatthecove
명예로운 기여자 III
1,012 조회수
Quoting - zorro68

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

0 포인트
Steven_L_Intel1
1,012 조회수

Since you cannot run the same executable on Linux and Windows, you can use the preprocessor symbols to "detect" the OS.

0 포인트
응답