“DATA INT /'STRING'/”与gfortran编译时出现问题 [英] "DATA INT / 'STRING' /" problem when compiling with gfortran

查看:177
本文介绍了“DATA INT /'STRING'/”与gfortran编译时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些旧的(〜1995)遗留Fortran代码,它是用g77编译器编译的,并且在gfortran上失败。
问题出现在以下几行(不兼容的类型转换,字符转换为整数):

pre $ $ $ $ c $ INT $ CKYAN
DATA CKYAN /'KYAN'/

变量CKYAN仅作为触发器使用一次:

  IF(IWVTX.EQ.CKYAN)THEN 
CALL FDCVERTEXSWITCHTOKYAN()
ENDIF

从输入文件(字符串'KYAN'或其他字符串)读取整数IWVTX。

我在fortran中没有任何重要的经验,而且在从字符串初始化整型变量时,我无法找到有关正在进行的任何文档。我已经检查过g77编译器。以下代码:

  INTEGER it,ita,it1,it2,it3,it4,it5,it6 
DATA it /'KYAN'/
DATA ita /'KYAN'/
DATA it1 /'K'/
DATA it2 /'Y'/
DATA it3 /'A'/
DATA it4 /'N'/
DATA it5 /'O'/
DATA it6 /'o'/
write(*,*)'test',it,ita, it1,it2,it3,it4,it5,it6

产生输出:

  1312905547 1312905547 538976331 538976345 538976321 538976334 538976335 538976367 

所以,如果字符串相等,数字也是相等的。如果一个字母紧挨着另一个字母,它的代码会加1。



问题如下:


  1. 这里发生了什么?

  2. 是否有一个函数可以执行相同且可用的gfortran?

  3. 或有没有简单的方法来解决这个问题,而不是触及任何其他文件?

有人可以帮我解决这个问题吗?谢谢你。

哇 - 这是1995年写的? Eep。



据我所知,这基本上是 Hollerith编码,用整数对字符常量进行编码(从CHARACTER数据类型之前开始)。作为一个快速测试,设置一个等于4HKYAN的整数似乎给出了相同的答案。



这里的原因似乎是设置一个等于一些不断测试之后。如果你想做同样的事情,现代化的方法是使用字符串的位表示形式,即 ckyan = transfer('KYAN',ckyan)将其转换为作为第二个参数传递的变量的格式,并将其返回。



但是在这里,只要IWVTX在不同情况下可以采取的值不同,则命名常量的值就不是关键...



顺便说一下,您可能已经知道这一点,但Fortran Wiki在现代化旧Fortran ;它不覆盖所有东西(比如之前我没有看到过的那个),但它有助于将很多旧的,非标准的构件转换为现代的Fortran。


I have some old (~1995) legacy fortran code which is compiled with g77 compiler and fails on gfortran. The problem is in following lines (incompatible types conversion, character to integer):

INTEGER  CKYAN
DATA     CKYAN / 'KYAN' /

The variable CKYAN is used only once as trigger:

IF(IWVTX.EQ.CKYAN)THEN
    CALL FDCVERTEXSWITCHTOKYAN()
ENDIF

The integer IWVTX is read from input file (string 'KYAN' or some other string).

I do not have any significant experience in fortran and I fail to find any documentation on what is going on when I initialize integer variable from the string. I have checked with the g77 compiler. The following code:

  INTEGER it,ita,it1,it2,it3,it4,it5,it6
  DATA it  / 'KYAN' /
  DATA ita / 'KYAN' /
  DATA it1 / 'K' /
  DATA it2 / 'Y' /
  DATA it3 / 'A' /
  DATA it4 / 'N' /
  DATA it5 / 'O' /
  DATA it6 / 'o' /
  write(*,*) 'test', it, ita, it1, it2, it3, it4, it5, it6

produces the output:

1312905547 1312905547 538976331 538976345 538976321 538976334 538976335 538976367

So, if the strings are equal the numbers are also equal. If one letter goes next to the other, it's code is incremented by 1.

The questions are the following:

  1. What is going on here?
  2. Is there a function that does the same and available gfortran?
  3. Or is there a simple way to fix this, not touching any other files?

Can anybody help me with this? Thank you in advance.

解决方案

Wow - and this was written in 1995? Eep.

As far as I can tell, this is basically Hollerith encoding, encoding character constants in integers (from back before there was a CHARACTER data type). As a quick test, setting one of those integers equal to 4HKYAN seems to give the same answer.

The reason for this here just seems to be to set a flag equal to some constant to test against afterwards. If you want to do the same thing, the modern way to do this is ckyan = transfer('KYAN',ckyan), which takes the bit representation of the character string, converts it to the format of the variable passed as it's second parameter, and returns it.

But here, it looks like the value of the named constant isn't critical as long as the values IWVTX can take on for the different cases are distinct...

By the way, you may already know about this, but the Fortran Wiki has a very handy page on Modernizing Old Fortran; it doens't cover everything (like this one, which I hadn't seen in quite this form before), but it has help for translating a lot of old, non-standard contstructs into modern Fortran.

这篇关于“DATA INT /'STRING'/”与gfortran编译时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆