[comp.lang.fortran] How to use -I to specify an alternate include directory in f77

oliveria@caen.engin.umich.edu (ROQUE DONIZETE DE OLIVEIRA) (04/18/91)

The transcript below demonstrates tht problem I'm having with specifying
an alternate directory to search for INCLUDE files in f77 on the decs running
ultrix 4.1 or apollos running sr10.3 DomainOS.

spam% cat ~/nodes.cbl
      PARAMETER (MaxNode=10000)
spam% pwd
//spam/sys/node_data/tmp
spam% cat ~/nodes.cbl
      PARAMETER (MaxNode=10000)
spam% cat j.F
      INCLUDE 'nodes.cbl'
      DIMENSION L(Maxnode),F(Maxnode)
C Do some calculations
      STOP
      END

spam% f77 -c -I/users/oliveria j.F
j.f:
(00001)       INCLUDE 'nodes.cbl'
**** Error #64 on Line 1: cannot open file

The transcript above is for the apollos but I get a similar error on the decs.
I tried several combinations of -I options. I also use j.f instead of j.F but
nothing. 
The man page on f77 for both decs (decstation 5000)  and apollos mention 
the -I option although it says the -I option changes the search path for
 #include files. Isn't this #include refering to the INCLUDE f77 statement ?

Does anyone know what is wrong ? I'm using the -I option incorrectly ? 
Or is it just another bug. On the apollos the f77 compiler is  
               "Fortran 77 compiler 68K Rev 10.8(190)"

Thanks.

    Roque Oliveira
    oliveria@caen.engin.umich.edu

silvert@cs.dal.ca (Bill Silvert) (04/18/91)

In article <1991Apr18.055611.6793@engin.umich.edu> oliveria@caen.engin.umich.edu (ROQUE DONIZETE DE OLIVEIRA) writes:
>The transcript below demonstrates tht problem I'm having with specifying
>an alternate directory to search for INCLUDE files in f77 on the decs running
>ultrix 4.1 or apollos running sr10.3 DomainOS.
>(00001)       INCLUDE 'nodes.cbl'
>**** Error #64 on Line 1: cannot open file
>
>The transcript above is for the apollos but I get a similar error on the decs.
>I tried several combinations of -I options. I also use j.f instead of j.F but
>nothing. 
>The man page on f77 for both decs (decstation 5000)  and apollos mention 
>the -I option although it says the -I option changes the search path for
> #include files. Isn't this #include refering to the INCLUDE f77 statement ?
>
>Does anyone know what is wrong ? I'm using the -I option incorrectly ? 

I've run into this on my SGI machine and was informed that the -I option
supports only the #include format.  So although it is in the manual, it
doesn't seem to do us any good.  I gather it is a general Unix problem.

If anybody can come up with a scheme to implement the -I option in f77
with the standard indented form that Roque describes above, it would be
great!


-- 
William Silvert, Habitat Ecology Division, Bedford Inst. of Oceanography
P. O. Box 1006, Dartmouth, Nova Scotia, CANADA B2Y 4A2.  Tel. (902)426-1577
UUCP=..!{uunet|watmath}!dalcs!biome!silvert
BITNET=silvert%biome%dalcs@dalac	InterNet=silvert%biome@cs.dal.ca

peterson@fman.enet.dec.com (Bob Peterson) (04/18/91)

In article <1991Apr18.055611.6793@engin.umich.edu>, 
oliveria@caen.engin.umich.edu (ROQUE DONIZETE DE OLIVEIRA)
 writes:

>The man page on f77 for both decs (decstation 5000)  and apollos mention 
>the -I option although it says the -I option changes the search path for
> #include files. Isn't this #include refering to the INCLUDE f77 statement ?

Speaking for DEC Fortran V3: -I is passed to the cpp, and 
hence affects only '#include'.   INCLUDE statements are not affected
by -I.  The file gets foud in either the working directory or
the place where the including source was found, depending on
the -vms switch.

\bob
 peterson@tle.enet.dec.com

ddh@hare.cdc.com (Dan Horsfall) (04/18/91)

In article <1991Apr18.055611.6793@engin.umich.edu>,
   oliveria@caen.engin.umich.edu (ROQUE DONIZETE DE OLIVEIRA) writes:
> The transcript below demonstrates tht problem I'm having with specifying
> an alternate directory to search for INCLUDE files in f77 on the decs running
> ultrix 4.1 or apollos running sr10.3 DomainOS.
> 
> spam% cat j.F
>       INCLUDE 'nodes.cbl'
>       DIMENSION L(Maxnode),F(Maxnode)
>       END
> 
> spam% f77 -c -I/users/oliveria j.F
> j.f:
> (00001)       INCLUDE 'nodes.cbl'
> **** Error #64 on Line 1: cannot open file
> 
> Does anyone know what is wrong ? I'm using the -I option incorrectly ? 

In a word, yes.  You caught the problem yourself, but I trimmed it to
fit posting guidelines on this system.

Understand that "f77" is not the compiler itself.  It is a driver, which
calls lots of separate pieces of the "compiler system" in sequence,
depending on file suffices and command-line options.

1) The -I parameter on f77 line, particularly when used with ".F" files,
   tells the *preprocessor* (usually _cpp_, where to look for #include
   files.  This form of include is _not_ a FORTRAN statement, which you can
   tell because it does not start in column 7, contains a non-FORTRAN
   character, etc.  

2) The " INCLUDE 'nodes.cbl' " statement _is_ a FORTRAN statement.  The
   preprocessor doesn't see it, because it's looking for #include in
   column 1.  This INCLUDE is processed by the compiler itself (fcom, in
   many cases).  In general, the compiler looks ONLY in the same 
   directory as the file it is compiling.

The incompatibility of these two statements is causing your problem.
Unfortunately, there is no completely-portable solution to this
issue, as each vendor has implemented this extension to the language
in his own fashion (and you can bet your ass that NO vendor is going
to invalidate all the "millions and millions" of lines of existing
code on their platform by changing their compiler, solely to be compatible
with one of their competitors!)

For C-based systems, the #include statement will be more-portable 
since many systems will have cpp.

oliveria@srvr1 (ROQUE DONIZETE DE OLIVEIRA) (04/19/91)

From article <1991Apr18.055611.6793@engin.umich.edu>, by oliveria@caen.engin.umich.edu (ROQUE DONIZETE DE OLIVEIRA):
> The transcript below demonstrates tht problem I'm having with specifying
> an alternate directory to search for INCLUDE files in f77 on the decs running
> ultrix 4.1 or apollos running sr10.3 DomainOS.
> 
> spam% cat ~/nodes.cbl
>       PARAMETER (MaxNode=10000)
> spam% pwd
> //spam/sys/node_data/tmp
> spam% cat ~/nodes.cbl
>       PARAMETER (MaxNode=10000)
> spam% cat j.F
>       INCLUDE 'nodes.cbl'
>       DIMENSION L(Maxnode),F(Maxnode)
> C Do some calculations
>       STOP
>       END
> 
> spam% f77 -c -I/users/oliveria j.F
> j.f:
> (00001)       INCLUDE 'nodes.cbl'
> **** Error #64 on Line 1: cannot open file
> 
> The transcript above is for the apollos but I get a similar error on the decs.
> I tried several combinations of -I options. I also use j.f instead of j.F but
> nothing. 
> The man page on f77 for both decs (decstation 5000)  and apollos mention 
> the -I option although it says the -I option changes the search path for
>  #include files. Isn't this #include refering to the INCLUDE f77 statement ?
> 
> Does anyone know what is wrong ? I'm using the -I option incorrectly ? 
> Or is it just another bug. On the apollos the f77 compiler is  
>                "Fortran 77 compiler 68K Rev 10.8(190)"
> 
> Thanks.
> 
>     Roque Oliveira
>     oliveria@caen.engin.umich.edu
> 

Thanks to all those who replied. There is no portable way of doing this
but not all is lost. I did more testing on all platforms available to me.

In all the examples below I was working in /tmp. The include file 'nodes.cbl'
was in my home directory (not /tmp) and contained only 1 line, shown below:
      PARAMETER (MaxNode=10000)



------------------The transcript below is for the IBM RS/6000--------------
tsetse% pwd
/tmp
tsetse% cat junk.f
      SUBROUTINE FLGVVR ( )
      INCLUDE 'nodes.cbl'
      DIMENSION L(maxnode)
C do some calculations here
      RETURN
      END

tsetse% xlf -c junk.f
  2.6   1512-001: (S) Input file nodes.cbl was not found or is not define
d.  Statement is ignored.
1501-511  Compilation failed for file junk.f.

tsetse% xlf -c -I/afs/engin.umich.edu/user/o/l/oliveria junk.f
** flgvvr   === End of Compilation 1 ===
1501-510  Compilation successful for file junk.f.

------------------The transcript below is for the sun sparcstation---------

sol% cd /tmp
sol% cat junk.F
      SUBROUTINE FLGVVR ( )
#include 'nodes.cbl'
      DIMENSION L(maxnode)
C do some calculations here
      RETURN
      END

sol% f77 -c -I/n/engin/sol/u2/oliveria junk.F
/tmp/cpp.20784.0.f:
        flgvvr:

sol% pwd
/tmp
sol% cat nodes.cbl
cat: nodes.cbl: No such file or directory

------------------The transcript below is for the apollo------------
spam% cat junk.F
      SUBROUTINE FLGVVR ( )
      INCLUDE 'nodes.cbl'
      DIMENSION L(maxnode)
C do some calculations here
      RETURN
      END

spam% f77 -c -I/users/oliveria junk.F
junk.f:
(00002)       INCLUDE 'nodes.cbl'
**** Error #64 on Line 2: cannot open file

Error.  No assembly.
spam% f77 -c -W0,-idir,/users/oliveria junk.F
junk.f:

------------------The transcript below is for the decs (ultrix)------

I couldn't get the -I option to work in any shape or form (INCLUDE, #include,
filename with or without quotes, -cpp option, etc).
---------------------------------------------------------------------

Of the solutions shown above, the IBM RS/6000 was the only one that pleased
me, i.e., I don't have to call the source file filename.F and it follows
the fortran syntax 
                   INCLUDE 'nodes.cbl'

I wish more vendors would adopt a solution like this one.