pro expand_arrays, arr_ptr_array, new_array, dims, fill ; given an array of pointers to arrays & the new bounding dimensions, ; make a new array that contains the arrays with "empty" space containing ; the fill value where needed vind = (where(arr_ptr_array ne ptr_new()))[0] if (vind lt 0) then begin ; all null pointers; return a fill array if (n_elements(dims) eq 1) and (dims[0] eq 1) then $ new_array = [ fix(fill, type=1) ] $ else $ new_array = make_array(dim=dims, type=1, value=fill) return endif n = n_elements(arr_ptr_array) n_ptr_dims = size(arr_ptr_array, /n_dimensions) n_dims = n_elements(dims) if (n_dims gt 1) and (dims[n_elements(dims)-1] eq 1) then begin last_ind = max(where(dims ne 1)) if last_ind lt 0 then $ dims = [1] $ else $ dims = dims[0:last_ind] n_dims = n_elements(dims) endif atype = size(*arr_ptr_array[vind], /type) new_array = make_array(dim=dims, type=atype, value=fill) n_tmp_dims = n_dims-n_ptr_dims if (n_tmp_dims eq 0) then begin for j=0L,n-1 do begin cur_ptr = arr_ptr_array[j] if (cur_ptr ne ptr_new()) then $ new_array[j] = *cur_ptr endfor return endif else begin if n_ptr_dims gt 1 then begin ; have a multi-dimensional pointer array: ; temporarily reform new_array into something ; easier to process (as if there was 1 ptr_dim) n_dims = n_tmp_dims + 1 new_array = reform(new_array, [ dims[0:n_tmp_dims-1], n ], /overwrite) endif for j=0L,n-1 do begin cur_ptr = arr_ptr_array[j] if (cur_ptr ne ptr_new()) then begin case n_dims of 1: new_array[j] = *cur_ptr 2: new_array[0,j] = *cur_ptr 3: new_array[0,0,j] = *cur_ptr 4: new_array[0,0,0,j] = *cur_ptr 5: new_array[0,0,0,0,j] = *cur_ptr 6: new_array[0,0,0,0,0,j] = *cur_ptr 7: new_array[0,0,0,0,0,0,j] = *cur_ptr 8: new_array[0,0,0,0,0,0,0,j] = *cur_ptr endcase endif endfor if n_ptr_dims gt 1 then begin ; put new_array back the way it should be new_array = reform(new_array, dims, /overwrite) endif endelse end