;+ ; NAME: ; indxmap ; PURPOSE: (one line) ; Return indices from location array to 2-D map ; DESCRIPTION: ; Return indices from location array to 2-D map ; CATEGORY: ; Graphics ; CALLING SEQUENCE: ; indx_map = indxmap(name_loc2map=name_loc2map) ; KEYWORD INPUTS: ; name_loc2map : a string in the form or ->map_NLONMAP_NLATMAP ; OUTPUTS: ; indx_map - an array of values [n_lon_map, n_lat_map], each of which are ; in the range 0 .. n_loc-1 ; SIDE EFFECT ; Sets common blocks indx_map and name_loc2map ; MODIFICATION HISTORY: ; Written 2011 Aug 3, by Leslie Young, SwRI ; 2016 Apri 11, moved into Graphics directory ;- function indxmap, name_loc2map=name_loc2map common loc_map, indx_map_c, name_loc2map_c deg = !pi/180. ; First time called if n_elements(indx_map_c) eq 0 then begin name_loc2map_c = 'none->rect_1_1' indx_map_c = reform(-1,1,1) endif ; if called with no name, return the indx_map if not keyword_set(name_loc2map) then begin name_loc2map = name_loc2map_c return, indx_map_c endif name_loc2map_c = name_loc2map ; special cases case (name_loc2map) of 'latband_18->map_36_18': begin indx_map_c = replicate(1,36) # indgen(18) return, indx_map_c end 'latband_18->map_360_180': begin indx_map_c = rebin(replicate(1,36) # indgen(18),360,180) return, indx_map_c end 'rect_72_36->map_72_36' : begin indx_map_c = reform(lindgen(72*36), 72, 36) return, indx_map_c end 'rect_59_29->map_59_29' : begin indx_map_c = reform(lindgen(59*29L), 59,29) return, indx_map_c end 'onespot_0_180_10_10->map_72_36': begin indx_map_c = replicate(-1,72) # replicate(1,36) indx_map_c[35:36,17:18] = 0 return, indx_map_c end else: begin end end ; Not a special case. ; Separate out the loc and map name_lm = name_loc2map + '->map' tok_lm = strsplit(name_lm,'->',/ex) name_l = tok_lm[0] name_m = tok_lm[1] tok_m = strsplit(name_m,'_',/ex) if n_elements(tok_m) ne 3 then begin print_traceback, 'name_map ('+name_m_+') not of form map_nlat_nlon' n_lon_map = 1 n_lat_map = 1 endif else begin n_lon_map = long(tok_m[1]) n_lat_map = long(tok_m[2]) endelse lon_map_delta = 2*!dpi/n_lon_map lon_map_1d = ( dindgen(n_lon_map) + 0.5d ) * lon_map_delta lat_map_delta = !dpi/n_lat_map lat_map_1d = ( dindgen(n_lat_map) + 0.5d ) * lat_map_delta - !dpi/2.d indx_map_c = lonarr(n_lon_map, n_lat_map) - 1 if name_l eq '' then begin return, indx_map_c endif ; onespot if strmid(name_l,0,strlen('onespot')) eq 'onespot'then begin tok = ['onespot','180', '0', '10','10'] tok_str = strsplit(name_l,'_',/ex) tok[0:n_elements(tok_str)-1] = tok_str lon = float(tok[1]) * deg lat = float(tok[2]) * deg lon_delta = float(tok[3]) * deg lat_delta = float(tok[4]) * deg for i_lat_map = 0, n_lat_map-1 do begin _lat_map = lat_map_1d[i_lat_map] if abs(_lat_map - lat) lt lat_delta/2. then begin for i_lon_map = 0, n_lon_map-1 do begin _lon_map = lon_map_1d[i_lon_map] dlon = ( (_lon_map - lon + 180) mod 360 ) - 180 if abs(dlon) lt lon_delta/2. then begin indx_map_c[i_lon_map, i_lat_map] = 0 end endfor endif endfor return, indx_map_c endif ; latbad if strmid(name_l,0,strlen('latband')) eq 'latband'then begin n = name_l+'_18' ; default to n_lat = 18 tok = strsplit(n,'_',/ex) n_lat = long(tok[1]) indx_map_native = replicate(1,1) # indgen(n_lat) indx_map_c = CONGRID( indx_map_native, n_lon_map, n_lat_map,/CENTER) return, indx_map_c endif ; rect if strmid(name_l,0,strlen('rect')) eq 'rect'then begin n = name_l+'_36_18' ; default to n_lon = 36, n_lat = 18 tok = strsplit(n,'_',/ex) n_lon = long(tok[1]) n_lat = long(tok[2]) indx_map_native = reform(lindgen(n_lon*n_lat), n_lon, n_lat) indx_map_c = CONGRID( indx_map_native, n_lon_map, n_lat_map,/CENTER) return, indx_map_c endif return, indx_map_c end