Skip to content

Commit 37e83af

Browse files
committed
Merge branch 'devel'
2 parents be1de70 + 864d51f commit 37e83af

File tree

3 files changed

+42
-32
lines changed

3 files changed

+42
-32
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[package]
22
name = "parallel-gnuplot"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
authors = ["Cassio Kirch <cassiokirch@gmail.com>"]
55
description = "Parallel calls to `GNUPlot`. Calls the same `GNUPlot` script once for each data file block."
66
keywords = ["gnuplot", "parallel", "plot", "plotting"]
7-
categories = ["science"]
7+
categories = ["science", "command-line-utilities"]
88
license = "GPL-3.0"
99
readme = "README.md"
1010
repository = "https://github.com/kirch7/parallel-gnuplot"

README.md

+26-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
# parallel-gnuplot
22
Parallel calls to <a href="http://www.gnuplot.info/">GNUPlot</a>.
3-
Calls the same <tt>GNUPlot</tt> script once for each data file block.
4-
Please, note <tt>GNUPlot</tt> has copyrights,
5-
and <tt>parallel-gnuplot</tt> is <strong>not</strong> a modified version of <tt>GNUPlot</tt>.
3+
Calls the same `GNUPlot` script once for each data file block.
4+
Please, note `GNUPlot` has copyrights,
5+
and `parallel-gnuplot` is <strong>not</strong> a modified version of `GNUPlot`.
66

77
# GNUPlot variables
8-
<tt>parallel-gnuplot</tt> sets some <tt>GNUPlot</tt> variables:
8+
`parallel-gnuplot` sets some `GNUPlot` variables:
99
<ul>
10-
<li><tt>INDEX</tt>: block index, starting at <tt>0</tt>;</li>
11-
<li><tt>DATAFILE</tt>: path of a data file containing only a single block.</li>
10+
<li>`INDEX`: block index, starting at `0`;</li>
11+
<li>`DATAFILE`: path of a data file containing only a single block.</li>
1212
</ul>
1313

1414
# Usage
15-
<tt>parallel-gnuplot datafilename gpfilename [tmpdirectory]</tt>
15+
`parallel-gnuplot datafilename gpfilename [tmpdirectory]`
16+
17+
or
18+
19+
`cargo run --release -- datafilename gpfilename [tmpdirectory]`
20+
21+
where `[tmpdirectory]` is optional.
1622

1723
# Example
1824

@@ -50,5 +56,17 @@ set output sprintf("%d", INDEX).'.png'
5056
plot DATAFILE with lp lw 2 pt 7 ps 3 title sprintf("Block %d", INDEX)
5157
```
5258

53-
You can call: <tt>parallel-gnuplot ./data.txt ./script.gp .</tt>
59+
You can call:
60+
`parallel-gnuplot ./data.txt ./script.gp`
61+
or
62+
`cargo run --release -- ./data.txt ./script.gp`
5463

64+
# Features
65+
<ul>
66+
<li>Tested with the Operating Systems:
67+
<ul>
68+
<li><em>MS Windows</em> (works since v0.1.4),</li>
69+
<li><em>GNU/Linux</em>.</li>
70+
<li>(Let me know if works in other OSs.)</li>
71+
</ul>
72+
</ul>

src/main.rs

+14-22
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extern crate threadpool;
6161
use threadpool::ThreadPool;
6262
use std::sync::mpsc::channel;
6363
use std::process::Command;
64-
use std::fs::File;
64+
use std::fs::{File, ReadDir};
6565
use std::io::Write;
6666

6767
fn get_read_file(filename: &String) -> File {
@@ -71,6 +71,13 @@ fn get_read_file(filename: &String) -> File {
7171
}
7272
}
7373

74+
fn get_folder(foldername: &String) -> ReadDir {
75+
match std::fs::read_dir(&foldername) {
76+
Ok(dir) => dir,
77+
Err(e) => { panic!("Error opening {}: {}", foldername, e.to_string()); },
78+
}
79+
}
80+
7481
fn get_write_file(filename: &String) -> File {
7582
match File::create(filename) {
7683
Ok(file) => file,
@@ -79,24 +86,7 @@ fn get_write_file(filename: &String) -> File {
7986
}
8087

8188
fn check_folder(path: &String) -> Result<(), String> {
82-
let file = get_read_file(path);
83-
let metadata = match file.metadata() {
84-
Ok(metadata) => metadata,
85-
Err(e) => {
86-
let message = "Error getting ".to_string() + path + ": " + &e.to_string();
87-
return Err(message);
88-
},
89-
};
90-
if !metadata.is_dir() {
91-
let message = path.clone() + " is not a directory.";
92-
return Err(message);
93-
}
94-
95-
if metadata.permissions().readonly() {
96-
let message = path.clone() + "is readonly";
97-
return Err(message);
98-
}
99-
89+
let file = get_folder(path);
10090
Ok(())
10191
}
10292

@@ -126,12 +116,14 @@ fn main() {
126116
let gpfilename = &args[2];
127117
let tmpfoldername = {
128118
if args.len() > 3 {
129-
&args[3]
119+
args[3].clone()
130120
} else {
131-
"/tmp/"
121+
std::env::temp_dir()
122+
.into_os_string()
123+
.into_string()
124+
.unwrap()
132125
}
133126
};
134-
let tmpfoldername = tmpfoldername.to_string();
135127
match check_folder(&tmpfoldername) {
136128
Err(e) => { panic!(e); },
137129
_ => { },

0 commit comments

Comments
 (0)