Fortran How to Pass and Combine Arrays in Fortran g77?

  • Thread starter Thread starter mazinse
  • Start date Start date
  • Tags Tags
    Fortran
AI Thread Summary
The discussion addresses several key points regarding array manipulation in Fortran. First, to determine the index of non-zero cells in an array, a do-loop can be used to iterate through each cell and count non-zero values. For passing an entire array to a function, the correct syntax is 'call function(array)', which passes the address of the array rather than its contents. It is noted that standard Fortran 77 lacks intrinsic functions for array operations like merging or copying, although some newer compilers like g77 may offer additional functionalities. Concerns about seeing many zeros when writing an array to a file suggest that if non-zero values were stored, the zeros might indicate uninitialized or empty cells. To clarify issues, providing a specific code example is recommended. Additionally, when passing multi-dimensional arrays, the leading dimension must be specified to ensure proper array storage layout in the subroutine.
mazinse
Messages
188
Reaction score
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
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?
 
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
 
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.
 
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.
 
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)
       ...
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
5
Views
3K
Replies
22
Views
4K
Replies
5
Views
8K
Replies
13
Views
3K
Replies
5
Views
4K
Replies
13
Views
2K
Replies
31
Views
3K
Back
Top