pro move_files2, dir_in, dir_out, spec, qdelete, prefix_arr
;
;
;
qdebug = 0
qdelete = 0
if (n_elements(prefix_arr) eq 0) then prefix_arr = ['ada', 'bda', 'hda', 'wda', 'spr', 'sfr']

print, 'MOVE_FILES2.PRO Run on ', !stime
print, 'Input Directories: ', dir_in
print, 'Output Directories: ', dir_out
;
;dir_in = [finddir('reformat_a1', /makecre), finddir('reformat_a2', /makecre)]	&  dir_out = '/yd4/92_13a'	& spec = ''
;dir_in = '/yd3/reformat' & dir_out = '/yd6/reformat' & spec = '9204' + string(indgen(4)+1, format='(i2.2)') & qdelete = 1
;dir_in = '/yd5/92_08a' & dir_out = '/yd7/92_08a' & spec = '' & qdelete = 0
;dir_in = '/yd2/reformat_a1' & dir_out = '/yd5/91_52a' & spec = '' & qdelete = 0
;dir_in = '/yd3/reformat' & dir_out = '/yd4/reformat' & spec = '92040' & qdelete = 1
;dir_in = [finddir('reformat_b1'), finddir('reformat_b2')]	&  dir_out = '/yd5/92_14a'	& spec = ''	& qdelete = 1
;dir_in = [finddir('reformat_a1'), finddir('reformat_a2')]	&  dir_out = '/yd10/92_15a'	& spec = ''	& qdelete = 1
;dir_in = [finddir('reformat_b1'), finddir('reformat_b2')]	&  dir_out = '/yd8/92_16a'	& spec = ''	& qdelete = 1
;dir_in = [finddir('reformat_a1'), finddir('reformat_a2')]	&  dir_out = '/yd9/92_08a'	& spec = ''	& qdelete = 1
;dir_in = [finddir('reformat_b1'), finddir('reformat_b2')]	&  dir_out = '/yd7/91_40a'	& spec = ''	& qdelete = 1
;dir_in = [finddir('reformat_a1'), finddir('reformat_a2')]	&  dir_out = '/yd11/92_17a'	& spec = ''	& qdelete = 1
;dir_in = [finddir('reformat_a1'), finddir('reformat_a2')]	&  dir_out = '/yd4/92_20a'	& spec = ''	& qdelete = 1
;dir_in = [finddir('reformat_b1'), finddir('reformat_b2')]	&  dir_out = '/yd4/91_43a'	& spec = ''	& qdelete = 1
;dir_in = [finddir('reformat_a1'), finddir('reformat_a2')]	&  dir_out = '/yd9/92_04a'	& spec = ''	& qdelete = 1
;dir_in = [finddir('reformat_b1'), finddir('reformat_b2')]	&  dir_out = '/yd14/91_44a'	& spec = ''	& qdelete = 0
;spec = ['91102']		;27,28,29
;dir_in = [finddir('reformat_b1'), finddir('reformat_b2')]	&  dir_out = '/yd9/91_44b'	& spec = ''	& qdelete = 0
;spec = ['91103', '9111']	;30,31,1,2
;dir_in = [finddir('reformat_a1'), finddir('reformat_a2')]	&  dir_out = '/yd5/92_21a'	& spec = ''	& qdelete = 1
;dir_in = [finddir('reformat_b1'), finddir('reformat_b2')]	&  dir_out = '/yd9/91_45a'	& spec = ''	& qdelete = 1


if (n_elements(dir_in) gt 1) then if (dir_in(1) eq '') then dir_in = dir_in(0)	;no such second directory
if (n_elements(dir_in) gt 1) then begin
    ff = file_list(dir_in(1), '*')
    if (ff(0) eq '') then dir_in = dir_in(0)	;second directory is empty
end
;
grand_tot = 0
grand_run_time = 0
for i=0,n_elements(prefix_arr)-1 do begin
    ff = file_list(dir_in, prefix_arr(i)+'*')
    tot = 0
    ;
    st_time = systime(1)
    for idir=0,n_elements(dir_in)-1 do for j=0,n_elements(spec)-1 do begin
	in_str  = concat_dir(dir_in(idir), prefix_arr(i)+spec(j)+'*')
	out_str = concat_dir(dir_out, '.')
	if (qdelete) then cmd0 = 'mv ' else cmd0 = 'cp -p '
	cmd = cmd0 + in_str + '  ' + out_str

	tot = tot + disktot(in_str)/1e+6

	if (qdebug) then print, cmd else spawn, cmd, result

	;;if (result(0) ne '') then print, cmd, ' ********************* NOT EXECUTED ******************** '
	;;if (qdelete and (result(0) eq '')) then begin
	;;    cmd = 'rm -f ' + in_str
	;;    if (qdebug) then print, cmd else spawn, cmd
	;;end
    end
    en_time = systime(1)
    run_time = (en_time-st_time)/60.
    fmt = '(a, a, f7.2, a, f8.3, a, f8.3, a)'
    print, '  '+strupcase(prefix_arr(i)), ' copy took ', run_time, ' minutes for ', $
			tot, ' megabyte = ', (tot*1000)/(run_time*60), ' kbyte/sec', format=fmt

    grand_tot = grand_tot + tot
    grand_run_time = grand_run_time + run_time
end
print, 'Total', ' copy took ', grand_run_time, ' minutes for ', $
			grand_tot, ' megabyte = ', (grand_tot*1000)/(grand_run_time*60), ' kbyte/sec', format=fmt
;
cmd = 'rm -f ' + concat_dir(dir_out, '*temp')
spawn, cmd
;
bell
end
;------------------------------------------------------------------------------
 dir_a = [finddir('reformat_a1'), finddir('reformat_a2')]
 dir_b = [finddir('reformat_b1'), finddir('reformat_b2')]

;move_files2, dir_a, '/yd9/91_46a', '9111' + string(indgen(3)+10, format='(i2.2)'), 		0
;move_files2, dir_a, '/yd4/91_46b', '9111' + string(indgen(2)+13, format='(i2.2)'),		0
;move_files2, dir_a, '/yd5/91_46c', '9111' + string(indgen(2)+15, format='(i2.2)'),		0
;move_files2, dir_a, '/yd5/91_46c', '9111' + string(indgen(1)+16, format='(i2.2)'),		0
;
;move_files2, dir_b, '/yd10/91_47a', '',		0

;move_files2, dir_a, '/yd13/91_48a', '',		0

;move_files2, dir_b, '/yd8/92_22a', '',			0
;move_files2, '/yd8/92_22a', '/yd10/92_22b', '920530',	1
;move_files2, dir_b, '/yd10/92_22b', '920530',		0, 'sfr'

 move_files2, dir_a, '/yd9/92_05a', '',		0

end

