Re: gsn_add_text

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Tue, 27 Feb 2007 13:35:05 -0700 (MST)

On Tue, 27 Feb 2007, Sang-ki Lee wrote:

> Hi,
>
> I am trying put an array of text strings on a xy-plot by using
> "gsn_add_text". My text array should look like "87", "89", "01",
> "06". But, since the my text array is integer (or real) number,
> they appears like "87", "89", "1" "2" on the plot. How can I convert
> my data into character array?
>
> Thank you.
>
> Sang-ki

Hi Sang-ki,

You can use the "sprinti" function to format your integers and to
force a leading "0". To get "01" try this:

   i = 1
   s = sprinti("%0.2i",i)

For more examples, see the "Examples" section at:

   http://www.ncl.ucar.edu/Document/Functions/Built-in/sprinti.shtml

You could also do something completely different:

    if (i.lt.10) then
      s = "0" + i
    else
      s = "" + i
    end if

This is a bit kludgy, however, and I wouldn't recommend using
it in a "do" loop. I included the above so you can see the
sneaky method of quickly converting an integer to a string with:

      s = "" + i

--Mary

> ----------------------------------------------------------------------
> Dr. Sang-ki Lee
> RSMAS/CIMAS
> University of Miami
> 4600 Rickenbacker Causeway
> Miami, FL 33149 USA
> Tel) 305-361-4521
> Fax) 305-361-4412
> E-mail) sang-ki.lee_at_noaa.gov
> Homepage) http://www.aoml.noaa.gov/phod/people/sklee.html
> ----------------------------------------------------------------------
> Mailing-address:
> Dr. Sang-ki Lee
> AOML/PHOD
> 4301 Rickenbacker Causeway
> Miami, FL, 33149 USA
> ----------------------------------------------------------------------
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Feb 27 2007 - 13:35:05 MST

This archive was generated by hypermail 2.2.0 : Tue Feb 27 2007 - 13:43:39 MST