#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define SIZE 256
/*
* gera nome de arquivo: dados-DIAMESANO-HORAMINUTOSEGUNDO.txt
*/
void
mkname(char *fname)
{
char buffer[SIZE], d[7] = "dados-";
time_t curtime;
struct tm *loctime;
curtime = time(NULL);
loctime = localtime(&curtime);
strftime(buffer, SIZE, "%F-%H%M%S", loctime);
strncpy(fname, d, sizeof(d));
strncat(fname, buffer, sizeof(buffer) + sizeof(fname));
}
/* gera script gnuplot para transformar gráfico em arquivo .eps */
void
scrplot(char *fname)
{
FILE *dados;
if (!(dados = fopen("temp.gpt", "w"))) {
fprintf(stdout, "%s\n", errno);
exit(1);
}
fprintf(dados, "reset\n");
fprintf(dados, "set title \"Equacao Logistica\"\n");
fprintf(dados, "set nokey\n");
fprintf(dados, "set size 2,2\n");
fprintf(dados, "set term post eps enhanced color\n");
fprintf(dados, "set out \'%s.eps\'\n", fname);
fprintf(dados, "plot \'%s\' u 2:1", strncat(fname, ".txt", sizeof(fname)));
fclose(dados);
}
#include "def.h"
int
main(int argc, char *argv[])
{
FILE *dados;
float x, k = 2, i = 1, inc;
char *fname;
/* passagem de argumentos pela linha de comando ou interativamente */
if (argc < 2) {
fprintf(stdout, "Semente> ");
fscanf(stdin, "%f", &x);
fprintf(stdout, "Incremento> ");
fscanf(stdin, "%f", &inc);
} else {
x = atof(argv[1]);
inc = atof(argv[2]);
}
mkname(fname);
scrplot(fname);
if (!(dados = fopen(fname, "w"))) {
fprintf(stdout, "%s\n", errno);
exit(1);
}
while (!feof(dados)) {
while (k <= 4) {
i = 0;
while (i <= 10) {
x = k * x * (1 - x);
fprintf(dados, "%f %f\n", x, k);
fprintf(stdout, "x = %f\tk = %f\n", x, k);
i++;
}
k += inc;
}
break;
}
system("gnuplot < temp.gpt");
remove("temp.gpt");
exit(0);
}
|
Franklin Anderson de Oliveira Souza <[email protected]> -
Merovigiam
É garantida a permissão para copiar, distribuir e/ou modificar este documento sobre os termos da GNU Free Documentation Licence. 2004 |