source: trunk/SRC/Utilities/report.pro

Last change on this file was 495, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo; dupe empty lines; trailing blanks

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.8 KB
RevLine 
[2]1;+
2;
[224]3; @file_comments
[260]4; Like <proidl>DIALOG_MESSAGE</proidl> if there is already some widget
5; active or like <proidl>MESSAGE</proidl> if there is not any widget active.
[375]6;
[266]7; To ask a question whose answer is not yes/no, use <pro>xquestion</pro>.
[2]8;
[325]9; @param textin {in}{required} {type=scalar string or arrays of string}
10; If textin is a scalar string, we look for the line feed character "!C".
[375]11;
[325]12; If textin is set to an array of strings, each
[2]13; array element is displayed as a separate line of text.
14;
[224]15; @keyword SIMPLE
[136]16; activate to print only the message without the name
[242]17; and the line of the routine (defined by calling <pro>routine_name</pro>)
[495]18; or++
[242]19; Activate to print the error message without printing the routine name with
20; its full path.
[11]21;
[224]22; @keyword PARENT
[260]23; same as DIALOG_PARENT of <proidl>DIALOG_MESSAGE</proidl>
[2]24;
[136]25; @keyword QUESTION {default="Warning"}
26; Set this keyword to create a "Question" dialog.
[495]27; If batch mode is detected, answer to be given is ANSWER_BATCH if exists or
[485]28; the default one (see DEFAULT_NO keyword).
[2]29;
[485]30; @keyword ANSWER_BATCH
31; Answer to be given to replace human being when running in non interactive
32; session. Only used when QUESTION keyword is set.
33;
[136]34; @keyword DEFAULT_NO {default="Yes"}
[224]35; Set this keyword to make the "No" button the default selection for
36; "Question" dialog.
[2]37;
[242]38; @keyword _EXTRA
[495]39; Used to pass keywords to <proidl>DIALOG_MESSAGE</proidl> and
[260]40; <proidl>MESSAGE</proidl>
[2]41;
[224]42; @returns
[136]43; -1 if the keyword QUESTION is not activated
[230]44; If the keyword QUESTION is activated, return 1 for yes and 0 for no.
[224]45;
46; @examples
[136]47; If there is not any widget activated:
[2]48;
[371]49;   IDL> help, report('toto tata')
[136]50; % $MAIN$: toto tata
51; <Expression>    INT       =       -1
[371]52;   IDL> help, report('does it works ?',/question)
[136]53; does it works ? y/n (default answer is y)
54; <Expression>    BYTE      =    1
[371]55;   IDL> help, report('question1: !C does it works ?',/question)
[136]56; question1:
57; does it works ? y/n (default answer is y)
58; <Expression>    BYTE      =    1
[2]59;
[485]60; To simulated non interactive session :
61;
62;   IDL> set_default_device
63;   IDL> key_batch = 1
64;   IDL> help, report('question1: !C does it works ?',/question, answer_batch='y')
65; question1:
66; does it works ? y/n (default answer is y)
67; <Expression>    BYTE      =    1
68;
69; Like in determineminmax.pro:
70;
71;   set_default_device
72;   key_batch = 1
73;   vraimin = 0.d0
74;   question = ['Warning: constant filed, same value everywhere : ' + strtrim(vraimin, 2) +'!', 'Shall we make the plot?']
75;   answer = report(question, /default_no, /question)
76;
[133]77; If widgets are already activated, it is the same thing but with widgets!
[2]78;
[224]79; @history
[133]80;
[485]81; - fplod 20130802T123116Z cratos.locean-ipsl.upmc.fr (Linux)
82;
83;   * add ANSWER_BATCH keyword and handle key_batch
84;
[495]85; - Sebastien Masson (smasson\@lodyc.jussieu.fr) 21/10/1999
[485]86;
[224]87; @version
88; $Id$
[133]89;
[2]90;-
[327]91FUNCTION report, textin, DEFAULT_NO=default_no, PARENT=parent $
[485]92               , QUESTION=question, SIMPLE=simple $
93               , ANSWER_BATCH=answer_batch $
94               , _EXTRA=ex
[231]95;
[114]96  compile_opt idl2, strictarrsubs
[485]97
98  @cm_general
[114]99;
[133]100  res = -1                      ;
[485]101
102  ; check parameter and keywords
103  if keyword_set(default_no) then default_answer = 'n' ELSE default_answer = 'y'
104
105  ; if QUESTION keyword is set, ANSWER_BATCH must be also set with value in '', 'y' or 'n'
106  IF keyword_set(QUESTION) THEN BEGIN
107     IF NOT keyword_set(ANSWER_BATCH) THEN BEGIN
108        print, 'www : ANSWER_BATCH is not set, default answer while be used'
109        answer_batch = default_answer
110     ENDIF ELSE BEGIN
111         IF answer_batch NE '' and answer_batch NE 'y' and answer_batch NE 'n' THEN BEGIN
112             answer_batch = default_answer
113         ENDIF
114     ENDELSE
115  ENDIF
116
[133]117; we separate the text in different lines (separated by !C) if it is not already done...
[277]118  if n_elements(textin) EQ 1 then text = '% ' + str_sep(textin, '!C', /trim) ELSE text = '% ' + textin
[372]119; we get the line, routine name and revision version
[277]120  IF NOT keyword_set(simple) THEN BEGIN
[495]121;    Look for the revision in the code of the procedure/function calling this
[277]122;    report function (ie the one where an problem was detected) in the first
[493]123;    occurrence of the form :
[277]124;    "; $Id$"
125    prefix = routine_name(1)
[495]126    split = STRSPLIT(prefix, ' ', /EXTRACT, count = cnt)
[316]127    IF cnt GT 1 THEN BEGIN
128      coderoutine = getfile(split[1])
129      idline = (where(stregex(coderoutine, '^; \$Id: .* .* .* .* \$', /boolean) EQ 1))[0]
130      IF (idline GT 0) THEN BEGIN
131        split = STRSPLIT(coderoutine[idline], ' ', /EXTRACT)
132        prefix = '% '+prefix+ ' rev. ' + split[3] + ': '
133      ENDIF ELSE BEGIN
134        prefix = '% '+prefix+': '
135      ENDELSE
136    ENDIF
[277]137    text = [prefix, text]
138  ENDIF
[485]139  ; there is some widgets activated, it is easy, we call dialog_massage
[239]140  if (widget_info(/managed))[0] NE 0 then BEGIN
141    res = dialog_message(text, dialog_parent = parent, QUESTION = question $
142                         , title = routine_name(1), DEFAULT_NO = default_no, _extra = ex)
143    if keyword_set(question) THEN res = res EQ 'Yes' ELSE res = -1
144  ENDIF ELSE BEGIN
[485]145    ; there is not any widget activated
146    ; do we ask a question ?
[277]147    IF keyword_set(question) THEN BEGIN
[485]148      ; what is the answer by default ?
[239]149      if keyword_set(default_no) then answer = 'n' ELSE answer = 'y'
150      default_answer = answer
151      if n_elements(text) GT 1 THEN $
[277]152         for i = 0, n_elements(text)-2 do print, text[i]
[485]153      ;
154      ; if non interactive mode has not yet have been tested, do it
155      IF NOT testvar(var = key_batch) THEN BEGIN
156         set_default_device
157      ENDIF
158      if key_batch EQ 0 THEN BEGIN
159          ; if interactive mode is the current one, wait for human being answer ...
160          read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')', answer
161      ENDIF ELSE BEGIN
162          ; if not, answer with ANSWER_BATCH keyword or the default answer if not set
163          IF testvar(var = answer_batch) THEN BEGIN
164              print, 'batch answer with answer_batch ', answer_batch
165              answer = answer_batch
166          ENDIF ELSE BEGIN
167              print, 'batch answer with default_answer ', default_answer
168              answer = default_answer
169          ENDELSE
170      ENDELSE
[495]171
[239]172      answer = strlowcase(answer) ;
[485]173      ; if the answer is not appropriated
[239]174      while answer NE '' and answer NE 'y' and answer NE 'n' do begin
175        read, text[n_elements(text)-1]+' y/n (default answer is '+default_answer+')', answer
176        answer = strlowcase(answer)
177      ENDWHILE                  ;
[485]178      ; we adjust res in function of the answer
[239]179      case answer of
180        '':res = default_answer EQ 'y'
181        'y':res = 1
182        'n':res = 0
183      endcase
184    ENDIF
185  ENDELSE
[133]186; If we do not ask any question, we just make a print
[239]187  IF NOT keyword_set(question) THEN BEGIN
[277]188    FOR i = 0, n_elements(text)-1 do print, text[i]
189  ENDIF
[2]190
[277]191  return,  res
[2]192end
Note: See TracBrowser for help on using the repository browser.