//These macros were written by Steve Rothery
//FILM - Facility for Imaging in Light Microscopy, Imperial College London
//http://www3.imperial.ac.uk/imagingfacility/

//////////////////////////////1

macro "Change Channels LUT's Action Tool - Cccc F00hh C000 T0809L T6809U Td809T Cg00 T0g09R C0g0 T6g09G C00g Tdg09B" 
{

bit=bitDepth();

if (bit==24){
run("Make Composite");
}

getDimensions(width, height, channels, slices, frames);


Dialog.create("Change Channel Look-up Tables")
  Dialog.addMessage("Select Colour for each channel");
Colour = newArray("Red", "Green", "Blue", "Cyan", "Magenta", "Yellow", "Grays", "Light Blue", "HiLo", "16 colors", "Spectrum","lifetime");
for (i=1; i<=channels; i++) {
Ch="Channel " + i;
Dialog.addRadioButtonGroup(Ch, Colour, 2, 1, Colour[i-1]);
}
Dialog.show(); 


for (j=1; j<=channels; j++){
	if (channels>1){
	Stack.setChannel(j);
	}
newcol = Dialog.getRadioButton();
run(newcol);
}
}

////////////////////////////////////2


macro "Calibrate the resampled tiled images(ZEN) using bioformats open command Action Tool - C000 R0066 R1844 R2e22 Cg00 Tc407C Tcb07A Tdh07L" 
{

fn=getTitle();
getDimensions(ImageWidth, ImageHeight, ImageChannels, ImageSlices, ImageFrames);
getVoxelSize(px, py, pz, unit);

mul=getNumber("Input re-sampled image series number #", 2);
mul=pow(3, (mul-1));

setVoxelSize(px*mul, py*mul, pz*mul, unit);
}



/////////////////////////////////////3

macro "Calibration tool for Widefield exported images (v2) Action Tool - Cg00T1d16C C00gT9d12a C000L0ggg D0fD2fD4fD6fD8fDafDcfDefDgf" 
{


Dialog.create("Tiff Image Calibration");
  Dialog.addMessage("FILM Widefield Camera image export calibration tool");
  CameraOptions = newArray("HWF1 Colour", "HWF1 Flash", "Vivatome", "WF1 Flash", "WF2 CCD", "WF3 Flash", "WF3 Colour");
  Dialog.addRadioButtonGroup("Camera", CameraOptions, 1, 4, "HWF1 Colour");
  ObjectiveOptions = newArray("x 2.5", "x 5", "x 10", "x 20", "x 40 Air", "x 63 Oil", "x 100 Oil");
  Dialog.addRadioButtonGroup("Objective lens", ObjectiveOptions, 1, 7, "x 5");
  BinningOptions = newArray(" 1x1 ", " 2x2 ", " 3x3 ", " 4x4 ", " 5x5 ");
  Dialog.addRadioButtonGroup("Binning", BinningOptions, 1, 5, " 1x1 ");
  Dialog.addMessage("Scaling on export (eg 50% = 0.50)");
  Dialog.addNumber("Factor", 1, 2, 3,"" )
  Option = newArray("Yes", "No");
  Dialog.addRadioButtonGroup("Do you want to add a scale bar", Option, 1, 1, "No");
Dialog.show;
  
Camera = Dialog.getRadioButton(); 
Objective = Dialog.getRadioButton();
binning = Dialog.getRadioButton();
Exportfactor = Dialog.getNumber(); 
ScaleBar = Dialog.getRadioButton();


//(size of 1 pixel in image / obj corr   = correction
if (Camera == "HWF1 Colour" ) correction=1;
else if (Camera == "HWF1 Flash") correction=0.69892;
else if (Camera == "WF1 Flash" ) correction=0.69892;
else if (Camera == "Vivatome") correction=0.69354;
else if (Camera == "WF3 Flash") correction=0.69892;
else if (Camera == "WF3 Colour") correction=0.58925;
else if (Camera == "WF2 CCD") correction=0.8348;

if (Objective == "x 2.5" ) obj=3.72;
else if (Objective == "x 5") obj=1.86;
else if (Objective == "x 10") obj=0.930;
else if (Objective == "x 20") obj=0.465;
else if (Objective == "x 40 Air") obj=0.2325;
else if (Objective == "x 63 Oil") obj=0.1476;
else if (Objective == "x 100 Oil") obj=0.093; 

if (binning == " 1x1 " ) bin=1;
else if (binning == " 2x2 ") bin=2;
else if (binning == " 3x3 ") bin=3;
else if (binning == " 4x4 ") bin=4;
else if (binning == " 5x5 ") bin=5;



scale=obj*(1/Exportfactor)*bin*correction;

run("Set Scale...", "distance=1 known="+ scale +" pixel=1 unit=um");

if (ScaleBar=="Yes")
{
run("Scale Bar...");	
}
}



///////////////////////////////////////////////4

macro "Add scale bar  Action Tool - Cg00T1g12u Cg00T8g12m C000L03g3 L0105 Lg1g5" 
{
run("Scale Bar...");
}

////////////////////////////////////////////5

macro "Rotate image Action Tool -Caaa F00hh Cg00 O22cc C00g L0c37 L6c37 Lb6eb Lh6eb"
{

a=nImages; 
if(a>0){};
else {
	 exit("No Image open")
};
	
//get file info
getDimensions(width, height, channels, slices, frames);




//set canvas size
canvas=floor(sqrt((width*width)+(height*height)));


//draw line and work out angle
setTool("line");

title = "Get info";
msg = "draw line for new angle\n then select OK to continue";
waitForUser(title, msg);

getLine(x1, y1, x2, y2, lineWidth);
op=x1-x2;
ad=y1-y2;
an=atan2(ad, op);
an=180-(an*180/PI);

if (an>270){
	an=an-360;
}
else if (an>90){
	an=an-180;
}


//change canvas size and rotate
size="width=" + canvas + " height=" + canvas + " position=Center zero";
run("Canvas Size...", size);
rot="angle=" + an + " interpolation=Bilinear";
run("Rotate... ", rot);
setTool("rectangle");
}


/////////////////////////////////////////////6

macro "Rotate & Crop image Action Tool -Caaa F00hh Cg00 O22cc C00g L0c37 L6c37 Lb6eb Lh6eb Cggg R5577"
{

a=nImages; 
if(a>0){};
else {
	 exit("No Image open")
};
	
//get file info
getDimensions(width, height, channels, slices, frames);


//set canvas size
canvas=floor(sqrt((width*width)+(height*height)));


//draw line and work out angle
setTool("line");

title = "Get info";
msg = "draw line for new angle\n then select OK to continue";
waitForUser(title, msg);

getLine(x1, y1, x2, y2, lineWidth);
op=x1-x2;
ad=y1-y2;
an=atan2(ad, op);
an=180-(an*180/PI);

if (an>270){
	an=an-360;
}
else if (an>90){
	an=an-180;
}


//change canvas size and rotate
size="width=" + canvas + " height=" + canvas + " position=Center zero";
run("Canvas Size...", size);
rot="angle=" + an + " interpolation=Bilinear";
run("Rotate... ", rot);

setTool("rectangle");

Dialog.create("crop");
Dialog.addMessage("Specify size of crop");
Dialog.addNumber("X - pixels", 240);
Dialog.addNumber("Y - Pixels", 240);
Dialog.show;
xcrop = Dialog.getNumber();
ycrop = Dialog.getNumber();
xpos=floor((canvas-xcrop)/2);
ypos=floor((canvas-ycrop)/2);
spec="width=" + xcrop + " height=" + ycrop + " x=" + xpos + " y=" + ypos;
run("Specify...", spec);

title = "Get info";
msg = "draw crop region\n then select OK to continue";
waitForUser(title, msg);

run("Crop");

}


////////////////////////////////////////7

macro "Create Set & Copy Intensity Levels Action Tool - C00g F00hh C0g0 F00bh Cg00 F006h    C000 T1807B L0gg0 Cggg Tcg07C "
{

getDimensions(width, height, channels, slices, frames);


Channel=newArray(channels);
for (n=0;n<channels;n++){
	Channel[n]="Channel " + (n+1);
}
	
Maximum_Level=newArray(channels);
Minimum_Level=newArray(channels);


Menu();


//main menu
function Menu()
{
Dialog.create("Select");
  todo = newArray("Create Levels", "Apply Levels", "Load Levels from file","Load Levels from Image", "Enter Levels", "Save Levels", "Exit" );
  Dialog.addRadioButtonGroup("What do you want to do?", todo, 7, 2, "Create Levels");
Dialog.show;
  
op = Dialog.getRadioButton(); 

if (op=="Create Levels"){
	
	run("Brightness/Contrast...");

	title = "Set levels";
	msg = "Set thresholds for each cahnnels\n \n then select OK to continue";
	waitForUser(title, msg);

	CreateLevels(Minimum_Level,Maximum_Level);
}

if (op=="Apply Levels"){
	title = "Select Image";
	msg = "Select Image\n \n then select OK to continue";
	waitForUser(title, msg);
	ApplyLevels(Minimum_Level,Maximum_Level);
}

if (op=="Load Levels from file"){
	LoadLevelsFile(Minimum_Level,Maximum_Level);
}

if (op=="Load Levels from Image"){
	title = "Select Image";
	msg = "Select Image\n \n then select OK to continue";
	waitForUser(title, msg);
	CreateLevels(Minimum_Level,Maximum_Level);
}

if (op=="Enter Levels"){
	EnterLevels(Minimum_Level,Maximum_Level);
}

if (op=="Save Levels"){
	SaveLevels(Minimum_Level,Maximum_Level);
}

if (op=="Exit"){
	end();
}
}

//create results table interactively
function CreateLevels(Minimum_Level,Maximum_Level)
{

for (i=0;i<channels;i++){
if (channels>1){
Stack.setChannel(i+1);
}
getMinAndMax(Minimum_Level[i], Maximum_Level[i]);
//Maximum_Level[i]=min;
//Minimum_Level[i]=max;
}

Array.show("Results",Channel, Minimum_Level, Maximum_Level);
Menu();
}

//apply levels from results table
function ApplyLevels(Minimum_Level,Maximum_Level)
{

for (j=0;j<channels;j++){
	if (channels>1){
Stack.setChannel(j+1);
	}
minlevel=getResult("Minimum_Level", j);
maxlevel=getResult("Maximum_Level", j);
setMinAndMax(minlevel, maxlevel);
}
Menu();
}

//load levels from disk
function LoadLevelsFile(Minimum_Level,Maximum_Level)
{
	open();
	Menu();
}

//save the levels to disk
function SaveLevels(Minimum_Level,Maximum_Level)
{
	output = getDirectory("Select Directory");
	sr=getString("Name for results", "series");
	selectWindow("Results");
	out = output + sr + ".csv";
	saveAs("Results", out);
	Menu();
}


//enter your own levels
function EnterLevels(Minimum_Level, Maximum_Level)
{

Dialog.create("Enter");
  Dialog.addMessage("Enter Levels"); 
for (k=0;k<channels;k++){
if (channels>1){
Stack.setChannel(k+1);
}
getMinAndMax(minlevel, maxlevel);
  Dialog.addNumber("Channel "+ (k+1) + " Min", minlevel, 0, 0,"" );	
  Dialog.addNumber("Channel "+ (k+1) + " Max", maxlevel, 0, 0,"" );	
}
Dialog.show;

for (l=0;l<channels;l++){
Maximum_Level[l]=Dialog.getNumber();
Minimum_Level[l]=Dialog.getNumber();	
}
Array.show("Results",Channel, Minimum_Level, Maximum_Level);
Menu();
}

function end()
{
}
}

////////////////////////////////////////////////////////8

macro "Overlay 2 RGB Colour Images Action Tool -C000 T7a08+ Ca00 T0508R T0h08R C0a0 T7508G T7h08G C00a Te508B Teh08B" 
{

//select first image
waitForUser("Get info", "select first image \n select ok when done");
run("Duplicate...", "title=1");
run("Make Composite");
run("32-bit");

//select second image
waitForUser("Get info", "select second image \n select ok when done");
run("Duplicate...", "title=2");
run("Make Composite");
run("32-bit");

//join
imageCalculator("Add create stack", "1","2");
selectWindow("Result of 1");

Stack.setChannel(1);
run("Enhance Contrast", "saturated=0.35");
Stack.setChannel(2);
run("Enhance Contrast", "saturated=0.35");
Stack.setChannel(3);
run("Enhance Contrast", "saturated=0.35");

//flatten
run("RGB Color");
rename("Overlay");


//tidy up
selectWindow("Result of 1");
close();
selectWindow("1");
close();
selectWindow("2");
close();

}



///////////////////////////////////////////////////////////9

macro "Corrects White Balance in RGB Images  Action Tool - Cccg F008g Cggg F807g C000 R00gg Cf2f L28d8 La5d8 Labd8" 
{
run("Set Measurements...", "area mean min limit display redirect=None decimal=3");
//corrects white balance on RGB images
//makes sure image is rgh
if (bitDepth()!=24){
	run("RGB Color", "slices");
}

//imitialise
n=roiManager("count");
//roiManager("Reset");
run("Clear Results");
Int=newArray(3);
fn=getTitle();
getDimensions(ImageWidth, ImageHeight, ImageChannels, ImageSlices, ImageFrames);
setTool("Rectangle");


run("Make Composite");
rename("temp");

//select background 
title = "Get info";
msg = "Draw an roi over background/white reference \n and select OK to continue";
waitForUser(title, msg);
roiManager("Add");

//measure channel diffences
//roiManager("Multi Measure");

for (i=0;i<3;i++){
roiManager("select", n);
	Stack.setChannel(i+1);
	roiManager("Measure");
	Int[i]=getResult("Mean", i);
}
roiManager("select", n);
roiManager("delete");
Array.getStatistics(Int, min, max, mean, stdDev);
roiManager("Deselect");



//correct channels
run("Split Channels");
for (channel=0;channel<3;channel++){
	selectWindow("C"+channel+1+"-temp");
	change="value=" + mean/Int[channel] + " stack";
	run("Multiply...",change );
}


// creates final rgb
run("Merge Channels...", "c1=C1-temp c2=C2-temp c3=C3-temp create");
selectWindow("temp");
run("RGB Color", "slices");
rename("Corrected "+fn);

if (isOpen("temp")==true){
	selectWindow("temp");
	close();
}


selectWindow("Results");
run("Close");
}




///////////////////////////////////////////////////////////10

macro "Invert Intensities Action Tool - Cccc F00h9 C000 T0708I T4708N Ta708V C000 F09ha Cggg  T1h08I T6h08N  Tdh08T" 
{

//invert intensities

BD=bitDepth();

if (BD==24){
	BD=8;
}

if (BD==32){
	exit("Image is 32-Bit - use Reciprocal command");
}
a=pow(2, BD);


level="code=v="+a-1+"-v stack";

run("Macro...", level);
}



///////////////////////////////////////////////11

macro "Colour Deconvolution tools (keeps calibration & labels images) Action Tool - C000 T0h10D T7h10e Tdh10c C66g F0036 C0dd F3036 C0g0  F6036 Cgg0 F9036 Cg00 Fc036 Cd08 Ff036 " 
{

if (isOpen("Log")==true) {
selectWindow("Log");
run("Close");
}

if(nImages<1){
	exit("No Image open");
};

//load predifined deconvolution vectors
path=getDirectory("plugins");
Vectorfile=path+"colourdeconvolution.txt";
if (File.exists(path)==1){
	filestring=File.openAsString(Vectorfile); 
Vector_list=split(filestring, "\n"); 
Vector_list=Array.slice(Vector_list,1,Vector_list.length);
for (Vect=0;Vect<Vector_list.length;Vect++){
st=indexOf(Vector_list[Vect], ",");
Vector_list[Vect]=substring(Vector_list[Vect], 0, st);
}
UV=newArray("Saved User Values","Create and Save from ROI");
Vector_list=Array.concat(Vector_list,UV);
}
else{
	(exit("The Color Deconvolution plugin (<Image><Color><Color Deconvolution> needs to be run at least once before running this macro");
}


//channel labels
labels=newArray("C1","C2","C3","Nuclei","DAB","Collagen","Cytoplasm","Muscle","Background");




//get file info
Bit=bitDepth();
if (Bit!=24){
	run("RGB Color");  
}	
fn=getTitle();
getDimensions(ImageWidth, ImageHeight, ImageChannels, ImageSlices, ImageFrames);
getVoxelSize(px, py, pz, unit);

//options
Dialog.create("Options");
	Dialog.addRadioButtonGroup("Colour Deconvolution Method", Vector_list, 4, Vector_list.length/4, Vector_list[0]);
	Dialog.setInsets(15, 10, 5); 
	Dialog.addMessage("Image Labelling");
	Dialog.setInsets(0, 25, 5); 
	Dialog.addChoice("   Image 1 label:", labels, labels[0]);
	Dialog.addToSameRow();
	Dialog.addChoice("   Image 2 label:", labels, labels[1]);
	Dialog.addToSameRow();
	Dialog.addChoice("   Image 3 label:", labels, labels[2]);
	sm=newArray("None","Smooth","Despeckle");
	Dialog.setInsets(15, 10, 5); 
	Dialog.addRadioButtonGroup("Post Processing - filter: ", sm, 1, 3, "None");
	Dialog.addCheckbox("Change LUT to grayscale", false);

Dialog.show();

//responses
Vector=Dialog.getRadioButton();
Channel_1_name=Dialog.getChoice(); 
Channel_2_name=Dialog.getChoice();
Channel_3_name=Dialog.getChoice();
Smooth=Dialog.getRadioButton();
Lut_change=Dialog.getCheckbox();


//process
// fron saved vectors
if (Vector=="Saved User Values"){
	cv=newArray(9);
	vectorinfo=File.openAsString("");

Saved_vect=split(vectorinfo);
Saved_vect=Array.slice(Saved_vect,5,26);

v=0;
for (i=2;i<20;i++){
for (c=0;c<3;c++){	
	cv[v]=Saved_vect[i];
	v=v+1;
	i=i+2;
}	
}

run("Colour Deconvolution", "vectors=[User values] [r1]="+cv[0]+" [g1]="+cv[1]+" [b1]="+cv[2]+" [r2]="+cv[3]+" [g2]="+cv[4]+" [b2]="+cv[5]+" [r3]="+cv[6]+" [g3]="+cv[7]+" [b3]="+cv[8]+" hide");
Dialog.create("Save to Plugin");
	Dialog.addCheckbox("Add to the Plugin Vector list", false);
Dialog.show();
To_plugin_list=Dialog.getCheckbox();
if (To_plugin_list==true){
	Vectors_to_plugin();
}

// from ROI
}else if (Vector=="Create and Save from ROI"){
	if (isOpen("Log")==true){
	selectWindow("Log");
	run("Close");
	}
run("Colour Deconvolution", "vectors=[From ROI] show hide");
Dialog.create("Save");
	Dialog.addCheckbox("Save Vectors for future use", true);
	Dialog.addString("Vector File Name:	","My Vectors");
	Dialog.addCheckbox("Add to Plugin vector list from saved values", false);
Dialog.show();

sv=Dialog.getCheckbox();
vectname=Dialog.getString();
To_plugin_list=Dialog.getCheckbox();

vectorinfo=getInfo("log");

if (sv==true){
vectorinfo=getInfo("log");
showText(vectname, vectorinfo);
	saveAs("Text", "");
	run("Close");
}

if (To_plugin_list==true){
	Vectors_to_plugin();
}


// from predefined vectors
}else{
	run("Colour Deconvolution", "vectors=["+Vector+"] hide");
}


//finish up
selectWindow(fn+"-(Colour_1)");
rename(fn+" "+Channel_1_name);
setVoxelSize(px, py, pz, unit);
if (Smooth!="None"){
	run(Smooth);
}
if (Lut_change==true){
	run("Grays");
}
selectWindow(fn+"-(Colour_2)");
rename(fn+" "+Channel_2_name);
setVoxelSize(px, py, pz, unit);
if (Smooth!="None"){
	run(Smooth);
}
if (Lut_change==true){
	run("Grays");
}
selectWindow(fn+"-(Colour_3)");
rename(fn+" "+Channel_3_name);
setVoxelSize(px, py, pz, unit);
if (Smooth!="None"){
	run(Smooth);
}
if (Lut_change==true){
	run("Grays");
}


////write to colourdeconvolution text plugin
function Vectors_to_plugin(){

vect=split(vectorinfo);

vect=Array.slice(vect,38,47);

new_Vect="";
for (v=0;v<9;v++){
vect[v]=substring(vect[v],8,indexOf(vect[v],";"));
new_Vect=new_Vect+","+vect[v];

}

newname=getString("Enter Dye name", "new dye");

run("Text File... ", "open="+Vectorfile);

txtfile="[colourdeconvolution.txt]";
print(txtfile,newname+new_Vect);
waitForUser("","Edit colourdeconvolution file");
selectWindow("colourdeconvolution.txt");

run("Text...", "save="+Vectorfile);
run("Close");
}




}

//////////////////////////////////////////////12

macro "Blank1 Action Tool - "
{
}



//////////////////////////////////////13


macro "Batch Projection Action Tool - Cg4g T0608B T66o8a Tb608t Td608c Th608h T1g08P T7g08r Tag08o Tfg08j Thg08-"
{


number=0;
//open directory of images

Dialog.create("Batch Processing - Projections");
	Proj=newArray("Max Intensity","Average Intensity", "Min Intensity", "Sum Slices", "Standard Deviation", "Median" );
	Dialog.addChoice("Type of projection", Proj,"Max Intensity");
	Dialog.addCheckbox("Use Bio-Formats Importer ", true);
	Dialog.addCheckbox("Convert to RGB on save", false);
Dialog.show();
	ProjectionType = Dialog.getChoice();
	Bio=Dialog.getCheckbox(); 
	Convert = Dialog.getCheckbox(); 


input = getDirectory("location where images are stored");



//select location where images are stored
output = getDirectory("Location for results");

list = getFileList(input);

setBatchMode(true);

//loop to sequentially open images
for (im=0; im<list.length; im++){
full = input + list[im];

if (Bio==true){
run("Bio-Formats Importer", "open=full autoscale color_mode=Composite view=Hyperstack stack_order=XYCZT");
} else {
open(full);
}

fn=getTitle();
getDimensions(width, height, channels, slices, frames);
type="projection=["+ProjectionType+"] all";
run("Z Project...",type);
if (Convert==true){
	run("Make Composite");
//	run("RGB Color");
	run("Stack to RGB");
}
rename(ProjectionType + " Projection "+fn);
print(ProjectionType + " Projection "+fn + " done");
out = output + ProjectionType + " Projection "+fn;
saveAs("tiff", out);
run("Close All");
number=number+1;
}

setBatchMode(false);


print("All done - " + number + " images processed");

}


///////////////////////////////////////////


macro "Blank2 Action Tool - "
{
}



//////////////////////////////////////////////////////update

macro "Update College Macros Action Tool - C44g T0508M T65o8a Ta508c Te508r Th508o T0f08U T6f08p Taf08d Tef08a Thf08t"
{
//copies macros form the documentation drive to the toolsets directory
//has to be connected to the college network

//get os and macro directory
OS=getInfo("os.name");
MacroDir=getDirectory("macros");
LutDir=getDirectory("luts");
PlgDir=getDirectory("plugins");
macroinput="";
lutinput="";


// select documentation drive
if(startsWith(OS, "Wind")==true){
macroinput = "//film-nas2.med.ic.ac.uk/Documentation/FijiMacros/";
macrolist = getFileList(macroinput);
lutinput = "//film-nas2.med.ic.ac.uk/Documentation/FijiLuts/";
lutlist = getFileList(lutinput);
print(OS + " Updater");
}



if(startsWith(OS, "Mac")==true){
macroinput = "/Volumes/Documentation/FijiMacros/";
lutinput = "/Volumes/Documentation/FijiLuts/";
print(OS + " Updater");
title = "Connect";
msg = "Connect to the documentation drive \n smb://film-nas.med.ic.ac.uk/Documentation \n then click OK";
waitForUser(title, msg);
}

//print(macroinput);
//print(lutinput);


//get macro names list from documentation drive
macrolist = getFileList(macroinput);
lutlist = getFileList(lutinput);

//Array.show(macrolist,lutlist);

//error check
if (macrolist.length<1){
	exit("Directory or Drive not found");
}


//open, save and close macro files 
for (m=0; m<macrolist.length; m++){
File.copy(macroinput+macrolist[m], MacroDir + "toolsets/" + macrolist[m]);
print(macrolist[m] + " copied");
}

if (lutlist.length<1){
	exit("Directory or Drive not found");
}

for (l=0; l<lutlist.length; l++){
if (lutlist[l]=="colourdeconvolution.txt"){
over_write=getBoolean("Do you want to copy across the FILM colour deconvolution vectors \n \n This will replace the existing vector list");
if (over_write==true){
if (File.exists(PlgDir + lutlist[l])==true){
	getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec);
	File.rename(PlgDir + lutlist[l], PlgDir + "colourdeconvolution_"+year+"_"+month+1+"_"+dayOfMonth+".txt");
}
	File.copy(lutinput+lutlist[l],PlgDir + lutlist[l]);
print(lutlist[l] + " copied");
}
}
else{
File.copy(lutinput+lutlist[l],LutDir + lutlist[l]);
print(lutlist[l] + " copied");
}
}
	

}













