! Test ploting type 2000 files with compression (MAX) in the Y-direction. This
! also tests compression when Layer2D is in paging mode (e.g. for large
! data sets).
!
! <numblanklines> - Number of "blank lines" between the significant features.
!                   Controls the number of elements in the file (~4 times this
!                   value), which is the Y-direction or the height of the file.
! <fftsize>       - Controls FFT transform size, which ontrols the width (X-direction).
!
! @bug      1031, 1043
! @author   Neon Ngo
! @version  $Id: test_plot_layer2d_compression.mm,v 1.2 2008/04/09 19:41:45 ntn Exp $
! @since    NeXtMidas 2.5.5
! @see      test_plot_layer2d_view_rendering.mm for testing compression in X-direction
!
startmacro L:numblanklines[3000] L:fftsize[256]
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch LPB         lpb      GET DEF=128

  set fftfile  test_compression_fft_testfile.tmp
  set numlines 1
  set color green
  set yposmul numblanklines*fftsize
  ! x specifies the frequency for each line that should show up
  set T:feat {F1={NAME=F1,TYPE=|CIRC|,X=0.1,Y=^yposmul*1,DX=0.05,COLOR=^color},&
              F2={NAME=F2,TYPE=|CIRC|,X=0.2,Y=^yposmul*2,DX=0.05,COLOR=^color},&
              F3={NAME=F3,TYPE=|CIRC|,X=0.3,Y=^yposmul*3,DX=0.05,COLOR=^color},&
              F4={NAME=F4,TYPE=|CIRC|,X=0.4,Y=^yposmul*4,DX=0.05,COLOR=^color},&
             }

  if interAct then
    call createTestFile feat
    ! status ^fftfile

    res inst "There should be data (short colored line) shown within the four &
              circles on each of the plots. The colored lines should be horizontal &
              in the Y vs X plots (on left), and vertical on the X vs Y plots (on &
              right). This shows that MAX COMPRESSION is working in the Y-direction."
 
    pipe on
      panel/controls=gc/setup

      plot/id=plot1 fftfile{layer={compression=MAX}} features=feat z1=0.0 z2=0.5 view=iYX /lpb=lpb /all
      plot/id=plot2 fftfile{layer={compression=MAX}} features=feat z1=0.0 z2=0.5 view=XY /lpb=lpb /all

      ! force paged mode on these plots by setting /LPS to be smaller than number elements in data file
      plot/id=plot3 fftfile{layer={compression=MAX}} features=feat z1=0.0 z2=0.5 view=iYiX /lps=lpb /lpb=lpb /all
      plot/id=plot4 fftfile{layer={compression=MAX}} features=feat z1=0.0 z2=0.5 view=iXY /lps=lpb /lpb=lpb /all

      gcontrol label mainLabel "Main" AlwaysOpen
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      gcontrol text idtext "Instructions" "^inst" 24 14 /title
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}

    pipe off

    ! cleanup
    erase/warn=off ^fftfile

  endif
endmacro

!**************************************************************************************************!
procedure processMessage
  !say "msg.name ^msg.name, data ^msg.data"

  if msg.name eqs "MAIN" then
     assert/text="Layer2D raster plot compression" msg.data eqss "PASS"
    pipe stop
  else
    say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif

return


! create test data for y compression that with lots of blank rows (zerofile)
! followed by a few rows of data at specified frequencies that matches that
! freq in the feature table (eg. file1=feat.f1.x, etc.)
procedure createTestFile
  set zerofile test_compression_zerofile
  set file1    test_compression_file1
  set file2    test_compression_file2
  set file3    test_compression_file3
  set file4    test_compression_file4
  set testfile test_compression_testfile.tmp
  set nels0    fftsize*numblanklines
  set nels     fftsize*numlines

  wave out=^zerofile form=sf elem=nels0 shape=const amp=0
  wave out=^file1    form=sf elem=nels  shape=sin   freq=feat.f1.x
  wave out=^file2    form=sf elem=nels  shape=sin   freq=feat.f2.x
  wave out=^file3    form=sf elem=nels  shape=sin   freq=feat.f3.x
  wave out=^file4    form=sf elem=nels  shape=sin   freq=feat.f4.x

  ! make sure we have a clean test file for merges
  erase/warn=off ^testfile
  merge ^zerofile ^testfile

  merge ^file1    ^testfile
  merge ^zerofile ^testfile

  merge ^file2    ^testfile
  merge ^zerofile ^testfile

  merge ^file3    ^testfile
  merge ^zerofile ^testfile

  merge ^file4    ^testfile
  merge ^zerofile ^testfile

  fft IN1=^testfile OUT1=^fftfile NFFT=^fftsize WIN=None

  ! cleanup temp files
  erase/warn=off ^zerofile ^file1 ^file2 ^file3 ^file4 ^testfile
return
