本文介绍了程序内SUBROUTINE声明的无法分类的声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在Fortran 90编写了一个基本的Vigenere Cypher,但是当我尝试编译它时,由于我的内部子程序的缘故,我遭受了无法分类的声明错误。

我在'('')'中列出了每个SUBROUTINE中使用的变量,但是我仍然收到错误。我认为这是一个非常简单的解决方法,但我似乎无法找到解决方案。



这是我的代码:

  PROGRAM Assign_8 

IMPLICIT NONE


CHARACTER * 750 ::输入
CHARACTER * 10 ::键
CHARACTER * 750 :: RepeatedKey
CHARACTER * 750 ::加密,解密
LOGICAL ::路径
字符* 10 ::验证
INTEGER ::代表,加密,解密,KeyInt,InputInt,MergeInt,UnmergeInt

WRITE(*,*)'你想加密还是解密文件?'

CALL Validation_Sub
$ b $ SUBROUTINE Validation_Sub(Path,Validation)

IMPLICIT NONE

READ(*,*)验证

SELECT CASE(验证)

CASE('Encrypt','encrypt')
WRITE(*,*)'您已选择加密文件'
Path = .TRUE 。

CASE('Decrypt','decrypt')
WRITE(*,*)'您已选择解密文件'
Path = .FALSE。

CASE DEFAULT
WRITE(*,*)'选择无效请选择加密或解密文件。'

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
$ b OPEN(1,FILE ='plaintext.txt')
READ(1,'(A)')输入

WRITE(* *)'请输入10个字符的关键词组(包括空格和标点符号)'
READ(*,*)键
RepeatedKey = REPEAT(键(1:10),75)

DO Encrypt = 1,LEN_TRIM(输入)
InputInt = IACHAR(输入(加密:加密))
KeyInt = IACHAR(RepeatedK ey(Encrypt:Encrypt))
MergeInt = InputInt +(KeyInt - 32)

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

加密(加密:加密)= ACHAR(MergeInt)

END DO

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

子程序
$ b $ SUBROUTINE Decrypt_Sub(加密,密钥,重复密钥,解密,MergeInt,KeyInt,UnmergeInt,解密)

隐式无

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

WRITE(*,*)'请输入您的密钥短语'
READ(*,'(A)')键
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 UnmergeInt = UnmergeInt + 94
END IF

Decrypt(Decrypt:Decrypt)= ACHAR(UnmergeInt)

END DO

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

结束子程序

END PROGRAM Assign_8

我回来的具体错误是: (b)>

  SUBROUTINE Validation_Sub(Path,Validation)
1

>





  IMPLICIT NONE 
1

>意外的IMPLICIT NONE语句位于(1)

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

  END SUBROUTINE 
1

>期望在(1)

像以前一样,我怀疑这个我因为SUBROUTINE尚未定义。



这些错误会重复以下情况:

  SUBROUTINE Encrypt_Sub 

&

  SUBROUTINE Decrypt_Sub 

任何帮助将不胜感激,如果任何人都会在我的Vigenere Cypher代码本身中发现任何直接的错误,如果您能指出它是否没有问题,也将非常感激。解决方案

在你的子程序之前你缺少 CONTAINS

在未来的学习模块中,现在使用 CONTAINS ,使这些子程序在主程序中正常运行。



所以它应该看起来像

  PROGRAM Assign_8 
...

CALL Validation_Sub

CONTAINS

SUBROUTINE Validation_Sub(路径,验证)
END SUBROUTINE

...

END PRO GRAM Assign_8


So I've written a basic Vigenere Cypher in Fortran 90, however when I try to compile it, I am hammered with Unclassifiable Statement Errors due to my internal SUBROUTINES.

I have listed the variables used in each SUBROUTINE in '(' ')', but I am still getting back errors. I think it's a really simple fix, but I can't seem to find a solution to it.

Here is my code:

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

And the specific errors I am getting back are:

SUBROUTINE Validation_Sub(Path, Validation)
1

>Unclassifiable Statement at (1)

(Spacer)

IMPLICIT NONE
             1

>Unexpected IMPLICIT NONE statement at (1)

I suspect the IMPLICIT NONE error is due to the SUBROUTINE not being defined properly.

END SUBROUTINE
   1

>Expecting END Program statement at (1)

As before, I suspect this is because the SUBROUTINE has not been defined.

These errors repeat themselves for:

SUBROUTINE Encrypt_Sub

&

SUBROUTINE Decrypt_Sub

Any help would be greatly appreciated, if anyone does spot any immediate errors within my Vigenere Cypher code itself it would also be greatly appreciated if you could point them out if its no trouble.

解决方案

You are missing CONTAINS before your subroutine.

In the future learn modules, but now use CONTAINS to make those subroutines properly internal to the main program.

So it should look like

PROGRAM Assign_8
  ...

  CALL Validation_Sub

CONTAINS

  SUBROUTINE Validation_Sub(Path, Validation)
  END SUBROUTINE

  ...

END PROGRAM Assign_8

这篇关于程序内SUBROUTINE声明的无法分类的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 22:29