CPLErr IRISRasterBand::IReadBlock( int /* nBlockXOff */, int nBlockYOff, void * pImage ) { IRISDataset *poGDS = static_cast<IRISDataset *>(poDS); // Every product type has its own size. TODO: Move it like dataType. int nDataLength = 1; if( poGDS->nDataTypeCode == 2 ) nDataLength = 1; else if( poGDS->nDataTypeCode == 8 ) nDataLength = 2; else if( poGDS->nDataTypeCode == 9 ) nDataLength = 2; else if( poGDS->nDataTypeCode == 37 ) nDataLength = 2; else if( poGDS->nDataTypeCode == 33 ) nDataLength = 2; else if( poGDS->nDataTypeCode == 32 ) nDataLength = 1; // We allocate space for storing a record: if( pszRecord == nullptr ) { if( bBufferAllocFailed ) return CE_Failure; pszRecord = static_cast<unsigned char *>( VSI_MALLOC_VERBOSE(nBlockXSize*nDataLength)); if( pszRecord == nullptr ) { bBufferAllocFailed = true; return CE_Failure; } } // Prepare to read (640 is the header size in bytes) and read (the // y axis in the IRIS files in the inverse direction). The // previous bands are also added as an offset VSIFSeekL( poGDS->fp, 640 + static_cast<vsi_l_offset>(nDataLength)*poGDS->GetRasterXSize()*poGDS->GetRasterYSize()*(this->nBand-1) + static_cast<vsi_l_offset>(nBlockXSize)*nDataLength*(poGDS->GetRasterYSize()-1-nBlockYOff), SEEK_SET ); if( static_cast<int>(VSIFReadL( pszRecord, nBlockXSize*nDataLength, 1, poGDS->fp )) != 1 ) return CE_Failure; // If datatype is dbZ or dBT: // See point 3.3.3 at page 3.33 of the manual. if( poGDS->nDataTypeCode == 2 || poGDS->nDataTypeCode == 1 ) { for( int i = 0; i < nBlockXSize; i++) { float fVal = ((*(pszRecord + i * nDataLength)) - 64.0f) / 2.0f; if( fVal == 95.5f ) fVal = -9999.0f; ((float *) pImage)[i] = fVal; } // If datatype is dbZ2 or dBT2: // See point 3.3.4 at page 3.33 of the manual. } else if( poGDS->nDataTypeCode == 8 || poGDS->nDataTypeCode == 9 ) { for( int i = 0; i < nBlockXSize; i++) { float fVal = (CPL_LSBUINT16PTR(pszRecord + i * nDataLength) - 32768.0f) / 100.0f; if( fVal == 327.67f ) fVal = -9999.0f; ((float *) pImage)[i] = fVal; } // Fliquid2 (Rain1 & Rainn products) // See point 3.3.11 at page 3.43 of the manual. } else if( poGDS->nDataTypeCode == 37 ) { for( int i = 0; i < nBlockXSize; i++) { const unsigned short nVal = CPL_LSBUINT16PTR(pszRecord+i*nDataLength); const unsigned short nExp = nVal>>12; const unsigned short nMantissa = nVal - (nExp<<12); float fVal2 = 0.0f; if( nVal == 65535 ) fVal2 = -9999.0f; else if( nExp == 0 ) fVal2 = nMantissa / 1000.0f; else fVal2 = ((nMantissa + 4096) << (nExp - 1)) / 1000.0f; ((float *) pImage)[i] = fVal2; } // VIL2 (VIL products) // See point 3.3.41 at page 3.54 of the manual. } else if( poGDS->nDataTypeCode == 33 )
CPLErr IRISRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff, void * pImage ) { IRISDataset *poGDS = (IRISDataset *) poDS; //Every product type has it's own size. TODO: Move it like dataType int nDataLength = 1; if(poGDS->nDataTypeCode == 2){nDataLength=1;} else if(poGDS->nDataTypeCode == 37){nDataLength=2;} else if(poGDS->nDataTypeCode == 33){nDataLength=2;} else if(poGDS->nDataTypeCode == 32){nDataLength=1;} int i; //We allocate space for storing a record: if (pszRecord == NULL) { if (bBufferAllocFailed) return CE_Failure; pszRecord = (unsigned char *) VSIMalloc(nBlockXSize*nDataLength); if (pszRecord == NULL) { CPLError(CE_Failure, CPLE_OutOfMemory, "Cannot allocate scanline buffer"); bBufferAllocFailed = TRUE; return CE_Failure; } } //Prepare to read (640 is the header size in bytes) and read (the y axis in the IRIS files in the inverse direction) //The previous bands are also added as an offset VSIFSeekL( poGDS->fp, 640 + (vsi_l_offset)nDataLength*poGDS->GetRasterXSize()*poGDS->GetRasterYSize()*(this->nBand-1) + (vsi_l_offset)nBlockXSize*nDataLength*(poGDS->GetRasterYSize()-1-nBlockYOff), SEEK_SET ); if( (int)VSIFReadL( pszRecord, nBlockXSize*nDataLength, 1, poGDS->fp ) != 1 ) return CE_Failure; //If datatype is dbZ or dBT: //See point 3.3.3 at page 3.33 of the manual if(poGDS->nDataTypeCode == 2 || poGDS->nDataTypeCode == 1){ float fVal; for (i=0;i<nBlockXSize;i++){ fVal = (((float) *(pszRecord+i*nDataLength)) -64)/2.0; if (fVal == 95.5) fVal = -9999; ((float *) pImage)[i] = fVal; } //If datatype is dbZ2 or dBT2: //See point 3.3.4 at page 3.33 of the manual } else if(poGDS->nDataTypeCode == 8 || poGDS->nDataTypeCode == 9){ float fVal; for (i=0;i<nBlockXSize;i++){ fVal = (((float) CPL_LSBUINT16PTR(pszRecord+i*nDataLength)) - 32768)/100.0; if (fVal == 327.67) fVal = -9999; ((float *) pImage)[i] = fVal; } //Fliquid2 (Rain1 & Rainn products) //See point 3.3.11 at page 3.43 of the manual } else if(poGDS->nDataTypeCode == 37){ unsigned short nVal, nExp, nMantissa; float fVal2=0; for (i=0;i<nBlockXSize;i++){ nVal = CPL_LSBUINT16PTR(pszRecord+i*nDataLength); nExp = nVal>>12; nMantissa = nVal - (nExp<<12); if (nVal == 65535) fVal2 = -9999; else if (nExp == 0) fVal2 = (float) nMantissa / 1000.0; else fVal2 = (float)((nMantissa+4096)<<(nExp-1))/1000.0; ((float *) pImage)[i] = fVal2; } //VIL2 (VIL products) //See point 3.3.41 at page 3.54 of the manual } else if(poGDS->nDataTypeCode == 33){
fVal2 = -9999.0f; else if( nExp == 0 ) fVal2 = nMantissa / 1000.0f; else fVal2 = ((nMantissa + 4096) << (nExp - 1)) / 1000.0f; ((float *) pImage)[i] = fVal2; } // VIL2 (VIL products) // See point 3.3.41 at page 3.54 of the manual. } else if( poGDS->nDataTypeCode == 33 ) { for( int i = 0; i < nBlockXSize; i++) { float fVal = static_cast<float>(CPL_LSBUINT16PTR(pszRecord+i*nDataLength)); if( fVal == 65535.0f ) ((float *) pImage)[i] = -9999.0f; else if( fVal == 0.0f ) ((float *) pImage)[i] = -1.0f; else ((float *) pImage)[i] = (fVal-1) / 1000.0f; } // HEIGHT (TOPS products) // See point 3.3.14 at page 3.46 of the manual. } else if( poGDS->nDataTypeCode == 32 ) { for( int i = 0; i < nBlockXSize; i++) { unsigned char nVal = *(pszRecord+i*nDataLength);