;+ ; NAME: ; TimePosn_test ; PURPOSE: ; (Internal use by timeposn only) ; Tests for a number of ntest chars in ctest ; CATEGORY: ; gen/idl/toolbox/time ; CALLING SEQUENCE: FUNCTION TimePosn_test, ctest, ntest, cbreak, trail, lead, $ complement = complement , $ reverse_order = reverse_order , $ test_null = test_null ; INPUTS: ; ctest array; type: string ; array of strings to be tested ; Typically ctest is the "front" return argument of a call ; to href=strposn= called with /frontdefault set, i.e. ; ctest will end with the cbreak char, or is the remaining ; part of the string tested with strposn if no cbreak ; was present. ; ntest scalar; type: integer ; we are looking for isolated sequence of ntest numbers ; at the start (/reverse_order NOT set) or the end of ; ctest (/reverse_order SET). ; cbreak scalar; type: string ; The break char used in the strposn call (usually '_') ; (only used if /reverse_order SET) ; OPTIONAL INPUT PARAMETERS: ; OUTPUTS: ; result array; type: integer ; indices in ctest where strmid(ctest,0,ntest) ; is a self-contained number (i.e. numerical chars ; only, NOT followed by another numerical char) ; ctest array; type: string ; ctest[result] contains the self-contained ; numbers (i.e. the length of these substrings ; is ntest). The other entries in ctest are ; unmodified. ; lead array; type: string ; if /reverse_order is NOT set: array of null strings. ; if /reverse_order SET: part of ctest preceeding ; an isolated sequence of numbers. ; trail array; type: string ; trail[result] is the trailing part (not ; returned in ctest[result]. The other entries ; in trail are blank strings ; OPTIONAL OUTPUT PARAMETERS: ; complement=complement ; complement of the return index array ; i.e. indices in ctest that do not contain an ; isolated sequence of numbers ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; strreverse, where_common ; PROCEDURE: ; MODIFICATION HISTORY: ; JUL-2005, Paul Hick (UCSD/CASS) ; DEC-2007, Paul Hick (UCSD/CASS) ; Added keyword /reverse_order ; MAR-2008, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Added keyword /test_null ;- InitVar, reverse_order, /key InitVar, test_null, /key test_null AND= cbreak EQ '' CASE reverse_order OF 0: BEGIN ; Look for sequence at beginning of ctest trail = strmid(ctest,ntest,1) ; Char following first ntest chars in ctest i = strlen(ctest) i = i EQ ntest OR ( i GT ntest AND (test_null OR trail LT '0' OR trail GT '9') ) i = 1-i ; i=0: char ntest in ctest is not a number ; i=1: char ntest in ctest is a number FOR j=0,ntest-1 DO BEGIN c1 = strmid(ctest,j,1) ; Char j in ctest i += c1 LT '0' OR c1 GT '9' ENDFOR i <= 1 ; Entries in i are now 0 or 1. ; 0: chars [0..ntest-1] are numbers; and char ntest is not a number ; (i.e., ctest[0:ntest-1] is a sequence of numbers) i = where(1-i,complement=complement); Self-contained numbers trail = strarr(n_elements(ctest)) lead = trail IF i[0] NE -1 THEN BEGIN trail[i] = strmid(ctest[i],ntest) ; Usually this is cbreak ctest[i] = strmid(ctest[i],0,ntest) ; The number ENDIF END 1: BEGIN ; Look for sequence at end of ctest nobreak = where( strmid(ctest,0, /reverse) NE cbreak ) IF nobreak[0] NE -1 THEN ctest[nobreak] += cbreak ctest = strreverse(ctest) ; The reversed ctest now starts with cbreak for all elements i = strlen(ctest) LE ntest FOR j=1,ntest DO BEGIN c1 = strmid(ctest,j,1) ; Char j in ctest i += c1 LT '0' OR c1 GT '9' ENDFOR i <= 1 i = where(1-i,complement=complement) ; Self-contained numbers trail = strarr(n_elements(ctest)) lead = trail IF i[0] NE -1 THEN BEGIN lead [i] = strmid(ctest[i],ntest+1) trail[i] = strmid(ctest[i],0,1) ctest[i] = strmid(ctest[i],1,ntest) j = where_common(i,nobreak) IF j[0] NE -1 THEN trail[j] = strmid(trail[j],1) ENDIF ELSE BEGIN j = where_common(complement,nobreak) IF j[0] NE -1 THEN ctest[j] = strmid(ctest[j],1) ENDELSE lead = strreverse(lead) trail = strreverse(trail) ctest = strreverse(ctest) END ENDCASE RETURN, i & END