San-Diego-WX
San-Diego-WX

Reputation: 235

NCO: Copying data from one netcdf file into another only for a specific area

I have two NetCDF files with the exact same dimensions (time,lat,lon). Below is the header of one of the files.

netcdf file1 {
dimensions:
        lon = 360 ;
        lat = 177 ;
        time = 360 ;
variables:
        double lon(lon) ;
                lon:units = "degrees_east" ;
                lon:long_name = "Longitude" ;
        double lat(lat) ;
                lat:units = "degrees_north" ;
                lat:long_name = "Latitude" ;
        double time(time) ;
                time:long_name = "Time" ;
                time:units = "months since 1989-05-01 00:00" ;
        double tmp(time, lat, lon) ;
                tmp:_FillValue = -999000000. ;
}

I would like to copy values from one file into the other, but only for a small region determined by lat1,lat2 and lon1,lon2. Both files have the same time coordinates.

Something like: (lon1<lon<=lon2) & (lat1<lat<=lat2) file1 = file2

I was wondering if I could do that with NCO.

Any help will be appreciated. Thank

Upvotes: 1

Views: 1476

Answers (1)

Charlie Zender
Charlie Zender

Reputation: 6352

Read the manual section on the ncap2 where function. It describes how to use where on a hyperslab. That will do it:

*var_tmp=var2(:,0,:,:); 
where (var1 < 0.5) var_tmp=1234; 
var2(;,0,:,;)=var_tmp;

Upvotes: 2

Related Questions