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 8500589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:59:12+00:00 2026-06-11T00:59:12+00:00

I am a novice in Fortran programming. I have two .f90 files. fmat.f90 function

  • 0

I am a novice in Fortran programming. I have two .f90 files.

fmat.f90

function fmat(t,y)
 implicit none
 real::t
 real::y(2)
 real::fmat(2)
 fmat(1) = -2*t+y(1)
 fmat(2) = y(1)-y(2)
end function fmat

And, main.f90 looks like:

program main
 implicit none
 real::t
 real::y(2)
 real::fmat(2)
 real::k(2)
 t=0.1
 y(1)=0.5
 y(2)=1.4
 k=fmat(t,y)
 write(*,*) k
end program main

So, I am expecting 0.3 -0.9. But I keep getting the following error messages:

ifort fmat.f90 main.f90

main.f90(13): error #6351: The number of subscripts is incorrect.   [FMAT]
k=fmat(t,y)
--^
compilation aborted for main.f90 (code 1)

Any help is appreciated!

!==== EDIT ====

I thank Mark for his answers. I could actually compile the separate files without any error using a “subroutine” approach.

main.f90

program main
  implicit none
  real::t
  real::y(2)
  real::k(2)
  t=0.1
  y(1)=0.5
  y(2)=1.4
  call fmat_sub(t,y,k)
  write(*,*) k
end program main

fmat_sub.f90

subroutine fmat_sub(t,y,k)
  implicit none
  real::t
  real::y(2),k(2)
  k(1) = -2*t+y(1)
  k(2) = y(1)-y(2)
end subroutine fmat_sub
  • 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-11T00:59:13+00:00Added an answer on June 11, 2026 at 12:59 am

    Your declaration, in main, of real::fmat(2) tells the compiler that fmat is an array of reals with rank 1 and length 2. It does not tell it anything about the function fmat written in your other file.

    One good way to avoid such issues is to use the capabilities of modern Fortran. Put your subroutines and functions into modules and use-associate them. So, change fmat.f90 to something like

    module useful_functions
    
    contains
    function fmat(t,y)
     implicit none
     real::t
     real::y(2)
     real::fmat(2)
     fmat(1) = -2*t+y(1)
     fmat(2) = y(1)-y(2)
    end function fmat
    
    end module useful_functions
    

    and modify main.f90 to something like

    program main
     use useful_functions
     implicit none
     real::t
     real::y(2)
     real::k(2)
     t=0.1
     y(1)=0.5
     y(2)=1.4
     k=fmat(t,y)
     write(*,*) k
    end program main
    

    This approach lets the compiler generate explicit interfaces for the module functions and allows it to check, at compile time, the match between dummy arguments and actual arguments.

    Since you are a novice I’ve put some key terms in italics, read about them in your compiler manual or other favourite Fortran documentation.

    Another way to solve your problem would be to edit main.f90 to include the source for function fmat, like this:

    program main
     implicit none
     real::t
     real::y(2)
     real::k(2)
     t=0.1
     y(1)=0.5
     y(2)=1.4
     k=fmat(t,y)
     write(*,*) k
    
    contains
    
    function fmat(t,y)
     implicit none
     real::t
     real::y(2)
     real::fmat(2)
     fmat(1) = -2*t+y(1)
     fmat(2) = y(1)-y(2)
    end function fmat
    end program main
    

    I favour the first approach, it scales much better when your programs and projects get large and the benefits of modularisation start to become necessities rather than nice-to-have, but the second approach is OK for small programs while you are learning the language.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

C++ novice here. I have some basic questions. In int main( int argc, char
Novice Programmer here - I have an application with two threads that I start,
Python novice here. I am using python2.7.2 on Windows7. I have installed the PyWin32
Purpose: Create a program that takes two separate files, opens and reads them, assigns
Programming novice here. I'm trying to allow a user to enter their name, firstName
complete novice at work (who is also ill and feeling particularly thick) I have
im novice in XML and XSLT. i have a an xml file ( book.xml
total novice here. Trying to work with sqlalchemy but have hit a problem. class
I'm a novice at programming although I've been teaching myself Python for about a
Total Novice here. I have some list items. I need to add a class

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.