contribution: mylib_input_integer
Stefan Pofahl <[email protected]> Wed, 06 Dec 2006 11:29:06 +0100
| Newsgroups | gmane.comp.gnu.octave.sources |
|---|---|
| Organization | ZSW GB3 Ulm |
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--------------080509010108030708010906
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
## Copyright of Octave (C) 1996, 1997 John W. Eaton
##
## This file is part of Octave.
##
## Octave is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING. If not, write to the Free
## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA.
Hello Dear Maintainers!
Here is my contribution, feel free to improve it ;-)
Sincerely Yours
Stefan Pofahl
**********************************************************************
## -*- texinfo -*-
## @deftypefn {Function File} {} input_integer (@var{min}, @var{max})
## Prompt integer number, min and max values optional
##
## @code{input_integer (@var{min}, @var{max})} will ask you to prompt an
## integer value, input is checked if it is a true integer number.
##
## If @var{min} and @var{max} are given as pareters and both are scalare
## values they are used as borders for the prompt.
## Output is an integer number.
##
## Author: Stefan N. Pofahl <[email protected]>
## Created: Dez. 2006, Vers.1.0(Dez.2006)
## Adapted-By: n.n.
function integer_number= mylib_input_integer(min_integer, max_integer)
fflush(stdout); # flush buffer to the standard output
is_integer=false;
outside_min_max=true;
integer_number= realmin;
if (nargin==2)
if (isscalar(min_integer) && isscalar(max_integer))# condition1
str_prompt= ["please prompt integer number between ",...
int2str(min_integer) ," and ",
int2str(max_integer), ": "];
endif
else
min_integer= realmin;# [statementblock]
max_integer= realmax;
str_prompt= "please prompt integer number: ";
endif
while ((not(is_integer)) || outside_min_max)
fflush(stdout); # flush buffer to the standard output
integer_number= input (str_prompt, "s");
fflush(stdout); # flush buffer to the standard output
is_digit=isdigit(integer_number);
is_integer=min(is_digit); # condition1
if is_integer # condition1
integer_number= str2num(integer_number);
if ((integer_number<min_integer)||(integer_number>max_integer)
)# condition1
outside_min_max=true; # [statementblock]
else
outside_min_max=false; # [statementblock]
endif
else
outside_min_max=true; # [else statementblock]]
endif
endwhile
endfunction
--------------080509010108030708010906
Content-Type: text/plain;
name="mylib_input_integer.m"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="mylib_input_integer.m"
## Copyright of Octave (C) 1996, 1997 John W. Eaton
##
## This file is part of Octave.
##
## Octave is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## Octave is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Octave; see the file COPYING. If not, write to the Free
## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA.
## -*- texinfo -*-
## @deftypefn {Function File} {} input_integer (@var{min}, @var{max})
## Prompt integer number, min and max values optional
##
## @code{input_integer (@var{min}, @var{max})} will ask you to prompt an
## integer value, input is checked if it is a true integer number.
##
## If @var{min} and @var{max} are given as pareters and both are scalare
## values they are used as borders for the prompt.
## Output is an integer number.
##
## Author: Stefan N. Pofahl <[email protected]>
## Created: Dez. 2006, Vers.1.0(Dez.2006)
## Adapted-By: n.n.
function integer_number= mylib_input_integer(min_integer, max_integer)
fflush(stdout); # flush buffer to the standard output
is_integer=false;
outside_min_max=true;
integer_number= realmin;
if (nargin==2)
if (isscalar(min_integer) && isscalar(max_integer))# condition1
str_prompt= ["please prompt integer number between ",...
int2str(min_integer) ," and ", int2str(max_integer), ": "];
endif
else
min_integer= realmin;# [statementblock]
max_integer= realmax;
str_prompt= "please prompt integer number: ";
endif
while ((not(is_integer)) || outside_min_max)
fflush(stdout); # flush buffer to the standard output
integer_number= input (str_prompt, "s");
fflush(stdout); # flush buffer to the standard output
is_digit=isdigit(integer_number);
is_integer=min(is_digit); # condition1
if is_integer # condition1
integer_number= str2num(integer_number);
if ((integer_number<min_integer)||(integer_number>max_integer) )# condition1
outside_min_max=true; # [statementblock]
else
outside_min_max=false; # [statementblock]
endif
else
outside_min_max=true; # [else statementblock]]
endif
endwhile
endfunction
--------------080509010108030708010906
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Octave-sources mailing list
[email protected]
https://www.cae.wisc.edu/mailman/listinfo/octave-sources
--------------080509010108030708010906--