; docformat = 'rst' ; ; NAME: ; lineStyleID ; PURPOSE: ; Provide a simple convertion between IDL linestyle numbers and description. ; ;+ ; :Description: ; Provide a simple convertion between IDL linestyle numbers and description. ; ; :Categories: ; graphics ; ; :Params: ; ID: in, required, type=integer/string ; Line style identifyer ; ; :Returns: The name of the linestyle, usable for plots ; ; :Examples: ; IDL> plot, randomn(10), linestyle=lineStyleID('--') ; ; :Uses: ; ; :Author: ; B.Carry (OCA) ; ; :History: ; Change History:: ; Original Version written in November 2014, B. Carry (IMCCE) ; 2016 Dec. - B. Carry (OCA) - Corrected bug occuring when ID was an array ;- function lineStyleID, ID ;--I-- Initialization And Input Verification ------------------------------------------ COMPILE_OPT hidden, idl2 if n_params() ne 1 then begin message, /ioError, 'Syntax: name = lineStyleID(ID)' return, -1 endif ;--II-- Dictionary of Line Styles ---------------------------------------------------- name = ['solid', 'dot', 'dash', 'dash dot', 'dash dot dot dot', 'long dash', 'none' ] code = ['-', ':', '--', '-.', '-:', '__', ' '] ;--III-- Convert Input ID into Line Style Name --------------------------------------- if size(ID,/type) eq 7 then begin ;--III.1-- Provided ID is a Name test = strLowCase(strTrim(ID[0],2)) pos=where( strCmp(name,test) ) if pos[0] eq -1 then begin ;--III.2-- Provided ID is a Code bis=where(strCmp(code,test,/fold)) ;--III.3-- Invalid Input ID (n.a.) if bis[0] eq -1 then begin message, 'Unknown input code: '+strtrim(string(ID,format='(A)'),2) return, -1 endif else return, bis endif else return, pos endif else begin ;--III.4-- Invalid Input ID (N>max) if ID gt 6 then begin message, /ioError, 'Input code must be between 0 and 6' return, -1 endif ;--III.5-- Input ID is a Number return, name(ID) endelse end