Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8858217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:46:41+00:00 2026-06-14T14:46:41+00:00

Assume we need to call fortran function, which returns some values, in python program.

  • 0

Assume we need to call fortran function, which returns some values, in python program. I found out that rewriting fortran code in such way:

subroutine pow2(in_x, out_x)
      implicit none
      real, intent(in)      :: in_x
!f2py real, intent(in, out) :: out_x
      real, intent(out)     :: out_x
      out_x = in_x ** 2
      return
end

and calling it in python in such way:

import modulename
a = 2.0
b = 0.0
b = modulename.pow2(a, b)

gives us working result. Can I call fortran function in other way, cause I think the first way is a bit clumsy?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:46:42+00:00Added an answer on June 14, 2026 at 2:46 pm

    I think you just need to change your f2py function signature slightly (so that out_x is only intent(out) and in_x is only intent(in)):

    subroutine pow2(in_x, out_x)
      implicit none
      real, intent(in)   :: in_x
      !f2py real, intent(in) :: in_x
      real, intent(out)     :: out_x
      !f2py real, intent(out) :: out_x
      out_x = in_x ** 2
      return
    end subroutine pow2
    

    Now compile:

    f2py -m test -c test.f90
    

    Now run:

    >>> import test
    >>> test.pow2(3)   #only need to pass intent(in) parameters :-)
    9.0
    >>>
    

    Note that in this case, f2py is able to correctly scan the signature of the function without the special !f2py comments:

    !test2.f90
    subroutine pow2(in_x, out_x)
      implicit none
      real, intent(in)   :: in_x
      real, intent(out)     :: out_x
      out_x = in_x ** 2
      return
    end subroutine pow2
    

    Compile:

    f2py -m test2 -c test2.f90
    

    run:

    >>> import test2
    >>> test2.pow2(3)   #only need to pass intent(in) parameters :-)
    9.0
    >>>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to call a function that updates some JS objects on the page
Let's assume that we need some class for wrapping std::string, and besides all other
Assume I have some program that pulls airline data. Each airline data uses a
Assume you are given a large number of variables that need to be initialized
Assume that I only have a country code (en, de, fr) and I need
I need to do a blocking xmlrpc call from my python script to several
I need to program the Ackermann function. This is what I have so far:
I assume I need to use the method call syntax instead of the query
The problem is next: Assume that we have a select. Onchange event we need
Let's assume I've got a class SomethingDAO which I need to adapt to an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.