f



What does "Error: Explicit interface required for '*' at (1): assumed-shape argument" mean?

I got the following error. But I am not sure how to fix it. Could anyone please help me with this?

$ gfortran -fimplicit-none -o ./main.exe main.f90
main.f90:16.16:

      call evalf (x, n, f)
                1
Error: Explicit interface required for 'evalf' at (1): assumed-shape argument
$ cat main.f90 
      program main
      implicit none
      integer,  parameter    :: n = 25
      integer,  parameter    :: dp = kind(1.0d0)
      real(dp)               :: f
      real(dp), allocatable  :: x(:)
      integer                :: i

!     Allocate dynamic arrays

      allocate (x(n))
      do 14 i=1, n
         x(i) = 3.0d0
  14  continue

      call evalf (x, n, f)
!      f=.25d0*( x(1)-1.d0 )**2
!      do 20 i=2, n
!         f = f + (x(i)-x(i-1)**2)**2
! 20   continue
!      f = 4.d0*f

      end program

      subroutine evalf (x, n, f)
        implicit none
        integer, parameter :: dp = kind(1.0d0)
        real(dp), intent(in)  :: x(:)
        integer, intent(in) :: n
        real(dp), intent(out)  :: f
        integer :: i

        f=.25d0*( x(1)-1.d0 )**2
        do 20 i=2, n
           f = f + (x(i)-x(i-1)**2)**2
 20     continue
        f = 4.d0*f
      end subroutine



Regards,
Peng
0
Peng
5/27/2015 2:36:29 AM
comp.lang.fortran 11941 articles. 2 followers. Post Follow

4 Replies
1302 Views

Similar Articles

[PageSpeed] 47

> "Peng Yu"  wrote in message

>  call evalf (x, n, f)
                1
Error: Explicit interface required for 'evalf' at (1): assumed-shape 
argument

> $ cat main.f90
.....
>      real(dp), allocatable  :: x(:)
.....
>      allocate (x(n))
.....
      call evalf (x, n, f)
.....
>      end program

>      subroutine evalf (x, n, f)
>        implicit none
>        integer, parameter :: dp = kind(1.0d0)
>        real(dp), intent(in)  :: x(:)
>        integer, intent(in) :: n
>        real(dp), intent(out)  :: f

As the message says, an assumed-shape argument requires an explicit 
interface.
An array declared with (:) is assumed shape.
There are 3 ways to get an explicit interface:

1. write an interface block - Don't do this.
2. make the subroutine an internal procedure - put it after a contains 
statement within the main proram.
3. put the subroutine in a module - If you want to compile as one source 
file, put the code for the module before the main program.

---- e

0
e
5/27/2015 3:20:39 AM
Peng Yu <pengyu.ut@gmail.com> wrote:

> I got the following error. But I am not sure how to fix it. Could anyone
> please help me with this?

(As an aside, I note that unlike the code mentioned in your previous
thread that I responded to, which looked mostly like f77 with minor f90
features, this one is quite heavy in f90-isms. I also see that you do
have access to an f90/f95 compiler).

>       call evalf (x, n, f)
>                 1
> Error: Explicit interface required for 'evalf' at (1): assumed-shape argument

In f77 and before, each procedure in a program could always be compiled
completely independently from every other procedure. That is you could
always call a subroutine without telling the compiler anything about it.
(For a function, you needed to tell the compiler the result type, but
nothing else). The form of the subroutine call (or function reference)
told the compiler everything it needed to know in order to compile the
call (or function reference) correctly. This was called implicit
interface because the information about the procedure's interface was
implicit in the form of the call.

Fortran 90 introduced many features relating to procedure arguments, and
most of those features required that the calling procedure know things
about the procedure that are not evident just from the form of the call.
One of those features is assumed-shape arguments, as in your

>       subroutine evalf (x, n, f)
....
>         real(dp), intent(in)  :: x(:)

The (:) in the declaration of x here means that the compiler takes care
of passing information about the shape of x to the subroutine. That's
handy, but it does mean that the compiler must know to do this when
compiling the call to this subroutine. This is not evident from the CALL
statement alone. So the compiler must have information about the
subroutine's dummy arguments. This information is called an explicit
interface, as opposed to the implicit interface of all f77 subroutines.
It is explicit because you have to explicitly tell the compiler this
information instead of counting on it to infer the information from the
call statement.

Explicit interfaces are required to use most of the f90 features
relating to procedure arguments, but they are useful even in cases where
they are not required. In particular, they help the compiler catch many
common errors. I recommend using explicit interfaces with almost all
procedures in modern Fortran code. In addition to the benefits of
improved error diagnosis, if you make it a habit to use explicit
interfaces everywhere, then you won't need to bother with learning the
exact rules on where they are required.

There are 3 ways to provide an explicit interface.

1. The most recommended way is usually to put the subroutine in a
module. There can be some fine points of this, but the simplest version
looks something like

  module some_module_name
  contains
      ... your subroutine goes here. The whole thing, including
          its subroutine and end subroutine statements.
  end module some_module_name

Then in whatever code that calls the subroutine, before any
declarations, but after the recommended implicit none, add a USE
statement for the module, as in

  use some_module_name

The usual implementation of what happens here is that when you compile
the module, the compiler automatically generates a file that has the
information necessary to use the things in this module. In particular,
this file includes the needed interface information for procedures in
the module.

You previously mentioned being familloiar with C. Although the analogy
isn't perfect, you could think of this file as somewhat like a C include
file with function prototypes, except that the file is automatically
generated.

The USE statement then tells the compiler to look for that file of
information when compiling the calling code.

2. You can make the subroutine an internal subroutine to whatever calls
it. This doesn't require quite as much "fuss" as putting the subroutine
in a module, but it tends to have pretty limitted applicability. In some
ways, it is the simplest approach if it happens to fit your need, but it
doesn't fit a lot of needs. Like the module approach, the generation of
the interface information is automatic. To do that put a CONTAINS
statement (just that word - nothing else) right before the end statement
of the calling procedure and then put the entire code of the called
subroutine after that CONTAINS statement.

3. You can write an interface body for the procedure. This is usually
the *LEAST* recommended approach. It is a bit laborious and error prone.
Unfortunately, some people get confused by the terminology and think
that when they are told they need an explicit interface, that means they
need such an interface body. But an interface body is only one of the
three ways to provide an explicit interface. One admited advantage of
using an interface body is that it can be done without touching the code
of the subroutine. The subroutine doesn't even have to be written in
Fortran. Most of the interface bodies I write are for C functions called
by my Fortran code. To write an interface body in the calling procedure,
do

  interface
    .. code excerpted from your subroutine goes here. Include the
       subroutine statement, the end subroutine statement, and
       all the declarations relating to the subroutine dummy arguments.
       Do not include any executable statements (well, technically
       the end subroutine statement is executable, but that's a special
       case).
  end interface

-- 
Richard Maine
email: last name at domain . net
dimnain: summer-triangle
0
nospam
5/27/2015 3:49:00 AM
"Richard Maine"  wrote in message 
news:1m51orp.oje9a3hnmrk6N%nospam@see.signature...

Beautiful discussion about the need for explicit interface, but the
bullet points below missed proofreading:

> There are 3 ways to provide an explicit interface.

> 1. The most recommended way is usually to put the subroutine in a
> module. There can be some fine points of this, but the simplest version
> looks something like

>   module some_module_name
>   contains
>       ... your subroutine goes here. The whole thing, including
>           its subroutine and end subroutine statements.
>   end module some_module_name

> Then in whatever code that calls the subroutine, before any
> declarations, but after the recommended implicit none, add a USE
> statement for the module, as in

>   use some_module_name

In the above paragraph, USE goes before IMPLICIT NONE of course
(10-007.pdf, table 2.1).

> The usual implementation of what happens here is that when you compile
> the module, the compiler automatically generates a file that has the
> information necessary to use the things in this module. In particular,
> this file includes the needed interface information for procedures in
> the module.

> You previously mentioned being familloiar with C. Although the analogy
> isn't perfect, you could think of this file as somewhat like a C include
> file with function prototypes, except that the file is automatically
> generated.

> The USE statement then tells the compiler to look for that file of
> information when compiling the calling code.

> 2. You can make the subroutine an internal subroutine to whatever calls
> it. This doesn't require quite as much "fuss" as putting the subroutine
> in a module, but it tends to have pretty limitted applicability. In some
> ways, it is the simplest approach if it happens to fit your need, but it
> doesn't fit a lot of needs. Like the module approach, the generation of
> the interface information is automatic. To do that put a CONTAINS
> statement (just that word - nothing else) right before the end statement
> of the calling procedure and then put the entire code of the called
> subroutine after that CONTAINS statement.

> 3. You can write an interface body for the procedure. This is usually
> the *LEAST* recommended approach. It is a bit laborious and error prone.
> Unfortunately, some people get confused by the terminology and think
> that when they are told they need an explicit interface, that means they
> need such an interface body. But an interface body is only one of the
> three ways to provide an explicit interface. One admited advantage of
> using an interface body is that it can be done without touching the code
> of the subroutine. The subroutine doesn't even have to be written in
> Fortran. Most of the interface bodies I write are for C functions called
> by my Fortran code. To write an interface body in the calling procedure,
> do

>   interface
>     .. code excerpted from your subroutine goes here. Include the
>        subroutine statement, the end subroutine statement, and
>        all the declarations relating to the subroutine dummy arguments.
>        Do not include any executable statements (well, technically
>        the end subroutine statement is executable, but that's a special
>        case).
>   end interface

4. The interface to a RECURSIVE subroutine or a RECURSIVE function
with a RESULT clause is explicit within the procedure.

5. Explicit interfaces may be cloned in a procedure declaration
statement.

0
James
5/27/2015 4:13:38 AM
James Van Buskirk <not_valid@comcast.net> wrote:

> "Richard Maine"  wrote in message 
> news:1m51orp.oje9a3hnmrk6N%nospam@see.signature...
> 
> Beautiful discussion about the need for explicit interface, but the
> bullet points below missed proofreading:
....

Thank you for the corrections.

-- 
Richard Maine
email: last name at domain . net
dimnain: summer-triangle
0
nospam
5/27/2015 5:03:10 AM
Reply:

Similar Artilces:

how to make ["a","b",["c","d"],"e"] into ['a', 'b', 'c', 'd', 'e'] ?
--001a11c34e8edbc7c404f6a94bbe Content-Type: text/plain; charset=ISO-8859-1 >>> x=["a","b",["c","d"],"e"] >>> y=x[2] >>> y ['c', 'd'] >>> x.insert(2,y[0]) >>> x ['a', 'b', 'c', ['c', 'd'], 'e'] >>> x.insert(3,y[1]) >>> x ['a', 'b', 'c', 'd', ['c', 'd'], 'e'] >>> del x[4] >>> x ['a', 'b', 'c', 'd', &#...

(mapcar 'quote '("1" "2" "3" "4"))
(mapcar 'quote '("1" "2" "3" "4")) returns ((quote "4") (quote "4") (quote "4") (quote "4")) Interesting and (for me) unexpected. Because (mapcar 'read '("1" "2" "3" "4")) returns (1 2 3 4) and (mapcar 'princ '("1" "2" "3" "4")) gives 1234("1" "2" "3" "4") Why isn't (mapcar 'quote '("1" "2" "3" "4&q...

solution to ""ERROR: Output argument 'a' was not assigned during call to 'xlim'": Link to download xlim.m/ylim.m is not updated
Hi, I found technical solution to download new fixed xlim.m/ylim.m files in this adress: http://www.mathworks.com/support/solutions/en/data/1-19WWP/index.html?product=CO&solution=1-19WWP However they refering to a link to get the fixed files - but the link is not available any more. Do you know where I can download those files from? Thanks, Gilad "Gilad Asseraf" <gilad_asseraf@amat.com> wrote in message news:hsr9v6$333$1@fred.mathworks.com... > Hi, > I found technical solution to download new fixed xlim.m/ylim.m files in > this adress: &g...

"Undefined operator '/' for input arguments of type 'cell'." Error?
What does this error mean? On 8/30/2015 12:49 PM, bobDizzle wrote: > What does this error mean? > You seem to have used {} to build your matrix or vectors. use [] instead of {} and try again On 08/30/2015 1:10 PM, Nasser M. Abbasi wrote: > On 8/30/2015 12:49 PM, bobDizzle wrote: >> What does this error mean? >> > > You seem to have used {} to build your matrix or vectors. > > use [] instead of {} and try again or, dereference cell array contents with {}. The precise solution would depend on the context The answer to the question is tha...

Why """, not '''?
Why is """ the preferred delimiter for multi-line strings? On Mar 5, 9:56 am, MartinRineh...@gmail.com wrote: > Why is """ the preferred delimiter for multi-line strings? Is it ? FWIW, I use single quotes whenever I can and double whenever I have to (i.e. rarely). George On Wed, 5 Mar 2008 06:56:24 -0800 (PST) MartinRinehart@gmail.com wrote: > Why is """ the preferred delimiter for multi-line strings? Where did you see that? The only place I saw it was the style guide and it was only talking about docstrings. Even there they used "...

what does this error mean `activate': can't activate activesupport (= 3.0.1, runtime) for ["activerecord-3.0.1"]
i am using active record in my program and cannot understand what this error means. require 'watir' include Watir require 'active_record' ActiveRecord::Base.establish_connection( :adapter => "mysql", :host => "127.0.0.1", #:host => "sun", :database => "Trader", :username => "root", :password => "password" ) class Rawdata < ActiveRecord::Base set_table_name "rawdatas" end E:\TradingTools\trader\app\helpers>GrabMBTTrades.rb C:/Ruby187/lib/ruby/site_ruby/1.8/rubygems.rb:233:in `ac...

MNRFIT Error "Undefined function or method 'mnrfit' for input arguments of type 'double'"
My data looks like this: Y=[4;4;5;13.....]; (n by 1) X= 1.3 6.9 2.0 3.2 4.2 6.9048 ..... (n by 2) when i used: [B,dev,stats]=mnrfit(x,y,'interactions','off'); The error message appeared : ??? Undefined function or method 'mnrfit' for input arguments of type 'double'. What caused that problem? Also, shall I convert the y into a format of 1,2,3,4,...k, rather than the code number originally assigned for each choice (starting from 4, to 500+. with irregular numbering) Thanks! "Yiyi Wang" <yiyiwang@mail.ute...

What do the authors in The Little Schemer mean by the "function's structure" and "argument's structure"?
Hi all, I finished reading The Little Schemer a few days ago and one of the answers was not clear to me. It's on page 40, 3rd from the top. It's about simplifying the rember function (which removes the first occurrence of an element from a list). The question asks "So why don't we simplify right away?" and the answer is "Because then a function's structure does not coincide with its argument's structure." Any ideas what "a function's structure" and "argument's structure" are? And how do they coincide or not coincide? Here...

fminsearch error: "Undefined function or method 'L' for input arguments of type 'double'"
Hi, I am trying to minimizing the function 'L' below but I keep getting the error: ?? Undefined function or method 'L' for input arguments of type 'double' My code is the following: ---------------------------------------------------------------- %seastate = 2000 x 1 vector %pings = 2000 x 1 vector %entang = 2000 x 1 vector x0 = [-1.5 0.3 -0.1 0.001]; %my initial parameters exponent = @(x0) x0(1) + x0(2).*seastate + x0(3).*pings + x0(4).*pings.^2; pi = @(x0) exp(exponent)./(1 + exp(exponent); oneminuspi = @(x0) 1 - pi(x0); L = @(x0) -1*log(pr...

Request " ''BOLD' Error in process BDUGKSH ''NORMAL' "
How could I put bold characters in request command, like this : Request " ''BOLD' Error in process BDUGKSH ''NORMAL' " Thanks in advance. In article <ddf392ea.0311131305.595344d3@posting.google.com>, contracer11@uol.com.br (Shiva MahaDeva) writes: > How could I put bold characters in request command, like this : > > Request " ''BOLD' Error in process BDUGKSH ''NORMAL' " > > Thanks in advance. It depends on what kind of terminal it's going to. In article <ddf392ea.0311131305.595344d3@pos...

Can't "mk CONF=9pcdisk" --> gives error "rc: #d/0: token '=': syntax error"
I'm in /sys/src/9/pc and I type `mk CONF=9pcdisk` and rc gives me the error "rc: #d/0: token '=': syntax error". Why is this? Just doing mk works fine (I think). Thanks! Plan9 looks very cool... just finished reading through intro (all of it). you're using backquotes, why? that would be `{mk CONF=3D9pcdisk} in rc's syntax. now to compile that kernel the syntax is: % mk 'CONF=3Dpcdisk' now are you sure you want a pcdisk?=20 On Jul 19, 2012, at 6:07 AM, kalaracey@gmail.com wrote: > I'm in /sys/src/9/pc and I type >=20 ...

Compile time error: "error: 'write_n' is not a member of 'ACE'"
Hi All, ACE VERSION: 5.5.6 HOST MACHINE and OPERATING SYSTEM: LINUX, Kernel 2.6.19-1.2288.fc5, i686 I tried to compile the program given below, but was giving following compilation error: Please help me to compile this proram --------------------------------------- COMPILATION------------------------------------------ [root@paresh ACE_MSG_BLOCK]# g++ main.C -o main -lACE -IACE_ROOT main.C: In function 'int main(int, char**)': main.C:9: error: 'read_n' is not a member of 'ACE' main.C:20: error: 'write_n' is not a member of 'ACE' -------...

html dir="rtl" does 'a b c' in same direction as "ltr" but '1 2 3' in different direction
http://www.frostjedi.com/terra/scripts/demo/rtl.html If you view the source, you'll see two divs - <div>a b c</div> and <div>1 2 3</div>. Both are displayed on the right hand side of the screen. <div>a b c</div> renders as 'a b c' but '1 2 3', instead, renders as '3 2 1' and I don't know why. Any ideas? On 2009-02-23, yawnmoth <terra1024@yahoo.com> wrote: > http://www.frostjedi.com/terra/scripts/demo/rtl.html > > If you view the source, you'll see two divs - <div>a b c</div> and &g...

lynx 'browser' can't do "<?xml version="1.0" encoding="utf-8"?>"
lynx is lighteningly fast to fetch a set of pages [via a script] via dump > fileID. But [my current version] doesn't render the 'style' of: "<?xml version="1.0" encoding="utf-8"?>" What is this new "xml" crap ? Will it likely take over the older *.html ? Thanks for any info, == Chris Glur. news@absamail.co.za wrote in news:1172596265.663611@vasbyt.isdsl.net: > lynx is lighteningly fast to fetch a set of pages [via a script] via > dump > fileID. > > But [my current version] doesn't ...

Web resources about - What does "Error: Explicit interface required for '*' at (1): assumed-shape argument" mean? - comp.lang.fortran

Resources last updated: 1/25/2016 3:15:48 PM