home *** CD-ROM | disk | FTP | other *** search
- /*
- SortAndMergeContrasts.c
- HISTORY:
- 8/24/91 dgp Added typedef and cast to make it compatible with THINK C 5.0.
- 1/25/93 dgp removed obsolete support for THINK C 4.
- 11/1/94 dgp fixed minor bug in SortAndMergeContrasts reported by Bart Farell. If there
- were more than 2 identical contrasts, the 3rd would not be merged. This did not corrupt
- any data, it just produced a less compact printout than it should. It had no effect
- on Weibull fits since they effectively treat each trial independently, but it did
- allow an extra degree of freedom per unmerged contrast to the monotonic fit.
- */
- #include "Quick3.h"
-
- typedef int (*qsort_cmp_func)(const void *,const void *);
-
- static int CompareContrasts(contrastRecord *c1,contrastRecord *c2);
-
- void SortAndMergeContrasts(dataRecord *dataPtr)
- {
- int i,j;
-
- /* Sort the contrastRecords in order of increasing contrast. */
- qsort(dataPtr->c,dataPtr->contrasts,sizeof(contrastRecord)
- ,(qsort_cmp_func)&CompareContrasts);
-
- /* Merge records at equal contrast. */
- i=j=0;
- for(i=0;i+1<dataPtr->contrasts;i++){
- while(i+1<dataPtr->contrasts && dataPtr->c[i].contrast==dataPtr->c[i+1].contrast){
- dataPtr->c[i].trials += dataPtr->c[i+1].trials;
- dataPtr->c[i].correct += dataPtr->c[i+1].correct;
- for(j=i+1;j<dataPtr->contrasts-1;j++) dataPtr->c[j]=dataPtr->c[j+1];
- dataPtr->contrasts--;
- }
- }
- }
-
- static int CompareContrasts(contrastRecord *c1,contrastRecord *c2)
- {
- if(c1->contrast > c2->contrast) return 1;
- if(c1->contrast == c2->contrast) return 0;
- return -1;
- }