Both sides previous revisionPrevious revisionNext revision | Previous revision |
language:fortran [2018/06/11 10:19] – [Command line으로 Arguments를 받고 저장, 출력] ledyx | language:fortran [2021/02/07 03:15] (current) – external edit 127.0.0.1 |
---|
| |
{{tag>Language Fortran}} | {{tag>Language Fortran}} |
| |
| = gFortran에서 행 길이 제한 무시 = |
| |
| <sxh bash> |
| gfortran -ffree-line-length-none xxx.f90 |
| # -ffree-line-length-0 |
| </sxh> |
| |
| |
| |
</code> | </code> |
| |
| = String, Integer 상호 변환 = |
| |
| * https://gcc.gnu.org/onlinedocs/gfortran/ICHAR.html |
| |
| <code fortran> |
| program read_val |
| integer value |
| character(len=10) string, string2 |
| string = '154' |
| |
| ! Convert a string to a numeric value |
| read (string,'(I10)') value |
| print *, value |
| |
| ! Convert a value to a formatted string |
| write (string2,'(I10)') value |
| print *, string2 |
| end program read_val |
| </code> |
| |
| |
| == 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,'(I10)') args(i) |
| END DO |
| |
| !print |
| DO i = 1, SIZE(args) |
| print *, args(i) |
| end do |
| |
| deallocate(args) |
| |
| END PROGRAM |
| </code> |
| |
| = 문자열 동적 할당 = |
| <code fortran> |
| PROGRAM test |
| CHARACTER(len=128) :: arg |
| CHARACTER(len=:), ALLOCATABLE :: path |
| |
| INTEGER date(3) |
| |
| CALL getarg(1, arg) |
| path = TRIM(arg) |
| |
| DO i=1, 3 |
| CALL getarg(i+1, arg) |
| READ(arg,'(I10)') date(i) |
| END DO |
| |
| print *,LEN(path) |
| print *,"path : ",path," /// ",date(1),date(2),date(3) |
| |
| END PROGRAM |
| </code> |