Language problem newbie

macro
Tags: #<Tag:0x00007fa303eb89c8>

#21

More as addition than as criticism, avoid messing with slashes and backslashes, use the File.separator, as used a few lines earlier, because the system then inserts the proper symbol. It also saves the confusion with ‘’ or “” (single and double quotes). (Whaa! I see the Forum software changes them to single and double comma’s and inverted commas!)

See this question for some scary examples as why not to use a backslash or slash.
Also note differences in quotes, double quotes and inverted comma’s (single or double).


#22

Just an add to all the others good suggestions I think that if you come from a “structured” and imperative language as C, for you it will be much more easier use one of the programming langugages supported by ImageJ/Fiji pointed out by @etarena since they are closer to a programming language as C than the ImageJ macro language.


#23

could be…that was working however and the missing ‘)’ had moved down below it. now the missing ‘)’ is at the top because I changed the unknown list out and used len in stead of list.length


#24

you know I’m messing around in matlab and really its going all right. the missing ‘)’ error is confusing however. there are also some things I like about what I’ve seen in image j too. its amusing. anyhow I’ve got this code running into a different problem now but I know that missing ) is still out there…


#25

Fwiw - I now get a File Saving Error (IO) exception: which I have no Idea how to debug.

#@ File (label = “Input directory”, style = “directory”) input
#@ File (label = “Output directory”, style = “directory”) output
#@ String (label = “File suffix”, value = “.tif”) suffix

processFolder(input);

function processFolder(input) {

setBatchMode(true);
list = getFileList(input);
list = Array.sort(list);
for (i = 0; i < list.length; i++) {
	if(File.isDirectory(input + File.separator + list[i]))
		processFolder(input + File.separator + list[i]);
	if(endsWith(list[i], suffix))
		processFile(input, output, list[i]);
}

}

function processFile(input, output, file) {

run("Bio-Formats Windowless Importer", "open=[" + input + File.separator +  file + "] autoscale color_mode=Default view=Hyperstack stack_order=XYCZT");
suffix = ".tif";
name = getTitle;
stack = "stack";
path = output + File.separator + path;
File.makeDirectory(path);;
path = output + File.separator + stack + File.separator + name + suffix;
saveAs("Tiff", path);

getDimensions(width, height, channelCount, sliceCount, frameCount);

run("Split Channels", name);
path = output + File.separator + "splitchannels" + File.separator + name + suffix;

for(i = 1; i<=channelCount; i++) {
	name = getInfo("Selection Name");
	channel = strcat("channel", i);
	path = output + File.separator + channel;
	File.makeDirectory(path);
	path = output + File.separator + channel + File.separator + name + suffix;
	saveAs("Tiff", path);

	
	close();
}

}


#26

@sonderyugen

Use print() statements to be sure your variables are what they should be… checking stack, path, etc. at different stages of the code. This will help you debug it.

eta


#27

@sonderyugen: Though print() might be helpful, it is a cumbersome way of debugging. If you are not bound to FIJI because some commands are only available in FIJI, use ImageJ. ImageJ has an option to single step macro code and at every step inspect the contents of the variables in use
(Plugin>New>Macro, once in macro.txt, the last item in the menu bar changes to a Debug menu).

Variables can be inspected in the Debug window, which opens if you tick the checkbox at ‘Show “Debug” Window’ of the dialog that appears on the first error the macro encounters, in your case most likely " ‘)’ expected in line 31".
Array variables can be double-clicked to inspect every element of the array etc.

Once your code runs fine, take it back to FIJI if you need FIJI because of other reasons.