http://imagingsolution.blog107.fc2.com/blog-entry-142.html
$ make
ifort -c -CB -traceback -fpe0 main.f90
ifort -c -CB -traceback -fpe0 bilnr.f90
ifort -o bl main.o bilnr.o
real 0m0.111s
user 0m0.071s
sys 0m0.040s
[Fri Sep 16 10:49:01 JST 2011]
[am@aofd30 processor=x86_64]
[~/teaching/bilinear]
$ ./bl
Program name: ./bl
For given xa(i),ya(i),za(i),x & y, z is estimated.
(xa(4),ya(4),za(4)) (xa(3),ya(3),za(3))
+------------------+
| |
| x |
| (x,y,z) |
| |
| |
| |
| |
| |
+------------------+
(xa(1),ya(1),za(1)) (xa(2),ya(2),za(2))
INPUT
i, xa(i),ya(i),za(i) = 1 0.0 0.0 1.0
i, xa(i),ya(i),za(i) = 2 1.0 0.0 2.0
i, xa(i),ya(i),za(i) = 3 1.0 1.0 2.0
i, xa(i),ya(i),za(i) = 4 0.0 1.0 1.0
OUTPUT
x, y, z = 0.9 0.5 1.9
./bl terminated nomally.
#
# 参考文献
# makefile の書き方
# http://www.eis.osakafu-u.ac.jp/~yabu/soft/makefile.html
#-----------------------------------------
#j マクロの定義
#-----------------------------------------
# コンパイラの指定
FC=ifort
#FC=ifc
#FC=gfortran
#FC=g95
#FC=g77
#FC=f90
#FC=f77
#FC=fort
# ターゲット名(最終的に作りたい実行ファイル名)
TARGET1=bl
# OBJ1 (ターゲットを作るのに必要なオブジェクトファイル名)
OBJ1=main.o bilnr.o #print_header.o print_ioinfo.o
#-----------------------------------------
# コンパイルオプション(ifort)
#-----------------------------------------
# デバッグ用オプション(はじめて実行するときには必ずこのオプションをつけてコンパイルする)
FDFLAGS= -CB -traceback -fpe0
# 最適化(他にも何種類かある. ifort -helpかマニュアルを見て調べる)
#FFLAGS = #-O3
# 倍精度
#FFLAGS = -r8
# 入力データのバイト・スワップ(大型計算機のバイナリデータを読む時などにつかう)
#FFLAGS = #-convert big_endian
#-----------------------------------------
# リンク用のオプション
#-----------------------------------------
LDFLAGS = #
#-----------------------------------------
# ここからコンパイルのルールの記述
#-----------------------------------------
all:$(TARGET1)
$(TARGET1): $(OBJ1)
$(FC) -o $@ $(OBJ1) ${LDFLAGS}
# 暗黙のサフィックスルールを無効にする
.SUFFIXES:
#j サフィックスの追加
.SUFFIXES: .o .f .f90
#j f77のソースファイルのコンパイル(.f用のサフィックスルール)
.f.o:
$(FC) -c ${FDFLAGS} ${FFLAGS} $<
#j f90のソースファイルのコンパイル(.f90用のサフィックスルール)
.f90.o:
$(FC) -c ${FDFLAGS} ${FFLAGS} $<
#j オブジェクトファイルを削除
clean:
rm *.o
#j オブジェクトファイルと実行ファイルを削除
distclean:
rm -f *.o $(TARGET1)
program
dimension xa(4), ya(4), za(4)
! Subscript, a indicates the input.
! For handling I/O files
character progname*70
character infle*70,ofle*70,ofle2*70
character strm*200
!
! !REVISION HISTORY:
! [Thu Aug 20 14:17:59 JST 2009] A. Manda (am)
!
! I/O file handling
!
NUMARGS=2 ! Expected number of arguments
call getarg( 0, progname) ! Get program name
idxpn=index(progname,' ')-1
write(*,'(A,A)')'Program name: ',progname(1:idxpn)
write(*,*)' For given xa(i),ya(i),za(i),x & y, z is estimated.'
write(*,*)
write(*,*)' (xa(4),ya(4),za(4)) (xa(3),ya(3),za(3))'
write(*,*)' +------------------+'
write(*,*)' | |'
write(*,*)' | x |'
write(*,*)' | (x,y,z) |'
write(*,*)' | |'
write(*,*)' | |'
write(*,*)' | |'
write(*,*)' | |'
write(*,*)' | |'
write(*,*)' +------------------+'
write(*,*)' (xa(1),ya(1),za(1)) (xa(2),ya(2),za(2))'
write(*,*)
xa(1)=0
ya(1)=0
za(1)=1.
xa(2)=1
ya(2)=0
za(2)=2.
xa(3)=1
ya(3)=1
za(3)=2.
xa(4)=0
ya(4)=1
za(4)=1.
write(*,*)'INPUT'
do i=1,4
write(*,'(a,i4,1x,3f7.1)')'i, xa(i),ya(i),za(i) = ',i,xa(i),ya(i),za(i)
enddo
x=0.9
y=0.5
call bilnr(xa,ya, za, x, y, z)
write(*,*)'OUTPUT'
write(*,'(a,3f7.1)')'x, y, z = ',x,y,z
write(*,*)
write(*,'(A,A)')progname(1:idxpn), ' terminated nomally.'
write(*,*)
stop
! Error handling
8000 write(*,'(A)')'Error(8000): Wrong number of arguments.'
write(*,'(A,i10)')'Expected number of arguments = ',NUMARGS
write(*,'(A,A)')progname(1:idxpn), ' terminated.'
write(*,*)
stop
8010 write(*,'(A)')'Error(8010): No input file.'
write(*,'(A,A)')'file name = ',infle(1:idxin)
write(*,'(A,A)')progname(1:idxpn), ' terminated.'
write(*,*)
stop
end program
!***********************************************************************
! bilnr.f90
! TASK
! 2D-bilinear interpolation
! Reference
! http://www.library.cornell.edu/nr/bookfpdf/f3-6.pdf
!***********************************************************************
subroutine bilnr(xa,ya, za, x, y, z)
!----------------- PARAMETERS AND COMMON VARIABLES ---------------------
! implicit double precision(a-h,o-z)
!--------------------------- ARGUMENTS ---------------------------------
real, intent(in) :: xa(4), ya(4), za(4)
real, intent(in) :: x,y
real, intent(out) :: z
!------------------------- LOCAL VARIABLES -----------------------------
real t, u
!-----------------------------------------------------------------------
! Subscript, a indicates the input.
!
!
! For given xa(i),ya(i),za(i),x & y, z is estimated.
!
! (xa(4),ya(4),za(4)) (xa(3),ya(3),za(3))
! +------------------+
! | |
! | x |
! | (x,y,z) |
! | |
! | |
! | |
! | |
! | |
! +------------------+
! (xa(1),ya(1),za(1)) (xa(2),ya(2),za(2))
!
t=(x-xa(1))/(xa(2)-xa(1))
u=(y-ya(1))/(ya(4)-ya(1))
z = (1.-t)*(1.-u)*za(1) &
& + t*(1.-u)*za(2) &
& + t*u*za(3) &
& + (1.-t)*u*za(4)
return
end subroutine
https://sites.google.com/site/fcfortran/home/recipe/bilinear