[ncl-talk] text res

Mary Haley haley at ucar.edu
Tue Oct 20 10:08:47 MDT 2015


Any graphical resource in NCL that ends in the word "Color" can be an
integer value, a color name ("blue"), an RGB triplet (/1.,0.,0./), or an
RGBA triplet (/1.,0.,0.,0.5/).

When you use an integer value, then NCL assumes you are using indexed
color, so it queries your workstation to see what the current color map is
associated with it, and uses the color associated with that index.

The problem in your case is that you have an array of 6 strings, and only
four of them have valid color names. The others are empty:

(0)    Red
(1)
(2)    Blue
(3)    Red
(4)    Yellow
(5)

The error message, "Unable to convert string "" to requested type" is
simply telling you that it doesn't recognize the color "". If you have a
blank color string, then this probably means that you had no values in that
range, and hence you should skip that particular step.

--Mary



On Tue, Oct 20, 2015 at 9:56 AM, Geeta Geeta <geetag54 at yahoo.com> wrote:

> Thanks Alan and Mary for your help.
> Thanks Alan. I have tried your way of defining the colors. It worked but
> with some warnings.
> I am getting warning message because txFontColor is an integer while I am
> passing a string variable I guess.
> ariable: colors
> Type: string
> Total Size: 24 bytes
>             6 values
> Number of Dimensions: 1
> Dimensions and sizes:    [6]
> Coordinates:
> Number Of Attributes: 1
>   _FillValue :    missing
> (0)    Red
> (1)
> (2)    Blue
> (3)    Red
> (4)    Yellow
> (5)
> fatal:CvtStringToColorIndex: Unable to convert string "" to requested type
> warning:Error retrieving resource txFontColor from args - Ignoring Arg
> fatal:CvtStringToColorIndex: Unable to convert string "" to requested type
> warning:Error retrieving resource txFontColor from args - Ignoring Arg
> aditya at agniilap:~/geeta/ncl$
> Pls clarify this Point (txFontColor = integer)
>
> Mary the script runs fine.  Thank you.
> I did not intend to send a message to you directly but since many tabs
> were open. It happened by mistake.
>
> Thanks
>
> Geeta.
>
>
>
> On Tuesday, 20 October 2015 12:32 AM, Mary Haley <haley at ucar.edu> wrote:
>
>
> Geeta,
>
> Please email all follow-up questions to ncl-talk at ucar.edu, and do not
> send them to me directly.
>
> You need to group the text strings by the color you want to render them
> in.  So, you should be looping across the number of ranges you have, and
> not each value. Your code would look something like this:
>
>   range_bot = (/   0.1,   2.5,      7.5/)
>   range_top = (/   2.5,   7.5,     15.5/)
>   colors    = (/"Blue", "Red", "Green"/)
>   nranges   = dimsizes(range_bot)
> ;
> ; Loop through each range and get the indices of
>
> ; all the values that fall in this range. These
>
> ; are the values that should be drawn in the given
>           ; ; color.
> ;
>
>   do n=0,nranges-1
>     ii := ind(rf.ge.range_bot(n).and.rf.lt.range_top(n))
>     if(.not.any(ismissing(ii))) then
>       txres at txFontColor = colors(n)     ; set the color for this range
>       unqstr = unique_string("text")    ; generate a unique id for text
> object
>       plot@$unqstr$ = gsn_add_text(wks,plot," "+sprintf("%9.4g",rf(ii)), \
>                                        lon(ii),lat(ii),txres)
>     end if
>   end do
>
>
> See the attached script, which is based on your script, but using random
> data.
>
> --Mary
>
>
> On Mon, Oct 19, 2015 at 11:02 AM, Geeta Geeta <geetag54 at yahoo.com> wrote:
>
>  Hi Mary.
> I have tried three things for giving a range to the rainfall. Pls see the
> lines 91 to 110 of my script.
>
>
>
> 1.  I tried the following.
>
> 1. print(nrf)
>      92   colors = where(((rf.ge.0.1).and.(rf.lt.2.5)),"Blue","   ")  ;
> This is a string variable
>      93   colors = where(((rf.ge.2.5).and.(rf.lt.7.5)),"Red","   ")
>      94 ;  colors = where(((rf.ge.7.5).and.(rf.lt.15.5)),"Yellow","   ")
>      95 ;  colorss= stringtoint(colors)
>
> 2nd Method in which I have defined the colors as an array. So there is
> error on line 106. Also this will give an individual color to each data.
> Variable: colors
> Type: integer
> Total Size: 16 bytes
>             4 values
> Number of Dimensions: 1
> Dimensions and sizes:    [4]
> Coordinates:
> (0)    1
> (1)    21
> (2)    41
> (3)    61
> fatal:Subscript out of range, error in subscript #0
> fatal:An error occurred reading colors
> fatal:["Execute.c":8578]:Execute: Error occurred at or near line 106 in
> file stn-v3.ncl
>
> aditya at agniilap:~/geeta/ncl$
>
> can U pls suggest???I also tried combining two statements with where but
> that did not work.
>  Geeta.
>
> Geeta.
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20151020/a80706b9/attachment.html 


More information about the ncl-talk mailing list