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

Categories

0 votes
360 views
in Technique[技术] by (71.8m points)

C/Fortran 2D arrays (basic)

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

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

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...