GRASS Programmer's Manual  6.4.2(2012)
sort_cell.c
Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include <grass/gis.h>
00003 #include <grass/stats.h>
00004 
00005 static int ascending(const void *aa, const void *bb)
00006 {
00007     const DCELL *a = aa, *b = bb;
00008 
00009     if (G_is_d_null_value((DCELL *) a) && G_is_d_null_value((DCELL *) b))
00010         return 0;
00011 
00012     if (G_is_d_null_value((DCELL *) a))
00013         return 1;
00014 
00015     if (G_is_d_null_value((DCELL *) b))
00016         return -1;
00017 
00018     return (*a < *b) ? -1 : (*a > *b) ? 1 : 0;
00019 }
00020 
00021 int sort_cell(DCELL * array, int n)
00022 {
00023     int i;
00024 
00025     qsort(array, n, sizeof(DCELL), ascending);
00026 
00027     for (i = 0; i < n; i++)
00028         if (G_is_d_null_value(&array[i]))
00029             break;
00030 
00031     return i;
00032 }
00033 
00034 int sort_cell_w(DCELL(*array)[2], int n)
00035 {
00036     int i;
00037 
00038     qsort(array, n, 2 * sizeof(DCELL), ascending);
00039 
00040     for (i = 0; i < n; i++)
00041         if (G_is_d_null_value(&array[i][0]))
00042             break;
00043 
00044     return i;
00045 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines