function mk_script, str_data, name=name, append=append, $
	comment=comment, nohead=nohead, submit=submit
;
;+ 
;   Name: mk_script
;
;   Purpose: make a script file from str_data and optionally spawn it
;
;   Input Parameters:
;      str_data - string array of commands
;
;   Optional Keyword Parameters
;      name - file name for script file (default='mk_script.src')
;      submit - switch; if set, the file is sourced (executed)
;
;   Output - function return value is script file name
;
;   History - slf, 15-nov-92
;	      slf,  6-mar-92 - allow 'appending' to new file
;
;-
append=keyword_set(append)
;
if not keyword_set(name) then name = 'mk_script.src'
if n_params() eq 0 then str_data = $
   '# *** mk_script - null entry on ' + systime() 
;
open=['openw','openu']
call_procedure, open(keyword_set(append)), unit, /get_lun, $
	name, append=append 

;
status=fstat(unit)
point_lun,unit, status.size		; position to end of file
;
if not keyword_set(nohead) then begin	; add program annotation
   printf,unit,'#'
   printf,unit,'# *** mk_script Version 1.0 entry on ',systime()
   printf,unit,'#'
endif
;
if keyword_set(comment) then begin
   if strmid(comment,0,1) ne '#' then comment='# ' + comment
   printf,unit,comment
endif
;
printf,unit, str_data, format='(a)'	; write the data
;
free_lun,unit
;
if keyword_set(submit) then spawn,'source ' + name
;
return,name
end
