I am using readfits.pro program to read the FITS file which is giving array of struct type. Which program should I use so that I can find the sum of the elements the obtained array?
How to find the sum of array elements using idl\gdl program?
886 views Asked by Arya Stark At
2
I can answer for the case of using MRDFITS, which you described in the comments of Dick Jackson's answer,
What I think you are getting is an array of structures. And it looks like each structure has a single field, populated with a single float. To illustrate, I defined an array of those structures, using your values for b, and I arbitrarily named the field "data":
I get the same output as you when I print it:
So, I'm pretty sure this is what your data looks like. To check it for yourself,
help
is your friend.This tells you that b is an array of structures. You can pass the
/structure
keyword (/str
for short) to get info on makeup of the structures within the array:This says that the first element of the array b, is a structure with a field called 'data', which points to a float value of 1.61571e-13. Alternately, you could just use
help
with the individual structures by indexing the array b:I find arrays of structures to be super useful because you can easily look at an individual structure, or you can easily make an array out of a particular field from all the structures. In other words, to get at your data, simply use the structure.field notation, and you have a vector made of the floats from each of the three structures in the array:
Finally, to get the sum, use
total()
as Dick Jackson suggested: