1+ #= =========================================================================================+
2+ | TABLE OF CONTENTS: |
3+ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4+ | - readxy |
5+ | - readxyz |
6+ | - savexy |
7+ | - savexyz |
8+ +==========================================================================================#
9+
10+ export readxy
11+ export readxyz
12+ export savexy
13+ export savexyz
14+
15+ """
16+ readxy(file_dir::P) where P <: String
17+
18+ Description:
19+ ---
20+ Read the 2D `.xy` file from `file_dir`.
21+ """
22+ function readxy (file_dir:: P ) where P <: String
23+ xy = readdlm (file_dir, ' ' )[:, 1 : 2 ]
24+ return Array {Float64} (xy)
25+ end
26+
27+ """
28+ readxyz(file_dir::P) where P <: String
29+
30+ Description:
31+ ---
32+ Read the 3D `.xyz` file from `file_dir`.
33+ """
34+ function readxyz (file_dir:: P ) where P <: String
35+ xyz = readdlm (file_dir, ' ' )[:, 1 : 3 ]
36+ return Array {Float64} (xyz)
37+ end
38+
39+ """
40+ savexy(file_dir::P, pts::T) where {P <: String, T <: AbstractMatrix}
41+
42+ Description:
43+ ---
44+ Save the 2D points `pts` to the `.xy` file (`file_dir`).
45+ """
46+ function savexy (file_dir:: P , pts:: T ) where {P <: String , T <: AbstractMatrix }
47+ size (pts, 2 ) == 2 || throw (ArgumentError (" The input points should have 2 columns." ))
48+ open (file_dir, " w" ) do io
49+ writedlm (io, pts, ' ' )
50+ end
51+ end
52+ savexy (pts:: T , file_dir:: P ) where {P <: String , T <: AbstractMatrix } = savexy (file_dir, pts)
53+
54+ """
55+ savexyz(file_dir::P, pts::T) where {P <: String, T <: AbstractMatrix}
56+
57+ Description:
58+ ---
59+ Save the 3D points `pts` to the `.xyz` file (`file_dir`).
60+ """
61+ function savexyz (file_dir:: P , pts:: T ) where {P <: String , T <: AbstractMatrix }
62+ size (pts, 2 ) == 3 || throw (ArgumentError (" The input points should have 3 columns." ))
63+ open (file_dir, " w" ) do io
64+ writedlm (io, pts, ' ' )
65+ end
66+ end
67+ savexyz (pts:: T , file_dir:: P ) where {P <: String , T <: AbstractMatrix } = savexyz (file_dir, pts)
0 commit comments