Changeset 5539
- Timestamp:
- Jul 21, 2008, 11:42:58 AM (17 years ago)
- Location:
- anuga_core/source/anuga/shallow_water
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/data_manager.py
r5537 r5539 5059 5059 permutation = ensure_numeric([int(line.split(',')[0]) for line in ordering_lines]) 5060 5060 else: 5061 # Use empty array to signify 'all' points 5062 # We could have used 'None' but it got too hard in the C-code ;-) 5063 permutation = ensure_numeric([], Float) 5061 permutation = None 5064 5062 5065 5063 -
anuga_core/source/anuga/shallow_water/test_data_manager.py
r5537 r5539 6719 6719 6720 6720 6721 def test_urs2sts_ordering_exception(self):6721 def Xtest_urs2sts_ordering_exception(self): 6722 6722 """Test that inconsistent lats and lons in ordering file are caught. 6723 6723 """ … … 8940 8940 if __name__ == "__main__": 8941 8941 8942 #suite = unittest.makeSuite(Test_Data_Manager,'test')8943 suite = unittest.makeSuite(Test_Data_Manager,'test_urs2sts_read_mux2_pyI')8942 suite = unittest.makeSuite(Test_Data_Manager,'test') 8943 #suite = unittest.makeSuite(Test_Data_Manager,'test_urs2sts_read_mux2_pyI') 8944 8944 #suite = unittest.makeSuite(Test_Data_Manager,'test_urs2sts') 8945 8945 #suite = unittest.makeSuite(Test_Data_Manager,'test_get_flow_through_cross_section_with_geo') … … 8955 8955 else: 8956 8956 pass 8957 runner = unittest.TextTestRunner( verbosity=2)8957 runner = unittest.TextTestRunner() #verbosity=2) 8958 8958 runner.run(suite) 8959 8959 -
anuga_core/source/anuga/shallow_water/urs_ext.c
r5537 r5539 32 32 float *weights, 33 33 double *params, 34 int number_of_selected_stations,34 int *number_of_stations, 35 35 int *permutation, 36 36 int verbose); … … 43 43 44 44 NOTE: 45 A Python int is equivalent to a C long 45 A Python int is equivalent to a C long (this becomes really important on 64 bit architectures) 46 46 A Python double corresponds to a C double 47 47 */ 48 48 49 PyObject *filenames; 49 50 PyArrayObject *pyweights; … … 71 72 int num_ts; 72 73 73 //printf("Checkpoint 1 for urs2sts_ext.c\n");74 75 74 // Convert Python arguments to C 76 75 if (!PyArg_ParseTuple(args, "iOOOOi", … … 110 109 if (muxFileNameArray == NULL) 111 110 { 112 printf("ERROR: Memory for muxFileNameArray could not be allocated.\n"); 113 return NULL; 114 } 115 116 printf("Checkpoint 2 for urs2sts_ext.c\n"); 117 //printf("numSrc = %d\n", numSrc); 111 PyErr_SetString(PyExc_ValueError, "ERROR: Memory for muxFileNameArray could not be allocated."); 112 return NULL; 113 } 114 118 115 for (i = 0; i < numSrc; i++) 119 116 { 120 117 121 //printf("check 2.1, i=%d\n", i);122 118 fname = PyList_GetItem(filenames, i); 123 //printf("check 2.2\n");124 119 if (!fname) 125 120 { 126 //printf("error\n");127 121 PyErr_SetString(PyExc_ValueError, "filename not a string"); 128 122 return NULL; 129 123 } 130 //printf("check 2.3\n"); 131 //printf("fname = %s\n", PyString_AsString(fname)); 132 133 134 //printf("check 2.4\n"); 124 135 125 muxFileNameArray[i] = PyString_AsString(fname); 136 126 if (muxFileNameArray[i] == NULL) … … 142 132 } 143 133 144 //printf("Checkpoint 3 for urs2sts_ext.c\n");145 134 if (file_params->nd != 1 || file_params->descr->type_num != PyArray_DOUBLE) 146 135 { … … 150 139 } 151 140 152 printf("Checkpoint 4 for urs2sts_ext.c\n"); 141 153 142 // Create array for weights which are passed to read_mux2 154 143 weights = (float*) malloc(numSrc*sizeof(float)); … … 158 147 } 159 148 160 161 149 number_of_selected_stations = (int) permutation->dimensions[0]; 162 printf("Checkpoint 5 for urs2sts_ext.c\n"); 150 163 151 // Read in mux2 data from file 164 152 cdata = _read_mux2(numSrc, … … 166 154 weights, 167 155 (double*)file_params->data, 168 number_of_selected_stations, // Desired number of stations156 &number_of_selected_stations, // Desired number of stations 169 157 (int*) permutation->data, // Ordering of selected stations 170 158 verbose); … … 177 165 178 166 179 //printf("Checkpoint 6 for urs2sts_ext.c\n");180 167 // Allocate space for return vector 181 168 nsta0 = (int)*(double*)(file_params->data + 0*file_params->strides[0]); … … 183 170 nt = (int)*(double*)(file_params->data + 2*file_params->strides[0]); 184 171 185 printf("Checkpoint 7 for urs2sts_ext.c\n");186 172 187 173 // Find min and max start times of all gauges … … 190 176 for (i = 0; i < number_of_selected_stations; i++) 191 177 { 192 printf("cdata[%d] start = %f\n", i, (double) cdata[i][nt+3]);193 printf("cdata[%d] finish = %f\n", i, (double) cdata[i][nt+4]);178 //printf("cdata[%d] start = %f\n", i, (double) cdata[i][nt+3]); 179 // printf("cdata[%d] finish = %f\n", i, (double) cdata[i][nt+4]); 194 180 195 181 if ((int)cdata[i][nt + 3] < start_tstep) … … 203 189 } 204 190 205 printf("Checkpoint 8 for urs2sts_ext.c\n");206 191 if ((start_tstep > nt) | (finish_tstep < 0)) 207 192 { … … 229 214 } 230 215 231 printf("Checkpoint 9 for urs2sts_ext.c\n");216 232 217 // Each gauge begins and ends recording at different times. When a gauge is 233 218 // not recording but at least one other gauge is. Pad the non-recording gauge … … 242 227 if (it + 1 > (int)cdata[i][nt + 4]) 243 228 { 244 // This gauge has stopped recording but others are still recording229 // This gauge has stopped recording but others are still recording 245 230 *(double*)(pydata->data + i*pydata->strides[0] + time*pydata->strides[1]) = 0.0; 246 231 } … … 259 244 } 260 245 261 printf("Checkpoint 10 for urs2sts_ext.c\n");262 246 free(weights); 263 247 … … 272 256 free(cdata); 273 257 274 printf("Checkpoint 11 for urs2sts_ext.c\n");275 258 return PyArray_Return(pydata); 276 259 } … … 280 263 float *weights, 281 264 double *params, 282 int number_of_selected_stations,265 int *number_of_stations, 283 266 int *permutation, 284 267 int verbose) … … 290 273 int istart, istop; 291 274 int *fros=0, *lros=0; 275 int number_of_selected_stations; 292 276 char susMuxFileName; 293 277 float *muxData; … … 328 312 } 329 313 330 printf("P1\n");331 314 /* Loop over all sources, read headers and check compatibility */ 332 315 for (isrc = 0; isrc < numSrc; isrc++) … … 406 389 } 407 390 408 printf("P2\n");409 391 params[0] = (double)nsta0; 410 392 params[1] = (double)mytgs0[0].dt; … … 413 395 // Apply rule that an empty permutation file means 'take all stations' 414 396 // We can change this later by passing in None instead of the empty permutation. 415 416 printf("number_of_selected_stations B4 = %d\n", number_of_selected_stations); 397 398 399 number_of_selected_stations = *number_of_stations; 417 400 if (number_of_selected_stations == 0) 418 401 { 419 402 number_of_selected_stations = nsta0; 403 *number_of_stations = nsta0; // Return possibly updated number of stations 420 404 421 printf("Creating identity permutation vector of length = %d\n", nsta0);422 405 // Create the Identity permutation vector 423 406 permutation = (int *) malloc(number_of_selected_stations*sizeof(int)); … … 426 409 permutation[i] = i; 427 410 } 428 429 } 430 431 printf("P3\n"); 432 printf("Number of selected stations = %d\n", number_of_selected_stations); 411 } 412 413 414 433 415 /* Make array(s) to hold demuxed data for stations given in the permutation file */ 434 416 sts_data = (float**)malloc(number_of_selected_stations*sizeof(float*)); … … 439 421 } 440 422 441 printf("P4\n");442 423 // For each selected station, allocate space for its data 443 424 len_sts_data = mytgs0[0].nt + POFFSET; // Max length of each timeseries (I think) 444 425 for (i = 0; i < number_of_selected_stations; i++) 445 426 { 446 printf("P4.1, i=%d\n", i);447 448 427 // Initialise sts_data to zero 449 428 sts_data[i] = (float*)calloc(len_sts_data, sizeof(float)); … … 454 433 } 455 434 456 457 printf("P4.2, i=%d\n", i);458 435 ista = permutation[i]; // Get global index into mux data 459 436 460 461 printf("P4.3, i=%d\n", i);462 437 sts_data[i][mytgs0[0].nt] = (float)mytgs0[ista].geolat; 463 438 sts_data[i][mytgs0[0].nt + 1] = (float)mytgs0[ista].geolon; … … 466 441 sts_data[i][mytgs0[0].nt + 4] = (float)lros[ista]; 467 442 } 468 469 printf("P5\n"); 443 470 444 temp_sts_data = (float*)calloc(len_sts_data, sizeof(float)); 471 445 … … 480 454 if((fp = fopen(muxFileName, "r")) == NULL) 481 455 { 482 //fprintf(stderr, "%s: cannot open file %s\n", av[0], muxFileName);483 456 fprintf(stderr, "cannot open file %s\n", muxFileName); 484 457 return NULL; … … 524 497 { 525 498 sts_data[i][k] += temp_sts_data[k] * weights[isrc]; 526 //printf("%d,%d,%f\n",ista,k,sts_data[ista][k]);527 499 } 528 500 else … … 534 506 } 535 507 536 printf("P6\n");537 508 free(muxData); 538 509 free(temp_sts_data);
Note: See TracChangeset
for help on using the changeset viewer.