У меня есть скрипт, который устанавливает файл nc из некоторых текстовых файлов и фреймов успеха.Я получаю сообщение об ошибке: преобразование чисел невозможно представить, что указывает на проблему с типом данных.Если да, то как бы я проверил тип данных и изменил его?
Я пытался использовать другой диапазон входных папок с той же проблемой
clear
clc
close all
cd D:\wass\WASS_Rohinee\Post_Processing\IMU_kalman_WASS
javaaddpath([pwd '/netcdfAll-4.6.14.jar']);
javaaddpath ([pwd '/mexcdf/snctools/classes']);
addpath ([pwd '/mexcdf/mexnc']);
addpath ([pwd '/mexcdf/snctools']);
%
%%
load('D:\wass\test\output_12351\success_frames.mat')
%% READ SETUP FILE (check last available version)
%-----------------------------
%%%%% SETUP FILE
%-----------------------------
setup_file='D:\wass\test\output_12351\setup_pp_gridding_antartide.txt';
%-----------------------------
%%%%% DISPLAY FOR EDITING
%-----------------------------
edit(setup_file)
%-----------------------------
%%%%% CHECK VALUES
%-----------------------------
sprintf('check setup file')
%-----------------------------
%%%%% READ PARAMETERS
%-----------------------------
fid = fopen(setup_file);
clear setup
for ii=1:27 % stop to 21 if we use older version without IMU option
setup{ii}=fscanf(fid, '%s\n', [1]);
end
fclose(fid);
%-----------------------------
%%%%% STORE PARAMETERS
%-----------------------------
dummy=setup{1}; data=dummy(30:end);
dummy=setup{2}; dir_3d=dummy(8:end);
dummy=setup{3}; event_3d=dummy(10:end);
dummy=setup{4}; date_acq_list=dummy(15:end);
dummy=setup{5}; dir_pp=dummy(8:end);
dummy=setup{6}; fps=eval(dummy(5:end));
dummy=setup{7}; dir_ster_imm=dummy(14:end);
dummy=setup{8}; dxy=eval(dummy(8:end));
dummy=setup{9}; x_min=eval(dummy(10:end));
dummy=setup{10}; x_max=eval(dummy(10:end));
dummy=setup{11}; y_min=eval(dummy(10:end));
dummy=setup{12}; y_max=eval(dummy(10:end));
dummy=setup{13}; scale=eval(dummy(10:end));
dummy=setup{14}; step=eval(dummy(6:end));
dummy=setup{15}; iniz_datum=eval(dummy(12:end));
dummy=setup{16}; fin_datum=eval(dummy(11:end));
dummy=setup{17}; desp_cycle=eval(dummy(12:end));
dummy=setup{18}; if_plot=eval(dummy(9:end));
dummy=setup{19}; if_ncnew=eval(dummy(10:end));
dummy=setup{20}; if_ncadd=eval(dummy(10:end));
dummy=setup{21}; if_mat=eval(dummy(8:end));
%-----------------------------
%%%%% x IMU
%-----------------------------
dummy=setup{22}; if_imu=eval(dummy(8:end));
dummy=setup{23}; x_min_imu=eval(dummy(14:end));
dummy=setup{24}; x_max_imu=eval(dummy(14:end));
dummy=setup{25}; y_min_imu=eval(dummy(14:end));
dummy=setup{26}; y_max_imu=eval(dummy(14:end));
dummy=setup{27}; file_imu=(dummy(10:end));
%-----------------------------
%%%%% PREPARE FOLDERS
%-----------------------------
dir_imm=[dir_pp 'imm'] %TO STORE IMAGES
str=['mkdir ' dir_imm]
unix(str)
dir_nc=[dir_pp 'nc'] %TO STORE NC FILE
str=['mkdir ' dir_nc]
unix(str)
%-----------------------------
%%%%% DATE OF ACQUISITION
%-----------------------------
date_acq=
datenum(eval(date_acq_list(1:4)),eval(date_acq_list(5:6)),
eval(date_acq_list(7:8)),...
eval(date_acq_list(10:11)),eval(date_acq_list(12:13)),
eval(date_acq_list(14:15)));
quanti=-iniz_datum+fin_datum;
%-----------------------------
%%%%% PLOT TYPE (image requires correct link to right-camera images)
%-----------------------------
plotto='surf';
plotto='image';
if strcmp(plotto,'image') & if_plot==1 & numel(dir_ster_imm)>0
cd(dir_ster_imm)
d_imm=dir('*.tif');
end
%-----------------------------
%%%%% LIST OF 3D OUTPUT FOLDERS
%-----------------------------
cd([dir_3d event_3d '' ''])
d=dir('*_wd');
cd ..
%% READ IMU DATA (if any)
if if_imu==1
cd(dir_pp)
filen=file_imu;
read_Hydrins_IMU_Hulliburton_fun
end
%% CREATE NC FILE
%NCNEW: NC IS CREATED AND DATA ARE ADDED
%NCADD: DATA ARE ADDED
%-----------------------------
%%%%% X,Y GRID
%-----------------------------
xn = x_min:dxy:x_max;
yn = y_min:dxy:y_max;
[xnn,ynn]=meshgrid(xn,yn); %grid for triangulation
xnn_grid=xnn;ynn_grid=ynn;
%-----------------------------
%%%%% X,Y GRID FOR IMU DATA
%-----------------------------
if if_imu==1
xn_imu = x_min_imu:dxy:x_max_imu;
yn_imu = y_min_imu:dxy:y_max_imu;
[xnn_imu,ynn_imu]=meshgrid(xn_imu,yn_imu); %grid for triangulation
end
%-----------------------------
%%%%% CREATE NC
%-----------------------------
if if_ncnew==1 | if_ncadd==1
oufile=sprintf('wass__%s_step%02.0f.nc',date_acq_list,step); % NC
FILENAME WITH DATE AND STEP
end
%-----------------------------
%%%%% ADD DATA TO NC
%-----------------------------
if if_ncnew==1 % ONLY IF NCNEW THE FILE IS CREATED AND STORED
cd(dir_nc)
%%% xyz in mm ___________________________________________________
if if_imu==0
filone2netcdf_02_create_v2(oufile,numel(yn),numel(xn));
%%% xyz in mm _________________________________
nc_varput(oufile,'X_grid', xnn*1000)% in mm
nc_varput(oufile,'Y_grid', ynn*1000) % in mm
nc_varput(oufile,'fps', fps) % in hz
nc_varput(oufile,'datenum', date_acq) % matlab datenum
nc_varput(oufile,'dxy', dxy*1000)% in mm
nc_varput(oufile,'scale', scale)% in mm
%-----------------------------
%%%%% IF IMU
%-----------------------------
elseif if_imu==1
filone2netcdf_02_create_v2(oufile,numel(yn_imu),numel(xn_imu));
%%% xyz in mm _________________________________
nc_varput(oufile,'X_grid', xnn_imu*1000)% in mm
nc_varput(oufile,'Y_grid', ynn_imu*1000) % in mm
nc_varput(oufile,'fps', fps) % in hz
nc_varput(oufile,'datenum', date_acq) % matlab datenum
nc_varput(oufile,'dxy', dxy*1000)% in mm
nc_varput(oufile,'scale', scale)% in mm
end
end
%% CYCLE OVER 3-D SCATTER DATA
%-----------------------------
%%%%% Z-MASK (WILL BE UPDATED TO INCLUDE THE AREA COMMON TO EVERY 3-D)
%-----------------------------
mask_zz_put=ones(size(xnn,1),size(xnn,2));
% in case of IMU
if if_imu==1
mask_zz_put=ones(size(xnn_imu,1),size(xnn_imu,2));
end
% start from the iniz_datum (important for restart)
conta=0; %if the first dir starts with a number larger than 0, it does'n
work
%-----------------------------
%%%%% CYCLE
%-----------------------------
% prepare log file and mat file for data
fileID = fopen('log_pp.txt','w');
log_mat=[];
for ii=data_frames_success2(3201:3251)
conta=conta+1; %up-date conta variable to fill nc file
%write log
fprintf(fileID,'Output: %6.0f; ',ii);
% take time for processing
tic
%-----------------------------
%%%%% MOVE INTO THE CURRENT DIR
%-----------------------------
sprintf('+++++++++++++++++++++++++++')
cd([dir_3d event_3d '' '']);
%-----------------------------
%%%% LOAD XYZ DATA. OPTIONS AVAILABLE
%-----------------------------
%%%%%% ------------------------------------------------------------
if strcmp(data,'align') % load here 3-D aligned with the sea
% 1) ALIGN: 3-D HAVE BEEN ROTATED ACCORDINGLY TO THE MEAN PLANE
ii
sprintf('usato AVG plane to generate mesh_aligned.xyzbin ?');
piano='plane_avg_mid.txt'
dir_planes= 'D:\wass\test\output_12351\out';
D_planes=dir('D:\wass\test\output_12351\out\\
0*_wd_RT_imu_VSTD_0.5.txt');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
cd(sprintf('%06.0f_wd',ii));
sprintf('%06.0f_wd',ii)
mesh_cam = load_camera_mesh();
mesh_cam=mesh_cam*scale;
n_pts = size(mesh_cam,2);
cd(dir_planes)
plane=load(D_planes(ii).name); %conta replacement
D_planes(ii).name %conta replacement
R=plane(1:3,1:3)
T=plane(1:3,4)
%Rotate, translate
mesh=R*mesh_cam + repmat(T,1,n_pts);
mesh=mesh';
% Invert z axis
mesh(:,3)=mesh(:,3)*-1.0;
xyz_iniz=mesh;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%write log
fprintf(fileID,'npts: %6.0f; ',size(mesh,1));
log_mat(ii,1)=size(xyz_iniz,1); %conta replacement
%%%%%% -----------------------------------------------------
elseif strcmp(data,'cam_ptf') %for cam_ptf we must load _avg planes
elseif strcmp(data,'cam_ship')
end
%-----------------------------
%%%% LOAD P0 ONLY FOR PLOTTING PURPOSES
%-----------------------------
if strcmp(data,'cam_ship');
% cd(d(ii).name);
P0=load('P0.txt') %P0 is for right camera (P: xy 2 ij to project
data onto the image plane)
elseif strcmp(data,'cam_ptf');
% cd(d(ii).name);
P0=load('P0.txt'); %A rigire dovrei caricare PO_AVG
end
%% SPIKE REMOVAL
%1) keep only xy data within the GRIDDED XY area
%2) subsample to reduce data close the cameras (step parameters is
used
%here)
%3) remove 3D such that z > th*std(z), 10 AND -7
%4) despyking (desp_cycle is used here)
%-----------------------------
% 1) keep only xy data within the gridding area
%-----------------------------
gg=find(xyz_iniz(:,1)>xn(1)-1 & xyz_iniz(:,1)<xn(end)+1 & ...
xyz_iniz(:,2)>yn(1)-1 & xyz_iniz(:,2)<yn(end)+1);
xyz_iniz=xyz_iniz(gg,:);
%
figure,deci=1;plot(xyz_iniz(1:deci:end,1),xyz_iniz(1:deci:end,2),'.r');
fprintf(fileID,'area selection: %6.0f; ',size(xyz_iniz,1));
log_mat(ii,2)=size(xyz_iniz,1); %conta replacement
%-----------------------------
% 2) subsample to reduce data close the cameras (step parameters is
% used here)
%-----------------------------
if step==1
xyz=xyz_iniz;
else
%%%% sottocampiono i dati con una funzione lineare sulle y tra 1
%%%% (lontano, dove tengo tutti i punti) e step (vicino)
dummy=((yn(end)-yn(1))/step);
y_min=yn(1)-0.1;
xyz=[];
step_d=1;
for ss=1:step+1
g=find(xyz_iniz(:,2)>=y_min & xyz_iniz(:,2)<y_min+dummy);
xyz=[xyz;xyz_iniz(g(1:step_d:end),:)];
%hold on,plot(xyz(:,1),xyz(:,2),'xb')
y_min=y_min+dummy;
step_d=step_d+1;
end
end
fprintf(fileID,'stepping: %6.0f; ',size(xyz,1));
log_mat(ii,3)=size(xyz,1); %conta replacement
%-----------------------------
%%%%3) remove 3D such that z > th*std(z)
%-----------------------------
for tt=1
bb=find( abs(xyz(:,3)) > 8*std(xyz(:,3)));
xyz(bb,:)=[];
%%%%
end
fprintf(fileID,'th. on std: %6.0f; ',size(xyz,1));
log_mat(ii,4)=size(xyz,1); %conta replacement
%-----------------------------
for ss=1:desp_cycle
%[fo, ip] = func_despike_phasespace3d_ab(xyz(:,3));
[fo, ip] = func_despike_phasespace3d(xyz(:,3));
xyz(ip,:)=[];
clear fo ip;
% plot3(xyz(1:deci:end,1),xyz(1:deci:end,2),xyz(1:deci:end,3),'.r')
end
fprintf(fileID,'despiking: %6.0f\n ',size(xyz,1));
log_mat(ii,5)=size(xyz,1); %conta replacement
%-----------------------------
%%%% datum to be used
%-----------------------------
xyz_iniz=xyz;
%% if IMU converto to geo ccordinates
if if_imu==1
xyz_geo=xyz_iniz;
xyz_geo(:,2)=-xyz_geo(:,2);
xyz_geo(:,1)=+xyz_geo(:,1);
xyz_geo=xyz_geo';
%%% correction for ship movement
q=heading(ii)-90;
% rotation matrix
R=[[cosd(q) sind(q)];[-sind(q) cosd(q)]];
xyz_geo(1:2,:)=R*xyz_geo(1:2,:);
xyz_geo=xyz_geo';
xyz_geo(:,2)=xyz_geo(:,2)+lat_d_m(ii);
xyz_geo(:,1)=xyz_geo(:,1)+lon_d_m(ii);
% deci=1000;figure,plot3(xyz_geo(1:deci:end,1),
xyz_geo(1:deci:end,2),xyz_geo(1:deci:end ,3),'.'),xlabel 'x'
xyz=xyz_geo;
xnn_grid=xnn_imu;
ynn_grid=ynn_imu;
end
%% GRIDDING AND STORING 3-D DATA
%-----------------------------
%%%% INTERP, NATURAL (CONTINUOUS C1)
%-----------------------------
F=TriScatteredInterp(xyz(:,1),xyz(:,2),xyz(:,3),'natural');
zz=F(xnn_grid,ynn_grid);
% figure,imagesc(xnn(:),ynn(:),zz)
% figure,mesh(xnn_grid,ynn_grid,zz)
%-----------------------------
%%%% STORE
%-----------------------------
if if_ncnew==1 | if_ncadd==1
cd(dir_nc)
%%% mask (1:datum; 0: nan)
mask_z=zz;
mask_z(isnan(zz)==0)=1;
mask_z(isnan(zz)==1)=0;
mask_zz_put=mask_zz_put.*mask_z;
%update mask such that final map is equal
% to 1 only in inner anc common point. it can be used also to
% verify unwanted holes.
nc_varput(oufile,'mask_Z', mask_zz_put)%
%%% 3D datum
input_buffer.time = ii/fps; %conta replacement
input_buffer.count = conta;
%%% xyz in mm _________________________________
zz_put=zz*1000;
zz_put(abs(zz_put)<1)=1;
% per evitare che poi metta nan dove ? minore di 1
% ? 1 mm in alcuni punti. non dovrebbe dare noia
input_buffer.Z = zz_put;
%%% xyz in mm ____(int16)________________________
% input_buffer.chunking=0;
cd(dir_nc)
nc_addnewrecs (oufile, input_buffer);
clear input_buffer
end
Извините за публикацию большей частискрипт.Я попытался отредактировать его, но обнаружил, что для отображения ошибки требуется большая часть кода.Код перебирает около 3000 * _wd файлов, а затем появляется следующая ошибка.Я хочу, чтобы код продолжал циклически перебирать все файлы * _wd.
matlab Ошибка при использовании netcdflib В библиотеке NetCDF обнаружена ошибка во время выполнения функции putVarsDouble - «Числовое преобразование не представимо (NC_ERANGE)».
Ошибка в netcdf.putVar (строка 88) netcdflib (funcstr, ncid, varid, varargin {:});
Ошибка в nc_varput_tmw (строка 23) netcdf.putVar (ncid, varid, start, count, stepde, data);
Ошибка в nc_varput (строка 56) nc_varput_tmw (ncfile, varname, data, varargin {:});
Ошибка в nc_addrecs (строка 134)nc_varput (ncfile, new_data (j) .Name, current_var_data, corner, count);
Ошибка в nc_addnewrecs (строка 126) `` nc_addrecs (ncfile, input_buffer);
Ошибка в PTF_t_t_t_t___P__T_P__P___P__W_W_W_W_W_W_W___P___P__W____Rстрока 479) nc_addnewrecs (oufile, input_buffer);