;+ ; NAME: merope_payload.pro ; Brian Larsen ; Space Science and Engineering Lab ; larsen@ssel.montana.edu ; ; ; PURPOSE: Bin the MEROPE geiger tube data into a format that is useable ; in the analysis of the data ; ; INPUTS: 'data filename' (note the quotes -> ') ; ; OPTIONAL INPUTS: ; binsize= - sets binsize (default=10) ; /notitles - omits the standard titles on output ; /ylog - plot the y axis as a log scale ; title= - add a custom title ; subtitle= - add a custom subtitle ; xtitle= - add a custom x title ; ytitle= - add a custom y title ; xrange= - set xrange to a value different than whole histogram ; eg: xrange=[2,5] ; ps= - sets output to postscript and filename (remember ; quotes ' ;) ; /portait - when using ps plots in portriat mode ; /nostats - do not calculate statistics on the histogram (output ; to screen) ; jpg= - sets output to jpg and filename (remember quotes ' ;) ; /stop - tells the program to stop at the end maintaining variables ; cps= - sets the counts per stamp (N) also changes titles ; ; OUTPUTS: ; histogram plot of the data file with specified bin size ; ; COMMON BLOCKS: ; none ; ; SIDE EFFECTS: ; none (that i know of) ; ; RESTRICTIONS: ; a little limited, use it and you'll see ; ; EXAMPLE: ; merope_payload, '06212002a.payload', binsize=20 ; ; MODIFICATION HISTORY: ; 06-20-2002 (BAL) first draft written and data display thought through ; 06-25-2002 a lot of i/o added as well as interface to strip.c for data ; formatting. (BAL) ; 06-27-2002 (BAL) ; - added a case statement for keywords and neatened things up a lot ; - used read_ascii to make the interface to strip.c no longer needed ; 07-01-2002 ; - found plot_hist and implemented it and its options (looks nice) ; - implemented a ps option for plotting ; 07-02-2002 ; - implemented merope2rt() as a way to keep all the secs/tick in onle ; place for all routines. ; - various cosmetic chamges in the code to shorten it (trim, etc) ; 07-18-2002 ; - added statistics on the screen report ; - added support for jpg output ; ;- FUNCTION rt2merope, oldtime RETURN, (oldtime/merope2rt(1)) END pro plot_hist_MEROPE, data, x, h, bin=bin, xrange=xrange, yrange=yrange, $ title=title, log=log, noerase=noerase, $ linestyle=linestyle, charsize=charsize, $ oplot=oplot, xstyle=xstyle, $ ystyle=ystyle, xticklen=xticklen, yticklen=yticklen, $ xmargin=xmargin, ymargin=ymargin, xtitle=xtitle, $ ytitle=ytitle, CPS=cps ; ;+ ;NAME: ; plot_hist ;PURPOSE: ; To plot a histogram with a properly labeled X axis. ;SAMPLE CALLING SEQUENCE: ; plot_hist, img ; plot_hist, img, x, h ; plot_hist, img, bin=0.1 ; plot_hist, img, xrange=xrange, yrange=yrange, tit=tit ;INPUT: ; data - The data to perform the historam on ;OUTPUT: ; x - The x axis for the plotting ; h - The histogram ;OPTIONAL KEYWORD INPUTS: ; bin - The bin size to use (default is 1) ; xrange - The x plotting range ; yrange - The y plotting range ; [x,y]style - See plot keyword options ; {x,y]margin - See plot keyword options ; [x,y]ticklen - See plot keyword options ; [x,y]title - Optional titles for the x and y axes ; title - The title ; log - If set, then plot the y axis in log form ;HISTORY: ; Written Apr-95 by M.Morrison ; 18-May-95 (MDM) - Added /LOG switch ; - Plot such that the minimum occurance is 0.1 ; 7-Jul-95 (MDM) - Fixed the plot so that min occurance is 0.1 ; 27-Nov-95 (LWA) - Added noerase, linestyle, charsize keywords. ; 8-Nov-96 (MDM) - Merged 27-Nov-95 changes with the ones below: ; 17-May-96 (MDM) - Added xtitle ; 11-Sep-96 (MDM) - Added ROUND when creating "data0" ; 8-Nov-96 (MDM) - Added "oplot" option ; 21-Apr-99 (LWA) - Added xstyle and ystyle keywords. ; 30-Apr-99 (LWA) - Added [x,y]ticklen, [x,y]title, [x,y]margin keywords. ; 31-jul-02 Brian Larsen larsen@ssel.montana.edu - modifed for ; MEROEPE purposes ;- ; if (n_elements(bin) eq 0) then bin = 1 ; data0 = round(data/bin) h = histogram(data0) IF KEYWORD_SET(cps) THEN BEGIN h = h*cps/bin ENDIF n = n_elements(h) amin = min(data0) x = findgen(n)*bin + long(amin)*bin ; if NOT keyword_set(charsize) then charsize=0 else charsize=charsize if NOT keyword_set(linestyle) then linestyle=0 else linestyle=linestyle if NOT keyword_set(xstyle) then xstyle=0 else xstyle=xstyle if NOT keyword_set(ystyle) then ystyle=0 else ystyle=ystyle if NOT keyword_set(xticklen) then xticklen=0 else xticklen=xticklen if NOT keyword_set(yticklen) then yticklen=0 else yticklen=yticklen if NOT keyword_set(xmargin) then xmargin=[10,3] else xmargin=xmargin if NOT keyword_set(ymargin) then ymargin=[4,2] else ymargin=ymargin if (n_elements(xrange) eq 0) then xrange = [min(x), max(x)] if (n_elements(yrange) eq 0) then yrange = [min(h)>0.1, max(h)] if (n_elements(title) eq 0) then title = '' else title=title if (n_elements(xtitle) eq 0) then xtitle = 'Value' else xtitle=xtitle if (n_elements(ytitle) eq 0) then ytitle='# of Occurrences' else ytitle=ytitle ; if (keyword_set(oplot)) then begin oplot, x, h, psym=10, linestyle=linestyle END ELSE BEGIN plot, x, h, psym=10, ytitle=ytitle, xtitle=xtitle, $ xrange=xrange, yrange=yrange, title=title, ytype=keyword_set(log), $ noerase=noerase, linestyle=linestyle, charsize=charsize, $ xstyle=xstyle, ystyle=ystyle, xticklen=xticklen, yticklen=yticklen, $ xmargin=xmargin, ymargin=ymargin END ; END ;------------------------------------------------------------------ PRO merope_payload, filename, BINSIZE=binsize, PS=ps, $ NOTITLES=notitles, YLOG=ylog, $ XRANGE=xrange, TITLE=title, SUBTITLE=subtitle, $ XTITLE=xtitle, YTITLE=ytitle, PORTAIT=portait, $ NOSTATS=nostats, JPG=jpg, STOP=stop, CPS=cps ; add some error checking here ;fn = size(filename) ;IF fn[1] NE 7 THEN BEGIN ; print, 'You must have the filename in quotes' ; ;ENDIF ; set up the template struct for the data files ;form = {version: 1.0, datastart: 2l, delimiter:'', $ ; MISSINGVALUE:!VALUES.F_NAN, commentsymbol:'', $ ; fieldcount:2l, fieldtypes:[7, 5], $ ; fieldnames:['payload', 'stamp'], fieldlocations:[0l, 9l], $ ; fieldgroups:[0, 1]} ; as defined by ascii_template ;data = read_ascii(filename,template=form) recnum = get_recno(filename) openr, lun, filename, /get_lun a = '' ;prep as string READF, lun, a ; Read a line of data (header) READF, lun, a ; Read a line of data (blank) i = 0l data1 = dblarr(recnum-2) WHILE NOT EOF(lun) DO BEGIN READF, lun, a ; Read a line of data data1(i) = double(strmid(a, 8, 8)) i = i+1 ENDWHILE ;sec_per_tick = 73.728e-3 in a seperate function now so that it ;doesnt have to be changed all over the place data1 = temporary(merope2rt(data1)) ; transform the data to real time not sysclk time tf = data1[n_elements(data1)-1] ; initial and final times t0 = data1[0] ; what to do based on keywords inputted IF KEYWORD_SET(binsize) THEN BEGIN binsize = floor(rt2merope(binsize)) binsize = merope2rt(binsize) ENDIF ELSE binsize = merope2rt(27) ;~2s IF NOT KEYWORD_SET(NOTITLES) THEN BEGIN ; not set ; set up default titles if none given IF KEYWORD_SET(subtitle) EQ 0 THEN $ subtitle = trim(t0) + $ 's to ' + trim(tf) + $ 's' + ' ' + filename IF KEYWORD_SET(title) EQ 0 THEN title='MEROPE payload data ' + subtitle IF KEYWORD_SET(xtitle) EQ 0 THEN xtitle='Time '+ $ ' binsize=' + trim(binsize)+'s' IF NOT KEYWORD_SET(ytitle) THEN BEGIN IF NOT KEYWORD_SET(cps) THEN ytitle='frequency (stamps/bin)' IF KEYWORD_SET(cps) THEN BEGIN ytitle='count rate (counts/sec)' cps = double(cps) ENDIF ENDIF IF KEYWORD_SET(xrange) EQ 0 THEN xrange=[t0, tf] END ; am i plotting to ps? IF KEYWORD_SET(ps) AND keyword_set(portait) THEN setps, ps IF keyword_set(ps) AND NOT keyword_set(portait) THEN setps, ps, /land plot_hist_MEROPE, data1, x, h, TITLE=title, XTITLE=xtitle, YTITLE=ytitle, $ LOG=ylog, bin=binsize, XRANGE=xrange, YRANGE=yrange, CPS=cps IF KEYWORD_SET(ps) THEN BEGIN device, /close set_x ENDIF IF KEYWORD_SET(jpg) AND NOT KEYWORD_SET(ps) THEN BEGIN x2jpg, jpg wdelete ENDIF print, '' print, 'Binsize used is MEROPE2RT('+trim(rt2merope(binsize))+')' ;;lets output a little info to the terminal just as FYI IF NOT KEYWORD_SET(nostats) THEN BEGIN stats = moment(h, /double, MDEV=mdev, SDEV=sdev) PRINT, '' & $ PRINT, '# stamps: ', TRIM(N_ELEMENTS(data1)) & $ PRINT, 'Mean: ', TRIM(stats[0]) & $ PRINT, 'Variance: ', TRIM(stats[1]) & $ PRINT, 'STD DEV: ', TRIM(sdev) & $ PRINT, 'ABS DEV: ', TRIM(mdev) & $ PRINT, 'Skewness: ', TRIM(stats[2]) & $ PRINT, 'Kurtosis: ', TRIM(stats[3]) ENDIF IF KEYWORD_SET(stop) THEN stop bailout: END