2017-03-21 47 views
1

我有一個包含netCDF文件4-d的變量:無法修改特定變量值在特定維中的NetCDF

variables: 
    double maxvegetfrac(time_counter, veget, lat, lon) ; 
     maxvegetfrac:_FillValue = 1.00000002004088e+20 ; 
     maxvegetfrac:history = "From Topo.115MaCTRL_WAM_360_180" ; 
     maxvegetfrac:long_name = "Vegetation types" ; 
     maxvegetfrac:missing_value = 1.e+20f ; 
     maxvegetfrac:name = "maxvegetfrac" ; 
     maxvegetfrac:units = "-" ; 

    double mask_veget(time_counter, veget, lat, lon) ; 
     mask_veget:missing_value = -1.e+34 ; 
     mask_veget:_FillValue = -1.e+34 ; 
     mask_veget:long_name = "IF MYVEG4 EQ 10 AND I GE 610 AND J GT 286 THEN 16 ELSE MYVEG4" ; 
     mask_veget:history = "From desert_115Ma_3" ; 

我想使用變量「mask_veget」作爲掩模,以改變的值特定區域上的變量「maxvegetfrac」以及其「veget」維度的選定值。 爲此,我使用ncap2。例如,如果我想在veget維度的第5等級設置maxvegetfrac值500,其中mask_veget等於6,我做的:

> ncap2 -s "where (mask_veget(:,:,:,:)== 6) maxvegetfrac(:,5,:,:) = 500" test.nc 

我的問題是,在產生test.nc文件,maxvegetfrac已被修改在「素」維的第一級,而不是第五級。如果我在整個素尺寸上運行腳本,我會得到相同的結果:

ncap2 -s "where (mask_veget(:,:,:,:)== 6) maxvegetfrac(:,:,:,:) = 500" test.nc 

所以我錯了某個地方,但是......在哪裏? 任何幫助表示讚賞!

回答

1

你可能不知道的幾件事 你不應該在哪裏體驗hyperslabbing變量 - 目前沒有意義。

這是確定在哪裏聲明證明了其單一指數 爲暗淡的一個單個值hyperslab崩潰

試試這個:

/*** hyper.nco *****/ 
maxvegetfrac5=maxvegetfrac(:,5,:,:); 

where(mask_veget(:,5,:,:)== 6) 
    maxvegetfrac5=500.0; 

/* put the hyperslab back in */ 
maxvegetfrac(:,5,:,:)=maxvegetfrac5; 
/* script end *****/ 

現在用命令運行腳本

ncap2 -v -O -S hyper.nco test.nc out.nc 

...亨利

+0

非常感謝你。它工作完美。 –