begin data gag_scratch:repro.auto
TASK\FILE "Input file" Z_NAME$ 'mytrepro%z_name'
TASK\FILE "Output file" X_NAME$ 'mytrepro%x_name'
TASK\LOGICAL "Reproject on a third file's projection [YES|NO]" TEMPLATE$ 'mytrepro%template'
TASK\FILE "This Template File Name" Y_NAME$ 'mytrepro%y_name'
TASK\CHARACTER "Projection type" PROJECTION$ 'mytrepro%projection'
TASK\CHARACTER "Coord.System [EQUATORIAL [epoch]|GALACTIC|UNCHANGED]" SYSTEM$ 'mytrepro%system'
TASK\CHARACTER "Coord. 1 of projection center. Could be UNCHANGED" CENTER_1$ 'mytrepro%center_1'
TASK\CHARACTER "Coord. 2 of projection center" CENTER_2$ 'mytrepro%center_2'
TASK\REAL "Position angle of projection" ANGLE$ 'mytrepro%angle'                                    mytrepro%dimensions
TASK\INTEGER "Dimensions of output image [0 0 mean guess]" DIMENSIONS$[2] 'mytrepro%dimensions[1]' 'mytrepro%dimensions[2]'
TASK\REAL "First axis conversion formula [0 0 0 mean guess]" AXIS_1$[3] 'mytrepro%axis_1[1]' 'mytrepro%axis_1[2]' 'mytrepro%axis_1[3]'
TASK\REAL "Second axis conversion formula [0 0 0 mean guess]" AXIS_2$[3] 'mytrepro%axis_2[1]' 'mytrepro%axis_2[2]' 'mytrepro%axis_2[3]'
TASK\LOGICAL "Change blanking value" CHANGE$ 'mytrepro%change' 
TASK\REAL "New blanking value and tolerance" BLANKING$ 'mytrepro%blanking[1]' 'mytrepro%blanking[2]'
TASK\GO
end data gag_scratch:repro.auto
!
begin procedure demo-repro-task-init
   if (.not.exist(mytrepro)) then 
      define structure mytrepro /global
      define character*256 mytrepro%z_name mytrepro%x_name mytrepro%y_name /global
      define character*24 mytrepro%projection mytrepro%system mytrepro%center_1 mytrepro%center_2 /global
      define real mytrepro%angle mytrepro%axis_1[3] mytrepro%axis_2[3] mytrepro%blanking[2] /global
      define integer mytrepro%dimensions[2] /global
      define logical mytrepro%template mytrepro%change /global
   endif
   !
   let mytrepro%z_name raw/c18o10-s1-fts.lmv
   let mytrepro%x_name task-repro-out.lmv
   let mytrepro%template no
   let mytrepro%y_name ""
   let mytrepro%projection UNCHANGED
   let mytrepro%system UNCHANGED
   let mytrepro%center_1 UNCHANGED
   let mytrepro%center_2 UNCHANGED
   let mytrepro%angle 0
   let mytrepro%dimensions 0
   let mytrepro%axis_1 0
   let mytrepro%axis_2 0
   let mytrepro%change no
   let mytrepro%blanking 0
end procedure demo-repro-task-init
!
begin procedure demo-repro-task-destroy
   if (exist(mytrepro)) then
      delete /var mytrepro
   end if
end procedure demo-repro-task-destroy
!
begin procedure demo-repro-init
   if (exist(myrepro)) delete /var myrepro
   !
   define structure myrepro /global
   define character*512 myrepro%cline /global
   define character*128 myrepro%fname /global
   define character*256 myrepro%opt /global
   define character*64 myrepro%cbase myrepro%ddir /global
   define character*64 myrepro%fdemo /global
   define logical myrepro%trace myrepro%info myrepro%pause /global
   define integer myrepro%ntest /global
   !
   @ demo-repro-init-tests
   !
   let myrepro%cbase "cube\reproject "
   ! VVV this is where we should do the test for the existence of the
   ! file and wget when necessary.
   let myrepro%fname "c18o10-s1-fts"
   let myrepro%trace no
   let myrepro%info no
   let myrepro%pause no
   let myrepro%ddir "demo-repro"
   let myrepro%fdemo "centaurus-3d.gdf"
   !
   on error pause
   sic message cube s-i
   sic message cube s-t
   !
end procedure demo-repro-init
!
begin procedure demo-repro-init-tests
   !
   let myrepro%ntest 10 ! Add more tests here 
   !
   define character*256 myrepro%test[myrepro%ntest] /global
   define character*64 myrepro%ref[myrepro%ntest] /global
   !
   for itest 1 to myrepro%ntest
      let myrepro%ref[itest] "repro-demo-t"'itest'".gdf"
   next itest
   !
   ! RA  = 13:22:24.00000      DEC = -42:45:00.0000
   ! LII = -50.50723644680070  BII = 19.42957151969227
   !
   let myrepro%test[1] "/system galactic"
   let myrepro%test[2] "/system equatorial 1950"
   let myrepro%test[3] "/system equatorial 2000"
   let myrepro%test[4] "/proj gnomonic"
   let myrepro%test[5] "/proj = 13:32:24.00000 ="
   let myrepro%test[6] "/proj = = -42:55:00.0000"
   let myrepro%test[7] "/proj = 13:32:24.00000 -42:55:00.0000"
   let myrepro%test[8] "/proj gnomonic 13:32:24.00000 -42:55:00.0000"
   let myrepro%test[9] "/proj gnomonic 13:32:24.00000 -42:55:00.0000 45"
   let myrepro%test[10] "/proj = -50.00723644680070 19.52957151969227 /system galactic"
   !
end procedure demo-repro-init-tests
!
begin procedure demo-repro-destroy
   if (exist(myrepro)) then
      delete /var myrepro
   end if
   @ demo-repro-task-destroy
end procedure demo-repro-destroy
!
begin procedure demo-repro-status
   say ""
   say "Trace: "'myrepro%trace' "Info: "'myrepro%info'
   say "Pause after each sub-test: "'myrepro%pause'
   say ""
end procedure demo-repro-status
!
begin procedure demo-repro-welcome
   say "************************************************************"
   say ""
   say "Welcome to the Reproject demo!"
   say ""
   say "************************************************************"
end procedure demo-repro-welcome
!
begin procedure demo-repro-main
   @ demo-repro-init
   @ demo-repro-welcome
   !
   @ demo-repro-mainloop
   !
   @ demo-repro-destroy
   return base
end procedure demo-repro-main
!
begin procedure demo-repro-mainloop
   define logical continue
   define integer choice
   let continue yes
   for /while continue
      @ demo-repro-status
      say "What do you want to do?"
      say ""
      say " 1: Change verbosity or behaviour"
      say " 2: Acceleration curve"
      say " 3: Comparison with reproject task"
      say " 4: Demo tests"
      say "-1: Cube command line"
      say " 0: Exit"
      say ""
      !
      let choice
      say ""
      !
      if (choice.eq.0) then
         let continue no
      else if (choice.eq.1) then
         @ demo-repro-control
      else if (choice.eq.2) then
         @ demo-repro-accel
      else if (choice.eq.3) then
         @ demo-repro-task-comp
      else if (choice.eq.4) then
         @ demo-repro-demo-main
      else if (choice.eq.-1) then
         @ demo-repro-tosic
      else
         say "Unrecognized option: "'choice'
      endif
   next ! while
end procedure demo-repro-mainloop
!
begin procedure demo-repro-control
   say ""
   say "Do you want to be shown trace messages? (yes|no)"
   let myrepro%trace
   say ""
   say "Do you want to be shown Info messages? (yes|no)"
   let myrepro%info
   say ""
   say "Do you want to pause after each sub-test? (yes|no)"
   let myrepro%pause
   say ""
   !
   if (myrepro%trace) then
      sic message cube s+t
   else
      sic message cube s-t
   endif
   if (myrepro%info) then
      sic message cube s+i
   else
      sic message cube s-i
   endif
   !
end procedure demo-repro-control
!
begin procedure demo-repro-tosic
   say ""
   say "************************************************************"
   say ""
   say "Using pause to access SIC prompt"
   say "Type continue to come back to the DEMO"
   say ""
   say "************************************************************"
   say ""
   pause
end procedure demo-repro-tosic
!
begin procedure demo-repro-task-comp
   !
   say ""
   say "************************************************************"
   say ""
   !
   ! Change system to galactic
   @ demo-repro-task-init
   let mytrepro%system GALACTIC
   let myrepro%opt "/system galactic"
   @ demo-repro-taskvscomm
   if (myrepro%pause) pause
   !
   ! Change System epoch
   @ demo-repro-task-init
   let mytrepro%system "EQUATORIAL 1950"
   let myrepro%opt "/system equatorial 1950"
   @ demo-repro-taskvscomm
   if (myrepro%pause) pause
   !
   ! No changes actually
   @ demo-repro-task-init
   let mytrepro%system "EQUATORIAL 2000"
   let myrepro%opt "/system equatorial 2000"
   @ demo-repro-taskvscomm
   if (myrepro%pause) pause
   !
   ! Change projection to gnomonic
   @ demo-repro-task-init
   let mytrepro%projection gnomonic
   let myrepro%opt "/proj gnomonic"
   @ demo-repro-taskvscomm
   if (myrepro%pause) pause
   !
   ! Orig:
   ! RA  = 05:40:54.27000      DEC = -02:28:00.0000
   ! LII = 206.9543524549399   BII = -16.79642919591265
   !
   ! 10 hour minutes to the east
   @ demo-repro-task-init
   let mytrepro%center_1 05:30:54.27000
   let myrepro%opt "/proj = 05:30:54.27000 ="
   @ demo-repro-taskvscomm
   if (myrepro%pause) pause
   !
   ! 10 arcminutes to the south
   @ demo-repro-task-init
   let mytrepro%center_2 -02:38:00.0000
   let myrepro%opt "/proj = = -02:38:00.0000"
   @ demo-repro-taskvscomm
   if (myrepro%pause) pause
   !
   ! 10 arcminutes to the south and 10 hour minutes to the east
   @ demo-repro-task-init
   let mytrepro%center_1 05:30:54.27000
   let mytrepro%center_2 -02:38:00.0000
   let myrepro%opt "/proj = 05:30:54.27000 -02:38:00.0000"
   @ demo-repro-taskvscomm
   if (myrepro%pause) pause
   !
   ! 10 arcminutes to the south and 10 hour minutes to the east
   ! Also change projection
   @ demo-repro-task-init
   let mytrepro%projection gnomonic
   let mytrepro%center_1 05:30:54.27000
   let mytrepro%center_2 -02:38:00.0000
   let myrepro%opt "/proj gnomonic 05:30:54.27000 -02:38:00.0000"
   @ demo-repro-taskvscomm
   if (myrepro%pause) pause
   !
   ! 10 arcminutes to the south and 10 hour minutes to the east
   ! Also change projection and position angle
   @ demo-repro-task-init
   let mytrepro%projection gnomonic
   let mytrepro%center_1 05:30:54.27000
   let mytrepro%center_2 -02:38:00.0000
   let mytrepro%angle 45
   let myrepro%opt "/proj gnomonic 05:30:54.27000 -02:38:00.0000 45"
   @ demo-repro-taskvscomm
   if (myrepro%pause) pause
   !
   ! Change position by 30 arcminutes in both directions and system to galactic
   @ demo-repro-task-init
   let mytrepro%system GALACTIC
   let mytrepro%center_1 206.4543524549399
   let mytrepro%center_2 -16.29642919591265
   let myrepro%opt "/proj = 206.4543524549399 -16.29642919591265 /system galactic"
   @ demo-repro-taskvscomm
   if (myrepro%pause) pause
   !
end procedure demo-repro-task-comp
!
begin procedure demo-repro-taskvscomm
   define real tcomm ttask
   let myrepro%cline 'myrepro%cbase'" "'myrepro%fname'" "'myrepro%opt'
   sic cpu
   say ""
   say "Running Reproject task"
   say ""
   run reproject gag_scratch:repro.auto /nowindow
   sic cpu
   let ttask SIC%CPU%RAW%ELAPSED
   sic cpu
   say ""
   say "Running CUBE\REPROJECT"
   say ""
   sic\execute 'myrepro%cline'
   sic cpu
   let tcomm SIC%CPU%RAW%ELAPSED
   header tmp/c18o10-s1-fts-reproject.lmv /extrema
   header task-repro-out.lmv /extrema
   say ""
   say "************************************************************"
   say ""
   say "Execution times:"
   say "task = "'ttask'" s, comm = "'tcomm'" s"
   say ""
   say "diff for:"
   say 'myrepro%cline'
   diff tmp/c18o10-s1-fts-reproject.lmv task-repro-out.lmv
   say ""
   say "************************************************************"
   say ""
end procedure demo-repro-taskvscomm
!
begin procedure demo-repro-accel
   @ p_accel "cube\reproject "'myrepro%fname'" /proj = 206.4543524549399 -16.29642919591265 /system galactic"
end procedure demo-repro-accel
!
begin procedure demo-repro-fetchdemodata
   sic find 'myrepro%ddir'
   if (dir%nfile.eq.0) then ! Directory does not exist
      sic mkdir 'demo-repro'
   endif
   !
   !VVV Right now this is only a copy of the initial file. Later on
   !this will be a fetch of the initial file plus the reference
   !result files.
   !
   !sic copy gag_demo:'myrepro%fdemo' 'myrepro%ddir'/
   !
end procedure demo-repro-fetchdemodata
!
begin procedure demo-repro-dodemo
   directory raw 'myrepro%ddir'
   directory tmp 'myrepro%ddir'
   !
   for itest 1 to myrepro%ntest
      @ demo-repro-demotest 'itest'
   next itest
   !
end procedure demo-repro-dodemo
!
begin procedure demo-repro-demotest
   define integer test
   let test &1
   let myrepro%cline 'myrepro%cbase'" "'myrepro%fdemo'" "'myrepro%test[test]'
   !
   say ""
   say "************************************************************"
   say ""
   say "Executing test: "'test'
   say ""
   !
   sic\execute 'myrepro%cline'
   !
   say "Diff for test: "'test'
   diff 'myrepro%ddir'/'myrepro%fdemo'-reproject 'myrepro%ddir'/'myrepro%ref[test]'
   ! VVV Should stop here if test not successful with error message
   say ""
   say "************************************************************"
   say ""
end procedure demo-repro-demotest
!
begin procedure demo-repro-demo-main
   @ demo-repro-fetchdemodata
   @ demo-repro-dodemo
end procedure demo-repro-demo-main
!
@ demo-repro-main
!
