할당 가능 배열에 문제가 있습니다.FORTRAN에 할당 가능 배열이 필요합니다
파일의 모든 정보를 할당 가능한 배열에 복사해야합니다. 파일은 다음과 같다 :
3
3 5
2 1
4 0
3 다른 여섯 개 번호 (X, Y)의 형태로 그래프상의 점을 나타내고 점의 수이다. 그래서 (3,5), (2, 1), (4,0)이 포인트입니다. 하지만이 번호를 쌍으로 만드는 데 문제가 있습니다. 내가 오류가 ...
PROGRAM practice
IMPLICIT NONE
INTEGER :: astat, ioStatus
INTEGER :: x, y
INTEGER :: num, code1, code2, code3, code4, code5, code6
! num shows number of location. in this case 3
! code 1 to 6 shows x and y variable. and code1 and 2 have to be paired.
! as well as this, code 3 and 4, code 5 and 6 have to be paired
! Declare TYPE
! set 1 to 3 show pair of (x, y)
TYPE Location
INTEGER :: set1, set2, set3
INTEGER :: num_locations
END TYPE
! Array()
! for number of locations to visit
TYPE(Location), DIMENSION(:) :: numLocationArray(1000)
! allocatable array
! For locations
TYPE(Location), DIMENSION(:, :) :: LocationArray
ALLOCATABLE :: LocationArray
! allocate LocationArray
ALLOCATE(LocationArray(x, y), STAT = astat)
IF (astat < 0) STOP "allocate failed"
! open input file to copy info into array
OPEN (UNIT = 10, File ="input.txt", STATUS = "OLD", ACTION = "READ", &
IOSTAT = ioStatus)
IF (ioStatus < 0) STOP "open failed"
! format of the file
100 FORMAT (I1, /, 2I2, /, 2I2,/2I2)
! Do loop to set table
DO x = 0, size(LocationArray), 1
READ (UNIT = 10, FMT = 100, IOSTAT = ioStatus) num, code1, code2, &
code3, code4, code5, code6
! check whether program read file correctly (option)
PRINT *, num, code1, code2, code3, code4, code5, code6
IF (x == code1) THEN
DO y = 0, size(LocationArray), 1
IF (y == code2) THEN
LocationArray%set1 = LocationArray(x, y)
! check whether copied correctly
PRINT *, LocationArray(x, y)
PRINT *, LocationArray%set1
END IF
END DO
END IF
END DO
! ==============
! execution part
! ==============
! instructions:
! use pointer to do excecution
! read allocatable array above
! do excecution (distance) ** do not forget to go back to the original place (0,0)
! ** do not forget to try every single possible way
! when get total distance, do distance times 2 and figure out cost
! print all info (cost, distance, and steps)
! (example of output)
! The minimum cost is 36
! The distance travelled is 18
! Step 1: Start at ( 0, 0)
! Step 2: Goes to ( 2, 1)
! Step 3: Goes to ( 3, 5)
! Step 4: Goes to ( 4, 0)
! Step 5: Ends at ( 0, 0)
END PROGRAM
이 프로그램은 작동하지 않습니다 :
내가 코드를 시도하고, 여기 내 코드입니다
LocationArray%set1 = LocationArray(x, y)
Error: Can't convert TYPE(location) to INTEGER(4) at (1)
나는이 오류를 알아낼 피곤, 그러나 나는 할 수 없었다 코딩에 대한 조언이나 제안이있는 사람이 있습니까?
나는 내 영어를 용서하고, 나는 일본어.
내 질문에 대한 질문이 있으시면 (자세한 설명이 필요함) 알려 주시기 바랍니다.
감사합니다. 우카
그 코볼입니다 : 장소의 수는 진정으로 가변적이고 경우
, 당신은 같은 것을 할 필요가 거라고? – Amit