I have to browse pictures of 96 well plates. These are named by their position on the plate (A01, A02, ..., H12). So I wrote a macro with a Dialog with a couple of arrays in which the user can select the coordinates and get the images. For browsing from one location to the next I simply increase the column index and reset it to 0 when I reach 12. But how can I go to the next row? I would like to get the index of the current string in the 'row'-array. Is there a way to do this? Below I pasted a shortend sample script with three exclamation marks at the point where I am stuck:
row=newArray("A", "B", "C", "D", "E", "F", "G", "H"); column=newArray("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"); if (File.exists(getDirectory("macros")+"test.txt")) { liste=getDirectory("macros")+"test.txt"; string=File.openAsString(liste); liste=split(string, " "); R=liste[0]; //row c=liste[1]; //column nc=parseInt(liste[2]); //next column if (nc == 1){ c=parseInt(liste[1]); if (c==12) { c=0; //!!! R=R+1; //how can I achieve this? //this is rather bulky but the best I have. an array index would help here. any better idea? if (R=="A") { R="B";} else if (R=="B") { R="C";} else if (R=="C") { R="D";} else if (R=="D") { R="E";} else if (R=="E") { R="F";} else if (R=="F") { R="G";} else if (R=="G") { R="H";} else if (R=="H") { R="A";} // } else { c=column[c]; } } } else { R=row[0]; c=column[0]; nc=0; } Dialog.create("Data Loader"); Dialog.addChoice("row:", row, R); Dialog.addChoice("column:", column, c); Dialog.addCheckbox("next column", nc); Dialog.show(); row=Dialog.getChoice(); column=Dialog.getChoice(); nextImage=Dialog.getCheckbox(); print("\\Clear"); print(row+" "+column+" "+ nextImage); selectWindow("Log"); saveAs("Text", getDirectory("macros")+"test.txt"); |
First, in your Dialog you use
row=Dialog.getChoice(); but I don't think that's what you want. That overwrites your array. I think 'row' should be 'R'. If you do it this way, and if your text file has a character for the row, then you can find the index of the current row using the following found = 0; row_index = -1; for ( i = 0 ; i < row.length && found == 0; i++ ) { if ( R == row[i] ) { row_index = i ;found = 1; } }//Might want some check to make sure that a row_index was found. Then use this to get to the next row if ( R == row[row.length-1] ) // Check if you're at the last row; R = row[0]; else R = row[row_index+1]; This is pretty much exactly what aRnim suggested, expect the code is shorter and doesn't need to be rewritten if you change what's in your array. Justin On Nov 15, 2007 4:00 PM, aRnim <[hidden email]> wrote: > I have to browse pictures of 96 well plates. These are named by their > position on the plate (A01, A02, ..., H12). So I wrote a macro with a Dialog > with a couple of arrays in which the user can select the coordinates and get > the images. For browsing from one location to the next I simply increase the > column index and reset it to 0 when I reach 12. But how can I go to the next > row? I would like to get the index of the current string in the 'row'-array. > Is there a way to do this? Below I pasted a shortend sample script with > three exclamation marks at the point where I am stuck: > > row=newArray("A", "B", "C", "D", "E", "F", "G", "H"); > column=newArray("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", > "11", "12"); > if (File.exists(getDirectory("macros")+"test.txt")) { > liste=getDirectory("macros")+"test.txt"; > string=File.openAsString(liste); > liste=split(string, " "); > R=liste[0]; //row > c=liste[1]; //column > nc=parseInt(liste[2]); //next column > if (nc == 1){ > c=parseInt(liste[1]); > if (c==12) { > c=0; > //!!! R=R+1; //how can I achieve this? > //this is rather bulky but the best I have. an array index would help here. > any better idea? > if (R=="A") { R="B";} > else if (R=="B") { R="C";} > else if (R=="C") { R="D";} > else if (R=="D") { R="E";} > else if (R=="E") { R="F";} > else if (R=="F") { R="G";} > else if (R=="G") { R="H";} > else if (R=="H") { R="A";} > // > } else { > c=column[c]; > } > } > } else { > R=row[0]; > c=column[0]; > nc=0; > } > Dialog.create("Data Loader"); > Dialog.addChoice("row:", row, R); > Dialog.addChoice("column:", column, c); > Dialog.addCheckbox("next column", nc); > Dialog.show(); > row=Dialog.getChoice(); > column=Dialog.getChoice(); > nextImage=Dialog.getCheckbox(); > print("\\Clear"); > print(row+" "+column+" "+ nextImage); > selectWindow("Log"); > saveAs("Text", getDirectory("macros")+"test.txt"); > -- > View this message in context: http://www.nabble.com/getting-array-index-of-a-string-tf4817445.html#a13782677 > > Sent from the ImageJ mailing list archive at Nabble.com. > |
Free forum by Nabble | Edit this page |