1

Is there a function in Fortran that inquires the type of operative system? and gives this type as a string or similar? Basically I would like to use the function SYSTEM and run my program both on linux and windows machines. My program employing the function SYSTEM works well on linux but now I want to do it general and run it also on windows. Lets say that this function I am looking for is called INQUIRE_SYSTEM. My program reads:

    USE IFPORT

    stringSYSTEM = INQUIRE_SYSTEM()

    if (TRIM(ADJUSTL(stringSYSTEM).eq.linux)) THEN ! linux systems
      I = SYSTEM("mv final.out restart.dat")
      If (I == -1) then
         errnum = ierrno( )
         print *, 'Error ', errnum
      end if
    else  !dos systems
      I = SYSTEM("rename final.out restart.dat")
      If (I == -1) then
      errnum = ierrno( )
      print *, 'Error ', errnum
    end if

thank you very much for any help. A.

4

1 回答 1

1

一种方法是检查预处理器宏。根据您支持的操作系统建立一个列表。请参阅如何使用预处理器指令检查操作系统?.

当文件类型为大写时,许多 Fortran 编译器会运行预处理器:F90。或者有一个编译器选项。代码示例:

#ifdef __GFORTRAN__ 
    write (*, '( "gfortran" )' )
#endif

为什么需要了解 Fortran 程序的操作系统?

于 2013-07-03T21:18:24.993 回答