forked from UsAndRufus/ThirdYearProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added creation of custom fit scripts
- Loading branch information
1 parent
0237990
commit 21b46b0
Showing
4 changed files
with
57 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,8 @@ hs_err_pid* | |
# Project files | ||
*.data | ||
|
||
gnuplot/created | ||
|
||
# Output files | ||
*.png | ||
*.ps | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
set logscale x | ||
set logscale y | ||
set xrange [1:] | ||
set yrange [:1] | ||
set yrange [:2] | ||
set xlabel "a" | ||
set ylabel "P(A≥a)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package output; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES; | ||
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; | ||
|
||
public class FitScriptCreator { | ||
private static final String REPLACE_STRING = "REPLACE"; | ||
private static final String FILE_TYPE = ".data"; | ||
private static final Path FIT_SCRIPT_PATH = Paths.get("ThirdYearProject/gnuplot/fit.plt"); | ||
private static final String CREATED_DIRECTORY_PATH_STRING = "ThirdYearProject/gnuplot/created/"; | ||
|
||
public static void main(String[] args) throws IOException { | ||
System.out.println("Run from outside ThirdYearProject"); | ||
if (!(args[0].startsWith("ThirdYearProject/"))) { | ||
System.out.println("Filepath argument must start with ThirdYearProject/"); | ||
throw new IllegalArgumentException(); | ||
} | ||
String dataFilePathString = args[0]; | ||
|
||
createFor(Paths.get(dataFilePathString)); | ||
|
||
} | ||
|
||
public static void createFor(Path dataFilePath) throws IOException { | ||
String filename = dataFilePath.getFileName().toString(); | ||
filename = "fit_" + filename.substring(0, filename.length() - FILE_TYPE.length()); | ||
Path createdFitScript = Paths.get(CREATED_DIRECTORY_PATH_STRING + filename); | ||
Files.copy(FIT_SCRIPT_PATH, createdFitScript, REPLACE_EXISTING, COPY_ATTRIBUTES); | ||
|
||
replaceFilename(createdFitScript, dataFilePath); | ||
} | ||
|
||
private static void replaceFilename(Path fitScript, Path dataFilePath) throws IOException { | ||
Charset charset = StandardCharsets.UTF_8; | ||
|
||
String content = new String(Files.readAllBytes(fitScript), charset); | ||
String relativeFilePath = fitScript.getParent().relativize(dataFilePath).toString(); | ||
relativeFilePath = relativeFilePath.replace("\\", "/"); | ||
System.out.println(relativeFilePath); | ||
content = content.replaceAll(REPLACE_STRING, relativeFilePath); | ||
System.out.println(content); | ||
Files.write(fitScript, content.getBytes(charset)); | ||
} | ||
} |