回 帖 发 新 帖 刷新版面

主题:数组变量问题

下面是我编的一个程序,在标示的地方出错,是数组定义的变量不对吗?还是什么,刚学习,请大神指点

       program  main
         implicit none
         integer eno,nno,enoi,enoj
         integer fixn,forn
         real:: iek
         module iek
         real:: igk
         module igk
         real, allocatable,dimension(:):: springk
        

         open(unit=11,file='setup.txt',status='old')

         read(11,*)
         read(11,*)nno
         read(11,*)
         read(11,*)eno
         allocate (springk(eno))
         read(11,*)
         read(11,*)springk
         read(11,*)
         read(11,*)fixn
         read(11,*)
         read(11,*)forn

         close(11)

         write(*,*)springk
         write(*,*)'----------------------'

         call sspp(nno,eno,springk,fixn,forn)
         end

 


c----------------------------------------------------------------
         subroutine sspp(nno,eno,springk,fixn,forn)
         implicit none
         integer eno,nno,enoi,enoj
         real springk(eno),ek(eno,2,2),gk(eno,nno,nno)
         integer fixn,forn

         do iek = 1,eno
           ek=0
           gk=0
           igk = iek
           enoi = iek
           enoj = enoi+1
            call SpringElementStiffness(springk(iek),ek,iek)
c           call SpringAssemble(gk(igk,nno,nno),ek(iek,2,2),enoi,enoj)
         enddo


         write(*,*)'global stiffness matrix : '

         write(*,*)'gk(',igk,')='
         write(*,*)gk(igk,1,:)
         write(*,*)gk(igk,2,:)
         write(*,*)gk(igk,3,:)

        end subroutine
c---------------------------------------------------------------------------------
c       SpringElementStiffness: This function returns the element stiffness
c                         matrix for a spring with stiffness k.
c                         The size of the element stiffness matrix
c                         is 2*2.

         subroutine SpringElementStiffness(spk,ek,iek)
         implicit none
         real ek(iek,2,2),spk
         ek(iek,1,1) = spk
         ek(iek,1,2) = -spk
         ek(iek,2,1) = -spk
         ek(iek,2,2) = spk

         write(*,*)'spk= ',spk
         write(*,*)'ek( ',iek,') = '
         write(*,*)ek(iek,1,:)
         write(*,*)ek(iek,2,:)
         end subroutine

c--------------------------------------------------------------------------

c      SpringAssemble: This function assembles the element stiffness
c                 matrix k of the spring with nodes i and j into the
c                 globalstiffness matrix k.
c                 This function returns the global stiffness matrix k
c                 after the element stiffness matrix k is assembled.

       subroutine SpringAssemble(gk, ek, enoi, enoj)
        implicit none
        integer iek,igk,enoi,enoj
        real gk(igk,3,3),ek(iek,2,2)
         gk(igk,enoi,enoi)  =  gk(igk,enoi,enoi)+ek(iek,1,1);
         gk(igk,enoi,enoj)  =  gk(igk,enoi,enoj)+ek(iek,1,2);
         gk(igk,enoj,enoi)  =  gk(igk,enoj,enoi)+ek(iek,2,1);
         gk(igk,enoj,enoj)  =  gk(igk,enoj,enoj)+ek(iek,2,2);


c        write(*,*)gk(1,3,1),gk(1,3,2),gk(1,3,3)

         end subroutine

回复列表 (共3个回复)

沙发

你没有把错误信息贴出来。
用fortran开数组时,

板凳

上一楼误操作了,不能编辑已发的东西,下面继续。

你把第二行改成gk(:,:,:),ek(:,:,:)试试

3 楼

找到原因了  是因为有些参数没有在调用语句中出现导致的,将用到的参数直接都添加在括号中即可

我来回复

您尚未登录,请登录后再回复。点此登录或注册