fin = 'biotoy_ini_ecosim.nc' fout = 'biotoy_ini_ecosim_32x32.nc'; % created with ncgen -b on a modifed cdl file % get structure of nc file - use this to find list of variables s = nc_info(fout); % get dimensions of target xi_rho = nc_getdiminfo(fout,'xi_rho'); eta_rho = nc_getdiminfo(fout,'eta_rho'); % step through all 3D variables that new copying to the new file % 15,16 are temp,salt % 22:84 are all the ecosim variables for i = [15 16 22:84] vname = char(s.DataSet(i).Name); disp(['doing ' vname]) % get vertical vector datain = nc_varget(fin,vname,[0 0 0 0],[1 -1 1 1]); % copy it to all i,j index values dataout = repmat(datain,[1 1 eta_rho xi_rho]); % write to the new file nc_varput(fout,vname,dataout) end