Fortran 77 中的内在函数 "INDEX" 有什么作用?

What does the intrinsic function "INDEX" in Fortran 77 do?

我正在研究代码并遇到以下行:

NP = INDEX (PATH, ' ')-1

"NP" 声明为整型变量,PATH 声明为字符。 "INDEX" 一词代表 Fortran 函数(它在代码中突出显示)。

这是什么意思,有什么作用?我在网上搜索了帮助,但 none 的结果令我满意。

我确实找到了一个参考资料,说 INDEX 功能总是写成 "INDEX (STRING, SUBSTRING)",但它什么也没说;因此,怀疑仍然存在。

如果您能解释上面的代码行是如何工作的,或者您能为我指明一些好的资源方向,我将不胜感激。

它returns子字符串在字符串中的位置。应该不难查找(除了在 phone 上)它在每个后续的 Fortran 中。

由于您特别要求 FORTRAN 77 的定义,这里是 FORTRAN 77 标准的相应部分...

Cl. 15.10 "Table of Intrinsic Functions":

Notes for Table 5:

[...]

  1. INDEX(a1,a2) returns an integer value indicating the starting position within the character string a1 of a substring identical to string a2. If a2 occurs more than once in a1, the starting position of the first occurrence is returned.

    If a2 does not occur in a1, the value zero is returned. Note that zero is returned if LEN(a1) < LEN(a2).

以及 Table 5 中的对应行:

|                   |                 |          |        |         |                     |
|                   |                 | Number of| Generic| Specific|       Type of       |
|Intrinsic Function | Definition      | Arguments|  Name  | Name    | Argument | Function |
|___________________|_________________|__________|________|_________|__________|__________|
| [...] 
|___________________|_________________|__________|________|_________|__________|__________|
|                   |                 |          |        |         |          |          |
|Index of           | Location of     |     2    |        | INDEX   | Character| Integer  |
|  a Substring      | Substring a2    |          |        |         |          |          |
|                   | in String a1    |          |        |         |          |          |
|                   | See Note 1      |          |        |         |          |          |
|___________________|_________________|__________|________|_________|__________|__________|

所以你的台词

NP = INDEX (PATH, ' ')-1

搜索变量 PATH 中第一次出现的空白 (</code>) 并从其位置减去 <code>1。然后将其分配给 NP