replaced a couple of variable names with more meaningful names: i -> iRang, j -> iAzim, nrang -> nRang, nazim -> nAzim (there may have been a bug with this variable, nAzim was initialized, but nazim was used)
there was previously just one missing-value value 'mssing', which was applied to three arguments teximage, rhoimage, and zdrimage. I introduced texMissing, rhoMissing, and zdrMissing and replaced 'missing' by the correct variable name
there were something like 14 occurences of 'iRang+iAzim*nRang' in the code. I introduced a new variable 'iGlobal' and replaced those 14  occurrences by 'iGlobal'
introduced +    double texOffset;
replaced one line if-statement by if with curly braces
renamed threstex to texThres, thresrho to rhoThres, threszdr to zdrThres, threstexmin to texThresMin, thresrhomin to rhoThresMin, threszdrmin to zdrThresMin
replaced k by iNeighborhood, ii by iRangLocal, jj by iAzimLocal, ii+jj*nRang by iLocal
replaced some but not all occurrences of ij by iGlobal, and replaced nAzim*nRang by nGlobal
added the recalculation of iLocal where appropriate, and relocated some duplicate code from the if and else parts to outside the if else
divided an if (A || B){continue} into an if (A) and an if (B)
I introduced variables iCellIdentifier, iGlobalOther, nCells; I removed variables ncells, ij; I split a complex if condition into separate components, which together are equivalent.