home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / VideoToolbox 95.04.18 / Utilities / Quick3 / SortAndMergeContrasts.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-01  |  1.5 KB  |  43 lines  |  [TEXT/MMCC]

  1. /*
  2. SortAndMergeContrasts.c
  3. HISTORY:
  4. 8/24/91    dgp    Added typedef and cast to make it compatible with THINK C 5.0.
  5. 1/25/93 dgp removed obsolete support for THINK C 4.
  6. 11/1/94 dgp fixed minor bug in SortAndMergeContrasts reported by Bart Farell. If there
  7. were more than 2 identical contrasts, the 3rd would not be merged. This did not corrupt
  8. any data, it just produced a less compact printout than it should. It had no effect
  9. on Weibull fits since they effectively treat each trial independently, but it did
  10. allow an extra degree of freedom per unmerged contrast to the monotonic fit.
  11. */
  12. #include "Quick3.h"
  13.  
  14. typedef int (*qsort_cmp_func)(const void *,const void *);
  15.  
  16. static int CompareContrasts(contrastRecord *c1,contrastRecord *c2);
  17.  
  18. void SortAndMergeContrasts(dataRecord *dataPtr)
  19. {
  20.     int i,j;
  21.     
  22.     /* Sort the contrastRecords in order of increasing contrast. */
  23.     qsort(dataPtr->c,dataPtr->contrasts,sizeof(contrastRecord)
  24.         ,(qsort_cmp_func)&CompareContrasts);
  25.     
  26.     /* Merge records at equal contrast. */
  27.     i=j=0;
  28.     for(i=0;i+1<dataPtr->contrasts;i++){
  29.         while(i+1<dataPtr->contrasts && dataPtr->c[i].contrast==dataPtr->c[i+1].contrast){
  30.             dataPtr->c[i].trials += dataPtr->c[i+1].trials;
  31.             dataPtr->c[i].correct += dataPtr->c[i+1].correct;
  32.             for(j=i+1;j<dataPtr->contrasts-1;j++) dataPtr->c[j]=dataPtr->c[j+1];
  33.             dataPtr->contrasts--;
  34.         }
  35.     }
  36. }
  37.  
  38. static int CompareContrasts(contrastRecord *c1,contrastRecord *c2)
  39. {
  40.     if(c1->contrast >  c2->contrast) return 1;
  41.     if(c1->contrast == c2->contrast) return 0;
  42.     return -1;
  43. }