-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathas_exportstructtocsv__define.pro
More file actions
51 lines (35 loc) · 1.21 KB
/
as_exportstructtocsv__define.pro
File metadata and controls
51 lines (35 loc) · 1.21 KB
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
FUNCTION as_exportstucttocsv::init
@as_scatterheader.macro
RETURN, 1
END
PRO as_exportstructtocsv::export, structArray, FILENAME = fileName
@as_scatterheader.macro
numberTags = N_Tags(structArray)
tagNames = Tag_Names(structArray)
array = !null
FOREACH name, TagNames, key DO BEGIN
column = [name, String(structArray.(key))]
array = [array,Transpose(column)]
ENDFOREACH
reopen:
IF ~KeyWord_Set(fileName) THEN fileName = Dialog_Pickfile(/OVERWRITE_PROMPT, /WRITE, FILTER = ['*.CSV'], DEFAULT_EXTENSION = 'CSV')
IF fileName EQ 'Cancel' THEN RETURN
OpenW, fileLun, fileName, ERROR = err, /GET_LUN
IF err NE 0 THEN BEGIN
result = Dialog_Message('Error opening file for writing. Choose another file?', /QUESTION)
IF ISA(fileLun,/NUMBER) THEN Free_Lun, fileLun
IF result EQ 'Yes' THEN BEGIN
fileName = !null
GOTO, reopen
ENDIF ELSE RETURN
ENDIF
FOR i=0, N_Elements(column) - 1 DO BEGIN
tempStr = StrJoin(array[*,i],',',/SINGLE)
PrintF, fileLun, tempStr
ENDFOR
Free_Lun, fileLun
END
PRO as_exportstructtocsv__define
void = {as_exportstructtocsv, $
void : ''}
END