Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Format Fortran:将文本文件中的值赋给变量_Format_Fortran - Fatal编程技术网

Format Fortran:将文本文件中的值赋给变量

Format Fortran:将文本文件中的值赋给变量,format,fortran,Format,Fortran,我们最近在大学开始了fortran的讲座,而我们的讲师实际解释某些东西的时间非常有限。因此,由于我从未有过使用这种编程语言的经验,我正在为一些问题而挣扎。特别是格式的整个概念。我试图从文本文件中为变量赋值 program interpolation implicit none integer :: i,N real :: T1,Hfg1,T2,Hfg2,T,Hfg !------------------------------------- open(20,file='values.txt')

我们最近在大学开始了fortran的讲座,而我们的讲师实际解释某些东西的时间非常有限。因此,由于我从未有过使用这种编程语言的经验,我正在为一些问题而挣扎。特别是格式的整个概念。我试图从文本文件中为变量赋值

program interpolation

implicit none
integer :: i,N
real :: T1,Hfg1,T2,Hfg2,T,Hfg
!-------------------------------------
open(20,file='values.txt')
!Input temperature to be interpolated
print*,'Input temperature to be interpolated'
read(*,*) T
!Read number of values from file
read(20,1000) N
1000 format(I5)
代码从这里继续,但我真正努力理解的是整个格式概念。我的看法是,我打开一个文件“values.txt”并将单元20分配给它,因此每当我调用单元20时,我都会引用该文件。正确的?之后,我要求用户为T输入一些初始值。这并不重要。在这之后,我从unit=20文件中读取一个赋值给变量N。现在数字1000是什么意思?下一步“1000格式(I5)”的目的是什么?据我所知,“I5”是指最大字符数为5的整数?还是我错了?

“1000”是连接read和format语句的语句标签。在读取时,“I5”表示整数需要在前五列中右对齐

有关该语言的功能,请参见