2024-06-21

This commit is contained in:
2024-06-21 16:45:09 +09:00
parent 5960e7ca43
commit 7633aa300d
21 changed files with 260 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
# 배열
포트란에서 배열의 첫 번째 인덱스는 1부터 시작됩니다.
## 배열의 선언
배열을 선언하는 방법은 2가지가 있습니다.
```fortran
! dimension 키워드를 이용하는 방식
integer, dimension(10) :: array1
! 변수명 뒤에 배열의 크기를 전달하는 방식
integer :: array2(10)
```
### 다차원 배열
```fortran
real, dimension(10, 10) :: array3
```
### 배열의 인덱스를 명시
```fortran
integer :: array4(0:9)
integer :: array5(-5:5)
```

View File

@@ -0,0 +1,14 @@
# Hello, World
```fortran
program hello
implicit none
! This is a Hello world program.
print *, 'Hello, World!'
end program hello
```
## 특이사항
- 대소문자를 구분하지 않습니다.
- 배열의 첫 번째 인덱스는 1부터 시작됩니다.

28
Writerside/topics/IO.md Normal file
View File

@@ -0,0 +1,28 @@
# 표준 입출력
```fortran
program stdio
implicit none
character(len=16) :: name
read (*,*) name
print *, 'Hello, ', name
end program stdio
```
## 표준 출력
화면에 출력할 때에는 `print`를 사용합니다.
```fortran
print *, 'Hello, ', name
```
## 표준 입력
키보드로부터 입력을 받을 때에는 `read`를 사용합니다.
```fortran
read (*,*) name
```

View File

@@ -0,0 +1,9 @@
# 연산자
| 연산자 | | |
| --- | --- | --- |
| + | | |
| - | | |
| * | | |
| / | | |
| ** | | |

View File

@@ -0,0 +1,3 @@
# String
Start typing here...

View File

@@ -0,0 +1,80 @@
# 변수
## 자료형
포트란에는 5 종류의 기본 자료형이 있습니다.
- integer
- real
- complex
- character
- logical
### 정수형
### 실수형
```fortran
program variables
implicit none
real :: value1
end program variables
```
아래와 같은 방식으로 원하는 부동 소수의 정밀도를 지정해서 사용할 수 있습니다.
```fortran
program variables
use, intrinsic :: iso_fortran_env, only: sp=>real32, dp=>real64
! use, intrinsic :: iso_c_binding, only: sp=>c_float, dp=>c_double
implicit none
real :: val0
real(sp) :: val1 ! 단정도
real(dp) :: val2 ! 배정도
val0 = 0.
val1 = 0._sp
val2 = 0._dp
print *, 'Max = ', huge(val0)
print *, 'Max32 = ', huge(val1)
print *, 'Max64 = ', huge(val2)
end program variables
```
### 복소수형
복소수는 실수부와 허수부를 콤마로 구분하고 괄호로 묶어 표현합니다.
### 문자형
문자는 홑 따옴표 또는 쌍 따옴표로 묶어서 표현합니다.
### 논리형
`.true.` 또는 `.false.`값을 가질 수 있습니다.
## 변수 선언
변수는 `자료형 :: 변수명` 형식을 사용해서 정의합니다. 포트란은 대소문자를 구분하지 않으며, 이 규칙은 변수명에도 적용됩니다. 변수명의 길이는 최대 31자까지만 지정할 수 있습니다.
```fortran
program variables
implicit none
integer :: count
logical :: isOk
end program variables
```
### implicit none
기본적으로 포트란에서는, 선언되지 않은 변수를 사용하면 변수명의 첫 번째 문자에 따라 자동으로 변수를 선언합니다. `implicit none`을 선언하면 무조건 변수해야 하도록 지정합니다.

View File

@@ -0,0 +1,19 @@
# Fortran
## 설치
```bash
sudo apt install gfortran
```
## 버전 확인
```bash
gfortran --version
```
## 컴파일
```bash
gfortran hello.f90 -o hello
```