home *** CD-ROM | disk | FTP | other *** search
- /*
- * chemtab - a periodic table data base (C) 1990 Jim King (pulsar@lsrhs)
- *
- * dogph.c Contains graphing procedures
- */
-
- #include <curses.h>
- #include "windows.h"
- #include <stdio.h>
- #include <math.h>
- #include "tune.h"
- #include "variables.h"
- #include "element.h"
- #include "graph.h"
- #include "undefs.h"
-
- /*
- * numr(ch)
- * input: ch - char - input to determine output
- * output: return() - int
- *
- * purpose: to print the top line of the graph, x vs. y, we need
- * the array number of the chosen function, array gname[]
- * found in graph.h...
- */
- numr(ch)
- char ch;
- {
- char luk[12];
- int i;
-
- strcpy(luk, " abcdefghij");
- for (i = 1; i < 11; i++)
- if (ch == luk[i]) return(i);
- }
-
- fixup(win)
- WINDOW *win;
- {
- wmove(win, 0, 0);
- wmove(btm, 0, 0);
- wmove(win, 0, 0);
- move(0, 0);
- refresh();
- wrefresh(btm);
- wrefresh(win);
- }
-
- extern void find();
-
- /*
- * dogph() - no input
- *
- * purpose: This is the main graphing routine.
- */
- dogph()
- {
- struct elem *tmp;
- char c, str[80];
- int i, j, count;
-
- for (i = 0; i < 70; i++) /* clear the x axis points */
- xaxis[i] = 0;
- for (i = 0; i < 21; i++) /* clear the y axis points */
- yaxis[i] = 0;
-
- l2: wclear(graph); wrefresh(graph); clear(); refresh();
- menu("Graphing Module");
- mvwaddstr(mn, 0, 0, "a] Atomic Number");
- mvwaddstr(mn, 1, 0, "b] Atomic Mass");
- mvwaddstr(mn, 2, 0, "c] Melting Temp.");
- mvwaddstr(mn, 3, 0, "d] Boiling Temp.");
- mvwaddstr(mn, 4, 0, "e] Ionization Energy");
- mvwaddstr(mn, 5, 0, "f] Electronegativity");
- wrefresh(mn);
- wmove(mn, 6, 0);
- wclrtoeol(mn);
- mvwaddstr(mn, 6, 0, "g] Specific Heat");
- wrefresh(mn);
- mvwaddstr(mn, 7, 0, "h] Density");
- mvwaddstr(mn, 8, 0, "i] Atomic Radius");
- mvwaddstr(mn, 9, 0, "j] Discovery Year");
- mvwaddstr(mn, 10, 0, "Graphing by this, across the X axis.");
- mvwaddstr(mn, 13, 0, "*** Due to lack of information at this time, graphs beyond");
- mvwaddstr(mn, 14, 0, "*** Atomic number 86 may be misleading. The program is designed");
- mvwaddstr(mn, 15, 0, "*** to compensate, but nothing is perfect.");
- mvwaddstr(mn, 16, 0, ">>> PRESS RETURN TO RETURN TO MAIN MENU.");
- first: mvwaddstr(mn, 11, 0, "Your choice: ");
- wrefresh(mn); /* collect their choices */
- cur = mn; xp = 14; yp = 11;
- crmode();
- noecho();
- c1 = getchar(); /* X axis chc */
- if (c1 == '\n') { wclear(mn); return; }
- if (c1 == '?') { help(3); goto first; }
- if (c1 < 'a' || c1 > 'j')
- goto first;
- for (i = 12; i < 17; i++) {
- wmove(mn, i, 0); wclrtoeol(mn);
- }
-
- find(c1, e->anum);
- xmax = xmin = x;
- if (gtot > 0) {
- for (tmp = e; tmp->next != NULL; tmp = tmp->next) {
- find(c1, tmp->anum);
- if (x == -999.0) continue;
- if (x > xmax) xmax = x;
- if (x < xmin) xmin = x;
- }
- } else {
- for (i = 1; i < gtot; i++) {
- find(c1, sub1[i]);
- if (x == -999.0) continue;
- if (i == 1) xmax = xmin = x;
- else {
- if (x > xmax) xmax = x;
- if (x < xmin) xmin = x;
- }
- }
- }
-
- mvwaddstr(mn, 10, 0, "If you would rather use the maximum and minimum values of");
- mvwaddstr(mn, 11, 0, "all the elements, hit RETURN once.");
- wmove(mn, 12, 0); wprintw(mn, "All the element's values: Minimum %f, Maximum %f", xmin, xmax);
- l4: mvwaddstr(mn, 13, 0, "What range, X Minimum? ");
- wrefresh(mn);
- cur = mn; xp = 24; yp = 13;
- echo(); nocrmode();
- gets(str);
- if (str[0] == '?') { help(4); goto l4; }
- if (!strlen(str)) {
- xmin = -999;
- goto nt;
- }
- xmin = atof(str);
- fixup(mn); fixup(stdscr);
- mvwaddstr(mn, 13, 0, "What range, X Maximum [RETURN for value above]? ");
- wrefresh(mn);
- cur = mn; xp = 48; yp = 13;
- echo(); nocrmode();
- gets(str);
- if (strlen(str))
- xmax = atof(str);
- fixup(mn);
-
- nt: wmove(mn, 10, 0); wclrtoeol(mn); wmove(mn, 11, 0); wclrtoeol(mn);
- mvwaddstr(mn, 10, 0, "Graphing by this, down the Y axis. ");
- scnd: wmove(mn, 12, 0); wclrtoeol(mn); wmove(mn, 13, 0); wclrtoeol(mn);
- mvwaddstr(mn, 11, 0, "Your choice: ");
- wrefresh(mn);
- cur = mn; xp = 14; yp = 11;
- noecho(); crmode();
- c2 = wgetch(mn); /* Y axis chc */
- if (c2 == '?') { help(5); goto scnd; }
- if (c2 < 'a' || c2 > 'j')
- goto scnd;
- noecho();
-
- wclear(mn); wrefresh(mn);
- clear(); refresh();
- /* Here we find the x axis max and min values */
- /* if they are not already defined */
- if (xmin == -999) {
- find(c1, e->anum);
- xmax = xmin = x;
- for (tmp = e; tmp->next != NULL; tmp = tmp->next) {
- find(c1, tmp->anum);
- if (x == -999.0) continue;
- if (x > xmax) xmax = x;
- if (x < xmin) xmin = x;
- }
- }
-
- /* Here we find the y axis min and max values */
-
- find(c2, e->anum);
- ymax = ymin = x;
- if (gtot > 0) {
- for (tmp = e; tmp->next != NULL; tmp = tmp->next) {
- find(c2, tmp->anum);
- if (x == -999.0) continue;
- if (x > ymax) ymax = x;
- if (x < ymin) ymin = x;
- }
- } else {
- for (i = 1; i < gtot; i++) {
- find(c2, sub1[i]);
- if (x == -999.0) continue;
- if (i == 1)
- ymax = ymin = x;
- else {
- if (x > ymax) ymax = x;
- if (x < ymin) ymin = x;
- }
- }
- }
-
- /* Now we have min & maxs we have to put a number in
- each slot on both axes using a scale */
-
- scale = (xmax - xmin) / 69.0; /* 69 is # of slots in X axis */
-
- xaxis[1] = xmin;
- for (i = 2; i < 70; i++)
- xaxis[i] = xaxis[i-1] + scale;
-
- scale = (ymax - ymin) / 20.0; /* 20 is # of slots in Y axis */
-
- yaxis[20] = ymin;
- for (i = 19; i > 1; i--)
- yaxis[i] = yaxis[i+1] + scale;
-
- sprintf(str, "%s (x-axis) vs. %s (y-axis)", gname[numr(c1)], gname[numr(c2)]);
- mvwaddstr(graph, 0, (40 - (strlen(str) / 2)), str);
- wrefresh(graph); /* That is the top graph line */
- for (i = 20; i > 1; i--) { /* The y axis line */
- mvwaddstr(graph, i, 10, "|");
- wrefresh(graph);
- }
- for (i = 11; i < 80; i++) { /* The x axis line */
- mvwaddstr(graph, 21, i, "-");
- wrefresh(graph);
- }
- fixup(graph);
- mvwaddstr(graph, 21, 10, "+"); /* The corner */
- wrefresh(graph);
- for (i = 20; i > 1; i -= 5) { /* Y axis points */
- if (c2 < 'f' || c2 > 'i')
- sprintf(str, "%d ->", (int)(yaxis[i]+.5));
- else
- sprintf(str, "%4.2f ->", yaxis[i]);
- mvwaddstr(graph, i, 0, str);
- }
- for (i = 1; i < 79; i += 10) { /* X axis points */
- if (c1 < 'f' || c1 > 'i')
- sprintf(str, "^%d", (int)(xaxis[i]+.5));
- else
- sprintf(str, "^%4.2f", xaxis[i]);
- mvwaddstr(graph, 22, i+10, str);
- }
- /* The actual find & graph */
-
- if (gtot > 0) {
- for (tmp = e; tmp->next != NULL; tmp = tmp->next) {
- find(c1, tmp->anum);
- if (x == -999.0) continue;
- if (x < xmin)
- continue;
- else if (x < xaxis[2])
- xspot = 1;
- else {
- for (j = 2; j < 70; j++) {
- if (x > xaxis[j])
- continue;
- else
- break;
- }
- xspot = j - 1;
- if (x > xmax)
- continue;
- }
-
- /* Found where it goes on the x, now the y */
-
- find(c2, tmp->anum);
- if (x == -999.0) continue;
- if (x < yaxis[19])
- yspot = 20;
- else {
- for (j = 19; j > 1; j--) {
- if (x > yaxis[j])
- continue;
- else
- break;
- }
- yspot = j;
- }
-
- /* Align and put the dot where X marks the spot */
-
- mvwaddstr(graph, yspot, xspot+10, "o");
- wrefresh(graph);
- }
- } else {
- for (i = 1; i < gtot; i++) {
- find(c1, sub1[i]);
- if (x == -999.0) continue;
- if (x < xmin)
- continue;
- else if (x < xaxis[2])
- xspot = 1;
- else {
- for (j = 2; j < 70; j++) {
- if (x > xaxis[j])
- continue;
- else
- break;
- }
- xspot = j - 1;
- if (x > xmax)
- continue;
- }
-
- /* Found where it goes on the x, now the y */
-
- find(c2, sub1[i]);
- if (x == -999.0) continue;
- if (x < yaxis[19])
- yspot = 20;
- else {
- for (j = 19; j > 1; j--) {
- if (x > yaxis[j])
- continue;
- else
- break;
- }
- yspot = j;
- }
-
- /* Align and put the dot where X marks the spot */
-
- mvwaddstr(graph, yspot, xspot+10, "o");
- wrefresh(graph);
- }
- }
-
- capture(graph, 1, 0);
- spc(); /* Space to continue? */
- wclear(graph);
- wrefresh(graph);
- return(0);
- }
-