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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.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
Fortran 如何使用维度属性?_Fortran_Fortran90 - Fatal编程技术网

Fortran 如何使用维度属性?

Fortran 如何使用维度属性?,fortran,fortran90,Fortran,Fortran90,我需要找到如何在此程序中使用维度属性。这里我无法解决的问题是,用户如何指定行数?(换言之,学生人数): 基本上,您有固定(静态)数组,这些数组是使用维度定义的: real,dimension(4) :: X X是长度为4(1-4)的数组。这相当于: real :: X(4) 静态数组在其作用域中具有固定长度(例如,在全局变量的整个程序中或在函数/子例程中) 您需要的是allocate数组,这些数组在运行时是allocated: program test implicit none r

我需要找到如何在此程序中使用
维度
属性。这里我无法解决的问题是,用户如何指定行数?(换言之,学生人数):


基本上,您有固定(静态)数组,这些数组是使用
维度定义的:

real,dimension(4) :: X
X
是长度为
4
1
-
4
)的数组。这相当于:

real :: X(4)
静态数组在其作用域中具有固定长度(例如,在全局变量的整个程序中或在函数/子例程中)

您需要的是
allocate
数组,这些数组在运行时是
allocate
d:

program test
  implicit none
  real, allocatable :: B(:) ! The shape is given by ":" - 1 dimension
  integer           :: stat

  ! allocate memory, four elements: 
  allocate( B(4), stat=stat )
  ! *Always* check the return value
  if ( stat /= 0 ) stop 'Cannot allocate memory'

  ! ... Do stuff

  ! Clean up
  deallocate( B )

  ! Allocate again using a different length:
  allocate( B(3), stat=stat )
  ! *Always* check the return value
  if ( stat /= 0 ) stop 'Cannot allocate memory'

  ! No need to deallocate at the end of the program! 

end program
这管用!谢谢你们。

你们什么意思?这有用?您显示的代码片段肯定不起作用。
program test
  implicit none
  real, allocatable :: B(:) ! The shape is given by ":" - 1 dimension
  integer           :: stat

  ! allocate memory, four elements: 
  allocate( B(4), stat=stat )
  ! *Always* check the return value
  if ( stat /= 0 ) stop 'Cannot allocate memory'

  ! ... Do stuff

  ! Clean up
  deallocate( B )

  ! Allocate again using a different length:
  allocate( B(3), stat=stat )
  ! *Always* check the return value
  if ( stat /= 0 ) stop 'Cannot allocate memory'

  ! No need to deallocate at the end of the program! 

end program
real,dimension(:,:),allocatable ::A

character(len=10),dimension(:),allocatable::B
.
.
.
 DEALLOCATE(A)
          DEALLOCATE(B)