Re: Generic type converter

From: Wei Huang <huangwei_at_nyahnyahspammersnyahnyah>
Date: Thu May 17 2012 - 20:49:30 MDT

Dave,

Have you tried the toxxx functions?
where xxx can be: double, float, string, int, short, long, etc.

for example, y = tofloat(x) will convert any NCL type of x which
can be converted to float to y as float.

Wei

huangwei@ucar.edu
VETS/CISL
National Center for Atmospheric Research
P.O. Box 3000 (1850 Table Mesa Dr.)
Boulder, CO 80307-3000 USA
(303) 497-8924

On May 17, 2012, at 4:26 PM, Dave Allured wrote:

> All,
>
> To support some generic data processing, I would like to find a
> numeric type converter that takes a numeric (or double) input, and
> converts to a numeric type specified by a string "type" argument such
> as argument 2 of the "new" function. For example:
>
> y = type_convert (x, "float")
>
> Or more generically, what I am really trying to do:
>
> y = type_convert (x, data_type)
>
> Where "data_type" is a string containing the name of any legal NCL data type.
>
> The following does not work for some output types, because NCL checks
> for loss of precision in assignments, a valuable feature.
>
> y = new (1, data_type)
> y = x
>
> Does anyone know a nice way to do this without a stack of if
> statements? I did not find anything like this on the type converters
> page. Thank you.
>
> --Dave
> _______________________________________________
> 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 Thu May 17 20:49:43 2012

This archive was generated by hypermail 2.1.8 : Fri May 25 2012 - 08:35:50 MDT