fortran - Printing/writing a nested derived data type -


i obtained following module colleague. trying make program returns data in derived data types. not have experience derived data types. tried program table (end of file) not able anything. how can print or write derived data type?

  c=======================================================================   module mod_asoscommdates   c=======================================================================    implicit none    integer, parameter :: ncommdates=2    type asosdata         character (len=40) :: city         character (len=60) :: location         character (len=2)  :: state         integer            :: iwban         character (len=4)  :: intcall         character (len=3)  :: usacall         real               :: ddlat         real               :: ddlon         character (len=8)  :: commisdate         character (len=3)  :: pub         character (len=3)  :: sitetype         real               :: anem_feet         real               :: anem_meters   end type asosdata    type (asosdata), dimension(ncommdates) :: asoscommdates    contains       subroutine initasoscomminfo (asoscommdates)       type (asosdata), dimension(ncommdates) :: asoscommdates    asoscommdates(1) = asosdata("anchorage","lake hood seaplane base",  &  "ak",26491,"palh","lhd",61.17,-149.96,"19980122","no","faa",  &  33.00,10.05)   asoscommdates(2) = asosdata("anchorage","merrill field airport",  &  "ak",26409,"pamr","mri",61.21,-149.85,"19971015","no","faa",  &  16.00,4.87)           end subroutine initasoscomminfo    end module mod_asoscommdates    program table   use mod_asoscommdates   call initasoscomminfo(asoscommdates)   print *,asoscommdates(1)%asosdata%city   end program table 

post edited may 25, 2016 @ 10:54 est example posted had different errors associated question of post.

ncommdates changed ncommdates=886 ncommdates=2 call line changed call initasoscomminfo call initasoscomminfo(asoscommdates)

error during compilation is:

$ gfortran 2.for 2.for:48.39:        print *,asoscommdates(1)%asosdata%city                     1 error: 'asosdata' @ (1) not member of 'asosdata' structure 

although fortran standard specifies can write type-bound procedures i/o, many compilers don't support yet. simplest solution print derived type component-wise.

however, in code there no need specify type when accessing components:

print *,asoscommdates(1)%city 

... , other components.


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -