You may not have noticed the difference between 'B' and 'b'. 'B' means unsigned byte; small 'b' means signed byte.
The value you are entering as a signed byte is out of range. The range of a signed byte is -128 to +127.
If you enter a value that is out of range for this function, there may be some system dependencies in the result. 
But try 
print(tosigned(157B))
 
-dave
On Mar 30, 2014, at 11:10 PM, "yinjinfang88@163.com" <yinjinfang88@163.com> wrote:
> Hi  All,
>      I still get a wrong result.  For example
> ncl 0> print(tosigned(157b))
>  
> The reslult is
> (0)     157
>  
> However, the result should be 
> (0)     -99
>  
> This may suggest that there is something wrong with our setup. I am confused whether it is related to the computer hardware. I run NCL in a unix system  of AIX.
>  
> The returns of uname and gcc commands are shown
>  
> $uname -a
> AIX cma18n01 1 7 0007471BD400
>  
> $gcc --version
> gcc (GCC) 4.8.1
> Copyright (C) 2013 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>  
>   Yin
> Mar 31, 2014
>  
>  
> The origins of the problem are shown as follows:
>  
> I   got a strange error when I read TRMM version 7 Level 2 hdf file with NCL.  The variable in the hdf file is named as freezingHeightIndex with the 1-byte integer type.
>  
>  ncl 0> f = addfile("2A12.20100101.69095.7.HDF","r")   ; Add file
>  ncl 1> fzHIndex      = f->freezingHeightIndex                 ; read freezingHeightIndex
>  ncl 2> printVarSummary(fzHIndex)
>  
>  Variable: fzHIndex
>  Type: byte
>  Total Size: 607568 bytes
>               607568 values
>  Number of Dimensions: 2
>  Dimensions and sizes:   [nscan | 2921] x [npixel | 208]
>  
>  
>  I can get the values of freezingHeightIndex by the following command :
>  
>  ncl_filedump  -v  freezingHeightIndex  A12.20100101.69095.7.HDF
>  
> I can find a value of -99, and I can also find -99 by the HDFview.  (The -99 (byte) is a missing value but the variable has no such information associated with it)
>  
> However,   I got a strange result of 157 by the NCL read command:
>  
>  
> According to previous responses from ncl-talk, several functions have been used, but didn't solve the proble.
>  
> ncl 0> f = addfile("2A12.20100101.69095.7.HDF","r")   ; Add file
> ncl 1> fzHIndex      = f->freezingHeightIndex                 ; read freezingHeightIndex 
> ncl 2> printVarSummary(fzHIndex)
>  
> Variable: fzHIndex
> Type: byte
> Total Size: 607568 bytes
>             607568 values
> Number of Dimensions: 2
> Dimensions and sizes:   [nscan | 2921] x [npixel | 208]
> Coordinates: 
> Number Of Attributes: 1
>   hdf_name :    freezingHeightIndex
>  
> ncl 3> print("fzHIndex: min="+min(fzHIndex)+"   max="+max(fzHIndex))
> (0)     fzHIndex: min=0x01   max=0x9d
>  
> ncl 4> print("fzHIndex: min="+min(toshort(fzHIndex))+" max="+max(toshort(fzHIndex)))
> (0)     fzHIndex: min=1 max=157                    
>  
> ncl 5> print("fzHIndex: min="+min(toshort(fzHIndex))+" max="+max(toshort(fzHIndex)))
> (0)     fzHIndex: min=1 max=157
>  
> ncl 6> print("fzHIndex: min="+toshort(min(fzHIndex))+" max="+toshort(max(zHIndex)))
> (0)     fzHIndex: min=1 max=157
>  
> ncl 8> print("fzHIndex: min="+min(toint(fzHIndex))+" max="+max(toint(fzHIndex)))
> (0)     fzHIndex: min=1 max=157
>  
> ncl 9> print("fzHIndex: min="+toint(min(fzHIndex))+"   max="+toint(max(fzHIndex)))
> (0)     fzHIndex: min=1   max=157
>  
> ==============================
>  
> ncl 3> print(tounsigned(-99b))
>  
> (0)     157
>  
> ncl 5> print(tosigned(157b))
> (0)     157
>  
> Those test suggest that the  functions (toshort, tounsigned, etc) are not work.
>  
>  
>  
>  
>  
>  
>  
>  
> Yin Jin-Fang
> 
> Department of Earth Science, Zhejiang University, Hangzhou 310027, China
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Mar 31 11:21:48 2014
This archive was generated by hypermail 2.1.8 : Mon Mar 31 2014 - 11:47:09 MDT