gpt4 book ai didi

fortran - 程序内 SUBROUTINE 声明中的不可分类语句

转载 作者:行者123 更新时间:2023-12-04 03:13:53 24 4
gpt4 key购买 nike

所以我用 Fortran 90 编写了一个基本的 Vigenere Cypher,但是当我尝试编译它时,由于我的内部子程序,我遇到了无法分类的语句错误。

我已经在'(' ')' 中列出了每个子程序中使用的变量,但我仍然收到错误。我认为这是一个非常简单的修复,但我似乎找不到解决方案。

这是我的代码:

PROGRAM Assign_8

IMPLICIT NONE


CHARACTER*750 :: Input
CHARACTER*10 :: Key
CHARACTER*750 :: RepeatedKey
CHARACTER*750 :: Encrypted, Decrypted
LOGICAL :: Path
CHARACTER*10 :: Validation
INTEGER :: Reps, Encrypt, Decrypt, KeyInt, InputInt, MergeInt, UnmergeInt

WRITE(*,*) 'Do you wish to Encrypt or Decrypt a file?'

CALL Validation_Sub

SUBROUTINE Validation_Sub(Path, Validation)

IMPLICIT NONE

READ(*,*) Validation

SELECT CASE (Validation)

CASE ('Encrypt' , 'encrypt')
WRITE(*,*) 'You have selected to Encrypt a file.'
Path = .TRUE.

CASE ('Decrypt' , 'decrypt')
WRITE(*,*) 'You have selected to Decrypt a file.'
Path = .FALSE.

CASE DEFAULT
WRITE(*,*) 'Selection not valid please select to either Encrypt or Decrypt a file.'

IF (Path .EQV. .TRUE.) THEN

CALL Encrypt_Sub

ELSE IF (Path .EQV. .FALSE.) THEN

CALL Decrypt_Sub

END IF
END SELECT
END SUBROUTINE

SUBROUTINE Encrypt_Sub(Input, Key, RepeatedKey, Encrypt, InputInt, KeyInt, MergeInt, Encrypted)

IMPLICIT NONE

OPEN(1,FILE='plaintext.txt')
READ(1,'(A)') Input

WRITE(*,*) 'Please Enter a Key Phrase of 10 Characters (Including Spaces and Punctuation)'
READ(*,*) Key
RepeatedKey = REPEAT(Key(1:10),75)

DO Encrypt = 1, LEN_TRIM(Input)
InputInt = IACHAR(Input(Encrypt:Encrypt))
KeyInt = IACHAR(RepeatedKey(Encrypt:Encrypt))
MergeInt = InputInt + (KeyInt - 32)

IF (MergeInt > 126) THEN
MergeInt = MergeInt - 94
END IF

Encrypted(Encrypt:Encrypt) = ACHAR(MergeInt)

END DO

OPEN(2,FILE='EncryptionTest.txt')
WRITE(2,'(A)') Encrypted
CLOSE(2)

END SUBROUTINE

SUBROUTINE Decrypt_Sub(Encrypted, Key, RepeatedKey, Decrypt, MergeInt, KeyInt, UnmergeInt, Decrypted)

IMPLICIT NONE

OPEN(1,FILE='EncryptionTest.txt')
READ(1,'(A)') Encrypted
CLOSE(1)

WRITE(*,*) 'Please Enter Your Key Phrase'
READ(*,'(A)') Key
RepeatedKey = REPEAT(Key(1:10),75)

DO Decrypt = 1, 750, 1
MergeInt = IACHAR(Encrypted(Decrypt:Decrypt))
KeyInt = IACHAR(RepeatedKey(Decrypt:Decrypt))
UnmergeInt = MergeInt - (KeyInt - 32)

IF (UnmergeInt < 32) THEN
UnmergeInt = UnmergeInt + 94
END IF

Decrypted(Decrypt:Decrypt) = ACHAR(UnmergeInt)

END DO

OPEN(2,FILE='DecryptionTest.txt')
WRITE(2,'(A)') Decrypted
CLOSE(2)

END SUBROUTINE

END PROGRAM Assign_8

我得到的具体错误是:

SUBROUTINE Validation_Sub(Path, Validation)
1

>Unclassifiable Statement at (1)

(间隔)

IMPLICIT NONE
1

>Unexpected IMPLICIT NONE statement at (1)

我怀疑 IMPLICIT NONE 错误是由于未正确定义 SUBROUTINE 造成的。

END SUBROUTINE
1

>Expecting END Program statement at (1)

和之前一样,我怀疑这是因为SUBROUTINE没有被定义。

这些错误会重复出现:

SUBROUTINE Encrypt_Sub

&

SUBROUTINE Decrypt_Sub

任何帮助将不胜感激,如果有人发现我的 Vigenere Cypher 代码本身存在任何即时错误,如果您能指出这些错误(如果没有问题的话),我们将不胜感激。

最佳答案

您在子例程之前缺少 CONTAINS

将来学习模块,但现在使用 CONTAINS 使这些子例程正确地包含在主程序内部。

应该是这样的

PROGRAM Assign_8
...

CALL Validation_Sub

CONTAINS

SUBROUTINE Validation_Sub(Path, Validation)
END SUBROUTINE

...

END PROGRAM Assign_8

关于fortran - 程序内 SUBROUTINE 声明中的不可分类语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42743842/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com