; ; $Id$ ; ; Read time_series.dat and sort data into structure or variables ; ; Author: wd (Wolfgang.Dobler@kis.uni-freiburg.de) ; $Date: 2007-08-03 13:32:52 $ ; $Revision: 1.24 $ ; ; 14-nov-02/wolf: coded ; 27-nov-02/tony: ported to routine of standard structure ; 03-oct-13/MR : handling of complex data in timeseries added ; ; Requires: input_table.pro ; ; Usage: ; pc_read_ts, OBJECT=ts1 ; Read all into a structure (recommended) ; plot, ts1.t, ts1.urms ; help, ts1, /STRUCTURE ; ; pc_read_ts, T=time, DT=timestep ; Name variables (limited to those coded) ; ; pc_read_ts, /HELP ; ; function parse_tsheader, hline COMPILE_OPT IDL2,HIDDEN ; ; Split header line into the individual variable names. ; line = strmid(hline,strpos(hline,'#')+1) line2 = strmid(hline,strpos(hline,'%')+1) if (strlen(line2) lt strlen(line)) then line=line2 labels = [''] ; ; strsplit() is not available in IDL prior to 5.3 (and str_sep() was ; obsoleted after 5.2..), so we do this manually: ; while (line ne '') do begin repeat begin line = strmid(line,1) ; remove first character endrep until (strmid(line,0,1) ne '-') endlb = strpos(line,'-') labels = [labels, strmid(line,0,endlb)] line = strmid(line,endlb) endwhile ; ; Eliminate empty labels. ; good = where(labels ne '') return, labels[good] end ; ---------------------------------------------------------------------- ; function list_idx, label, list COMPILE_OPT IDL2,HIDDEN ; ; Return index if label is contained in list, else 0. ; return, (where(list eq label))[0] end ; ---------------------------------------------------------------------- ; function in_list, label, list COMPILE_OPT IDL2,HIDDEN ; ; Return 1 if label is contained in list, else 0. ; return, (list_idx(label,list)+1) ne 0 end ; ---------------------------------------------------------------------- ; pro pc_read_ts, $ filename=filename, datadir=datadir, object=object, double=double, $ print=print, quiet=quiet, help=help, verbose=verbose, $ num=num, it=it, t=t, dt=dt, dtc=dtc, urms=urms, labels=labels, $ ekin=ekin, eth=eth, rhom=rhom, ssm=ssm, trimfirst=trimfirst, $ movingaverage=movingaverage, monotone=monotone, njump=njump COMPILE_OPT IDL2,HIDDEN ; ; If no meaningful parameters are given show some help! ; if ( keyword_set(help) ) then begin print, "Usage: " print, "" print, "pc_read_ts, t=t," print, " object=object," print, " filename=filename," print, " movingaverage=maverage," print, " /print, /double, /quiet, /help" print, "" print, "Read time series data from time_series.dat into separate " print, "variables or a structure." print, "" print, " filename: specify the filename of the time series data [string]" print, " Default is 'time_series.dat' " print, " maverage: number of points to include in a moving [integer]" print, " average. (should probably be odd!) " print, " datadir: specify the path to the data directory [string]" print, " containing the time series file. " print, " Default is 'data' " print, " NB. if filename contains any / characters, datadir " print, " be ignored. " print, " njump: return time series data every njump lines [integer]" print, " " print, " num: number of entries (valid - not commented out) [long]" print, " it: array of time step numbers [long(n)]" print, " t: array containing time in code units [float(n)]" print, " dt: array of time step sizes [float(n)]" print, " dtc: time step limit by CFL condition [float(n)]" print, " urms: RMS velocity [float(n)]" print, " ekin: total kinetic energy [float(n)]" print, " eth: total thermal energy [float(n)]" print, " rhom: [float(n)]" print, " ssm: [float(n)]" print, "" print, " object: optional structure in which to return all [structure]" print, " the above as tags " print, "" print, " /double: instruction to read all values as double precision " print, " /print: instruction to print all variables to standard output " print, "/monotone: trim data so that time is monotonously increasing" print, " /quiet: instruction not to print any 'helpful' information " print, " /help: display this usage information, and exit " return endif ; ; Default data directory. ; datadir = pc_get_datadir(datadir) default, filename, 'time_series.dat' default, monotone, 0 default, njump, 1 default, movingaverage,0 ; if (strpos(filename,'/') eq -1) then begin fullfilename=datadir+'/'+filename endif else begin fullfilename=filename endelse ; ; Initialize / set default returns for ALL variables. ; num=0L it=0L t=0. dt=0. dtc=0. urms=0. ekin=0. eth=0. rhom=0. ssm=0. ; ; Get a unit number. ; get_lun, file ; ; read header ; ; Check for existence and read the data if (file_test(fullfilename)) then begin if ( not keyword_set(QUIET) ) THEN print, 'Reading ' + fullfilename + '...' openr, file, fullfilename line = '' repeat begin readf, file, line line = strtrim(line) hashpos = strpos(line,'#') hashpos2 = strpos(line,'%') if hashpos2 gt hashpos then hashpos=hashpos2 ;; identify header line as / *#--/ endrep until ((hashpos ge 0) and (strmid(line,hashpos+1,2) eq '--')) point_lun,-file,fileposition close,file free_lun,file end else begin free_lun,file message, 'ERROR: cannot find file ' + fullfilename endelse ; ; Read table. ; newheader=line full_data=0. full_labels='' while (fileposition ne -1) do begin labels = parse_tsheader(newheader) ncols = n_elements(labels) newheader='^#--' data = input_table(fullfilename,double=double, $ stop_at=newheader,fileposition=fileposition,verbose=verbose,inds_compl=inds_compl) if inds_compl[0] ne -1 then begin ; ; If there are complex quantities in output ; ninds=n_elements(inds_compl) nlabs=n_elements(labels) ; ; Replace the corresponding labels: