;+ ; NAME: ; loc2map ; PURPOSE: (one line) ; Reform a location array to a map ; DESCRIPTION: ; Reform a location array (1D or 2D) to a map (2D or 3D) ; CATEGORY: ; Volatile Transport ; CALLING SEQUENCE: ; val_map = loc2map, val, map_indx, name_loc2map = name_loc2map ; INPUTS: ; val - a list of values. Either 1-D [n_loc] or 2-D [n_loc, n_other] ; INPUT/OUTPUT ; indx_map - an array of values [n_lon_map, n_lat_map], each of which are ; in the range 0 .. n_loc-1 ; KEYWORD INPUTS: ; name_loc2map : a string in the form or ->map_NLONMAP_NLATMAP ; OUTPUTS: ; val_map - a list of values. Either 2-D [n_lon_map, n_lat_map] or 3-D [n_lon_map, n_lat_map, n_other] ; PROCEDURE ; The mapping is done in this order: ; 1. if map_indx is defined and has length greater than 1, use map_index ; 2. if name_loc2map is defined and has a name_loc and name_map, use that ; 3 if name_map is undefined, default to rect_360_180 ; 4. if name_loc is undefined, try to guess from the size ; MODIFICATION HISTORY: ; Written 2011 Aug 3, by Leslie Young, SwRI ; 2016 Apri 11, moved into Graphics directory ;- function loc2map, val, indx_map, name_loc2map=name_loc2map, nan=nan common loc_map, indx_map_c, name_loc2map_c if n_elements(nan) eq 0 then nan = 0. n_dim_val = size(val, /n_dim) dim_val = size(val, /dim) n_loc = dim_val[0] indx_map = indxmap(name_loc2map=name_loc2map) nxnyn, indx_map, n_lon_map, n_lat_map ; mindx is an index into indx_map mindx_nan = where(indx_map lt 0 or indx_map ge n_loc, n_nan, compl=mindx_gd,ncomp=n_gd) if n_nan eq 0 then begin case n_dim_val of 0: begin map = replicate(val, n_lat_map, n_lon_map) return, map end 1: begin map = val[indx_map] return, map end 2: begin dim_val = size(val, /dim) n_loc = dim_val[0] n_else = n_elements(val)/n_loc type = size(val, /type) map = make_array(n_lon_map * n_lat_map, n_else, type=type,/noz) for i = 0, n_else-1 do map[*,i] = val[indx_map, i] return, reform(map, n_lon_map, n_lat_map, n_else) end else: begin dim_val = size(val, /dim) n_loc = dim_val[0] n_else = n_elements(val)/n_loc val2d = reform(val, n_loc, n_else) type = size(val, /type) map2d = make_array(n_lon_map * n_lat_map, n_else, type=type,/noz) for i = 0, n_else-1 do map2d[*,i] = val2d[map_indx, i] dim_map = [n_lon_map, n_lat_map, dim_val[1:n_dim_val-1]] map = make_array(dim=dim_map, type=type,/noz) map[*] = map2d[*] return, map end endcase endif if n_dim_val eq 0 then begin map = replicate(nan, n_lat_map, n_lon_map) map[mindx_gd] = val return, map end if n_dim_val eq 1 then begin map = make_array(n_lon_map * n_lat_map, type=type,/noz) map[*,*] = nan map[mindx_gd] = val[indx_map[mindx_gd]] return, reform(map, n_lon_map, n_lat_map) end if n_dim_val eq 2 then begin dim_val = size(val, /dim) n_loc = dim_val[0] n_else = n_elements(val)/n_loc type = size(val, /type) map = make_array(n_lon_map * n_lat_map, n_else, type=type,/noz) map[*,*] = nan for i = 0, n_else-1 do map[mindx_gd,i] = val[indx_map[mindx_gd], i] return, reform(map, n_lon_map, n_lat_map, n_else) end dim_val = size(val, /dim) n_loc = dim_val[0] n_else = n_elements(val)/n_loc val2d = reform(val, n_loc, n_else) type = size(val, /type) map2d = make_array(n_lon_map * n_lat_map, n_else, type=type,/noz) map2d[*,*] = nan for i = 0, n_else-1 do map2d[mindx_gd,i] = val2d[indx_map[mindx_gd], i] dim_map = [n_lon_map, n_lat_map, dim_val[1:n_dim_val-1]] map = make_array(dim=dim_map, type=type,/noz) map[*] = map2d[*] return, map end