function g_numberDataInput(hObject,varargin)
   % Called whenever the user changes the number of data inputs:
   
   global params
   
   if nargin>2
      prevNumb = varargin{1};
      newNumb  = varargin{2};
   else
      prevNumb = get(hObject,'UserData');
      newNumb  = str2double(get(hObject,'String'));
      if isnan(newNumb), set(hObject,'String',num2str(prevNumb)); return; end
   end
   
   fakeInp  = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Ground');
   if ~isempty(fakeInp) && newNumb>0
      blockLines   = get_param(fakeInp{1},'LineHandles');
      if (blockLines.Outport(1)~=-1 && ~isempty(blockLines.Outport(1))),   delete_line(blockLines.Outport(1)); end
      delete_block(fakeInp{1})
   end
   
   dataInports  = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Inport');
   
   paramFromSimulink = 0;
   for ii=1:nparams(params)
      paramvals{ii} = params.params(ii).val;
      if isa(paramvals{ii},'char') && numel(paramvals{ii})>2 && strcmp(paramvals{ii},'-->'), paramFromSimulink = paramFromSimulink + 1; end
   end
   
   % To set the proper port number for parameters inport:
   for ii=1:paramFromSimulink
      set_param(dataInports{end-paramFromSimulink+ii},'Port',num2str(newNumb+11));
   end
   % To avoid considering inports for parameters:
   dataInports(end-paramFromSimulink+1:end) = [];
   
   % To remove all previous data inports:
   for ii=1:numel(dataInports)
      try %#ok<ALIGN>
         blockLines   = get_param(dataInports{ii},'LineHandles');
         if (blockLines.Outport(1)~=-1 && ~isempty(blockLines.Outport(1))),   delete_line(blockLines.Outport(1)); end
         delete_block(dataInports{ii});
      catch, end
   end
   
   % To add new inports for all data expected:
   if newNumb==0, add_block('simulink/Sources/Ground', [gcb,'/data_input'],'MakeNameUnique','on','Name','data'); end
   for ii=1:newNumb
      newBlock = add_block('simulink/Sources/In1', [gcb,'/Inport1'],'MakeNameUnique','on','Name',['data',num2str(ii)]);
      set_param(newBlock,'Port',num2str(ii));
   end
   
   g_UpdateInports('',1)
   
end
