wxy 发表于 2024-3-27 19:24:27

用f2py 编译f77程序报错

本帖最后由 wxy 于 2024-3-27 19:32 编辑

最近想用f2py编译打包一个模型,大部分代码是f77(.for),f2py -c -m solar solar2.for一直报错。用一个简单函数测试了下转化为自由格式(f90)就没问题,看了下.pyf文件没有正确识别代码 undefined symbol: unknown_subroutine_,尝试设置fcompiler和 --f77flags="-ffixed-form"都不管用,需要加什么设定吗
C=======================================================================

      SUBROUTINE DAYLEN(
   &    DOY, XLAT,                                    !Input
   &    DAYL, DEC, SNDN, SNUP)                        !Output

!-----------------------------------------------------------------------
      IMPLICIT NONE
Cf2py intent(in) doy, xlat
Cf2py intent(out) dayl, dec, sndn, snup
      INTEGER DOY
      REAL DEC,DAYL,PI,RAD,SOC,SNDN,SNUP,XLAT
      PARAMETER (PI=3.14159, RAD=PI/180.0)

!-----------------------------------------------------------------------
C   Calculation of declination of sun (Eqn. 16). Amplitude= +/-23.45
C   deg. Minimum = DOY 355 (DEC 21), maximum = DOY 172.5 (JUN 21/22).
      DEC = -23.45 * COS(2.0*PI*(DOY+10.0)/365.0)

C   Sun angles.SOC limited for latitudes above polar circles.
      SOC = TAN(RAD*DEC) * TAN(RAD*XLAT)
      SOC = MIN(MAX(SOC,-1.0),1.0)

C   Calculate daylength, sunrise and sunset (Eqn. 17)
      DAYL = 12.0 + 24.0*ASIN(SOC)/PI
C FO 06/05/2022 Added protection to avoid day length less than 0.0
C               and greater than 24.0 hours.      
      DAYL = MIN(MAX(DAYL,0.0),24.0)
      SNUP = 12.0 - DAYL/2.0
      SNDN = 12.0 + DAYL/2.0

      RETURN
      END SUBROUTINE DAYLEN



wxy 发表于 2024-3-27 20:33:51

感谢群里大佬 是!号注释的锅

wxy 发表于 2024-3-28 10:29:57

本帖最后由 wxy 于 2024-3-28 13:23 编辑

wxy 发表于 2024-3-27 20:33
感谢群里大佬 是!号注释的锅
提交了bug,等修复吧
https://github.com/numpy/numpy/issues/26148
https://github.com/numpy/numpy/i ... ecomment-2022895355
页: [1]
查看完整版本: 用f2py 编译f77程序报错