Labels

APPLE (1) astro (1) IDL (4) life (2) linux (5) LSD (2) Mac (2) teaching (1) volleyball (2) work (1)

Wednesday, August 5, 2009

[SHELL]Setting Environment Variables

ref: https://www.ccs.uky.edu/docs/cluster/env.html

There are two styles of shells on most UNIX (and Linux) systems:

Those derived from the original bourne shell (sh) which include bash, ksh etc. and those derived from the C shell which include csh, tsch, etc. The difficulty for many beginners is that these two families of shells support different syntax for setting variables in the environment along with different control flow commands.
You can find which shell you are using by typing:

echo $SHELL at the prompt

Under sh or bash, you set an environment variable as follows:

PATH= $PATH:$HOME/bin
export PATH

The first line sets the PATH environment variable. These two commands can be combined into a single line as follows:

PATH= $PATH:$HOME/bin; export PATH

The semicolon allows multiple commands to be issued on the same command line. Normally, this command would be placed in the .profile file located in your home directory. The .profile file is read when the sh, bash, orksh shell starts. It acts as an initialization file where you can set all kinds of environment variables, change behaviors of the shells, etc. The bash shell will also read a .bshrc resource file in your home directory if it exists. This .bshrc file is for commands that only the bash shell understands. A similar .bash_profile file can also be used for bash-only startup commands. If these files don't exist in your home directory, then the system uses some system-wide files in the /etc/profile. If you set these environment variables for bash in the .profile file, then they will be inherited by any shells that you start (spawn) from this shell including c shells. The "set", "env" or "printenv" command will display all of your current environment variables. You may need to pipe this command through less or more(e.g env | less) to see all of the variables

Assuming that the did not find mpif90 when you type it at the command prompt,

[ccs@agt-login ccs]$ mpif90
bash: mpif90: command not found

You can verify the existence of the command, by executing whereis mpif90 or locate mpif90 at the command prompt,

[ccs@agt-login ccs]$ whereis mpif90
mpif90: /opt/mpich-1.2.4/bin/mpif90

Once you find the path for mpif90 you can add it to the PATH environment variable so that the shell automatically finds the command when you type it next time at the shell. This can be done by either creating .profile or.bshrc or modifying the PATH variable in the already existing .bash_profile file

Append /opt/mpich-1.2.4/bin to the end of the PATH environment variable.

PATH=$PATH:$HOME/bin:/opt/mpich-1.2.4/bin
export PATH


Now we switch to the C shell side of things. The syntax to set an enviroment variables in the csh (and tcsh) is different.

setenv PATH $PATH:$HOME/bin

The "setenv" command will display the environment variables. These commands could be placed in a .cshrc file in your home directory that is read whenever a c shell starts. The .login file is read after the .cshrc file when this is a login script.

Assuming that the did not find mpif90 when you type it at the command prompt,

[ccs@agt-login ccs]$ mpif90
bash: mpif90: command not found

You can verify the existence of the command, by executing whereis mpif90 or locate mpif90 at the command prompt,

[ccs@agt-login ccs]$ whereis mpif90
mpif90: /opt/mpich-1.2.4/bin/mpif90

Once you find the path for mpif90 you can add it to the PATH environment variable so that the shell automatically finds the command when you type it next time at the shell. This can be done by modifying the PATHvariable in the .cshrc file. (You need to create if .cshrc file doesnt exist)

Append /opt/mpich-1.2.4/bin to the end of the PATH environment variable.

setenv PATH $PATH:$HOME/bin:/opt/mpich-1.2.4/bin

Wednesday, July 22, 2009

[VI] find and replace

Find the 'txt': /txt (forward searching)
?txt (backward searching)
/\ (searching for the whole word 'txt')

Get rid of the highlighting after search:
:set nohlsearch
Enable highlighting searching:
:set hlsearch

Find the replace:
:s/word/replacement/ ( once )
:s/word/replacement/g ( all at once on a single line )
:.,.+Ns/word/replacement/g ( all at once on the current line and
the next N lines )
:%s/word/replacement/g ( all at once the whole text )
:s/word/replacement/cg ( you need confirm whether or not to
replace )
:s/word/replacement/gi ( case insensitive )
:set ic ( case insensitive )
:set noic ( case sensitive )
:%//g ( remove all tab characters )

ref: http://www.linux.ie/articles/tutorials/vi2.php

Thursday, March 19, 2009

[IDL] How to save IDL plots

1. How to save an IDL plot as a jpeg file

After you made your plot in IDL you can type the following:
IDL> im=tvrd() ; im is the matrix for the image
IDL>write_jpeg,'filename.jpeg',im ; a file named filename.jpeg is stored in the current IDL working directory

2. How to make a PostScript plot


IDL> set_plot,'ps'
IDL> device,filename='name.ps'
IDL> {set of instructions to make desired plot}
IDL> device, /close
IDL> set_plot,'x'