Viewing contents of file '../idllib/contrib/tappin/graffer/gr_asc_save.pro'
pro Gr_asc_save, pdefs
;+
; GR_ASC_SAVE
; Save a graffer dataset to a file
;
; Usage:
; gr_asc_save, pdefs
;
; Argument:
; pdefs struct input The graffer data structure.
;
; History:
; Original: 16/8/95; SJT
; Remove file argument (use pdefs.name): 17/8/95; SJT
; Add facilities for string-type data: 18/8/95; SJT
; Add auto-save: 22/9/95; SJT
; Complete rewrite for new (V2) file organization should
; facilitate future extensions without some of the ghastly
; coding needed to (say) read 1.04 files with 1.05 program:
; 1/11/96; SJT
; Rename as GR_ASC_SAVE: 14/1/97; SJT
; Drop CDF support: 10/2/97; SJT
; Made unique in 8.3: 11/2/97; SJT
; Add REM(arks) field: 23/6/97; SJT
;-
file = pdefs.dir+pdefs.name
on_ioerror, no_open
openw, ilu, /get, file
on_ioerror, null
; Header & title information
printf, ilu, pdefs.version, pdefs.dir, pdefs.name, systime(), $
format = "('Graffer V',I2,'.',I2.2,': ',2A,' : @ ',A)"
printf, ilu, 'GT:', pdefs.title, format = "(2a)"
printf, ilu, 'GS:', pdefs.subtitle, format = "(2a)"
printf, ilu, 'GC:', pdefs.charsize, ':GA:', pdefs.axthick, format = $
"(a,f8.4,a,i3)"
printf, ilu, 'GP:', pdefs.position, ':GR:', pdefs.aspect, $
format = "(a,4f8.5,a,f9.5,f8.5)"
; X-axis information
printf, ilu, 'XR:', pdefs.xrange, ':XL:', pdefs.xtype, format = $
"(a,2g17.10,a,i2)"
printf, ilu, 'XSI:', pdefs.xsty.idl, ':XSE:', pdefs.xsty.extra, $
':XSG:', pdefs.xsty.grid, ':XST:', pdefs.xsty.time, $
':XSZ:', pdefs.xsty.tzero, format = "(5(a,i6))"
printf, ilu, 'XT:', pdefs.xtitle, format = "(2a)"
; Y-axis information
printf, ilu, 'YR:', pdefs.yrange, ':YL:', pdefs.ytype, format = $
"(a,2g17.10,a,i2)"
printf, ilu, 'YSI:', pdefs.ysty.idl, ':YSE:', pdefs.ysty.extra, $
':YSG:', pdefs.ysty.grid, ':YST:', pdefs.ysty.time, $
':YSZ:', pdefs.ysty.tzero, format = "(5(a,i6))"
printf, ilu, 'YT:', pdefs.ytitle, format = "(2a)"
; Colour table for displayed Z data
printf, ilu, 'ZT:', pdefs.ctable, ':ZG:', pdefs.gamma, format = $
"(a,i4,a,f7.3)"
; Number of data sets.
printf, ilu, 'DN:', pdefs.nsets, ':DC:', pdefs.cset, format = $
"(2(a,i6))"
; Output each dataset
handle_value, pdefs.data, data, /no_copy
for j = 0, (pdefs.nsets-1) > 0 do begin
printf, ilu, 'DS:', j, format = "(a,i6)"
printf, ilu, 'D:', data(j).descript, format = "(2a)"
printf, ilu, 'T:', data(j).type, ':M:', data(j).mode, ':N:', $
data(j).ndata, ':N2:', data(j).ndata2, $
format = "(a,i3,a,i2,2(a,i8))"
printf, ilu, 'J:', data(j).pline, ':P:', data(j).psym, ':S:', $
data(j).symsize, ':L:', data(j).line, ':C:', data(j).colour, $
':W:', data(j).thick, ':O:', data(j).sort, ':K:', $
data(j).noclip, ':E:', data(j).medit, $
format = "(2(a,i3),a,f8.3,a,i2,a,i3,a,i4,3(a,i1))"
handle_value, data(j).xydata, xydata, /no_copy
if (data(j).type lt 0) then begin ; Function
printf, ilu, 'R:', xydata.range, format = "(a,4g17.10)"
if (data(j).type eq -3) then $
printf, ilu, 'FX:', xydata.funct(0), 'FY:', xydata.funct(1), $
format = "(2a/2a)" $ ; Make 2 lines for parametric case
else printf, ilu, 'F:', xydata.funct, format = "(2a)"
endif else if (data(j).type eq 9) then begin ; 2-D data
handle_value, xydata.x, x, /no_copy
handle_value, xydata.y, y, /no_copy
handle_value, xydata.z, z, /no_copy
printf, ilu, 'ZXS:', format = "(A)"
printf, ilu, x, format = "(6g17.10)"
printf, ilu, 'ZXE:', format = "(A)"
printf, ilu, 'ZYS:', format = "(A)"
printf, ilu, y, format = "(6g17.10)"
printf, ilu, 'ZYE:', format = "(A)"
printf, ilu, 'ZZS:', format = "(A)"
printf, ilu, z, format = "(6g17.10)"
printf, ilu, 'ZZE:', format = "(A)"
handle_value, xydata.x, x, /no_copy, /set
handle_value, xydata.y, y, /no_copy, /set
handle_value, xydata.z, z, /no_copy, /set
endif else begin ; Ordinary data
sxy = size(xydata)
fmtd = '('+string(sxy(1), format = "(I0)")+'g17.10)'
printf, ilu, 'VS:', sxy(1), format = "(A,I2)"
printf, ilu, xydata, format = fmtd
printf, ilu, 'VE:', format = "(a)"
endelse
; We only need to save the 2-D
; specific options for 2-D data (types
; 9 & -4)
if (data(j).type eq 9 or data(j).type eq -4) then begin
printf, ilu, 'ZF:', data(j).zopts.format, format = "(A,I2)"
if (data(j).zopts.format eq 0) then begin ; contour data
printf, ilu, 'ZNL:', data(j).zopts.n_levels, ':ZNC:', $
data(j).zopts.n_cols, ':ZNS:', data(j).zopts.n_sty, $
':ZNT:', data(j).zopts.n_thick, ':ZCF:', $
data(j).zopts.fill, ':ZLI:', data(j).zopts.label, $
format = "(4(a,i3),a,i2,a,i3)"
if (data(j).zopts.n_levels gt 0) then $ ; Explicit levels
printf, ilu, 'ZL:', $
data(j).zopts.levels(0:data(j).zopts.n_levels-1), $
format = "(a,30g17.10)"
printf, ilu, 'ZC:', $
data(j).zopts.colours(0:data(j).zopts.n_cols-1), $
format = "(a,30I4)"
printf, ilu, 'ZS:', $
data(j).zopts.style(0:data(j).zopts.n_sty-1), $
format = "(a,30I4)"
printf, ilu, 'ZT:', $
data(j).zopts.thick(0:data(j).zopts.n_thick-1), $
format = "(a,30i4)"
endif else if (data(j).zopts.format eq 1) then begin ; colour
; picture
printf, ilu, 'ZR:', data(j).zopts.range, ':ZP:', $
data(j).zopts.pxsize, format = "(a,2g17.10,a,f7.3)"
endif
endif
printf, ilu, 'DE:', format = "(a)"
handle_value, data(j).xydata, xydata, /set, /no_copy
endfor
handle_value, pdefs.data, data, /no_copy, /set
; Note: don't save the widget ids.
printf, ilu, 'TN:', pdefs.ntext, format = "(a,i6)" ; Number of text items
handle_value, pdefs.text, text, /no_copy
for j = 0, (pdefs.ntext-1) > 0 do begin
printf, ilu, 'TS:', j, format = "(a,i6)"
printf, ilu, 'T:', text(j).text, format = "(2a)"
printf, ilu, 'X:', text(j).x, ':Y:', text(j).y, ':N:', $
text(j).norm, format = "(2(a,g17.10),a,i2)"
printf, ilu, 'C:', text(j).colour, ':S:', text(j).size, ':O:', $
text(j).orient, ':A:', text(j).align, ':F:', text(j).font, $
':W:', text(j).thick, format = $
"(a,i3,a,f8.3,a,f9.4,a,f8.5,a,i3,a,i4)"
printf, ilu, 'TE:', format = "(a)"
endfor
handle_value, pdefs.text, text, /no_copy, /set
; The text template (no need to dump the text string or position
; here as it
; must be the null string, only included to simplify coding)
printf, ilu, 'TTS:', format = "(a)"
printf, ilu, 'C:', pdefs.text_options.colour, ':S:', $
pdefs.text_options.size, ':O:', pdefs.text_options.orient, ':A:', $
pdefs.text_options.align, ':F:', pdefs.text_options.font, ':W:', $
pdefs.text_options.thick, ':N:', pdefs.text_options.norm, format = $
"(a,i3,a,f8.3,a,f9.4,a,f8.5,a,i3,a,i4,a,i2)"
printf, ilu, 'TTE:', format = "(a)"
; Specify the key information
printf, ilu, 'KU:', pdefs.key.use, ':KN:', pdefs.key.norm, ':KC:', $
pdefs.key.cols, ':KF:', pdefs.key.frame, ':KP:', $
pdefs.key.one_point, format = "(a,i2,a,i2,a,i3,2(a,i2))"
printf, ilu, 'KX:', pdefs.key.x, ':KY:', pdefs.key.y, format = $
"(2(a,2g17.10))"
printf, ilu, 'KT:', pdefs.key.title, format = "(2a)"
handle_value, pdefs.key.list, list, /no_copy
if (n_elements(list) ne 0) then printf, ilu, 'KLN:', n_elements(list), $
':KL:', list, format = "(a,i5,a," + string(n_elements(list), format $
= "(I0)") + "I5)"
handle_value, pdefs.key.list, list, /no_copy, /set
; Any remarks associated with the file.
handle_value, pdefs.remarks, remarks, /no_copy
if (n_elements(remarks) ne 0) then begin
printf, ilu, 'REM:', n_elements(remarks), format = "(a,i4)"
printf, remarks, format = "(a)"
endif
handle_value, pdefs.remarks, remarks, /no_copy, /set
; The hardcopy options
printf, ilu, 'HC:', pdefs.hardset.colour, ':HE:', pdefs.hardset.eps, $
':HO:', pdefs.hardset.orient, ':HP:', pdefs.hardset.psize, ':HT:', $
pdefs.hardset.timestamp, format = "(5(a,i2))"
printf, ilu, 'HS:', pdefs.hardset.size, ':HD:', pdefs.hardset.off, $
format = "(2(a,2f8.3))"
printf, ilu, 'HAB:', pdefs.hardset.action(0), 'HAA:', $
pdefs.hardset.action(1), format = "(2a/2a)"
printf, ilu, 'HF:', pdefs.hardset.font.family, ':HWS:', $
pdefs.hardset.font.wg_sl, format = "(a,i3,a,i2)"
free_lun, ilu
pdefs.chflag = 0b ; Clear change flag
pdefs.transient.changes = 0
return
No_open:
graff_msg, pdefs.ids.message, ["Failed to open save file:"+file, $
!Err_string]
end