Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing c arrays into fortran as a variable sized matrix
    primarykey
    data
    text
    <p>So, i've been commissioned to translate some fortran subroutines into C. These subroutines are being called as part of the control flow of a large porgram based primarily in C.</p> <p>I am translating the functions one at a time, starting with the functions that are found at the top of call stacks.</p> <p>The problem I am facing is the hand-off of array data from C to fortran.</p> <p>Suppose we have declared an array in c as </p> <pre><code>int* someCArray = (int*)malloc( 50 * 4 * sizeof(int) ); </code></pre> <p>Now, this array needs to be passed down into a fortran subroutine to be filled with data</p> <pre><code>someFortranFunc( someCArray, someOtherParams ); </code></pre> <p>when the array arrives in fortran land, it is declared as a variable sized matrix as such:</p> <pre><code>subroutine somefortranfunc(somecarray,someotherparams) integer somefarray(50,*) </code></pre> <p>The problem is that fortran doesn't seem to size the array correctly, becuase the program seg-faults. When I debug the program, I find that indexing to</p> <pre><code>somefarray(1,2) </code></pre> <p>reports that this is an invalid index. Any references to any items in the first column work fine, but there is only one available column in the array when it arrives in fortran.</p> <p>I can't really change the fact that this is a variable sized array in fortran. Can anyone explain what is happening here, and is there a way that I can mitigate the problem from the C side of things?</p> <p>[edit]</p> <p>By the way, the fortran subroutine is being called from the replaced fortran code as</p> <pre><code>integer somedatastorage(plentybignumber) integer someindex ... call somefarray(somedatastorage(someindex)) </code></pre> <p>where the data storage is a large 1d array. There isn't a problem with overrunning the size of the data storage. Somehow, though, the difference between passing the C array and the fortran (sub)array is causing a difference in the fortran subroutine.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload