home *** CD-ROM | disk | FTP | other *** search
- #ifdef ReGIS
-
- /*
- * chemtab - a periodic table data base (C) 1990 Jim King
- * jek5036@ritvax.isc.rit.edu (formerly pulsar@lsrhs)
- *
- * doregisgph.c - Graph better for ReGIS compatible users (OCT 1990)
- */
-
- #include <curses.h>
- #include "windows.h"
- #include <stdio.h>
- #include <math.h>
- #include "variables.h"
- #include "element.h"
- #include "graph.h"
- #include "undefs.h"
- #include <signal.h>
-
- extern int numr(), stop();
-
- #endif ReGIS
- /*
- * find(ch, en)
- *
- * inputs: char ch; int enum;
- * returns: floating point integer
- * purpose: replace many switch statements
- */
- find(ch, en)
- int ch, en;
- {
- struct elem *pos;
- int i;
-
- for (pos = e; en != pos->anum; pos = pos->next) ;
-
- switch(ch) {
- case 'a': x = pos->anum; break;
- case 'b': x = pos->amass; break;
- case 'c': x = pos->melt; if (x == MEL) x = -999.0;
- break;
- case 'd': x = pos->boil; if (x == BOI) x = -999.0;
- break;
- case 'e': x = pos->fio; if (x == FIO) x = -999.0;
- break;
- case 'f': x = pos->eneg; if (x == ENG) x = -999.0;
- break;
- case 'g': x = pos->spht; if (x == SPHT) x = -999.0;
- break;
- case 'h': x = pos->dens; if (x == DENS) x = -999.0;
- break;
- case 'i': x = pos->arad; if (x == ARD) x = -999.0;
- break;
- default: x = pos->year; if (x == YEA) x = -999.0;
- break;
- }
- }
-
- /*
- * doregisgph - no input
- *
- * purpose: ReGIS graphics support
- */
- doregisgph()
- {
- #ifdef ReGIS
- char c, str[80];
- int i, j, grid, lastx, lasty, connect, type, firstup;
- struct elem *tmp;
-
- #ifdef USERSHELL
- signal(SIGTSTP, SIG_IGN);
- #endif USERSHELL
-
- for (i = 0; i < XAXISDEF; i++)
- xaxis[i] = 0;
- for (i = 0; i < YAXISDEF; i++)
- yaxis[i] = 0;
-
- wclear(graph); wrefresh(graph); clear(); refresh();
- menu("ReGIS 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");
- mvwaddstr(mn, 6, 0, "g] Specific Heat");
- 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 == '?') { help(3); goto first; }
- if (c1 == '\n') {
- #ifdef USERSHELL
- signal(SIGTSTP, stop);
- #endif USERSHELL
- wclear(mn);
- return;
- }
- 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);
- rl4: mvwaddstr(mn, 13, 0, "What range, X Minimum? ");
- wrefresh(mn);
- cur = mn; xp = 23; yp = 13;
- echo(); nocrmode();
- gets(str);
- if (str[0] == '?') { help(4); goto rl4; }
- 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 = 49; 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 = 13; yp = 11;
- noecho(); crmode();
- c2 = wgetch(mn); /* Y axis chc */
- if (c2 == '?') { help(5); goto scnd; }
- if (c2 < 'a' || c2 > 'j')
- goto scnd;
- noecho();
-
- /* Here we find the x axis max and min values */
-
- bot("Calculating the X axis max and min values...");
-
- 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 */
- bot("Calculating the Y axis max and min values...");
-
- if (gtot > 0) {
- find(c2, e->anum);
- ymax = ymin = x;
- 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 the scale */
-
- bot("Scaling...");
- scale = (xmax - xmin) / (double)XAXISDEF;
- xaxis[1] = xmin;
- for (i = 2; i < XAXISDEF; i++)
- xaxis[i] = xaxis[i-1] + scale;
-
- scale = (ymax - ymin) / (double)YAXISDEF;
- yaxis[YAXISDEF-1] = ymin;
- for (i = YAXISDEF-2; i > 1; i--)
- yaxis[i] = yaxis[i+1] + scale;
-
- rl6: noecho(); crmode();
- mvwaddstr(btm, 0, 0, "Would you like a grid? ");
- wrefresh(btm);
- cur = btm; xp = 24; yp = 0;
- switch(getchar()) {
- case 'y':
- case 'Y': grid = 1; break;
- case '?': help(6); goto rl6;
- default: grid = 0; break;
- }
- if (c1 < 'c') {
- rl7: mvwaddstr(btm, 0, 0, "Would you like the points connected? ");
- wrefresh(btm);
- cur = btm; xp = 38; yp = 0;
- switch(getchar()) {
- case '?': help(7); goto rl7;
- case 'y': case 'Y': connect = 1; break;
- default: connect = 0; break;
- }
- } else connect = 0;
- rl8: wclear(btm);
- mvwaddstr(btm, 0, 0, "Would you like dots instead of hashmarks (slower) ");
- wrefresh(btm);
- cur = btm; xp = 44; yp = 0;
- switch(getchar()) {
- case 'y': case 'Y': type = 1; break;
- case '?': help(8); goto rl8;
- default: type = 0; break;
- }
- #ifdef LASERPRT
- rl9: wclear(btm);
- mvwaddstr(btm, 0, 0, "Would you like a laser print file of this? ");
- wrefresh(btm);
- cur = btm; xp = 40; yp = 0;
- switch(getchar()) {
- case 'y': case 'Y': laser = 1; break;
- case '?': help(19); goto rl9;
- default: laser = 0; break;
- }
- if (laser == 1) {
- if ((lsr = fopen("laser", "w")) == NULL) {
- bot("Sorry, the file 'laser' could not be opened for writing.");
- sleep(2);
- bot("No laser print document will be made.");
- sleep(2);
- bot(" ");
- laser = 0;
- } else
- fprintf(lsr, "\014");
- bot("A copy will be found in the file 'laser' when you exit chemtab.");
- sleep(2);
- }
- #endif LASERPRT
- bot("Initializing for graphics...");
- wclear(mn); wrefresh(mn);
- wclear(btm); wrefresh(btm);
- clear(); refresh();
-
- initregis();
- regisgoto(450, 10);
- chcolor(RED_3);
- text(3, 0, -5, "Chemtab V2.01");
- regisgoto(400 - (strlen(gname[numr(c1)]) * 10), YMAXDEF + 20);
- text(2, 0, 0, gname[numr(c1)]);
- regisgoto(YMINDEF - 46, 200 + (strlen(gname[numr(c2)]) * 10));
- text(2, 90, 0, gname[numr(c2)]);
- chcolor(WHT_3);
- mybox(1, XMINDEF, YMINDEF, XMAXDEF, YMAXDEF);
- mybox(2, 0, 0, 798, 478);
- for (i = YAXISDEF-1; i > 1; i -= YAXISDEF/7) {
- if (c2 < 'f' || c2 > 'i')
- sprintf(str, "%d -", (int)(yaxis[i]+.5));
- else if (yaxis[i] > 9.99)
- sprintf(str, "%2.3f", yaxis[i]);
- else
- sprintf(str, "%2.3f", yaxis[i]);
- chcolor(BLU_3);
- if (grid) line(XMINDEF, i+YBOUND+1, XMAXDEF, i+YBOUND+1);
- chcolor(RED_3);
- regisgoto(XMINDEF-60, i-7+YBOUND);
- text(1, 0, 5, str);
- }
- for (i = 1; i < XAXISDEF; i += XAXISDEF/10) {
- if (c1 < 'f' || c1 > 'i')
- sprintf(str, "%d", (int)(xaxis[i]+.5));
- else
- sprintf(str, "%4.2f", xaxis[i]);
- chcolor(BLU_3);
- if (grid && i < XAXISDEF-20) line(i+XBOUND+1, YMINDEF, i+XBOUND+1, YMAXDEF);
- chcolor(RED_3);
- regisgoto(i-6+XBOUND, YMAXDEF+2);
- text(1, 0, 5, str);
- }
-
- firstup++;
- 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 < XAXISDEF; j++) {
- if (x > xaxis[j])
- continue;
- else
- break;
- }
- xspot = j;
- 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[YAXISDEF-1])
- yspot = YAXISDEF-1;
- else {
- for (j = YAXISDEF-2; j > 1; j--) {
- if (x > yaxis[j])
- continue;
- else
- break;
- }
- yspot = j;
- }
- chcolor(YEL_3);
- if (firstup) { lastx = xspot; lasty = yspot; firstup = 0; }
- if (connect && i != 1) {
- chcolor(GRN_3);
- line(xspot+XBOUND, yspot+YBOUND, lastx+XBOUND, lasty+YBOUND);
- lastx = xspot; lasty = yspot;
- }
- hash(xspot+XBOUND, yspot+YBOUND, type);
- }
- } 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 < XAXISDEF; j++) {
- if (x > xaxis[j])
- continue;
- else
- break;
- }
- xspot = j;
- 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[YAXISDEF-1])
- yspot = YAXISDEF-1;
- else {
- for (j = YAXISDEF; j > 1; j--) {
- if (x > yaxis[j])
- continue;
- else
- break;
- }
- yspot = j;
- }
- chcolor(YEL_3);
- if (i == 1) lastx = xspot, lasty = yspot;
- if (connect && i != 1) {
- chcolor(GRN_3);
- line(xspot+XBOUND, yspot+YBOUND, lastx+XBOUND, lasty+YBOUND);
- lastx = xspot; lasty = yspot;
- }
- hash(xspot+XBOUND, yspot+YBOUND, type);
- }
- }
- regispc();
- endregis();
- #ifdef LASERPRT
- if (laser)
- fclose(lsr);
- #endif LASERPRT
- clear(); refresh();
- wclear(graph); wrefresh(graph);
- #ifdef USERSHELL
- signal(SIGTSTP, stop);
- #endif USERSHELL
- return(0);
- #endif ReGIS
- }
-