This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| language:fortran [2018/06/11 09:19] – [Command line으로 Arguments를 받고 저장, 출력] ledyx | language:fortran [2021/02/07 03:15] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| {{tag> | {{tag> | ||
| + | |||
| + | = gFortran에서 행 길이 제한 무시 = | ||
| + | |||
| + | <sxh bash> | ||
| + | gfortran -ffree-line-length-none xxx.f90 | ||
| + | # -ffree-line-length-0 | ||
| + | </ | ||
| + | |||
| Line 39: | Line 47: | ||
| </ | </ | ||
| + | = String, Integer 상호 변환 = | ||
| + | |||
| + | * https:// | ||
| + | |||
| + | <code fortran> | ||
| + | program read_val | ||
| + | integer value | ||
| + | character(len=10) string, string2 | ||
| + | string = ' | ||
| + | | ||
| + | ! Convert a string to a numeric value | ||
| + | read (string,' | ||
| + | print *, value | ||
| + | | ||
| + | ! Convert a value to a formatted string | ||
| + | write (string2,' | ||
| + | print *, string2 | ||
| + | end program read_val | ||
| + | </ | ||
| + | |||
| + | |||
| + | == Command Line 응용 == | ||
| + | |||
| + | <code fortran> | ||
| + | PROGRAM test_getarg | ||
| + | INTEGER :: i | ||
| + | CHARACTER(len=8) :: arg | ||
| + | INTEGER, DIMENSION (:), ALLOCATABLE :: args | ||
| + | |||
| + | allocate(args(iargc())) | ||
| + | |||
| + | DO i = 1, iargc() | ||
| + | CALL getarg(i, arg) | ||
| + | read(arg,' | ||
| + | END DO | ||
| + | |||
| + | |||
| + | DO i = 1, SIZE(args) | ||
| + | print *, args(i) | ||
| + | end do | ||
| + | |||
| + | deallocate(args) | ||
| + | |||
| + | END PROGRAM | ||
| + | </ | ||
| + | |||
| + | = 문자열 동적 할당 = | ||
| + | <code fortran> | ||
| + | PROGRAM test | ||
| + | | ||
| + | | ||
| + | |||
| + | | ||
| + | |||
| + | CALL getarg(1, arg) | ||
| + | path = TRIM(arg) | ||
| + | |||
| + | DO i=1, 3 | ||
| + | CALL getarg(i+1, arg) | ||
| + | READ(arg,' | ||
| + | END DO | ||
| + | |||
| + | print *,LEN(path) | ||
| + | print *," | ||
| + | |||
| + | END PROGRAM | ||
| + | </ | ||