pro export_particles_for_ralf, only_current=ocurrent @TOOLS/common_blocks.inc if N_ELEMENTS(*parti.names) eq 0 or (*parti.names)[0] eq '' then return names = (*parti.names) filename = DIALOG_PICKFILE(FILTER="*.mdmp", PATH=data_dir, $ FILE=default_filename, DIALOG_PARENT=BASE2, $ TITLE="Select ralfs particles mdmp Export Filename", $ GET_PATH=data_dir, /NOCONFIRM, /WRITE, $ /OVERWRITE_PROMPT) if filename eq '' then return mdmp_pos = strpos(filename, '.mdmp') if mdmp_pos lt 0 then begin print, 'export_particles_for_ralf:', filename, ' filename has to end in .mdmp' return endif if N_elements(ocurrent) eq 0 then begin ocurrent = 0 these_grids = all_grid_info endif else these_grids=grid_info ind = where(these_grids.num_particle gt 0, count) if count gt 0 then these_grids = these_grids[ind] else begin print, 'export_particles_for_ralf: no grids with particles found' return endelse h = histogram(these_grids.timestep, reverse_indices=r) ntimesteps = N_elements(where(h gt 0)) slashisat = strpos(filename, '/', /reverse_search) fbase = strmid(filename, 0, mdmp_pos)+'_' rfbase = strmid(filename, slashisat+1, mdmp_pos-slashisat-1)+'_' openw, lun, filename, /get_lun nfields = N_elements(names) printf, lun, '#point format(ASCII) V00' for i=0, 3 do begin thisi = i if i eq 3 then thisi = parti.index ; make sure the 4th colums is what is selected in GUI printf, lun, '#datavar'+strcompress(i-3)+' '+strcompress(names[thisi], /remove_all) endfor for i=0L, Ntimesteps-1 do begin ts = these_grids[r[r[i]]].time printf, lun, strcompress(ts), ' '+ strcompress(i) + ' '+rfbase+string(i, format='(i5.5)')+'.dmp' endfor close, lun free_lun, lun typeind = where(*parti.names eq 'particle_type', count) if count ge 0 then fieldstoread = (*parti.names)[[0,1,2,parti.index, typeind]] $ else fieldstoread = (*parti.names)[[0,1,2,parti.index]] cnt = 0L for i=0L, Ntimesteps-1 do begin ; write indivdual times into separate files thisfile = fbase+string(i, format='(i5.5)')+'.dmp' ;breaki openw, lun, thisfile, /get_lun if h[i] gt 1 then begin ngrids = r[i+1]-r[i] ; cg = get_particle_data(these_grids[r[r[i]]:r[(r[i+1]-1)]], ; (*parti.names)) cg = get_particle_data(these_grids[r[r[i]]:r[(r[i+1]-1)]], fieldstoread) ts = these_grids[r[r[i]]].time ; printf, lun, 'datatime ', strcompress(i),' # time:', strcompress(ts), ' ',strcompress(ngrids), ' grids' for j=0L,N_elements(cg)-1 do begin ca = cg[j] if ptr_valid(ca.data[0]) then nparticles = N_elements(*ca.data[0]) else nparticles=-1 for k=0L,nparticles-1 do begin line = '' if typeind[0] ge 0 then ctype = (*ca.data[4])[k] else ctype = parti.type if ((parti.type eq 0) or (ctype eq parti.type)) and (cnt mod parti.every) eq 0 then begin for ii=0, 3 do begin line = line + strcompress((*ca.data[ii])[k]) endfor printf, lun, line endif cnt += cnt endfor endfor printf, lun, '' endif close, lun free_lun, lun endfor return end