鍍金池/ 教程/ Java/ Fortran重塑函數(shù)
Fortran還原功能
Fortran關(guān)系運(yùn)算符
Fortran運(yùn)算符優(yōu)先級(jí)
Fortran基本語法
Fortran文件輸入輸出
Fortran嵌套select case結(jié)構(gòu)
Fortran變量
Fortran Cycle語句
Fortran語言環(huán)境設(shè)置
Fortran數(shù)據(jù)類型
Fortran數(shù)組
Fortran字符
Fortran if...else if...else 語句
Fortran調(diào)試程序
Fortran編程風(fēng)格
Fortran if...then語句結(jié)構(gòu)
Fortran嵌套循環(huán)
Fortran常量
Fortran循環(huán)
Fortran導(dǎo)出數(shù)據(jù)類型
Fortran字符串
Fortran操作函數(shù)
Fortran do...while循環(huán)結(jié)構(gòu)
Fortran內(nèi)部函數(shù)
Fortran數(shù)字精度
Fortran選擇決策
Fortran重塑函數(shù)
Fortran運(yùn)算符
Fortran構(gòu)造函數(shù)
Fortran模塊
Fortran位置函數(shù)
Fortran數(shù)字
Fortran指針
Fortran算術(shù)運(yùn)算符
Fortran exit語句
Fortran動(dòng)態(tài)數(shù)組
Fortran嵌套if結(jié)構(gòu)
Fortran select case結(jié)構(gòu)
Fortran向量和矩陣乘法函數(shù)
Fortran邏輯運(yùn)算符
Fortran if...then...else 結(jié)構(gòu)
Fortran教程
Fortran過程
Fortran Stop語句
Fortran基本輸入輸出
Fortran do循環(huán)結(jié)構(gòu)
Fortran查詢函數(shù)

Fortran重塑函數(shù)

下表描述了重塑函數(shù):

函數(shù) 描述
reshape(source, shape, pad, order) 它構(gòu)造一個(gè)特定形狀的形狀,從一個(gè)給定source陣列中的元素開始的數(shù)組。如果墊不包含則soure的尺寸必須至少為產(chǎn)物(形狀)。如果pad包括在內(nèi),它必須具有相同的類型的soure。如果order被包括,它必須使用相同的形狀的形狀的整數(shù)數(shù)組,值必須是一個(gè)排列(1,2,3,...,n),其中n是在形狀要素的數(shù)量,它必須小于或等于7。

示例

下面的例子演示了這一概念:

program arrayReshape
implicit none

interface
   subroutine write_matrix(a)
   real, dimension(:,:) :: a
   end subroutine write_matrix
   end interface

   real, dimension (1:9) :: b = (/ 21, 22, 23, 24, 25, 26, 27, 28, 29 /)
   real, dimension (1:3, 1:3) :: c, d, e
   real, dimension (1:4, 1:4) :: f, g, h

   integer, dimension (1:2) :: order1 = (/ 1, 2 /)
   integer, dimension (1:2) :: order2 = (/ 2, 1 /)
   real, dimension (1:16) :: pad1 = (/ -1, -2, -3, -4, -5, -6, -7, -8, &
                                 & -9, -10, -11, -12, -13, -14, -15, -16 /)

   c = reshape( b, (/ 3, 3 /) )
   call write_matrix(c)

   d = reshape( b, (/ 3, 3 /), order = order1)
   call write_matrix(d)

   e = reshape( b, (/ 3, 3 /), order = order2)
   call write_matrix(e)

   f = reshape( b, (/ 4, 4 /), pad = pad1)
   call write_matrix(f)

   g = reshape( b, (/ 4, 4 /), pad = pad1, order = order1)
   call write_matrix(g)

   h = reshape( b, (/ 4, 4 /), pad = pad1, order = order2)
   call write_matrix(h)

end program arrayReshape


subroutine write_matrix(a)
   real, dimension(:,:) :: a
   write(*,*)
   
   do i = lbound(a,1), ubound(a,1)
      write(*,*) (a(i,j), j = lbound(a,2), ubound(a,2))
   end do上一篇:Fortran構(gòu)造函數(shù)下一篇:Fortran基本輸入輸出