program main implicit none integer :: students integer,allocatable :: a(:) integer :: i write(*,*) "How many students:" read(*,*) students allocate(a(students)) !分配内存 write(*,*) "size of array = ",size(a) deallocate(a) !释放内存 stop end ...
write(*,*) "size of array = ",size(a) deallocate(a) !释放内存 stop end 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 测试程序(测试当前计算机所能分配的最大内存) program main implicit none integer :: size_N=0,error=0 integer,parameter :: one_mb=1024*1024 character...
print *, 'Enter the size of the array:' read *, n ! 分配动态数组 allocate(array(n)) ! 初始化数组元素 do i = 1, n array(i) = i * i end do ! 打印数组元素 print *, 'Array elements:' do i = 1, n print *, 'array(', i, ') = ', array(i) end do ! 释放动态数组 d...
ALLOCATED(ARRAY) 判断可分配数组的分配状态 LBOUND(ARRAY,DIM) 如果缺少DIM, 返回所有的ARRAY 下界:如果给出了DIM, 返回指定的ARRAY下界。如果DIM 缺省,结果是一个一维数组,如果给出了DIM, 结果是一个标量 SHAPE(SOURCE) 返回数组SOURCE的结构 SIZE(ARRAY,DIM) 如果给出了DIM返回指定维度的ARRAY的宽度, 否则返回...
或SUM (ARRAY [, MASK]) 数组元素的求和 2.1.15 数组查询函数通用内函数名 说明 ALLOCATED (ARRAY) 数组分配状态 LBOUND (ARRAY [, DIM]) 数组的维数下界 SHAPE (SOURCE) 数组或标量的形式 SIZE (ARRAY [, DIM]) 数组中的元素总数 UBOUND (ARRAY [, DIM]) 数组的维数上界 2.1...
!Method 4: The size of the array varies !当事先不知道每行要输出多少个,或者说数组大小会一直变,又不想每次都去更改程序的输出语句的时候,利用下面的方法 do i = 1, imax write (xstring,1000) jmax !把数字转换为字符串 1000 format(I3) xstring = '('//trim(ADJUSTL(xstring))//'f12.6)' !
When assumed shape arrays are used as procedure parameters, unlike the adjustable array examples above, the size of the arrays are not passed by the programmer as explicit parameters. Furthermore, the code generated for the function/subroutine does not assume that the passed parameters are con...
Suppose I wanted to measure, at runtime, the size of RAM available for an array allocation. The only Fortran-bound solution that I can think of, involves randomly (binary) searching for the maximum possible allocation and checking for zero status error, like the ...
Enter the size of the array: 3,4 darray( 1 , 1 ) = 1.00000000 darray( 1 , 2 ) = 2.00000000 darray( 1 , 3 ) = 3.00000000 darray( 1 , 4 ) = 4.00000000 darray( 2 , 1 ) = 2.00000000 darray( 2 , 2 ) = 4.00000000 darray( 2 , 3 ) = 6.00000000 darray( 2 , 4 ) =...
subroutineArray(num,size)implicitnoneinteger::sizeintegernum(size)!可以定义一个数组,其大小是通过传递过来的参数决定的。这很实用……returnend (5)save命令:将函数中的变量值在调用之后保留下来,下次调用此函数时该变量的值就是上次保的值。只要在定义时加上save就行:integer, save :: a=1 ...