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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:11:02+00:00 2026-05-16T14:11:02+00:00

Hey, I wrote this (fortran) with the aim of finding the minimum spanning tree

  • 0

Hey, I wrote this (fortran) with the aim of finding the minimum spanning tree of a bunch of points (syscount of them). I know for a fact that this approach works, since i wrote it in javascript earlier today. js is slow though, and i wanted to see how much faster fortran would be!!
only problem is it’s not working, i’m getting an annoying error;

prims.f95:72.43:

if((check == 1) .and. (path(nodesin(j))(k) < minpath)) then

                                 1

Error: Expected a right parenthesis in expression at (1)

What the hell is that about?! the 43rd character on the line is the “h” of “path”

nodesin(1) = 1

do i = 1,syscount-1
    pathstart = -1
    pathend = -1
    minpath = 2000

    do j = 1,i
        do k = 1, syscount

            check = 1
            do l = 1, i
                if(nodesin(l) == k) then
                    check = 0
                end if
            end do

            if((check == 1) .and. (path(nodesin(j))(k) < minpath)) then
                minpath = path(nodesin(j))(k)
                pathstart = nodesin(j)
                pathend = k
            end if

        end do
    end do

    nodesin(i+1) = pathend
    minpaths(i)(1) = pathstart
    minpaths(i)(2) = pathend

end do

Also, i’m fairly new to fortran, so i have a few other questions;

can i use && instead of .and. ?

is there a versions of the for(object in list){} loop found in many other languages?

is there a verion of the php function in_array ? i.e. bool in_array(needle,haystack), and if there is, is there a better way of doing it than:

check = false
Asize = size(array)
do i = 1, Asize
    if(array(i) == needle) then
        check = true
    end if
end do

then to using the check variable to see if it’s there?

(I haven’t posted anything on stackoverflow before. please don’t get angry if i’ve broken loads of etiquette things!)

  • 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-05-16T14:11:02+00:00Added an answer on May 16, 2026 at 2:11 pm

    It looks like you have defined path and minpaths as two-dimensional arrays. Multi-dimensional arrays are accessed differently in Fortran when compared to C-like languages. In Fortran you separate the indices by commas within one set of parentheses.

    I’m guessing by the use of these variables they are integer arrays. Here is how you access elements of those arrays (since you didn’t share your variable declarations I am making up the shape of these arrays):

    integer :: path(n1, n2)
    integer :: minpaths(n3, 2)
    

    your if statement should be:

    if((check == 1) .and. (path(nodesin(j), k) < minpath)) then
    

    your access to minpaths should be:

    minpaths(i, 1) = pathstart
    minpaths(i, 2) = pathend
    

    Also, if you are not using IMPLICIT NONE I recommend you consider it. Not using it is dangerous, and you are using variable names that are close to each other (minpath and minpaths). You could save hours of hair pulling debugging by using IMPLICIT NONE.

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

Sidebar

Related Questions

No related questions found

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.