问题描述
我对2D阵列有一些基本问题,例如:
I have a few basic questions about 2D arrays, e.g.:
double bn[NNODES][NBASIS]
1-如何在C中声明?在Fortran中?
1-How is the declaration in C? And in Fortran?
2-对于C和Fortran,第一个[]用于行号,第二个用于列?
2-The first [] is for the rows number and the second for columns, both for C and Fortran?
3-使用bn时,例如bn [i] [j], i索引用于行, j索引用于行?在C和Fortran中都是这样?
3- When using bn, e.g. bn[i][j], the "i" index is for rows and "j" is for columns? Both in C and Fortran?
4-如何仅对一个(例如i = 15)和整行写入/打印功能(对于C和Fortran)?
4- How is the write/print function (both for C and Fortran) only for one (e.g. i=15) and entire row?
谢谢
推荐答案
其中一些示例用于方阵掩盖了一个问题。 C和Fortran对多维数组使用不同的内存布局。 C是行主要的,而Fortran是列主要的。请参阅。在两种语言之间进行操作时,可以在声明中方便地进行处理,例如在C:
Some of the examples are for a square matrix which obscures one issue. C and Fortran uses different memory layouts for multi-dimensions arrays. C is row-major, while Fortran is column major. See http://en.wikipedia.org/wiki/Row-major_order. When working between the languages, it can be convenient to deal with this in the declarations, e.g., in C:
double array [20][10];
并在Fortran中,使用 iso_c_binding
内在函数模块:
and in Fortran, using the iso_c_binding
intrinsic module:
real (C_DOUBLE), dimension (10,20) :: array
这篇关于C / Fortran 2D数组(基本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!