Hi everyone,
is there any equivalent to 'continue' in a for loop in the macro language? I'm inside a foor loop and want to skip to the next value in the loop if a certain condition is not meet. Here's a bit of code example // get list of files and options for (i = 0; i < lengthOf(file_list); i++) { // check if file exists before opening. Skip if it's no longer there if(File.exists(file_list[i]) { file.open(file_list[i]); } else { print ("File disappeared. Skipping"); continue; } // Do very smart image analysis here } I tried continue and it doesn't work. "next" also doesn't. Any help would be appreciated. Thanks in advance, Carnë Draug |
Hi,
Hi Carnë, Why don't you put the "smart analysis" part inside the if(File.exist) condition, just after opening the file ? So it will not be done for non existing images and the outputn will be the same ? Or maybe I missed something. Christophe 2011/3/15 Carnë Draug <[hidden email]> > Hi everyone, > > is there any equivalent to 'continue' in a for loop in the macro > language? I'm inside a foor loop and want to skip to the next value in > the loop if a certain condition is not meet. Here's a bit of code > example > > // get list of files and options > > for (i = 0; i < lengthOf(file_list); i++) { > // check if file exists before opening. Skip if it's no longer there > if(File.exists(file_list[i]) { > file.open(file_list[i]); > } else { > print ("File disappeared. Skipping"); > continue; > } > // Do very smart image analysis here > } > > I tried continue and it doesn't work. "next" also doesn't. Any help > would be appreciated. > > Thanks in advance, > Carnë Draug > |
Hi Christophe,
it's just to avoid nesting code even more. Since the code is already in another loop and there will be more if and loops in the analysis part, if that could be avoided great. I'm more of a perl programmer so I like my code clean and easy to read (hahahaha!) But from your answer I'm guessing there's no way to do it, just as there's no equivalent to the break statement. Can this mail maybe count as a feature request? Thanks anyway, Carnë 2011/3/15 Christophe Leterrier <[hidden email]>: > Hi, > Hi Carnë, > Why don't you put the "smart analysis" part inside the if(File.exist) > condition, just after opening the file ? So it will not be done for non > existing images and the outputn will be the same ? Or maybe I missed > something. > Christophe > > 2011/3/15 Carnë Draug <[hidden email]> >> >> Hi everyone, >> >> is there any equivalent to 'continue' in a for loop in the macro >> language? I'm inside a foor loop and want to skip to the next value in >> the loop if a certain condition is not meet. Here's a bit of code >> example >> >> // get list of files and options >> >> for (i = 0; i < lengthOf(file_list); i++) { >> // check if file exists before opening. Skip if it's no longer there >> if(File.exists(file_list[i]) { >> file.open(file_list[i]); >> } else { >> print ("File disappeared. Skipping"); >> continue; >> } >> // Do very smart image analysis here >> } >> >> I tried continue and it doesn't work. "next" also doesn't. Any help >> would be appreciated. >> >> Thanks in advance, >> Carnë Draug > > |
Carnë,
did you consider using functions to make your (smart) code more structured? >Hi Christophe, > >it's just to avoid nesting code even more. Since the code is already >in another loop and there will be more if and loops in the analysis >part, if that could be avoided great. I'm more of a perl programmer so >I like my code clean and easy to read (hahahaha!) > >But from your answer I'm guessing there's no way to do it, just as >there's no equivalent to the break statement. Can this mail maybe >count as a feature request? > >Thanks anyway, >Carnë > >2011/3/15 Christophe Leterrier <[hidden email]>: >> Hi, >> Hi Carnë, >> Why don't you put the "smart analysis" part inside the if(File.exist) >> condition, just after opening the file ? So it will not be done for non >> existing images and the outputn will be the same ? Or maybe I missed >> something. >> Christophe >> >> 2011/3/15 Carnë Draug <[hidden email]> >>> >>> Hi everyone, >>> >>> is there any equivalent to 'continue' in a for loop in the macro >>> language? I'm inside a foor loop and want to skip to the next value in >>> the loop if a certain condition is not meet. Here's a bit of code >>> example >>> >>> // get list of files and options >>> >>> for (i = 0; i < lengthOf(file_list); i++) { >>> // check if file exists before opening. Skip if it's no longer there >>> if(File.exists(file_list[i]) { >>> file.open(file_list[i]); >>> } else { >>> print ("File disappeared. Skipping"); >>> continue; >>> } >>> // Do very smart image analysis here >>> } >>> >>> I tried continue and it doesn't work. "next" also doesn't. Any help >>> would be appreciated. >>> >>> Thanks in advance, > >> Carnë Draug Best -- Herbie ------------------------ <http://www.gluender.de> |
In reply to this post by Carnë Draug
2011/3/15 Carnë Draug <[hidden email]>:
> Hi everyone, > > is there any equivalent to 'continue' in a for loop in the macro > language? I'm inside a foor loop and want to skip to the next value in > the loop if a certain condition is not meet. Here's a bit of code > example > > // get list of files and options > > for (i = 0; i < lengthOf(file_list); i++) { > // check if file exists before opening. Skip if it's no longer there > if(File.exists(file_list[i]) { > file.open(file_list[i]); > } else { > print ("File disappeared. Skipping"); > continue; > } > // Do very smart image analysis here > } > > I tried continue and it doesn't work. "next" also doesn't. Any help > would be appreciated. > > Thanks in advance, > Carnë Draug Carnë, Macro recording and macros in general are great for specific tasks that can be applied to individual images, and are suitable for batch processing. For complex programs I'd go for a language that makes shuffling data around easy. For example python. Here is a tutorial on using python with Fiji, an ImageJ distribution packed with many libraries and plugins: http://www.ini.uzh.ch/~acardona/fiji-tutorial/ Hope that helps. Albert -- http://albert.rierol.net |
On 16 March 2011 11:48, Gluender <[hidden email]> wrote:
> Carnë, > > did you consider using functions to make your (smart) code more structured? I did. But then I can't return more than one value from a function. I could return an array so I tried it despite the limited array manipulation functions but I get an error saying that an array of arrays is not possible. That said I did made a few functions (mostly for array manipulation) but not nearly as much as I would like to. I'm trying to make the code the easy to read since I'm not writing it for myself, but for people in the lab who don't know programming and I don't want to scare them away even more from looking at code. On 16 March 2011 12:15, Albert Cardona <[hidden email]> wrote: > Macro recording and macros in general are great for specific tasks > that can be applied to individual images, and are suitable for batch > processing. For complex programs I'd go for a language that makes > shuffling data around easy. For example python. Yeah, I feel like I'm using an axe for doing surgery. I was trying to avoid it because I thought that macro would be easier for non-programmers (the real users of it) to read and thus incentive them into tweaking and maybe creating their own macros. But I've been delaying learning Python for ages so this may be a good time. If only there was perl support as well... Still, thank you all for you comments. Carnë |
I know it's messy and was absolutely forbidden when I took programming in college, but you can cheat by making global variables.
Cheers, Michael -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Carnë Draug Sent: Wednesday, March 16, 2011 9:47 AM To: [hidden email] Subject: Re: continue equivalent on macro language (for loop control) On 16 March 2011 11:48, Gluender <[hidden email]> wrote: > Carnë, > > did you consider using functions to make your (smart) code more structured? I did. But then I can't return more than one value from a function ------------------------------------------------------------ This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is proprietary, confidential, and exempt from disclosure under applicable law. Any unauthorized review, use, disclosure, or distribution is prohibited. If you have received this email in error please notify the sender by return email and delete the original message. Please note, the recipient should check this email and any attachments for the presence of viruses. The organization accepts no liability for any damage caused by any virus transmitted by this email. ================================= |
In reply to this post by Carnë Draug
Carnë,
perhaps you should get more acquainted with the IJ macro language: macro "Test [t]" { a = newArray( 3 ); testFunction( a ); print( "Values: " + a[0] + " " + a[1] + " " + a[2] ); } function testFunction( a ) { for ( i = 0; i < 3 ; i++ ) { a[i] = i; } } >On 16 March 2011 11:48, Gluender <[hidden email]> wrote: > > Carnë, >> >> did you consider using functions to make your (smart) code more structured? > >I did. But then I can't return more than one value from a function. I >could return an array so I tried it despite the limited array >manipulation functions but I get an error saying that an array of >arrays is not possible. That said I did made a few functions (mostly >for array manipulation) but not nearly as much as I would like to. I'm >trying to make the code the easy to read since I'm not writing it for >myself, but for people in the lab who don't know programming and I >don't want to scare them away even more from looking at code. > > >On 16 March 2011 12:15, Albert Cardona <[hidden email]> wrote: >> Macro recording and macros in general are great for specific tasks >> that can be applied to individual images, and are suitable for batch >> processing. For complex programs I'd go for a language that makes >> shuffling data around easy. For example python. > >Yeah, I feel like I'm using an axe for doing surgery. I was trying to >avoid it because I thought that macro would be easier for >non-programmers (the real users of it) to read and thus incentive them >into tweaking and maybe creating their own macros. But I've been >delaying learning Python for ages so this may be a good time. If only >there was perl support as well... > > >Still, thank you all for you comments. >Carnë HTH -- Herbie ------------------------ <http://www.gluender.de> |
Free forum by Nabble | Edit this page |