pro Graff_get, pdefs, f, no_set=no_set, recover=recover ;+ ; GRAFF_GET ; Get a graffer dataset from a file ; ; Usage: ; graff_get, pdefs[, f] ; ; Argument: ; pdefs struct in/out The graffer data structure. ; f string input The file to read. ; Keywords: ; no_set input If set, then don't try to set up the widget ; values (because the widgets aren't there) ; recover input If set, then try to recover the file from the ; autosave file ; ; History: ; Original: 16/8/95; SJT ; Remove file argument (use pdefs.name): 17/8/95; SJT ; Add facilities for string-type data and restore filename: 18/8/95; SJT ;- if (n_params() eq 1) then begin junk = findfile(pdefs.dir, count = num) if (num ge 1) then path = pdefs.dir $ else cd, current = path f = pickfile(/read, filter = '*.grf', title = 'Graffer Restore', $ /must, path = path) if (f eq '') then return endif split_dir, f, dir ; Split the name and directory after ; opening pdefs.name = f pdefs.dir = dir on_ioerror, nofile if (keyword_set(recover)) then openr, ilu, /get, dir+'#'+f+'#' $ else openr, ilu, /get, dir+f on_ioerror, null rs = '' readf, ilu, rs ; read the overall header vp = strpos(rs, 'V')+1 file_v = float(strmid(rs, vp, 5)) if (file_v lt 1.0) then begin graff_msg, pdefs.ids.message, "Version 0.xx files are no longer " + $ "supported." free_lun, ilu return end readf, ilu, rs ; Plot headers pdefs.title = rs readf, ilu, rs pdefs.subtitle = rs fv = 0. iv = 0 readf, ilu, fv, iv pdefs.charsize = fv pdefs.axthick = iv axr = fltarr(2) axs = intarr(2) readf, ilu, axr, axs ; X axis properties pdefs.xrange = axr pdefs.xtype = axs(0) pdefs.xsty = axs(1) readf, ilu, rs pdefs.xtitle = rs readf, ilu, axr, axs ; Y axis properties pdefs.yrange = axr pdefs.ytype = axs(0) pdefs.ysty = axs(1) readf, ilu, rs pdefs.ytitle = rs sets = intarr(2) readf, ilu, sets ; Number of data sets. pdefs.nsets = sets(0) pdefs.cset = sets(1) nds = pdefs.nsets > 1 data = replicate({graff_data}, nds) psym = 0 & symsize = 0. & line = 0 & colour = 0 & thick = 0 isort = 0b & ndata = 0 & ity = 0 & dsr = '' for j = 0, nds-1 do begin readf, ilu, psym, symsize, line, colour, thick, isort, ndata data(j).psym = psym data(j).symsize = symsize data(j).line = line data(j).colour = colour data(j).thick = thick data(j).sort = isort data(j).ndata = ndata if (file_v ge 1.01) then readf, ilu, dsr data(j).descript = dsr readf, ilu, ity if (file_v le 1.01) then ity = ([0, -1, 1, 2])(ity) ;re-map type ;codes data(j).type = ity if (ity ge 0) then begin ; Ordinary X-Y data xydata = fltarr(ity+2, ndata > 2) readf, ilu, xydata endif else begin ; Function r = fltarr(2) if (ity eq -3) then f = strarr(2) $ else f = '' readf, ilu, r readf, ilu, f xydata = {range:r, funct:f} endelse data(j).xydata = handle_create() handle_value, data(j).xydata, xydata, /set, /no_copy endfor handle_value, pdefs.data, data, /set, /no_copy ntext = 0 readf, ilu, ntext ; Number of text items pdefs.ntext = ntext ntext = ntext > 1 text = replicate({graff_text}, ntext) colour = 0 & size = 0. & orient = 0. & align = 0. & font = 0 thick = 0 & x = 0. & y = 0. & norm = 0b & texts = '' for j = 0, ntext-1 do begin readf, ilu, colour, size, orient, align, font, thick, x, y, norm text(j).colour = colour text(j).size = size text(j).orient = orient text(j).align = align text(j).font = font text(j).thick = thick text(j).x = x text(j).y = y text(j).norm = norm readf, ilu, texts text(j).text = texts endfor handle_value, pdefs.text, text, /set, /no_copy ; Note: don't get the widget ids. hf = bytarr(4) hs = fltarr(2) readf, ilu, hf, hs ; The hardcopy options pdefs.hardset.colour = hf(0) pdefs.hardset.eps = hf(1) pdefs.hardset.orient = hf(2) pdefs.hardset.timestamp = hf(3) pdefs.hardset.size = hs readf, ilu, rs pdefs.hardset.action(0) = rs readf, ilu, rs pdefs.hardset.action(1) = rs Got_data: free_lun, ilu pdefs.chflag = 0 ; Clear changes flag if (not keyword_set(no_set)) then begin graff_set_vals, pdefs pv = total(pdefs.version*[1., .01]) if (pv ne file_v) then graff_msg, pdefs.ids.message, $ ['File and program versions differ', $ 'File: '+string(file_v, format = "(f5.2)")+ $ ' Program: '+string(pdefs.version, format = "(I2,'.',I2.2)")] endif return Nofile: graff_msg, pdefs.ids.message, ['Failed to open file: '+dir+f, $ !Err_string] return end