;+
; NAME:
;   teambb
; PURPOSE:
;   Display items from the teambb
;
; Note: needs logical or environment variable DIR_GEN_TBB defined.
;
; CALLING SEQUENCE:
;   teambb
;   teambb,'add'	; Access member addresses
;   teambb,'sci'	; Access the science menu
; INPUTS:
;   command	= The entry top level menu item
; MODIFICATION HISTORY:
;   D.M. fecit, 9 December, 1993. Version A.0.3.
;   11-dec-93, J. R. Lemen, V A.0.4 Changed to a procedure;
;		            write temporary files to user's home directory
;   13-dec-93, JRL,  V A.0.5 Changed directory name strategy; Fixed some bugs
;   14-dec-93, DMZ,  V A.0.6 Changed DIR_GEN_TBB to $DIR_GEN_TBB
;   10-feb-94, JRL,  V A.0.7 Deleted the trailing '\' in inter_stir. Save the
;			     entry directory to return there on exiting.  
;			     Renamed "more" procedure to more_tbb.
;			     Renamed file_list variables to file_list_t
;   17-feb-94, JRL,  V A.0.8 Call clear_screen if VMS
;   13-oct-94, NN,   V A.0.81 Add 'mi' in the author search
;   13-feb-95, JRL,  V A.0.9 Added access to completed items.  Changed code
; 			     to use break_file so that items are correctly
;			     listed on an VMS system
;
;   28-apr-95, SLF,  	     Add SCI_EV procedure
;-
;
function inter_stir, tree, inter_char
;
n_tree = n_elements(tree)
;
if n_tree eq 1 then begin
   interfix = inter_char + tree
endif else begin
   interfix = inter_char + tree(0)
   for i_tree = 1, n_tree - 1 do begin
      interfix = interfix + inter_char + tree(i_tree)
   end
end
;;interfix = interfix + '\'		; Commented out (JRL 10-Feb-94)
;
return, interfix & end

function check_tree, dummy_argument
;
; Check logical name / environment variable for DIR_GEN_TBB.
;
check = 0
case !version.os of
     'vms': check = trnlog('$DIR_GEN_TBB', equivalent_name)
 'windows': print, '%CHECK_TREE-I-WINDOZE, not implemented yet.'
   'MacOS': print, '%CHECK_TREE-I-MAC, not implemented yet.'
      else: if getenv('DIR_GEN_TBB') ne '' then check = 1
endcase
return, check & end

pro set_tree, alternate_home
;
; Set logical name / environment variable for DIR_GEN_TBB.
;
case !version.os of
     'vms': setlog, '$DIR_GEN_TBB', alternate_home, /concealed, /terminal
 'windows': print, '%SET_TREE-I-WINDOZE, not implemented yet.'
   'MacOS': print, '%SET_TREE-I-MAC, not implemented yet.'
      else: setenv, 'DIR_GEN_TBB=' + alternate_home
endcase
return & end
               
pro more_tbb, filename, tree = tree
;
not_yet_mess = '%MORE-W-NTYTSUPP, this environment not yet supported.'
interfix = ''
if keyword_set(tree) then begin
   n_tree = n_elements(tree)
   case !version.os of
        'vms': begin
                  if n_tree eq 1 then begin
                     interfix = '[' + tree
                  endif else begin
                     interfix = '[' + tree(0)
                     for i_tree = 1, n_tree - 1 do begin
                        interfix = interfix + '.' + tree(i_tree)
                     end
                  end
                  interfix = interfix + ']'
               end
    'windows': interfix = inter_stir(tree, '\')
      'MacOS': interfix = inter_stir(tree, ':')
         else: interfix = inter_stir(tree, '/')
   endcase
end
;
; print, '%MORE-D-FILENAME, filename = ', filename
case !version.os of
    'vms': begin
              if strpos(filename, '.') lt 0 then filename = filename + '.*'
              spawn, 'type /page $DIR_GEN_TBB:' + interfix + filename
           end
'windows': print, not_yet_mess
  'MacOS': print, not_yet_mess
     else: begin
	message,'more $DIR_GEN_TBB' + interfix + '/' + filename,/info
	more,rd_tfile('$DIR_GEN_TBB' + interfix + '/' + filename)
     endelse
endcase
return & end

pro cdir, subdirectory
case !version.os of
     'vms': begin
               prefix = '[' & top = '$DIR_GEN_TBB:'
               n_sub = n_elements(subdirectory)
               if n_sub gt 1 then begin
                  subdir = '[' + subdirectory(0)
                  for i_sub = 1, n_sub - 1 do begin
                     subdir = subdir + '.' + subdirectory(i_sub)
                  end
                  subdir = subdir + ']'
               endif else subdir = '[' + subdirectory + ']'
            end
 'windows': begin & prefix = '\' & subdir = subdirectory & end
   'MacOS': begin & prefix = ':' & subdir = subdirectory & end
      else: begin
               prefix = '/' & subdir = subdirectory & top = '$DIR_GEN_TBB/'
            end
endcase
n_sub = n_elements(subdir)
if n_sub gt 1 then begin
   subd = subdir(0)
   for i_sub = 1, n_sub - 1 do subd = subd + prefix + subdir(i_sub)
   subdir = subd
end
cd, top + subdir
; print,'%CDIR-I-CD, directory changed to ' + top + subdir
return & end


pro clear, dummy_variable
not_yet_mess = '%CLEAR-W-NTYTSUPP, this environment not yet supported.'
case !version.os of
     'vms': clear_screen		; Call RDB's routine
 'windows': print, not_yet_mess
   'MacOS': print, not_yet_mess
      else: spawn, 'clear'
endcase
return & end

pro print_ast, out_unit
if n_params() eq 1 then unit = out_unit else unit = -1
ast = "***********************************************************************"
printf, unit, "" & printf, unit, ast & printf, unit, ""
return & end
            
pro space_return, dummy_argument
for i = 0, 3 do print, " "
print, "                         Press RETURN                   "
dummy_variable = '' & read, dummy_variable
return & end

pro ban, dummy_menu
;
; TeamBB news banner
;
clear & more_tbb, 'banner.news', tree = 'news' & space_return
return & end

pro old, dummy_argument
;
; Look at old messages.
;
old_menu:
print, " The following options are available:"
print, ""
case !version.os of
       'vms': spawn, 'directory /col = 1 /brief $DIR_GEN_TBB:[old]
   'windows': print, not_yet_mess
     'MacOS': print, not_yet_mess
        else: spawn, 'ls -1 $DIR_GEN_TBB/old
endcase
;
print, ""
print, "Enter a filename (or part of a filename; ignore ., ;, and version number):"
print, "      e.g. *       ..... to list all messages"
fname = '' & read, 'file name> ', fname & fname = strlowcase(fname)
if fname ne '' then begin
   print, "************************************************************"
   print, "" & more_tbb, fname, tree = 'old' & print, ""
   print, "************************************************************"
   print, ""
end
yesnox,"Do you want to try the OLD option again ?", answer,'N'
if answer then goto, old_menu
return & end

pro sci_ea, dummy_argument
;
print,  "" & print, "Search on authors"
;
keep_searching = 1
while keep_searching do begin
;
   print, "" & author = ''
   read, "Enter author of interest (e.g. acton, act, or cton): ", author
   author = strlowcase(author)
   if strlen(strcompress(author)) eq 0 then return
   cdir, ['proposal','current']
   author_list = findfile('*.' + author + '*')
   print, "" 
;
   if author_list(0) eq '' then begin
      print, "No files under this author found"
;      if strupcase(strmid(answer,0,1)) ne 'Y' then return
      return
   endif
;
   file_list_t = [findfile('fl*.' + author + '*'), $
                findfile('ar*.' + author + '*'), $
                findfile('qs*.' + author + '*'), $
                findfile('mi*.' + author + '*')]
   file_list_t = file_list_t(where(file_list_t ne ''))
   n_file = n_elements(file_list_t)
;
   scratch, auth_unit, name=author_fil, /open
   printf, auth_unit, 'These are the topics led by ' + author + ':'
   print_ast, auth_unit
   for i_file = 0, n_file - 1 do begin
      openr, file_unit, file_list_t(i_file), /get_lun
      break_file, file_list_t(i_file), disk, dir, topic
      s = '' & for i_line = 0, 5 do readf, file_unit, s
      for i_line = 6, 9 do begin
         readf, file_unit, s
         if i_line eq 6 then s = topic + ': ' + s
         printf, auth_unit, s
      end
      printf, auth_unit, ' '
      close, file_unit & free_lun, file_unit
   end
   scratch, auth_unit, /nodelete
;
   same_author = 1
   while same_author do begin
      more, rd_tfile(author_fil)
      print, "" 
      print, "                  (For full title, select 'su' in Science Menu) "
      print, "" 
;
      print, "" 
      print, "Enter a filename or part of a filename:"
      print, "      e.g. qs002 ..... to list second quiet sun topic"
;     print, "      or   acton ..... to list all entries by a particular author"
      fname = '' & read, 'Filename> ', fname
      fname = strlowcase(fname)
; print, '%SCI_EA-D-FNAME, fname = ', fname
      if fname ne '' then begin
         fname = '*' + fname + '*.*'
         print, "" & print_ast
         test_fname = findfile(fname)
         match = not ((n_elements(test_fname) eq 1) and (test_fname(0) eq ''))

         if match then begin
            more_tbb, fname, tree=['proposal','current']
            print_ast & print, ""
	    yesnox,"Search on the same author again ?", answer, 'N'
            same_author = answer
         endif else begin
            print, "Sorry, please try again."
         end
      endif else same_author = 0
   end
   file_delete, author_fil
;
; New author
;
   print, ""
   yesnox,"Continue searching on authors ?", answer, 'N'
   keep_searching = answer
end
;
clear & return & end

pro sci_et, dummy_argument
command_set = ["AR","FL","MI","QS","SCI","MENU"]
n_command = n_elements(command_set)
cdir, ['proposal','current']
clear
command = ''
while command ne 'MENU' do begin
   print, "" & print, "Search on Topics" & print, "" 
   print, "Enter a science topic            "
   print, "" 
   print, "          AR   ..... List Active Region science topics"
   print, "          FL   ..... List FLare science topics"
   print, "          MI   ..... List MIscellaneous (or Modelling/Instrument) topics"
   print, "          QS   ..... List Quiet Sun science topics"
   print, "          SCI  ..... Return to Science Menu"
;   print, "          MENU ..... Return to top-level menu"	;*** This option doesn't work
   print, "" 
   command = '' & read, "ET option> ", command & cmd = strupcase(command)
   for i_command = 0, n_command - 2 do begin
      if cmd eq command_set(i_command) then begin
         print, ""
         print, '%SCI-I-OPTION, selected ' + cmd + '.'
         print, ""
;         if i_command lt (n_command - 2) then et_topic, cmd else sci, ''
         if i_command lt (n_command - 2) then et_topic, cmd else $
	  if (cmd eq 'MENU') or (cmd eq 'SCI') then return
      end
   end
   if cmd ne 'MENU' then begin
;
; If we got here, the user typed in something bogus.
;
      print, "Please try again."
   end
end
return & end

pro et_topic_nolist, topic_type, file_name
;
file_name = ''
type_upper = strupcase(topic_type) & type_lower = strlowcase(topic_type)
;
print, ''
print, 'Enter a filename (or part of a filename):'
print, '      e.g. ' + type_lower + $
   '005          ..... to list the 5th ' + type_upper + ' topic'
print, '           ' + type_lower + $
   '*.sakurai    ..... to list all ' + type_upper + ' topics by Sakurai'
print, '           ' + type_lower + $
   '001.uchida03 ..... to list a specific item'
print, '' 
read, type_upper + ' file name> ', file_name
file_name = strlowcase('*'+file_name+'*')
;
return & end

pro et_topic, topic_type, dummy_argument
;
type = ["AR", "FL", "MI", "QS"]
this_type = strupcase(topic_type) & this_type = where(type eq this_type)
if n_elements(this_type) eq 1 then begin
   this_type = this_type(0)
endif else begin
   print,'%ET_TOPIC-E-BOGUSTT, topic type should not be ', topic_type
   stop
end
; print,'%ET_TOPIC-D-THIS_TYPE, this_type =', this_type
type = type(this_type)
; print,'%ET_TOPIC-D-TYPE, type = ', type
exploded_type = ['active region', 'flare', $
                 'miscellaneous (e.g. modeling, instrument, &c.)', $
                 'quiet Sun']
exploded_type = exploded_type(this_type)
file_type = strlowcase(topic_type)
;
done_with_topics = 0
while not done_with_topics do begin
   file_list_t = findfile(file_type + '*.*')
   n_file = n_elements(file_list_t)
;
   scratch, type_unit, name=type_fil, /open
   printf, type_unit, ''
   printf, type_unit, 'These are the ' + exploded_type + ' topics:'
   printf, type_unit, ''
   for i = 0, 1 do print, ''
   for i_file = 0, n_file - 1 do begin
      openr, file_unit, file_list_t(i_file), /get_lun
      break_file, file_list_t(i_file), disk, dir, topic
      s = '' & for i_line = 0, 5 do readf, file_unit, s
      for i_line = 6, 9 do begin
         readf, file_unit, s
         if i_line eq 6 then s = topic + ': ' + s
         printf, type_unit, s
      end
      printf, type_unit, ' '
      close, file_unit & free_lun, file_unit
   end
   scratch, type_unit, /nodelete
   more, rd_tfile(type_fil)
;
   print, "       (For full title, select 'su' in Science Menu)"
   no_list = 1
;
   while no_list do begin
      print_ast & file_name = '' & et_topic_nolist, topic_type, file_name
; print,'%ET_TOPIC-D-FILE_NAME, file_name = ', file_name + ' (' + $
;    strtrim(strlen(file_name),2) + ' characters)'
      if file_name ne '' then begin
         numeric = strtrim(indgen(10), 2)
         first_part = 0
         for i = 0, 9 do begin
            if (strpos(file_name, strlowcase(topic_type)) ge 0) and $
               (strpos(file_name, numeric(i)) ge 0) and $
               (strpos(file_name, numeric(i)) le 4) and $
               (strpos(file_name, '.') lt 0) then first_part = 1
         end
         if first_part then file_name = file_name + '.*'
;
         print_ast
         more_tbb, file_name, tree = ['proposal','current']
         print_ast & print, ''
      end
;
      yesnox, 'Search on ' + type + ' topics again ?', answer, 'N'
      if answer then begin
         yesnox, 'List files again ?', answer, 'N'
         if answer then more, rd_tfile(type_fil)
      endif else begin
         no_list = 0 & done_with_topics = 1
      end
   end
end
;
file_delete, type_fil
;
return & end

pro su_nolist, file_name
file_name = ''
while file_name eq '' do begin
   print, "Enter a filename (or part of a filename):"
   print, "      e.g.,    qs002 ..... to list the second QS topic"
   print, "      or       ar005 ..... to list the fifth AR topic"
   print, "      or       fl032 ..... to list 32nd flare topic"
   print, "" 
   read, "File name> ", file_name
   file_name = strlowcase('*'+file_name+'*')
   if file_name ne '' then begin
      if strpos(file_name, '.') lt 0 then file_name = file_name + '.*'
   end
end
return & end

pro sci_su, dummy_argument
;
list_summary_file = 1
while list_summary_file do begin
   print, "" & print, "" & 
   more_tbb, 'summary.file', tree = ['proposal','summary']
   print, ""
   list_file = 1
   while list_file do begin
      su_nolist, file_name
      print, file_name & print, ""
      print_ast & more_tbb, file_name, tree = ['proposal','current']
      print_ast & print, ""

      yesnox, "Select a file from the summary file again?", answer, 'N'
      if answer then begin
         yesnox, "Do you want to list the summary file again?", answer, 'N'
         if answer then begin
            list_file = 0 & list_summary_file = 1
         endif else begin
            list_file = 1 & list_summary_file = 0
         end
      endif else begin
         list_file = 0 & list_summary_file = 0
      end
   end
end
;
return & end

pro sci_ev, dummy_argument

more_tbb, 'event.list', tree=['proposal','event']

return
end
;
pro sci_cl, dummy_argument
list_summary_file = 1
while list_summary_file do begin
   print, "" & print, "" & 
   more_tbb, 'sum_closed.file', tree = ['proposal','complete']
   print, ""
   list_file = 1
   while list_file do begin
      su_nolist, file_name
      print, file_name & print, ""
      print_ast & more_tbb, file_name, tree = ['proposal','complete']
      print_ast & print, ""

      yesnox, "Select a file from the summary of closed topics again?", answer, 'N'
      if answer then begin
         yesnox, "Do you want to list the summary file again?", answer, 'N'
         if answer then begin
            list_file = 0 & list_summary_file = 1
         endif else begin
            list_file = 1 & list_summary_file = 0
         end
      endif else begin
         list_file = 0 & list_summary_file = 0
      end
   end
end
;
return & end

pro sci_th, dummy_argument
;
print, ""
print, " The following files are available in this category:"
print, ""
cdir, ['proposal', 'thesis']
file_list_t = findfile('*_topics') & n_file = n_elements(file_list_t)
for i_file = 0, n_file - 1 do print, strlowcase(file_list_t(i_file))
;
print, ""
print, "Enter a filename (or part of a filename):"
print, "      e.g.,    master ..... to find master's thesis topics"
file_name = '' & read, 'File name> ', file_name
file_name = strlowcase('*'+file_name+'*')
if file_name ne '' then begin
   clear & print_ast & more_tbb, file_name, tree = ['proposal', 'thesis']
   print_ast & space_return & clear
end
;
return & end

pro sci_uw, dummy_argument
;
print, ""
print, "PROPOSALS DELETED BECAUSE OF NO VALID UPDATE FOR 6 MONTHS"
print, "" & more_tbb, 'list_sleeping', tree = ['proposal','old']
print, ""
space_return
;
return & end

pro sci, dummy_argument
;
command_set = ["EA","ET","SU","CL","EV","TH","UW","MENU"]
n_command = n_elements(command_set)
cdir, ['proposal','current']
clear
cmd = ''
while cmd ne 'MENU' do begin
   executed = 0
   print, ""
   print, "#################### Science Menu #######################"
   print, ""
   print, " The following options are available:"
   print,   "   EA ..... Enter Author's name"
   print,   "   ET ..... Enter Topic name"
   print,   "   SU ..... Summary listing"
   print,   "   CL ..... List completed proposal"
   print,   "   EV ..... List events being analyzed"
   print,   "   TH ..... List master/doctor thesis topics based on Yohkoh"
   print,   "   UW ..... List header of underworld (i.e. deleted) proposals"
   print,   "   MENU ... Return to top-level menu"
   print, ""
   command = '' & read, "SCI option> ", command & cmd = strupcase(command)
; print, '%SCI-D-CMD, cmd = ' + cmd
   for i_command = 0, n_command - 2 do begin
      if cmd eq command_set(i_command) then begin
         print, ""
         print, '%SCI-I-OPTION, selected ' + command + '.'
         print, ""
         call_procedure, 'sci_' + command, ''
         executed = 1
      end
   end
   if (cmd ne 'MENU') and (not executed) then begin
; print,'%SCI-D-PLEASE, got passed dual conditional with cmd, executed =', $
;    cmd, ' ', executed
;
; If we got here, the user typed in something bogus.
;
      print, "Please try again."
   end
; print, '%SCI-D-MENU, fell through: cmd = ' + cmd
end
return & end

pro tbb_help, dummy_argument
;
command_set = ["GEN", "NEW", "STA", "CPY", "RUL", "MENU"]
help_file = ['general', 'newitem', 'statusitem', 'copyitem', 'rules']
n_command = n_elements(command_set)
;
cmd = ''
while cmd ne 'MENU' do begin
   clear & for i = 0, 1 do print, ""
   print, "The following HELP topics are available:"
   print, ""
   print, "		GEN	Information on Yohkoh Team Bullatin Board"
   print, "		NEW	How to a create a new science topic"
   print, "		STA	How to submit a status report"
   print, "		CPY	How to get a copy of a file"
   print, "		RUL     Copy of the Team Bullatin Board RULES"
   print, "		MENU    Return to top-level menu"         
   print, ""
   command = '' & read, "Option> ", command & cmd = strupcase(command)
   j_command = -1
   for i_command = 0, n_command - 2 do begin
      if cmd eq command_set(i_command) then j_command = i_command
   end
   if j_command ge 0 then begin
      file_name = help_file(j_command) + '.help'
      print_ast & more_tbb, file_name, tree = 'help' & print_ast & space_return
   endif else begin
      if cmd ne 'MENU' then begin
;
; If we got here, the user typed in something bogus.
;
         print, "Please try again."
      end
   end
end
;
return & end

pro add, dummy_argument
;
print, "" & print, " These are the available addresses:" & print, ""
cdir, ['address', 'yohkoh']
file_list_y = findfile('address.*') & n_addr = n_elements(file_list_t)
addr_list = str_replace(strlowcase(file_list_y),'address.', ' ')
;
more_addresses = 1 & list_names = 1
while more_addresses do begin
;
   print, "" & if list_names then print, addr_list
   name = '' & read, "Enter a name (e.g. strong):   ", name
   n_addr = n_elements(addr_list) & match = 0
   for i_addr = 0, n_addr - 1 do begin
      if strpos(addr_list(i_addr), name) gt 0 then begin
         print, "" & more_tbb, 'address.' + name, tree = ['address', 'yohkoh']
         match = 1
      end
   end
   if not match then print,'Sorry, you must have made a typo.'
   print, "" 
   yesnox, "Find the address of another person?", answer, 'N'
   if answer then begin
      print, "" 
      yesnox, "Do you want to see the list of people?", list_names, 'N'
   endif else more_addresses = 0
end
;
return & end

pro news, dummy_argument
;
command_set = ["NSCI", "NCAM", "NCOL", "NGBO", "NMEET", "NTRAV", "NMISC", $
               "SCI", "MENU"]
n_command = n_elements(command_set)
;
header = ['News on science topics', $
          'News on campaign observations', $
          'News on collaborations with outside parties', $
          'News from groundbased observatories', $
          'News (sometimes including abstracts) on recent conferences', $
          'Casual notes on travel carried by Yohkoh members', $
          'Miscellanous news']
subdir = ['science', 'campaigns', 'collaborations', 'gbo', 'meetings', $
          'travel', 'miscellaneous']
file_sug = ['      e.g.,    science ..... to list new science topics', $
 '      e.g.,    future ... to find plans of campaigns in the near future', $
 '      e.g.,    poletto ..... collaborative proposal with Poletto', $
 '      e.g.,    hiraiso ..... news from CRL/Hiraiso', $
 '      e.g.,    asj ..... selection of abstracts for ASJ meeting', $
 '      e.g.,    china  ..... on a China trip', $
 '']
;
print, "" & print, "'news' option selected"
;
cmd = ''
while cmd ne 'MENU' do begin
   clear & print, ""
   print, "########################### News Menu #############################"
   print, ""
   print, " The following categories are available:"
   print, "    NSCI  ..... News on Science Topics"
   print, "    NCAM  ..... News on campaign observations"
   print, "    NCOL  ..... News on collaborations with non-Yohkoh communities"
   print, "    NGBO  ..... News from groundbased observatories"
   print, $
   "    NMEET ..... Yohkoh-related abstracts for recent and upcoming meetings"
   print, "    NTRAV ..... Casual writeups on recent travel"
   print, "    NMISC ..... News on miscellaneous things"
   print, ""
   print, "    SCI   ..... Go to science menu"
   print, ""
   print, "    MENU  ..... Go back to the main menu"
;
   command = '' & read, "News option> ", command & cmd = strupcase(command)
   command_chosen = -1
   for i_command = 0, n_command - 1 do begin
      if cmd eq command_set(i_command) then command_chosen = i_command
   end
; print,'%NEWS-D-CHOSEN, cmd, command_chosen = ', cmd, ' ', command_chosen
;
   if command_chosen ge 0 then begin
      if command_chosen le (n_command - 3) then begin
;
; Substitute for all of the nsci, ncam, &c. entry points
;
         print, "" & print, header(command_chosen) & print, ""
         print, "  The following files are available in this category"
         print, ""
;
         cdir, ['news', subdir(command_chosen)]
         file_list_t = findfile('news.*')
         n_file = n_elements(file_list_t)
         if (n_file eq 1) and (file_list_t(0) eq '') then begin
            print,'%TEAM_BB-I-NONEWS, sorry, no news in the ' + $
               subdir(comand_chosen) + ' subdirectory.'
            return
         endif else begin
	    break_file, file_list_t, disk, dir, filnam, article_list
	    article_list = strmid(article_list,1,max(strlen(article_list)))
            print, article_list
;
            print, ""
            print, "Enter a filename (or part of a filename):"
            print, file_sug(command_chosen)
            file_name = '' & read, "File name> ", file_name
            file_name = strlowcase(file_name)
            if file_name ne '' then begin
               file_name = 'news.*' + file_name + '*'
               clear & print_ast
               more_tbb, file_name, tree = ['news', subdir(command_chosen)]
               print_ast & space_return
            end
         end
      end
      if cmd eq 'SCI' then SCI
   endif else begin
;
; If we got here, the user typed in something bogus.
;
      if cmd ne 'MENU' then print, "Please try again."
   end
end
;
return & end

pro quit_team_bb, save_dir
;
clear
if n_elements(save_dir) ne 0 then begin
  cd,save_dir
  print,'Returning to directory: ',save_dir
endif
more_tbb, 'close.txt', tree = 'news'
return & end

; ---------------
pro teambb, first_command

cd,current=save_current		; Save current directory

version = "               ***** TeamBB  V A.0.9 (13-Feb-95) ******"
first = 1
;
if not check_tree() then begin
   alternate_home = ''
   read, 'Alternate root for DIR_GEN_TBB?      ', alternate_home
   set_tree, alternate_home
end
;
;command_set = ["SCI","NEWS","HELP","ADD","OLD","BAN","QUIT"]	; old option not available presently
command_set = ["SCI","NEWS","HELP","ADD","BAN","QUIT"]
n_command = n_elements(command_set)
;
if n_params() eq 0 then begin
  more_tbb, 'banner.news', tree = 'news' & space_return
endif
;
print, ""
print, "              WELCOME TO THE YOHKOH TEAM BULLETIN BOARD       "
print,version
print, ""
print, "       #######################################################"
print, "        Please use lowercase letters when entering file names"
print, "       #######################################################"
print, ""
print, ""
print, ""
print, "***  List of deleted proposals now available  ***"
print, "              Select SCI (to science menu) and UW (underworld)"
print, ""
print, ""
print, ""
space_return
;
; Select a TeamBB option.
;
cmd = ''
while cmd ne 'QUIT' do begin
   executed = 0
   clear
   print, ""
   print, "################ MAIN MENU #######################"
   print, ""
   print, " The following options are available:"
   print,   "   SCI  ..... Access Yohkoh Science Topics"
   print,   "   NEWS ..... List TBB News Items"
   print,   "   HELP ..... Get Helpful Hints and TBB Rules"
   print,   "   ADD  ..... Access Yohkoh Team addresses"
;   print,   "   OLD  ..... Look at old messages"	;*** Not available presently
   print,   "   BAN  ..... Repeat Banner page"
   print,   "   QUIT ..... Quit the TBB" 
   print, "" 
   if first and n_elements(first_command) ne 0 then begin
      command = first_command
      first = 0
   endif else begin
      command = '' & read, "Option> ", command 
   endelse
   cmd = strupcase(command)
; print, '%TEAM_BB-D-CMD, cmd = ' + cmd
   for i_command = 0, n_command - 2 do begin
      if cmd eq command_set(i_command) then begin
         print, ""
         print, '%TEAM_BB-I-OPTION, selected ' + cmd + '.'
         print, ""
         if cmd eq 'HELP' then tbb_help else call_procedure, cmd, ''
         executed = 1
      end
   end
   if (cmd ne 'QUIT') and (not executed) then begin
;
; If we got here, the user typed in something bogus.
;
      print, "Please try again."
   end
end
;
quit_team_bb, save_current	; Return user to his original directory
;
end
