Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a few basic questions about 2D arrays, e.g.:

double bn[NNODES][NBASIS]

1-How is the declaration in C? And in Fortran?

2-The first [] is for the rows number and the second for columns, both for C and 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- How is the write/print function (both for C and Fortran) only for one (e.g. i=15) and entire row?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
342 views
Welcome To Ask or Share your Answers For Others

1 Answer

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];

and in Fortran, using the iso_c_binding intrinsic module:

real (C_DOUBLE), dimension (10,20) :: array

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...