安靖 发表于 2015-5-22 19:17:20

GDB调试fortran程序,如何查看派生类型数据

本帖最后由 安靖 于 2015-5-22 20:59 编辑

用gdb调试Fortran程序,如何查看派生类型数据?
例如,查看ndim就可以直接输入:   p data%ndim但是要查看coorn里的数据是什么命令呢? coorn是动态分配的数组
我输入 p data%coorn 提示 =<object is not allocated>
但是coorn明明已经分配好内存了


!   test2.f90
program main
      use comm_data
      implicit none
      type(core_data) :: data


      call allo_core_data( data, 2, 4)
      data % coorn = 4.0

      write(*,*) data % coorn

      stop
end program main

! comm_data.f90
module comm_data
      implicit none
      
      save
      
      type core_data               
                integer ndim               
                integer npoint
                real,    allocatable, dimension(:,:) :: coorn               
      end type core_data      
      
      contains

subroutine allo_core_data(      data, ndim, npoint )
      implicit none
      type(core_data), intent(out) :: data
      integer, intent(in) :: npoint
      integer, intent(in) :: ndim
      
      data % ndim = ndim
      data % npoint = npoint
      
      allocate( data % coorn( data % ndim, data % npoint ) )
      data % coorn = 0.0
      
end subroutine allo_core_data


end module comm_data


makefile

TARGET= test.out
GC      = ifort
CFLAGS= -fpp -g
SOR      = comm_data.f90 test2.f90
OBJS      = test2.o comm_data.o
$(OBJS):
      @echo "-----------------------------------"
      @echo "Compiling..."
      @echo "-----------------------------------"
      @$(GC) $(CFLAGS) -c $(SOR) $(INCLUDE)
      @echo "-----------------------------------"
      @echo "Linking..."
      @echo "-----------------------------------"
      @$(GC) $(CFLAGS) -o $(TARGET) $(OBJS) $(LIBS)
      @echo "-----------------------------------"
      @echo "Deleting OBJ & MOD files..."
      @echo "-----------------------------------"
      @rm -fr *.o
      @echo "-----------------------------------"
clean:
      @rm -fr *.o *.mod
      @rm -fr $(TARGET)



安靖 发表于 2015-5-22 21:03:10

makefile文件不能添加附件,只能手工复制了

安靖 发表于 2015-5-23 17:34:21

看来用gdb的人不多啊

好小爱新 发表于 2015-6-15 08:57:04

您用ifort配合gdb?确实没试过,不过如果是windows版本的话,用打过董兄(xunxun)的补丁的gdb就可以用print显示结构内数据及动态数组数据了。

fcode 发表于 2015-6-15 13:42:44

小爱,么么哒

安靖 发表于 2015-7-2 12:04:15

好小爱新 发表于 2015-6-15 08:57
您用ifort配合gdb?确实没试过,不过如果是windows版本的话,用打过董兄(xunxun)的补丁的gdb就可以用print显 ...

linux版本的。 后来也是没有解决掉,只靠write慢慢调试
页: [1]
查看完整版本: GDB调试fortran程序,如何查看派生类型数据