netcdf file lon lat extraction

2 views (last 30 days)
sensation
sensation on 24 Apr 2018
Edited: sensation on 24 Apr 2018
Hi there,
I have a huge netcdf file that does not allow me to read 'dis' variable (time, lat, lon). What i want is to extract only those cells from cooling.txt file. Here is the summary of my code:
%read txt file for lat lon extraction
fid = fopen('...cooling.txt', 'r');
max_num_col = 3;
format = repmat('%f',1,max_num_col);
Ab = textscan(fid,format,'HeaderLines',0,'Delimiter','');
frewind(fid);
tline = fgets(fid);
fclose(fid);
lon1=Ab{1,1};
lat1=Ab{1,2};
id=Ab{1,3};
%read netcdf file
ncid = netcdf.open('dis.nc','NC_NOWRITE');
lat=ncread('dis.nc','lat');
whos lat
lon=ncread('dis.nc','lon');
whos lon
time=ncread('dis.nc','time');
%disch=ncread('dis.nc','dis'); % FILE TOO BIG TO BE READ
Results:
For example I want to have disch1.txt that will have all values of variable dis wit lon=6.85 and lat=4.75; then disch2 that corresponds to ID 2 in cooling.txt with lon=7.15 and lat=4.75 and so on FOR ALL TIME STEPS.
Thought:
disch1 = ncread('dis.nc','dis',...
[lon1(1,1) lat1(1,1)], [Inf Inf]);
dis.nc file display:
if true
Format:
netcdf4
Dimensions:
lon = 695
lat = 721
time = 12419 (UNLIMITED)
Variables:
dis
Size: 695x721x12419
Dimensions: lon,lat,time
Datatype: single
Attributes:
_FillValue = -9999
standard_name = 'DischargeMaps'
long_name = 'ChanQAvg'
units = 'm3/s'
esri_pe_string = 'GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.0174532925199433]]'
end
Thanks a lot!

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!