home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / EDUCATIO / NTUMIN10.ZIP / CHECKOUT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-09  |  5.8 KB  |  195 lines

  1. /****************************************************************************
  2.  *
  3.  *    Program Name : CHECKOUT.C
  4.  *
  5.  *    This program checks the correctness of the solution array by
  6.  *     converting the input array and output array to minterms, sorting
  7.  *    them (ascending order) and check to see if they are equal.
  8.  *
  9.  * --------------------------------------------------------------------------
  10.  *    Copyright (c) 1992. All Rights Reserved. Nanyang Technological
  11.  *    University.
  12.  *
  13.  *    You are free to use, copy and distribute this software and its
  14.  *    documentation providing that:
  15.  *
  16.  *        NO FEE IS CHARGED FOR USE, COPYING OR DISTRIBUTION.
  17.  *
  18.  *        IT IS NOT MODIFIED IN ANY WAY.
  19.  *
  20.  *        THE COPYRIGHT NOTICE APPEAR IN ALL COPIES.
  21.  *
  22.  *    This program is provided "AS IS" without any warranty, expressed or
  23.  *    implied, including but not limited to fitness for any particular
  24.  *    purpose.
  25.  *
  26.  *    If you find NTUMIN fast, easy, and useful, a note or comment would be
  27.  *    appreciated. Please send to:
  28.  *
  29.  *        Boon-Tiong Tan or Othman Bin Ahmad
  30.  *        School of EEE
  31.  *        Nanyang Technological University
  32.  *        Nanyang Avenue
  33.  *        Singapore 2263
  34.  *        Republic of Singapore
  35.  *
  36.  ****************************************************************************/
  37.  
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #define mask8 255
  42.  
  43.  
  44. main()
  45.  
  46. {
  47.    unsigned short    m1, m2, ma, mb, md, i, j, k;
  48.    unsigned char     *infile, *outfile, *readf(), *sorting();
  49.    unsigned char     *a, *b, *d, nspm, na, nb, c;
  50.          int     test;
  51.    unsigned long     m3;
  52.    FILE              *in, *out;            /*  file pointers */
  53.  
  54.    printf("This program is for checking the output generated by the minimization \n");
  55.    printf("program to verify that it is correct.\n\n");
  56.    printf("Before that, the output file must be converted to one similar to the\n");
  57.    printf("input file. (Usable for inputs with DC array)\n\n");
  58.    printf("Press any key to Continue or <ESC> to QUIT\n\n");
  59.    c = getch();
  60.    if (c==27)
  61.       exit(0);
  62.  
  63.    infile = (unsigned char *)malloc (21);       /* space for 1st filename */
  64.    if (infile==0)
  65.       {
  66.      printf("Out of memory -- VERIFY, *infile\n");
  67.      printf("Program Terminated - 1\n");
  68.      exit(0);
  69.       }
  70.  
  71.    outfile = (unsigned char *)malloc (21);      /* space for 2nd filename */
  72.    if (outfile==0)
  73.       {
  74.      printf("Out of memory -- VERIFY, *outfile\n");
  75.      printf("Program Terminated - 2\n");
  76.      exit(0);
  77.       }
  78.  
  79.    printf("Enter input filename -> ");
  80.    gets(infile);                                 /* read 1st filename */
  81.  
  82.    printf("Enter output filename -> ");
  83.    gets(outfile);                                /* read 2nd filename */
  84.  
  85.    if ((in = fopen(infile, "r+")) == NULL)           /* open 1st file */
  86.       {
  87.      printf("Error opening file, %s\n", infile);
  88.      printf("Program terminated.\n ") ;
  89.      exit(0);
  90.       }
  91.  
  92.    if ((out = fopen(outfile, "r+")) == NULL)         /* open 2nd file */
  93.       {
  94.      printf("Error opening file, %s\n", outfile);
  95.      printf("Program terminated.\n ") ;
  96.      exit(0);
  97.       }
  98.  
  99.    d = (unsigned char *) malloc(4);                  /* DC array */
  100.    if (d == 0)
  101.       {
  102.      printf("Out of memory -- VERIFY, *d\n");
  103.      printf("Program terminated.\n ") ;
  104.      exit(0);
  105.       }
  106.  
  107.    /***
  108.     ***  READING FROM FILES AND CONVERTING TO MINTERMS
  109.     ***/
  110.  
  111.    printf("\nPlease Hang On, Reading From Files & Converting To Minterms ... \n\n");
  112.  
  113.    a = readf(in, a, 0);                /* read ON array, 1st file */
  114.    a = sorting(a);                     /* sort in ascending order */
  115.  
  116.    *d = *a;                            /* headers for DC array */
  117.    *(d+1) = 0;
  118.    *(d+2) = 0;
  119.    *(d+3) = *(a+3);
  120.    d = readf(in, d, 1);                /* read DC array */
  121.    d = sorting(d);                     /* sort in ascending order */
  122.    fclose(in);                         /* close 1st file */
  123.  
  124.    na = *a;                            /* no. of variables */
  125.    m1 = *(a+1);
  126.    m2 = *(a+2);
  127.    ma = (m2&mask8)<<8 | m1;            /* no. of minterms */
  128.  
  129.    md = *(d+2)<<8 | *(d+1);
  130.  
  131.    b = readf(out, b, 0);               /* read ON array, 2nd file */
  132.    b = sorting(b);                     /* sort in ascending order */
  133.    fclose(out);                        /* close 2nd file */
  134.  
  135.    nb = *b;                            /* no. of variables */
  136.    m1 = *(b+1);
  137.    m2 = *(b+2);
  138.    nspm = *(b+3);                      /* no. of byte/minterm */
  139.    mb = (m2&mask8)<<8 | m1;            /* no. of minterms */
  140.  
  141.    /***
  142.     ***  COMPARING MINTERMS
  143.     ***/
  144.  
  145.    printf("\nPlease Hang On, Comparing Minterms ... \n\n");
  146.  
  147.    if (na !=  nb)                      /* unequal no. of variables */
  148.       {
  149.      printf("Different number of variables in the 2 files. \n");
  150.      printf("Program Terminated - 3 \n");
  151.      exit(0);
  152.       }
  153.  
  154.    for (i=0; i<mb; i++)           /* minterms in output array */
  155.       {
  156.      for (j=0; j<ma; j++)     /* minterms in ON array */
  157.         {
  158.            test = memcmp((a+4+nspm*j),(b+4+nspm*i),nspm);
  159.            if (test==0)
  160.           {
  161.              ma--;
  162.              memcpy((a+4+nspm*j),(a+4+nspm*(j+1)),nspm*(ma-j));
  163.              break;
  164.           }
  165.         }
  166.  
  167.      if (test!=0)
  168.         {
  169.            for (k=0; k<md; k++)          /* minterms in DC array */
  170.           {
  171.              test = memcmp((d+4+nspm*k),(b+4+nspm*i),nspm);
  172.              if (test==0)
  173.             {
  174.                md--;
  175.                memcpy((d+4+nspm*k),(d+4+nspm*(k+1)),nspm*(md-k));
  176.                break;
  177.             }
  178.           }
  179.         }
  180.      if (test != 0)                          /* not in ON & DC array */
  181.         break;
  182.       }
  183.  
  184.    if (test==0 && ma==0)                         /* successful */
  185.       printf("SUCCESS IN COMPARISION !\n");
  186.    else                                          /* solution array error */
  187.       printf("ERROR IN COMPARISION !\n");
  188.  
  189.    free(a);                          /* free pointers */
  190.    free(b);
  191.    free(d);
  192.    free(infile);
  193.    free(outfile);
  194. }
  195.