MJ = cd ~/research.ln/Source/Oneway/; make $(bin)/joint_encode.x ; cd 
#norne-flat-%:
#	$(mj)
#	./flat.py \
#		/data/sep/goayeni/workspace/norne-me-hx-$*/modl/norne-me-hx-$*-ang.H \
		shift-ang.p \
		$@
 
#Test Flatten gather
norne-flat:
	cd ~/research.ln/Source/Oneway/; make $(bin)/joint_encode.x ; cd 
	Window3d squeeze=n min1=1500  n1=501 min2=0 n2= 21 < /data/sep/goayeni/workspace/norne-me-hx-06-2759/modl/norne-me-hx-06-2759-ang.H > junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13  > mod-flat-1.H 
	$B/joint_encode.x report=$@.log modl=mod-flat-1.H  \
		modl1=mod-flat-1.H rm1=mod-flat-1.H  smodl1=mod-flat-1-s.H ts1=mod-flat-1-ts.H sd1=mod-flat-tsd1.H cc1=mod-flat-cc1.H rr1=mod-flat-rr1.H \
        	nmix=1 par=shift-ang.p nmix=5 nodes=1 shift_nodes=1 lflat=y
	touch $@
norne-flat2:
	cd ~/research.ln/Source/Oneway/; make $(bin)/joint_encode.x ; cd 
	Window3d squeeze=n min1=1500  n1=501 min2=0 n2= 21 < /data/sep/goayeni/workspace/norne-flat/norne-flat-06-2759/test-model-pri6-06.H > junk$@.H ; Transp plane=13 reshape=2,3,4 < junk$@.H | Transp > mod-flat2-1.H 
	$B/joint_encode.x report=$@.log modl=mod-flat2-1.H  \
		modl1=mod-flat2-1.H rm1=mod-flat2-1.H  smodl1=mod-flat2-1-s.H ts1=mod-flat2-1-ts.H sd1=mod-flat2-tsd1.H cc1=mod-flat2-cc1.H rr1=mod-flat2-rr1.H \
        	nmix=1 par=shift-ang.p nmix=7 nodes=1 shift_nodes=1 lflat=y

# ADCIG Flatten after multiple suppression
norne-flat-negpos-06-%:
	$(MJ)
	#+ve
	Window3d squeeze=n min2=0  < norne-negpos-$*-afmult-06.H 	       		> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-pos.H 
	Window3d squeeze=n min2=0  < norne-pos-pri-$*-06.H 				> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-pos-rm.H 
	$B/joint_encode.x report=$@.log modl=$@-pos.H  \
		modl1=$@-pos.H rm1=$@-pos-rm.H  smodl1=$@-pos-s.H ts1=$@-pos-ts.H sd1=mod-flat-tsd1.H cc1=mod-flat-cc1.H rr1=mod-flat-rr1.H \
        	nmix=1 par=flat-ang.p nmix=5 nodes=1 shift_nodes=1 lflat=y &
	#-ve
	Window3d squeeze=n n2=61   < norne-negpos-$*-afmult-06.H | Reverse which=2       	> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-neg.H
	Window3d squeeze=n n2=61   < norne-neg-pri-$*-06.H       | Reverse which=2       	> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-neg-rm.H 
	$B/joint_encode.x report=$@.log modl=$@-neg.H  \
		modl1=$@-neg.H rm1=$@-neg-rm.H  smodl1=$@-neg-s.H ts1=$@-neg-ts.H sd1=mod-flat-tsd1.H cc1=mod-flat-cc1.H rr1=mod-flat-rr1.H \
        	nmix=1 par=flat-ang.p nmix=5 nodes=1 shift_nodes=1 lflat=y 
	touch $@
	Window3d n4=1 n6=61 	 < $@-neg-ts.H | Transp reshape=1,3 | Reverse which=2 	  > $@-tmp1-ts.H 
	Window3d n4=1 n6=60 f6=1 < $@-pos-ts.H | Transp reshape=1,3 			  > $@-tmp2-ts.H 
	Cat3d $@-tmp1-ts.H $@-tmp2-ts.H axis=2 > $@-ts.H
	Transp plane=24 < $@-neg-s.H | Window3d n2=61      | Transp plane=13 | Reverse which=2 > $@-tmp1.H
	Transp plane=24 < $@-pos-s.H | Window3d n2=60 f2=1 | Transp plane=13 	   	       > $@-tmp2.H
	Cat3d $@-tmp1.H $@-tmp2.H axis=2 > $@-s.H

norne-hole-flat-negpos-06-%:
	$(MJ)
	#+ve
	Window3d squeeze=n min2=0  < norne-hole-negpos-$*-afmult-06.H 	       			> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-pos.H 
	Window3d squeeze=n min2=0  < norne-hole-pos-pri-$*-06.H 				> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-pos-rm.H 
	$B/joint_encode.x report=$@.log modl=$@-pos.H  \
		modl1=$@-pos.H rm1=$@-pos-rm.H  smodl1=$@-pos-s.H ts1=$@-pos-ts.H sd1=mod-flat-tsd1.H cc1=mod-flat-cc1.H rr1=mod-flat-rr1.H \
        	nmix=1 par=flat-ang.p nmix=5 nodes=1 shift_nodes=1 lflat=y &
	#-ve
	Window3d squeeze=n n2=61   < norne-hole-negpos-$*-afmult-06.H | Reverse which=2       	> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-neg.H
	Window3d squeeze=n n2=61   < norne-hole-neg-pri-$*-06.H       | Reverse which=2       	> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-neg-rm.H 
	$B/joint_encode.x report=$@.log modl=$@-neg.H  \
		modl1=$@-neg.H rm1=$@-neg-rm.H  smodl1=$@-neg-s.H ts1=$@-neg-ts.H sd1=mod-flat-tsd1.H cc1=mod-flat-cc1.H rr1=mod-flat-rr1.H \
        	nmix=1 par=flat-ang.p nmix=5 nodes=1 shift_nodes=1 lflat=y 
	touch $@
	Window3d n4=1 n6=61 	 < $@-neg-ts.H | Transp reshape=1,3 | Reverse which=2 	  > $@-tmp1-ts.H 
	Window3d n4=1 n6=60 f6=1 < $@-pos-ts.H | Transp reshape=1,3 			  > $@-tmp2-ts.H 
	Cat3d $@-tmp1-ts.H $@-tmp2-ts.H axis=2 > $@-ts.H
	Transp plane=24 < $@-neg-s.H | Window3d n2=61      | Transp plane=13 | Reverse which=2 > $@-tmp1.H
	Transp plane=24 < $@-pos-s.H | Window3d n2=60 f2=1 | Transp plane=13 	   	       > $@-tmp2.H
	Cat3d $@-tmp1.H $@-tmp2.H axis=2 > $@-s.H

norne-hole-sxgx-flat-negpos-06-%:
	$(MJ)
	#+ve
	Window3d squeeze=n min2=0  < norne-hole-sxgx-negpos-$*-afmult-06.H 	       			> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-pos.H 
	Window3d squeeze=n min2=0  < norne-hole-sxgx-pos-pri-$*-06.H 				> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-pos-rm.H 
	$B/joint_encode.x report=$@.log modl=$@-pos.H  \
		modl1=$@-pos.H rm1=$@-pos-rm.H  smodl1=$@-pos-s.H ts1=$@-pos-ts.H sd1=mod-flat-tsd1.H cc1=mod-flat-cc1.H rr1=mod-flat-rr1.H \
        	nmix=1 par=flat-ang.p nmix=5 nodes=1 shift_nodes=1 lflat=y &
	#-ve
	Window3d squeeze=n n2=61   < norne-hole-sxgx-negpos-$*-afmult-06.H | Reverse which=2       	> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-neg.H
	Window3d squeeze=n n2=61   < norne-hole-sxgx-neg-pri-$*-06.H       | Reverse which=2       	> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-neg-rm.H 
	$B/joint_encode.x report=$@.log modl=$@-neg.H  \
		modl1=$@-neg.H rm1=$@-neg-rm.H  smodl1=$@-neg-s.H ts1=$@-neg-ts.H sd1=mod-flat-tsd1.H cc1=mod-flat-cc1.H rr1=mod-flat-rr1.H \
        	nmix=1 par=flat-ang.p nmix=5 nodes=1 shift_nodes=1 lflat=y 
	touch $@
	Window3d n4=1 n6=61 	 < $@-neg-ts.H | Transp reshape=1,3 | Reverse which=2 	  > $@-tmp1-ts.H 
	Window3d n4=1 n6=60 f6=1 < $@-pos-ts.H | Transp reshape=1,3 			  > $@-tmp2-ts.H 
	Cat3d $@-tmp1-ts.H $@-tmp2-ts.H axis=2 > $@-ts.H
	Transp plane=24 < $@-neg-s.H | Window3d n2=61      | Transp plane=13 | Reverse which=2 > $@-tmp1.H
	Transp plane=24 < $@-pos-s.H | Window3d n2=60 f2=1 | Transp plane=13 	   	       > $@-tmp2.H
	Cat3d $@-tmp1.H $@-tmp2.H axis=2 > $@-s.H

norne-grad-flat-negpos-06-%:
	$(MJ)
	#+ve
	Window3d squeeze=n min2=0  < norne-grad-negpos-$*-afmult-06.H 	       			> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-pos.H 
	Window3d squeeze=n min2=0  < norne-grad-pos-pri-$*-06.H 				> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-pos-rm.H 
	$B/joint_encode.x report=$@.log modl=$@-pos.H  \
		modl1=$@-pos.H rm1=$@-pos-rm.H  smodl1=$@-pos-s.H ts1=$@-pos-ts.H sd1=mod-flat-tsd1.H cc1=mod-flat-cc1.H rr1=mod-flat-rr1.H \
        	nmix=1 par=flat-ang.p nmix=5 nodes=1 shift_nodes=1 lflat=y &
	#-ve
	Window3d squeeze=n n2=61   < norne-grad-negpos-$*-afmult-06.H | Reverse which=2       	> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-neg.H
	Window3d squeeze=n n2=61   < norne-grad-neg-pri-$*-06.H       | Reverse which=2       	> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-neg-rm.H 
	$B/joint_encode.x report=$@.log modl=$@-neg.H  \
		modl1=$@-neg.H rm1=$@-neg-rm.H  smodl1=$@-neg-s.H ts1=$@-neg-ts.H sd1=mod-flat-tsd1.H cc1=mod-flat-cc1.H rr1=mod-flat-rr1.H \
        	nmix=1 par=flat-ang.p nmix=5 nodes=1 shift_nodes=1 lflat=y 
	touch $@
	Window3d n4=1 n6=61 	 < $@-neg-ts.H | Transp reshape=1,3 | Reverse which=2 	  > $@-tmp1-ts.H 
	Window3d n4=1 n6=60 f6=1 < $@-pos-ts.H | Transp reshape=1,3 			  > $@-tmp2-ts.H 
	Cat3d $@-tmp1-ts.H $@-tmp2-ts.H axis=2 > $@-ts.H
	Transp plane=24 < $@-neg-s.H | Window3d n2=61      | Transp plane=13 | Reverse which=2 > $@-tmp1.H
	Transp plane=24 < $@-pos-s.H | Window3d n2=60 f2=1 | Transp plane=13 	   	       > $@-tmp2.H
	Cat3d $@-tmp1.H $@-tmp2.H axis=2 > $@-s.H
norne-hole-sxgx-grad-flat-negpos-06-%:
	$(MJ)
	#+ve
	Window3d squeeze=n min2=0  < norne-hole-sxgx-grad-negpos-$*-afmult-06.H 	       			> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-pos.H 
	Window3d squeeze=n min2=0  < norne-hole-sxgx-grad-pos-pri-$*-06.H 				> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-pos-rm.H 
	$B/joint_encode.x report=$@.log modl=$@-pos.H  \
		modl1=$@-pos.H rm1=$@-pos-rm.H  smodl1=$@-pos-s.H ts1=$@-pos-ts.H sd1=mod-flat-tsd1.H cc1=mod-flat-cc1.H rr1=mod-flat-rr1.H \
        	nmix=1 par=flat-ang.p nmix=5 nodes=1 shift_nodes=1 lflat=y &
	#-ve
	Window3d squeeze=n n2=61   < norne-hole-sxgx-grad-negpos-$*-afmult-06.H | Reverse which=2       	> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-neg.H
	Window3d squeeze=n n2=61   < norne-hole-sxgx-grad-neg-pri-$*-06.H       | Reverse which=2       	> junk$@.H ; < junk$@.H Transp reshape=2,3,4 plane=13 | Transp   > $@-neg-rm.H 
	$B/joint_encode.x report=$@.log modl=$@-neg.H  \
		modl1=$@-neg.H rm1=$@-neg-rm.H  smodl1=$@-neg-s.H ts1=$@-neg-ts.H sd1=mod-flat-tsd1.H cc1=mod-flat-cc1.H rr1=mod-flat-rr1.H \
        	nmix=1 par=flat-ang.p nmix=5 nodes=1 shift_nodes=1 lflat=y 
	touch $@
	Window3d n4=1 n6=61 	 < $@-neg-ts.H | Transp reshape=1,3 | Reverse which=2 	  > $@-tmp1-ts.H 
	Window3d n4=1 n6=60 f6=1 < $@-pos-ts.H | Transp reshape=1,3 			  > $@-tmp2-ts.H 
	Cat3d $@-tmp1-ts.H $@-tmp2-ts.H axis=2 > $@-ts.H
	Transp plane=24 < $@-neg-s.H | Window3d n2=61      | Transp plane=13 | Reverse which=2 > $@-tmp1.H
	Transp plane=24 < $@-pos-s.H | Window3d n2=60 f2=1 | Transp plane=13 	   	       > $@-tmp2.H
	Cat3d $@-tmp1.H $@-tmp2.H axis=2 > $@-s.H
#flat all
flat-negpos-%:
	#make norne-flat-negpos-06-$* &  
	#make norne-hole-flat-negpos-06-$* & 
	#make norne-hole-sxgx-flat-negpos-06-$* 
	make norne-hole-sxgx-grad-flat-negpos-06-$* 

# ADCIG Warp after multiple suppression + Flatten
norne-flat-warp-%:
	$(MJ)
	Window3d squeeze= n f2= 0 n2= 11 j1= 2 n1= 320 n4= 100 j2= 2 j3= 2 < norne-flat-negpos-06-$*-s.H > junk$@.H ; < junk$@.H Transp plane=13  > $@-06.H 
	Window3d squeeze= n f2= 0 n2= 11 j1= 2 n1= 320 n4= 100 j2= 2 j3= 2 < norne-negpos-$*-afmult-08.H > junk$@.H ; < junk$@.H Transp plane=13  > $@-08.H 
	$B/joint_encode.x report=$@.log modl=$@-06.H  \
		modl1=$@-06.H rm1=$@-06.H  smodl1=$@-06-s.H .H ts1=$@-06-ts.H 2.H sd1=$@-06-tsd.H .H cc1=$@-06-cc.H H rr1=$@-06-rr.H  \
		modl2=$@-08.H rm2=$@-08.H  smodl2=$@-08-s.H .H ts2=$@-08-ts.H 2.H sd2=$@-08-tsd.H .H cc2=$@-08-cc.H H rr2=$@-08-rr.H  \
        	nmix=1 par=warp-ang.P nmix=7 nodes=1 shift_nodes=1 verb=8
	touch $@
norne-hole-flat-warp-%:
	$(MJ)
	Window3d squeeze= n f2= 0 n2= 11 j1= 2 n1= 320 n4= 100 j2= 2 j3= 2 < norne-hole-flat-negpos-06-$*-s.H > junk$@.H ; < junk$@.H Transp plane=13  > $@-06.H 
	Window3d squeeze= n f2= 0 n2= 11 j1= 2 n1= 320 n4= 100 j2= 2 j3= 2 < norne-hole-negpos-$*-afmult-08.H > junk$@.H ; < junk$@.H Transp plane=13  > $@-08.H 
	$B/joint_encode.x report=$@.log modl=$@-06.H  \
		modl1=$@-06.H rm1=$@-06.H  smodl1=$@-06-s.H .H ts1=$@-06-ts.H 2.H sd1=$@-06-tsd.H .H cc1=$@-06-cc.H H rr1=$@-06-rr.H  \
		modl2=$@-08.H rm2=$@-08.H  smodl2=$@-08-s.H .H ts2=$@-08-ts.H 2.H sd2=$@-08-tsd.H .H cc2=$@-08-cc.H H rr2=$@-08-rr.H  \
        	nmix=1 par=warp-ang.P nmix=7 nodes=1 shift_nodes=1 verb=8 &
	touch $@
norne-grad-flat-warp-%:
	$(MJ)
	Window3d squeeze= n f2= 0 n2= 11 j1= 2 n1= 320 n4= 100 j2= 2 j3= 2 < norne-grad-flat-negpos-06-$*-s.H > junk$@.H ; < junk$@.H Transp plane=13  > $@-06.H 
	Window3d squeeze= n f2= 0 n2= 11 j1= 2 n1= 320 n4= 100 j2= 2 j3= 2 < norne-grad-negpos-$*-afmult-08.H > junk$@.H ; < junk$@.H Transp plane=13  > $@-08.H 
	$B/joint_encode.x report=$@.log modl=$@-06.H  \
		modl1=$@-06.H rm1=$@-06.H  smodl1=$@-06-s.H .H ts1=$@-06-ts.H 2.H sd1=$@-06-tsd.H .H cc1=$@-06-cc.H H rr1=$@-06-rr.H  \
		modl2=$@-08.H rm2=$@-08.H  smodl2=$@-08-s.H .H ts2=$@-08-ts.H 2.H sd2=$@-08-tsd.H .H cc2=$@-08-cc.H H rr2=$@-08-rr.H  \
        	nmix=1 par=warp-ang.P nmix=7 nodes=1 shift_nodes=1 verb=8 &
	touch $@
norne-hole-sxgx-grad-flat-warp-%:
	$(MJ)
	Window3d squeeze= n f2= 0 n2= 11 j1= 2 n1= 320 n4= 100 j2= 2 j3= 2 < norne-hole-sxgx-grad-flat-negpos-06-$*-s.H > junk$@.H ; < junk$@.H Transp plane=13  > $@-06.H 
	Window3d squeeze= n f2= 0 n2= 11 j1= 2 n1= 320 n4= 100 j2= 2 j3= 2 < norne-hole-sxgx-grad-negpos-$*-afmult-08.H > junk$@.H ; < junk$@.H Transp plane=13  > $@-08.H 
	$B/joint_encode.x report=$@.log modl=$@-06.H  \
		modl1=$@-06.H rm1=$@-06.H  smodl1=$@-06-s.H .H ts1=$@-06-ts.H 2.H sd1=$@-06-tsd.H .H cc1=$@-06-cc.H H rr1=$@-06-rr.H  \
		modl2=$@-08.H rm2=$@-08.H  smodl2=$@-08-s.H .H ts2=$@-08-ts.H 2.H sd2=$@-08-tsd.H .H cc2=$@-08-cc.H H rr2=$@-08-rr.H  \
        	nmix=1 par=warp-ang.P nmix=7 nodes=1 shift_nodes=1 verb=8 &
	touch $@
warp-negpos-%:
	#make norne-flat-warp-$*
	#make norne-hole-flat-warp-$* &
	#make norne-hole-sxgx-flat-warp-$*
	#make norne-hole-sxgx-grad-flat-warp-$*

# Get final images for inversion
mig-norne-grad-flat-warp-%:
	Window3d min3=1500 n3=501 < norne-grad-flat-warp-$*-06.H   | Stack3d | Transp plane=23 > $@-06.H; echo o2=0 d2=25 >> $@-06.H  
	Window3d min3=1500 n3=501 < norne-grad-flat-warp-$*-08-s.H | Stack3d | Transp plane=23 > $@-08.H; echo o2=0 d2=25 >> $@-08.H 
mig-norne-hole-sxgx-grad-flat-warp-%:
	Window3d min3=1500 n3=501 < norne-hole-sxgx-grad-flat-warp-$*-06.H   | Stack3d | Transp plane=23 > $@-06.H; echo o2=0 d2=25 >> $@-06.H  
	Window3d min3=1500 n3=501 < norne-hole-sxgx-grad-flat-warp-$*-08-s.H | Stack3d | Transp plane=23 > $@-08.H; echo o2=0 d2=25 >> $@-08.H 
#warp stacked images
mig-shift-norne-grad-flat-warp-%:
	$(MJ)
	$B/joint_encode.x report=$@.log modl=mig-norne-grad-flat-warp-$*-06.H   \
		modl1=mig-norne-grad-flat-warp-$*-06.H rm1=mig-norne-grad-flat-warp-$*-06.H  smodl1=$@-06-s.H .H ts1=$@-06-ts.H 2.H sd1=$@-06-tsd.H .H cc1=$@-06-cc.H H rr1=$@-06-rr.H  \
		modl2=mig-norne-grad-flat-warp-$*-08.H rm2=mig-norne-grad-flat-warp-$*-08.H  smodl2=$@-08-s.H .H ts2=$@-08-ts.H 2.H sd2=$@-08-tsd.H .H cc2=$@-08-cc.H H rr2=$@-08-rr.H  \
        	nmix=1 par=warp-ang.P nmix=7 nodes=1 shift_nodes=1 verb=8 &
	touch $@
mig-shift-norne-hole-sxgx-grad-flat-warp-%:
	$(MJ)
	$B/joint_encode.x report=$@.log modl=mig-norne-hole-sxgx-grad-flat-warp-$*-06.H   \
		modl1=mig-norne-hole-sxgx-grad-flat-warp-$*-06.H rm1=mig-norne-hole-sxgx-grad-flat-warp-$*-06.H  smodl1=$@-06-s.H .H ts1=$@-06-ts.H 2.H sd1=$@-06-tsd.H .H cc1=$@-06-cc.H H rr1=$@-06-rr.H  \
		modl2=mig-norne-hole-sxgx-grad-flat-warp-$*-08.H rm2=mig-norne-hole-sxgx-grad-flat-warp-$*-08.H  smodl2=$@-08-s.H .H ts2=$@-08-ts.H 2.H sd2=$@-08-tsd.H .H cc2=$@-08-cc.H H rr2=$@-08-rr.H  \
        	nmix=1 par=warp-ang.P nmix=7 nodes=1 shift_nodes=1 verb=8 &
	touch $@
