X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 18 Sep 2015 11:15 AM by  anon
Trailing Singleton Dimensions of Structure Fields
 2 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
18 Sep 2015 11:15 AM
    Is there a *good* way to programmatically determine whether or not a structure field contains trailing singleton dimensions? The HELP procedure correctly lists the trailing dimensions, but when you access the field it is stripped of those dimensions. I could use the OUTPUT keyword to HELP, however that is not ideal and not recommended by IDL. Here is an example: ; Create structure with a 5x1 field. ; Inspect the structure and its field. IDL> a = {field:reform(lindgen(5),5,1)} IDL> help, a ** Structure , 1 tags, length=20, data length=20, refs=1: FIELD LONG Array[5, 1] IDL> help, a.field LONG = Array[5] You can see that the help on the structure shows the field to be 2-dimensional while help on the field itself shows it to be 1-dimensional. This is important to a routine I have where I treat fields of different number of dimensions differently.

    Zachary Norman



    Basic Member


    Posts:173
    Basic Member


    --
    22 Sep 2015 12:02 PM
    Hi Paul, That does seem off that the wrong dimensions are being returned. I'm going to look around and see if I can't find any information on that behavior. Apart from that,here is a small example that could show you how to do this to check the array dimensions of all the structure fields, although it is not much help if the array dimensions are different than expected. pro structure_data_tags compile_opt idl2 arr1 = reform(make_array(10, /float), 10, 1) arr2 = make_array(10, /float) struct = {arr1:arr1, arr2:arr2} tags = tag_names(struct) for i=0, n_elements(tags)-1 do begin print, tags[i] print, size(struct.(i), /dimensions) endfor end

    Zachary Norman



    Basic Member


    Posts:173
    Basic Member


    --
    23 Sep 2015 09:55 AM
    As it turns out, trailing dimensions of 1 are almost always removed by any operation in IDL except by REFORM. This means that when you define a structure with a 5 by 1 array, the trailing dimension of 1 goes away. A good workaround might be to use the SIZE function without any keywords. Here is an example of what SIZE returns: IDL> size(reform(findgen(5),5,1)) 2 5 1 4 5 IDL> size(findgen(5,1)) 1 5 4 5 The first value returned by size is the number of dimensions followed by the actual dimensions. The first call to SIZE tells you there are two dimensions and that it is a 5 by 1 array. The second call to SIZE tells you that there is one dimension and is it a 5 element array. The last two numbers for each call to SIZE are the type code and the total number of elements.
    You are not authorized to post a reply.