How can I obtain time seris data from ECMWF netcdf file
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello all,
I am trying to get time series data from daily ECMWF netcdf file at exact location. I want to do that for multiple files located in a folder and write to results on excel sheet. My code and error are given below.
Thanks!
clc
clear all
folder='C:/Users/kullanici/Documents/MATLAB/PBL-Daily-1200-2017';
filetype='*.nc';
f=fullfile(folder,filetype);
d=dir(f);
LT=41.25;LG=21.25;
for i=1:numel(d);
blh(i)=ncread([fullfile(folder,d(i).name)],'blh');
lon(i)=ncread([fullfile(folder,d(i).name)],'longitude');
lat(i)=ncread([fullfile(folder,d(i).name)],'latitude');
time1(i)=ncread([fullfile(folder,d(i).name)],'time');
end
for i=1:numel(d);
time(i)=double(time1);
[TEMP,a2]=min(abs(lon(i)-LG));
[TEMP,a1]=min(abs(lat(i)-LT));
blh_ist(i)=blh(a2,a1,:);
BLH(i)=blh_ist(:);
AA(i)=datestr(time(i)./24+datenum('1900-01-01 0:0:0'));
AA(i)=datenum(AA(i));
AA(i)=datenum(AA(i));
yy(i)=year(AA(i));mm(i)=month(AA(i));dd(i)=day(AA(i));hh(i)=hour(AA(i));
date1(i)=[yy mm dd hh];
end
for i=1:numel(d);
filename='PBL_12.xlsx';
sheet = 1;
xlswrite(filename,date1(i),sheet,'A2')
xlswrite(filename,BLH(i),sheet,'E2')
end
ERROR: Subscripted assignment dimension mismatch.
Error in PBL (line 9)
blh(i)=ncread([fullfile(folder,d(i).name)],'blh');
0 commentaires
Réponses (2)
KSSV
le 27 Fév 2019
YOur data read shoule be a matrix or array..you cannot store them like the way you did. YOu shoule do as below:
clc
clear all
folder='C:/Users/kullanici/Documents/MATLAB/PBL-Daily-1200-2017';
filetype='*.nc';
f=fullfile(folder,filetype);
d=dir(f);
LT=41.25;LG=21.25;
N = numel(d) ;
blh = cell(N,1) ;
lon = cell(N,1) ;
lat = cell(N,1) ;
time1 = cell(N,1) ;
for i=1:N
blh{i}=ncread([fullfile(folder,d(i).name)],'blh');
lon{i}=ncread([fullfile(folder,d(i).name)],'longitude');
lat{i}=ncread([fullfile(folder,d(i).name)],'latitude');
time1{i}=ncread([fullfile(folder,d(i).name)],'time');
end
If all the variables in each file has same dimensions..you can save them into a matrix. As I am not aware of the dimensions, I have stored them into a cell.
0 commentaires
sujan ghimire
le 21 Déc 2020
I have below information from NetCDF file, how can i covert to CSV or XLS for specific Lat long.
ei.oper.an.sfc.regn128sc.hcc_188.201107.ghimire463266.nc
Format:
64bit
Global Attributes:
creation_date = 'Sat Dec 19 05:45:16 MST 2020'
NCL_Version = '6.6.2'
system = 'Linux casper34 3.10.0-1127.18.2.el7.x86_64 #1 SMP Sun Jul 26 15:27:06 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux'
Conventions = 'None'
grib_source = 'ei.oper.an.sfc.regn128sc.hcc_188.201107.ghimire463266.grb'
title = 'NCL: convert-GRIB-to-netCDF'
Dimensions:
initial_time0_hours = 124 (UNLIMITED)
g4_lat_1 = 256
g4_lon_2 = 512
ncl_strlen_0 = 18
Variables:
HCC_GDS4_SFC
Size: 512x256x124
Dimensions: g4_lon_2,g4_lat_1,initial_time0_hours
Datatype: single
Attributes:
forecast_time_units = 'hours'
forecast_time = 0
parameter_number = 188
parameter_table_version = 128
gds_grid_type = 4
level_indicator = 1
_FillValue = 1.000000020040877e+20
units = '(0 - 1)'
long_name = 'High cloud cover'
center = 'European Center for Medium-Range Weather Forecasts (RSMC)'
initial_time0_hours
Size: 124x1
Dimensions: initial_time0_hours
Datatype: double
Attributes:
units = 'hours since 1800-01-01 00:00'
long_name = 'initial time'
initial_time0_encoded
Size: 124x1
Dimensions: initial_time0_hours
Datatype: double
Attributes:
units = 'yyyymmddhh.hh_frac'
long_name = 'initial time encoded as double'
g4_lat_1
Size: 256x1
Dimensions: g4_lat_1
Datatype: single
Attributes:
La1 = 89.463
Lo1 = 0
La2 = -89.463
Lo2 = 359.297
Di = 0.70313
N = 128
units = 'degrees_north'
GridType = 'Gaussian Latitude/Longitude Grid'
long_name = 'latitude'
g4_lon_2
Size: 512x1
Dimensions: g4_lon_2
Datatype: single
Attributes:
La1 = 89.463
Lo1 = 0
La2 = -89.463
Lo2 = 359.297
Di = 0.70313
N = 128
units = 'degrees_east'
GridType = 'Gaussian Latitude/Longitude Grid'
long_name = 'longitude'
initial_time0
Size: 18x124
Dimensions: ncl_strlen_0,initial_time0_hours
Datatype: char
Attributes:
NCL_converted_from_type = 'string'
units = 'mm/dd/yyyy (hh:mm)'
long_name = 'Initial time of first record'
Variable names are:
HCC_GDS4_SFC
initial_time0_hours
initial_time0_encoded
g4_lat_1
g4_lon_2
initial_time0
0 commentaires
Voir également
Catégories
En savoir plus sur NetCDF dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!