From 58b497110df0e3961b9327b2d215cfa4881bc76a Mon Sep 17 00:00:00 2001 From: Olivier Sauter <Olivier.Sauter@epfl.ch> Date: Wed, 27 Jan 2021 09:05:38 +0100 Subject: [PATCH] add gas, gash for JET and fix cdf2mat for ASTRA cdf file as well --- matlab/CHDF/cdf2mat.m | 77 ++++++++++++++++++++++--------- matlab/JET/jet_requests_mapping.m | 5 ++ 2 files changed, 61 insertions(+), 21 deletions(-) diff --git a/matlab/CHDF/cdf2mat.m b/matlab/CHDF/cdf2mat.m index 22eaf3b7..c9d7a14e 100644 --- a/matlab/CHDF/cdf2mat.m +++ b/matlab/CHDF/cdf2mat.m @@ -47,16 +47,31 @@ for i=1:length(coordnames_sorted) matcdf.coords(i).index_allvarnames = strmatch(matcdf.coords(i).name,allvarnames,'exact'); matcdf.coords(i).index_varnames_sorted = strmatch(matcdf.coords(i).name,varnames_sorted,'exact'); matcdf.coords(i).varid = allvarids(matcdf.coords(i).index_allvarnames); - if strcmp(allinfo.Variables(matcdf.coords(i).index_allvarnames).Datatype,'single') - matcdf.coords(i).data = netcdf.getVar(funnetcdf,matcdf.coords(i).varid,'double'); + if ~isempty(matcdf.coords(i).index_allvarnames) + if strcmp(allinfo.Variables(matcdf.coords(i).index_allvarnames).Datatype,'single') + matcdf.coords(i).data = netcdf.getVar(funnetcdf,matcdf.coords(i).varid,'double'); + else + matcdf.coords(i).data = netcdf.getVar(funnetcdf,matcdf.coords(i).varid); + end + for ij=1:length(fields_variables_to_copy) + matcdf.coords(i).(fields_variables_to_copy{ij}) = allinfo.Variables(matcdf.coords(i).index_allvarnames).(fields_variables_to_copy{ij}); + end + for jj=1:numel(allinfo.Variables(matcdf.coords(i).index_allvarnames).Attributes) + if strcmp(lower(allinfo.Variables(matcdf.coords(i).index_allvarnames).Attributes(jj).Name),'units') + matcdf.coords(i).units = strtrim(allinfo.Variables(matcdf.coords(i).index_allvarnames).Attributes(jj).Value); + end + if strcmp(lower(allinfo.Variables(matcdf.coords(i).index_allvarnames).Attributes(jj).Name),'long_name') + matcdf.coords(i).long_name = strtrim(allinfo.Variables(matcdf.coords(i).index_allvarnames).Attributes(jj).Value); + end + end else - matcdf.coords(i).data = netcdf.getVar(funnetcdf,matcdf.coords(i).varid); - end - for ij=1:length(fields_variables_to_copy) - matcdf.coords(i).(fields_variables_to_copy{ij}) = allinfo.Variables(matcdf.coords(i).index_allvarnames).(fields_variables_to_copy{ij}); + matcdf.coords(i).data = []; + for ij=1:length(fields_variables_to_copy) + matcdf.coords(i).(fields_variables_to_copy{ij}) = []; + end + matcdf.coords(i).units = ''; + matcdf.coords(i).long_name = [matcdf.coords(i).name ' empty']; end - matcdf.coords(i).units = strtrim(allinfo.Variables(matcdf.coords(i).index_allvarnames).Attributes(1).Value); - matcdf.coords(i).long_name = strtrim(allinfo.Variables(matcdf.coords(i).index_allvarnames).Attributes(2).Value); matcdf.coords(i).label = [matcdf.coords(i).name ' ' num2str(matcdf.coords(i).Size) ': ' matcdf.coords(i).long_name]; cdf2mat_out.coords.(matcdf.coords(i).name) = matcdf.coords(i); end @@ -65,16 +80,31 @@ for i=1:length(varnames_sorted) matcdf.vars(i).name = varnames_sorted{i}; matcdf.vars(i).index_allvarnames = strmatch(matcdf.vars(i).name,allvarnames,'exact'); matcdf.vars(i).varid = allvarids(matcdf.vars(i).index_allvarnames); - if strcmp(allinfo.Variables(matcdf.vars(i).index_allvarnames).Datatype,'single') - matcdf.vars(i).data = netcdf.getVar(funnetcdf,matcdf.vars(i).varid,'double'); + if ~isempty(matcdf.vars(i).index_allvarnames) + if strcmp(allinfo.Variables(matcdf.vars(i).index_allvarnames).Datatype,'single') + matcdf.vars(i).data = netcdf.getVar(funnetcdf,matcdf.vars(i).varid,'double'); + else + matcdf.vars(i).data = netcdf.getVar(funnetcdf,matcdf.vars(i).varid); + end + for ij=1:length(fields_variables_to_copy) + matcdf.vars(i).(fields_variables_to_copy{ij}) = allinfo.Variables(matcdf.vars(i).index_allvarnames).(fields_variables_to_copy{ij}); + end + for jj=1:numel(allinfo.Variables(matcdf.vars(i).index_allvarnames).Attributes) + if strcmp(lower(allinfo.Variables(matcdf.vars(i).index_allvarnames).Attributes(jj).Name),'units') + matcdf.vars(i).units = strtrim(allinfo.Variables(matcdf.vars(i).index_allvarnames).Attributes(jj).Value); + end + if strcmp(lower(allinfo.Variables(matcdf.vars(i).index_allvarnames).Attributes(jj).Name),'long_name') + matcdf.vars(i).long_name = strtrim(allinfo.Variables(matcdf.vars(i).index_allvarnames).Attributes(jj).Value); + end + end else - matcdf.vars(i).data = netcdf.getVar(funnetcdf,matcdf.vars(i).varid); - end - for ij=1:length(fields_variables_to_copy) - matcdf.vars(i).(fields_variables_to_copy{ij}) = allinfo.Variables(matcdf.vars(i).index_allvarnames).(fields_variables_to_copy{ij}); + matcdf.vars(i).data = []; + for ij=1:length(fields_variables_to_copy) + matcdf.vars(i).(fields_variables_to_copy{ij}) = []; + end + matcdf.vars(i).units = ''; + matcdf.vars(i).long_name = [matcdf.vars(i).name ' empty']; end - matcdf.vars(i).units = strtrim(allinfo.Variables(matcdf.vars(i).index_allvarnames).Attributes(1).Value); - matcdf.vars(i).long_name = strtrim(allinfo.Variables(matcdf.vars(i).index_allvarnames).Attributes(2).Value); matcdf.vars(i).label = matcdf.vars(i).name; for j=1:length(matcdf.vars(i).Dimensions) ij = strmatch(matcdf.vars(i).Dimensions(j).Name,coordnames_sorted,'exact'); @@ -93,13 +123,18 @@ for i=1:length(varnames_sorted) matcdf.vars(i).label = [matcdf.vars(i).label ': ' matcdf.vars(i).long_name ' [' matcdf.vars(i).units ']']; cdf2mat_out.allvars.(matcdf.vars(i).name) = matcdf.vars(i); end -top_attr_names = {allinfo.Attributes(:).Name}; -ij = strmatch('shot',top_attr_names,'exact'); -cdf2mat_out.shot = allinfo.Attributes(ij).Value; +if ~isempty(allinfo.Attributes) + top_attr_names = {allinfo.Attributes(:).Name}; + ij = strmatch('shot',top_attr_names,'exact'); + cdf2mat_out.shot = allinfo.Attributes(ij).Value; +else + cdf2mat_out.shot = NaN; +end cdf2mat_out.fname = pfname; -cdf2mat_out.id = pfname(length(pfname)-11:length(pfname)-4); +[a1,a2,a3]=fileparts(pfname); +cdf2mat_out.id = a2; -netcdf.close(funnetcdf); + netcdf.close(funnetcdf); clear matcdf return diff --git a/matlab/JET/jet_requests_mapping.m b/matlab/JET/jet_requests_mapping.m index f96b106d..4ed7576f 100644 --- a/matlab/JET/jet_requests_mapping.m +++ b/matlab/JET/jet_requests_mapping.m @@ -101,6 +101,11 @@ switch lower(data_request) mapping.gdat_timedim = 2; mapping.method = 'switchcase'; % could use function make_eqdsk directly? mapping.expression = ''; + case {'gas','gasm','gash','eler'} + mapping.label = 'eler'; + mapping.timedim = 1; + mapping.method = 'signal'; + mapping.expression = [{'ppf'},{'gash'},{'eler'}]; case 'halpha' mapping.label = 'Halpha'; mapping.timedim = 1; -- GitLab