CIMSS SGI Frequently Asked Questions (FAQ)
------------------------------------------

Maintained by Liam Gumley (liamg@ssec.wisc.edu)
20-FEB-1996
Changes since last version (24-OCT-1995):
1.0 Web Sites
 SGI FORTRAN-77, FORTRAN-90, C, and C++ manuals
 IDL Home
 IDL FAQ
3.0 FORTRAN
 3.10 My program compiles but crashes with 'Segmentation fault (core dumped)'
      when it tries to allocate some large arrays - what gives?
   
Acknowledgements
----------------
Many thanks go to the following contributors to this list:
Steve Nieman, Kathy Strabala, Chris Moeller.
 
Introduction
------------
This FAQ is an attempt to document answers to common questions asked by
CIMSS people about Silicon Graphics workstations, that are not covered in the 
Internet SGI FAQ lists.

Please send any additions, corrections, or suggestions to liamg@ssec.wisc.edu

Index
-----
1.0 Web Sites

2.0 Newsgroups

3.0 FORTRAN
 3.01 Why does my FORTRAN program that works on an IBM/RISC crash or give
      wildly different results on an SGI?
 3.02 Does the SGI FORTRAN compiler allow array bounds checking at runtime?
 3.03 Why does READ/WRITE act in a strange way when I OPEN a direct access file
      with a record length of 1 byte on the SGI?
 3.04 Can I call a C function from my SGI FORTRAN program?
 3.05 Are there SGI FORTRAN manuals available online? 
 3.06 How do I trap floating point errors like divide by zero or over/under flow?
 3.07 Can I access a tape drive from a FORTRAN program?
 3.08 How does SGI system X compare in FORTRAN execution speed to system Y?
 3.09 How do I get the best FORTRAN performance on SGI R8000 systems?
 3.10 My program compiles but crashes with 'Segmentation fault (core dumped)'
      when it tries to allocate some large arrays - what gives?
       
4.0 IDL
 4.1 Does IDL work on SGI R8000 CPUs running Irix 6.0.1?
 4.2 How do I stop the color table from flashing when I move the cursor between
     a graphics window and any other window?
 4.3 How do I stop a graphics window from being partially erased when I bring
     another window to the foreground over the graphics window?
     
5.0 UNIX
 5.1 How do I get my SGI to support a 24 bit display?
 5.2 I'm sick of using vi. Is there a better text editor for the SGI?
 5.3 How do I print text files in 2 column format in landscape mode?
  
6.0 MCIDAS
 6.1 Why doesn't the SGI FORTRAN compiler accept ZFFFF as a valid value?
 6.2 Why am I having problems when I call DKWP, DPP, DPPLL, or DKWPLL in FORTRAN?
 6.3 Why does the FORTRAN intrinsic ATAN2 fail when it worked on the IBM/RISC?
 6.4 Why does my FORTRAN output look strange when I use SDEST and WRITE(*,*)?
 6.5 Is there an easy way to read binary direct-access files in FORTRAN?
 
7.0 USING TAPE DRIVES
 7.1 Can I read a cpio tape that was created on an IBM/RISC?

1.0 Web Sites
-------------
 SGI Home
  http://www.sgi.com

 SGI FAQ
  http://www.cis.ohio-state.edu/hypertext/faq/usenet/sgi/top.html

 SGI anonymous FTP sites
  http://reality.sgi.com/employees/billh_hampton/anonftp

 SGI FORTRAN-77, FORTRAN-90, C, and C++ manuals
  http://www.sgi.com/Technology/TechPubs

 IDL Home
  http://www.rsinc.com

 IDL FAQ
  ftp://fermi.jhuapl.edu/www/s1r/idl/idl_faq/idl_faq.html

2.0 Newsgroups
--------------
(Use spool.cs.wisc.edu as your newserver)
news:comp.sys.sgi.admin
news:comp.sys.sgi.announce
news:comp.sys.sgi.apps
news:comp.sys.sgi.audio
news:comp.sys.sgi.bugs
news:comp.sys.sgi.graphics
news:comp.sys.sgi.hardware
news:comp.sys.sgi.misc

3.0 FORTRAN
-----------

3.01
Q: Why does my FORTRAN program that works on an IBM/RISC crash or give
   wildly different results on an SGI?
A: There are several possible reasons....
(a)The MIPS compiler by default does not initialize variables to zero,
   or SAVE variables in subroutines and functions. Use the -static
   compiler option to force it to.
(b)The MIPS compiler assumes record lengths are in 32 byte words by
   default. Use the compiler option -bytereclen to tell the compiler
   that record lengths are in bytes.
(c)The MIPS compiler on a R8000 CPU generates 64 bit code by default.
   Use the -32 compiler option to generate 32 bit code.
   In general, to get the closest agreement with code compiled on an IBM/RISC,
   use the compiler options -32 -bytereclen -static.

3.02
Q: Does the SGI FORTRAN compiler allow array bounds checking at runtime?
A: Yes. Use the -C compiler option (it's not documented in the man pages).

3.03
Q: Why does READ/WRITE act in a strange way when I OPEN a direct access file
   with a record length of 1 byte?
A: When you open a direct access file with a record length of 1 byte, the
   MIPS compiler treats the file as an ordinary system file (i.e. as a byte
   string). READ/WRITE requests consume bytes from the beginning of the file
   until satisfied, rather than acting on a specific record number. There
   is no known way to alter this behavior.

3.04   
Q: Can I call a C function from my FORTRAN program?
A: Yes. The C function name should have an underscore appended in the C source
   code. To call the C function as a SUBROUTINE, declare it as void in the
   C source code. To call the C function as a FUNCTION, declare it in the C
   source code to have the same type as in the FORTRAN calling program, e.g.
   int in C = INTEGER*2 in FORTRAN, long in C = INTEGER*4 in FORTRAN,
   float in C = REAL*4 in FORTRAN, double in C = DOUBLE PRECISION in FORTRAN.
   Also, ensure that you use either the -32 (or -64) compiler switches when 
   compiling both the C and FORTRAN programs, e.g.
   cc -32 -c cfile.c
   f77 -32 cfile.f cfile.o 
   Here's an example of calling a C function from FORTRAN...
   C code fragment:
   #include 
   #include 
   #include 
   short int closeb_( fd )
   short int *fd;
   {
   short int val;
   val = close( *fd );
   return( val );
   }
   FORTRAN calling program:
   INTEGER*2 CLOSEB, FD, RETVAL
   EXTERNAL CLOSEB
   RETVAL = CLOSEB( FD )

3.05
Q: Are there FORTRAN manuals available online?
A: Yes. If online manuals were installed, they can be viewed using insight.
   When you start insight, the following books should be displayed:
   Fortran 77 Language Reference Manual
   MIPSPro Fortran 77 Language Reference Manual
   MIPSPro Fortran 77 Programmers Guide
   If these books are not displayed, or they are displayed but will not open,
   then the books have not been installed. Contact your system administrator
   if this is the case.

3.06
Q: How do I trap floating point errors like divide by zero or over/under flow?
A: There are several ways. The simplest way is to link your program with the
   32-bit floating point exception library (/usr/lib/libfpe.a) and to set the
   environment variable TRAP_FPE to "ALL=DEFAULT", e.g. (C shell assumed)
   setenv TRAP_FPE "ALL=DEFAULT"
   f77 -32 prog.f /usr/lib/libfpe.a   (-32 may be omitted on non Irix 6 systems)
   See the man page for 'handle_sigfpes' for more information.

3.07
Q: Can I access a tape drive from a FORTRAN program?
A: Yes. The following FORTRAN-callable C code fragment allows reading/writing
   to Exabyte tape drives on an SGI (or other systems, if you remove the 
   trailing underscore from the function names). It should work for DAT, but
   has not yet been tested (Anyone care to verify that it works for DAT?).
   ----- cut here -----
   #include 
   #include 
   #include 
   short int openb_( name, status )
   char *name;
   short int *status;
   {
   short int fd;
   fd = -1;
   if( *status == 0 ) fd = open( name, 0 );
   if( *status == 1 ) fd = creat( name, 0644 );
   return( fd );
   }
   long int getb_( fd, buf, n )
   short int *fd;
   char *buf;
   long int *n;
   {
   long int nread;
   nread = read( *fd, buf, *n );
   return( nread );
   }
   long int putb_( fd, buf, n )
   short int *fd;
   char *buf;
   long int *n;
   {
   long int nwrit;
   nwrit = write( *fd, buf, *n );
   return( nwrit );
   }
   short int closeb_( fd )
   short int *fd;
   {
   short int val;
   val = close( *fd );
   return( val );
   }
   ----- cut here -----
   In your FORTRAN calling program, make the following declarations:
	character filename*72
      integer*2 openb, closeb, status, getb, putb, fd1
      integer*4 n, nread, nwrit
	external openb, closeb, getb, putb
   Then to open the tape device:
	filename = '/dev/tape'
	filename( 10 : 10 ) = char( 0 )
      status = 0
      fd1 = openb( filename, status )
      if( fd1 .eq. -1 ) stop 'Error opening input file'
   Note that status = 0 implies open for read-only, status = 1 implies open for
   read/write. The filename character string must be null-terminated.
   To read a 32K data block (buffer is a character*1 array with 32768 elements):
	n = 32768 
      nread = getb( fd1, buffer, n )
      if( nread .ne. n ) stop 'Error reading input file'
   To write a 32K data block (assuming status = 1 in openb call):
	n = 32768
	nwrit = putb( fd1, buffer, n )
	if( nwrit .ne. n ) stop 'Error writing output file' 
   To close the tape device
	status = closeb( fd1 )
	if( status .eq. -1 ) stop 'Error closing file'
   And that's all there is to it. For doing things like rewinding the tape, and
   skipping forward and backwards over files or records, use the SYSTEM
   subroutine (a FORTRAN-77 extension), e.g.
	call system( 'mt -f /dev/tape rewind' )
	call system( 'mt -f /dev/tape fsf 1' )
   Make sure that you use the correct tape device driver. We always use the 
   'nrnsv' drivers (e.g. /dev/rmt/tps0d3nrnsv) which means no rewind, no
   swap-bytes, variable block length. To compile you main program (say prog.f):
   cc -c fileio.c      (or whatever you called the C code fragment)
   f77 -o prog prog.f fileio.o
   If you use the -32 or -mips2 switches on an Irix 6 system, make sure you
   use it for both the C and FORTRAN compile commands.

3.08
Q: How does SGI system X compare in FORTRAN execution speed to system Y?
A: Check out http://www.sissa.it/furio/mdbnch.html. You will find a list
   of benchmark results for a wide variety of workstations, including many
   varieties of SGI boxes. This particular benchmark is a reasonable indicator
   of execution speed for numerically intensive FORTRAN codes that do not
   utilize parallel processing.

3.09
Q: How do I get the best FORTRAN performance on SGI single-CPU R8000 systems?
A: Check out http://www.astro.ku.dk:80/~aake/optimize/index.html for an
   excellent summary of the steps involved in optimizing FORTRAN code for
   the best performance on SGI R8000 systems, as well as issues involved in
   porting code from SGI R3000/R4000/R4400 systems to R8000 systems. In general,
   the best performance can be had by using the following compiler options:
   f77 -O3 -OPT:round=3:IEEE_ar=3:fast_sq=ON -GCM:array_sp=ON -lfastm prog.f
   However be aware that this may give different results when compared to
   output from the same program compiled at a lower optimization level.
   Check your results at several optimization levels to see if there are any
   significant differences.
   If you have a program that was developed on an IBM/RISC, try
   f77 -mips2 -O2 -static -bytereclen prog.f
   on SGI R4000/R4400/R8000 systems to give the best performance, while
   generating results which are in close agreement with those obtained on
   the IBM/RISC.

3.10
Q: My program compiles but crashes with 'Segmentation fault (core dumped)'
   when it tries to allocate some large arrays - what gives?
A: You may be running into a stacksize limit. In csh, try
   % limit
   to see the current limits. To see the maximum limits allowed, use
   % limit -h
   If you want to increase the current limits to the maximum allowed, use
   % unlimit
   In ksh, the command to view the current limits is
   $ ulimit -a
   and to see the maximum limits allowed
   $ ulimit -a -H
   To reset the stacksize to the maximum, use
   $ ulimit -s value
   where value is the stacksize reported by 'ulimit -a -H'. For more
   information, check the man page for csh or ksh.

4.0 IDL
-------

4.1
Q: Does IDL work on SGI R8000 CPUs running Irix 6.0.1?
A: Yes. IDL 4.0 and 4.0.1 run just fine on the Power Indigo2 under Irix 6.0.1.

4.2
Q: How do I stop the color table from flashing when I move the cursor between
   a graphics window and any other window?
A: Add the following line to the .Xdefaults file in your login directory:
   Idl*visual: PseudoColor
   if you have an 8 bit display, or add the line
   Idl*visual: TrueColor
   if you have a 24 bit display.

4.3
Q: How do I stop the graphics window from being partially erased when I bring
   another window to the foreground over the graphics window?
A: When you create the graphics window, use the keyword RETAIN=2. For a
   permanent fix, see section 5.1. All you need to do is remove the -bs flag
   in /usr/lib/X11/xdm/Xservers.

5.0 UNIX
--------

5.1
Q: How do I get my SGI to support a 24 bit display?
A: You need to edit the file /usr/lib/X11/xdm/Xservers (root privilege
   required). By default this file should contain the following:
:0 secure /usr/bin/X11/X -bs -c -pseudomap 4sight
   To enable 24 bit color (if you have 24 bit hardware) and backing store
   change this to read:
:0 secure /usr/bin/X11/X -c -class TrueColor -depth 24
   Notice the "-bs" is also missing: removing "-bs" enables backingstore.
   You will then need to restart your X server.  To accomplish this type the
   following:
   % killall -TERM Xsgi

5.2
Q: I'm sick of using vi. Is there a better text editor for the SGI?
A: Yes. Nedit is an easy to use GUI editor that requires no special
   installation or setup. It is available via anonymous FTP from ftp.fnal.gov
   in pub/nedit/v3_1_1/nedit_sgi.

5.3
Q: How do I print text files in 2 column format in landscape mode?
A: The following C shell script will print text files (such as source code) in
   2 column format in landscape mode, with line numbers added, and a banner
   specifying the date and name of the file.
   ----- cut here -----
   #!/bin/csh
   # a quick hack to print text file(s) in 2 column format with a header
   if ( $#argv == 0 ) then
     echo "usage: print file(s)"
     exit(-1)
   endif
   while ( $#argv )
     nl -ba $argv[1] | /usr/lib/print/lptops \
	 -G -E `pwd`/$argv[1] -U -L 0pt -R 0pt \
	 -H -FC -P 7pt -M2 | lpr -Plp2
     shift
   end
   exit(0)
   ----- cut here -----

6.0 MCIDAS
----------

6.1
Q: Why doesn't the SGI FORTRAN compiler accept ZFFFF as a valid value?
A: Hexadecimal constants in SGI FORTRAN are specified as 'string'Z where
   string may contain a maximum of 16 characters. Valid 'string' characters
   are 0-9, A-F.

6.2
Q: Why am I having problems when I call DKWP, DPP, DPPLL, or DKWPLL in FORTRAN?
A: These functions must be explicitly declared as DOUBLE PRECISION. When DKWP
   is given a default value, make sure to append D0 to the value (e.g. 1.5D0).
   To return a single precision keyword, use the DKWP as follows:
   VAR = SNGL( DKWP( 'VAR', 1, 1.5D0 ) )

6.3
Q: Why does the FORTRAN intrinsic ATAN2 fail when it worked on the IBM/RISC?
A: ATAN2 will return nonsense if you feed it an argument where it fails.
   The IBM/RISC fills a zero when this happens. See the man page for ATAN2
   for more details.

6.4
Q: Why does my FORTRAN output look strange when I use SDEST and WRITE(*,*)?
A: SDEST sends output to the screen as it occurs, whereas WRITE(*,*) output
   is buffered into blocks and sent to the screen after the buffer fills.
   The result is a very confusing mish-mash of output that is of little use.
   This does not happen on the IBM RISC. The solution is to use either SDEST
   or WRITE(*,*) exclusively.

6.5
Q: Is there an easy way to read binary direct-access files in FORTRAN?
A: Yes. Use the MCIDAS LBI function, which has the following form:
   RTN = LBI( FILE, START, LENGTH, BUFFER )
   where RTN is the return code, FILE is a file name string, START is the 
   start byte number (0=first), LENGTH is the number of bytes to read, and
   BUFFER is an array of appropriate type and size to hold the requested data.
   If you have a record length RECLEN in bytes and a record number RECNUM:
   START = ( RECNUM - 1 ) * RECLEN
   LENGTH = RECLEN

7.0 USING TAPE DRIVES
---------------------

7.1
Q: Can I read a cpio tape that was created on an IBM/RISC?
A: Yes. However, please note that tar tapes are generally much more portable
   between different systems than cpio tapes, and thus the use of cpio is
   discouraged.
   The important points to be aware of are:
(a)Ensure that you are using the correct tape device on the SGI. Before you use
   the /dev/tape or /dev/nrtape softlinks, use the command
   ls -lsa /dev/tape
   to check exactly which tape device the link points to. Ensure that you use
   the device with the same density/compression options as on the IBM/RISC.
(b)If the -C switch was used when the cpio tape was created on the IBM/RISC,
   then it must also be used on the SGI. However on the IBM/RISC, '-C value'
   means that input and output is stored with (value*512) bytes per record
   (e.g. -C 64 => 32768 bytes per record). On the SGI, '-C value' means that
   input and output is stored with (value) bytes per record (no *512 factor).
   So, if '-C 64' was used to create the tape on the IBM/RISC, then
   '-C 32768' must be used on the SGI to read the tape.