MathGroup Archive 2008

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

Search the Archive

Re: DumpSave of packages

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88926] Re: DumpSave of packages
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Wed, 21 May 2008 14:52:06 -0400 (EDT)
  • References: <g0uavk$57s$1@smc.vnet.net>

Hannes Kessler wrote:
> Hello,
> 
> how to save interrelated packages to mx-files? This question is a
> follow-up to my previous one
> http://groups.google.de/group/comp.soft-sys.math.mathematica/browse_thread/thread/99547ed0a031ccbe/c2f36a4341d05396?lnk=gst&q=kessler#c2f36a4341d05396
> 
> DumpSave["package.mx", {"package`", "otherpackage`"}] does not work
> always if the packages depend on each other and contain subcontexts.
> No problems using only .m files.
> 
> Here is roughly what I tried:
> 1. Start the notebook package.nb (working directly with package.m
> gives similar results).
> 2. Assign Contexts[] to a variable initialContexts
> 3. Execute the package itself
> 4. Execute Contexts[] again, delete all contexts already in
> initialContexts and assign the result to a variable requiredContexts
> 5. DumpSave["package.mx", requiredPackages]
> 
> Now, executing Needs["package`"] loads the correct context package`
> but some functions do not work anyways.
> 
> Below are the details (paste into a notebook). Any ideas are
> appreciated.
> 
> Regards,
> Hannes Kessler
> 
> (* not an initialization cell *)
> virgin\[LetterSpace]contexts = Contexts[];
> 
> BeginPackage["package`", {...}]
> ...
> EndPackage[];
> 
> (* Now the DumpSave, again not an initialization cell *)
> nb = EvaluationNotebook[];
> Module[{
>   required\[Dash]contexts =
>    DeleteCases[
>     Contexts[], _?(MemberQ[virgin\[LetterSpace]contexts, #] &)],
>   nb\[Dash]file = Replace["FileName", NotebookInformation[nb]][[2]],
>   nb\[Dash]dir =
>    ToFileName  @
>     First  @  Replace["FileName", NotebookInformation[nb]],
>   mx\[Dash]file, mx\[Dash]dir, save
>   },
>  mx\[Dash]file =
>   StringReplace[nb\[Dash]file,
>    s_ ~~ ".nb" ~~ EndOfString :> s <> ".mx"];
>  mx\[Dash]dir =
>   ToFileName[{nb\[Dash]dir, mx\[Dash]file, ToString  @  $SystemID}];
>  If[  FileNames@mx\[Dash]dir === {},
>   CreateDirectory  @  mx\[Dash]dir];
>  save = Hold[
>     DumpSave[ToFileName[{mx\[Dash]dir}, mx\[Dash]file],
>      "contexts"]] /. {"contexts" -> required\[Dash]contexts};
>  ReleaseHold  @  save]
> 
In the complex collection of packages that you described in your 
previous message, I guess it is possible that something untoward is 
happening - possibly as a result of some manipulation of contexts. It 
may be better to step back a bit and say what exactly you are trying to 
achieve. .mx files are indeed a very effecient way of loading 
(typically) large arrays of data. If this is your situation, it may be 
better to store these individually:

DumpSave[mxfile,{list of items to be saved}];

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: fails?
  • Next by Date: Re: Colors chosen for ListPlot, etc., in v. 6 -- followup
  • Previous by thread: DumpSave of packages
  • Next by thread: Cannot NSolve a system of equations