在Fortran 90中,是否不可能在新变量的声明语句中引用先前声明的变量?(In Fortran 90, is it impossible to refer to previously-declared variables in the declaration statement of a new variable?)
在Fortran中,变量的声明语句是否可以引用先前声明的变量? 例如,当我尝试以下操作时:
PROGRAM test3 IMPLICIT NONE INTEGER :: a=2286 INTEGER :: b=a/3 WRITE(*,*) a, b END PROGRAM test3
我收到编译时错误消息:
test3.f90:5.16: INTEGER :: b=a/3 1 Error: Parameter 'a' at (1) has not been declared or is a variable, which does not reduce to a constant expression
另一方面,如果我在与声明b不同的语句中将b赋值给a / 2 ,它将编译并运行良好:
PROGRAM test3 IMPLICIT NONE INTEGER :: a=2286 INTEGER :: b b=a/3 WRITE(*,*) a, b END PROGRAM test3
这给了我正确的输出:
2286 762
为什么会出现这种情况 - 先前声明的变量不能包含在新变量的声明语句中? 难道我做错了什么? 或者这只是一个“Fortran生活事实”?
非常感谢您的宝贵时间!
In Fortran, is it possible for declaration statements for variables to refer to previously-declared variables? For example, when I try the following:
PROGRAM test3 IMPLICIT NONE INTEGER :: a=2286 INTEGER :: b=a/3 WRITE(*,*) a, b END PROGRAM test3
I get a compile-time error message:
test3.f90:5.16: INTEGER :: b=a/3 1 Error: Parameter 'a' at (1) has not been declared or is a variable, which does not reduce to a constant expression
On the other hand, if I assign b to a/2 in a statement separate from the declaration of b, it compiles and runs fine:
PROGRAM test3 IMPLICIT NONE INTEGER :: a=2286 INTEGER :: b b=a/3 WRITE(*,*) a, b END PROGRAM test3
which gives me the correct output:
2286 762
Why is this the case--that previously-declared variables cannot be included in declaration statements of new variables? Am I doing something wrong? Or is this just a "Fortran fact of life"?
Thank you very much for your time!
原文:https://stackoverflow.com/questions/6510161
最满意答案
这工作
var currentSource string var currentDest string func main() { file := "A1,B2\n" scanner := bufio.NewScanner(strings.NewReader(file)) for scanner.Scan() { strs := strings.Split(scanner.Text(), ",") currentSource = strs[0] currentDest = strs[1] fmt.Println(strs) } }
你确定你的文件(
chessin.txt
)没问题吗?This works
var currentSource string var currentDest string func main() { file := "A1,B2\n" scanner := bufio.NewScanner(strings.NewReader(file)) for scanner.Scan() { strs := strings.Split(scanner.Text(), ",") currentSource = strs[0] currentDest = strs[1] fmt.Println(strs) } }
Are you sure your file (
chessin.txt
) it is ok?
相关问答
更多-
将第二个字符串字符与数组中的第一个字符串进行比较(Compare the 2nd strings characters with the 1st string in an array)[2022-07-08]
感谢@Bergi,我想出了答案。 他也非常友好地允许我自己发布答案。 这里是... function mutation(arr) { var string2 = arr.splice(1).toString().toLowerCase(); var string1 = arr.toString().toLowerCase(); for(var i = 0; i < string2.length; i++) { if (string1.indexOf(string2.charAt(i ... -
我不熟悉PHP,但你可以用string.Join连接字符串数组的所有元素: return string.Join(" ", docs); 第一个参数是分隔符; 如果你不需要分隔符,你可以传递一个空字符串。 I am not familiar with PHP, but you can concatenate all elements of a string array with string.Join: return string.Join(" ", docs); The first parameter ...
-
把它写成单词 - 你想知道foo任何项目是否包含在bar 。 所以在代码中,几乎完全一样: if(foo.Any(item => bar.Contains(item))) Putting it into words - you want to know if any of the items in foo is contained in bar. So in code, almost exactly the same: if(foo.Any(item => bar.Contains(item)))
-
如何匹配另一个字符串开头的数组中的字符串(How to match a string from an array at the beginning of another string)[2023-01-03]
我用的是: TOKENS = ["m", "o"] DATA_COL = ["M", "b", "Mabc", "abc m b"] RE = /^(?:#{Regexp.union(TOKENS).source})(?: |$)/i DATA_COL.select{ |string| string[RE] } # => ["M"] 打破一点: Regexp.union(TOKENS).source # => "m|o" /^(?:#{Regexp.union(TOKENS).source})(?: | ... -
如果您的输入是以空格分隔的,则可以将studentID读入string (例如: cin >> studentID )。 然后,您可以编写一个循环来读取20个字符( char数据类型)到testAnswers数组中。 If your input is space-delimited, you can read the studentID into a string (ex: cin >> studentID). You can then write a loop to read 20 characters ...
-
这工作 var currentSource string var currentDest string func main() { file := "A1,B2\n" scanner := bufio.NewScanner(strings.NewReader(file)) for scanner.Scan() { strs := strings.Split(scanner.Text(), ",") currentSource = strs[0] ...
-
你可以为此编写自己的函数 public boolean convertToBoolean(String input) throws Exception{ if(input == null){ throw new Exception("Input is null"); } if(input.toLowerCase().contains("true")){ return true; } else { return false ...
-
使用c_str 。 http://en.cppreference.com/w/cpp/string/basic_string/c_str 像这样复制到数组: strcpy(a, word.c_str()); Use c_str. http://en.cppreference.com/w/cpp/string/basic_string/c_str And something like this to copy to array: strcpy(a, word.c_str());
-
这不是一个“两种类型的数组”,它是一个元组数组 。 您可以从数组中获取一个项目,并像下面这样获取其各个部分: let (name, score) = totalDoubleSet1Array[i] 在这个赋值之后,你会得到两个变量 - 类型为String的名称,其值为第i个元素的名称,以及类型为Int score ,其值为第i个元素的得分。 如果你需要的只是名字,你有两种选择: 你可以使用let (name, _) = totalDoubleSet1Array[i]语法,或者 你可以使用let name ...
-
c# - 使用另一个字符串数组中的字符串搜索字符串数组(c# - search a string array using strings from another string array)[2022-01-31]
如果你打破一些问题,这一点都不难。 首先,远离处理数组和索引。 只需使用IEnumerable,它将使您的生活更轻松。 以下是我的看法: 首先,你想要找到阵列needles所有字符串,它们是字符串的一部分, haystack 。 public static IEnumerable MatchingStrings(string haystack, IEnumerable needles) { return needles.Where(needle => hays ...