Technical tips (UNIX, Linux, etc.) - may be computer-specific

This is edited as tips.sxw and exported as tips.html. Reason: OO 1.1.3 can only add ToC to .sxw, not to .html. Problem: ToC does not contain hyperlinks. OO is not ideal tool.

LaTeX2html might be better for sectioning. Also, it makes equations easier. But inserting non-eps graphics or hyperlinks would be more difficult.

This document should really be organized into sections.



Table of Contents

Technical tips (UNIX, Linux, etc.) - may be computer-specific 1

Miscellaneous printing issues 1

Duplexing-collating mistake: 1

VPN help (connecting to purdue vpn from linux): 1

Installing SuSE 10.1: More or less following the instructions on the website. 1

Connecting to Purdue's VPN: 1

Installing RealPlayer (for playing mp3s, for example): 1

Gaim and my vpn script: 1

Migrating from tcsh to bash 1

Stupid mistake 1

rsync (2006-5-22) 1

Intel Fortran Compiler (2006-2-23) 1

Intel Fortran Compiler on meissner (2006-4-3) 1

Parallel programming 1

Searching for 'Langevin' in TeX files, say 1

Programming languages and libraries on my systems (C, Fortran 9x, Java) 1

Useful file locations (standard Mathematica packages, C++ headers, LaTeX styles, etc.) 1

Don't use csh or tcsh for shell scripting 1

Mathematica efficiency 1

How to get a tree view in the Nautilus file manager on SuSE Linux 1

Cygwin as an alternative to Exceed 1

Behaviour of cout 1

Installing FFTW 1

Reloading Java applets 1

Links in UNIX 1

Bitter complaints about Emacs 1

Printing in PCN 1

Printing Mathematica documents 1

Installing Mathematica 1

Inserting EPS files into OpenOffice documents 1

Inserting EPS files into xfig figures 1

Installing epstool by Russell Lang 1

My .cshrc 1

Numerics in C 1

Forcing GTK+ widgets to redraw immediately 1

Makefiles 1

Recursively list directories (tree structure) 1

Configuring X 1

Converting PostScript files to PNG image files 1

Octave's file format 1

Java 1

sshfs

sshfs rocks!!!!

1. (Under SuSE 10.x) Use YaST-Software Management to install   sshfs.  This will install  fuse as well.
2. Might need to reboot (or rehash or something).
3. As user, do   

   mkdir LOCALDIR
   sshfs USERNAME@HOSTNAME:REMOTEDIR  LOCALDIR
   PASSWORD

  (where LOCALDIR is the mountpoint; REMOTEDIR can be blank).
4. Now you can just    cd MOUNTPOINT and have fun.
5. If this doesn't work, see below.  (you must be root to do the mknod)

http://wezzul.com/index.php


sshfs and fuse issues
If you are trying to mount something with sshfs and you get the following error:

fusermount: failed to open /dev/fuse: No such device or address


execute the following command to resolve it:

mknod -m 666 /dev/fuse c 10 229

More C(++) mistakes

Originally:

#define jj(x,y,b) jjj[ b + bmax*(x+xmax*y)]
myfunc( x-1, y-1, 2);

Took me a while to realize this should be

#define jj(x,y,b) jjj[ (b) + bmax*((x)+xmax*(y))]

Hmm, maybe I should have defined jj as an inline function instead.

Miscellaneous printing issues

New Century Schoolbook came out funny from the printer -- I need to find out what went wrong.

Whenever trying a new thing, CHECK ALL OPTIONS!  and then TEST!  For example: 
printing to evans: tray 1 = transparencies, tray 2 = normal paper.

Printing from Impress:  If you get a warning about page margins not matching printable area etc ....  choose “Trim”.

Duplexing-collating mistake:

I had a 9-page document.  I sent several copies of this to be printed, duplexed, from OpenOffice 1.0.?.    After the printer had printed page 9 it printed page 1 (of the next set) on the opposite side!  So right and left pages for that next set were interchanged.  So half of the sets came out right but the other half were wrong (mirrored).  and there was some wastage.

Lesson: When printing multiple duplex copies, ALWAYS pad with one blank page if necessary to make up an even number of pages.

VPN help (connecting to purdue vpn from linux):

http://help.itap.purdue.edu/view_article.php?articleid=1131&refid=3
http://kb.iu.edu/data/ajrq.html
http://kb.iu.edu/data/akcx.html
http://plug.student-orgs.purdue.edu/bb/
Important piece of advice: It was very useful to follow instructions on the web, from various sources.

Installing SuSE 10.1: More or less following the instructions on the website.

1. I downloaded the "Boot CD" image from the website, and burnt it to a CD.
2. I had to copy down the IP address of the FTP installation source from the website, as well as the directory name.  This was important!  
3. I booted from the boot CD and followed the prompts.  I had to type in my network configuration (DNS, gateway, etc.) as well as the IP and path of the installation source.
4. Later on, I followed the further instructions to install zen-updater and update YaST.  It was a PITA.  It required multiple passes and long periods of waiting.

Connecting to Purdue's VPN:

Eventually I managed to do this.  I have a bunch of config files (/etc/ppp/peers/purdue, /etc/ppp/options.pptp, /etc/ppp/ip-up, etc.) and a script that does "route add something" and "pppd call purdue".  When I want to connect, I su to root and run the script.

I had also installed the graphical client, kvpnc, and a whole bunch of vpn clients or daemons, but I still can't get it to work, even after upgrading to the latest version of kvpnc (which had some important bug fixes).

Installing RealPlayer (for playing mp3s, for example):

I followed instructions by "The Jem Report".  This involved adding some sources (YaST-->Installation Source) and then using the software manager (??) to download the "realplayer" package.

Gaim and my vpn script:

Both of these throw errors unless you run them as root.  To avoid having to log in as root, I tried setting the "SUID flag" on the executables:
chmod u+s  /xx/xxx/xxx/xx/gaim
but GTK complains!  Also, I tried setting the suid flag on my vpn shell script, but apparently Linux IGNORES that due to security considerations --- Linux REFUSES to suid root for shell scripts.  Anyway, suid is said to be dangerous.

Migrating from tcsh to bash

bash is much better for scripting, so they say.
Important files:  /etc/bash.bashrc,   ~/.bashrc,  ~/.profile (??) 

Stupid mistake

2006-6-18: Ran code with nice +20, and then wondered why it was taking 6 times longer than usual.


rsync (2006-5-22)

Instad of 
rcp -r meissner:MC . 
I used
rsync -rv meissner:MC . 
It worked:
sent 52656 bytes  received 3985244 bytes  897311.11 bytes/sec
total size is 11594458  speedup is 2.87

I should perhaps have used the -u option to avoid overwriting newer files.

Intel Fortran Compiler (2006-2-23)

I downloaded and installed IFC and the Intel 'performance' math library. This involved using 'tar zxvf' to unzip the .tgz and .tar.gz files. I did this in my user's home directory. Then I cd'd to the relevant directories and ran ./install.sh and followed the menus. After installation, I eventually figured out that I should read the documentation in the /opt/intel/fc/9.0/doc directory. I added the command

 
source /opt/intel/fc/9.0/bin/ifortvars.csh

to my ~/.cshrc. This sources a script that sets environment variables in order for ifort to run properly. It MUST be sourced, not simply executed. It adds /opt/intel/fc/9.0/bin to the PATH environment variable, as well as setting LD_LIBRARY_PATH=/opt/intel/fc/9.0/lib, which is necessary for the dynamic linker to know where to find the libraries. The documentation suggested that I run the script in my .login file. I tried this and it did not work at first. Eventually I realized that I had to restart the computer (or at least restart X), because launching a terminal from the GNOME panel doesn't create a new login shell. Now everything is ok. Presumably, if one is using sh, one should use .profile or .bash_rc instead of .cshrc. The command ifort f.f90 -o f creates a 380K executable; the command ifort f.f90 -i-dynamic -o f creates an 11K executable.


Intel Fortran Compiler on meissner (2006-4-3)

I just tried ifort on meissner for fun; I found out that ifort a.f90 -static-libcxa works. (it generates a.out)


Parallel programming

I'm told that all one needs to do is

 
$OMP PARALLEL DO
DO i=1,10
...
END DO

Searching for 'Langevin' in TeX files, say

I think I'm misusing the regexp, but never mind

 grep --include='*.tex' -R angevin *

Programming languages and libraries on my systems (C, Fortran 9x, Java)

meissner:/usr/...:      gcc, icc(?), ifort (?)
meissner:~yloh/...:     fftw3, gsl-1.7
meissner:/scratch/...:  jdk1.5.0_05
amdahl:/?/...:          gcc, icc, ifort, imsl (a.k.a. f95), pgcc, pgf90

See http://amdahl.physics.purdue.edu/using-cluster/node16.html for instructions ...


Useful file locations (standard Mathematica packages, C++ headers, LaTeX styles, etc.)

Sometimes one needs to modify Mathematica routines at a low level (for example, to make coloured error bars, or to get hold of the low-level code that chooses automatic tick marks). On meissner these are located at /net/aristotle/package/mathematica/linux/AddOns/StandardPackages/ . There are plenty of interesting tidbits and comments, for example:

(* myhold - this is a holding head that does nothing. It is the
   first piece of a nice chunk of cleverness (that I hope doesn't
   turn around and bite me) in ScaledPlot. *)

and

(* This is turning into something of a kludge tower; revisit
   the design soon... --JMN 17.2.98 *)

Ha, ha, ha! How candid. Some of the standard C++ headers on meissner are in /usr/include/c++/3.3/. The LaTeX style files are in /usr/share/texmf/tex/latex/.


Don't use csh or tcsh for shell scripting

I have to admit I was a fan of tcsh until I started hitting some problems: http://www-uxsup.csx.cam.ac.uk/misc/csh.html


Mathematica efficiency


How to get a tree view in the Nautilus file manager on SuSE Linux

http://lists.suse.com/archive/suse-linux-e/2005-Mar/2309.html


Cygwin as an alternative to Exceed

I had been looking around for some time for a free version of the Exceed X server. Purdue's ITaP computers come installed with something by Vandyke Software but I couldn't figure out how to use it. Anyway, I finally discovered that Cygwin, the Linux emulator for Windows, is fine for my purposes. I downloaded the setup.exe from the website and ran it; I kept setup.exe in a special directory and had to run it several times because I didn't realize I had to select the important packages; in particular, I needed 'xorg-x11-base', 'inetutils', and'openssh'. Now I can just use 'ssh -X user@h.o.s.t' to connect to a remote machine. Hooray!


Behaviour of cout

I just discovered that replacing 'endl' by 'whitespace' in the output section of my code produces an enormous speedup (400%)! This is probably because the 'ofstream' object is line-buffered, so that writing an 'endl' flushes it, which takes a long time.


Installing FFTW

It appeared that FFTW 2.1.5 was installed on meissner, but FFTW 3.0.1 was not (it was not properly installed, anyway). Thus I decided to do it myself as follows:

1. Download fftw-3.0.1.tar.gz from the FFTW website.
2. Type   tar zxvf fftw-3.0.1.tar.gz
3. Type   cd fftw-3.0.1
4. Type   ./configure --prefix=${HOME}/fftw3
5. Type   make
6. Type   make install

I can now compile my C(++) source code as follows:

g++ fftwdemo.cc -I${HOME}/fftw3/include -L${HOME}/fftw3/lib -lfftw3 -o fftwdemo

Reloading Java applets

Typical browsers maintain two caches, one for HTML files and one for Java class files. I am told that you can make the browser reload HTML files from the original location (bypassing the cache) by pressing Shift-Reload or Ctrl-Reload (if the reload button itself doesn't do the trick). To reload a java applet afresh (e.g., if the class file has changed because you recompiled it), choose 'Tools - Web Development - Java Console' or an equivalent menu option, and press 'X' in the window. This will 'clear the classloader cache'.


Links in UNIX

Remember the power of soft links (ln -s) and hard links (ln).


Bitter complaints about Emacs

Here's how to set the indentation (tab stops). The following worked on xemacs:

1. Menu -> Options -> Customize Emacs -> Browse customization groups
2. Click on the '+' to the left of "Programming" (or move the cursor there and press Enter).
3. Click on the '+' to the left of "Languages".
4. Click on the '+' to the left of "C".
5. Click on the 'Option' to the left of "C Basic Offset".
6. In the other window, click on "Override style settings" and change "4" to "2".

In order to get Java code formatted in the same way I had to do the following as well:
7. In the original window, click on "Java Mode Hook".
8. Click "Show".
9. Click "Ins". 
10. Type "setq c-basic-offset 2" into the box.
11. Scroll back up and click "Set for Current Session" and "Save for Future Sessions".  The status bar shows "Wrote .../.gnu-emacs-custom".
12. Click "Finish" a few times.  I don't know if this is really necessary.

Now when you press TAB it should ...work....;  or press C-c h (or is that C-c C-h?) and select the "Indent section" item from the menu.  IT'S ALL REALLY OBVIOUS, ISN'T IT?

I did the above steps for GNU emacs but it did not work.  After TWO HOURS I found that you have to:
13. Scroll down to find "CC Mode Common Hook"
14. In (setq c-basic-offset 4), change the 4 to 2.

Printing in PCN

We have been told by the Cannon printer repairman that the reason for the numerous paper jams in Knuth is due to the printouts formatted for A4 sized paper.  We do not stock A4 size paper, so in order to print jobs formatted for A4 paper, you will need to re-format them to letter size.
...

Yeah, sorry, we've been rather busy and havn't had a chance to update the
website.  Anyway the printer Warnock is not available for anyone outside the
business office.  The printer Babbage has been moved to room 293.  ...

We don't use the traditional lpr here in physics.  We've upgraded to a much
better printing system called CUPS.  CUPS has an lpr hook-in but a lot of the
old lpr options don't work.  To print duplex to Turing simply do:

lpr -Pturing -o Duplex=DuplexNoTumble filename.ps

To find out what to set the duplex option for each printer I believe you can use
the lpoption command with the -l option.

For example:

lpoptions -pturing -l
lpoptions -pevans -l
lpr -Pevans -o ManualFeed=True     (to print transparencies)

Printing Mathematica documents

I like to run Mathematica in a maximized window. As a result, my notebooks are often 1024 pixels across, which is too wide to fit on A4 or letter paper. I do not know if Mathematica can print at reduced magnification, and I do not like hacking ps files or using psutils. Therefore my solution is: (1) Export the .nb file as a .html file (and associated directories). (2) Open the .html file in Mozilla. (3) In Mozilla, do page setup, print preview, and print. This works because the browser always fits everything in its window.


Installing Mathematica

PCN did it.  Apparently, it involved copying the license file to my home directory.

Inserting EPS files into OpenOffice documents

You can insert an ordinary EPS file into OpenOffice.  It will print ok, but it will be displayed on-screen as a bounding box only.  If you want things to be WYSIWYG, you need to make sure your EPS contains an "embedded preview".  OpenOffice does NOT understand ".epsi" files, but it understands EPS with TIFF preview.  So:

1. Produce the eps file:
   a. From LaTeX: Either of the following:
      i)  latex myeqn; dvips -E myeqn.dvi -o myeqn.temp.eps
      ii) pdflatex myeqn; convert myeqn.pdf myeqn.eps          
   b. From Mathematica: Either:
      i)  mygraph = Plot[x,{x,0,1}]; Export["mygraph.eps", mygraph];
      ii) right-click on graphic and save/export as EPS, I think.
   c. From gnuplot:
        [to be added]
   d. From xmgrace:
        [to be added]
   e. From xfig:
        Use the export button, I think .... I think the shortcut is alt-x
2. Run epstool to add a TIFF preview (see Installing epstool)
        epstool -t6p --dpi 300 myeqn.eps meqn.tiff.eps
3. Run OpenOffice Writer or Impress.
        Press Alt-I-G (Insert->Graphics) and choose myeqn.tiff.eps .

Inserting EPS files into xfig figures

1. Generate myeqn.temp.eps as above (the TIFF preview is unnecessary, since xfig knows how to render eps files).
2. In xfig, click "Picture" (the camera icon), "Browse", select file, click "Use Original Size", click "Apply", and if you're happy, click "Done".

Remember that the FIG file only stores a link to the EPS file, not the EPS data itself (unlike OOo). The FIG file is therefore small (can be less than 1KB). Warning: for a little one-line equation, the TeX file is about 800B (bytes), the DVI file is 600B, the TIFF file is 2600B (at pretty good resolution), but the PDF file is 22KB and the EPS file is 42KB (without the preview)! I think this is because the EPS file includes the Computer Modern fonts. What a pity.


Installing epstool by Russell Lang

1. Download the tarball (.tgz file) from http://www.cs.wisc.edu/~ghost/gsview/epstool.htm and save it as ~/epstool-3.08.tar.gz .
2. In home directory, do "tar zxvf epstool-3.08.tar.gz".
3. Do "cd epstool-3.08" and then "make".  This will compile the source code.
4. Do "cd ~/bin" and then "ln -s ~/epstool-3.08/bin/epstool .".
5. Make sure that .cshrc contains 
      "setenv PATH ${PATH}:.:/net/aristotle/home/yloh/bin"
   If not, add it and "source ~/.cshrc".
   If you are not already using csh or tcsh, do "chfn".
6. "rehash".  Now epstool is ready to use.

My .cshrc

setenv PATH ${PATH}:.:/net/aristotle/home/yloh/bin
set prompt="%B%m:%~%#%b "
if (  "$version"  =~  *linux*  ) then
    #echo "cuddlymogwai- This is a Linux machine.  Aliasing ls to ls --color."
    alias ls 'ls --color'
else if (  "$version"  =~  *FreeBSD* ) then
    #echo "cuddlymogwai- This is a FreeBSD machine.  Aliasing ls to ls -G."
    alias ls 'ls -G'
endif
alias rm 'rm -iv'
alias mv 'mv -iv'
alias cp 'cp -iv'
alias top 'top -id 1'
alias xfig xfig -metric -pheight 21
alias av appletviewer
alias ff '~/firefox/firefox'
alias e "emacs -fn '-*-courier-medium-r-*-*-12-*-*-*-*-*-*-*' -geometry 80x67"
alias g gedit --new-window
#alias m make -f ~/bin/makefile
alias oo openoffice
alias k kill
alias xdvi xdvi -expert -s 6 -bg lightblue
#alias xdvi xdvi -expert -paper a4 -bg lightgrey -geometry 725x996 -s 7
alias x xmgrace -free  -viewport 0.15 0.05 1.25 0.95
alias jobs 'jobs -l'
alias asdf "setxkbmap dvorak"
alias aoeu "setxkbmap us"
limit coredumpsize 0

Numerics in C

Remember the painful lesson that wasted 2 days of my time:

int n,nn;
double x,y,k1,s1,s3;
...
for (n=1; n<=nn; n++) {
   s3 = exp(-n*n/4) / (n*n + 4*x*x);
   s4 = 2*x - k2*(2*x*cosh(n*y) - I*n*sinh(n*y));
   s5 += s3*s4;
}

Forcing GTK+ widgets to redraw immediately

Suppose you have a function like this:

void foobar () {
    gnome_appbar_set_status (GNOME_APPBAR(statusbar1), "Foo ...");
    for (int i=0; i<0x10000000; i++) ; // long delay
    gnome_appbar_set_status (GNOME_APPBAR(statusbar1), "... bar!")
}

The text "Foo ..." never appears, because event processing waits until the function foobar() terminates. How do we get the text to show up? By far the best way to do this is to add, before the delay,

while (g_main_iteration(FALSE));

The function g_main_iteration  runs a single iteration of GTK's main loop.   The argument FALSE means non-blocking mode:   if the event queue is empty, just go on.   This line of code purges the event queue.

Situations to beware:
- This can lead to recursion, if foobar() is called a second time as a result of the queued events.
- If an idle function has been attached, it will keep on being called ... the event queue can never be purged.  So the programme hangs.
 


Makefiles

"make" reads Makefile.
"gmake" reads GNUmakefile and then Makefile.
The system makefile is /usr/share/mk/sys.mk,
but I don't know if gmake reads this.

Recursively list directories (tree structure)

find . -type d

Configuring X

In XFree86 version 3, use "XF86Setup".
In XFree86 version 4, use "xf86config".

The configuration file is called XF86Config, and is searched for in various directories, including /etc, /etc/X11, and so on.  The currently referenced version is /etc/X11/XF86Config.

I added a ModeLine setting in XF86Config (13/9/2001).

To install fonts:

1. xset fp+ /usr/X11R6/lib/X11/fonts/webfonts  (for example)
2. xset fp rehash
3. To make this permanent, need to edit XF86Config and restart X.

Converting PostScript files to PNG image files

The disadvantages of using   pstopnm  as follows are that it doesn't do antialiasing, and getting the crop coordinates right is extremely troublesome:

pstopnm -pgm -llx 3 -lly 10 -urx 5 -ury 11 -portrait -xsize 400 hello.ps

A much better method is

pstoimg -crop a hello.ps

Remember to make LaTeX files without page numbers, if you are trying to make little PNG's of equations.

Octave's file format

Use

save -binary junk.mat mymat

This produces a file called junk.mat with a 31-byte header,
followed by raw data (generally 8 bytes per double, or 16 bytes per complex).
The number of rows and columns are stored as 4-byte integers somewhere in the header.

Java

                            appletviewer    netscape
Java1.1/AWT    Application   Ok              Ok
Java1.1/AWT    Applet        Ok              Ok
Java1.2/Swing  Application   Ok              Ok
Java1.2/Swing  Applet        Ok              Fails