Difference between revisions of "Statistical Algorithms Importer: Linux-compiled Project FAQ"

From Gcube Wiki
Jump to: navigation, search
(Fortran Example)
 
(13 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
|}
 
|}
  
F.A.Q. of Statistical Algorithms Importer (SAI), here are common mistakes we have found in Linux-compiled Project.
+
F.A.Q. of [[Statistical_Algorithms_Importer|Statistical Algorithms Importer (SAI)]], here are common mistakes we have found in Linux-compiled Project.
  
  
== How to use the input parameters ==
+
== How to use the input and output parameters (C++ Example) ==
 
:For example we consider BasicStatistic algorithm that use basicstatistic linux executable file:
 
:For example we consider BasicStatistic algorithm that use basicstatistic linux executable file:
[[Image:StatisticalAlgorithmsImporter_BasicStatistic0.png|thumb|center|800px|BasicStatistic, SAI]]
+
[[Image:StatisticalAlgorithmsImporter_BasicStatistic0.png|thumb|center|750px|BasicStatistic, SAI]]
  
 
:DataMiner show the BasicStatistic algorithm in this way:
 
:DataMiner show the BasicStatistic algorithm in this way:
[[Image:StatisticalAlgorithmsImporter_BasicStatistic1.png|thumb|center|800px|BasicStatistic in DataMiner interface, SAI]]
+
[[Image:StatisticalAlgorithmsImporter_BasicStatistic1.png|thumb|center|750px|BasicStatistic in DataMiner interface, SAI]]
  
 
:Below the C++ code in sample which generates basicstatistic linux executable file:
 
:Below the C++ code in sample which generates basicstatistic linux executable file:
 
+
 
<source lang="cpp">
 
<source lang="cpp">
 
//============================================================================
 
//============================================================================
Line 32: Line 32:
 
int main(int argc, char **argv) {
 
int main(int argc, char **argv) {
 
printf("BasicStatistic");
 
printf("BasicStatistic");
printf("Operator: %s\n",argv[1]);
+
printf("Operator: %s\n", argv[1]);
printf("Maximum number of items considered: %s\n",argv[2]);
+
printf("Maximum number of items considered: %s\n", argv[2]);
printf("Input file: %s\n",argv[3]);
+
printf("Input file: %s\n", argv[3]);
  
 
FILE * finput;
 
FILE * finput;
Line 42: Line 42:
  
 
finput = fopen(argv[3], "r");
 
finput = fopen(argv[3], "r");
if (finput == NULL){
+
if (finput == NULL) {
 
printf("No input file found: %s\n", argv[3]);
 
printf("No input file found: %s\n", argv[3]);
 
return -1;
 
return -1;
 
}
 
}
  
int limit=atoi(argv[2]);
+
int limit = atoi(argv[2]);
int i=0;
+
int i = 0;
int value=0;
+
int value = 0;
int result=0;
+
int result = 0;
  
while (((read = getline(&line, &len, finput)) != -1) && (i<limit||limit==-1)) {
+
while (((read = getline(&line, &len, finput)) != -1)
printf("Retrieved line of length %zu and value: %s", read,line);
+
&& (i < limit || limit == -1)) {
value=atoi(line);
+
printf("Retrieved line of length %zu and value: %s", read, line);
if(i==0){
+
value = atoi(line);
result=value;
+
if (i == 0) {
 +
result = value;
 
} else {
 
} else {
if (strcmp(argv[1], "max") == 0)
+
if (strcmp(argv[1], "max") == 0) {
{
+
if (value > result) {
if(value>result){
+
result = value;
result=value;
+
 
}
 
}
 
} else {
 
} else {
if (strcmp(argv[1], "min") == 0)
+
if (strcmp(argv[1], "min") == 0) {
{
+
if (value < result) {
if(value<result){
+
result = value;
result=value;
+
 
}
 
}
 
} else {
 
} else {
if (strcmp(argv[1], "average") == 0)
+
if (strcmp(argv[1], "average") == 0) {
{
+
result = result + value;
result=(result+value)/2;
+
 
} else {
 
} else {
 
break;
 
break;
Line 81: Line 79:
  
 
i++;
 
i++;
 +
}
 +
 +
if (strcmp(argv[1], "average") == 0 && i > 0) {
 +
result = result / i;
 
}
 
}
  
 
fclose(finput);
 
fclose(finput);
if (line){
+
if (line) {
 
free(line);
 
free(line);
 
}
 
}
Line 90: Line 92:
 
//Write result
 
//Write result
 
FILE *foutput = fopen("output.txt", "w");
 
FILE *foutput = fopen("output.txt", "w");
if (foutput == NULL)
+
if (foutput == NULL) {
{
+
 
printf("Error opening file!\n");
 
printf("Error opening file!\n");
 
return -1;
 
return -1;
Line 115: Line 116:
 
100
 
100
 
</pre>
 
</pre>
 
  
 
:with basicstatistic max -1 test.txt, output.txt:
 
:with basicstatistic max -1 test.txt, output.txt:
Line 126: Line 126:
 
[[File:BasicStatistic.zip|BasicStatistic.zip]]
 
[[File:BasicStatistic.zip|BasicStatistic.zip]]
  
 +
 +
== Fortran Example ==
 +
:For example we consider Fortran Statistic algorithm and we will use its executable version fortran-statistic.sh in SAI in this way:
 +
[[Image:StatisticalAlgorithmsImporter_FortranStatistic1.png|thumb|center|750px|FortranStatistic, SAI]]
 +
 +
:DataMiner show the Fortran Statistic algorithm in this way:
 +
[[Image:StatisticalAlgorithmsImporter_FortranStatistic2.png|thumb|center|750px|FortranStatistic in DataMiner interface, SAI]]
 +
 +
 +
:values.txt:
 +
<pre style="display:block;font-family:monospace;white-space:pre;margin:1em 0;">
 +
10
 +
20
 +
30
 +
40
 +
50
 +
60
 +
70
 +
80
 +
90
 +
100
 +
</pre>
 +
 +
:with fortran-statistic.sh values.txt avg, result.txt:
 +
<pre style="display:block;font-family:monospace;white-space:pre;margin:1em 0;">
 +
The result is:      55
 +
</pre>
 +
 +
:FortranStatistic code:
 +
[[File:FortranStatistic.zip|FortranStatistic.zip]]
  
 
[[Category:Statistical Algorithms Importer]]
 
[[Category:Statistical Algorithms Importer]]

Latest revision as of 19:13, 30 May 2019

F.A.Q. of Statistical Algorithms Importer (SAI), here are common mistakes we have found in Linux-compiled Project.


How to use the input and output parameters (C++ Example)

For example we consider BasicStatistic algorithm that use basicstatistic linux executable file:
BasicStatistic, SAI
DataMiner show the BasicStatistic algorithm in this way:
BasicStatistic in DataMiner interface, SAI
Below the C++ code in sample which generates basicstatistic linux executable file:
//============================================================================
// Name        : BasicStatistic.cpp
// Author      : Giancarlo Panichi
// Version     :
// Copyright   : GNU GENERAL PUBLIC LICENSE. Version 3.0
// Description : BasicStatistic in C++, Ansi-style
//============================================================================
 
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
 
int main(int argc, char **argv) {
	printf("BasicStatistic");
	printf("Operator: %s\n", argv[1]);
	printf("Maximum number of items considered: %s\n", argv[2]);
	printf("Input file: %s\n", argv[3]);
 
	FILE * finput;
	char * line = NULL;
	size_t len = 0;
	ssize_t read;
 
	finput = fopen(argv[3], "r");
	if (finput == NULL) {
		printf("No input file found: %s\n", argv[3]);
		return -1;
	}
 
	int limit = atoi(argv[2]);
	int i = 0;
	int value = 0;
	int result = 0;
 
	while (((read = getline(&line, &len, finput)) != -1)
			&& (i < limit || limit == -1)) {
		printf("Retrieved line of length %zu and value: %s", read, line);
		value = atoi(line);
		if (i == 0) {
			result = value;
		} else {
			if (strcmp(argv[1], "max") == 0) {
				if (value > result) {
					result = value;
				}
			} else {
				if (strcmp(argv[1], "min") == 0) {
					if (value < result) {
						result = value;
					}
				} else {
					if (strcmp(argv[1], "average") == 0) {
						result = result + value;
					} else {
						break;
					}
				}
			}
		}
 
		i++;
	}
 
	if (strcmp(argv[1], "average") == 0 && i > 0) {
		result = result / i;
	}
 
	fclose(finput);
	if (line) {
		free(line);
	}
 
	//Write result
	FILE *foutput = fopen("output.txt", "w");
	if (foutput == NULL) {
		printf("Error opening file!\n");
		return -1;
	}
 
	fprintf(foutput, "BasicStatistic Result: \n");
	fprintf(foutput, "%d\n", result);
	fclose(foutput);
 
	return 0;
}
test.txt:
9
20
12
23
44
65
80
100
with basicstatistic max -1 test.txt, output.txt:
BasicStatistic Result: 
100
BasicStatistic code:

File:BasicStatistic.zip


Fortran Example

For example we consider Fortran Statistic algorithm and we will use its executable version fortran-statistic.sh in SAI in this way:
FortranStatistic, SAI
DataMiner show the Fortran Statistic algorithm in this way:
FortranStatistic in DataMiner interface, SAI


values.txt:
10
20
30
40
50
60
70
80
90
100
with fortran-statistic.sh values.txt avg, result.txt:
The result is:       55
FortranStatistic code:

File:FortranStatistic.zip