FloatingFeather
Programmer
Hi there. I have written a code, as a series of subroutines. The code works properly, it does the job. However, I've written it for the first time in FORTRAN77 (don't ask why, I wish I wouldn't). And then I passed it to Fortran90, because I needed dynamic arrays to work with MPI.
However, I have some array, which has a certain shape, and doesn't start in 1.
Let's say my array is f(sx:ex). And in a certain subroutine, I call another subroutine like this (I do this for different arrays f's, with different shapes):
call mysub(f, and some other parameters I need)
Then comes the subroutine, and this is why I am writing this post. This subroutine looks much like my first F77 code, and I have:
subroutine mysub(g, other parameters)
integer mxpts
parameter (mxpts=1024)
real*8 g(mxpts)
Then I work with the array g. And when it finishes it continues in the previous subroutine, but now what the code has done is, it has put the result for g, which wasn't defined with the shape of f, in the array f(sx:ex).
When I did this for the first time, I didn't realize. The code worked, and stills works, and everything is fine like this. However, I would like to understand what the compiler is doing, if I had thought a little bit more on what I was doing, I would have thought that the approach was wrong, because I have different arrays, with different shapes, even f is allocated (while g is set as an static array), and I call this subroutine for different allocated arrays, with different shapes, but it would look like if the code would take anything I put for g, copy it to the first element of g, operate on g, and return again whatever array I put with the result operated on g, but giving the correct shape for the array I have used as an argument in the subroutine call.
Can somebody tell me how is that this actually works?
Thanks in advance.
However, I have some array, which has a certain shape, and doesn't start in 1.
Let's say my array is f(sx:ex). And in a certain subroutine, I call another subroutine like this (I do this for different arrays f's, with different shapes):
call mysub(f, and some other parameters I need)
Then comes the subroutine, and this is why I am writing this post. This subroutine looks much like my first F77 code, and I have:
subroutine mysub(g, other parameters)
integer mxpts
parameter (mxpts=1024)
real*8 g(mxpts)
Then I work with the array g. And when it finishes it continues in the previous subroutine, but now what the code has done is, it has put the result for g, which wasn't defined with the shape of f, in the array f(sx:ex).
When I did this for the first time, I didn't realize. The code worked, and stills works, and everything is fine like this. However, I would like to understand what the compiler is doing, if I had thought a little bit more on what I was doing, I would have thought that the approach was wrong, because I have different arrays, with different shapes, even f is allocated (while g is set as an static array), and I call this subroutine for different allocated arrays, with different shapes, but it would look like if the code would take anything I put for g, copy it to the first element of g, operate on g, and return again whatever array I put with the result operated on g, but giving the correct shape for the array I have used as an argument in the subroutine call.
Can somebody tell me how is that this actually works?
Thanks in advance.