문자열의 내용을 숫자 유형 (int, real, 배정도, real (real128))으로 변환하는 서브 루틴을 갖고 싶습니다.Fortran에서 숫자로 문자열 변환
그러나 Class(*)
을 사용하려고하면 오류가 발생합니다. 오류 는 다음과 같습니다 :
gfortran -o build/lib/larsa.o -c -ffree-form -g -J./build/lib lib/larsa.f
lib/larsa.f:1933.35:
Read (s, frmt, iostat=ios) num
1
Error: Data transfer element at (1) cannot be polymorphic unless
it is processed by a defined input/output procedure
lib/larsa.f:1935.32:
Read (s, *, iostat=ios) num
1
Error: Data transfer element at (1) cannot be polymorphic unless
it is processed by a defined input/output procedure
이것은 내가 작성한 서브 루틴이다.
Subroutine converts_str_to_num &
( &
s, num, &
fmt, wrn &
)
Character (len=*), Intent (in) :: s
Character (len=*), Intent (in), Optional :: fmt
Class (*) :: num
Character (len=*), Intent (inout), Optional :: wrn
Integer :: ios
Character (len=65) :: frmt
!!$ Reads contents of s and puts value in i.
If (Present (fmt)) Then
frmt = "(" // Trim (fmt) // ")"
Read (s, frmt, iostat=ios) num
Else
Read (s, *, iostat=ios) num
End If
End Subroutine converts_str_to_num
무엇이 당신의 질문입니까? 오류 메시지는 분명합니다 : 정의 된 I/O를 사용하지 않는 한 I/O 목록에서 다형 변수를 사용할 수 없습니다. 그게 무슨 뜻 이니? – francescalus
해결 방법이 있고 거기에'Class (*)'가 있습니까? – Zeus
@ChristopherDimech 그렇습니다. 'select type' 구조체를 사용하고 처리하고자하는 모든 유형의 사례를 작성하십시오. – casey