How to Pass and Combine Arrays in Fortran g77?

  • Fortran
  • Thread starter mazinse
  • Start date
  • Tags
    Fortran
In summary: MyArray2(10,20)End The subprogram MySubProgram would then see MyArray starting at element 10 in the first dimension and 20 in the second dimension.
  • #1
mazinse
189
2
1. Is there a way to get the index of array, how many cells are nonzeros and have actual data. I can probably do it the hard way.

2. How do you pass an array to a function, the entire array I mean, do I do like function (array(i)) or function (array())

3. Is there an easier way to combine two arraries.

If there are libraries or functions out there that I can call to, lease help
 
Technology news on Phys.org
  • #2
mazinse said:
1. Is there a way to get the index of array, how many cells are nonzeros and have actual data. I can probably do it the hard way.

Write a do-loop that tests each cell one at a time, and increments a counter each time it finds a nonzero cell.

2. How do you pass an array to a function, the entire array I mean, do I do like function (array(i)) or function (array())

Neither way. Use 'call function (array)'.

3. Is there an easier way to combine two arraries.

Easier than what?
 
  • #3
easier than write a loop, checks every cell for value then add them all to a new array.

but I have a new question. When I write my array to a file, I see a lot of 0's, are they empty cells or something else
 
  • #4
With older Fortran compilers, only the addresses of paramters were passed to subroutines. I don't know if this has changed. If it hasn't, then function(array) just passes the address of the array, not the contents of the array.
 
  • #5
mazinse said:
easier than write a loop, checks every cell for value then add them all to a new array.

I'm pretty sure standard Fortran 77 doesn't have intrinsic functions for array operations (copy, merge, etc.). g77 might add some such functions, but you'd have to search through the g77 documentation.

When I write my array to a file, I see a lot of 0's, are they empty cells or something else

If you stored non-zeroes in all the array cells, then you shouldn't get any zeroes on output. But it's hard to say whether anything is wrong because your description is vague. Can you post a specific code example that demonstrates what you're talking about? It would be best if you can post a short complete compilable program that doesn't do anything else.
 
  • #6
Also, when you pass an array, you're passing the starting address of the array, ie, a reference to the first element of the array. Hence, for a vector, you can pass any valid "starting address" within the array by specifying the array element, for example

Code:
Call MySubProgram(MyVector(2))

or

Code:
MyVar = MyFunction(MyVector(2))

This passes a reference to the vector MyVector element 2 to your subprogram or function. Your subprogram or function then sees MyVector starting with element 2 as defined in the main

Also, when passesing multi-dimensioned arrays, you must also pass the physical dimension of the column length so that the subprogram can resolve the array storage layout. For example, passing a two dimensioned array such as

Code:
c      MAIN
       REAL  MyArray2(10,20)
c      variable "LDA" is "Leading dimension of Array"
       INTEGER LDA

       ...

       LDA = 10

       CALL MySubProgram(MyArray2, LDA)

       ...

       Subroutine MySubProgram(Array, L)
       INTEGER L
       REAL Array(L,1)
       ...
 

Related to How to Pass and Combine Arrays in Fortran g77?

1. What is Fortran g77?

Fortran g77 is a programming language commonly used for scientific and engineering applications. It was widely used in the 1970s and 1980s, but has since been largely replaced by newer versions of Fortran.

2. How can I get help with Fortran g77?

There are several online resources available for getting help with Fortran g77, including forums, tutorials, and documentation. You can also reach out to other Fortran users or join a programming community for additional support.

3. Is Fortran g77 still relevant and useful?

While Fortran g77 may not be as widely used as it once was, it is still a valuable language for scientific and engineering applications. Many legacy codes and programs are still written in Fortran g77, and it can also be useful for porting older code to newer versions of Fortran.

Similar threads

  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
17
Views
2K
  • Programming and Computer Science
Replies
20
Views
1K
  • Programming and Computer Science
Replies
31
Views
2K
  • Programming and Computer Science
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Programming and Computer Science
Replies
4
Views
787
  • Programming and Computer Science
Replies
5
Views
3K
  • Programming and Computer Science
Replies
5
Views
3K
  • Programming and Computer Science
Replies
5
Views
1K
Back
Top