MathGroup Archive 1997

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

Search the Archive

RE: Loading packages

  • To: mathgroup at smc.vnet.net
  • Subject: [mg9527] RE: [mg9516] Loading packages
  • From: jmthomas <jmthomas at cybercable.tm.fr>
  • Date: Thu, 13 Nov 1997 01:39:56 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

The command
<<myPackage.m
works fine in two situations only:
first case: the file myPackage is in your working directory. You can 
determine your working directory by Directory[], and set it by 
SetDirectory["myDirectory"];
second case: you have extended the init.m file to be read at kernel 
initialization, and this file contains instructions to extend $Path in
 order to include the directory containing "myPackage".

Of course, the second case will take you a little more time but will 
allow you to go through a number of questions that are interesting if 
you intend to use Mathematica in a customized way:

When starting the kernel, an init.m file is read. On my Windows NT 
system, this init.m file is located in C:\Program 
Files\Mathematica\Configuration\Kernel. Depending on your operating 
system, this path might be different, but the HelpBrowser can tell you
 where this initialization file should be. This is the modified init.m
file:

(******************)
(** User Mathematica initialization file **)
If[$UserName=="jmt",Get["C:\\users\\jmt\\Mathematica\\AddOns\\Autoload\\jmt_init.m"]]
(** Decide how to display graphics on this machine **)

Begin["System`Private`"]
(* Hide any symbols which are created *)

Which[
        $Remote || $ParentLink =!= Null,               
<<"PSDirect.m",
        Environment["DISPLAY"]        =!= $Failed,     <<"Motif.m",
        $System == "NeXT",                             <<"NeXT.m",
        True,                                          <<"Terminal.m"
     ]

End[]
(********end of file********)

I have only added to the original file the second line:
If[$UserName=="jmt",Get["C:\\users\\jmt\\Mathematica\\AddOns\\Autoload\\jmt_init.m"]]

I cannot know whether your operating system handles user names, if it's
 not the case, you can always drop the If and have the file, here 
jmt_init, read at any startup of the kernel.

This file is located somewhere in my user's directory, you could place 
it anywhere, depending on how your computer is used and how you store 
your files. This package file is generated by a notebook created using 
the
>If you are using Mathematica 3.x, you can do one of the following:
>
>   1)  Declare the cell containing the package commands to be an
>   initialization cell.  Highlight the cell, then from the Menu 
commands
>   select:  "Cell", "Properties", "Initialization".  Now save the
>   notebook and when the popup menu says "Auto Save Package" respond 
with
>   "Create Auto Save Package".  Mathematica will automatically save a 
copy of the
>   initialization cell as a package with the .m file extension.
The presence of the notebook to generate the package is handy because 
modifications to the user_init.m file are easier to write. Just make 
sure the path to the automatic package file is correct, ie is the one 
you indicated in the kernel init file.
This is a part of my user init file:

$Path=Join[$Path,FileNames["*","C:\\users\\jmt\\Mathematica\\AddOns",2]
]
$Path=Join[$Path,
    FileNames["*","C:\\users\\jmt\\Mathematica\\ExtraPackages",3]]

When read by the kernel init file, it causes to extend $Path to the 
directories I need to have access via a single <<file command You can
of course do the same with $Packages, and so on. Hope this helps.

----------------------------------------------- Jean-Marie THOMAS
Conseil et Audit en Ingnierie de Calcul jmthomas at cybercable.tm.fr
www.cybercable.tm.fr/~jmthomas
======================

-----Original Message-----
From:	Steven Wilkinson [SMTP:wilkinson at NKU.EDU] To:
mathgroup at smc.vnet.net
Sent:	Sunday, November 09, 1997 5:05 AM To:	mathgroup at smc.vnet.net
Subject:	[mg9516] Loading packages

Mathgroup,

I have a problem that I have seen pop up on this list from time to time,
but I can't make any of the answers that have appeared work. I can't
load the packages I write into Mathematica 3.0 with either Get or Need.
One response I saw  was given in the following message:

>If you are using Mathematica 3.x, you can do one of the following:
>
>   1)  Declare the cell containing the package commands to be an
>   initialization cell.  Highlight the cell, then from the Menu 
commands
>   select:  "Cell", "Properties", "Initialization".  Now save the
>   notebook and when the popup menu says "Auto Save Package" respond 
with
>   "Create Auto Save Package".  Mathematica will automatically save a 
copy of the
>   initialization cell as a package with the .m file extension.
>
>   OR
>
>   2)  Save the notebook as a package file.  You have to manually type 
in
>   the file name with the .m file extension in the dialog box
>   window--selecting the package file type from the drop down menu 
won't
>   do it.  This method should work in pre Mathematica 3.x versions.  
But I found
>   that in some instances with pre Mathematica 3.x versions, there was 
a bug in
>   the notebook frontend and it was best just to write the package in a
>   standard text editor and save it with the .m file extension.
>
>   Dave Harvatin
>
>   On 31 Jul 1997 03:49:25 GMT, "jmt" <jmt at cybercable.tm.fr> wrote:
>
   >>If I write a package, say
   >>
   >>BeginPackage["myPackage`"]
   >>f::usage="f does strictly nothing"
   >>Begin["Private`"]
   >>f[_]=Null
   >>EndPackage[]
   >>End[]
   >>
   >>using an ordinary notebook, I will have to save it, let's say 
myPackage.nb
   >>If I read this notebook, using << or Get, the content of the file 
is not
   >>evaluated: no "myPackage`" context is happened to $ContextPath.
   >>
   >>It I use the command File->Save As Special->Package Format, I'm not 
asked
   >>wether I want the file to be either .nb or .m, the standard is .nb

I followed instruction set (2) on the above package. When I issued the
Get command

	<<myPackage.m

Mathematica responded with the error message

	Get : : Noopen :   Cannot open myPackage.m.

What am I doing wrong? Does this error message mean it couldn't find the
file "myPackage.m" or that once it found it it couldn't do anything
with it?

In another response to a similar question that dealt with the Needs
command, David Withoff said

>The Needs::nocont message is generated when Needs["context"] finds that
>"context" is not present in the value of $Packages. Since "context" is
>prepended to $Packages as one of the first  steps in evaluation of
>BeginPackage["context"], the appearance of this message usually means
>that BeginPackage["context"] hasn't been evaluated.  The first thing
>that I would do to solve this problem would be to take a close look at
>the .m file with an ordinary text editor.

What am I looking for?

Steve Wilkinson
Northern Kentucky University




  • Prev by Date: [Q] gnuplot features in Mathematica 3.x
  • Next by Date: Re: latex format in saving mathematica files..
  • Previous by thread: Re: Loading packages
  • Next by thread: variable problems