Keyword: ランダム2元配置表
概要
本サンプルはランダム2元配置表の生成を行うFortranによるサンプルプログラムです。 本サンプルは行の合計が9、11、7、23、列の合計が16、17、17となる 4x3 のランダム2元配置表を生成し出力します。
※本サンプルはnAG Fortranライブラリに含まれるルーチン g05pzf() のExampleコードです。本サンプル及びルーチンの詳細情報は g05pzf のマニュアルページをご参照ください。
ご相談やお問い合わせはこちらまで
入力データ
(本ルーチンの詳細はg05pzf のマニュアルページを参照)| このデータをダウンロード |
G05PZF Example Program Data 1 1 1762543 :: GENID,SUBID,SEED(1) 4 3 :: NROW,NCOL 9 11 7 23 :: TOTR 16 17 17 :: TOTC
- 1行目はタイトル行で読み飛ばされます。
- 2行目に使用する生成器(genid=1:nAG基本生成器)、生成器に関する情報(subid=1:GENIDが1の場合この値は参照されません)、生成器の初期値(seed=1762543)を指定しています。
- 3行目に表の行数(nrow=4)と列数(ncol=3)を指定しています。
- 4行目に行の合計(totr)を指定しています。
- 5行目に列の合計(totc)を指定しています。
出力結果
(本ルーチンの詳細はg05pzf のマニュアルページを参照)| この出力例をダウンロード |
G05PZF Example Program Results
Random Table
1 2 3
1 2 4 3
2 6 1 4
3 2 4 1
4 6 8 9
Supplied row totals = 9 11 7 23
Supplied column totals = 16 17 17
- 4〜8行目に生成されたランダム2元配置表が出力されています。
- 10行目に与えられた行の合計が出力されています。
- 11行目に与えられた列の合計が出力されています。
ソースコード
(本ルーチンの詳細はg05pzf のマニュアルページを参照)
※本サンプルソースコードは科学技術・統計計算ライブラリである「nAG Fortranライブラリ」のルーチンを呼び出します。
サンプルのコンパイル及び実行方法
| このソースコードをダウンロード |
PROGRAM g05pzfe
! G05PZF Example Program Text
! Mark 23 Release. nAG Copyright 2011.
! .. Use Statements ..
USE nag_library, ONLY : g05kff, g05pzf, nag_wp, x04eaf
! .. Implicit None Statement ..
IMPLICIT NONE
! .. Parameters ..
INTEGER, PARAMETER :: lseed = 1, nin = 5, nout = 6
! .. Local Scalars ..
INTEGER :: genid, ifail, ldx, lr, lstate, mode, &
ncol, nrow, subid
! .. Local Arrays ..
REAL (KIND=nag_wp), ALLOCATABLE :: r(:)
INTEGER :: seed(lseed)
INTEGER, ALLOCATABLE :: state(:), totc(:), totr(:), x(:,:)
! .. Intrinsic Functions ..
INTRINSIC sum
! .. Executable Statements ..
WRITE (nout,*) 'G05PZF Example Program Results'
WRITE (nout,*)
FLUSH (nout)
! Skip heading in data file
READ (nin,*)
! Read in the base generator information and seed
READ (nin,*) genid, subid, seed(1)
! Initial call to initialiser to get size of STATE array
lstate = 0
ALLOCATE (state(lstate))
ifail = 0
CALL g05kff(genid,subid,seed,lseed,state,lstate,ifail)
! Reallocate STATE
DEALLOCATE (state)
ALLOCATE (state(lstate))
! Initialize the generator to a repeatable sequence
ifail = 0
CALL g05kff(genid,subid,seed,lseed,state,lstate,ifail)
! Read in the problem size
READ (nin,*) nrow, ncol
ldx = nrow
ALLOCATE (totr(nrow),totc(ncol),x(ldx,ncol))
! Read in row and column totals
READ (nin,*) totr(1:nrow)
READ (nin,*) totc(1:ncol)
lr = sum(totr(1:nrow)) + 5
ALLOCATE (r(lr))
! Using a single call to G05PZF, so set up reference vector
! and generate values in one go
mode = 2
! Generate the random table
ifail = 0
CALL g05pzf(mode,nrow,ncol,totr,totc,r,lr,state,x,ldx,ifail)
! Display the results
ifail = 0
CALL x04eaf('General',' ',nrow,ncol,x,ldx,'Random Table',ifail)
WRITE (nout,*)
WRITE (nout,*) 'Supplied row totals = ', totr(1:nrow)
WRITE (nout,*) 'Supplied column totals = ', totc(1:ncol)
END PROGRAM g05pzfe
