home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.soft-sys.matlab
- Path: sparky!uunet!stanford.edu!nntp.Stanford.EDU!forsythe.stanford.edu!nova!maurer
- From: Michael Maurer <maurer@nova.stanford.edu>
- Subject: SOURCE: tempname.m - generate temporary filename
- Message-ID: <maurer.727751313@nova.Stanford.EDU>
- Sender: news@leland.Stanford.EDU (Mr News)
- Organization: STAR Lab, Stanford University, California USA
- Date: 23 Jan 93 01:08:33 GMT
- Lines: 67
-
- Hoping to start a trend, here is an unsolicited matlab m-file.
- TEMPNAME generates a temporary filename.
- Suggested improvements are welcome.
-
- #! /bin/sh
- # This is a shell archive, meaning:
- # 1. Remove everything above the #! /bin/sh line.
- # 2. Save the resulting text in a file.
- # 3. Execute the file with /bin/sh (not csh) to create the files:
- # tempname.m
- # This archive created: Fri Jan 22 16:55:48 1993
- export PATH; PATH=/bin:$PATH
- echo shar: extracting "'tempname.m'" '(705 characters)'
- if test -f 'tempname.m'
- then
- echo shar: will not over-write existing file "'tempname.m'"
- else
- sed 's/^XX//' << \SHAR_EOF > 'tempname.m'
- XXfunction s=tempname(prefix,ext,touch)
- XX
- XX%TEMPNAME
- XX% S=TEMPNAME returns a temporary filename.
- XX% S=TEMPNAME(PREFIX) returns a filename with PREFIX prepended.
- XX% S=TEMPNAME(PREFIX,EXT) appends EXT.
- XX
- XX% Michael Maurer, Feb 4 1991
- XX% Copyright (c) 1993 by Michael Maurer
- XX
- XXif (nargin<1)
- XX prefix='tmp';
- XXend
- XXif (nargin<2)
- XX ext='';
- XXend
- XXif nargin<3,
- XX touch=1;
- XXend
- XX
- XXt = clock;
- XXt(6) = t(6)*100;
- XXt=fix(t);
- XXts=sprintf('%02.0f%02.0f%04.0f',t(4),t(5),t(6));
- XXs = [prefix ts ext];
- XX
- XX% Now add distinguishing letter if necessary
- XXlet='a';
- XXwhile exist(s)==2 & let<='z',
- XX s=[prefix ts let ext];
- XX let=setstr(let+1)
- XXend
- XXif exist(s)==2,
- XX error('Failed to find temporary filename')
- XXend
- XXif touch,
- XX eval(['!touch ' s])
- XXend
- SHAR_EOF
- if test 705 -ne "`wc -c < 'tempname.m'`"
- then
- echo shar: error transmitting "'tempname.m'" '(should have been 705 characters)'
- fi
- fi # end of overwriting check
- # End of shell archive
- exit 0
- --
- ______________________________________________________________________
- Michael Maurer maurer@nova.stanford.edu (415) 723-1024
-