Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


next up previous contents index
Next: os - Tool Up: misc - Tool Previous: misc.listfields - Function


misc.tovector - Function



Package utility
Module misc
Tool misc


Convert variable to a vector


Synopsis
tovector(thing, type, unsetvalue)



Arguments

thing   Variable to convert
    Allowed: Any Glish variable
type   Specify the output type of the vector
    Allowed: String chosen from `string', `float', `double', `integer'
    Default: 'string'
unsetvalue   Unset value for unset items in records
    Allowed: Numeric value
    Default: unset


Returns
Vector of given type or fail



Description
This function converts a Glish variable to a vector of the given type. It is a bit specialized, and ultimately this functionality should be moved to a central parsing location like entryparser.g

Its purpose is so that a vector variable can be specified as a vector, a string, or a vector of strings. Thus no matter how the vector is entered to Glish, the right thing comes back. It is really meant for numeric and string vectors. If you put in what you want out (e.g. input a float vector and ask for the output to be a float vector) that is ok. If the input is a string, you can use space or comma or both delimiters.

After attempting to convert the input (argument thing) to a vector, it is type converted to the specified type.

The unsetvalue argument is only relevant if the input thing is a record. Then, any fields in the record that are unset, are replaced by unsetvalue. If unsetvalue=unset and a record field is unset, then an exception will be thrown. The record fields are then converted to vector of the appropriate type.



Example
- dms.tovector("1 2.2 3", 'double')     # Vector of strings
[1 2.2 3]  
- dms.tovector('1 2.2 3', 'double')     # String (space delimiters)
[1 2.2 3]  
- dms.tovector('1,  2.2,  3', 'double') # String (space and comma delimiters)
[1 2.2 3]  
- dms.tovector([1,2.2,3], 'float')      # Numeric vector
[1 2.2 3]  
- dms.tovector([1,2.2,3], 'integer')    # Float -> integer
- r := [=]
- r.a := '1'
- r.b := unset                          # Unset field
- r.c := 2
- dms.tovector(r,'float', 20)           # Record -> float
[1 20 2]








next up previous contents index
Next: os - Tool Up: misc - Tool Previous: misc.listfields - Function   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15