Changeset 6902 for branches/numpy/anuga/shallow_water/urs_ext.c
- Timestamp:
- Apr 24, 2009, 5:22:14 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/numpy/anuga/shallow_water/urs_ext.c
r6780 r6902 104 104 memcpy(data + it, muxData + offset, sizeof(float)); 105 105 106 //printf("%d: muxdata=%f\n", it, muxData[offset]); 107 //printf("data[%d]=%f, offset=%d\n", it, data[it], offset); 106 //printf("%d: muxdata=%f\n", it, muxData[offset]); 107 //printf("data[%d]=%f, offset=%d\n", it, data[it], offset); 108 108 offset++; 109 109 } … … 221 221 222 222 // Open the mux file 223 if((fp = fopen(muxFileName, "r ")) == NULL)223 if((fp = fopen(muxFileName, "rb")) == NULL) 224 224 { 225 225 char *err_msg = strerror(errno); … … 237 237 } 238 238 239 fros = (int*) malloc(*total_number_of_stations*numSrc*sizeof(int)); 239 fros = (int*) malloc(*total_number_of_stations*numSrc*sizeof(int)); 240 240 lros = (int*) malloc(*total_number_of_stations*numSrc*sizeof(int)); 241 241 … … 447 447 temp_sts_data = (float*) calloc(len_sts_data, sizeof(float)); 448 448 449 muxData = (float*) malloc(numDataMax*sizeof(float));449 muxData = (float*) calloc(numDataMax, sizeof(float)); 450 450 451 451 // Loop over all sources … … 460 460 // Read in data block from mux2 file 461 461 muxFileName = muxFileNameArray[isrc]; 462 if((fp = fopen(muxFileName, "r ")) == NULL)462 if((fp = fopen(muxFileName, "rb")) == NULL) 463 463 { 464 464 fprintf(stderr, "cannot open file %s\n", muxFileName); … … 470 470 } 471 471 472 offset = sizeof(int) + total_number_of_stations*(sizeof(struct tgsrwg) + 2*sizeof(int)); 473 fseek(fp, offset, 0); 472 offset = (long int)sizeof(int) + total_number_of_stations*(sizeof(struct tgsrwg) + 2*sizeof(int)); 473 //printf("\n offset %i ", (long int)offset); 474 fseek(fp, offset, 0); 474 475 475 476 numData = getNumData(fros_per_source, 476 477 lros_per_source, 477 478 total_number_of_stations); 478 479 480 481 elements_read = fread(muxData, ((int) numData)*sizeof(float), 1, fp); 479 // Note numData is larger than what it has to be. 480 //elements_read = fread(muxData, ((int) numData)*sizeof(float), 1, fp); 481 elements_read = fread(muxData, (size_t) sizeof(float), (size_t) numData, fp); 482 //printf("\n elements_read %d, ", (int)elements_read); 483 //printf("\n ferror(fp) %d, ", (int)ferror(fp)); 482 484 if ((int) elements_read == 0 && ferror(fp)) { 483 485 fprintf(stderr, "Error reading mux data\n"); 484 486 return NULL; 485 } 486 487 fclose(fp); 487 } 488 488 489 490 // FIXME (Ole): This is where Nariman and Ole traced the platform dependent 491 // difference on 11 November 2008. We don't think the problem lies in the 492 // C code. Maybe it is a problem with the MUX files written by the unit test 493 // that fails on Windows but works OK on Linux. JJ's test on 17th November shows 494 // that as far as Python is concerned this file should be OK on both platforms. 495 496 497 498 // These printouts are enough to show the problem when compared 499 // on the two platforms 500 //printf("\nRead %d elements, ", (int) numData); 501 //printf("muxdata[%d]=%f\n", 39, muxData[39]); 502 503 504 /* 505 In Windows we get 506 507 Read 85 elements, muxdata[39]=0.999574 508 Read 85 elements, muxdata[39]=-0.087599 509 Read 85 elements, muxdata[39]=-0.087599 510 511 512 In Linux we get (the correct) 513 514 Read 85 elements, muxdata[39]=0.999574 515 Read 85 elements, muxdata[39]=-0.087599 516 Read 85 elements, muxdata[39]=1.490349 517 */ 518 519 520 521 489 fclose(fp); 522 490 523 491 // loop over stations present in the permutation array
Note: See TracChangeset
for help on using the changeset viewer.