added fileParser

This commit is contained in:
gurkenhabicht 2018-05-04 01:28:36 +02:00
parent 08a435f1c3
commit 9b2999f4e7
2 changed files with 100 additions and 6 deletions

View File

@ -20,6 +20,7 @@
#define USED_WEIGHTS 1
#define RESULTS 2
#define DIRECT_PREDECESSOR 3
#define GRAPH 4
double x[] = {0};
double _x[M] = {0};
@ -30,11 +31,11 @@ char * mkFileName( char* buffer, size_t max_len, int suffixId );
char *fileSuffix( int id );
void myLogger( FILE* fp, int myVar);
/* *rand seed functions* */
/* *rand seed* */
double r2( void );
double rndm( void );
/* *math functions * */
/* *math* */
double sum_array( double x[], int length );
void directPredecessor( void );
void localMean( void );
@ -65,8 +66,8 @@ int main(int argc, char **argv ) {
// math magic
//directPredecessor(); // TODO: needs some love!
localMean();
directPredecessor(); // TODO: needs some love!
//localMean();
// save test_array after math magic happened
@ -186,6 +187,7 @@ void directPredecessor( void ) {
xError[xCount] = xActual - xPredicted;
fprintf(fp3, "{%d}.\txPredicted{%f}\txActual{%f}\txError{%f}\n", xCount, xPredicted, xActual, xError[xCount]);
double xSquared = 0.0;
//get x squared
@ -250,11 +252,27 @@ char *mkFileName( char* buffer, size_t max_len, int suffixId) {
*/
char * fileSuffix( int id ) {
char * suffix[] = {"_weights_pure.txt", "_weights_used.txt", "direct_predecessor.txt", "ergebnisse.txt"};
char * suffix[] = {"_weights_pure.txt", "_weights_used.txt", "direct_predecessor.txt", "ergebnisse.txt", "_graph.svg"};
return suffix[id];
}
/*
==========================================================================
svgGraph
==========================================================================
*/
/*
void Graph ( ) {
char fileName[50];
mkFileName(fileName, sizeof(fileName), GRAPH);
FILE* fp4 = fopen(fileName, "w");
pfrintf
*/
/*
==========================================================================
@ -268,7 +286,9 @@ char * fileSuffix( int id ) {
*/
void myLogger ( FILE* fp, int myVar ){
fprintf( fp, "Logging: %d\n", myVar);
}
@ -318,10 +338,51 @@ double r2( void ) {
fills a double variable with random value and returns it
=========================================================================
==========================================================================
*/
double rndm( void ) {
double rndmval= r2();
return rndmval;
}
/*
==========================================================================
parser
Parses files, used for template.svg mainly
==========================================================================
*/
char * parser( char buffer) {
FILE *fp = fopen ( "template.svg", "wr" );
char *line = NULL;
char *ptr;
size_t len = 0;
ssize_t read;
char string[] = "HECK!!!";
if( fp == NULL ) {
exit(EXIT_FAILURE);
}
while ( ( read = getline(&line, &len, fp) ) != -1) {
// printf("Retrieved line of length %zu :\n", read);
//puts(line);
if( strstr(line, "<path d=\"M0 0 ") != NULL ) {
ptr = line;
printf("%s", *ptr);
fprintf(fp, "%s\n", string);
}
}
free(line);
exit(EXIT_SUCCESS);
}

33
bin/template.svg Normal file
View File

@ -0,0 +1,33 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg height="1200" viewBox="100 50 400 -400" width="3000" version="1.1"
xmlns="http://www.w3.org/2000/svg">
<desc>NLMSvariants output graph
</desc>
<defs>
<pattern id="smallGrid" width="10" height="10" patternUnits="userSpaceOnUse">
<path d="M 10 0 L 0 0 0 10" fill="none" stroke="gray" stroke-width="0.5"></path>
</pattern>
<pattern id="grid10" width="100" height="100" patternUnits="userSpaceOnUse">
<rect width="100" height="100" fill="url(#smallGrid)"></rect>
<path d="M 100 0 L 0 0 0 100" fill="none" stroke="gray" stroke-width="1"></path>
</pattern>
</defs>
<rect fill="white" height="1200" width="3000" y="0"></rect>
<rect fill="url(#grid10)" height="1200" width="3000" y="0"></rect>
<g transform="translate(0,0) scale(1, 1)">
<line class="l1 s-black " stroke="black" x1="-200" x2="3000" y1="400" y2="400"></line>
<line class="l1 s-black " stroke="black" x1="200" x2="200" y1="-200" y2="1200"></line>
</g>
<g transform="translate(200, 400) scale(1,-1)">
<path d="M0 0
" fill="none" stroke="red" stroke-width="0.8px"/>
<text class="t36 t-mid bold f-black" x="50" y="50">+ +</text>
<text class="t36 t-mid bold f-black" x="-50" y="50">- +</text>
<text class="t36 t-mid bold f-black" x="50" y="-50">+ -</text>
<text class="t36 t-mid bold f-black" x="-50" y="-50">- -</text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB