DataSet *brute_viewshed(DataSet *terrain, GridPoint start) { static Rtimer rt; DataSet *viewshed; GridPoint p; float fNODATA, h; rt_start(rt); fNODATA = getNODATA(terrain); gpHeight(terrain, start, h); if (h == fNODATA) return NULL; viewshed = dInit(terrain->grid.nrow, terrain->grid.ncol, UCHAR); viewshed->grid.ucNODATA = 0; for (p.r = 0; p.r < viewshed->grid.nrow; p.r++) for (p.c = 0; p.c < viewshed->grid.ncol; p.c++) dSet(viewshed, p.r, p.c, visible(terrain, start, p, fNODATA)); rt_stop(rt); static char buf[256]; rt_sprint(buf, rt); printf("brute_viewshed('%s',start={r=" DGI_FMT ",c=" DGI_FMT "}):\t%s\n", terrain->path, start.r, start.c, buf); return viewshed; }
AMI_STREAM<elevation_type> * classifyNodata(AMI_STREAM<elevation_type> *elstr) { Rtimer rt; rt_start(rt); if (stats) stats->comment("finding nodata", opt->verbose); detectEdgeNodata md(nrows, ncols, nodataType::ELEVATION_NODATA); md.generateNodata(*elstr); if (stats) *stats << "nodata stream length = " << md.getNodata()->stream_len() << endl; { char * foo; md.getNodata()->name(&foo); if (stats) *stats << "nodata stream name: " << foo << endl; } rt_stop(rt); if (stats) stats->recordTime("classifyNodata::generate nodata", rt); rt_start(rt); if (stats) stats->comment("relabeling nodata", opt->verbose); md.relabelNodata(); /* re-assign labels (combine connected plateaus) */ rt_stop(rt); if (stats) stats->recordTime("classifyNodata::relabeling", rt); rt_start(rt); if (stats) stats->comment("merging relabeled grid", opt->verbose); AMI_STREAM<elevation_type> *mergeStr; mergeStr = md.merge(); rt_stop(rt); if (stats) stats->recordTime("classifyNodata::merge", rt); mergeStr->seek(0); return mergeStr; }
DataSet *brute_viewshed_terrain2(DataSet *terrain) { DataSet *vshed_cnt; Rectangle a, b; float fNODATA; const index_t nrow = terrain->grid.nrow; const index_t ncol = terrain->grid.ncol; const index_t w = 50; const index_t h = 50; static Rtimer rt; //start timing rt_start(rt); // grab NODATA value, make sure this is a valid point fNODATA = getNODATA(terrain); // initialize viewshed count grid vshed_cnt = dInit(terrain->grid.nrow, terrain->grid.ncol, UINT); assert(vshed_cnt); // step through 50x50 block in the grid, computing visibility count for (a.p.r = 0; a.p.r < nrow; a.p.r += h) { a.q.r = a.p.r + h; for (a.p.c = 0; a.p.c < ncol; a.p.c += w) { a.q.c = a.p.c + w; printf("SubGrid (" DGI_FMT "," DGI_FMT ")\n", a.p.r, a.p.c); for (b.p.r = a.p.r; b.p.r < nrow; b.p.r += h) { b.q.r = b.p.r + h; for (b.p.c = 0; b.p.c < ncol; b.p.c += w) { if (a.p.r == b.p.r && a.p.c > b.p.c) continue; b.q.c = b.p.c + w; printf(" Target (" DGI_FMT "," DGI_FMT ")\n", b.p.r, b.p.c); brute_viewshed_subterrain(terrain, a, b, fNODATA, vshed_cnt); } } } } // stop timing rt_stop(rt); static char buf[256]; rt_sprint(buf, rt); printf("brute_viewshed_terrain2('%s'):\t%s\n", terrain->path, buf); return vshed_cnt; }
/* open fill's output stream and get all info from there; delete fillStream */ AMI_STREAM<sweepItem>* fillstr2sweepstr(AMI_STREAM<waterWindowBaseType>* fillStream) { Rtimer rt; AMI_STREAM<sweepItem> *sweepstr; rt_start(rt); if (stats) stats->comment("creating sweep stream from fill output stream"); assert(fillStream->stream_len() == nrows * ncols); /* create the sweep stream */ sweepstr = new AMI_STREAM<sweepItem>(); waterWindowBaseType2sweepItem(fillStream, nrows, ncols, nodataType::ELEVATION_NODATA, sweepstr); delete fillStream; if (opt->verbose) { fprintf(stderr, "sweep stream size: %.2fMB", (double)sweepstr->stream_len()*sizeof(sweepItem)/(1<<20)); fprintf(stderr, " (%d items, item size=%d B\n ", (int)sweepstr->stream_len(), sizeof(sweepItem));; } if (stats) stats->recordLength("sweep stream", sweepstr); /* sort sweep stream by (increasing) priority */ if (opt->verbose) { fprintf(stderr, "sorting sweep stream (%.2fMB) in priority order\n", (double)sweepstr->stream_len()*sizeof(sweepItem)/(1<<20)); } if (stats) stats->comment("sorting sweep stream"); sort(&sweepstr, PrioCmpSweepItem()); rt_stop(rt); if (stats) { stats->recordTime("create sweep stream", rt); stats->recordLength("(sorted) sweep stream", sweepstr); } return sweepstr; }
DataSet *run_viewshed_terrain(DataSet *terrain, int nthread, unsigned int (*vcount) (DataSet *terrain, GridPoint p)) { static Rtimer rt; DataSet *vmap; Vector *thread_bands; ViewshedBand band; int i; float fNODATA; rt_start(rt); assert(nthread > 0); fNODATA = getNODATA(terrain); vmap = dInit(terrain->grid.nrow, terrain->grid.ncol, UINT); assert(vmap); vmap->grid.uiNODATA = 0; thread_bands = vinit2(sizeof(ViewshedBand), nthread); for (i = 0; i < nthread; i++) { band.nthread = nthread; band.index = i; band.terrain = terrain; band.vmap = vmap; band.fNODATA = fNODATA; band.vcount = vcount; vappend(thread_bands, &band); } run_threads(nthread, viewshed_terrain_sub, thread_bands); rt_stop(rt); static char buf[256]; rt_sprint(buf, rt); printf("run_viewshed_terrain('%s'):\t%s\n", terrain->path, buf); return vmap; }
DataSet *sweep_viewshed(DataSet *terrain, GridPoint start) { static Rtimer rt; DataSet *viewshed; float fNODATA, h; SweepEvent *event_list; size_t len; // start timing rt_start(rt); // grab NODATA value, make sure this is a valid point fNODATA = getNODATA(terrain); gpHeight(terrain, start, h); if (h == fNODATA) return NULL; // initialize viewshed terrain viewshed = dInit(terrain->grid.nrow, terrain->grid.ncol, UCHAR); viewshed->grid.ucNODATA = 0; // build list of start and end events build_event_list(terrain, start, fNODATA, &event_list, &len); // iterate event list, marking visible points in viewshed terrain process_event_list(terrain, start, event_list, len, viewshed); // garbage collect free(event_list); // stop timing rt_stop(rt); static char buf[256]; rt_sprint(buf, rt); printf("sweep_viewshed('%s',start={r=" DGI_FMT ",c=" DGI_FMT "}):\t%s\n", terrain->path, start.r, start.c, buf); return viewshed; }
/**************************************************************************** * Exported Functions ****************************************************************************/ uint8 ert_test_1(void) { DE_LIST deque_1 = {0}; DE_LIST deque_2 = {0}; ER_LOCATION *location_0; char *message_0; ER_OBJECT *object_0; uint8 result = ERT_SUCCESS; char string_0[80]; uint16 tag_0; RT_DATA *timestamp_0; UART_1_Start(); UART_1_PutString("\x1b\x5b\x32\x4a"); UART_1_PutString("ERROR MANAGEMENT LIBRARY TEST\r\n"); UART_1_PutString("\r\n"); UART_1_PutString("Test\tFunction\t\tResult\r\n"); UART_1_PutString("----\t--------\t\t------\r\n"); /* * Test _add_standard(). */ if (result == ERT_SUCCESS) { if (_add_standard(NULL, E00900, ER_OPTIONS_NONE, NULL, __LINE__) == ER_BAD_ARGUMENT) { UART_1_PutString(" 1\ter_add_standard()\tPASS\r\n"); } else { UART_1_PutString(" 1\ter_add_standard()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (_add_standard(NULL, E00900, ER_OPTIONS_NONE, __FILE__, __LINE__) == ER_BAD_ARGUMENT) { UART_1_PutString(" 2\ter_add_standard()\tPASS\r\n"); } else { UART_1_PutString(" 2\ter_add_standard()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (_add_standard(&deque_1, E00900, ER_OPTIONS_NONE, NULL, __LINE__) == ER_BAD_ARGUMENT) { UART_1_PutString(" 3\ter_add_standard()\tPASS\r\n"); } else { UART_1_PutString(" 3\ter_add_standard()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (_add_standard(&deque_1, E00900, ER_OPTIONS_NONE, __FILE__, __LINE__) == ER_SUCCESS) { UART_1_PutString(" 4\ter_add_standard()\tPASS\r\n"); } else { UART_1_PutString(" 4\ter_add_standard()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Initialise _add_standard() test. */ if (result == ERT_SUCCESS) { if (de_get_last_object(&deque_1, &tag_0, (void **)&object_0) == DE_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test _add_standard(). */ if (result == ERT_SUCCESS) { if (object_0->error_type == ER_STANDARD_TYPE) { UART_1_PutString(" 5\ter_add_standard()\tPASS\r\n"); } else { UART_1_PutString(" 5\ter_add_standard()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (object_0->error.number == E00900) { UART_1_PutString(" 6\ter_add_standard()\tPASS\r\n"); } else { UART_1_PutString(" 6\ter_add_standard()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (_add_standard(&deque_1, E00900, ER_OPTIONS_TIMESTAMP, __FILE__, __LINE__) == ER_FAILURE) { UART_1_PutString(" 7\ter_add_standard()\tPASS\r\n"); } else { UART_1_PutString(" 7\ter_add_standard()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Initialise _add_standard() test. */ if (result == ERT_SUCCESS) { if (rt_start() == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test _add_standard(). */ if (result == ERT_SUCCESS) { if (_add_standard(&deque_1, E00900, ER_OPTIONS_TIMESTAMP, __FILE__, __LINE__) == ER_SUCCESS) { UART_1_PutString(" 8\ter_add_standard()\tPASS\r\n"); } else { UART_1_PutString(" 8\ter_add_standard()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Initialise _add_standard() test. */ if (result == ERT_SUCCESS) { if (de_get_last_object(&deque_1, &tag_0, (void **)&object_0) == DE_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test _add_standard(). */ if (result == ERT_SUCCESS) { if (object_0->timestamp->Year == 1918) { UART_1_PutString(" 9\ter_add_standard()\tPASS\r\n"); } else { UART_1_PutString(" 9\ter_add_standard()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (_add_standard(&deque_1, E00900, ER_OPTIONS_LOCATION, __FILE__, __LINE__) == ER_SUCCESS) { UART_1_PutString(" 10\ter_add_standard()\tPASS\r\n"); } else { UART_1_PutString(" 10\ter_add_standard()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Initialise _add_standard() test. */ if (result == ERT_SUCCESS) { if (de_get_last_object(&deque_1, &tag_0, (void **)&object_0) == DE_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test _add_standard(). */ if (result == ERT_SUCCESS) { if (strcmp(object_0->location->file, ".\\error_test.c") == 0) { UART_1_PutString(" 11\ter_add_standard()\tPASS\r\n"); } else { UART_1_PutString(" 11\ter_add_standard()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (_add_standard(&deque_1, E00900, (ER_OPTIONS_TIMESTAMP | ER_OPTIONS_LOCATION), __FILE__, __LINE__) == ER_SUCCESS) { UART_1_PutString(" 12\ter_add_standard()\tPASS\r\n"); } else { UART_1_PutString(" 12\ter_add_standard()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Initialise _add_standard() test. */ if (result == ERT_SUCCESS) { if (de_get_last_object(&deque_1, &tag_0, (void **)&object_0) == DE_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test _add_standard(). */ if (result == ERT_SUCCESS) { if (object_0->timestamp->Month == 11) { UART_1_PutString(" 13\ter_add_standard()\tPASS\r\n"); } else { UART_1_PutString(" 13\ter_add_standard()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (object_0->location->line == 333) { UART_1_PutString(" 14\ter_add_standard()\tPASS\r\n"); } else { UART_1_PutString(" 14\ter_add_standard()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Initialise _add_standard() test. */ if (result == ERT_SUCCESS) { if (de_set_limit(&deque_1, 4) == DE_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test _add_standard(). */ if (result == ERT_SUCCESS) { if (_add_standard(&deque_1, E00900, (ER_OPTIONS_TIMESTAMP | ER_OPTIONS_LOCATION), __FILE__, __LINE__) == ER_FULL) { UART_1_PutString(" 15\ter_add_standard()\tPASS\r\n"); } else { UART_1_PutString(" 15\ter_add_standard()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Initialise _add_special() test. */ if (result == ERT_SUCCESS) { if (de_set_limit(&deque_1, 0) == DE_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test _add_special(). */ if (result == ERT_SUCCESS) { if (_add_special(NULL, NULL, ER_OPTIONS_NONE, NULL, __LINE__) == ER_BAD_ARGUMENT) { UART_1_PutString(" 16\ter_add_special()\tPASS\r\n"); } else { UART_1_PutString(" 16\ter_add_special()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (_add_special(NULL, NULL, ER_OPTIONS_NONE, __FILE__, __LINE__) == ER_BAD_ARGUMENT) { UART_1_PutString(" 17\ter_add_special()\tPASS\r\n"); } else { UART_1_PutString(" 17\ter_add_special()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (_add_special(NULL, "Special message.", ER_OPTIONS_NONE, NULL, __LINE__) == ER_BAD_ARGUMENT) { UART_1_PutString(" 18\ter_add_special()\tPASS\r\n"); } else { UART_1_PutString(" 18\ter_add_special()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (_add_special(NULL, "Special message.", ER_OPTIONS_NONE, __FILE__, __LINE__) == ER_BAD_ARGUMENT) { UART_1_PutString(" 19\ter_add_special()\tPASS\r\n"); } else { UART_1_PutString(" 19\ter_add_special()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (_add_special(&deque_1, NULL, ER_OPTIONS_NONE, NULL, __LINE__) == ER_BAD_ARGUMENT) { UART_1_PutString(" 20\ter_add_special()\tPASS\r\n"); } else { UART_1_PutString(" 20\ter_add_special()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (_add_special(&deque_1, NULL, ER_OPTIONS_NONE, __FILE__, __LINE__) == ER_BAD_ARGUMENT) { UART_1_PutString(" 21\ter_add_special()\tPASS\r\n"); } else { UART_1_PutString(" 21\ter_add_special()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (_add_special(&deque_1, "Special message.", ER_OPTIONS_NONE, NULL, __LINE__) == ER_BAD_ARGUMENT) { UART_1_PutString(" 22\ter_add_special()\tPASS\r\n"); } else { UART_1_PutString(" 22\ter_add_special()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (_add_special(&deque_1, "Special message.", ER_OPTIONS_NONE, __FILE__, __LINE__) == ER_SUCCESS) { UART_1_PutString(" 23\ter_add_special()\tPASS\r\n"); } else { UART_1_PutString(" 23\ter_add_special()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Initialise _add_special() test. */ if (result == ERT_SUCCESS) { if (de_get_last_object(&deque_1, &tag_0, (void **)&object_0) == DE_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test _add_special(). */ if (result == ERT_SUCCESS) { if (object_0->error_type == ER_SPECIAL_TYPE) { UART_1_PutString(" 24\ter_add_special()\tPASS\r\n"); } else { UART_1_PutString(" 24\ter_add_special()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (strcmp(object_0->error.message, "Special message.") == 0) { UART_1_PutString(" 25\ter_add_special()\tPASS\r\n"); } else { UART_1_PutString(" 25\ter_add_special()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Initialise _add_special() test. */ if (result == ERT_SUCCESS) { if (rt_stop() == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test _add_special(). */ if (result == ERT_SUCCESS) { if (_add_special(&deque_1, "Special message.", ER_OPTIONS_TIMESTAMP, __FILE__, __LINE__) == ER_FAILURE) { UART_1_PutString(" 26\ter_add_special()\tPASS\r\n"); } else { UART_1_PutString(" 26\ter_add_special()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Initialise _add_special() test. */ if (result == ERT_SUCCESS) { if (rt_start() == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test _add_special(). */ if (result == ERT_SUCCESS) { if (_add_special(&deque_1, "Special message.", ER_OPTIONS_TIMESTAMP, __FILE__, __LINE__) == ER_SUCCESS) { UART_1_PutString(" 27\ter_add_special()\tPASS\r\n"); } else { UART_1_PutString(" 27\ter_add_special()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Initialise _add_special() test. */ if (result == ERT_SUCCESS) { if (de_get_last_object(&deque_1, &tag_0, (void **)&object_0) == DE_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test _add_special(). */ if (result == ERT_SUCCESS) { if (object_0->timestamp->DayOfMonth == 11) { UART_1_PutString(" 28\ter_add_special()\tPASS\r\n"); } else { UART_1_PutString(" 28\ter_add_special()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test _add_special(). */ if (result == ERT_SUCCESS) { if (_add_special(&deque_1, "Special message.", ER_OPTIONS_LOCATION, __FILE__, __LINE__) == ER_SUCCESS) { UART_1_PutString(" 29\ter_add_special()\tPASS\r\n"); } else { UART_1_PutString(" 29\ter_add_special()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Initialise _add_special() test. */ if (result == ERT_SUCCESS) { if (de_get_last_object(&deque_1, &tag_0, (void **)&object_0) == DE_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test _add_special(). */ if (result == ERT_SUCCESS) { if (strcmp(object_0->location->file, ".\\error_test.c") == 0) { UART_1_PutString(" 30\ter_add_special()\tPASS\r\n"); } else { UART_1_PutString(" 30\ter_add_special()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (_add_special(&deque_1, "Special message.", (ER_OPTIONS_TIMESTAMP | ER_OPTIONS_LOCATION), __FILE__, __LINE__) == ER_SUCCESS) { UART_1_PutString(" 31\ter_add_special()\tPASS\r\n"); } else { UART_1_PutString(" 31\ter_add_special()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Initialise _add_special() test. */ if (result == ERT_SUCCESS) { if (de_get_last_object(&deque_1, &tag_0, (void **)&object_0) == DE_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test _add_special(). */ if (result == ERT_SUCCESS) { if (object_0->timestamp->Hour == 11) { UART_1_PutString(" 32\ter_add_special()\tPASS\r\n"); } else { UART_1_PutString(" 32\ter_add_special()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (object_0->location->line == 754) { UART_1_PutString(" 33\ter_add_special()\tPASS\r\n"); } else { UART_1_PutString(" 33\ter_add_special()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Initialise _add_special() test. */ if (result == ERT_SUCCESS) { if (de_set_limit(&deque_1, 8) == DE_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test _add_special(). */ if (result == ERT_SUCCESS) { if (_add_special(&deque_1, "Special message.", (ER_OPTIONS_TIMESTAMP | ER_OPTIONS_LOCATION), __FILE__, __LINE__) == ER_FULL) { UART_1_PutString(" 34\ter_add_special()\tPASS\r\n"); } else { UART_1_PutString(" 34\ter_add_special()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test er_get_first_object(). */ if (result == ERT_SUCCESS) { if (er_get_first_object(NULL, NULL) == ER_BAD_ARGUMENT) { UART_1_PutString(" 35\ter_get_first_object()\tPASS\r\n"); } else { UART_1_PutString(" 35\ter_get_first_object()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_first_object(NULL, &object_0) == ER_BAD_ARGUMENT) { UART_1_PutString(" 36\ter_get_first_object()\tPASS\r\n"); } else { UART_1_PutString(" 36\ter_get_first_object()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_first_object(&deque_1, NULL) == ER_BAD_ARGUMENT) { UART_1_PutString(" 37\ter_get_first_object()\tPASS\r\n"); } else { UART_1_PutString(" 37\ter_get_first_object()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_first_object(&deque_1, &object_0) == ER_SUCCESS) { UART_1_PutString(" 38\ter_get_first_object()\tPASS\r\n"); } else { UART_1_PutString(" 38\ter_get_first_object()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (object_0->error_type == ER_STANDARD_TYPE) { UART_1_PutString(" 39\ter_get_first_object()\tPASS\r\n"); } else { UART_1_PutString(" 39\ter_get_first_object()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (object_0->timestamp == NULL) { UART_1_PutString(" 40\ter_get_first_object()\tPASS\r\n"); } else { UART_1_PutString(" 40\ter_get_first_object()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (object_0->location == NULL) { UART_1_PutString(" 41\ter_get_first_object()\tPASS\r\n"); } else { UART_1_PutString(" 41\ter_get_first_object()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_first_object(&deque_2, &object_0) == ER_EMPTY) { UART_1_PutString(" 42\ter_get_first_object()\tPASS\r\n"); } else { UART_1_PutString(" 42\ter_get_first_object()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test er_get_last_object(). */ if (result == ERT_SUCCESS) { if (er_get_last_object(NULL, NULL) == ER_BAD_ARGUMENT) { UART_1_PutString(" 43\ter_get_last_object()\tPASS\r\n"); } else { UART_1_PutString(" 43\ter_get_last_object()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_last_object(NULL, &object_0) == ER_BAD_ARGUMENT) { UART_1_PutString(" 44\ter_get_last_object()\tPASS\r\n"); } else { UART_1_PutString(" 44\ter_get_last_object()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_last_object(&deque_1, NULL) == ER_BAD_ARGUMENT) { UART_1_PutString(" 45\ter_get_last_object()\tPASS\r\n"); } else { UART_1_PutString(" 45\ter_get_last_object()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_last_object(&deque_1, &object_0) == ER_SUCCESS) { UART_1_PutString(" 46\ter_get_last_object()\tPASS\r\n"); } else { UART_1_PutString(" 46\ter_get_last_object()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (object_0->error_type == ER_SPECIAL_TYPE) { UART_1_PutString(" 47\ter_get_last_object()\tPASS\r\n"); } else { UART_1_PutString(" 47\ter_get_last_object()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (object_0->timestamp != NULL) { UART_1_PutString(" 48\ter_get_last_object()\tPASS\r\n"); } else { UART_1_PutString(" 48\ter_get_last_object()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (object_0->location != NULL) { UART_1_PutString(" 49\ter_get_last_object()\tPASS\r\n"); } else { UART_1_PutString(" 49\ter_get_last_object()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_last_object(&deque_2, &object_0) == ER_EMPTY) { UART_1_PutString(" 50\ter_get_last_object()\tPASS\r\n"); } else { UART_1_PutString(" 50\ter_get_last_object()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test er_get_message(). */ if (result == ERT_SUCCESS) { if (er_get_message(NULL, NULL) == ER_BAD_ARGUMENT) { UART_1_PutString(" 51\ter_get_message()\tPASS\r\n"); } else { UART_1_PutString(" 51\ter_get_message()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_message(NULL, &message_0) == ER_BAD_ARGUMENT) { UART_1_PutString(" 52\ter_get_message()\tPASS\r\n"); } else { UART_1_PutString(" 52\ter_get_message()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_message(object_0, NULL) == ER_BAD_ARGUMENT) { UART_1_PutString(" 53\ter_get_message()\tPASS\r\n"); } else { UART_1_PutString(" 53\ter_get_message()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_message(object_0, &message_0) == ER_SUCCESS) { UART_1_PutString(" 54\ter_get_message()\tPASS\r\n"); } else { UART_1_PutString(" 54\ter_get_message()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (object_0->error_type == ER_SPECIAL_TYPE) { UART_1_PutString(" 55\ter_get_message()\tPASS\r\n"); } else { UART_1_PutString(" 55\ter_get_message()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (strcmp(message_0, "Special message.") == 0) { UART_1_PutString(" 56\ter_get_message()\tPASS\r\n"); } else { UART_1_PutString(" 56\ter_get_message()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Initialise er_get_message() test. */ if (result == ERT_SUCCESS) { if (er_get_first_object(&deque_1, &object_0) == ER_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test er_get_message(). */ if (result == ERT_SUCCESS) { if (er_get_message(object_0, &message_0) == ER_SUCCESS) { UART_1_PutString(" 57\ter_get_message()\tPASS\r\n"); } else { UART_1_PutString(" 57\ter_get_message()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (object_0->error_type == ER_STANDARD_TYPE) { UART_1_PutString(" 58\ter_get_message()\tPASS\r\n"); } else { UART_1_PutString(" 58\ter_get_message()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (strcmp(message_0, "E00900: Start of error management library error message block.") == 0) { UART_1_PutString(" 59\ter_get_message()\tPASS\r\n"); } else { UART_1_PutString(" 59\ter_get_message()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test er_remove(). */ if (result == ERT_SUCCESS) { if (er_remove(NULL) == ER_BAD_ARGUMENT) { UART_1_PutString(" 60\ter_remove()\t\tPASS\r\n"); } else { UART_1_PutString(" 60\ter_remove()\t\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_remove(&deque_1) == ER_SUCCESS) { UART_1_PutString(" 61\ter_remove()\t\tPASS\r\n"); } else { UART_1_PutString(" 61\ter_remove()\t\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (deque_1.count == 7) { UART_1_PutString(" 62\ter_remove()\t\tPASS\r\n"); } else { UART_1_PutString(" 62\ter_remove()\t\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_remove(&deque_2) == ER_EMPTY) { UART_1_PutString(" 63\ter_remove()\t\tPASS\r\n"); } else { UART_1_PutString(" 63\ter_remove()\t\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test er_get_count(). */ if (result == ERT_SUCCESS) { if (er_get_count(NULL) == 0) { UART_1_PutString(" 64\ter_get_count()\t\tPASS\r\n"); } else { UART_1_PutString(" 64\ter_get_count()\t\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_count(&deque_1) == 7) { UART_1_PutString(" 65\ter_get_count()\t\tPASS\r\n"); } else { UART_1_PutString(" 65\ter_get_count()\t\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_count(&deque_2) == 0) { UART_1_PutString(" 66\ter_get_count()\t\tPASS\r\n"); } else { UART_1_PutString(" 66\ter_get_count()\t\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test er_get_timestamp(). */ if (result == ERT_SUCCESS) { if (er_get_timestamp(NULL, NULL) == ER_BAD_ARGUMENT) { UART_1_PutString(" 67\ter_get_timestamp()\tPASS\r\n"); } else { UART_1_PutString(" 67\ter_get_timestamp()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_timestamp(NULL, ×tamp_0) == ER_BAD_ARGUMENT) { UART_1_PutString(" 68\ter_get_timestamp()\tPASS\r\n"); } else { UART_1_PutString(" 68\ter_get_timestamp()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_timestamp(object_0, NULL) == ER_BAD_ARGUMENT) { UART_1_PutString(" 69\ter_get_timestamp()\tPASS\r\n"); } else { UART_1_PutString(" 69\ter_get_timestamp()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_timestamp(object_0, ×tamp_0) == ER_SUCCESS) { UART_1_PutString(" 70\ter_get_timestamp()\tPASS\r\n"); } else { UART_1_PutString(" 70\ter_get_timestamp()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (timestamp_0 == NULL) { UART_1_PutString(" 71\ter_get_timestamp()\tPASS\r\n"); } else { UART_1_PutString(" 71\ter_get_timestamp()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test er_get_location(). */ if (result == ERT_SUCCESS) { if (er_get_location(NULL, NULL) == ER_BAD_ARGUMENT) { UART_1_PutString(" 72\ter_get_location()\tPASS\r\n"); } else { UART_1_PutString(" 72\ter_get_location()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_location(NULL, &location_0) == ER_BAD_ARGUMENT) { UART_1_PutString(" 73\ter_get_location()\tPASS\r\n"); } else { UART_1_PutString(" 73\ter_get_location()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_location(object_0, NULL) == ER_BAD_ARGUMENT) { UART_1_PutString(" 74\ter_get_location()\tPASS\r\n"); } else { UART_1_PutString(" 74\ter_get_location()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_location(object_0, &location_0) == ER_SUCCESS) { UART_1_PutString(" 75\ter_get_location()\tPASS\r\n"); } else { UART_1_PutString(" 75\ter_get_location()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (location_0 == NULL) { UART_1_PutString(" 76\ter_get_location()\tPASS\r\n"); } else { UART_1_PutString(" 76\ter_get_location()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Initialise er_convert_timestamp() test. */ if (result == ERT_SUCCESS) { if (er_get_last_object(&deque_1, &object_0) == ER_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_timestamp(object_0, ×tamp_0) == ER_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test er_convert_timestamp(). */ if (result == ERT_SUCCESS) { if (er_convert_timestamp(NULL, NULL) == ER_BAD_ARGUMENT) { UART_1_PutString(" 77\ter_convert_timestamp()\tPASS\r\n"); } else { UART_1_PutString(" 77\ter_convert_timestamp()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_convert_timestamp(NULL, string_0) == ER_BAD_ARGUMENT) { UART_1_PutString(" 78\ter_convert_timestamp()\tPASS\r\n"); } else { UART_1_PutString(" 78\ter_convert_timestamp()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_convert_timestamp(timestamp_0, NULL) == ER_BAD_ARGUMENT) { UART_1_PutString(" 79\ter_convert_timestamp()\tPASS\r\n"); } else { UART_1_PutString(" 79\ter_convert_timestamp()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test er_convert_timestamp(). */ if (result == ERT_SUCCESS) { if (er_convert_timestamp(timestamp_0, string_0) == ER_SUCCESS) { UART_1_PutString(" 80\ter_convert_timestamp()\tPASS\r\n"); } else { UART_1_PutString(" 80\ter_convert_timestamp()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (strcmp(string_0, "11/11/1918 11:00:00") == ER_SUCCESS) { UART_1_PutString(" 81\ter_convert_timestamp()\tPASS\r\n"); } else { UART_1_PutString(" 81\ter_convert_timestamp()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Initialise er_convert_location() test. */ if (result == ERT_SUCCESS) { if (er_get_location(object_0, &location_0) == ER_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test er_convert_location(). */ if (result == ERT_SUCCESS) { if (er_convert_location(NULL, NULL) == ER_BAD_ARGUMENT) { UART_1_PutString(" 82\ter_convert_location()\tPASS\r\n"); } else { UART_1_PutString(" 82\ter_convert_location()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_convert_location(NULL, string_0) == ER_BAD_ARGUMENT) { UART_1_PutString(" 83\ter_convert_location()\tPASS\r\n"); } else { UART_1_PutString(" 83\ter_convert_location()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_convert_location(location_0, NULL) == ER_BAD_ARGUMENT) { UART_1_PutString(" 84\ter_convert_location()\tPASS\r\n"); } else { UART_1_PutString(" 84\ter_convert_location()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_convert_location(location_0, string_0) == ER_SUCCESS) { UART_1_PutString(" 85\ter_convert_location()\tPASS\r\n"); } else { UART_1_PutString(" 85\ter_convert_location()\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (strcmp(string_0, "file .\\error_test.c line 754") == ER_SUCCESS) { UART_1_PutString(" 86\ter_convert_location()\tPASS\r\n"); } else { UART_1_PutString(" 86\ter_convert_location()\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test er_get_limit(). */ if (result == ERT_SUCCESS) { if (er_get_limit(NULL) == 0) { UART_1_PutString(" 87\ter_get_limit()\t\tPASS\r\n"); } else { UART_1_PutString(" 87\ter_get_limit()\t\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_get_limit(&deque_1) == 8) { UART_1_PutString(" 88\ter_get_limit()\t\tPASS\r\n"); } else { UART_1_PutString(" 88\ter_get_limit()\t\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test er_set_limit(). */ if (result == ERT_SUCCESS) { if (er_set_limit(&deque_1, 2) == ER_FAILURE) { UART_1_PutString(" 89\ter_set_limit()\t\tPASS\r\n"); } else { UART_1_PutString(" 89\ter_set_limit()\t\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_set_limit(&deque_1, 0) == ER_SUCCESS) { UART_1_PutString(" 90\ter_set_limit()\t\tPASS\r\n"); } else { UART_1_PutString(" 90\ter_set_limit()\t\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Test er_destroy(). */ if (result == ERT_SUCCESS) { if (er_destroy(NULL) == ER_BAD_ARGUMENT) { UART_1_PutString(" 91\ter_destroy()\t\tPASS\r\n"); } else { UART_1_PutString(" 91\ter_destroy()\t\tFAIL\r\n"); result = ERT_FAILURE; } } if (result == ERT_SUCCESS) { if (er_destroy(&deque_1) == ER_SUCCESS) { UART_1_PutString(" 92\ter_destroy()\t\tPASS\r\n"); } else { UART_1_PutString(" 92\ter_destroy()\t\tFAIL\r\n"); result = ERT_FAILURE; } } /* * Report test result. */ if (result == ERT_SUCCESS) { UART_1_PutString("\r\n"); UART_1_PutString("TEST PASSED\r\n"); } else { UART_1_PutString("\r\n"); UART_1_PutString("TEST FAILED\r\n"); } /* * Clean-up test. */ while ((UART_1_ReadTxStatus() & UART_1_TX_STS_FIFO_EMPTY) != UART_1_TX_STS_FIFO_EMPTY) { CyDelay(1); } UART_1_Stop(); return result; }
void ccforest<T>::findAllRoots(int depth) { if(foundAllRoots) return; foundAllRoots = 1; Rtimer rt; rt_start(rt); if(depth > 5) { cerr << "WARNING: excessive recursion in ccforest (ignored)" << endl; } int explicitRootCount = 0; assert(!superTree); superTree = new ccforest<T>(); if (stats) DEBUG_CCFOREST *stats << "sort edgeStream (by cclabel)): "; keyCmpKeyvalueType<T> fo; sort(&edgeStream, fo); /* XXX -changed this to use a cmp obj */ /* time forward processing */ EMPQueueAdaptive<cckeyvalue,T> *pq = new EMPQueueAdaptive<cckeyvalue,T>(); /* parent queue */ size_t streamLength = edgeStream->stream_len(); T prevSrc = T(-1); T parent = T(-1); ccedge prevEdge; for(unsigned int i=0; i<streamLength; i++) { ccedge *e; AMI_err ae = edgeStream->read_item(&e); assert(ae == AMI_ERROR_NO_ERROR); #if(0) if (stats) { DEBUG_CCFOREST *stats << "------------------------------" << endl; DEBUG_CCFOREST *stats << "processing edge " << *e << endl; } DEBUG_CCFOREST pq->print(); #endif if(*e == prevEdge) { if (stats) DEBUG_CCFOREST *stats << "\tduplicate " << *e << " removed\n"; continue; /* already have this done */ } prevEdge = *e; if (stats) DEBUG_CCFOREST *stats << "processing edge " << *e << endl; /* find root (assign parent) */ if(e->src() != prevSrc) { prevSrc = e->src(); cckeyvalue kv; /* check if we have a key we don't use. */ while(pq->min(kv) && (kv.getPriority() < e->src())) { pq->extract_min(kv); assert(kv.src() >= kv.dst()); removeDuplicates(kv.src(), kv.dst(), *pq); ae = rootStream->write_item(kv); /* save root */ assert(ae == AMI_ERROR_NO_ERROR); } /* try to find our root */ if(pq->min(kv) && ((e->src() == kv.getPriority()))) { pq->extract_min(kv); parent = kv.getValue(); removeDuplicates(e->src(), parent, *pq); } else { parent = e->src(); /* we are root */ explicitRootCount++; /* technically, we could skip this part. the lookup function automatically assumes that values without parents are roots */ } /* save result */ cckeyvalue kroot(e->src(), parent); assert(kroot.src() >= kroot.dst()); ae = rootStream->write_item(kroot); assert(ae == AMI_ERROR_NO_ERROR); } #ifndef NDEBUG cckeyvalue kv2; assert(pq->is_empty() || (pq->min(kv2) && kv2.getPriority() > e->src())); #endif /* insert */ cckeyvalue kv(e->dst(), parent); assert(kv.src() >= kv.dst()); pq->insert(kv); /* cout << "identified: " << kroot << endl; */ } /* drain the priority queue */ if (stats) DEBUG_CCFOREST *stats << "draining priority queue" << endl; while (!pq->is_empty()) { cckeyvalue kv; pq->extract_min(kv); assert(kv.src() >= kv.dst()); if (stats) DEBUG_CCFOREST *stats << "processing edge " << kv << endl; removeDuplicates(kv.src(), kv.dst(), *pq); AMI_err ae = rootStream->write_item(kv); assert(ae == AMI_ERROR_NO_ERROR); } delete pq; /* note that rootStream is naturally ordered by src */ if(superTree->size()) { if (stats) { DEBUG_CCFOREST *stats << "resolving cycles..." << endl; /* printStream(rootStream); */ DEBUG_CCFOREST *stats << "sort rootStream: "; } AMI_STREAM<cckeyvalue> *sortedRootStream; dstCmpKeyvalueType<T> dstfo; sortedRootStream = sort(rootStream, dstfo); /* XXX replaced this to use a cmp object -- laura AMI_STREAM<cckeyvalue>*sortedRootStream=new AMI_STREAM<cckeyvalue>(); AMI_err ae = AMI_sort(rootStream, sortedRootStream, valueCmp); assert(ae == AMI_ERROR_NO_ERROR); */ delete rootStream; cckeyvalue *kv; T parent; AMI_err ae; AMI_STREAM<cckeyvalue>* relabeledRootStream = new AMI_STREAM<cckeyvalue>(); ae = sortedRootStream->seek(0); superTree->findAllRoots(depth+1); while((ae = sortedRootStream->read_item(&kv)) == AMI_ERROR_NO_ERROR) { parent = superTree->findNextRoot(kv->dst()); ae = relabeledRootStream->write_item(cckeyvalue(kv->src(), parent)); assert(ae == AMI_ERROR_NO_ERROR); } delete sortedRootStream; if (stats) DEBUG_CCFOREST *stats << "sort relabeledRootStream: "; rootStream = sort(relabeledRootStream, fo); /* laura: changed this rootStream = new AMI_STREAM<cckeyvalue>(); ae = AMI_sort(relabeledRootStream, rootStream); assert(ae == AMI_ERROR_NO_ERROR); */ delete relabeledRootStream; if (stats) DEBUG_CCFOREST *stats << "resolving cycles... done." << endl; } rootStream->seek(0); if (stats){ DEBUG_CCFOREST *stats << "Rootstream length=" << rootStream->stream_len() << endl; DEBUG_CCFOREST printStream(*stats, rootStream); DEBUG_CCFOREST *stats << "Explicit root count=" << explicitRootCount << endl; } rt_stop(rt); if (stats) stats->recordTime("ccforest::findAllRoots", (long int)rt_seconds(rt)); }
/* deletes fillStream */ void computeFlowAccumulation(AMI_STREAM<waterWindowBaseType>* fillStream, AMI_STREAM<sweepOutput> *& outstr) { Rtimer rt, rtTotal; AMI_STREAM<sweepItem> *sweepstr; rt_start(rtTotal); assert(fillStream && outstr == NULL); if (stats) { stats->comment("------------------------------"); stats->comment("COMPUTING FLOW ACCUMULATION"); } { /* timestamp stats file and print memory */ time_t t = time(NULL); char buf[BUFSIZ]; if(t == (time_t)-1) { perror("time"); exit(1); } #ifdef __MINGW32__ strcpy(buf, ctime(&t)); #else ctime_r(&t, buf); buf[24] = '\0'; #endif if (stats) { stats->timestamp(buf); *stats << endl; } size_t mm_size = (opt->mem << 20); /* (in bytes) */ formatNumber(buf, mm_size); if (stats) *stats << "memory size: " << buf << " bytes\n"; } /* create sweepstream using info from fillStream */ sweepstr = fillstr2sweepstr(fillStream); /* fillStream is deleted inside fillstr2sweepstr */ /* sweep and dump outputs into outStream; trustdir=1 */ outstr = sweep(sweepstr, opt->d8cut, 1); assert(outstr->stream_len() == sweepstr->stream_len()); delete sweepstr; /* sort output stream into a grid */ rt_start(rt); if (stats) { stats->comment( "sorting sweep output stream"); stats->recordLength("output stream", outstr); } sort(&outstr, ijCmpSweepOutput()); rt_stop(rt); if (stats) { stats->recordLength("output stream", outstr); stats->recordTime("sorting output stream", rt); } rt_stop(rtTotal); if (stats) stats->recordTime("compute flow accumulation", rtTotal); #ifdef SAVE_ASCII printStream2Grid(outstr, nrows, ncols, "flowaccumulation.asc", printAccumulationAscii()); printStream2Grid(outstr, nrows, ncols, "tci.asc", printTciAscii()); #endif return; }
/* ingrid is the input grid that contains the header and data. outgrid is the ouutput grid, it has a valid header and data is allocated but has no values yet. the eventlist contains all events for any viewpoint. */ void compute_multiviewshed_radial(MultiviewOptions opt, int DO_EVERY, Grid* ingrid, Grid* outgrid, int nevents, Event* eventlist) { assert(ingrid && outgrid && eventlist); printf("\n----------------------------------------\n"); printf("Starting radial sweep, total %d viewpoints.\n", opt.NVIEWSHEDS); int nvis, nviewsheds=0; Rtimer sweepTotalTime; int nrows, ncols, row, col; Viewpoint vp; /* get raster rows and cols */ nrows = ingrid->hd->nrows; ncols = ingrid->hd->ncols; /* ************************************************************ */ //compute just one viewshed if (opt.NVIEWSHEDS == 1) { rt_start(sweepTotalTime); //compute just one viewshed count set_viewpoint(&vp, opt.vr, opt.vc, get(ingrid, opt.vr, opt.vc)); if (is_nodata_at(ingrid, opt.vr, opt.vc)) printf("point at (%5d,%5d): NODATA\n",opt.vr, opt.vc); else { /*set the angles for all the events in the eventlist*/ set_event_list_angles_and_dist(nevents, eventlist, &vp); /*sort the eventlist*/ #ifdef SYSTEM_SORT qsort(eventlist, nevents, sizeof(Event), compare_events_angle); #else event_quicksort_radial(eventlist, nevents); #endif /*compute the visibility of the viewpoint */ nvis = sweep_radial(eventlist,nevents, ingrid->grid_data[opt.vr], vp,ingrid); rt_stop(sweepTotalTime); printf("v=(%5d,%5d): nvis=%10d\n", opt.vr, opt.vc, nvis); fflush(stdout); printf("TOTAL time: \n"); char timeused[100]; rt_sprint_safe_average(timeused, sweepTotalTime, 1); printf("%20s: %s\n", "total", timeused); } return; } /* ************************************************************ */ //else compute VC for many/all viewpoints rt_start(sweepTotalTime); for(row = 0; row < nrows; row++) { for (col = 0; col < ncols; col++) { if (((row*ncols)+col) % DO_EVERY !=0){ /* do not compute the viewshed of this point: set this point in the output as NODATA */ set_nodata(outgrid, row, col); continue; } /*check if this point is nodata. If it is, write it as such in output raster and continue*/ if (is_nodata_at(ingrid, row, col)) { set_nodata(outgrid, row, col); if (opt.NVIEWSHEDS < 10) //don't print unless very few viewsheds printf("point at (%5d,%5d): NODATA; ignoring\n",row, col); fflush(stdout); continue; } /* compute the viewshed of this point */ nviewsheds++; /* print progress to the user: one dot per viewshed computed*/ //printf("."); fflush(stdout); //printf("point at (%5d,%5d): ",row, col); fflush(stdout); /*set the viewpoint to be this point */ float crt_elev = get(ingrid, row, col); set_viewpoint(&vp, row, col, crt_elev); /*set the angles for all the events in the eventlist*/ set_event_list_angles_and_dist(nevents, eventlist, &vp); /*sort the eventlist*/ /* note: this should be done with an optimized quicksort */ qsort(eventlist, nevents, sizeof(Event), compare_events_angle); /*compute the visibility of the viewpoint */ nvis = sweep_radial(eventlist,nevents, ingrid->grid_data[row],vp,ingrid); /* write nvis to the output raster */ set(outgrid, row, col, nvis); #ifdef INTERPOLATE_RESULT //insert this poitn in the array of computed viewsheds Nvis x = {row,col,nvis}; viewsheds[nvp] = x; nvp++; #endif //print this point if (opt.verbose) printf("v=(%5d,%5d): nvis=%10d\n", row, col, nvis); } /* for col */ } /* for row */ rt_stop(sweepTotalTime); printf("\ndone.\n"); printf("----------------------------------------\n"); printf("RADIAL sweep:\n"); printf("total nviewsheds=%d\n", nviewsheds); if (nviewsheds==0) { printf("%20s: 0\n", "total"); } else { char timeused[100]; rt_sprint_safe_average(timeused, sweepTotalTime, nviewsheds); printf("AVERAGE viewshed time per viewpoint: \n"); printf("%20s: %s\n", "total", timeused); printf("TOTAL time: \n"); rt_sprint_safe_average(timeused, sweepTotalTime, 1); printf("%20s: %s\n", "total", timeused); } return; }
/* ************************************************************ */ void compute_multiviewshed_distribution(MultiviewOptions opt, int DO_EVERY, Grid* ingrid, Grid* outgrid, int nevents, Event* eventlist) { assert(ingrid && outgrid && eventlist); printf("\n----------------------------------------\n"); printf("Starting distribute sweep"); printf("total %d viewpoints, BASECASE_THRESHOLD=%d NUM_SECTORS=%d\n", opt.NVIEWSHEDS, opt.BASECASE_THRESHOLD,opt.NUM_SECTORS); Viewpoint vp; int nvis; int dropped, total_dropped=0; /* dropped cells during distribution */ int nviewsheds = 0; Rtimer sweepTotalTime; int nrows, ncols, row, col; /* get raster rows and cols */ nrows = ingrid->hd->nrows; ncols = ingrid->hd->ncols; /* ************************************************************ */ //compute just one viewshed if (opt.NVIEWSHEDS == 1) { rt_start(sweepTotalTime); //compute just one viewshed count set_viewpoint(&vp, opt.vr, opt.vc, get(ingrid, opt.vr, opt.vc)); if (is_nodata_at(ingrid, opt.vr, opt.vc)) printf("point at (%5d,%5d): NODATA\n",opt.vr, opt.vc); else { /*set the viewpoint to be this point */ float crt_elev = get(ingrid, opt.vr, opt.vc); set_viewpoint(&vp, opt.vr, opt.vc, crt_elev); /*set the angles for all the events in the eventlist*/ set_event_list_angles_and_dist(nevents, eventlist, &vp); /*sort the eventlist*/ #ifdef SYSTEM_SORT qsort(eventlist, nevents, sizeof(Event), compare_events_angle); #else event_quicksort_radial(eventlist, nevents); #endif /*compute the visibility of the viewpoint */ dropped = 0; nvis = distribute_and_sweep(eventlist, nevents, opt.NUM_SECTORS, opt.BASECASE_THRESHOLD, &vp, &dropped); /* update total number of drpped cells */ total_dropped += dropped; /* write nvis to output raster */ set(outgrid, opt.vr, opt.vc, nvis); rt_stop(sweepTotalTime); printf("v=(%5d,%5d): nvis=%10d\n", opt.vr, opt.vc, nvis); fflush(stdout); printf("cells dropped = %d\n", total_dropped); char timeused[100]; printf("TOTAL time: \n"); rt_sprint_safe_average(timeused, sweepTotalTime, 1); printf("%20s: %s\n", "total", timeused); } return; } /* ************************************************************ */ //else compute VC for many/all viewpoints for(row = 0; row < nrows; row++) { for(col = 0; col < ncols; col++) { if(((row*ncols)+col) % DO_EVERY != 0){ /* do not compute the viewshed of this point: set this point in the output as NODATA */ set_nodata(outgrid, row, col); continue; } /* check if this point is nodata. If it is, write it as such in output raster and continue*/ if (is_nodata_at(ingrid, row, col)) { set_nodata(outgrid, row, col); if (opt.NVIEWSHEDS < 10) //don't print unless very few viewsheds printf("point at (%5d,%5d): NODATA; ignoring\n",row, col); fflush(stdout); continue; } /* compute the viewshed of this point */ nviewsheds++; /* print progress to user, one dot per viewpoint */ //printf("."); fflush(stdout); /*set the viewpoint to be this point */ float crt_elev = get(ingrid, row, col); set_viewpoint(&vp, row, col, crt_elev); /*set the angles for all the events in the eventlist*/ set_event_list_angles_and_dist(nevents, eventlist, &vp); /*sort the eventList by distance */ //printf("\nsorting concentrically.."); fflush(stdout); #ifdef SYSTEM_SORT qsort(eventlist, nevents, sizeof(Event), compare_events_dist); #else event_quicksort_distance(eventlist, nevents); #endif /*distribute and sweep */ dropped = 0; nvis = distribute_and_sweep(eventlist, nevents, opt.NUM_SECTORS, opt.BASECASE_THRESHOLD, &vp, &dropped); /* update total number of drpped cells */ total_dropped += dropped; /* write nvis to output raster */ set(outgrid, row, col, nvis); #ifdef INTERPOLATE_RESULT //insert this poitn in the array of computed viewsheds Nvis x = {row,col,nvis}; viewsheds[nvp] = x; nvp++; #endif // print this point if (opt.verbose) { printf("point at (%5d,%5d): ",row, col); fflush(stdout); printf("nvis=%10d, dropped=%10d\n", nvis, dropped); fflush(stdout); } } /* for col */ } /* for row */ rt_stop(sweepTotalTime); printf("\ndone."); printf("DISTRIBUTION SWEEP: BASECASE_THRESHOLD=%d NUM_SECTORS=%d\n", opt.BASECASE_THRESHOLD,opt.NUM_SECTORS); printf("total nviewsheds=%d\n", nviewsheds); if (nviewsheds==0) { printf("%20s: 0\n", "total"); } else { float avg_dropped; avg_dropped = (float)total_dropped / (float)nviewsheds; printf("average nb. cells dropped = %f (%.2f %%)\n", avg_dropped, avg_dropped/(float)nevents * 100); char timeused[100]; rt_sprint_safe_average(timeused, sweepTotalTime, nviewsheds); printf("AVERAGE TIME PER VIEWPOINT: \n"); printf("\t%20s: %s\n", "viewshed average total", timeused); printf("TOTAL time: \n"); rt_sprint_safe_average(timeused, sweepTotalTime, 1); printf("%20s: %s\n", "total", timeused); } return; }
int main(int argc, char* argv[]) { //this variable collects all user options MultiviewOptions options; parse_args(argc, argv, &options); record_args(options); #ifdef INTERPOLATE_RESULT viewsheds = (Nvis*) malloc((options->NVIEWSHEDS+10)*sizeof(Nvis)); assert(viewsheds); #endif //read input raster printf("reading input grid %s ", options.input_name); Grid *ingrid = read_grid_from_arcascii_file(options.input_name); assert(ingrid); printf("..done\n"); //number of rows and columns in the grid int nrows, ncols; nrows = ingrid->hd->nrows; ncols = ingrid->hd->ncols; printf("grid: rows = %d, cols = %d\n", nrows, ncols); if (options.NVIEWSHEDS ==0) options.NVIEWSHEDS = nrows * ncols; //create an output grid Grid* outgrid = create_empty_grid(); assert(outgrid); //outgrid->hd = create_empty_header(); //the header is allocated in create_empty_grid() copy_header(outgrid->hd, *(ingrid->hd)); alloc_grid_data(outgrid); /* **************************************** */ /* INITIALIZE EVENT LIST */ /* **************************************** */ /*allocate the eventlist to hold the maximum number of events possible*/ Event* eventList; eventList = (Event*) malloc(ncols * nrows * 3 * sizeof(Event)); assert(eventList); /*initialize the eventList with the info common to all viewpoints */ long nevents; Rtimer initTime; rt_start(initTime); nevents = init_event_list(eventList, ingrid ); printf("nb events = %ld\n", nevents); rt_stop(initTime); print_init_timings(initTime); /* ****************************** */ /* compute the viewshed of the i % DO_EVERY point */ /* ****************************** */ assert(options.NVIEWSHEDS > 0); int DO_EVERY = nrows * ncols/ options.NVIEWSHEDS; /* start going through the data and considering each point, in turn, as a viewshed */ if (options.SWEEP_MODE == SWEEP_DISTRIBUTE) { assert(options.BASECASE_THRESHOLD >0 && options.NUM_SECTORS >0); compute_multiviewshed_distribution(options, DO_EVERY, ingrid, outgrid, nevents, eventList); } else { compute_multiviewshed_radial(options, DO_EVERY, ingrid, outgrid, nevents, eventList); } /* ****************************** */ /*all sweeping and computing done - clean up */ free(eventList); //write output grid to file save_grid_to_arcascii_file(outgrid, options.output_name); //clean up destroy_grid(ingrid); destroy_grid(outgrid); #ifdef INTERPOLATE_RESULT //for NVIEWSHEDS small, the resulting map is basically all empty; //the interpolate function extends each non-empty output viewshed //value to a ball centered at that point interpolate_raster(outgrid, output_name); #endif exit(0); }
int main(int argc, char *argv[]) { int rc = -1, n, priority; const char *importer, *scanner, *geo; char *endptr; size_t nctl; double speed; struct timecode_def *timecode; bool protect, use_mlock, phono; struct controller ctl[2]; struct rt rt; struct library library; #if defined WITH_OSS || WITH_ALSA int rate; #endif #ifdef WITH_OSS int oss_buffers, oss_fragment; #endif #ifdef WITH_ALSA int alsa_buffer; #endif fprintf(stderr, "%s\n\n" NOTICE "\n\n", banner); if (thread_global_init() == -1) return -1; if (rig_init() == -1) return -1; rt_init(&rt); library_init(&library); ndeck = 0; geo = ""; nctl = 0; priority = DEFAULT_PRIORITY; importer = DEFAULT_IMPORTER; scanner = DEFAULT_SCANNER; timecode = NULL; speed = 1.0; protect = false; phono = false; use_mlock = false; #if defined WITH_OSS || WITH_ALSA rate = DEFAULT_RATE; #endif #ifdef WITH_ALSA alsa_buffer = DEFAULT_ALSA_BUFFER; #endif #ifdef WITH_OSS oss_fragment = DEFAULT_OSS_FRAGMENT; oss_buffers = DEFAULT_OSS_BUFFERS; #endif /* Skip over command name */ argv++; argc--; while (argc > 0) { if (!strcmp(argv[0], "-h")) { usage(stdout); return 0; #ifdef WITH_OSS } else if (!strcmp(argv[0], "-f")) { /* Set fragment size for subsequent devices */ if (argc < 2) { fprintf(stderr, "-f requires an integer argument.\n"); return -1; } oss_fragment = strtol(argv[1], &endptr, 10); if (*endptr != '\0') { fprintf(stderr, "-f requires an integer argument.\n"); return -1; } /* Fragment sizes greater than the default aren't useful * as they are dependent on DEVICE_FRAME */ if (oss_fragment < DEFAULT_OSS_FRAGMENT) { fprintf(stderr, "Fragment size must be %d or more; aborting.\n", DEFAULT_OSS_FRAGMENT); return -1; } argv += 2; argc -= 2; } else if (!strcmp(argv[0], "-b")) { /* Set number of buffers for subsequent devices */ if (argc < 2) { fprintf(stderr, "-b requires an integer argument.\n"); return -1; } oss_buffers = strtol(argv[1], &endptr, 10); if (*endptr != '\0') { fprintf(stderr, "-b requires an integer argument.\n"); return -1; } argv += 2; argc -= 2; #endif #if defined WITH_OSS || WITH_ALSA } else if (!strcmp(argv[0], "-r")) { /* Set sample rate for subsequence devices */ if (argc < 2) { fprintf(stderr, "-r requires an integer argument.\n"); return -1; } rate = strtol(argv[1], &endptr, 10); if (*endptr != '\0') { fprintf(stderr, "-r requires an integer argument.\n"); return -1; } argv += 2; argc -= 2; #endif #ifdef WITH_ALSA } else if (!strcmp(argv[0], "-m")) { /* Set size of ALSA buffer for subsequence devices */ if (argc < 2) { fprintf(stderr, "-m requires an integer argument.\n"); return -1; } alsa_buffer = strtol(argv[1], &endptr, 10); if (*endptr != '\0') { fprintf(stderr, "-m requires an integer argument.\n"); return -1; } argv += 2; argc -= 2; #endif } else if (!strcmp(argv[0], "-d") || !strcmp(argv[0], "-a") || !strcmp(argv[0], "-j")) { int r; unsigned int sample_rate; struct deck *ld; struct device *device; struct timecoder *timecoder; /* Create a deck */ if (argc < 2) { fprintf(stderr, "-%c requires a device name as an argument.\n", argv[0][1]); return -1; } if (ndeck == ARRAY_SIZE(deck)) { fprintf(stderr, "Too many decks; aborting.\n"); return -1; } fprintf(stderr, "Initialising deck %zd (%s)...\n", ndeck, argv[1]); ld = &deck[ndeck]; device = &ld->device; timecoder = &ld->timecoder; ld->importer = importer; ld->protect = protect; /* Work out which device type we are using, and initialise * an appropriate device. */ switch(argv[0][1]) { #ifdef WITH_OSS case 'd': r = oss_init(device, argv[1], rate, oss_buffers, oss_fragment); break; #endif #ifdef WITH_ALSA case 'a': r = alsa_init(device, argv[1], rate, alsa_buffer); break; #endif #ifdef WITH_JACK case 'j': r = jack_init(device, argv[1]); break; #endif default: fprintf(stderr, "Device type is not supported by this " "distribution of xwax.\n"); return -1; } if (r == -1) return -1; sample_rate = device_sample_rate(device); /* Default timecode decoder where none is specified */ if (timecode == NULL) { timecode = timecoder_find_definition(DEFAULT_TIMECODE); assert(timecode != NULL); } timecoder_init(timecoder, timecode, speed, sample_rate, phono); /* Connect up the elements to make an operational deck */ r = deck_init(ld, &rt, ndeck); if (r == -1) return -1; /* Connect this deck to available controllers */ for (n = 0; n < nctl; n++) controller_add_deck(&ctl[n], &deck[ndeck]); /* Connect this deck to OSC server */ osc_add_deck(); ndeck++; argv += 2; argc -= 2; } else if (!strcmp(argv[0], "-t")) { /* Set the timecode definition to use */ if (argc < 2) { fprintf(stderr, "-t requires a name as an argument.\n"); return -1; } timecode = timecoder_find_definition(argv[1]); if (timecode == NULL) { fprintf(stderr, "Timecode '%s' is not known.\n", argv[1]); return -1; } argv += 2; argc -= 2; } else if (!strcmp(argv[0], "-33")) { speed = 1.0; argv++; argc--; } else if (!strcmp(argv[0], "-45")) { speed = 1.35; argv++; argc--; } else if (!strcmp(argv[0], "-c")) { protect = true; argv++; argc--; } else if (!strcmp(argv[0], "-u")) { protect = false; argv++; argc--; } else if (!strcmp(argv[0], "--line")) { phono = false; argv++; argc--; } else if (!strcmp(argv[0], "--phono")) { phono = true; argv++; argc--; } else if (!strcmp(argv[0], "-k")) { use_mlock = true; track_use_mlock(); argv++; argc--; } else if (!strcmp(argv[0], "-q")) { if (argc < 2) { fprintf(stderr, "-q requires an integer argument.\n"); return -1; } priority = strtol(argv[1], &endptr, 10); if (*endptr != '\0') { fprintf(stderr, "-q requires an integer argument.\n"); return -1; } if (priority < 0) { fprintf(stderr, "Priority (%d) must be zero or positive.\n", priority); return -1; } argv += 2; argc -= 2; } else if (!strcmp(argv[0], "-g")) { if (argc < 2) { fprintf(stderr, "-g requires an argument.\n"); return -1; } geo = argv[1]; argv += 2; argc -= 2; } else if (!strcmp(argv[0], "-i")) { /* Importer script for subsequent decks */ if (argc < 2) { fprintf(stderr, "-i requires an executable path " "as an argument.\n"); return -1; } importer = argv[1]; argv += 2; argc -= 2; } else if (!strcmp(argv[0], "-s")) { /* Scan script for subsequent libraries */ if (argc < 2) { fprintf(stderr, "-s requires an executable path " "as an argument.\n"); return -1; } scanner = argv[1]; argv += 2; argc -= 2; } else if (!strcmp(argv[0], "-l")) { /* Load in a music library */ if (argc < 2) { fprintf(stderr, "-%c requires a pathname as an argument.\n", argv[0][1]); return -1; } if (library_import(&library, scanner, argv[1]) == -1) return -1; argv += 2; argc -= 2; #ifdef WITH_ALSA } else if (!strcmp(argv[0], "--dicer")) { struct controller *c; if (nctl == sizeof ctl) { fprintf(stderr, "Too many controllers; aborting.\n"); return -1; } c = &ctl[nctl]; if (argc < 2) { fprintf(stderr, "Dicer requires an ALSA device name.\n"); return -1; } if (dicer_init(c, &rt, argv[1]) == -1) return -1; nctl++; argv += 2; argc -= 2; #endif } else { fprintf(stderr, "'%s' argument is unknown; try -h.\n", argv[0]); return -1; } } #ifdef WITH_ALSA alsa_clear_config_cache(); #endif if (ndeck == 0) { fprintf(stderr, "You need to give at least one audio device to use " "as a deck; try -h.\n"); return -1; } rc = EXIT_FAILURE; /* until clean exit */ if (osc_start((struct deck *)&deck, &library) == -1) return -1; osc_start_updater_thread(); /* Order is important: launch realtime thread first, then mlock. * Don't mlock the interface, use sparingly for audio threads */ if (rt_start(&rt, priority) == -1) return -1; if (use_mlock && mlockall(MCL_CURRENT) == -1) { perror("mlockall"); goto out_rt; } if (interface_start(&library, geo) == -1) goto out_rt; if (rig_main() == -1) goto out_interface; rc = EXIT_SUCCESS; fprintf(stderr, "Exiting cleanly...\n"); out_interface: interface_stop(); out_rt: rt_stop(&rt); for (n = 0; n < ndeck; n++) deck_clear(&deck[n]); for (n = 0; n < nctl; n++) controller_clear(&ctl[n]); timecoder_free_lookup(); library_clear(&library); rt_clear(&rt); rig_clear(); osc_stop(); thread_global_clear(); if (rc == EXIT_SUCCESS) fprintf(stderr, "Done.\n"); return rc; }
/**************************************************************************** * Exported Functions ****************************************************************************/ uint8 rtt_test_1(void) { RT_DATA data_0; uint8 result = RTT_SUCCESS; char string[20] = {0}; UART_1_Start(); UART_1_PutString("\x1b\x5b\x32\x4a"); UART_1_PutString("REAL-TIME CLOCK LIBRARY TEST\r\n"); UART_1_PutString("\r\n"); UART_1_PutString("Test\tFunction\t\tResult\r\n"); UART_1_PutString("----\t--------\t\t------\r\n"); /* * Test rt_set_date(). */ if (result == RTT_SUCCESS) { if (rt_set_date(27, 8, 2013) == RT_FAILURE) { UART_1_PutString(" 1\trt_set_date()\t\tPASS\r\n"); } else { UART_1_PutString(" 1\trt_set_date()\t\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Initialise rt_set_date() test. */ if (result == RTT_SUCCESS) { if (rt_start() == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Test rt_set_date(). */ if (result == RTT_SUCCESS) { if (rt_set_date(27, 8, 0) == RT_BAD_ARGUMENT) { UART_1_PutString(" 2\trt_set_date()\t\tPASS\r\n"); } else { UART_1_PutString(" 2\trt_set_date()\t\tFAIL\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (rt_set_date(27, 0, 2013) == RT_BAD_ARGUMENT) { UART_1_PutString(" 3\trt_set_date()\t\tPASS\r\n"); } else { UART_1_PutString(" 3\trt_set_date()\t\tFAIL\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (rt_set_date(0, 8, 2013) == RT_BAD_ARGUMENT) { UART_1_PutString(" 4\trt_set_date()\t\tPASS\r\n"); } else { UART_1_PutString(" 4\trt_set_date()\t\tFAIL\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (rt_set_date(27, 8, 2013) == RT_SUCCESS) { UART_1_PutString(" 5\trt_set_date()\t\tPASS\r\n"); } else { UART_1_PutString(" 5\trt_set_date()\t\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Initialise rt_set_time() test. */ if (result == RTT_SUCCESS) { if (rt_stop() == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Test rt_set_time(). */ if (result == RTT_SUCCESS) { if (rt_set_time(8, 24, 44) == RT_FAILURE) { UART_1_PutString(" 6\trt_set_time()\t\tPASS\r\n"); } else { UART_1_PutString(" 6\trt_set_time()\t\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Initialise rt_set_time() test. */ if (result == RTT_SUCCESS) { if (rt_start() == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Test rt_set_time(). */ if (result == RTT_SUCCESS) { if (rt_set_time(8, 24, 255) == RT_BAD_ARGUMENT) { UART_1_PutString(" 7\trt_set_time()\t\tPASS\r\n"); } else { UART_1_PutString(" 7\trt_set_time()\t\tFAIL\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (rt_set_time(8, 255, 44) == RT_BAD_ARGUMENT) { UART_1_PutString(" 8\trt_set_time()\t\tPASS\r\n"); } else { UART_1_PutString(" 8\trt_set_time()\t\tFAIL\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (rt_set_time(255, 24, 44) == RT_BAD_ARGUMENT) { UART_1_PutString(" 9\trt_set_time()\t\tPASS\r\n"); } else { UART_1_PutString(" 9\trt_set_time()\t\tFAIL\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (rt_set_time(8, 24, 44) == RT_SUCCESS) { UART_1_PutString(" 10\trt_set_time()\t\tPASS\r\n"); } else { UART_1_PutString(" 10\trt_set_time()\t\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Initialise rt_write() test. */ if (result == RTT_SUCCESS) { if (rt_stop() == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Test rt_write(). */ if (result == RTT_SUCCESS) { if (rt_write() == RT_FAILURE) { UART_1_PutString(" 11\trt_write()\t\tPASS\r\n"); } else { UART_1_PutString(" 11\trt_write()\t\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Initialise rt_write() test. */ if (result == RTT_SUCCESS) { if (rt_start() == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Test rt_write(). */ if (result == RTT_SUCCESS) { if (rt_write() == RT_SUCCESS) { UART_1_PutString(" 12\trt_write()\t\tPASS\r\n"); } else { UART_1_PutString(" 12\trt_write()\t\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Initialise rt_read() test. */ if (result == RTT_SUCCESS) { if (rt_stop() == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Test rt_read(). */ if (result == RTT_SUCCESS) { if (rt_read(&data_0) == RT_FAILURE) { UART_1_PutString(" 13\trt_read()\t\tPASS\r\n"); } else { UART_1_PutString(" 13\trt_read()\t\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Initialise rt_read() test. */ if (result == RTT_SUCCESS) { if (rt_start() == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Test rt_read(). */ if (result == RTT_SUCCESS) { if (rt_read(NULL) == RT_BAD_ARGUMENT) { UART_1_PutString(" 14\trt_read()\t\tPASS\r\n"); } else { UART_1_PutString(" 14\trt_read()\t\tFAIL\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (rt_read(&data_0) == RT_SUCCESS) { UART_1_PutString(" 15\trt_read()\t\tPASS\r\n"); } else { UART_1_PutString(" 15\trt_read()\t\tFAIL\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (data_0.Year == 1918) { UART_1_PutString(" 16\trt_read()\t\tPASS\r\n"); } else { UART_1_PutString(" 16\trt_read()\t\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Test rt_convert(). */ if (result == RTT_SUCCESS) { if (rt_convert(NULL, NULL) == RT_BAD_ARGUMENT) { UART_1_PutString(" 17\trt_convert()\t\tPASS\r\n"); } else { UART_1_PutString(" 17\trt_convert()\t\tFAIL\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (rt_convert(NULL, string) == RT_BAD_ARGUMENT) { UART_1_PutString(" 18\trt_convert()\t\tPASS\r\n"); } else { UART_1_PutString(" 18\trt_convert()\t\tFAIL\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (rt_convert(&data_0, NULL) == RT_BAD_ARGUMENT) { UART_1_PutString(" 19\trt_convert()\t\tPASS\r\n"); } else { UART_1_PutString(" 19\trt_convert()\t\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Initialise rt_convert() test. */ if (result == RTT_SUCCESS) { if (rt_set_date(1, 2, 2013) == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (rt_set_time(3, 4, 5) == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (rt_write() == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (rt_read(&data_0) == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Test rt_convert(). */ if (result == RTT_SUCCESS) { if (rt_convert(&data_0, string) == RT_SUCCESS) { UART_1_PutString(" 20\trt_convert()\t\tPASS\r\n"); } else { UART_1_PutString(" 20\trt_convert()\t\tFAIL\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (strcmp(string, "01/02/2013 03:04:05") == 0) { UART_1_PutString(" 21\trt_convert()\t\tPASS\r\n"); } else { UART_1_PutString(" 21\trt_convert()\t\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Initialise rt_convert() test. */ if (result == RTT_SUCCESS) { if (rt_set_date(11, 12, 2013) == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (rt_set_time(12, 13, 14) == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (rt_write() == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (rt_read(&data_0) == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Test rt_convert(). */ if (result == RTT_SUCCESS) { if (rt_convert(&data_0, string) == RT_SUCCESS) { UART_1_PutString(" 22\trt_convert()\t\tPASS\r\n"); } else { UART_1_PutString(" 22\trt_convert()\t\tPASS\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (strcmp(string, "11/12/2013 12:13:14") == 0) { UART_1_PutString(" 23\trt_convert()\t\tPASS\r\n"); } else { UART_1_PutString(" 23\trt_convert()\t\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Initialise rt_convert() test. */ if (result == RTT_SUCCESS) { if (rt_set_time(0, 0, 0) == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (rt_write() == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (rt_read(&data_0) == RT_SUCCESS) { UART_1_PutString(" -\tInitialise test...\tPASS\r\n"); } else { UART_1_PutString(" -\tInitialise test...\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Test rt_convert(). */ if (result == RTT_SUCCESS) { if (rt_convert(&data_0, string) == RT_SUCCESS) { UART_1_PutString(" 24\trt_convert()\t\tPASS\r\n"); } else { UART_1_PutString(" 24\trt_convert()\t\tPASS\r\n"); result = RTT_FAILURE; } } if (result == RTT_SUCCESS) { if (strcmp(string, "11/12/2013 00:00:00") == 0) { UART_1_PutString(" 25\trt_convert()\t\tPASS\r\n"); } else { UART_1_PutString(" 25\trt_convert()\t\tFAIL\r\n"); result = RTT_FAILURE; } } /* * Report test result. */ if (result == RTT_SUCCESS) { UART_1_PutString("\r\n"); UART_1_PutString("TEST PASSED\r\n"); } else { UART_1_PutString("\r\n"); UART_1_PutString("TEST FAILED\r\n"); } /* * Clean-up test. */ while ((UART_1_ReadTxStatus() & UART_1_TX_STS_FIFO_EMPTY) != UART_1_TX_STS_FIFO_EMPTY) { CyDelay(1); } UART_1_Stop(); rt_stop(); return result; }
/* ---------------------------------------------------------------------- */ int main(int argc, char *argv[]) { struct GModule *module; Rtimer rtTotal; char buf[BUFSIZ]; /* initialize GIS library */ G_gisinit(argv[0]); module = G_define_module(); #ifdef ELEV_SHORT module->description = _("Flow computation for massive grids (integer version)."); #endif #ifdef ELEV_FLOAT module->description = _("Flow computation for massive grids (float version)."); #endif G_add_keyword(_("raster")); G_add_keyword(_("hydrology")); /* read user options; fill in global <opt> */ opt = (userOptions*)malloc(sizeof(userOptions)); assert(opt); region = (struct Cell_head*)malloc(sizeof(struct Cell_head)); assert(region); parse_args(argc, argv); /* get the current region and dimensions */ G_get_set_window(region); check_args(); int nr = Rast_window_rows(); int nc = Rast_window_cols(); if ((nr > dimension_type_max) || (nc > dimension_type_max)) { G_fatal_error(_("[nrows=%d, ncols=%d] dimension_type overflow -- " "change dimension_type and recompile"), nr, nc); } else { nrows = (dimension_type)nr; ncols = (dimension_type)nc; } G_verbose_message( _("Region size is %d x %d"), nrows, ncols); /* check STREAM path (the place where intermediate STREAMs are placed) */ sprintf(buf, "%s=%s",STREAM_TMPDIR, opt->streamdir); /* don't pass an automatic variable; putenv() isn't guaranteed to make a copy */ putenv(G_store(buf)); if (getenv(STREAM_TMPDIR) == NULL) { fprintf(stderr, "%s:", STREAM_TMPDIR); G_fatal_error("not set"); } else { fprintf(stderr, "STREAM temporary files in %s ", getenv(STREAM_TMPDIR)); fprintf(stderr, "(THESE INTERMEDIATE STREAMS WILL NOT BE DELETED IN CASE OF ABNORMAL TERMINATION OF THE PROGRAM. TO SAVE SPACE PLEASE DELETE THESE FILES MANUALLY!)\n"); } /* open the stats file */ stats = new statsRecorder(opt->stats); record_args(argc, argv); { char buf[BUFSIZ]; long grid_size = nrows * ncols; *stats << "region size = " << formatNumber(buf, grid_size) << " elts " << "(" << nrows << " rows x " << ncols << " cols)\n"; stats->flush(); } /* set up STREAM memory manager */ size_t mm_size = (size_t) opt->mem << 20; /* opt->mem is in MB */ MM_manager.set_memory_limit(mm_size); if (opt->verbose) { MM_manager.warn_memory_limit(); } else { MM_manager.ignore_memory_limit(); } MM_manager.print_limit_mode(); /* initialize nodata */ nodataType::init(); *stats << "internal nodata value: " << nodataType::ELEVATION_NODATA << endl; /* start timing -- after parse_args, which are interactive */ rt_start(rtTotal); #ifndef JUMP2FLOW /* read elevation into a stream */ AMI_STREAM<elevation_type> *elstr=NULL; long nodata_count; elstr = cell2stream<elevation_type>(opt->elev_grid, elevation_type_max, &nodata_count); /* print the largest interm file that will be generated */ printMaxSortSize(nodata_count); /* -------------------------------------------------- */ /* compute flow direction and filled elevation (and watersheds) */ AMI_STREAM<direction_type> *dirstr=NULL; AMI_STREAM<elevation_type> *filledstr=NULL; AMI_STREAM<waterWindowBaseType> *flowStream=NULL; AMI_STREAM<labelElevType> *labeledWater = NULL; flowStream=computeFlowDirections(elstr, filledstr, dirstr, labeledWater); delete elstr; /* write streams to GRASS raster maps */ stream2_CELL(dirstr, nrows, ncols, opt->dir_grid); delete dirstr; #ifdef ELEV_SHORT stream2_CELL(filledstr, nrows, ncols, opt->filled_grid); #else stream2_CELL(filledstr, nrows, ncols, opt->filled_grid,true); #endif delete filledstr; stream2_CELL(labeledWater, nrows, ncols, labelElevTypePrintLabel(), opt->watershed_grid); setSinkWatershedColorTable(opt->watershed_grid); delete labeledWater; #else AMI_STREAM<waterWindowBaseType> *flowStream; char path[GPATH_MAX]; sprintf(path, "%s/flowStream", streamdir->answer); flowStream = new AMI_STREAM<waterWindowBaseType>(path); fprintf(stderr, "flowStream opened: len=%d\n", flowStream->stream_len()); fprintf(stderr, "jumping to flow accumulation computation\n"); #endif /* -------------------------------------------------- */ /* compute flow accumulation (and tci) */ AMI_STREAM<sweepOutput> *outstr=NULL; computeFlowAccumulation(flowStream, outstr); /* delete flowStream -- deleted inside */ /* write output stream to GRASS raster maps */ #ifdef OUTPUT_TCI stream2_FCELL(outstr, nrows, ncols, printAccumulation(), printTci(), opt->flowaccu_grid, opt->tci_grid); #else stream2_FCELL(outstr, nrows, ncols, printAccumulation(), opt->flowaccu_grid); #endif setFlowAccuColorTable(opt->flowaccu_grid); delete outstr; rt_stop(rtTotal); stats->recordTime("Total running time: ", rtTotal); stats->timestamp("end"); G_done_msg(" "); /* free the globals */ free(region); free(opt); delete stats; return 0; }
int main(int argc, char** argv) { //make sure the input is valid if(argc != 3) { printf("Incorrect number of arguments passed\n"); printf("Usage: multVis <input file path> <output file path>\n"); exit(0); } Rtimer total_time; rt_start(total_time); //argv[1] is input path, argv[2] is output path //create the grid from the input file. Note, this only fills in the elevation values - other values are filled in later with a call To Grid_fillPointValues and depending on viewpoint Grid* grid = Grid_createFromFile(argv[1]); //create a double array of shorts to hold the number of visible points from each point short** outputGrid = (short**) malloc(sizeof(short*) * Grid_getNCols(*grid)); assert(outputGrid); int w; for(w = 0; w < Grid_getNCols(*grid); w++) { outputGrid[w] = (short*) malloc(sizeof(short) * Grid_getNRows(*grid)); assert(outputGrid[w]); } //now, make the Point* array to hold all the points for the visibilty algorithm Point** points = (Point**) malloc((Grid_getNCols(*grid)*(Grid_getNRows(*grid))) * sizeof(Point*)); assert(points); //the logical size of the points array int pointsLength = 0; //fill the points array int c, r; for(c = 0; c < Grid_getNCols(*grid); c++) { for(r = 0; r < Grid_getNRows(*grid); r++) { //Do not add points that are NODATA if(Point_getElev(*Grid_getPoint(grid, c, r))==Grid_getNoDataValue(*grid)) continue; //otherwise, add the point points[pointsLength] = Grid_getPoint(grid, c, r); pointsLength++; } } //the Viewpoint* for the viewpoint Viewpoint* vp = (Viewpoint*) malloc(sizeof(Viewpoint)); //go through all points on the grid, and compute visibility with current point as viewpoint int vc, vr; /* int i, j; */ int numVis; int curProgress = -1; for(vc = 0; vc < Grid_getNCols(*grid); vc++) { for(vr = 0; vr < Grid_getNRows(*grid); vr++) { //write progress if((int) 100*(vc*Grid_getNCols(*grid)+vr%Grid_getNRows(*grid)) / (Grid_getNCols(*grid) * Grid_getNRows(*grid)) != curProgress) { curProgress = (int)100*(vc*Grid_getNCols(*grid)+vr%Grid_getNRows(*grid)) / (Grid_getNCols(*grid) * Grid_getNRows(*grid)); printf("%d ", curProgress); fflush(stdout); } //if the point at vc, vr is NODATA, write NODATA to output file if(Point_getElev(*Grid_getPoint(grid,vc,vr))==Grid_getNoDataValue(*grid)){ outputGrid[vc][vr] = Grid_getNoDataValue(*grid); continue; } //create a viewpoint at vc, vr Viewpoint_fill(vp, Point_getElev(*Grid_getPoint(grid, vc, vr))); //fill the other vales of the Points in the grid based on the viewpoint Grid_fillPointValues(grid, *vp, vc, vr); //now, sort by distance qsort(points, pointsLength, sizeof(Point*), PointPointer_compareByDist); //pointsLength is the maximum number of possible visible points numVis = pointsLength; //start the visibility recursion - we don't really care about the output horizon. Once it is done, the visibility values for all the points in the grid should be set correctly. visibility(0, pointsLength, points, &numVis); //write the number of visible points to the grid outputGrid[vc][vr] = numVis; } } //now, write the output grid to file //reminder that argv[1] is input path and argv[2] is output path writeOutputGrid(argv[1], argv[2], outputGrid, Grid_getNRows(*grid), Grid_getNCols(*grid)); //free and kill stuff free(points); for(w = 0; w < Grid_getNCols(*grid); w++) { free(outputGrid[w]); } free(outputGrid); free(vp); Grid_kill(grid); //stop and print the timer rt_stop(total_time); char buf[1000]; rt_sprint(buf, total_time); printf("\ntotal time: %s\n", buf); exit(1); }