/
RoughSurface.jl
70 lines (58 loc) · 1.73 KB
/
RoughSurface.jl
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
module RoughSurface
# Write your package code here.
using DelimitedFiles, JLD2, FileIO
using PyCall
export write_surf, read_surf, show_surf
```@meta
CurrentModule = RoughSurface
```
include(joinpath(@__DIR__, "RoughSurface_GUI.jl"))
include(joinpath(@__DIR__, "RoughSurface_Controller.jl"))
"""
write_surf()
将表面数据写入文件, 默认txt文件的数据用制表符分割, csv文件的数据用``,''分割,
jld2则为直接保存二进制文件
"""
function write_surf(file_path, surf)
# 利用splitext来得到文件类型
file_ext = splitext(file_path)[2]
if file_ext == ".txt"
open(file_path, "w") do io
writedlm(io, surf)
end # do
elseif file_ext == ".csv"
open(file_path, "w") do io
writedlm(io, surf, ',')
end # do
elseif file_ext == ".jld2"
save(file_path, "surf", surf)
else
@warn("未知的文件类型, 保存为jld2格式")
save(file_path*".jld2", "surf", surf)
end
end # function
"""
read_surf()
从文件读取表面数据, 与写入数据保持一致, 默认txt文件的数据用制表符分割, csv文件的数据用``,''分割,
jld2则为直接保存二进制文件.
"""
function read_surf(file_path)
file_ext = splitext(file_path)[2]
if file_ext == ".txt"
surf = readdlm(file_path)
elseif file_ext == ".csv"
surf = readdlm(file_path, ',')
elseif file_ext == ".jld2"
surf = load(file_path,"surf")
else
@warn("未知的文件类型, 尝试jld2格式")
surf = load(file_path*".jld2","surf")
end
return surf
end # function
"""
show_surf()
利用python的pyvista包显示规则表面数据.
"""
show_surf(surf_mat) = py"show_surf"(surf_mat)
end # module