Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
language:fortran [2018/06/11 10:19] – [Command line으로 Arguments를 받고 저장, 출력] ledyxlanguage:fortran [2021/02/07 03:15] (current) – external edit 127.0.0.1
Line 2: Line 2:
  
 {{tag>Language Fortran}} {{tag>Language Fortran}}
 +
 += gFortran에서 행 길이 제한 무시 =
 +
 +<sxh bash>
 +gfortran -ffree-line-length-none xxx.f90
 +# -ffree-line-length-0
 +</sxh>
 +
  
  
Line 39: Line 47:
 </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>
language/fortran.1528708741.txt.gz · Last modified: 2021/02/07 03:15 (external edit)