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

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