MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Alternative to DumpSave

  • To: mathgroup at smc.vnet.net
  • Subject: [mg117050] Re: Alternative to DumpSave
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Tue, 8 Mar 2011 05:38:35 -0500 (EST)
  • References: <201103031059.FAA20715@smc.vnet.net> <AANLkTik9tqxP1gCA+TkYdwFK+SiHX4at+8f-nYDtFqxF@mail.gmail.com> <il2dg8$68d$1@smc.vnet.net>

Hi,

> I have tried the .wdx format, but could not get it to work. I have saved 
> my data as downvalues of variables ("indexed storage", e.g. 
> var["1"]=Something, var["2"]=SomethingElse), and not as direct 
> assignments. I could not find a way that exporting to wdx saved these 
> assignments.
> 
> Any tips on how to Export or Put to a wdx file properly?

As others have mentioned it is not clear on how efficient wdx is
compared to saving to .m, so it is not clear whether the result is worth
the effort. That said, you could extract the actual information that is
stored with var and restore it.  When you use DownValues to only store
data, this would be a starting point:

(* prepare example data *)
var["p1"] = 5;
var["p2"] = {"asdf", 1.6, Plot[x, {x, 0, 1}]};
fname = ToFileName[{$HomeDirectory, "Desktop"}, "test.wdx"];


(* replace actual variable name in case you want to restore to another
variable name ... *)
Export[fname, DownValues[var] /. var[s_] :> Hold[s]]

(* read back data *)
data = Import[fname]

(* restore data in DownValues, here to another variable newvar *)
DownValues[newvar] = Replace[data,
  Verbatim[RuleDelayed][Verbatim[HoldPattern][Hold[lhs_]],
    rhs_] :> (HoldPattern[newvar[lhs]] :> rhs),
  {1}]

note that this of course is not equivalent to a save or dumpsave, which
also will store definitions of other symbols automatically if necessary.

hth,

albert


  • Prev by Date: Re: Spacing of group of Line[]-s -- any simple way?
  • Next by Date: Re: NDSolve (loop)
  • Previous by thread: Re: Alternative to DumpSave
  • Next by thread: Re: Alternative to DumpSave