home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / softsys / matlab / 120 < prev    next >
Encoding:
Text File  |  1993-01-23  |  2.1 KB  |  78 lines

  1. Newsgroups: comp.soft-sys.matlab
  2. Path: sparky!uunet!stanford.edu!nntp.Stanford.EDU!forsythe.stanford.edu!nova!maurer
  3. From: Michael Maurer <maurer@nova.stanford.edu>
  4. Subject: SOURCE: tempname.m - generate temporary filename
  5. Message-ID: <maurer.727751313@nova.Stanford.EDU>
  6. Sender: news@leland.Stanford.EDU (Mr News)
  7. Organization: STAR Lab, Stanford University, California USA
  8. Date: 23 Jan 93 01:08:33 GMT
  9. Lines: 67
  10.  
  11. Hoping to start a trend, here is an unsolicited matlab m-file.
  12. TEMPNAME generates a temporary filename.
  13. Suggested improvements are welcome.
  14.  
  15. #! /bin/sh
  16. # This is a shell archive, meaning:
  17. # 1. Remove everything above the #! /bin/sh line.
  18. # 2. Save the resulting text in a file.
  19. # 3. Execute the file with /bin/sh (not csh) to create the files:
  20. #    tempname.m
  21. # This archive created: Fri Jan 22 16:55:48 1993
  22. export PATH; PATH=/bin:$PATH
  23. echo shar: extracting "'tempname.m'" '(705 characters)'
  24. if test -f 'tempname.m'
  25. then
  26.     echo shar: will not over-write existing file "'tempname.m'"
  27. else
  28. sed 's/^XX//' << \SHAR_EOF > 'tempname.m'
  29. XXfunction s=tempname(prefix,ext,touch)
  30. XX
  31. XX%TEMPNAME
  32. XX%    S=TEMPNAME returns a temporary filename.
  33. XX%    S=TEMPNAME(PREFIX) returns a filename with PREFIX prepended.
  34. XX%    S=TEMPNAME(PREFIX,EXT) appends EXT.
  35. XX
  36. XX%    Michael Maurer, Feb  4 1991
  37. XX%    Copyright (c) 1993 by Michael Maurer
  38. XX
  39. XXif (nargin<1)
  40. XX   prefix='tmp';
  41. XXend
  42. XXif (nargin<2)
  43. XX   ext='';
  44. XXend
  45. XXif nargin<3,
  46. XX   touch=1;
  47. XXend
  48. XX
  49. XXt = clock;
  50. XXt(6) = t(6)*100;
  51. XXt=fix(t);
  52. XXts=sprintf('%02.0f%02.0f%04.0f',t(4),t(5),t(6));
  53. XXs = [prefix ts ext];
  54. XX
  55. XX% Now add distinguishing letter if necessary
  56. XXlet='a';
  57. XXwhile exist(s)==2 & let<='z',
  58. XX   s=[prefix ts let ext];
  59. XX   let=setstr(let+1)
  60. XXend
  61. XXif exist(s)==2,
  62. XX   error('Failed to find temporary filename')
  63. XXend
  64. XXif touch,
  65. XX   eval(['!touch ' s])
  66. XXend
  67. SHAR_EOF
  68. if test 705 -ne "`wc -c < 'tempname.m'`"
  69. then
  70.     echo shar: error transmitting "'tempname.m'" '(should have been 705 characters)'
  71. fi
  72. fi # end of overwriting check
  73. #    End of shell archive
  74. exit 0
  75. --
  76. ______________________________________________________________________
  77. Michael Maurer          maurer@nova.stanford.edu        (415) 723-1024
  78.