プログラムを実行するコンピューターにとっては、 メモリー内にデータがどう並んでいるかだけが問題であるので、 Fortran 言語で書かれたプログラム (をコンパイルして作られたオブジェクト・コード) が 「期待している」順にメモリー上にデータが並ぶように、 C プログラムの側で用意してやればよい。
| cmain.c |
/* cmain.c */
#include <stdio.h>
#define M 3
#define N 3
void print_(int *row, int *col, double *A);
int main()
{
int i,j,k,m,n;
double a[M][N], A[M*N];
for (i = 0; i < M; i++)
for (j = 0; j < N; j++)
a[i][j] = 10 * (i + 1) + (j + 1);
k = 0;
for (j = 0; j < N; j++)
for (i = 0; i < M; i++)
A[k++] = a[i][j];
m = M; n = N;
print_(&m, &n, A);
return 0;
}
|
| fortransub.f |
* fortransub.f
subroutine print(m,n,a)
integer m,n
real*8 a(m,n)
integer i,j
do i=1,m
write(*,*) (a(i,j),j=1,n)
end do
end
|
| コンパイル&リンク&実行 |
oyabun% make candf gcc -W -Wall -O -I/usr/local/include -c cmain.c g77 -O -c fortransub.f g77 -O -o candf cmain.o fortransub.o oyabun% ./candf 11. 12. 13. 21. 22. 23. 31. 32. 33. oyabun% |
桂田 祐史