FUNCTION GET_NUMBER, text, low, high, default, INTEGER=integer, LONG=long, $ DOUBLE=double, REAL=real ;=============================================================================== ; (c) 1990 - khd c/o FU BERLIN. A l l r i g h t s r e s e r v e d. || ; ** No part of this software package may be reproduced, transmitted, || ; 1992 transcribed, stored in a retrieval system, or translated into || ; any form by any means without the w r i t t e n permission of || ; Karl-Heinz Dittberner-FU BERLIN, Arnimallee 22, D-1000 Berlin 33 || ;=============================================================================== ; PRO:GET_NUMBER.PRO K.-H. Dittberner - 28.DEZ.1990 ; V 01.4 P 476/50 - 30.JUL.1992 ; ; IDL(V2.1)-Routine: Eingabe einer Zahl mit Pruefung der Wertegrenzen ; (low <= x <= high). ; ; HINWEISE: Keine. ; ; KEYWORDS: Von den folgenden Keywords darf im Aufruf jeweils ; nur eines verwendet werden. ; ; /INTEGER = Die Zahl wird als Integer-Zahl uebergeben. ; /LONG = Die Zahl wird als LongInteger uebergeben. ; /REAL = Die Zahl wird als Gleitkommazahl uebergeben (Default). ; /DOUBLE = Die Zahl wird als DoublePrecision uebergeben. ; ; Quelle: Do-it-yourself! Merkposten: o ; o ; Aufruf: z.B.: o ; z = Get_Number("Zahl eingeben", o ; 1,10,4,/INTEGER) o ;=============================================================================== ; Aenderungen: [24/7/92-khd] => V 01.2: ; - Die Experimentalfassung ist endlich fertig. ; [29/7/92-khd] => V 01.3: ; - Wenn kein Default-Wert gegeben: "no" ==> "--" geaendert. ; [30/7/92-khd] => V 01.4: ; - Pkt.3: Die Behandlung der Default-Eingabe geaendert; dazu ; CONST dash eingefuehrt. ;=============================================================================== ; 1. Prolog, Variablen und Konstanten: ;=============================================================================== ; On_Error, 2 ; Return => Ruf. Programm. On_IOerror, Start ; Typ-Deklarationen: string = "" ; String. first = 1 ; Boolean. dash = "--" ; Symbol f. fehlenden Default-Wert. If (N_Params() eq 3) $ ; VAR default fehlt im Aufruf. then default = dash $ else default = StrCompress(default, /Remove_All) ; ;=============================================================================== ; 2. Behandlung der Keywords (Default-Werte): ;=============================================================================== ; If Not Keyword_Set(integer) and Not Keyword_Set(long) and $ Not Keyword_Set(real) and Not Keyword_Set(double) $ then real = 1 ; ;=============================================================================== ; 3. Lesen und Ueberpruefen der Zahl: ;=============================================================================== ; Start: Repeat Begin If Not first $ then Message, "Number is out of range; try again.", /Continue Read, text + " [" + default + "] > ", string If (string eq "") and (default ne dash) $ then string = default If Keyword_Set(integer) then x = Fix(string) If Keyword_Set(long) then x = Long(string) If Keyword_Set(real) then x = Float(string) If Keyword_Set(double) then x = Double(string) first = 0 descr = Size(x) EndRep Until (low le x) and (x le high) and $ (descr(1) ge 2) and (descr(1) le 5) ; ;=============================================================================== ; 5. Schluss: ;=============================================================================== ; Ende: Return, x END ;===============================================================================