2.10) Structures (cont'd)
Perhaps of more use, structures can be used to hold arrays of data. In this example, we will create some arrays which hold information about some locations around the world and the group them into a structure. Insert the following code into a file called locations.pro.
name = ['London', 'Paris', 'Berlin', 'Rome', 'Madrid'] lats = [52.51, 48.85,52.52, 41.89, 40.42] lons = [-0.13, 2.35, 13.41, 12.48, -3.70] elevs = [21, 30, 36, 15, 638] places = {name:names, lat:lats, lon:lons, elev:elevs} END
Save the file and run the program in IDL.
.r locations
Use IDL help to get information about the structure.
If we want to access the data for a particular place, we can just use it's array index in conjunction with the tag name we want. So to print the name, latitude, longitude and elevation of London, we use:
print, places.name(0), places.lat(0), places.lon(0), places.elev(0)