-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added extra files and put routines from external sources in separate folder.
- Loading branch information
1 parent
c5d84fd
commit ba71599
Showing
8 changed files
with
417 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
;+ | ||
; NAME: | ||
; COUNTER | ||
; PURPOSE: | ||
; Print a progress status to the screen on a single | ||
; line. This is WAY cooler than it sounds. | ||
; | ||
; CALLING SEQUENCE: | ||
; COUNTER, NUMBER, OUTOF [,INFOSTRING, /PERCENT, WAIT_TIME=variable] | ||
; | ||
; INPUTS: | ||
; NUMBER: The current number. Usually the loop index variable | ||
; OUTOF: The total number of iterations. The last loop index | ||
; | ||
; OPTIONAL INPUTS: | ||
; | ||
; INFOSTRING: A string telling the user what is being | ||
; counted e.g. 'Flat ' | ||
; | ||
; KEYWORD PARAMETERS: | ||
; | ||
; PERCENT: Set to output update in percent completed | ||
; percent = rount(number/outof) * 100 | ||
; | ||
; TIMELEFT: Set to append estimated time remaining. | ||
; STARTTIME= Used in conjunction w/ /TIMELEFT. Named variable | ||
; that stores the start time of the loop, used for | ||
; calculation of time remaining | ||
; | ||
; WAIT_TIME: Used for test and demo purposes only. See | ||
; example below. | ||
; | ||
; OUTPUTS: | ||
; Status is printed to the screen and updated on a single line. | ||
; | ||
; SIDE EFFECTS: | ||
; This program takes much longer than a simple | ||
; print statement. So use COUNTER judiciously. | ||
; If your loop consists of only a couple | ||
; of relatively quick commands, updating the | ||
; status with this program could take up a | ||
; significant portion of the loop time! | ||
|
||
; PROCEDURE: | ||
; Put counter statement inside your loop, preferably at the end. | ||
; | ||
; PROCEDURES CALLED: fifteenb.pro | ||
; | ||
; EXAMPLE: | ||
; Try this to see how it works: | ||
; | ||
; IDL> for i = 0,4 do counter,i,4,'test ',wait=.5 | ||
; | ||
; | ||
; MODIFICATION HISTORY: | ||
; Written by JohnJohn, Berkeley 06 January 2003 | ||
; 07-Apr-2008 JohnJohn: Finally fixed /TIMELEFT and STARTTIME keywords | ||
;- | ||
|
||
pro counter,num,outof,infostring $ | ||
,wait_time = waittime $ | ||
,percent=percent $ | ||
,clear=clear $ | ||
,timeleft=timeleft $ | ||
,starttime=starttime | ||
on_error,2 | ||
clearline = fifteenb() ;get "15b character to create a fresh line | ||
if n_elements(infostring) eq 0 then infostring = 'Number ' | ||
if keyword_set(clear) then begin | ||
if keyword_set(timeleft) then begin | ||
timeinit = {t0: systime(/sec), tot: 0.} | ||
defsysv,'!time',timeinit | ||
return | ||
endif else begin | ||
len = strlen(infostring) | ||
print,clearline,format='('+strtrim(len,2)+'x, a)' | ||
return | ||
endelse | ||
endif | ||
|
||
case 1 of | ||
keyword_set(timeleft): begin | ||
if n_elements(starttime) eq 0 then begin | ||
starttime = systime(/sec) | ||
endif else begin | ||
tottime = (systime(/sec) - starttime) | ||
tave = tottime / float(num) | ||
tleft = sixty((outof-num) * tave/3600.) | ||
tleft = strjoin(str(fix(tleft),len=2), ':') | ||
len = strtrim(strlen(strtrim(tleft,2)),2) | ||
lenst = strtrim(strlen(infostring),2) | ||
leni = strtrim(strlen(strtrim(num,2)),2) | ||
leno = strtrim(strlen(strtrim(outof,2)),2) | ||
form = "($,a"+lenst+",i"+leni+",' of ',i" | ||
form += leno+",' Estimated time remaining: ',a"+len+",a,a)" | ||
print, form=form, infostring, num, outof $ | ||
, tleft, ' ', clearline | ||
endelse | ||
end | ||
keyword_set(percent) : begin | ||
per = strtrim(round(float(num)*100./outof),2) | ||
lenp = strtrim(strlen(strtrim(per,2)),2) | ||
form="($,a"+lenp+",' % Completed',a,a)" | ||
print, form=form, per, ' ', clearline | ||
end | ||
else : begin | ||
lenst = strtrim(strlen(infostring),2) | ||
leni = strtrim(strlen(strtrim(num,2)),2) | ||
leno = strtrim(strlen(strtrim(outof,2)),2) | ||
form="($,a"+lenst+",i"+leni+",' of ',i"+leno+",a,a)" | ||
print, form=form, infostring, num, outof, ' ',clearline | ||
end | ||
endcase | ||
if n_elements(waittime) gt 0 then wait,waittime | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
;+ | ||
; NAME: | ||
; FIFTEENB | ||
; | ||
; | ||
; PURPOSE: | ||
; Return the string version of the octal character | ||
; "15b which print's a new line to the screen. Used | ||
; by COUNTER.PRO This is a separate routine because the | ||
; unclosed quotation mark messes up IDLWAVE in Emacs, and | ||
; I can't have that! | ||
; | ||
; CATEGORY: | ||
; | ||
; | ||
; | ||
; CALLING SEQUENCE: | ||
; | ||
; result = fifteenb() | ||
; | ||
; INPUTS: | ||
; | ||
; | ||
; | ||
; OPTIONAL INPUTS: | ||
; | ||
; | ||
; | ||
; KEYWORD PARAMETERS: | ||
; | ||
; | ||
; | ||
; OUTPUTS: | ||
; | ||
; result is set to string("15b) | ||
; | ||
; OPTIONAL OUTPUTS: | ||
; | ||
; | ||
; | ||
; COMMON BLOCKS: | ||
; | ||
; | ||
; | ||
; SIDE EFFECTS: | ||
; | ||
; | ||
; | ||
; RESTRICTIONS: | ||
; | ||
; | ||
; | ||
; PROCEDURE: | ||
; | ||
; | ||
; | ||
; EXAMPLE: | ||
; | ||
; | ||
; | ||
; MODIFICATION HISTORY: | ||
; | ||
;- | ||
|
||
function fifteenb | ||
return,string("15b) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
;+ | ||
; NAME: | ||
; STR | ||
; | ||
; | ||
; PURPOSE: | ||
; Convert numerical values to a string and trim off | ||
; white space. Works better than IDL's STRING for quick and | ||
; dirty string formatting. | ||
; | ||
; | ||
; CALLING SEQUENCE: | ||
; result = str(num) | ||
; | ||
; | ||
; INPUTS: | ||
; num: Scalar or vector numbers to be converted to string | ||
; values. | ||
; | ||
; | ||
; KEYWORD PARAMETERS: | ||
; LENGTH: For integer values, this specifies the total string | ||
; length of the returned value including leading or trailing | ||
; characters. | ||
; | ||
; FORMAT: Conventional Fortran-style formatting string | ||
; | ||
; TRAIL: By defaul, characters are added to the front of integer | ||
; values, e.g. str(1, char='0', length=3) returns 001 | ||
; | ||
; CHARACTER: The fill character to be used. Default is '0' | ||
; | ||
; OUTPUTS: | ||
; RESULT: The resulting string | ||
; | ||
; EXAMPLE: | ||
; | ||
; IDL> print,str(1) | ||
; 1 | ||
; IDL> print,str(1, char='0', length=3) | ||
; 001 | ||
; IDL> print,str(1, char='*', length=3, /trail) | ||
; 1** | ||
; IDL> print,str(1.0, format='(f3.1)') | ||
; 1.0 | ||
; | ||
; MODIFICATION HISTORY: | ||
; Created sometime in 2003 by JohnJohn | ||
;- | ||
|
||
function str,number,length=length,format=format,trail=trail,character=char | ||
on_error,2 | ||
n = n_elements(number) | ||
s = strtrim(string(number,format=format),2) | ||
if 1-keyword_set(char) then char = '0' | ||
if n_elements(length) gt 0 then begin | ||
ilen = strlen(s) | ||
for i = 0,n-1 do begin | ||
nz = length-ilen[i] | ||
if nz gt 0 then begin | ||
for j=0,nz-1 do begin | ||
if keyword_set(trail) then s[i] = s[i]+char else $ | ||
s[i] = char+s[i] | ||
endfor | ||
endif | ||
endfor | ||
endif | ||
return,s | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
;+ | ||
; NAME: | ||
; CONSEC | ||
; | ||
; PURPOSE: | ||
; Finds sets of consecutive numbers in | ||
; an array. | ||
; | ||
; CALLING SEQUENCE: | ||
; CONSEC, ARRAY, LO, HI [, NUM, /SAME] | ||
; | ||
; INPUTS: | ||
; ARRAY: Umm, the array. | ||
; | ||
; KEYWORDS: | ||
; SAME: Search for elements which are the same, rather than | ||
; consecutive. | ||
; OUTPUTS: | ||
; LO: The lower index limit of each set | ||
; of consecutive numbers. Each set | ||
; goes from LO_i to HI_i | ||
; | ||
; HI: The upper index limit | ||
; | ||
; OPTIONAL OUTPUTS: | ||
; NUM: The number of sets. | ||
; DISTRIBUTION: Array containing the number of elements in each | ||
; set | ||
; | ||
; OPTIONAL KEYWORDS: | ||
; SAME: Search for consecutive elements containing the same value. | ||
; | ||
; EXAMPLE: | ||
; | ||
; IDL> a = [findgen(3),findgen(3)+6] | ||
; IDL> print,a | ||
; 0.00000 1.00000 2.00000 6.00000 7.00000 8.00000 | ||
; | ||
; IDL> consec,a,l,h,n | ||
; IDL> print,l | ||
; 0 3 | ||
; IDL> print,h | ||
; 2 5 | ||
; IDL> print,n | ||
; 2 | ||
; IDL> print,a[l[0]:h[0]] | ||
; 0.00000 1.00000 2.00000 | ||
; | ||
; MODIFICATION HISTORY: | ||
; Written in January 2003 by JohnJohn | ||
; 5-13-2003 JohnJohn Added SAME keyword | ||
; 4-16-2005 JohnJohn Found a bug where -1 was returned if there | ||
; were only two identical elemeents and /SAME. New logic introduced | ||
; to deal with this special case. Also added DISTRIBUTION keyword. | ||
; | ||
;- | ||
|
||
pro consec, a, l, h, n, same=same, distribution=dist | ||
on_error,2 | ||
nel = n_elements(a) | ||
case nel of | ||
1: begin | ||
l = 0 | ||
h = 0 | ||
n = 1 | ||
end | ||
2: begin | ||
if keyword_set(same) then begin | ||
if a[1] - a[0] eq 0 then begin | ||
l = 0 | ||
h = 1 | ||
n = 1 | ||
endif else begin | ||
l = -1 | ||
h = -1 | ||
n = 0 | ||
endelse | ||
endif else begin | ||
if abs(a[1] - a[0]) eq 1 then begin | ||
l = 0 | ||
h = 1 | ||
n = 1 | ||
endif else begin | ||
l = -1 | ||
h = -1 | ||
n = 0 | ||
endelse | ||
endelse | ||
end | ||
else: begin | ||
if not keyword_set(same) then begin | ||
arr = [a[0],a,a[nel-1]] ;add fat | ||
cond1 = abs(arr - shift(arr,1)) eq 1 | ||
cond2 = abs(arr - shift(arr,-1)) eq 1 | ||
range = indgen(nel)+1 ;trim fat | ||
endif else begin | ||
arr = [a[0]+1,a,a[nel-1]-1] ;add fat | ||
cond1 = abs(arr - shift(arr,1)) eq 0 | ||
cond2 = abs(arr - shift(arr,-1)) eq 0 | ||
range = indgen(nel)+1 ;trim fat | ||
endelse | ||
l = where(cond2[range] and not cond1[range], nl) | ||
h = where(cond1[range] and not cond2[range], nh) | ||
if nh*nl eq 0 then begin | ||
l = -1 | ||
h = -1 | ||
n = 0 | ||
endif else n = nh < nl | ||
end | ||
endcase | ||
if l[0] ne h[0] then dist = h-l+1 else dist = 0 | ||
|
||
end |
Oops, something went wrong.