FUNCTION DELCHR, OLD, C, help=hlp if (n_params(0) lt 2) or keyword_set(hlp) then begin print,' Delete all occurrences of a character from a text string.' print,' new = delchr(old, char)' print,' old = original text string. in' print,' char = character to delete. in' print,' new = resulting string. out' return, -1 endif B = BYTE(OLD) ; convert string to a byte array. CB = BYTE(C) ; convert char to byte. w = where(b ne cb(0)) if w(0) eq -1 then return, '' ; Nothing left. return, string(b(w)) ; Return new string. END FUNCTION ISNUMBER, TXT0, X, help=hlp if (n_params(0) lt 1) or keyword_set(hlp) then begin print,' Determine if a text string is a valid number.' print,' i = isnumber(txt, [x])' print,' txt = text string to test. in' print,' x = optionaly returned numeric value if valid. out' print,' i = test flag: out' print,' 0: not a number.' print,' 1: txt is a long integer.' print,' 2: txt is a float.' print,' -1: first word of txt is a long integer.' print,' -2: first word of txt is a float.' return, -1 endif TXT = STRTRIM(TXT0,2) ; trim blanks. X = 0 ; define X. IF TXT EQ '' THEN RETURN, 0 ; null string not a number. SN = 1 wrds = (strsplit(TXT,' ',/extract)) IF N_ELEMENTS(wrds) GT 1 THEN BEGIN ; get first word if more than one. SN = -1 TXT = wrds[0] ENDIF f_flag = 0 ; Floating flag. b = byte(txt) w = where(b eq 43, cnt) if cnt gt 1 then return, 0 t = delchr(txt,'+') w = where(b eq 45, cnt) if cnt gt 1 then return, 0 t = delchr(t,'-') w = where(b eq 46, cnt) ; '.' if cnt gt 1 then return, 0 ; May only be 1. if cnt eq 1 then f_flag = 1 ; If one then floating. t = delchr(t,'.') w = where(b eq 101, cnt) ; 'e' if cnt gt 1 then return, 0 if cnt eq 1 then f_flag = 1 t = delchr(t,'e') w = where(b eq 69, cnt) ; 'E' if cnt gt 1 then return, 0 if cnt eq 1 then f_flag = 1 t = delchr(t,'E') w = where(b eq 100, cnt) ; 'd' if cnt gt 1 then return, 0 if cnt eq 1 then f_flag = 1 t = delchr(t,'d') w = where(b eq 68, cnt) ; 'D' if cnt gt 1 then return, 0 if cnt eq 1 then f_flag = 1 t = delchr(t,'D') if total((b eq 101)+(b eq 69)+(b eq 100)+(b eq 68)) gt 1 then return,0 b = byte(t) if total((b ge 65) and (b le 122)) ne 0 then return, 0 c = strmid(t,0,1) if (c lt '0') or (c gt '9') then return, 0 ; First char not a digit. x = txt + 0.0 ; Convert to a float. if f_flag eq 1 then return, 2*sn ; Was floating. if x eq long(x) then begin x = long(x) return, sn endif else begin return, 2*sn endelse END pro read_speck_file, filename @common_blocks.inc lines = read_ascii_file_return_list_of_strings(filename) Nl = N_elements(lines) ; get fieldnames wheredatavar = where(strmatch(lines, '*datavar *') eq 1) names = ['x','y','z'] for i=0L,N_elements(wheredatavar)-1 do begin l = strsplit(lines[wheredatavar[i]],/extract) if N_elements(l) gt 2 then names = [names, l[2]] endfor print, names Nfields = N_elements(names) ; find the first line where the first word (of multiple) is a float headeratleast = max(wheredatavar) count = headeratleast+1 while (isnumber(lines[count]) ne -2) DO count += 1 ; read data into fltarr Np = Nl-count data = fltarr(Np, Nfields) nc = 0L while nc lt Nl-count do begin l = strsplit(lines[count+nc],/extract) if N_elements(l) eq Nfields then data[nc,*] = float(l) else print,'read_speck: wrong line ',nc,l nc++ endwhile parti.names = ptr_new(names) for i=0,Nfields-1 do begin parti.d[i] = ptr_new(data[* , i],/no_copy) parti.read[i] = 1 endfor print, count data_dim = 3 info = {grid, $ num: 0L, $ time: 0.D, $ timestep: 0L, $ parent: -1L, $ parent_s_index: INTARR(data_dim), $ parent_e_index: INTARR(data_dim), $ hier_file: '', $ level: 0, $ dim: INTARR(data_dim), $ Start_index: INTARR(data_dim), $ End_index: INTARR(data_dim), $ Left_edge: DBLARR(data_dim), $ Right_edge: DBLARR(data_dim), $ num_baryon_fields: 0 , $ num_particle: LONG(0) , $ baryon_file: '', $ particle_file:'', $ ngnl: 0L, $ ngtl: 0L $ } info.num_particle = Np info.baryon_file = filename info.particle_file = filename info.dim = [1,1,1] all_grid_info = info end