Fortran错误:子例程

时间:2016-02-01 23:29:51

标签: compilation fortran gfortran

好吧,这个让我难过。我正在合并两个不同的Fortran代码,并且要编译所有内容,首先要编译一个并将其链接到另一个。我非常确定我已经想到了大部分内容,除了当我尝试将其编译为对象时,我得到了

      subroutine snowpacrm(calday,ps,pmidm1,tm1,qm1,o3mmr,cld,clwp,pmln1,pintm1
      1
Error: Unclassifiable statement at (1)

我正在使用gfortran编译,指定固定格式,固定格式的行长度为132,c预处理器打开等。这是相关的代码片段:

#include <misc.h>
#include <params.h>
#define crmoutput 0

c     The following block allows the entire CRM to compile with a simple command
c     Using this command also checks that all needed files are in the CRM
#ifdef SINGLE_SOURCE_FILE
#include <aermix.F>
#include <albocean.F>
#include <blkdat.F>
#include <cldefr.F>
#include <cldems.F>
#include <endrun.F>
#include <freemem.F>
#include <getmem.F>
#include <fmrgrid.F>
#include <orb.F>
#include <radabs.F>
#include <radclr.F>
#include <radclw.F>
#include <radcsw.F>
#include <radctl.F>
#include <radded.F>
#include <radems.F>
#include <radini.F>
#include <radinp.F>
#include <radoz2.F>
#include <radtpl.F>
#include <resetr.F>
#include <torgrid.F>
#include <trcab.F>
#include <trcabn.F>
#include <trcems.F>
#include <trcmix.F>
#include <trcplk.F>
#include <trcpth.F>
#include <zenith.F>
#include <netcdf.F>
#ifndef CRAY
#include <intmax.F>
#include <isrchfgt.F>
#include <isrchfle.F>
#include <wheneq.F>
#include <whenfgt.F>
#include <whenflt.F>
#include <whenne.F>
#endif /* CRAY */ 
#endif /* not SINGLE_SOURCE_FILE */


#include <implicit.h>
c     Parameters
#include <prgrid.h>
c     Commons
#include <comtim.h> /* calday */ 
#include <comvmr.h> /* co2vmr, n2ovmr, ch4vmr, f11vmr, f12vmr */ 
#include <comsol.h> /* scon, tauvis, eccen, obliq, mvelp, iyear_AD, obliqr, lambm0, mvelpp */
#include <comctl.h> /* anncyc,iradsw,iradlw,iradae */
#ifdef CRM_SRB
#include <crmsrb.h> /* Surface radiation budget diagnostics */
#endif

      subroutine snowpacrm(calday,ps,pmidm1,tm1,qm1,o3mmr,cld,clwp,pmln1,pintm1,pilnm1,        
     &                     ts,tg,oro,snowh,gsol0,iyear_AD,loctim,pie,clat,clon,eccen,obliq,    
     &                     mvelp,obliqr,lambm0,mvelpp,o3vmr,asdir,asdif,aldir,aldif,tauvis,    
     &                     co2vmr,n2ovmr,ch4vmr,f11vmr,f12vmr,                                 
     &                     flswn,fllwn,flswu,flswd,fllwu,fllwd,flnet)   !outputs


      real clon(plon)           ! Centered longitude (radians)
      real clat                 ! Current centered latitude (radians)
      real cld(plond,plevp)     ! fractional cloud cover
      real clwp(plond,plev)     ! cloud liquid water path
      real coslat               ! cosine latitude
      real gsol0


c     NB: o3mmr and o3vmr should be dimensioned (plond,plevr) if a different 
c     size radiation grid is used. Clashes between prgrid.h and ptrrgrid.h
c     (they both define plngbuf) prevent us from dimensioning anything by
c     plevr in this top level crm() routine.
      real o3mmr(plond,plev)    ! Ozone mass mixing ratio
      real o3vmr(plond,plev)    ! Ozone volume mixing ratio

      real aldif(plond)         ! Albedo: longwave, diffuse
      real aldir(plond)         ! Albedo: longwave, direct
      real asdif(plond)         ! Albedo: shortwave, diffuse
      real asdir(plond)         ! Albedo: shortwave, direct
      real oro(plond)           ! Land/ocean/sea ice flag
      real pilnm1(plond,plevp)  ! natural log of pintm1
      real pintm1(plond,plevp)  ! model interface pressures
      real pmidm1(plond,plev)   ! model level pressures
      real pmlnm1(plond,plev)   ! natural log of pmidm1
      real ps(plond)            ! surface pressure
      real qm1(plond,plev)      ! model level specific humidity
      real snowh(plond)         ! snow depth (liquid water equivalent)
      real tg(plond)            ! surface (skin) temperature
      real tm1(plond,plev)      ! model level temperatures
      real ts(plond)            ! surface air temperature

c     Fields computed from user input
      real coszrs(plond)        ! cosine solar zenith angle
      real eccf                 ! earth/sun distance factor 
      real effcld(plond,plevp)  ! effective cloud=cld*emis
      real emis(plond,plev)     ! cloud emissivity
      real fice(plond,plev)     ! fractional amount of ice
      real loctim(plond)        ! local time of solar computation
      real lwup(plond)          ! Longwave up flux at surface
      real rei(plond,plev)      ! ice particle size
      real rel(plond,plev)      ! liquid effective drop size (microns)
      real srfrad(plond)        ! srf radiative heat flux

c     Fields output to PLASIM
      real flswn(1,plevp)   ! Net shortwave flux
      real fllwn(1,plevp)   ! Net longwave flux
      real flswu(1,plevp)   ! Shortwave flux up
      real flswd(1,plevp)   ! Shortwave flux down
      real fllwu(1,plevp)   ! Longwave flux up
      real fllwd(1,plevp)   ! Longwave flux down
      real flnet(1,plevp)   ! Net flux

c     Output longwave arguments from radctl()
      real flwds(plond)         ! Surface down longwave flux
      real qrl(plond,plev)      ! Longwave cooling rate

c     Output shortwave arguments from radctl()
      real fsns(plond)          ! Surface absorbed solar flux
      real qrs(plond,plev)      ! Solar heating rate
      real soll(plond)          ! Downward solar rad onto surface (lw direct)
      real solld(plond)         ! Downward solar rad onto surface (lw diffuse)
      real sols(plond)          ! Downward solar rad onto surface (sw direct)
      real solsd(plond)         ! Downward solar rad onto surface (sw diffuse)

c     Additional CRM diagnostic output from radctl()
      real flns(plond)          ! srf longwave cooling (up-dwn) flux
      real flnsc(plond)         ! clr sky lw flx at srf (up-dwn)
      real flnt(plond)          ! net outgoing lw flx at model top
      real flntc(plond)         ! clr sky lw flx at model top
      real fsnsc(plond)         ! clr sky surface abs solar flux
      real fsds(plond)          ! [W m-2] Flux Shortwave Downwelling Surface
      real fsnt(plond)          ! total column absorbed solar flux
      real fsntc(plond)         ! clr sky total column abs solar flux
      real solin(plond)         ! solar incident flux
      real fsnirt(plond)        ! [W m-2] Near-IR flux absorbed at TOA
      real fsnirtsq(plond)      ! [W m-2] Near-IR flux absorbed at TOA>= 0.7 microns
      real fsnrtc(plond)        ! [W m-2] Clear sky near-IR flux absorbed at TOA

c     Local workspace: These variables are not saved
      real hbuf                 ! history buffer
      real pie                  ! 3.14159...
      integer i                 ! longitude index
      integer k                 ! level index
      integer lat               ! latitude row index 

c     Fundamental constants needed by radini()
      real cpair                ! heat capacity dry air at constant prs (J/kg/K)
      real epsilo               ! ratio mean mol weight h2o to dry air
      real gravit               ! gravitational acceleration (m/s**2)
      real stebol               ! Stefan-Boltzmann constant (W/m**2/K**4)

c     Externals
      external blkdat

c     Main Code

请注意,这主要是其他人的代码 - 可能有更好的方法可以编写代码,但主要目标是让它编译并使用不同的代码玩得很好。据我所知,子例程定义中的每个参数都是在子例程本身或#include文件中声明的类型(隐式none在implicit.h中设置)。关于什么可能导致这个错误的任何想法?

编辑:解决(见评论)。错误是在包含诸如implicit none和公共块之类的东西的一些include语句之后放置子例程声明。子程序声明需要先于这些声明。

2 个答案:

答案 0 :(得分:0)

如评论和原始帖子所述,代码的子程序声明需要相对于包含语句出现:

      subroutine snowpacrm(dcalday,ps,pmidm1,tm1,qm1,o3mmr,cld,clwp,pmlnm1,pintm1,pilnm1,        
     &                     ts,tg,oro,snowh,gsol0,diyear_AD,loctim,pie,clat,clon,deccen,dobliq,    
     &                     dmvelp,dobliqr,dlambm0,dmvelpp,o3vmr,asdir,asdif,aldir,aldif,dtauvis,    
     &                     dco2vmr,dn2ovmr,dch4vmr,df11vmr,df12vmr,                                 
     &                     flswn,fllwn,flswu,flswd,fllwu,fllwd,flnet)   !outputs



#include <implicit.h>
c     Parameters
#include <prgrid.h>
c     Commons
#include <comtim.h> /* calday */ 
#include <comvmr.h> /* co2vmr, n2ovmr, ch4vmr, f11vmr, f12vmr */ 
#include <comsol.h> /* scon, tauvis, eccen, obliq, mvelp, iyear_AD, obliqr, lambm0, mvelpp */
#include <comctl.h> /* anncyc,iradsw,iradlw,iradae */
#ifdef CRM_SRB
#include <crmsrb.h> /* Surface radiation budget diagnostics */
#endif

答案 1 :(得分:-2)

对于续行,&应放在行,而不是新行。