Plugin samples
Here are some basic examples of frequent use cases you may encounter.
Load a custom data file format
In this example, the plugin will register the onLoadDataFile event to implement a custom data file reader. The file format we'll load is really simple, but it uses a non standard date format not supported by PrestoPlot.
Let's say the file we want to load have .mcf. We'll use this to assume the file processing, and prevent PrestoPlot to try (and fail) to load it in a generic way.
If the file extension is not a determinist criteria for you, you would also have the possibility to open the file, read the header, then determine if
this is one of your file format you want to load.
Let's see what our file looks like :
Courant ligne 3
DATE HEURE CUR3 COURANT
27/01/2025 10:35:56 392.7 mA
27/01/2025 10:36:06 397.4 mA
27/01/2025 10:36:16 406.7 mA
27/01/2025 10:36:26 776.1 mA
27/01/2025 10:36:36 397.4 mA
27/01/2025 10:36:46 780.8 mA
27/01/2025 10:36:56 762.1 mA
27/01/2025 10:37:06 766.7 mA
27/01/2025 10:37:16 753.9 mA
27/01/2025 10:37:26 1100 mA
Our file is a tab separated values, has only one dataset, two header lines, date and hour on two distinct columns (that point is not natively supported by PrestoPlot), one column for the value, and one column for the unit.
Here is the code of the plugin :
package require PrestoPlotAPI 1
# Plugin initialisation
set plugin [PP currentPlugin]
$plugin set name "Sample Custom Loader"
$plugin set help {
## Plugin purpose
This is a demonstration plugin to load some specific text data file.
The specificity of the file format this plugin will load is that the date and time is separated by a field separator.
}
Files onLoadDataFile {filename} {
# Consider only *.mcf files
if { [file extension $filename] != ".mcf" } {
# Tell PrestoPlot we don't want to process this file
return false
}
# Here you can read and load the file.
set fileDescriptor [open $filename r]
# Read the two fixed headers
set header1 [gets $fileDescriptor]
set header2 [gets $fileDescriptor]
# Extract the dataset name from header2
set name [lindex [split $header2 \t] 2]
# Create a dataset, fills in its informations
set dataset [Datasets createDataset $name]
$dataset set description $header1
while {[gets $fileDescriptor line] >= 0} {
# Split line values into variables
lassign [split $line \t] date hour value unit
# Calculate date from "date hour" concatenation
# from EUR format, to the PrestoPlot internal format
set date [Dates from "$date $hour" "EUR"]
# Add this data point to the dataset
$dataset addPoint $date $value
}
# Set the dataset unit
$dataset set unit $unit
# Close file when finished
close $fileDescriptor
# Tell PrestoPlot we have processed this file
return true
}