アプリ版:「スタンプのみでお礼する」機能のリリースについて

乱数を配列に格納してcosθをベクトルから求めるプログラムを書いてみたのですが、コンパイルしてみるとrandom_numberのところの設定がおかしいみたいでうまくコンパイルできません。どこに問題があるのかわからないので困っています。教えて下さい。よろしくお願いします。
module subprogs
implicit none
contains
function vec_cos(a,b) result(vcos)
real(8), intent(in) :: a(:), b(:)
real(8) ab, vcos
if (size(a) /= size(b)) stop ' sr : size(a) /= size(b) '
ab = dot_product(a,a) * dot_product(b,b)
if (ab == 0.0d0) then
vcos = 0.0d0
else
vcos = dot_product(a,b)/sqrt(ab)
endif
end function vec_cos
end module subprogs

program main
use subprogs
implicit none
real(8), allocatable :: x(:), y(:)
integer n
write(*,'(a)', advance = 'no') ' input n : '
read(*,*) n
if ( n < 1 .or. n > 100 )stop ' n must be 0 < n < 101 '
allocate(x(n),y(n))
call random_seed
call random_number(x,y)
write(*,*) 'cos = ', vec_cos(x,y)
end program main

コンパイル結果
Undefined symbols:
"_random_number__", referenced from:
_MAIN_ in ccxYbc0C.o
ld: symbol(s) not found

A 回答 (1件)

「Undefined」といっているんだから, そんな名前の手続が見付からなかったということですよ.


あなたが使っている処理系に「random_number」という手続は存在するのですか?
あるなら, 標準ではリンクされないどこかのライブラリにあるはずなので, 処理系のマニュアルをひっくりかえして探してください.
ないのであれば, 自分で作ってください.
    • good
    • 0
この回答へのお礼

確かにそうですね。いろいろ試した結果、私の処理系にrandom_numberという手続きはありました。ただ、プログラム上のrandom_numberのxとyの設定が誤っていたようです。ちゃんと再度設定し直したら、うまくコンパイルできて実行結果も正しく表示されました。ありがとうございました。

お礼日時:2009/10/22 10:38

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!