Skip to content

Commit

Permalink
Addresses issue dtarb#228 and applies the fix recommended by dtarb (r…
Browse files Browse the repository at this point in the history
…epo author). I made code modifications to only src/area.cpp but wrote comments of possible issues that may occure in createpart.h, I will expand on this here. The previous expectation was athe value -1.0f and in createpartion.h this is of type double. The change swaps this value to MISSINGFLOAT which == MAXFLOAT * -1. This creates the 2's compliment of MAXFLOAT. Because this is of type double it should be recieved without issue but, it appears in certain cases, theis variable is recast as int32_t and more worrisome, int16_t, if this is the case, overflow errors may occur. This may be of no significance as the MISSINGFLOAT is a method of error handling not computation. This code has not been tested and should not be merged until that has occued and QC has taken place. DO NOT MERGE UNTIL AFTER QC.
  • Loading branch information
DanielJBeckman committed Jul 16, 2021
1 parent 98137bb commit 77d20f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/aread8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ int aread8( char* pfile, char* afile, char *datasrc, char *lyrname,int uselyrnam

//Create empty partition to store new information
tdpartition *aread8;
aread8 = CreateNewPartition(FLOAT_TYPE, totalX, totalY, dxA, dyA, -1.0f); // modified by Nazmus
aread8 = CreateNewPartition(FLOAT_TYPE, totalX, totalY, dxA, dyA, MISSINGFLOAT); // modified by DanielJbeckman, ref# issue #228

// con is used to check for contamination at the edges
long i,j;
Expand Down Expand Up @@ -266,7 +266,7 @@ int aread8( char* pfile, char* afile, char *datasrc, char *lyrname,int uselyrnam
double computet = MPI_Wtime();

//Create and write TIFF file
float aNodata = -1.0f;
float aNodata = MISSINGFLOAT; //Modifyied by DanielJBeckman Ref issue #228; This new value of MISSINGFLOAT originates in commonLib.h
tiffIO a(afile, FLOAT_TYPE, aNodata, p);
a.write(xstart, ystart, ny, nx, aread8->getGridPointer());
double writet = MPI_Wtime();
Expand Down
6 changes: 4 additions & 2 deletions src/createpart.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ email: [email protected]
// noDatarefactor 11/18/17 apparrently both functions are needed so that sometimes a no data pointer can be input and sometimes a nodata value
tdpartition *CreateNewPartition(DATA_TYPE datatype, long totalx, long totaly, double dxA, double dyA, double nodata){
//Takes a double as the nodata parameter to accommodate double returns from GDAL through tiffIO

//Modification occures downstream. Expected -0.1f has been swapped with MISSINGFLOAT which == MAXFLOAT *-1; Ref issue #228
//typecasting below may break as MISSINGFLOAT is of type double and is 2's compliment; May not convert to anything below 64 bits.
//Be on guard for overflow errors
tdpartition* ptr = NULL;
int rank;
MPI_Comm_rank(MCW, &rank);//returns the rank of the calling processes in a communicator
Expand All @@ -64,7 +66,7 @@ tdpartition *CreateNewPartition(DATA_TYPE datatype, long totalx, long totaly, do
ptr->init(totalx, totaly, dxA, dyA, MPI_INT16_T, ndinit);
}else if(datatype == LONG_TYPE){
ptr = new linearpart<int32_t>;
int32_t ndinit = (int32_t)nodata;
int32_t ndinit = (int32_t)nodata;
if (rank == 0) {
printf("Nodata value input to create partition from file: %lf\n", nodata);
printf("Nodata value recast to int32_t used in partition raster: %d\n", ndinit);
Expand Down

0 comments on commit 77d20f0

Please sign in to comment.