home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume24
/
chemtab
/
part02
/
element.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-03-12
|
2KB
|
98 lines
/*
* chemtab - a periodic table data base (C) 1990 Jim King (pulsar@lsrhs)
*
* element.c Reads in the file from the #define PERTABLE (which is the
* data file) and sorts into the structure elem (e).
* Also reads in the close values (at the end)
*/
#include "variables.h"
#include "element.h"
#include "tune.h"
#include <stdio.h>
float closev[15];
/*
* readelem() - no input
*
* purpose: Take a line from PERTABLE (tune.h) and put it in structure
* e which is defined as the element table used throughout
* the program. This was designed so the operator could easily
* change an element or add one without changing anything but
* tune.h
*/
readelem()
{
int first = 1;
char inp[160];
FILE *fptr; /* File pointer for PERTABLE */
struct elem *tmp, *old, *new;
fptr = fopen(PERTABLE, "r");
fgets(inp, 160, fptr); /* Read in comment line */
fgets(inp, 160, fptr); /* Eat the spacer */
tmp = NEW(elem);
e = tmp;
while (fscanf(fptr, "%s %s %d %f %d %d %d %d %d %d %d %f %f %f %f\n",
tmp->name, tmp->sym, &tmp->anum, &tmp->amass, &tmp->fam,
&tmp->row, &tmp->val, &tmp->melt, &tmp->boil,
&tmp->fio, &tmp->year, &tmp->eneg, &tmp->spht,
&tmp->dens, &tmp->arad) != EOF) {
if (first) { first = 0; tmp = NEW(elem); continue; }
if (tmp->anum < e->anum) {
tmp->next = e;
e = tmp;
tmp = NEW(elem);
continue;
}
old = NULL; new = e;
for (;;) {
if (new->next == NULL) { /* new tail */
new->next = tmp;
tmp->next = NULL;
break;
}
old = new;
new = new->next;
if ((old->anum < tmp->anum) &&
(tmp->anum < new->anum)) {
tmp->next = new;
old->next = tmp;
break;
}
}
tmp = NEW(elem);
}
tmp = NULL;
fclose(fptr); /* Be nice and neat */
}
/*
* getclose()
* inputs: none
* returns: 888 if bad closefile
* purpose: read close values from CLOSEFILE
*/
int getclose()
{
FILE *fp;
char str[90];
int i;
if ((fp = fopen(CLOSEFILE, "r")) == NULL) {
printf("chemtab: Make sure that tune.h reflects all file names. (CLOSEFILE)\n");
exit(1);
}
fgets(str, 90, fp); fgets(str, 90, fp);
for (i = 0; i < 15; i++)
if (fscanf(fp, "%s%c%f\n", str, str, &closev[i]) == EOF) return(888);
fclose(fp);
}