home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume24 / chemtab / part01 / esort.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-12  |  3.4 KB  |  127 lines

  1.  
  2. /*
  3.  * chemtab - a periodic table data base (C) 1990 Jim King (pulsar@lsrhs)
  4.  *
  5.  * esort.c    Takes the changed values to look for and sifts to sub1
  6.  */
  7.  
  8. #include "element.h"
  9. #include "undefs.h"
  10. #include "variables.h"
  11. #include "tune.h"
  12. #include <curses.h>
  13. #include "windows.h"
  14.  
  15.  
  16. int    sift[3][120],    /* Enough spaces to carry all the elements through
  17.                the sifting process 3 times. */
  18.     sftc[3];    /* number telling the amount of elements in sift[x] */
  19. int    tmp[120],    /* A place to put compared elements from 1&2 & 2&3 */
  20.     tc;        /* The temp[x] counter */
  21.  
  22. /*
  23.  * esort() - no input
  24.  *
  25.  * purpose:    Take the selecting characteristics from dosort[x] which are
  26.  *        defined in schar() and sift the elements through them, then
  27.  *        see what's left and store it away.
  28.  */
  29. esort()
  30. {
  31.     struct    elem    *tempo;
  32.     int    i, j, k;        /* loops */
  33.  
  34.     x = 0.0;            /* floating integer for cmp */
  35.  
  36.     if (dosort[0].wch == 0)            /* No chars to sort */
  37.         return(1);
  38.  
  39.     tc = gtot = 0;                /* Reset counter */
  40.     for (i = 0; i < 120; i++) {
  41.         sub1[i] = 0;            /* Clear the olds */
  42.         sift[0][i] = sift[1][i] = sift[2][i] = 0;
  43.         tmp[i] = 0;
  44.     }
  45.     sftc[0] = sftc[1] = sftc[2] = 0;
  46.  
  47.     for (i = 0; i < 3; i++) {
  48.         if (dosort[i].wch != 0) {    /* Sort on this */
  49.             for (tempo = e; tempo != NULL; tempo = tempo->next) {
  50.                 switch(dosort[i].wch) {
  51.                     case 1: x = tempo->anum;  break;
  52.                     case 2: x = tempo->amass; break;
  53.                     case 3: x = tempo->fam;   break;
  54.                     case 4: x = tempo->row;   break;
  55.                     case 5: x = tempo->val;   break;
  56.                     case 6: x = tempo->melt;  break;
  57.                     case 7: x = tempo->boil;  break;
  58.                     case 8: x = tempo->fio;   break;
  59.                     case 9: x = tempo->year;  break;
  60.                     case 10: x = tempo->eneg; break;
  61.                     case 11: x = tempo->spht; break;
  62.                     case 12: x = tempo->dens; break;
  63.                     case 13: x = tempo->arad; break;
  64.                     default:              break;
  65.                 }
  66.                 if ((x > dosort[i].amt && dosort[i].sgn == GREATER) ||
  67.                     (x < dosort[i].amt && dosort[i].sgn == LESS) ||
  68.                     (x == dosort[i].amt && dosort[i].sgn == EQUAL) ||
  69.                     (x >= dosort[i].amt - closev[dosort[i].wch] && x <= dosort[i].amt + closev[dosort[i].wch] && dosort[i].sgn == CLOSE)) {
  70.                     if (!((dosort[i].wch == 5 && x == VAL) ||
  71.                         (dosort[i].wch == 6 && x == MEL) ||
  72.                         (dosort[i].wch == 7 && x == BOI) ||
  73.                         (dosort[i].wch == 8 && x == FIO) ||
  74.                         (dosort[i].wch == 10 && x == ENG) ||
  75.                         (dosort[i].wch == 11 && x == SPHT) ||
  76.                         (dosort[i].wch == 12 && x == DENS) ||
  77.                         (dosort[i].wch == 13 && x == ARD))) {
  78.                         sftc[i]++;
  79.                         sift[i][sftc[i]] = tempo->anum;
  80.                         }
  81.                 }
  82.             }
  83.         }
  84.     }
  85.                     /* Now sift each to other */
  86.                     /* Compare 1 and 2 into tmp[] */
  87.     if (dosort[1].wch == 0) {    /* Only 1 sort */
  88.         for (i = 1; i < 120; i++) /* Copy sift[0] into sub1 */
  89.             sub1[i] = sift[0][i];
  90.         goto end;
  91.     }
  92.     for (j = 1; j < 120; j++) {    /* Compare sift[1] and sift[0] */
  93.         if (sift[0][j] != 0) {    /* If something to compare */
  94.             for (k = 1; k < 120; k++) {
  95.                 if (sift[0][j] == sift[1][k]) {
  96.                     tc++;    /* Match */
  97.                     tmp[tc] = sift[0][j];
  98.                 }
  99.             }
  100.         }
  101.     }
  102.     if (dosort[2].wch == 0) {    /* Only 2 sorts */
  103.         for (i = 1; i < 120; i++) /* Copy tmp into sub1 */
  104.             sub1[i] = tmp[i];
  105.         goto end;
  106.     }
  107.                     /* Now sift tmp[] with sift[2] */
  108.     for (i = 1; i < 120; i++) {
  109.         if (tmp[i] != 0) {
  110.             for (j = 1; j < 120; j++) {
  111.                 if (tmp[i] == sift[2][j]) {
  112.                     ++gtot;
  113.                     sub1[gtot] = tmp[i]; /* Match */
  114.                 }
  115.             }
  116.         }
  117.     }
  118.     goto rend;
  119. end:    for (i = 1; i < 120; i++) {
  120.         if (sub1[i] != 0)
  121.             gtot++;
  122.     }
  123. rend:    /* This is the end! */
  124.     tc = 0;
  125.     return(0);
  126. }
  127.