#
# This is a Makefile to make 3D-Data using the RadonTransform from 2D-Datas and 3DList.
#

#### Root Makefile ####
MAKE_ROOT=3DReconstructionRadon

#### Input extention and listname ####
IN_3D_EXT=fit
IN_3DLIST_EXT=3dlst

#### SUFFIXES RULE ####
.SUFFIXES: .sino .$(IN_3D_EXT) .3dradonlst .$(IN_3DLIST_EXT) .3dradon .3d .tiff

SHELL=/bin/bash

#### INCLUDE ####
-include ${EOS_HOME}/tutorial/TIPS/Help/Makefile/Makefile-lib
-include IN_3D_LIST

#### Definition ####
# Target structure name 
TARGET=Input

# Interpolation mode : Common with mrc2Dto3D
IN_MODE=2

### RadonTransform
PD=2.5
PHID=10
THETAD=10
RBP_MODE=1

#### For Works ####
JOP_NUM=-j 3

sino:$(IN_3D_LIST:.$(IN_3D_EXT)=.sino)

IN_3D_LIST::
	touch IN_3D_LIST
	echo "IN_3D_LIST=\\" > IN_3D_LIST
	ls -1 *.$(IN_3D_EXT) |  sed s/$(IN_3D_EXT)/$(IN_3D_EXT)\\\\/ >> IN_3D_LIST
	echo "" >> IN_3D_LIST


#### Commands ####
help_3DReconstructionRadon::
	@echo "This is a Makefile to make 3D-Data using the RadonTransform from 2D-Datas and 3DList."

All::
	make IN_3D_LIST;
	make sino;
	make 3DRadon;

3DRadon::
	make $(TARGET).3dradonlst;
	make $(TARGET).3dradon;
	make $(TARGET).3d;

3DTiff::
	make $(TARGET).tiff

##### Commands(Input to Output) #####
.$(IN_3D_EXT).sino:
	mrcImageSinogramCreate -i $*.$(IN_3D_EXT) -o $*.sino -dphi $(PHID);

.$(IN_3DLIST_EXT).3dradonlst:
	sed 's/.$(IN_3D_EXT)/.sino/g' $*.$(IN_3DLIST_EXT) > $*.3dradonlst;

.3dradonlst.3dradon:
	mrcRadon2Dto3D -I $*.3dradonlst -o $*.3dradon -ow $*.3dradonw -dp $(PD) -dtheta $(THETAD) -dphi $(PHID) -InterpolationMode $(IN_MODE);

.3dradon.3d:
	mrcImageInverseRadonTransform -i $*.3dradon -o $*.3d -bpm $(RBP_MODE);

.3d.tiff:
	@for (( loop_num = 0; loop_num <= 2; loop_num += 1 ))	\
	do \
		mrcImageProjection -i $(TARGET).3d -o $(TARGET).tmp -m $$loop_num;	\
		mrc2tiff -i $(TARGET).tmp -o $(TARGET)$$loop_num.tiff;	\
	done;
	rm $(TARGET).tmp;
