pro mk_mo_disk, mo_disk, dev=dev, qdebug=qdebug
;
;+
;NAME:
;	mk_mo_disk
;PURPOSE:
;	This is a program to copy the Yohkoh data from exabyte to
;	MO Disk
;SAMPLE CALLING SEQUENCE:
;	mk_mo_disk, '/mo/flare15.0'
;	mk_mo_disk, '/mo/flare15.0', dev=1
;	mk_mo_disk, '/mo/flare15.0', dev=1, /qdebug
;INPUT:
;	mo_disk	- The MO directory name
;OPTIONAL KEYWORD INPUT:
;	dev	- The device name for the exabyte.  If not passed,
;		  it uses device 0.
;	qdebug	- If set, do not execute the spawn commands to 
;		  create the directories and do not call RDTAP
;HISTORY:
;	Written 3-Feb-92 by M.Morrison (really 3-Feb-1993, gal)
;	modified, 4-Feb-93, by GAL, corrected usage of tape dev var,
;			and range switch on rd_tap.
;	modified, 5-Feb-93, correct cd command, gal.
;               3-Oct-95, LS, changed path to new mo_mount style /mo/flareN.X
;                       changed default machine to flare15
;                       have to parse mo_disk 's new style
;
;-
;
if (n_elements(mo_disk) eq 0) then mo_disk = '/mo/flare15.0'
if (n_elements(dev) eq 0) then begin
  dev = def_tapd(0)
endif else begin
  devsz = size(dev)
  If devsz(devsz(0)+1) ne 7 then dev = def_tapd(dev)	;get the name
endelse
;
infil = concat_dir('$DIR_GEN_MO', 'mdm')
restgen, mdm, file=infil			;MO Disk Map
;
n = n_elements(mdm)
label = strarr(n)
fmt = '(i3.3, a, 2x, a, 3x, a, 6x, a, 2x, a, i5)'
for i=0,n-1 do begin
    mdm0 = mdm(i)
    label(i) = string(mdm0.mo_disk, string(mdm0.st$side), string(mdm0.st$label), string(mdm0.st$week), $
		string(mdm0.st$first_fid), string(mdm0.st$last_fid), mdm0.nfid, format=fmt)
end
label_sides = strmid(label, 0, 18)
;string(mdm.mo_disk, format='(i3.3)') does not do the right thing
;
ss = uniq(label_sides)
usides = label_sides(ss)
umdm = mdm(ss)
;
iside = wmenu_sel(usides, /one)
if (iside(0) eq -1) then stop		;aborted
side2do = usides(iside)
side2do = side2do(0)		;turn into scalar
;
ss2 = where(label_sides eq side2do)
if (n_elements(ss2) eq 1) then begin
    ipart = 0
end else begin
    ipart = wmenu_sel(label(ss2), /one)
    if (ipart(0) eq -1) then stop		;aborted
end
;
mdm2do = mdm(ss2(ipart))
first_fid = string(mdm2do.st$first_fid)
last_fid = string(mdm2do.st$last_fid)
;
tt = string(mdm2do.mo_disk, format='(i3.3)')
if (string(mdm2do.st$side) eq 'A') then begin
    tape_label = tt + '   ' + string(umdm(iside).st$label)  + ' / ' + string(umdm(iside+1).st$label)
end else begin
    tape_label = tt + '   ' + string(umdm(iside-1).st$label)  + ' / ' + string(umdm(iside).st$label)
end
fileID = [first_fid, last_fid]			;gal change var 
prefix = ['ada', 'bda', 'hda', 'sfr', 'spr', 'wda']
;
print, 'Confirm that the MO disk label is: ' + tape_label
print, 'and that you have side ' + string(mdm2do.st$side) + ' inserted'
print, '  '
print, 'Insert the Exabyte for week: ' + strmid(string(mdm2do.st$week), 0, 5)
print, '  '
yesnox, 'Are you ready to do the copy? ', ans, 'Yes'
if (ans eq 1) then begin
    dir1 = concat_dir(mo_disk, 'yohkoh')
    exist = file_exist( dir1, /direct)
    if (not exist) then begin
	cmd = 'cd ' + mo_disk + '; mkdir yohkoh; chmod 777 yohkoh'
	print, cmd
	if (not keyword_set(qdebug)) then spawn, cmd
    end

    week = string(mdm2do.st$week)
    dir2 = concat_dir(dir1, week)
    exist = file_exist( dir2, /direct)
    if (not exist) then begin
	cmd = 'cd ' + dir1 + '; mkdir ' + week + '; chmod 777 ' + week
	print, cmd
	if (not keyword_set(qdebug)) then spawn, cmd
    end

    print, 'cd, '+dir2
    if (not keyword_set(qdebug)) then cd, dir2

    print, 'FILEID range =  ', fileID
    print, 'PREFIX = ', prefix
    print, 'rdtap, dev, fileID= fileID, prefix=prefix, /range

    if (not keyword_set(qdebug)) then rdtap, dev, fileID=fileID, $
		prefix=prefix, /range
end
;
end
