Changeset 5542
- Timestamp:
- Jul 21, 2008, 3:37:04 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/urs_ext.c
r5541 r5542 25 25 #define POFFSET 5 //Number of site_params 26 26 27 void fillDataArray(int, int, int, int, int *, int *, float *, int *, int *, float *); 27 void fillDataArray(int, int, int, int, int *, int *, float *, 28 int *, int *, float *); 28 29 long getNumData(const int *fros, const int *lros, const int nsta); 29 30 char isdata(float); … … 43 44 44 45 NOTE: 45 A Python int is equivalent to a C long (this becomes really important on 64 bit architectures) 46 A Python int is equivalent to a C long 47 (this becomes really important on 64 bit architectures) 48 46 49 A Python double corresponds to a C double 47 50 */ … … 50 53 PyArrayObject *pyweights; 51 54 PyArrayObject *file_params; 52 PyArrayObject *permutation; 55 PyArrayObject *permutation; // Ordering of selected stations 53 56 PyArrayObject *pydata; 54 57 PyObject *fname; … … 103 106 if(PyList_Size(filenames) != pyweights->dimensions[0]) 104 107 { 105 PyErr_SetString(PyExc_ValueError, "Must specify one weight for each filename"); 108 PyErr_SetString(PyExc_ValueError, 109 "Must specify one weight for each filename"); 106 110 return NULL; 107 111 } … … 110 114 if (muxFileNameArray == NULL) 111 115 { 112 PyErr_SetString(PyExc_ValueError, "ERROR: Memory for muxFileNameArray could not be allocated."); 116 PyErr_SetString(PyExc_ValueError, 117 "ERROR: Memory for muxFileNameArray could not be allocated."); 113 118 return NULL; 114 119 } … … 128 133 { 129 134 PyErr_SetString(PyExc_ValueError, 130 135 "ERROR: Memory for muxFileNameArray could not be allocated.\n"); 131 136 return NULL; 132 137 } … … 136 141 { 137 142 PyErr_SetString(PyExc_ValueError, 138 143 "file_params must be one-dimensional and of type double"); 139 144 return NULL; 140 145 } … … 145 150 for (i = 0; i < numSrc; i++) 146 151 { 147 weights[i] = (float)(*(double*)(pyweights->data + i*pyweights->strides[0])); 148 } 149 152 weights[i] = (float)(*(double*) 153 (pyweights->data + i*pyweights->strides[0])); 154 } 155 156 // Desired number of stations 150 157 number_of_selected_stations = (int) permutation->dimensions[0]; 151 158 … … 155 162 weights, 156 163 (double*)file_params->data, 157 &number_of_selected_stations, // Desired number of stations158 (long*) permutation->data, // Ordering of selected stations164 &number_of_selected_stations, 165 (long*) permutation->data, 159 166 verbose); 160 167 … … 193 200 { 194 201 printf("ERROR: Gauge data has incorrect start and finish times:\n"); 195 printf(" start_tstep = %d, max_number_of_steps = %d\n", start_tstep, nt); 196 printf(" finish_tstep = %d, min_number_of_steps = %d\n", finish_tstep, 0); 202 printf(" start_tstep = %d, max_number_of_steps = %d\n", 203 start_tstep, nt); 204 printf(" finish_tstep = %d, min_number_of_steps = %d\n", 205 finish_tstep, 0); 206 197 207 PyErr_SetString(PyExc_ValueError, "Incorrect start and finish times"); 198 208 return NULL; … … 201 211 if (start_tstep >= finish_tstep) 202 212 { 203 PyErr_SetString(PyExc_ValueError, "ERROR: Gauge data has non-postive_length"); 213 PyErr_SetString(PyExc_ValueError, 214 "ERROR: Gauge data has non-postive_length"); 204 215 return NULL; 205 216 } … … 212 223 if(pydata == NULL) 213 224 { 214 PyErr_SetString(PyExc_ValueError, "ERROR: Memory for pydata array could not be allocated."); 225 PyErr_SetString(PyExc_ValueError, 226 "ERROR: Memory for pydata array could not be allocated."); 215 227 return NULL; 216 228 } … … 218 230 219 231 // Each gauge begins and ends recording at different times. When a gauge is 220 // not recording but at least one other gauge is. Pad the non-recording gauge221 // array with zeros.232 // not recording but at least one other gauge is. 233 // Pad the non-recording gauge array with zeros. 222 234 for (i = 0; i < number_of_selected_stations; i++) 223 235 { … … 229 241 if (it + 1 > (int)cdata[i][nt + 4]) 230 242 { 231 // This gauge has stopped recording but others are still recording 232 *(double*)(pydata->data + i*pydata->strides[0] + time*pydata->strides[1]) = 0.0; 243 // This gauge has stopped recording but others are 244 // still recording 245 *(double*)(pydata->data + i*pydata->strides[0] 246 + time*pydata->strides[1]) = 247 0.0; 233 248 } 234 249 else 235 250 { 236 *(double*)(pydata->data + i*pydata->strides[0] + time*pydata->strides[1]) = cdata[i][it]; 251 *(double*)(pydata->data + i*pydata->strides[0] 252 + time*pydata->strides[1]) = 253 cdata[i][it]; 237 254 } 238 255 time++; … … 242 259 for (j = 0; j < POFFSET; j++) 243 260 { 244 *(double*)(pydata->data + i*pydata->strides[0] + (num_ts + j)*pydata->strides[1]) = cdata[i][nt + j]; 261 *(double*)(pydata->data + i*pydata->strides[0] 262 + (num_ts + j)*pydata->strides[1]) = 263 cdata[i][nt + j]; 245 264 } 246 265 } … … 277 296 int number_of_selected_stations; 278 297 char susMuxFileName; 279 float *muxData ;298 float *muxData=NULL; // Suppress warning 280 299 long numData; 281 300 … … 286 305 long int offset; 287 306 288 /* Allocate space for the names and the weights and pointers to the data*/ 307 /* Allocate space for the names and the weights and pointers to the data*/ 289 308 290 309 /* Check that the input files have mux2 extension*/ … … 293 312 { 294 313 muxFileName = muxFileNameArray[isrc]; 295 if(!susMuxFileName && strcmp(muxFileName + strlen(muxFileName) - 4, "mux2") != 0) 314 if(!susMuxFileName && strcmp(muxFileName + strlen(muxFileName) - 4, 315 "mux2") != 0) 296 316 { 297 317 susMuxFileName = 1; … … 396 416 397 417 // Apply rule that an empty permutation file means 'take all stations' 398 // We can change this later by passing in None instead of the empty permutation. 399 400 418 // We could change this later by passing in None instead of the empty 419 // permutation. 401 420 number_of_selected_stations = *number_of_stations; 402 421 if (number_of_selected_stations == 0) 403 422 { 404 423 number_of_selected_stations = nsta0; 405 *number_of_stations = nsta0; // Return possibly updated number of stations 424 425 // Return possibly updated number of stations 426 *number_of_stations = nsta0; 406 427 407 428 // Create the Identity permutation vector … … 422 443 423 444 424 /* Make array(s) to hold demuxed data for stations given in the permutation file */ 445 // Make array(s) to hold demuxed data for stations given in the 446 // permutation file 425 447 sts_data = (float**)malloc(number_of_selected_stations*sizeof(float*)); 426 448 if (sts_data == NULL) … … 431 453 432 454 // For each selected station, allocate space for its data 433 len_sts_data = mytgs0[0].nt + POFFSET; // Max length of each timeseries (I think)455 len_sts_data = mytgs0[0].nt + POFFSET; // Max length of each timeseries? 434 456 for (i = 0; i < number_of_selected_stations; i++) 435 457 { … … 527 549 528 550 /* thomas */ 529 void fillDataArray(int ista, int nsta, int nt, int ig, int *nst, int *nft, float *data, int *istart_p, int *istop_p, float *muxData) 551 void fillDataArray(int ista, int nsta, int nt, int ig, int *nst, 552 int *nft, float *data, int *istart_p, 553 int *istop_p, float *muxData) 530 554 { 531 555 int it, last_it, jsta; … … 562 586 if (ig == -1 || nst[ista] == -1) /* currently ig==-1 => nst[ista]==-1 */ 563 587 { 564 /* gauge never started recording, or was outside of all grids, fill array with 0 */ 588 /* gauge never started recording, or was outside of all grids, 589 fill array with 0 */ 565 590 for(it = 0; it < nt; it++) 566 591 { … … 593 618 } 594 619 else 595 /* gauge has finished recording */ 620 /* gauge has finished recording */ 596 621 { 597 622 data[it] = NODATA; … … 606 631 607 632 if(last_it < nt - 1) 608 /* the loop was exited early because the gauge had finished recording */ 633 /* the loop was exited early because the gauge had 634 finished recording */ 609 635 for(it = last_it+1; it < nt; it++) 610 636 data[it] = NODATA; … … 638 664 { 639 665 numData += *(lros + ista) - *(fros + ista) + 1; 640 last_output_step = (last_output_step < *(lros+ista) ? *(lros+ista):last_output_step); 666 last_output_step = (last_output_step < *(lros+ista) ? 667 *(lros+ista):last_output_step); 641 668 } 642 669 numData += last_output_step*nsta; /* these are the t records */
Note: See TracChangeset
for help on using the changeset viewer.