File: mwpath.m

package info (click to toggle)
octave-iso2mesh 1.9.8%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 11,128 kB
  • sloc: cpp: 11,982; ansic: 10,158; sh: 365; makefile: 59
file content (69 lines) | stat: -rw-r--r-- 1,727 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function tempname = mwpath(fname)
%
% tempname=meshtemppath(fname)
%
% get full temp-file name by prepend working-directory and current session name
%
% author: Qianqian Fang (q.fang at neu.edu)
%
% input:
%    fname: input, a file name string
%
% output:
%    tempname: output, full file name located in the working directory
%
%    if global variable ISO2MESH_TEMP is set in 'base', it will use it
%    as the working directory; otherwise, will use matlab function tempdir
%    to return a working directory.
%
%    if global variable ISO2MESH_SESSION is set in 'base', it will be
%    prepended for each file name, otherwise, use supplied file name.
%
% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
%

if (nargin < 1) || isempty(fname)
    fname = '';
end

p = getvarfrom({'caller', 'base'}, 'ISO2MESH_TEMP');
session = getvarfrom({'caller', 'base'}, 'ISO2MESH_SESSION');

if (isempty(session))
    session = '';
end

username = getenv('USER'); % for Linux/Unix/Mac OS

if (isempty(username))
    username = getenv('UserName'); % for windows
end

if (~isempty(username))
    username = ['iso2mesh-' username];
end

tempname = [];
if (isempty(p))
    if (isoctavemesh && tempdir == '\')
        tempname = ['.'  filesep session fname];
    else
        tdir = tempdir;
        if (tdir(end) ~= filesep)
            tdir = [tdir filesep];
        end
        if (~isempty(username))
            tdir = [tdir username filesep];
            if (exist(tdir) == 0)
                mkdir(tdir);
            end
        end
        if (nargin == 0)
            tempname = tdir;
        else
            tempname = [tdir session fname];
        end
    end
else
    tempname = [p filesep session fname];
end