home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / fortran / 4730 < prev    next >
Encoding:
Text File  |  1992-12-15  |  2.3 KB  |  86 lines

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!usc!cs.utexas.edu!hermes.chpc.utexas.edu!michael
  3. From: michael@chpc.utexas.edu (Michael Lemke)
  4. Subject: Re: file redirection under unix
  5. Message-ID: <1992Dec15.202353.5221@chpc.utexas.edu>
  6. Organization: The University of Texas System - CHPC
  7. References: <1992Dec15.192847.12970@wl.com>
  8. Distribution: usa
  9. Date: Tue, 15 Dec 92 20:23:53 GMT
  10. Lines: 74
  11.  
  12. In article <1992Dec15.192847.12970@wl.com> agrafiot@wl.com (Dimitris Agrafiotis) writes:
  13. >
  14. >A trivial question: how does one redirect fortran output on a unix system?
  15. >(the vms equivalent would be DEFINE FOR012 file.dat). If the answer is
  16. >soft links, how do we take care of multiple versions of the program 
  17. >running in the same default directory?
  18.  
  19. In general, the answer is soft links.  However, there are Unixes around
  20. that don't have soft links (Cray/UNICOS if I remember correctly) and
  21. also some that have special commands to do what you want (e.g.
  22. Cray/UNICOS' assign).
  23.  
  24. The version number problem is a nuisance but what can you expect from
  25. Unix?  You have to create temporary directories.  Run the stuff in a
  26. script (Bourne shell of course).  Here is my solution I use on a Sun. 
  27. It should work on many systems:
  28.  
  29.  
  30. #!/bin/sh
  31. #
  32. #    create temporary directory and define trap to make sure temp dir
  33. #       is removed at job end
  34. #
  35. HERE=`pwd`
  36. TEMP=$HOME/$$
  37. mkdir $TEMP
  38. trap 'cd ..; rm -r $TEMP; cd $HERE; exit' 0
  39. trap 'echo -n "Clean up? " >&2
  40.       read ans </dev/tty
  41.       if [ ${ans}x != 'yx' -a ${ans}x != 'Yx' ]
  42.       then
  43.          echo "Ok, files left in" $TEMP >&2
  44.          cd $HERE
  45.          trap 0
  46.       fi
  47.       exit' 2
  48. #
  49. #    traps defined
  50. #
  51.  
  52. #
  53. #   Do the links here (also copy of input file if necessary); e.g.:
  54. #
  55. ln -s file.dat $TEMP/fort.12
  56.  
  57. #
  58. # now switch to temp dir;  the reason I first copy files to $TEMP is that
  59. #                          file.dat could have a relative path name
  60. #
  61. cd $TEMP
  62.  
  63. #
  64. #  Do your stuff
  65. #
  66. stuff
  67.  
  68. #
  69. # copy results back to where you started from.  Watch out again for 
  70. # overwriting former results.  I love Unix.  
  71.  
  72. cp fort.7 ${HERE}/some_better_name_than_fort.7
  73.  
  74. #
  75. # clean up is done by traps
  76. #
  77.  
  78.  
  79. If you have questions about this send me e-mail.
  80.  
  81. Michael
  82. -- 
  83. Michael Lemke
  84. Astronomy, UT Austin, Texas
  85. (michael@io.as.utexas.edu or UTSPAN::UTADNX::IO::MICHAEL [SPAN])
  86.