From 108d22f9ed10090cce7f326b50352a01a8f3256f Mon Sep 17 00:00:00 2001 From: carloseir <64387887+carloseir@users.noreply.github.com> Date: Fri, 2 Oct 2020 22:38:40 -0600 Subject: [PATCH] menu and pipe added --- Euler.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++ Euler.h | 38 +++++++++++++++++ Files.c | 37 ++++++++++++++++ Files.h | 70 +++++++++++++++++++++++++++++++ Implementation | Bin 0 -> 12148 bytes Implementation.c | 80 +++++++++++++++++++++++++++++++++++ Makefile | 14 +++++++ 7 files changed, 346 insertions(+) create mode 100644 Euler.c create mode 100644 Euler.h create mode 100644 Files.c create mode 100644 Files.h create mode 100644 Implementation create mode 100644 Implementation.c create mode 100644 Makefile diff --git a/Euler.c b/Euler.c new file mode 100644 index 0000000..60efc29 --- /dev/null +++ b/Euler.c @@ -0,0 +1,107 @@ +#include +#include +#include + +#include "Euler.h" + +int euler_menu (float *k, float *m, float *position1, float *position2, float *dt, float *t){ + + int opcion; + do{ + printf("Calculo de salto bungee con método de Euler.\n\n"); + printf ("Bienvenido. Favor de ingresar los datos.\n"); + printf("1. Ingresar la constante del Bongee (k): \n"); + printf("2. Ingresar la masa de la persona (m): \n"); + printf("3. Ingresar la posicion inicial (Xo): \n"); + printf("4. Ingresar la diferencia de tiempo (dt): \n"); + printf("5. Ingresar el tiempo a medir (t): \n"); + printf("6. Calcular y salir. (Es necesario ingresar primero todos los datos)\n"); + printf("7. Salir.\n"); + printf("Opcion: "); + scanf ("%d", &opcion); + + switch (opcion){ + case 1: + printf("k = "); + scanf("%f",k); + break; + case 2: + printf("m = "); + scanf("%f",m); + break; + case 3: + printf("Xo = "); + scanf("%f",position1); + *position2 = *position1; + break; + case 4: + printf("dt = "); + scanf("%f",dt); + printf("Regresar? [S/*] "); + break; + case 5: + printf("t = "); + scanf("%f",t); + break; + case 7: + printf("Saliendo...\n"); + exit(1); + break; + default: + if(opcion != 6) + printf("Opcion invalida.\n"); + break; + }//switch + + }while (opcion != 6); + return 0; +} + +void euler_print (float position, float time) +{ + printf("position: %f\t",position); + printf("time: %f\n",time); +} + +float euler_form (float k, float m, const double g, float position1, float position2, float dt){ + float position; + float p1 = (-1*position1)*(1+((k*(dt*dt))/m)); + float p2 = 2 * position2; + float p3 = (dt*dt)*g; + position=p1+p2+p3; + return position; +} + +int euler_list (float position, conditions **first, float time){ + conditions *node, *aux; + node= (conditions*) malloc (sizeof (conditions)); + if (node==NULL){ + printf ("No se asigno el espacio en memoria.\n"); + exit (0); + } + node->position=position; + node->time = time; + node->sig=NULL; + + if (*first==NULL){ + *first=node; + } + else{ + aux = *first; + while (aux->sig != NULL) + aux = aux->sig; + aux->sig = node; + } + return 0; +} + +int euler_free (conditions *first){ + conditions *aux; + aux=first; + while (aux != NULL){ + first=first->sig; + free (aux); + aux=first; + } + return 0; +} diff --git a/Euler.h b/Euler.h new file mode 100644 index 0000000..bdae568 --- /dev/null +++ b/Euler.h @@ -0,0 +1,38 @@ +// +// Euler.h +// +// +// Created by Team 3. +// + +#ifndef Euler_h +#define Euler_h + +#include +#include + +typedef struct euler { + float position; + float time; + struct euler *sig; +}conditions; + +#ifdef Euler_IMPORT + #define EXTERN +#else + #define EXTERN extern +#endif + +EXTERN int euler_menu (float *k, float *m, float *position1, float *position2, float *dt, float *t); + +EXTERN void euler_print (float position, float time); + +EXTERN float euler_form (float k, float m, const double g, float position1, float position2, float dt); + +EXTERN int euler_list (float position, conditions **first, float time); + +EXTERN int euler_free (conditions *first); + +#undef Euler_IMPORT +#undef EXTERN +#endif /* Euler_h */ diff --git a/Files.c b/Files.c new file mode 100644 index 0000000..63cfe89 --- /dev/null +++ b/Files.c @@ -0,0 +1,37 @@ +#include +#include + +#include "Euler.h" + +FILE * file_new(char *name, char *mode){ + FILE *fp; + fp = fopen (name, mode); + return fp; +} + +void file_write(FILE * fp, conditions *first){ + conditions *node; + node=first; + while (node != NULL){ + fprintf(fp, "%f,",node->position); + fprintf(fp, "%f\n",node->time); + node = node->sig; + } + fclose (fp); +} + +void gnuplot () { + int i; + char *labels[] = {"set title \"Movimiento\"", + "set ylabel \"Posicion(x)\"", + "set xlabel \"Tiempo(t)\"", + "set grid", + "set datafile separator','", + "set terminal png", + "set output 'Posicion VS Tiempo.png'", + "plot \"datos.csv\" with lines"}; + FILE *VentanaGnuPlot = popen ("gnuplot -persist", "w"); + for (i=0; i<8; i++) + fprintf(VentanaGnuPlot, "%s \n", labels[i]); + pclose (VentanaGnuPlot); +} diff --git a/Files.h b/Files.h new file mode 100644 index 0000000..0719c45 --- /dev/null +++ b/Files.h @@ -0,0 +1,70 @@ +// +// Files.h +// +// +// Created by Team 3. +// + +#ifndef Files_h +#define Files_h + +#include +#include + +#include "Euler.h" + +#ifdef Files_IMPORT + #define EXTERN +#else + #define EXTERN extern +#endif + + +/* Files.h -- Function prototypes */ + +/** + * Instanciates a new file pointer identified via its name and mode. + * @param + * name (char *): + * Name of the file + * mode (char *): + * Mode of file to be opened {r, rb, a, ab, w, wb} + * + * @return FILE * opened_file. +*/ +EXTERN FILE * file_new(char *name, char *mode); + + + +/** + * Writes a dynamic list into a file. + * @param + * file (FILE *): + * Storage file + * first (conditions): + * The first node of the dynamic list + * aux (conditions): + * The auxiliary of the dynamic list + * node (conditions): + * The actual node of the dynamic list + * + * @return void. +*/ +EXTERN void file_write(FILE * file, conditions *first); + +/** + * Opens a gnuplot instance to graphicate the data from a file. + * @param + * name (char *): + * Name of the file + * + * @return void. +*/ +EXTERN void gnuplot (); + +#undef files_IMPORT +#undef EXTERN + + + +#endif /* Files_h */ diff --git a/Implementation b/Implementation new file mode 100644 index 0000000000000000000000000000000000000000..259345f47a70bd36dabd7b9758d18efe3eb7d9bc GIT binary patch literal 12148 zcmeHNdvsjIc^^G&79-ZOBR~ZaE=IOxiWkckegHX0wytcae#o}OqafC6?Ul56AL{O1 zTP8eg)&|sNPZi)Kw9o_$Cnp~TQxap4sLQ&BXH^>I3 zeW$;@Yp1^>5DJU68`iI0<6r7qF`29NEt|~OP3CGRb4%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cghQ#KYObpiP97BmA|cFhRUCaHd{}3=2yiv~;}Xvge57F+oOXxRDeXM&t^=g;!UE)-ddVm31n?}wJon#(?Z~_9 z1u361+=WxG4?2W;T$pO>L1WM4IP9+>d8CU(3{BffTS(9 zQ?CVvqbK)?nu@<$kNIB$XqWc5fAMJ3+d&&l9|4$$icHj7l+P1U=71|)qE5p&K*Koy l>j3nReatR*b(3gZAjG#_45wb6{9J7DD^z+OJSRDN{|o6ch{^x} literal 0 HcmV?d00001 diff --git a/Implementation.c b/Implementation.c new file mode 100644 index 0000000..fbf3219 --- /dev/null +++ b/Implementation.c @@ -0,0 +1,80 @@ +// +// Implementation.c +// +// +// Created by Team 3. +// +/** +* Our sample program. +* @copyright 2020 by TDA +* @license as you wish +* @author Team 3. +* @version 2020-09-30 +* @file +*/ + + +/* Include standard headers: */ +#include +#include +#include +#include + +/* Include modules header we directly invoke here: */ +#include "Euler.h" +#include "Files.h" + +/*Constants*/ +const double g = 9.81; + +/*Tentativo*/ +//start=clock (); +//