NRAO Home > CASA > CASA Cookbook and User Reference Manual

B.9 History and Searching

Numbered input/output history is provided natively within IPython. Command history is also maintained on-line.

  CASA [11]: x=1  
 
  CASA [12]: y=3*x  
 
  CASA [13]: z=x**2+y**2  
 
  CASA [14]: x  
    Out[14]: 1  
 
  CASA [15]: y  
    Out[15]: 3  
 
  CASA [16]: z  
    Out[16]: 10  
 
  CASA [17]: Out[14]   # Note: The ’Out’ vector contains command output  
    Out[17]: 1  
 
  CASA [18]: _15       # Note: The return value can be accessed by _number  
    Out[18]: 3  
 
  CASA [19]: ___       # Note: The last three return values can be accessed as:  
    Out[19]: 10        #       _, __, ___

Command history can be accessed via the ’hist’ command. The history is reset at the beginning of every CASA session, that is, typing ’hist’ when you first start CASA will not provide any commands from the previous session. However, all of the commands are still available at the command line and can be accessed through the up or down arrow keys, and through searching.

  CASA [22]: hist  
  1 : __IP.system("vi temp.py")  # Note:shell commands are designated in this way  
  2 : ipmagic("run -i temp.py") # Note:magic commands are designated in this way  
  3 : ipmagic("hist ")  
  4 : more temp.py  
  5 : __IP.system("more temp.py")  
  6 : quickhelp()                # Note: autoparenthesis are added in the history  
  7 : im.open(’ngc5921.ms’)  
  8 : im.summary()  
  9 : ipmagic("pdoc im.setdata")  
  10: im.close()  
  11: quickhelp()  
  12: ipmagic("logstate ")  
  13: x=1  
  14: y=3*x  
  15: z=x**2+y**2  
  16: x  
  17: y  
  18: z  
  19: Out[16]  
  20: _17  
  21: ___

The history can be saved as a script or used as a macro for further use:

  CASA [24]: save script.py 13:16  
    File ‘script.py‘ exists. Overwrite (y/[N])? y  
    The following commands were written to file ‘script.py‘:  
    x=1  
    y=3*x  
    z=x**2+y**2  
  CASA [25]: !more script.py  
    x=1  
    y=3*x  
    z=x**2+y**2

Note that the history commands will be saved up to, but not including the last value (i.e., history commands 13-16 saves commands 13, 14, and 15).

There are two mechanisms for searching command history:

  1. Previous/Next: use Ctrl-p (previous,up) and Ctrl-n (next,down) to search through only the history items that match what you have typed so far (min-match completion). If you use Ctrl-p or Ctrl-n at a blank prompt, they behave just like the normal arrow keys.
  2. Search: Ctrl-r opens a search prompt. Begin typing and the system searches your history for lines that contain what you’ve typed so far, completing what it can. For example:
      CASA [37]: <Cntl-r>  
     
      (reverse-i-search)‘’:

    Typing anything after the colon will provide you with the last command matching the characters, for example, typing ’op’ finds:

      (reverse-i-search)‘op’: im.open(’ngc5921.ms’)

    Subsequent hitting of Ctrl-r will search for the next command matching the characters.


More information about CASA may be found at the CASA web page

Copyright © 2010 Associated Universities Inc., Washington, D.C.

This code is available under the terms of the GNU General Public Lincense


Home | Contact Us | Directories | Site Map | Help | Privacy Policy | Search