포트란, 배열, Format문(Arrays, Formatted I/O)
Автор: Fortran Tutorial
Загружено: 16 дек. 2021 г.
Просмотров: 176 просмотров
#포트란배열 #포트란문법 #결과값원하는대로출력하기
0:00 소개
0:25 array, array2, array3
1:40 unit matrix, unit matrix2
2:15 dont know the size
2:36 array magic, array magic2, multi dimension array
4:03 formatting your output
5:27 정수형, 실수형, 문자형, 지수형 출력형태
6:08 impled do loop to write array
6:35 summary
*VREW 사용하다보니 음성이 부자연스러운 부분이 있습니다.
이것을 감안하시고 들으시면 좋겠습니다.
보다 많은 Fortran 자료를 찾으신다면 다음카페(https://cafe.daum.net/VFUN)를활용하세요.
FTN95에 사용한 포트란 코드들 공개합니다.
program av
implicit none
real :: x1, x2, x3,x4,x5,x6,x7,x8,x9,x10, average
read *, x1, x2, x3,x4,x5,x6,x7,x8,x9,x10
average=(x1+x2+ x3+x4+x5+x6+x7+x8+x9+x10)/10
print *, 'the average is', average
print *, x1
print *, x2
print *, x3
print *, x4
print *, x5
print *, x6
print *, x7
print *, x8
print *, x9
print *, x10
end program av
data.txt
24
45
67
89
12
99
33
68
37
11
program av2
implicit none
real, dimension(10) :: x
real :: average, sum
integer :: i
print *, 'enter 10 numbers'
sum=0.0
do i=1,10
read *,x(i)
sum=sum+x(i)
end do
average=sum/10
print *, 'the average is', average
print *, 'the numbers are'
print *, x
end program av2
program av3
!just change the value of the parameter to change the size of the !array
implicit none
integer, parameter :: imax = 10
real,dimension(imax) :: x
real :: average,sum
integer :: i
print *, 'enter ',imax, ' numbers'
sum=0.0
do i=1,imax
read *, x(i)
sum=sum+x(i)
end do
average=sum/imax
print *, 'the average is ',average
print *, 'the numbers are'
print *,x
end program av3
program identity
implicit none
integer, dimension(4,4) :: ra
integer :: i
ra=0
do i=1,4
ra(i,i)=1
end do
print *, ra
end program identity
program identity1
implicit none
integer, dimension(4,4) :: ra
integer :: i, row, col
ra=0
do i=1,4
ra(i,i)=1
end do
do row=1,4
write(*,10)(ra(row, col),col=1,4)
end do
10 format(4i3)
!print *, ra
end program identity1
program format
implicit none
!demonstrates use of the format statement
integer, parameter :: ikind=selected_real_kind(p=15)
real , dimension(4) :: x
integer, dimension(4) :: nums
integer :: i
real(kind=ikind),dimension(4) :: computed
!fill up the arrays with something
do i = 1,4
nums(i) = i * 10
computed(i) = cos(0.1*i)
x(i) = computed(i)
end do
print *,'nums - integer'
write(*,1) nums
1 format(2i10)
print *, 'x - real'
write(*,2) x
2 format(f6.2)
print *, 'computed - double precision'
write(*,3) computed
3 format(f20.7)
end program format
program ramagic
implicit none
real , dimension(10) :: a,b,c,d
open(10,file='data.txt')
read(10,*) a
b=a*10
c=b-a
d=1
print *,'a= ',a
print *,'b= ',b
print *,'c= ',c
print *,'d= ',d
end program ramagic
program ramagic2
implicit none
real , dimension(10) :: x,y,z
integer :: i
do i=1,10
x(i)=i/10.0
end do
print *,'cos(x) = ',cos(x)
print *,'sin(x) = ',sin(x)
end program ramagic2
program alloc
implicit none
integer, allocatable,dimension(:):: vector !note syntax - dimension(:)
integer :: elements,i
print *,'enter the number of elements in the vector'
read *,elements
allocate(vector(elements)) !allocates the correct amount of memory
print *,' your vector is of size ',elements,'. Now enter each element'
do i=1,elements
read *,vector(i)
end do
print *,'This is your vector'
do i=1,elements
print *,vector(i)
end do
deallocate(vector) !tidies up the memory
end program alloc
program twodra
implicit none
integer,dimension(2,3) :: a
integer ::row,col,count
count = 0
!creates an array with 3 cols and 2 rows
!sets col 1 to 1, col2 to 2 and so on
do row=1,2
count=0
do col =1,3
count=count+1
a(row,col)=count
end do
end do
do row=1,2
do col =1,3
print *,a(row,col)
end do
end do
end program twodra
program neatoutput
real :: x
integer :: i
x = 0.0;
write(*,*) " x exp(x) exp(x)"
write(*,*) " f format e format"
write(*,*) " -------------------------------"
do i = 1,10
write(*,10) x,exp(x),exp(x)
x = x + 0.1
end do
10 format( 2 F10.2,E18.5)
end program neatoutput
Integer :: col, row
Real :: ra(10,10)
!using do loop
Do row =1,10
do col =1,10
read *, ra(row, col)
write(*,*) ra(row, col)
end do
End do
Integer :: row, col
Real :: ra(10,10)
!using implied loop
Do row =1,10
do col =1,10
read *, ra(row, col)
end do
End do
Do row=1,10
write(*,10) (ra(row, col), col=1,10)
End do
10 format(10f5.1)

Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: