Login  Register

Macro language and non-ASCII characters

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Macro language and non-ASCII characters

Michael Doube-4
Dear all,

It seems like non-ASCII characters aren't handled by the macro interpreter, maybe in a platform-dependent way.

Most recently, this macro code gives a NaN result instead of the correct value from the table:

a = getResult("Vol. (µm³)", 0);
print(a);

After running BoneJ's Analyse Particles command. Seems like the ³ breaks it. Previously I broke the macro language by putting a ü in a menu item.

I had a look into the code and fail to see the source of the breakage. Can I make a request that someone more enlightened points me towards the right spot, or somehow makes the macro language understand Unicode?

Michael



[http://www.rvc.ac.uk/cf_images/button_rvc.png]<http://www.rvc.ac.uk>    [http://www.rvc.ac.uk/cf_images/button_twitter.png] <http://twitter.com/RoyalVetCollege>     [http://www.rvc.ac.uk/cf_images/button_facebook.png] <http://www.facebook.com/theRVC>

This message, together with any attachments, is intended for the stated addressee(s) only and may contain privileged or confidential information. Any views or opinions presented are solely those of the author and do not necessarily represent those of the Royal Veterinary College (RVC). If you are not the intended recipient, please notify the sender and be advised that you have received this message in error and that any use, dissemination, forwarding, printing, or copying is strictly prohibited. Unless stated expressly in this email, this email does not create, form part of, or vary any contractual or unilateral obligation. Email communication cannot be guaranteed to be secure or error free as information could be intercepted, corrupted, amended, lost, destroyed, incomplete or contain viruses. Therefore, we do not accept liability for any such matters or their consequences. Communication with us by email will be taken as acceptance of the risks inherent in doing so.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Macro language and non-ASCII characters

Michael Schmid
Hi Michael,

no such problem on Mac OS X or Wine (emulated Windows on OS X):

setResult("with space", 0, 1);
setResult("Vol. (µm³)", 0, 2);
getResult("with space", 0); //gives 1 in the Log window
getResult("Vol. (µm³)", 0); //gives 2

Note, however, that spaces or tabs should be avoided in column names - there are cases where spaces or tabs cause a problem, e.g.
  http://rsb.info.nih.gov/ij/macros/examples/PrintResults.txt

Concerning special characters: Java uses unicode, there should be no problems with it, but there are a few pitfalls:

For the 'µ' character, there are a few possibilities in Unicode, the Micro Sign 00B5, the greek mu 03BC, and more in the extended set of math alphanumeric symbols. In your email, it looks like the Micro Sign 00B5, but I don't know what you have in the column header.

If you have a macro file, make sure that file.encoding in Plugins>Utilities>ImageJ Properties matches the encoding of the file (does ImageJ display the macro correctly when opened in a text window?). To avoid file encoding problems, usually it is best to use only ascii characters in macros and Java sourcecode. Instead of the special characters, use the fromCharCode macro function:

muChar = fromCharCode(0xb5);
cubeChar = fromCharCode(0xb3);
getResult("Vol. ("+ muChar +"m"+ cubeChar +")", 0);

Michael
________________________________________________________________
On Mar 25, 2013, at 18:08, Doube, Michael wrote:

> Dear all,
>
> It seems like non-ASCII characters aren't handled by the macro interpreter, maybe in a platform-dependent way.
>
> Most recently, this macro code gives a NaN result instead of the correct value from the table:
>
> a = getResult("Vol. (µm³)", 0);
> print(a);
>
> After running BoneJ's Analyse Particles command. Seems like the ³ breaks it. Previously I broke the macro language by putting a ü in a menu item.
>
> I had a look into the code and fail to see the source of the breakage. Can I make a request that someone more enlightened points me towards the right spot, or somehow makes the macro language understand Unicode?
>
> Michael

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Macro language and non-ASCII characters

Michael Doube-4
Hi Michael

(adding to the large and growing tally of beers I owe you)
apologies in advance for lame Outlook web client not understanding quoting in replies.

-----------------------
no such problem on Mac OS X or Wine (emulated Windows on OS X):

setResult("with space", 0, 1);
setResult("Vol. (µm³)", 0, 2);
getResult("with space", 0); //gives 1 in the Log window
getResult("Vol. (µm³)", 0); //gives 2
----------------------------

Works here too, run as a macro on Ubuntu. Which makes me wonder what is happening with the code. Changing ³ to ^3 in the Java source fixed it for my user, and I'm pretty sure I'm using micron and not Greek mu.

----------------
Note, however, that spaces or tabs should be avoided in column names - there are cases where spaces or tabs cause a problem
--------------

Yeah, I remember that one for GenericDialog menu items too.

-------------
If you have a macro file, make sure that file.encoding in Plugins>Utilities>ImageJ Properties matches the encoding of the file (does ImageJ display the macro correctly when opened in a text window?).

 To avoid file encoding problems, usually it is best to use only ascii characters in macros and Java sourcecode. Instead of the special characters, use the fromCharCode macro function:

muChar = fromCharCode(0xb5);
cubeChar = fromCharCode(0xb3);
getResult("Vol. ("+ muChar +"m"+ cubeChar +")", 0);

------------------

Good hints, I will pass them on.

Michael
[http://www.rvc.ac.uk/cf_images/button_rvc.png]<http://www.rvc.ac.uk>    [http://www.rvc.ac.uk/cf_images/button_twitter.png] <http://twitter.com/RoyalVetCollege>     [http://www.rvc.ac.uk/cf_images/button_facebook.png] <http://www.facebook.com/theRVC>

This message, together with any attachments, is intended for the stated addressee(s) only and may contain privileged or confidential information. Any views or opinions presented are solely those of the author and do not necessarily represent those of the Royal Veterinary College (RVC). If you are not the intended recipient, please notify the sender and be advised that you have received this message in error and that any use, dissemination, forwarding, printing, or copying is strictly prohibited. Unless stated expressly in this email, this email does not create, form part of, or vary any contractual or unilateral obligation. Email communication cannot be guaranteed to be secure or error free as information could be intercepted, corrupted, amended, lost, destroyed, incomplete or contain viruses. Therefore, we do not accept liability for any such matters or their consequences. Communication with us by email will be taken as acceptance of the risks inherent in doing so.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Macro language and non-ASCII characters

Michael Doube-4
This was the problem
-----------
If you have a macro file, make sure that file.encoding in Plugins>Utilities>ImageJ Properties matches the encoding of the file (does ImageJ display the macro correctly when opened in a text window?).
--------------
It was set to MacRoman, which apparently is the default for Java on Mac, and in which there isn't a ³ . You can change it by putting a line into .bashrc.

This worked:
-----------------
use the fromCharCode macro function:

muChar = fromCharCode(0xb5);
cubeChar = fromCharCode(0xb3);
getResult("Vol. ("+ muChar +"m"+ cubeChar +")", 0);
------------------

Michael
[http://www.rvc.ac.uk/cf_images/button_rvc.png]<http://www.rvc.ac.uk>    [http://www.rvc.ac.uk/cf_images/button_twitter.png] <http://twitter.com/RoyalVetCollege>     [http://www.rvc.ac.uk/cf_images/button_facebook.png] <http://www.facebook.com/theRVC>

This message, together with any attachments, is intended for the stated addressee(s) only and may contain privileged or confidential information. Any views or opinions presented are solely those of the author and do not necessarily represent those of the Royal Veterinary College (RVC). If you are not the intended recipient, please notify the sender and be advised that you have received this message in error and that any use, dissemination, forwarding, printing, or copying is strictly prohibited. Unless stated expressly in this email, this email does not create, form part of, or vary any contractual or unilateral obligation. Email communication cannot be guaranteed to be secure or error free as information could be intercepted, corrupted, amended, lost, destroyed, incomplete or contain viruses. Therefore, we do not accept liability for any such matters or their consequences. Communication with us by email will be taken as acceptance of the risks inherent in doing so.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html