some functions done
This commit is contained in:
parent
b4d2569f46
commit
7b1c1cedb0
|
@ -3,7 +3,7 @@
|
||||||
// NLMSvariants.c
|
// NLMSvariants.c
|
||||||
//
|
//
|
||||||
// Created by FBRDNLMS on 26.04.18.
|
// Created by FBRDNLMS on 26.04.18.
|
||||||
// Copyright © 2018 FBRDNLMS. All rights reserved.
|
// Copyright © 2018 FBRDNLMS. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -22,10 +22,26 @@
|
||||||
#define DIRECT_PREDECESSOR 2
|
#define DIRECT_PREDECESSOR 2
|
||||||
#define LOCAL_MEAN 4
|
#define LOCAL_MEAN 4
|
||||||
#define RGB_COLOR 255
|
#define RGB_COLOR 255
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
#include <BaseTsd.h>
|
||||||
|
#include <codecvt> // std::codecvt_utf8_utf16
|
||||||
|
#include <locale> // std::wstring_convert
|
||||||
|
#include <string> // std::wstring
|
||||||
|
typedef SSIZE_T ssize_t;
|
||||||
|
#endif
|
||||||
double x[] = { 0 };
|
double x[] = { 0 };
|
||||||
double _x[M] = { 0 };
|
double _x[M] = { 0 };
|
||||||
double w[M][M] = { { 0 },{ 0 } };
|
double w[M][M] = { { 0 },{ 0 } };
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
/* UTF-8 to UTF-16 win Format*/
|
||||||
|
auto wstring_from_utf8(char const* const utf8_string)
|
||||||
|
-> std::wstring
|
||||||
|
{
|
||||||
|
std::wstring_convert< std::codecvt_utf8_utf16< wchar_t > > converter;
|
||||||
|
return converter.from_bytes(utf8_string);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* *svg graph building* */
|
/* *svg graph building* */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -198,8 +214,8 @@ void localMean( void ) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void directPredecessor(void) {
|
void directPredecessor(void) {
|
||||||
char fileName[50];
|
char fileName[512];
|
||||||
double xError [M];
|
double xError[2048];
|
||||||
int xCount = 0, i;
|
int xCount = 0, i;
|
||||||
double xActual;
|
double xActual;
|
||||||
|
|
||||||
|
@ -273,6 +289,7 @@ char *mkFileName( char* buffer, size_t max_len, int suffixId) {
|
||||||
strftime(buffer, max_len, format_str, localtime(&now));
|
strftime(buffer, max_len, format_str, localtime(&now));
|
||||||
date_len = strlen(buffer);
|
date_len = strlen(buffer);
|
||||||
strncat(buffer, suffix, max_len - date_len);
|
strncat(buffer, suffix, max_len - date_len);
|
||||||
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -320,7 +337,7 @@ void Graph ( ) {
|
||||||
|
|
||||||
==========================================================================
|
==========================================================================
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
void myLogger(FILE* fp, point_t points[]) {
|
void myLogger(FILE* fp, point_t points[]) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i <= M; i++) { // xActual
|
for (i = 0; i <= M; i++) { // xActual
|
||||||
|
@ -335,7 +352,26 @@ void myLogger ( FILE* fp, point_t points[] ){
|
||||||
fprintf(fp, "L %f %f\n", points[i].xVal[2], points[i].yVal[2]);
|
fprintf(fp, "L %f %f\n", points[i].xVal[2], points[i].yVal[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
void bufferLogger(char *buffer, point_t points[]) {
|
||||||
|
int i;
|
||||||
|
char _buffer[512] = "";
|
||||||
|
|
||||||
|
for (i = 0; i <= M; i++) { // xActual
|
||||||
|
sprintf(_buffer, "L %f %f\n", points[i].xVal[0], points[i].yVal[0]);
|
||||||
|
strcat(buffer, _buffer);
|
||||||
|
}
|
||||||
|
strcat(buffer, "\" fill=\"none\" stroke=\"blue\" stroke-width=\"0.4px\"/>\n<path d=\"M0 0\n");
|
||||||
|
for (i = 0; i < M - 1; i++) { // xPred from directPredecessor
|
||||||
|
sprintf(_buffer, "L %f %f\n", points[i].xVal[1], points[i].yVal[1]);
|
||||||
|
strcat(buffer, _buffer);
|
||||||
|
}
|
||||||
|
strcat(buffer, "\" fill=\"none\" stroke=\"green\" stroke-width=\"0.4px\"/>\n<path d=\"M0 0\n");
|
||||||
|
for (i = 0; i <= M; i++) { //xPred from lastMean
|
||||||
|
sprintf(_buffer, "L %f %f\n", points[i].xVal[2], points[i].yVal[2]);
|
||||||
|
strcat(buffer, _buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -398,7 +434,7 @@ double rndm( void ) {
|
||||||
|
|
||||||
getline
|
getline
|
||||||
|
|
||||||
This code is public domain -- Will Hartung 4/9/09
|
This code is public domain -- Will Hartung 4/9/09 //edited by Kevin Becker
|
||||||
Microsoft Windows is not POSIX conform and does not support getline.
|
Microsoft Windows is not POSIX conform and does not support getline.
|
||||||
|
|
||||||
=========================================================================
|
=========================================================================
|
||||||
|
@ -427,7 +463,9 @@ size_t getline(char **lineptr, size_t *n, FILE *stream) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (bufptr == NULL) {
|
if (bufptr == NULL) {
|
||||||
bufptr = malloc(128);
|
char c[128];
|
||||||
|
memset(c, 0, sizeof(c));
|
||||||
|
bufptr = c;
|
||||||
if (bufptr == NULL) {
|
if (bufptr == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -437,7 +475,7 @@ size_t getline(char **lineptr, size_t *n, FILE *stream) {
|
||||||
while (c != EOF) {
|
while (c != EOF) {
|
||||||
if ((p - bufptr) > (size - 1)) {
|
if ((p - bufptr) > (size - 1)) {
|
||||||
size = size + 128;
|
size = size + 128;
|
||||||
bufptr = realloc(bufptr, size);
|
realloc(bufptr, size);
|
||||||
if (bufptr == NULL) {
|
if (bufptr == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -471,32 +509,53 @@ size_t getline(char **lineptr, size_t *n, FILE *stream) {
|
||||||
void mkSvgGraph(point_t points[]) {
|
void mkSvgGraph(point_t points[]) {
|
||||||
FILE *input = fopen("template.svg", "r");
|
FILE *input = fopen("template.svg", "r");
|
||||||
FILE *target = fopen("output.svg", "w");
|
FILE *target = fopen("output.svg", "w");
|
||||||
char *line = NULL;
|
char line[512];
|
||||||
// char *ptr;
|
// char *ptr;
|
||||||
size_t len = 0;
|
//size_t len = 0;
|
||||||
ssize_t read;
|
//ssize_t read;
|
||||||
char values[64];
|
//char values[64];
|
||||||
char firstGraph[15] = {"<path d=\"M0 0"}; /* There is a space behind the last zero,
|
char firstGraph[15] = { "<path d=\"M0 0" };
|
||||||
but windows does not recognize it in strtsr() ?!
|
|
||||||
so no output will return*/
|
|
||||||
|
|
||||||
if (input == NULL) {
|
if (input == NULL) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
while ( ( read = getline(&line, &len, input) ) != -1) {
|
char buffer[131072] = "";
|
||||||
|
|
||||||
|
memset(buffer, '\0', sizeof(buffer));
|
||||||
|
//int length = 0;
|
||||||
|
while(!feof(input)) {
|
||||||
|
fgets(line, 512, input);
|
||||||
|
strncat(buffer, line,strlen(line));
|
||||||
|
printf("%s\n", line);
|
||||||
|
if (strstr(line, firstGraph) != NULL) {
|
||||||
|
bufferLogger(buffer, points);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
fprintf(target, buffer);
|
||||||
|
//int c = 0;
|
||||||
|
puts(buffer);
|
||||||
|
//getchar();
|
||||||
|
|
||||||
|
//if (strstr(line, firstGraph) != NULL) {
|
||||||
|
// //fprintf(target,"HECK!!!\n");
|
||||||
|
// bufferLogger(strstr(line, firstGraph),sizeof(firstGraph), points);
|
||||||
|
//}
|
||||||
|
|
||||||
|
/*while ((read = getline(&line, &len, input)) != -1) {
|
||||||
//printf("Retrieved line of length %zu :\n", read);
|
//printf("Retrieved line of length %zu :\n", read);
|
||||||
//puts(line); // debug purpose
|
//puts(line); // debug purpose
|
||||||
fprintf(target, "%s", line);
|
fprintf(target, "%s", line);
|
||||||
if (strstr(line, firstGraph) != NULL) {
|
if (strstr(line, firstGraph) != NULL) {
|
||||||
//fprintf(target,"HECK!!!\n");
|
fprintf(target,"HECK!!!\n");
|
||||||
myLogger(target, points);
|
myLogger(target, points);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
free(line);
|
/*free(line);
|
||||||
// free(target);
|
free(target);
|
||||||
// free(input);
|
free(input);*/
|
||||||
//exit(EXIT_SUCCESS);
|
//exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -550,7 +609,7 @@ static imagePixel_t *rdPPM ( const char *fileName ) {
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
while (fgetc(fp) != '\n');
|
while (fgetc(fp) != '\n');
|
||||||
image->data = (imagePixel_t *) malloc(image->x * image->y * sizeof(imagePixel_t));
|
image->data = (colorChannel_t *)malloc(image->x * image->y * sizeof(imagePixel_t));
|
||||||
if (!image) {
|
if (!image) {
|
||||||
fprintf(stderr, "malloc() failed");
|
fprintf(stderr, "malloc() failed");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -600,8 +659,10 @@ void mkPpmFile ( char *fileName, imagePixel_t *image ) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int * ppmColorChannel(imagePixel_t *image) {
|
int * ppmColorChannel(imagePixel_t *image) {
|
||||||
int length = (image->x * image->y)/3, i;
|
int length = (image->x * image->y) / 3;
|
||||||
int buffer[length];
|
int i = 0;
|
||||||
|
int buffer[10];
|
||||||
|
realloc(buffer,length);
|
||||||
|
|
||||||
printf("%d\n", length);
|
printf("%d\n", length);
|
||||||
if (image) {
|
if (image) {
|
||||||
|
@ -613,5 +674,3 @@ int * ppmColorChannel( imagePixel_t *image ) {
|
||||||
}
|
}
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue