-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmg_filename.pro
70 lines (59 loc) · 2.07 KB
/
mg_filename.pro
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
70
; From https://github.com/mgalloy/mglib/blob/master/src/fileio/mg_filename.pro
; docformat = 'rst'
;+
; Compose and/or decompose a filename.
;
; :Examples:
; Try the main-level example program at the end of this file::
;
; IDL> .run mg_filename
;
; It should do::
;
; IDL> f = mg_filename('a.dat', subdir=['b', 'c'], $
; IDL> basename=basename, extension=extension, $
; IDL> dirname=dirname, directories=directories)
; IDL>
; IDL> print, f, format='(%"Filename: %s")'
; Filename: b/c/a.dat
; IDL>
; IDL> print, basename, format='(%"Basename: %s")'
; Basename: a.dat
; IDL> print, extension, format='(%"Extension: %s")'
; Extension: dat
; IDL>
; IDL> print, dirname, format='(%"Directory: %s")'
; Directory: b/c/
; IDL> print, strjoin(directories, ', '), format='(%"Directories: %s")'
; Directories: b, c
;
; :Params:
; filename : in, optional, type=string
; filename/basename
;
; :Keywords:
; object : out, optional, type=object
; object reference of the underlying `MGffFilename` object; this object
; will be destroyed if it is not requested using this keyword
; _ref_extra : in, out, optional, type=keywords
; keywords to `MGffFilename::init`
;-
function mg_filename, filename, object=object, _ref_extra=e
compile_opt strictarr
object = obj_new('MGffFilename', filename, _extra=e)
f = object->toString()
if (~arg_present(object)) then obj_destroy, object
return, f
end
; main-level example program
f = mg_filename('a.dat', subdir=['b', 'c'], $
basename=basename, extension=extension, $
dirname=dirname, directories=directories)
print, f, format='(%"Filename: %s")'
print, basename, format='(%"Basename: %s")'
print, extension, format='(%"Extension: %s")'
print, dirname, format='(%"Directory: %s")'
print, strjoin(directories, ', '), format='(%"Directories: %s")'
print, mg_filename('link-%d.html', /clock_basename, /tmp), $
format='(%"Temporary file with time/date:\n %s")'
end