next up previous contents
Next: Detailed API Up: Adding a user subsection Previous: Adding a user subsection   Contents

Example

The following program adds a new Usec Section to a CLASS observation. A more realistic program would open an output file and write the observation into it. The data here contains dummy values and names for the example.

module mytypes
  type :: owner_title_version
    integer(kind=4)   :: datai4
    real(kind=4)      :: datar4
    real(kind=8)      :: datar8
    character(len=4)  :: datac4
  end type owner_title_version
end module mytypes

program myprog
  use class_types
  use class_user_interfaces
  use mytypes
  external :: toclass
  type(observation) :: obs
  type(owner_title_version) :: mydata
  integer(kind=4) :: version
  logical :: error
  !
  ! 1) Fill the data
  mydata%datai4 = 111
  mydata%datar4 = 222.
  mydata%datar8 = 333.
  mydata%datac4 = 'ABCD'
  !
  ! 2) Tell Class who I am
  call class_user_owner('OWNER','TITLE')
  !
  ! 3) Declare my transfer subroutine
  call class_user_toclass(toclass)
  !
  ! 4) Fill the User Section in the observation
  version = 1
  error = .false.
  call class_user_add(obs,version,mydata,error)
  if (error)  stop
  !
end program myprog

subroutine toclass(mydata,version,error)
  use class_user_interfaces
  use mytypes
  !---------------------------------------------------------------------
  ! Transfer and order the input 'mydata' object to the internal Class
  ! data buffer.
  !---------------------------------------------------------------------
  type(owner_title_version), intent(in)    :: 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 *,'TOCLASS: Unsupported data version ',version
    error = .true.
    return
  endif
  !
  call class_user_datatoclass(mydata%datai4)
  call class_user_datatoclass(mydata%datar4)
  call class_user_datatoclass(mydata%datar8)
  call class_user_datatoclass(mydata%datac4)
  !
end subroutine toclass



Gildas manager 2014-07-01