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

Example

When CLASS does not know about the User Subsection, it will not accept to make a custom user selection:

LAS90> FIND /USER
E-USER_SEC_FIND,  No user function for FIND /USER

The following subroutines show basically what should be done by the section owner to allow CLASS such custom selections. Note that this is divided into 2 main steps. The command line parsing is first called. For efficiency, this is done only once at the beginning of the command execution. Then CLASS loops on all the observations in the Input indeX and calls repeatedly the selection subroutine.

subroutine myfind_init
  !----------------------------------------------------------------------
  ! Preliminary declarations
  !----------------------------------------------------------------------
  !
  ! 1) Tell Class who I am
  call class_user_owner('OWNER','TITLE')
  !
  ! 2) Declare my command line parsing subroutine
  call class_user_find(myfind)
  !
  ! 3) Declare my selection subroutine
  call class_user_fix(myfix)
  !
  ! Nothing more: return and wait for Class to execute FIND /USER.
  !
end subroutine myfind_init

subroutine myfind(arg,narg,error)
  use gkernel_interfaces
  use mymod
  !---------------------------------------------------------------------
  ! Hook to command:
  !   LAS\FIND /USER [Arg1] ... [ArgN]
  ! Command line parsing: retrieve the arguments given to the option.
  !---------------------------------------------------------------------
  integer(kind=4),  intent(in)    :: narg       ! Number of arguments
  character(len=*), intent(in)    :: arg(narg)  ! Arguments
  logical,          intent(inout) :: error      ! Logical error flag
  ! Local
  integer(kind=4) :: iarg
  !
  ! Here you have to parse and save the selection criteria given to
  ! the command line. We assume here they are saved in a float array
  ! 'mycriteria' provided by the module 'mymod'
  mycriteria(:) = 0.0  ! Initialization
  !
  do iarg=1,narg
    ! Use Gildas kernel parsing subroutines (convert string to REAL*4)
    call sic_math_real(arg(iarg),len(arg(iarg)),mycriteria(iarg),error)
    if (error)  return
  enddo
  !
end subroutine myfind

subroutine myfix(version,found,error)
  use mymod
  use mytypes
  !---------------------------------------------------------------------
  ! Hook to command:
  !   LAS\FIND /USER
  !  Find or not according the User Subsection contents. Called only if
  ! the observation has a user section and it matches the one
  ! declared here.
  !  NB: 'FIX' stands for "Find in Input indeX"
  !---------------------------------------------------------------------
  integer(kind=4), intent(in)    :: version  ! The version of the data
  logical,         intent(out)   :: found    ! Selected or not selected?
  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
  !
  ! Use the criteria saved in 'myfind' e.g.
  found = mydata%r4.gt.mycriteria(1) .and. mydata%r8.lt.mycriteria(2)
  !
end subroutine myfix

With these routines, CLASS is now able make a custom search in the input index:

MYPROG> find  ! Find everything
I-FIND,  15504 observations found
MYPROG> find /user 1.0 2.0  ! Find with some user selection
I-FIND,  224 observations found
The option /USER can be combined with other selection criteria (e.g. FIND /SOURCE MYSOURCE /USER 1.0); as usual the result is the intersection of all the selections. If FIND /USER is invoked but the User Subsection is absent or is not owned by the program, the observation is not selected to the Current indeX2.



Gildas manager 2014-07-01