[ncl-talk] overwriting 4d array for specific locations only

Imran Hosen hosen.imran09 at gmail.com
Mon Apr 3 04:58:21 MDT 2017


Hi,

I'm trying to overwriting a variable for specific locations in a NetCDF
file in following way:

begin
f = addfile("wrfinput_d03_modified","r")
LU_INDEX = f->LU_INDEX(0,:,:)   ;3-D variable(Time:lat:lon)
var = f->SMOIS(:,:,:,:) ; 4-D variable(Time:layer:lat:lon)
var_mask = mask(var,(LU_INDEX.ne.1), False)
var_mask_25 = var_mask + var_mask * 0.25
SMOIS_NEW = var_mask_25
; write to netcdf
system("rm -f smois.nc")
fwrite = addfile("smois.nc","c")
fwrite->SMOIS_NEW = (/SMOIS_NEW/)
SMOIS_write = new((/1,4,117,117/),typeof(var))
SMOIS_write(:,:,:,:) = SMOIS_NEW


;Replacing the "_FillValues" of SMOIS_write by the var values
if (any(isnan_ieee(SMOIS_write))) then
       if(.not.isatt(SMOIS_write,"_FillValue")) then
       SMOIS_write at _FillValue = var(typeof(var))
       end if
       replace_ieeenan (SMOIS_write, SMOIS_write at _FillValue, 0)
end if
print(SMOIS_write)

end

I just want the *var* array to retain all its attributes

but just want to replace the values (specific locations where the LU_INDEX=1)

 with the real values of SMOIS_write.


It seems to me that "if" statement is not working. Still SMOIS_write
is printing

the "_FillValues" where LU_INDEX=1. Could you please advise me what should be

the remaining lines to complete the script.


Your cooperation will be highly appreciated.


Kind regards,

Imran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170403/84cf42b8/attachment.html 


More information about the ncl-talk mailing list