next up previous contents
Next: API Up: User hook for command Previous: User hook for command   Contents

Example

If no user hooks have been declared, the output of the command DUMP /SECTION USER will be (with the example shown in the previous section):

 USER ------------------------------------------------------
  Number of subsections: 1
  User Section #   1
    Owner:         OWNER
    Title:         TITLE
    Version:       1
    Data length:   5
    Data:
      (can not dump)
CLASS claims it is not able to understand the content of the data buffer in the User Subsection.

The following subroutines show basically what should be done by the section owner to allow CLASS to DUMP a specific user section:

subroutine mydump_init
  !----------------------------------------------------------------------
  ! Preliminary declarations
  !----------------------------------------------------------------------
  !
  ! 1) Tell Class who I am
  call class_user_owner('OWNER','TITLE')
  !
  ! 2) Declare my dumping routine
  call class_user_dump(mydump)
  !
  ! Nothing more: return and wait for Class to ask for my User
  ! Subsection dump.
  !
end subroutine mydump_init

subroutine mydump(version,error)
  use mytypes
  !---------------------------------------------------------------------
  ! Dump to screen my User Subsection
  !---------------------------------------------------------------------
  integer(kind=4), intent(in)    :: version  ! The version of the data
  logical,         intent(inout) :: error    ! Logical error flag
  ! Local
  type(owner_title_version) :: mydata
  !
  call fromclass(mydata,version,error)  ! Read the Class buffer and fill mydata
  if (error)  return
  !
  ! Display to screen
  print *,"     datai4 = ",mydata%datai4
  print *,"     datar4 = ",mydata%datar4
  print *,"     datar8 = ",mydata%datar8
  print *,"     datac4 = ",mydata%datac4
  !
end subroutine mydump

subroutine fromclass(mydata,version,error)
  use mytypes
  use class_user_interfaces
  !---------------------------------------------------------------------
  ! Transfer the data values from the Class data buffer to the 'mydata'
  ! instance.
  !---------------------------------------------------------------------
  type(owner_title_version), intent(out)   :: mydata   !
  integer(kind=4),           intent(in)    :: version  ! The version of the data
  logical,                   intent(inout) :: error    ! Logical error flag
  !
  if (version.ne.1) then
    print *,'FROMCLASS: Unsupported data version ',version
    error = .true.
    return
  endif
  !
  call class_user_classtodata(mydata%datai4)
  call class_user_classtodata(mydata%datar4)
  call class_user_classtodata(mydata%datar8)
  call class_user_classtodata(mydata%datac4)
  !
end subroutine fromclass

With these subroutines, CLASS is now able to ask for a translation of the User Subsection. The output of the command DUMP /SECTION USER will be:

 USER ------------------------------------------------------
  Number of subsections: 1
  User Section #   1
    Owner:         OWNER
    Title:         TITLE
    Version:       1
    Data length:   5
    Data:
      datai4 =          111
      datar4 =    222.00000
      datar8 =    333.00000000000000
      datac4 = ABCD



Gildas manager 2014-07-01