! Test creation of an Image file from a Type 2000 Midas file
!
! Author:  J. Bauer
!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

  call setDatDir

  call setup_complex_file
  convert ram:testfft blue2img "testmag.png" png IMGOPTS={nc=32,cxmode=mag}
  convert ram:testfft blue2img "testphase.gif" gif IMGOPTS={cxmode=phase}
  convert ram:testfft blue2img "test10log.png" png IMGOPTS={nc=32,cxmode=10log}
  convert ^{datDir}.altitude.prm blue2img "testAlt1.jpg" jpg IMGOPTS={cmap=terrain,nc=32}


  set inst "You should see 8 plots. The plots (of images) on the left side should be identical to the plots (of BLUE files) on the right."

  if interAct then
    pipe on
      panel/msgid=MAIN/setup/controls=gc
      plot/id=altImg "testAlt1.jpg"  axis="~show"
      plot/id=alt ^{datDir}.altitude.prm axis="~show"
      plot/id=magImg testmag.png axis="~show"
      plot/id=magplot ram:testfft cm=mag axis="~show"
      plot/id=phaseImg testphase.gif axis="~show"
      plot/id=phasePlot ram:testfft cm=phase axis="~show" view=yx
      plot/id=logImg test10log.png axis="~show"
      plot/id=logPlot ram:testfft cm=10log axis="~show"

      gcontrol label macro "MACRO"
      gcontrol menu MAIN "Exit with Status = " "PASS,FAIL" /tleft
      set gc.MAIN.itemColors {PASS=GREEN,FAIL=RED}
      gcontrol text   idtext "Instructions" "^inst" 24 10 /title

    pipe off
  endif

  erase/quiet "testAlt1.jpg"
  erase/quiet testmag.png
  erase/quiet test10log.png
  erase/quiet testphase.gif
endmacro


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

  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop

  else
    ! do nothing
    !say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

procedure setup_complex_file

  waveform out=ram:testcx form=cf elem=256
  fft ram:testcx ram:testfft nfft=16

return

!******************************************************************************!
! Set the dat directory
!******************************************************************************!
procedure setDatDir
  invoke nxmMajor env.nmversion.subString(0,1)
  invoke major java.lang.Integer.valueOf(nxmMajor)
  if major GE 4 then
    invoke s:datDir           nxm.sys.test.DatLocator.getDatDirLocation()
    invoke s:datDirSlash      nxm.sys.test.DatLocator.getDatDirSlashLocation()
    invoke z:sysDatFull       nxm.sys.test.DatLocator.sysDatFull()
    invoke z:sysTestDatExists nxm.sys.test.DatLocator.sysTestDatExists()
  else
    set s:datDir           "nxm.sys.dat"
    set s:datDirSlash      "nxm/sys/dat"
    set z:sysDatFull       true
    set z:sysTestDatExists false
  endif
return
