home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.fortran
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!hermes.chpc.utexas.edu!michael
- From: michael@chpc.utexas.edu (Michael Lemke)
- Subject: Re: file redirection under unix
- Message-ID: <1992Dec15.202353.5221@chpc.utexas.edu>
- Organization: The University of Texas System - CHPC
- References: <1992Dec15.192847.12970@wl.com>
- Distribution: usa
- Date: Tue, 15 Dec 92 20:23:53 GMT
- Lines: 74
-
- In article <1992Dec15.192847.12970@wl.com> agrafiot@wl.com (Dimitris Agrafiotis) writes:
- >
- >A trivial question: how does one redirect fortran output on a unix system?
- >(the vms equivalent would be DEFINE FOR012 file.dat). If the answer is
- >soft links, how do we take care of multiple versions of the program
- >running in the same default directory?
-
- In general, the answer is soft links. However, there are Unixes around
- that don't have soft links (Cray/UNICOS if I remember correctly) and
- also some that have special commands to do what you want (e.g.
- Cray/UNICOS' assign).
-
- The version number problem is a nuisance but what can you expect from
- Unix? You have to create temporary directories. Run the stuff in a
- script (Bourne shell of course). Here is my solution I use on a Sun.
- It should work on many systems:
-
-
- #!/bin/sh
- #
- # create temporary directory and define trap to make sure temp dir
- # is removed at job end
- #
- HERE=`pwd`
- TEMP=$HOME/$$
- mkdir $TEMP
- trap 'cd ..; rm -r $TEMP; cd $HERE; exit' 0
- trap 'echo -n "Clean up? " >&2
- read ans </dev/tty
- if [ ${ans}x != 'yx' -a ${ans}x != 'Yx' ]
- then
- echo "Ok, files left in" $TEMP >&2
- cd $HERE
- trap 0
- fi
- exit' 2
- #
- # traps defined
- #
-
- #
- # Do the links here (also copy of input file if necessary); e.g.:
- #
- ln -s file.dat $TEMP/fort.12
-
- #
- # now switch to temp dir; the reason I first copy files to $TEMP is that
- # file.dat could have a relative path name
- #
- cd $TEMP
-
- #
- # Do your stuff
- #
- stuff
-
- #
- # copy results back to where you started from. Watch out again for
- # overwriting former results. I love Unix.
-
- cp fort.7 ${HERE}/some_better_name_than_fort.7
-
- #
- # clean up is done by traps
- #
-
-
- If you have questions about this send me e-mail.
-
- Michael
- --
- Michael Lemke
- Astronomy, UT Austin, Texas
- (michael@io.as.utexas.edu or UTSPAN::UTADNX::IO::MICHAEL [SPAN])
-