Editing Tools for your Demeter scripts

Editing a Demeter script can be a bit tedious due, in large part, to the tedium of typing the unavoidable boilerplate. For example, to define a Data object, you might type something like:

   1 my $data -> Demeter::Data(file       => "cu10k.chi",
   2                           fft_kmin   => 3,            fft_kmax   => 14,
   3                           fit_k1     => 1,            fit_k3     => 1,
   4                           bft_rmin   => 1.6,          bft_rmax   => 4.3,
   5                           name       => 'My copper data',
   6                          );

For a many data set fit or for a fit with lots of Path objects, this is just a lot of stuff that needs to be typed or, I suppose, cut-n-pasted.

Here are a couple of suggestions for streamlining your editing.

Use Package::Alias

Package::Alias is a module available on CPAN that allows you to alias long package names with much shorter strings. To use it, you will need to fire up the cpan program and tell it to install Package::Alias.

With Package::Alias, you can get by with less typing. Here is a simple fitting script implementing a fit to copper foil data. And here is the same script written using Package::Alias. The key bit is in lines 20-25:

use Package::Alias
  DD   => 'Demeter::Data',
  GDS  => 'Demeter::GDS',
  DFE  => 'Demeter::Feff::External',
  Path => 'Demeter::Path',
  Fit  => 'Demeter::Fit';

This defines the shortened ways of refering to frquently used Demeter components. With this, you can replace a Data definition like the one above with this:

   1 my $data -> DD->new(file       => "cu10k.chi",
   2                     fft_kmin   => 3,          fft_kmax   => 14,
   3                     fit_k1     => 1,          fit_k3     => 1,
   4                     bft_rmin   => 1.6,        bft_rmax   => 4.3,
   5                     name       => 'My copper data',
   6                    );

You still have to type in all the attributes, but at least you don't have to type Demeter::Data and the like over and over.

Use Emacs skeletons

If you are an Emacs user, I have written a templating tool. You can have this loaded into your Emacs session by putting

(load-file "/path/to/demeter-skeletons.el")

into your ~/.emacs file. (Of course, you have to specify the correct path to that file on your computer.)

This file creates various templates and turns abbrev-mode on when you edit a perl file. Now, if you type DData then hit the space bar, the following will be inserted into your file at the cursor:

   1 my $data = Demeter::Data->new(name     => ,  cv       => ,
   2                               fft_kmin => ,  fft_kmax => ,
   3                               bft_rmin => ,  bft_kmax => ,
   4                               fit_k1   => 1, fit_k2   => 1, fit_k3 => 1,
   5                              );

You still have to type in attribute values, but this takes out some of the busywork. Follow the example to make your own templates!

Demeter/EditingTools (last edited 2011-04-13 19:50:16 by BruceRavel)