Function Ave, a1, a2, a3, a4, a5, a6, a7 ; This procedure will average 2-7 arrays. All the arrays are assumed to have the ; same dimensions and no error checking is done for this. On_Error, 1 ; Return to main IDL level n = N_Params() If n LT 2 Then $ ; Less than 2 Message, 'Minimum of 2 input arrays required' If n GT 7 Then $ ; More than 7 Message, 'Maximum of 7 input arrays allowed' dims = Size(a1) ; Arrays assumed to be same size col = dims(1) & row = dims(2) ; Build array ['1', '2', '3', '4', '5', '6', '7'] idx = StrTrim(IndGen(7) + 1, 2) sum = FltArr(col,row) output = FltArr(col, row) ; For j=0, n-1 Do Begin ; Add the arrays together str = 'output = output + a' + idx(j) check1 = Execute(str) ; Add the total for the divisor div = 'sum = sum + (a' + idx(j) + ' GT 0)' check2 = Execute(div) If check1 EQ 0 OR check2 EQ 0 Then $ Message, 'Function failed to execute' EndFor If (Min(sum) EQ 0) Then $ ; Check divide by 0 sum(Where(sum EQ 0)) = 1 Return, output/sum END