GNUPlot: Warning: Skipping data file with no valid points - c++

I have written a piece of code to plot a graph using GNUplot from a data file.
It's giving a warning:
warning: Skipping data file with no valid points
The code is:
{
FILE *gnuplotPipe, *tempDataFile;
FILE * pFile;
char *tempDataFileName;
char *Datafile;
double x, y;
int i;
tempDataFileName = "Pulse.txt";
Datafile = "PulseFinal.dat";
gnuplotPipe = _popen("gnuplot", "w");
if (gnuplotPipe)
{
fprintf(gnuplotPipe, "plot \"%s\" '-' using 1:2 with lines", Datafile);
fflush(gnuplotPipe);
printf("press enter to continue...");
getchar();
fprintf(gnuplotPipe, "exit \n");
}
else
{
printf("gnuplot not found...");
}
}
The data file is:
0.000000 0.018519
1.000000 0.000000
2.000000 0.000000
3.000000 0.000000
4.000000 0.000000
5.000000 0.000000
6.000000 0.000000
7.000000 0.000000
8.000000 0.000000
9.000000 0.000000
10.000000 -0.006173
Can someone please help me with this?

You have tried
plot \"%s\" '-' using 1:2 with lines
which means for Gnuplot
plot "YPulseFinal.dat" '-' using 1:2 with lines
You can't plot a file and the stream at the same time. You can
plot "YPulseFinal.dat" using 1:2 with lines
or
plot '-' using 1:2 with lines
I recommend you
fprintf(gnuplotPipe, "plot \"%s\" using 1:2 with lines", Datafile);

Related

C++ How to check last value in line and replace line if it is more than a certain value [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I want to replace a line of a file, but only if the 3rd (last) value is above 0.000000.
Specifically I have an Ascii .stl file, like below, where I want to be able to check the last value of each vertex line, and replace the entire line with a different string if it is above 0.000000.
I am really struggling with understanding how to create a parser using regex, to look for this. I also don't know if that's the best way.
Any help with the parsing would be very much appreciated.
facet normal -1.000000 0.000000 0.000000
outer loop
vertex 26.000000 6.000000 0.000000
vertex 26.000000 6.000000 1.000000
vertex 26.000000 7.000000 1.000000
endloop
endfacet
facet normal -1.000000 0.000000 0.000000
outer loop
vertex 26.000000 6.000000 0.000000
vertex 26.000000 7.000000 1.000000
vertex 26.000000 7.000000 0.000000
endloop
endfacet
facet normal 0.000000 1.000000 0.000000
outer loop
vertex 26.000000 7.000000 0.000000
vertex 26.000000 7.000000 1.000000
vertex 27.000000 7.000000 1.000000
endloop
endfacet
endsolid
If it matters, I'm working in Microsoft Visual Studio 2019
For something as simple as detecting which line starts with "vertex", I don't think you need something as heavy as a regular expression.
Here is a very simple example of detecting the line that starts with "vertex":
#include <sstream>
#include <string>
#include <iostream>
std::string test = "facet normal -1.000000 0.000000 0.000000\n"
"outer loop\n"
"vertex 26.000000 6.000000 0.000000\n"
"vertex 26.000000 6.000000 1.000000\n"
"vertex 26.000000 7.000000 1.000000\n"
"endloop\n"
"endfacet\n"
"facet normal -1.000000 0.000000 0.000000\n"
"outer loop\n"
"vertex 26.000000 6.000000 0.000000\n"
"vertex 26.000000 7.000000 1.000000\n"
"vertex 26.000000 7.000000 0.000000\n"
"endloop\n"
"endfacet\n"
"facet normal 0.000000 1.000000 0.000000\n"
"outer loop\n"
"vertex 26.000000 7.000000 0.000000\n"
"vertex 26.000000 7.000000 1.000000\n"
"vertex 27.000000 7.000000 1.000000\n"
"endloop\n"
"endfacet\n"
"endsolid";
int main()
{
std::istringstream strm(test);
std::string line;
int lineNumber = 0;
while (std::getline(strm, line))
{
++lineNumber;
if (line.compare( 0, 6, "vertex", 6) == 0) // check if line starts with "vertex"
{
std::istringstream strm2(line); // read the line
std::string type;
double num1, num2, num3;
strm2 >> type >> num1 >> num2 >> num3;
if ( num3 > 0 ) // checks the last number
std::cout << "Line " << lineNumber << ": " << line << "\n"; // just outputs that line
}
}
}
Output:
Line 4: vertex 26.000000 6.000000 1.000000
Line 5: vertex 26.000000 7.000000 1.000000
Line 11: vertex 26.000000 7.000000 1.000000
Line 18: vertex 26.000000 7.000000 1.000000
Line 19: vertex 27.000000 7.000000 1.000000
In lieu of a file, the code reads the data from a stringstream.
It's just a matter of detecting the line that starts with "vertex", and then using a std::istringstream to read the data.
I would agree with the comments of others that Regex may not be the best approach depending on the nature of your solution. But for a Regex to find what you're after:
vertex.+\s[0-9\.]*[1-9][0-9\.]*$
Should do the trick.
(regex101)

OpenVino model outputs zeroes

I have an acoustic model that successfully converted from ONNX to OpenVino. However, in OpenVino this model outputs tensor that consists of zeroes from some position.
#include <iostream>
#include <fstream>
#include <iterator>
#include <inference_engine.hpp>
typedef struct {
float* data;
size_t size;
size_t timeLen;
} Fbank;
using namespace InferenceEngine;
using std::cout;
using std::endl;
void print_arr(std::string text, const float* arr, int l, int r) {
cout << text << endl;
for (int i = l; i < r; i++) {
cout << arr[i] << " ";
}
cout << endl;
}
void doInference(ExecutableNetwork& executable_network, const std::string& input_name, const std::string& output_name, Fbank* fbank) {
InferRequest infer_request = executable_network.CreateInferRequest();
InferenceEngine::TensorDesc tDesc(InferenceEngine::Precision::FP32,
{fbank->size, fbank->timeLen}, InferenceEngine::Layout::HW);
Blob::Ptr blob = InferenceEngine::make_shared_blob<float>(tDesc, fbank->data);
infer_request.SetBlob(input_name, blob);
infer_request.Infer();
Blob::Ptr output_blob = infer_request.GetBlob(output_name);
auto dims = output_blob->getTensorDesc().getDims();
size_t batchSize = dims[0];
size_t T = dims[1];
size_t D = dims[2];
MemoryBlob::CPtr moutput = as<MemoryBlob>(output_blob);
if (!moutput) {
return;
}
auto moutputHolder = moutput->rmap();
const float *pred = moutputHolder.as<const float*>();
print_arr("AM output:", pred, D*29, D*31);
}
int main() {
Fbank* fbank = new Fbank;
fbank->size = 64;
fbank->timeLen = 2000;
fbank->data = new float[64*2000];
Core ie;
CNNNetwork network = ie.ReadNetwork("quartznet_random.xml", "quartznet_random.bin");
std::string input_name = network.getInputsInfo().begin()->first;
std::string output_name = network.getOutputsInfo().begin()->first;
network.getOutputsInfo().begin()->second->setPrecision(Precision::FP32);
ExecutableNetwork executable_network = ie.LoadNetwork(network, "cpu");
doInference(executable_network, input_name, output_name, fbank);
return 0;
}
Outputs:
AM output:
0.138650 -5.833140 -8.023724 -7.637482 -8.001101 -9.033963 -8.029905 -8.132050 -9.186495 -8.537528 -8.788505 -9.240234 -8.547676 -8.673388 0.000000 0.000000 -0.000000 0.000000 -0.000000 0.000000 0.000000 -0.000000 -0.000000 0.000000 -0.000000 0.000000 0.000000 -0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 -0.000000 0.000000 0.000000 -0.000000 0.000000 0.000000 -0.000000 -0.000000 -0.000000 -0.000000 -0.000000 0.000000 -0.000000 -0.000000 -0.000000 0.000000 -0.000000 -0.000000 -0.000000 0.000000 0.000000 -0.000000 -0.000000 0.000000 -0.000000 0.000000 -0.000000 -0.000000 -0.000000 0.000000 -0.000000 -0.000000 0.000000 -0.000000 0.000000
If I run ONNX model in Python using onnxruntime, the output will be correct. (Example).
Is it possible to fix it?
P.S. Command to convert the model from ONNX: python3 mo_onnx.py —input_model model.onnx —output="output" —input="fbanks[64 2000]"
Tested provided ONNX model in OpenVINO for Linux, couple of findings while testing OpenVINO 2020.1 and new 2020.2 version (released today 4/14/2020, release notes).
Using same command to convert from ONNX. Although its unclear what would be the expected output (probability between 0.0 and 1.0?), OpenVINO 2020.2 seems to affect the output results.
On 2020.1, observed similar results to yours (one can assume this is the OpenVINO version you used).
AM output: -3.55062 -3.5114 -3.50925 -3.52013 -3.51791 -3.54656 -3.53908 -3.54239 -3.53626 -3.50982 -3.54193 -3.55593 -3.52877 -3.53786 -1.546e-07 -6.14673e-08 -8.56817e-08 -1.41561e-07 -6.14673e-08 -1.16415e-07 -9.30158e-08 -9.12696e-08 -1.29454e-07 -1.04774e-07 -6.14673e-08 -5.58794e-08 -1.71363e-07 -1.02445e-07 -5.7742e-08 -1.35042e-07 -9.26666e-08 -1.00583e-07 -1.04308e-07 -1.2666e-07 -1.39698e-07 -7.26432e-08 -9.68575e-08 -1.47149e-07 -9.40636e-08 -9.77889e-08 -9.49949e-08 -1.16415e-07 -9.54606e-08 -8.3819e-08 -1.28523e-07 -1.35973e-07 -7.66013e-08 -1.12224e-07 -1.546e-07 -6.14673e-08 -8.56817e-08 -1.41561e-07 -6.14673e-08 -1.16415e-07 -9.30158e-08 -9.12696e-08 -1.29454e-07 -1.04774e-07 -6.14673e-08 -5.58794e-08 -1.71363e-07 -1.02445e-07 -5.7742e-08 -1.35042e-07 -9.26666e-08 -1.00583e-07 -1.04308e-07 -1.2666e-07
On OpenVINO 2020.2 had to change ExecutableNetwork executable_network = ie.LoadNetwork(network, "cpu"); to ExecutableNetwork executable_network = ie.LoadNetwork(network, "CPU"); as Inference Engine didnt't recognize lowercase CPU device, error was "terminate called after throwing an instance of 'InferenceEngine::details::InferenceEngineException'
what(): Device with "cpu" name is not registered in the InferenceEngine
Aborted (core dumped)"
On OpenVINO 2020.2, the results differ and are not close to zero (although all seem negative).
AM output: -3.55062 -3.5114 -3.50925 -3.52013 -3.51791 -3.54656 -3.53908 -3.54239 -3.53626 -3.50982 -3.54193 -3.55593 -3.52877 -3.53786 -3.52153 -3.52563 -3.51142 -3.54885 -3.52137 -3.54384 -3.53411 -3.55188 -3.5477 -3.52514 -3.51171 -3.5022 -3.5138 -3.50823 -3.50125 -3.51817 -3.53914 -3.50173 -3.50603 -3.51917 -3.55062 -3.5114 -3.50925 -3.52013 -3.51791 -3.54656 -3.53908 -3.54239 -3.53626 -3.50982 -3.54193 -3.55593 -3.52877 -3.53786 -3.52153 -3.52563 -3.51142 -3.54885 -3.52137 -3.54384 -3.53411 -3.55188 -3.5477 -3.52514 -3.51171 -3.5022 -3.5138 -3.50823 -3.50125 -3.51817 -3.53914 -3.50173 -3.50603 -3.51917
It's uncertain if the output results of OpenVINO 2020.2 are expected/correct. I am unable to test Python example with the ONNX model using onnxruntime, script expects /kek/fbank.out file. Clarify/share what output is expected, i.e. correct AM output.
The problem was due to numerical instability in our implementation of LogSoftmax. Without log of softmax all works fine.

tu tv texture coordinates larger than 1.0 ? __ (OBJ format)

I want to understand how OBJ format dealing with texture coordinates.
example:
vt 1.000000 1.005200
vt 0.467300 1.709900
vt 0.923800 1.994400
vt 0.500000 1.002600
vt 0.371400 1.000000
vt 0.438100 2.000000
vt 0.000000 1.000000
vt 0.467300 1.709900
vt 0.105000 1.159500
vt 0.434600 1.002300
i understand values should range from (0) to (1.000000) to cover Texture image file from 0% to 100% for each X and Y. (tu tv)
But i find some values in array are above 1.000000, and sometime below 0.000000
How should i deal with these values to stay between 0 and 1 ?
This kind of texture coodinate value indicates that the texture shall be repeated. In the cases of the obj-file
vt 0.438100 2.000000
the v-part shall be repeated twice.

mkChar does not escape percent sign

I have the following code :
#include <Rinternals.h>
#include <cmath>
extern "C" {
SEXP myChar(int x) {
/*PrintValue(nam);*/
SEXP colnames, result;
PROTECT(colnames = Rf_allocVector(STRSXP,2));
char buffer[20];
int n = sprintf(buffer,"%4.2f%%",2.5);
SET_STRING_ELT(colnames,0,mkChar(buffer));
n = sprintf(buffer,"%4.2f%c",5.0,0x25);
SET_STRING_ELT(colnames,1,mkChar(buffer));
PROTECT(result = Rf_allocVector(VECSXP, 2));
SEXP scol1 = PROTECT(allocVector(REALSXP,10));
SEXP scol2 = PROTECT(allocVector(REALSXP,10));
for (size_t k=0;k<10;++k){
REAL(scol1)[k] = std::pow(k,0.5);
REAL(scol2)[k] = std::pow(k,0.7);
}
SET_VECTOR_ELT(result,0,scol1);
SET_VECTOR_ELT(result,1,scol2);
setAttrib(result, R_NamesSymbol, colnames);
UNPROTECT(4);
return(result);
}
}
I compile like this :
R CMD SHLIB myChar.cpp
And run the following in my R session :
> dyn.load("myChar.so")
> out<-as.data.frame(.Call("myChar"))
> out
X2.50. X5.00.
1 0.000000 0.000000
2 1.000000 1.000000
3 1.414214 1.624505
4 1.732051 2.157669
5 2.000000 2.639016
6 2.236068 3.085169
7 2.449490 3.505144
8 2.645751 3.904529
9 2.828427 4.287094
10 3.000000 4.655537
My question is why the column names doesn't show the percent sign? I use '%%' to escape the percent sign but in the column names it is converted to a period, i.e. instead of "X2.50%" I get "X2.50.". Is that a feature of mkChar? Is there any other way to convert char array to SEXP?
There is nothing wrong with your C/C++ code. The problem arises when you coerce to data.frame. Try this:
out<-.Call("myChar")
#names are correct
names(out)
#[1] "2.50%" "5.00%"
#now correctly to data.frame, see ?data.frame
out<-data.frame(out,check.names=FALSE)
# 2.50% 5.00%
#1 0.000000 0.000000
#2 1.000000 1.000000
#3 1.414214 1.624505
#4 1.732051 2.157669
#5 2.000000 2.639016
#6 2.236068 3.085169
#7 2.449490 3.505144
#8 2.645751 3.904529
#9 2.828427 4.287094
#10 3.000000 4.655537
See the check.names argument of data.frame to get a grasp of what is going on.
You can try using \045 to represent the percentage symbol.

how to convert planar mesh to arrangement in CGAL

I need to convert 2d planar polygonal meshes to 2D Arrangements in CGAL. for example if I have the following mesh in Wavefront obj format:
v -5.687006 -4.782805 0.000000
v 4.878987 -4.782805 0.000000
v -5.687006 4.782805 0.000000
v 4.878987 4.782805 0.000000
v -0.404010 -4.782805 0.000000
v -5.687006 0.000000 0.000000
v 4.878987 0.000000 0.000000
v -0.404010 4.782805 0.000000
v -0.404010 0.000000 0.000000
f 5 2 9
f 9 2 7
f 7 4 9
f 9 4 8
f 8 3 9
f 9 3 6
f 6 1 9
f 9 1 5
what is the simplest way I could convert it to a 2d Arrangement using the CGAL library?
Using the following example, you'll find out.
insert_in_face_interior for the first segment
insert_from_left_vertex or insert_from_right_vertex for the middle one, depending on the orientation of your polygon.
insert_at_vertices for the last one