This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Hi Fereshte, > i am newbie with netcdf files manipulate. my aim is adding 3 variables( > which all of them are in 3 different netcdf files) with fourth netcdf file. > all of 4 files have same time step, longitude and latitude. but i cant fine > any way to do that. is it possible to do that with MATLAB? if it is, would > you please tell me how. or if there is other way please guide me. i prefer > to say that i have installed NCL too. I;m confident it's possible to do what you want with MATLAB, but I can't tell you exactly how, as we don't have a platform on which MATLAB is available, and we didn't develop or maintain the MATLAB netCDF interface. However, I can summarize how I would do it in C, and a similar approach should work for MATLAB: Call the variables var1, var2, var3, and var4, in files file1.nc, file2.nc, file3.nc, and file4.nc, respectively. (Use a copy of file4.nc, so that you don't clobber the file4 data in case of a mistake.) Open file4.nc for writing (involves a call to nc_open(...) ). Put it in "define mode" with a call to nc_def(...). In file4.nc, define var1, var2, and var3, using existing dimensions already defined in file4.nc. This involves 3 calls to nc_create_var(...). Leave file4.nc open, but exit define mode, with a call to nc_enddef(...). Open file1.nc for reading, using nc_open(...). Read the data from var1 into an array in memory, using nc_get_var_double(...) if it all fits in memory at once, or in slices using or nc_get_vara_double(...) otherwise. After you read each variable or slice into an array, write it to out to the corresponding variable in file4.nc, using nc_put_var_double(...) or nc_put_vara_double(...). If the data is not of type double, use the appropriate type. Close file1.nc. Now repeat the last step for var2 from file2.nc and var3 from file3.nc. Close file4.nc --Russ Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: WHV-523215 Department: Support netCDF Priority: Normal Status: Closed