0
votes

Alright, this one has me stumped. I'm merging two different Fortran codes, and to get everything to compile want to compile one first and link it to the other. I'm pretty sure I've figured most of that, except that when I try to compile this as an object, I get

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

I'm compiling with gfortran, specifying fixed form, with a fixed-form line length of 132, with the c preprocessor on, etc. Here's the relevant snippet of code:

#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

Note that this is primarily someone else's code--there may be better ways the code could be written, but the primary goal is just getting it to compile and play nice with a different code. As far as I can tell, each argument in the subroutine definition is declared with a type either in the subroutine itself or in an #include'd file (implicit none is set in implicit.h). Any ideas as to what could be causing this error?

EDIT: Solved (see comments). Error was in placing the subroutine declaration after some of the include statements that included stuff like implicit none and common blocks. Subroutine declaration needed to come before those.

2
What are in the included files? It's quite possible that those contain something which makes a subroutine statement not allowed to appear in that place. Especially as if implicit none is one thing then that suggests some form of program unit already appearing. - francescalus
And it's probably best to look at a minimal reproducible example. - francescalus
Is there a closing parenthesis for the formal parameter list? Oh I see. Are you using a compiler which supports the & line continuation in that form? - wallyk
@wallyk A Fortran compiler must support that character in column 6 as continuation. - francescalus
When creating the minimal example, the gfortran's option -E may prove useful to you. - Vladimir F

2 Answers

0
votes

As noted in comments and original post, code's subroutine declaration needed to appear relative to include statements as such:

      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
-2
votes

For line continuation, & should be placed on the old line, not on the new one.