Example #1
0
void printSummary (char code[], int auRuns[], int oppRuns[], int innings[], int attend[], int numGames)
{
   int arraySecAub[NUMSEC];
   int arraySecOpp[NUMSEC];
   int secGames = getSecGames(code, auRuns, numGames, arraySecAub);
   int oppSecGames = getSecGames(code, oppRuns, numGames, arraySecOpp);
   int count;
   int extra[MAXGAMES];
 
   
   printf("       2015 AU Softball Summary\n");
   printf("                #games  Min   Mean  Max\n");
   printf("Runs scored-all    %2d    %d    %.1f    %2d\n", numGames, intMin(auRuns, numGames), intMean(auRuns, numGames), intMax(auRuns, numGames));
   printf("Runs allowed-all         %d    %.1f    %2d\n", intMin(oppRuns, numGames), intMean(oppRuns, numGames), intMax(oppRuns, numGames));
   printf("Runs scored-SEC    %2d    %d    %.1f    %2d\n", secGames, intMin(arraySecAub, secGames),intMean(arraySecAub, secGames), intMax(arraySecAub, secGames)); 
   printf("Runs allowed-SEC         %d    %.1f    %2d\n\n",  intMin(arraySecOpp, secGames),intMean(arraySecOpp, oppSecGames), intMax(arraySecOpp, oppSecGames));      
   printf("Games with extra innings:\n");
   for (count = 0; count < extraInnings(innings, numGames, extra); count++)
   {
         printf(" %d ", extra[count]);
   }
   
}
/**
 *  Function Name;
 *      intInRange()
 *      intInRange() returns true if the target is within bound1 and bound2 (inclusivity can be checked if
 *                   LOWER_INCLUSIVE or UPPER_INCLUSIVE are included in the flags argument)
 */
int intInRange(int target, int bound1, int bound2, int flags) {
    int lowerBound = intMin(bound1, bound2);
    int upperBound = intMax(bound1, bound2);
    int result = ((target > lowerBound && target < upperBound) || (target == lowerBound && (flags & LOWER_INCLUSIVE)) ||
                  (target == upperBound && (flags & UPPER_INCLUSIVE)));
/*
    if (DEBUG) {
        char *intervalChars = "([)]";
        char *booleanStrings[] = {"false", "true"};
        char openIntervalChar = intervalChars[(flags & LOWER_INCLUSIVE) != 0];
        char closeIntervalChar = intervalChars[((flags & UPPER_INCLUSIVE) != 0) + 2];
        printf("%d in %c%d %d%c : %s\n", target, openIntervalChar, lowerBound, upperBound, closeIntervalChar,
               booleanStrings[result]);
    }
*/
    return result;
}
/**
 *  Function Name:
 *      pgmDrawLine()
 *      pgmDrawLine() draws a straight line in the image by setting relavant pixels to Zero.
 *                      In this function, you have to invoke a CUDA kernel to perform all image processing on GPU.
 *
 *  @param[in,out]  pixels  holds all pixels in the pgm image, which a 2D integer array. The array
 *                          are modified after the drawing.
 *  @param[in]      numRows describes how many rows of pixels in the image.
 *  @param[in]      numCols describes how many columns of pixels in one row in the image.
 *  @param[in]      p1row specifies the row number of the start point of the line segment.
 *  @param[in]      p1col specifies the column number of the start point of the line segment.
 *  @param[in]      p2row specifies the row number of the end point of the line segment.
 *  @param[in]      p2col specifies the column number of the end point of the line segment.
 *  @param[in,out]  header returns the new header after draw.
 *                  the function might change the maximum intensity value in the image, so we
 *                  have to change the maximum intensity value in the header accordingly.
 *
 *  @return         return 1 if max intensity is changed by the drawing, otherwise return 0;
 */
int pgmDrawLine(int *pixels, int numRows, int numCols, char **header, int p1row, int p1col, int p2row, int p2col) {
    if (pixels == NULL || header == NULL)
        return 1;

    int oldMaxIntens = 0;
    int newMaxIntens = 0;
    int i = 0;
    sscanf(header[3], "%i", &oldMaxIntens);

    // avoid a divide by zero error by not calculating the slope
    if (p1col == p2col) {
        if (!intInRange(p1col, 0, numCols, UPPER_INCLUSIVE | LOWER_INCLUSIVE))
            return 0;

        int startRow = intMin(p1row, p2row);
        int endRow = intMax(p1row, p2row);
        int curRow = startRow;
        for (; curRow < endRow; ++curRow) {
            // make sure this pixel is actually within the image
            if (!intInRange(curRow, 0, numRows, UPPER_INCLUSIVE | LOWER_INCLUSIVE))
                continue;
            i = numRows * curRow + p1col;


            pixels[i] = 0;
            if (pixels[i] > newMaxIntens)
                newMaxIntens = pixels[i];
        }
    }
    else // we don't have a vertical line
    {
        int p1[2] = {0, 0};
        int p2[2] = {0, 0};

        if (p1col < p2col) {
            p1[0] = p1row;
            p1[1] = p1col;
            p2[0] = p2row;
            p2[1] = p2col;
        }
        else {
            p1[0] = p2row;
            p1[1] = p2col;
            p2[0] = p1row;
            p2[1] = p1col;
        }

        double slope = (p2[0] - p1[0]) / (p2[1] - p1[1]);
        if(DEBUG)
            printf("slope: %lf\n", slope);

        int thisCol = p1[1];
        for (; thisCol < numCols; ++thisCol) {

            int relativeCol = thisCol - p1[1];
            int thisRow = relativeCol * slope + p1[0];

            // make sure this pixel is actually within the image
            if (!intInRange(thisRow, 0, numRows - 1, UPPER_INCLUSIVE | LOWER_INCLUSIVE))
                continue;
            if (!intInRange(thisCol, 0, numCols - 1, UPPER_INCLUSIVE | LOWER_INCLUSIVE))
                continue;
            //if(DEBUG)
            //    printf("plot(%d, %d)\n", thisRow, thisCol);

            i = numRows * thisRow + thisCol;
            pixels[i] = 0;
            if (pixels[i] > newMaxIntens)
                newMaxIntens = pixels[i];

        }
    }

    sprintf(header[3], "%i", newMaxIntens);
    return (newMaxIntens == oldMaxIntens) ? 0 : 1;
}