About Chandra Archive Proposer Instruments & Calibration Newsletters Data Analysis HelpDesk Calibration Database NASA Archives & Centers Chandra Science Links

Skip the navigation links
Last modified: December 2006

URL: http://cxc.harvard.edu/ciao3.4/array_map.tm.html
Hardcopy (PDF): A4 | Letter
AHELP for CIAO 3.4 array_map Context: slangrtl

Synopsis

Apply a function to each element of an array

Syntax

Array_Type array_map (type, func, arg0, ...)

Description

    DataType_Type type;
    Ref_Type func;

The array_map function may be used to apply a function to each element of an array and returns the result as an array of a specified type. The type parameter indicates what kind of array should be returned and generally corresponds to the return type of the function. The arg0 parameter should be an array and is used to determine the dimensions of the resulting array. If any subsequent arguments correspond to an array of the same size, then those array elements will be passed in parallel with the first arrays arguments.

Example

The first example illustrates how to apply the strlen function to an array of strings:

     S = ["", "Train", "Subway", "Car"];
     L = array_map (Integer_Type, &strlen, S);

This is equivalent to:

     S = ["", "Train", "Subway", "Car"];
     L = Integer_Type [length (S)];
     for (i = 0; i < length (S); i++) L[i] = strlen (S[i]);

Now consider an example involving the strcat function:

     files = ["slang", "slstring", "slarray"];

     exts = ".c";
     cfiles = array_map (String_Type, &strcat, files, exts);
     % ==> cfiles = ["slang.c slstring.c slarray.c"];

     exts =  [".a",".b",".c"];
     xfiles = array_map (String_Type, &strcat, files, exts);
     % ==> xfiles = ["slang.a", "slstring.b", "slarray.c"];

Many mathemetical functions already work transparantly on arrays. For example, the following two statements produce identical results:

     B = sin (A);
     B = array_map (Double_Type, &sin, A);
Hardcopy (PDF): A4 | Letter
Last modified: December 2006



The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory.
60 Garden Street, Cambridge, MA 02138 USA.    Email: cxcweb@head.cfa.harvard.edu
Smithsonian Institution, Copyright © 1998-2004. All rights reserved.