Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New post process #28

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions postprocess-module/postprocess_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,18 @@ function postprocess_controller()
"new_interval"=>array("type"=>"value", "short"=>"New feed interval:"),
"backup"=>array("type"=>"newfeed", "engine"=>5, "short"=>"Enter backup feed name:", "nameappend"=>"")
),
"allownegative"=>array(
"input"=>array("type"=>"feed", "engine"=>5, "short"=>"Select input feed:"),
"output"=>array("type"=>"newfeed", "engine"=>5, "short"=>"Enter output feed name:", "nameappend"=>"")
),
"allowpositive"=>array(
"input"=>array("type"=>"feed", "engine"=>5, "short"=>"Select input feed:"),
"output"=>array("type"=>"newfeed", "engine"=>5, "short"=>"Enter output feed name:", "nameappend"=>"")
),
"invertnegative"=>array(
"input"=>array("type"=>"feed", "engine"=>5, "short"=>"Select input feed:"),
"output"=>array("type"=>"newfeed", "engine"=>5, "short"=>"Enter output feed name:", "nameappend"=>"")
),
"offsetfeed"=>array(
"input"=>array("type"=>"feed", "engine"=>5, "short"=>"Select input feed to apply offset:"),
"offset"=>array("type"=>"value", "short"=>"Offset by:"),
Expand Down
76 changes: 76 additions & 0 deletions processes/allownegative.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

function allownegative($dir,$processitem)
{
if (!isset($processitem->input)) return false;
if (!isset($processitem->output)) return false;

$input = $processitem->input;
$output = $processitem->output;
// --------------------------------------------------

if (!file_exists($dir.$input.".meta")) {
print "input file $input.meta does not exist\n";
return false;
}

if (!file_exists($dir.$output.".meta")) {
print "output file $output.meta does not exist\n";
return false;
}

$input_meta = getmeta($dir,$input);

createmeta($dir,$output,$input_meta);
$output_meta = getmeta($dir,$output);
// if ($om->npoints >= $im->npoints) {
// print "output feed already up to date\n";
// return false;
// }

if (!$input_fh = @fopen($dir.$input.".dat", 'rb')) {
echo "ERROR: could not open $dir $input.dat\n";
return false;
}

if (!$output_fh = @fopen($dir.$output.".dat", 'c+')) {
echo "ERROR: could not open $dir $output.dat\n";
return false;
}

// get start position
$start_pos = $output_meta->npoints;

// get end position
$end_pos = $input_meta->npoints;

$buffer = "";

fseek($input_fh,$start_pos*4);
fseek($output_fh,$start_pos*4);

for ($n=($start_pos+1); $n<=$end_pos; $n++) {
$input_tmp = unpack("f",fread($input_fh,4));

$value = $input_tmp[1];
if (!is_nan($value)) {
if ($value>0) $value = 0;
}
$buffer .= pack("f",$value);
}

fwrite($output_fh,$buffer);

$byteswritten = strlen($buffer);
print "bytes written: ".$byteswritten."\n";
fclose($output_fh);
fclose($input_fh);

$time = $input_meta->start_time + ($input_meta->npoints * $input_meta->interval);

if ($byteswritten>0) {
print "last time value: ".$time." ".$value."\n";
updatetimevalue($output,$time,$value);
}
return true;
}
76 changes: 76 additions & 0 deletions processes/invertnegative.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

function invertnegative($dir,$processitem)
{
if (!isset($processitem->input)) return false;
if (!isset($processitem->output)) return false;

$input = $processitem->input;
$output = $processitem->output;
// --------------------------------------------------

if (!file_exists($dir.$input.".meta")) {
print "input file $input.meta does not exist\n";
return false;
}

if (!file_exists($dir.$output.".meta")) {
print "output file $output.meta does not exist\n";
return false;
}

$input_meta = getmeta($dir,$input);

createmeta($dir,$output,$input_meta);
$output_meta = getmeta($dir,$output);
// if ($om->npoints >= $im->npoints) {
// print "output feed already up to date\n";
// return false;
// }

if (!$input_fh = @fopen($dir.$input.".dat", 'rb')) {
echo "ERROR: could not open $dir $input.dat\n";
return false;
}

if (!$output_fh = @fopen($dir.$output.".dat", 'c+')) {
echo "ERROR: could not open $dir $output.dat\n";
return false;
}

// get start position
$start_pos = $output_meta->npoints;

// get end position
$end_pos = $input_meta->npoints;

$buffer = "";

fseek($input_fh,$start_pos*4);
fseek($output_fh,$start_pos*4);

for ($n=($start_pos+1); $n<=$end_pos; $n++) {
$input_tmp = unpack("f",fread($input_fh,4));

$value = $input_tmp[1];
if (!is_nan($value)) {
if ($value>0) $value = 0;
}
$buffer .= pack("f",$value * -1);
}

fwrite($output_fh,$buffer);

$byteswritten = strlen($buffer);
print "bytes written: ".$byteswritten."\n";
fclose($output_fh);
fclose($input_fh);

$time = $input_meta->start_time + ($input_meta->npoints * $input_meta->interval);

if ($byteswritten>0) {
print "last time value: ".$time." ".$value."\n";
updatetimevalue($output,$time,$value);
}
return true;
}