“数据INT/'字符串'/"使用 gfortran 编译时的问题 [英] "DATA INT / 'STRING' /" problem when compiling with gfortran

查看:13
本文介绍了“数据INT/'字符串'/"使用 gfortran 编译时的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些旧的(~1995 年)遗留 fortran 代码,这些代码是用 g77 编译器编译的,但在 gfortran 上失败了.问题出在以下几行(不兼容的类型转换,字符到整数):

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' /

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

The variable CKYAN is used only once as trigger:

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

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

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

我在 fortran 方面没有任何重要的经验,并且在我从字符串中初始化整数变量时,我找不到任何关于发生了什么的文档.我已经检查了 g77 编译器.以下代码:

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

产生输出:

1312905547 1312905547 538976331 538976345 538976321 538976334 538976335 538976367

因此,如果字符串相等,则数字也相等.如果一个字母紧挨着另一个,则其代码加 1.

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.

问题如下:

  1. 这是怎么回事?
  2. 是否有与 gfortran 相同且可用的函数?
  3. 或者有没有一种简单的方法来解决这个问题,而不涉及任何其他文件?

谁能帮我解决这个问题?提前谢谢你.

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

推荐答案

哇 - 这是 1995 年写的?哎呀.

Wow - and this was written in 1995? Eep.

据我所知,这基本上是 Hollerith 编码,将字符常量编码为整数(从以前有一个 CHARACTER 数据类型).作为一个快速测试,将其中一个整数设置为 4HKYAN 似乎给出了相同的答案.

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.

这里的原因似乎是设置一个等于某个常量的标志,以便之后进行测试.如果你想做同样的事情,现代的方法是 ckyan = transfer('KYAN',ckyan),它采用字符串的位表示,将其转换为变量作为它的第二个参数传递,并返回它.

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.

但在这里,命名常量的值似乎并不重要,只要 IWVTX 在不同情况下可以采用的值是不同的...

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...

顺便说一句,您可能已经知道了,但是 Fortran Wiki 在 现代化旧 Fortran;它并没有涵盖所有内容(比如这个,我以前从未见过这种形式),但它有助于将许多旧的、非标准的结构转换为现代 Fortran.

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.

这篇关于“数据INT/'字符串'/"使用 gfortran 编译时的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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