Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...