!
! Author : Jay Hallam
! Version: $Id: test_demux.mm,v 1.2 2006/10/09 14:41:12 jph Exp $
!
!  Macro for testing the DEMUX command
!
!  Dependencies:
!      WAVEFORM
!
startmacro

  call test_float_data
  call test_double_data

endmacro

!******************************************************************************!
procedure test_float_data S:format

  set inputFile  "test_demux_float{AUX=RAM}"
  set tempOutReal "test_demux_out_float_r{AUX=RAM}"
  set tempOutImag "test_demux_out_float_i{AUX=RAM}"
  waveform OUT=inputFile FORM=CF ELEM=10

  if inputFile NFEXISTS then
    assert/text="^reg.main.name: WAVEFORM failed to create test input file" 1 EQ 2
    return
  endif

  demux inputFile tempOutReal tempOutImag
  set L:inputSize  FILE(inputFile).getSize()
  set L:outputSize FILE(tempOutReal).size
  assert/text="^reg.main.name: FLOAT file size"/stat=tempStatus outputSize EQ inputSize

  if tempStatus isTRUE then
    set dataIsValid "TRUE"
    file open tag inputFile
      do i 0 inputSize-
        set cnum tag.data(i)
        set outReal FILE(tempOutReal).data(i)
        set outImag FILE(tempOutImag).data(i)
        if outReal NEQ cnum.r OR outImag NEQ cnum.i then
          set dataIsValid "FALSE"
        endif
      enddo
    file close tag
    assert/text="^reg.main.name: FLOAT data is the same" dataIsValid

  else
    warning "^reg.main.name: bypassed some tests"
  endif
return

!******************************************************************************!
procedure test_double_data
  set inputFile "test_demux_double{AUX=RAM}"
  set tempOutReal "test_demux_out_double_r{AUX=RAM}"
  set tempOutImag "test_demux_out_double_i{AUX=RAM}"
  waveform OUT=inputFile FORM=CD ELEM=10 
  if inputFile NFEXISTS then
    assert/text="^reg.main.name: WAVEFORM failed to create test input file" 1 EQ 2
    return
  endif
  demux inputFile tempOutReal tempOutImag

  set L:inputSize  FILE(inputFile).getSize()
  set L:outputSize FILE(tempOutReal).size
  assert/text="^reg.main.name: DOUBLE file size"/stat=tempStatus outputSize EQ inputSize
 if tempStatus isTRUE then
   set dataIsValid "TRUE"
   file open tag inputFile
     do i 0 inputSize-
       set cnum tag.data(i)
       set outReal FILE(tempOutReal).data(i)
       set outImag FILE(tempOutImag).data(i)
       if outReal NEQ cnum.r OR outImag NEQ cnum.i then
         set dataIsValid "FALSE"
       endif
     enddo
   file close tag
   assert/text="^reg.main.name: DOUBLE data is the same" dataIsValid

  else
    warning "^reg.main.name: bypassed some tests"
  endif
return
