; docformat = 'rst' ; ; NAME: ; ssoSpaceToUnderscore ; PURPOSE: ; Replace spaces by underscores in SSO Names ; ;+ ; :Description: ; Replace spaces by underscores in SSO Names ; ; :Categories: ; Database, SSO ; ; :Params: ; name: in, required, type=string ; The name of the SSO ; ; :Returns: The same name as upon input, with spaces replaced by ; underscores if applicable. ; ; :Examples: ; IDL> print, ssoSpaceToUnderscore('2004 TG25') ; IDL> print, ssoSpaceToUnderscore('Ceres') ; ; :Uses: ; ; :Author: ; B.Carry (OCA) ; ; :History: ; Change History:: ; Written in October 2015, B. Carry (OCA) ;- function ssoSpaceToUnderscore, name ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- I -- Initialization And Input Verification -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; COMPILE_OPT hidden, idl2 ;--I.1-- Test Input Variable Presence ------------------------------------------------- if not keyword_set(name) then begin message, /IOERROR, 'Syntax error: name_2 = ssoSpaceToUnderscore(name)' return, -1 endif ;--I.2-- Prepare Output --------------------------------------------------------------- output=strtrim(name,2) nbName = n_elements(name) ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- II -- Replace Spaces by Underscore -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; for kName=0, nbName-1 do begin ;--II.1-- Search for Space ------------------------------------------------------------- pos = strpos( name[kName], ' ') ;--II.2-- Replace Space by Underscore -------------------------------------------------- if pos[0] ne -1 then begin swap=name[kName] strput, swap, '_', pos[0] output[kName]=swap endif endfor return, output end