Global Index (short | long) | Local contents | Local Index (short | long)
Open netcdf file. First execute the command (on hayes): cp temp_A_L1_1000_years.nc biff2.nc ! ncks -x -v depth,temp,year biff2.nc biff.nc
This script calls | |
---|---|
clear cd /home/disk/hayes2/dvimont/csiro/data ! rm biff.nc % oldfid = ncmex('OPEN', 'biff2.nc', 'NC_NOWRITE') [cdfid, rcode] = ncmex('CREATE', 'biff.nc', 'NC_CLOBBER') % Get existing netcdf [ndims, nvars, natts, recdim, status] = ncmex('INQUIRE', oldfid) for i = 1:ndims [name, length, status] = ncmex('DIMINQ', oldfid, (i-1)); if strcmp(name, 'depth'); status = ncmex('DIMDEF', cdfid, name, 10); eval(['l' num2str(i) ' = 10;']); elseif strcmp(name, 'year'); status = ncmex('DIMDEF', cdfid, name, 'UNLIMITED'); eval(['l' num2str(i) ' = 1000;']); else status = ncmex('DIMDEF', cdfid, name, length); eval(['l' num2str(i) ' = ' num2str(length) ';']); end end len = [l1 l2 l3 l4]; for i = 1:nvars [name, datatype, ndims, dim, natts, status] = ncmex('VARINQ', oldfid, (i-1)); if status == -1; error(['1 Problem with variable: ' name]); end; status = ncmex('VARDEF', cdfid, name, datatype, ndims, dim); if status == -1; error(['2 Problem with variable: ' name]); end; for j = 1:natts; [attname, status] = ncmex('ATTNAME', oldfid, (i-1), (j-1)); if status == -1; error(['1 Problem with attribute: ' attname ' ' name]); end; status = ncmex('ATTCOPY', oldfid, (i-1), attname, cdfid, (i-1)); if status == -1; error(['2 Problem with attribute: ' attname ' ' name]); end; end end status = ncmex('CLOSE', cdfid) cdfid = ncmex('OPEN', 'biff.nc', 'NC_WRITE') for i = 1:nvars; [name, datatype, ndims, dim, natts, status] = ncmex('VARINQ', oldfid, (i-1)); if status == -1; error(['1 Problem i = ' num2str(i)]); end; if ~any([strcmp(name, 'depth') ... strcmp(name, 'temp') strcmp(name, 'dtts')]); [value, status] = ncmex('VARGET', oldfid, (i-1), zeros(1, ndims), len(dim+1)); if status == -1; error(['2 Problem name = ' name]); end; status = ncmex('VARPUT', cdfid, (i-1), zeros(1, ndims), len(dim+1), value); if status == -1; error(['3 Problem name = ' name]); end; end end status = ncmex('CLOSE', cdfid) status = ncmex('CLOSE', oldfid) ! ncks -A -v dtts biff2.nc biff.nc clear cd /home/disk/hayes2/dvimont/csiro/data nc2 = netcdf('biff.nc', 'write'); for i = 1:10; filin = ['temp_A_L' num2str(i) '_1000_years.nc']; nc1 = netcdf(filin, 'nowrite'); depth = nc1{'depth'}(:); temp1 = nc1{'temp'}(:,1,:,:); nc1 = close(nc1); nc2{'depth'}(i) = depth; nc2{'temp'}(:,i,:,:) = temp1; end