function fig = obspl(Keyword,Handle)
% GUI observations planner
% Package: telescope.obs
% Description: GUI Observation Planer. Plot Alt/Airmass and moon sky
%              brightness as a function of time in night, or yearly
%              visibility plot per celestial object.
% Input  : not documented
% Output : null
% Tested : Matlab 5.3
%     By : Eran O. Ofek                    Aug 2001
%    URL : http://weizmann.ac.il/home/eofek/matlab/
% Example: telescope.obs.obspl;
% Reliable: 2
%-----------------------------------------------------------------------------

RAD     = 180./pi;
AirMass = 2.5; 

load obspl

global ObsCoo;
global Date;
global RA;
global Dec;

% set default values
if (nargin==0),
   ObsCoo  = 'Wise';
   Date    = [1 1 2001];
   RA      = [0 0 0];
   Dec     = [1 0 0 0];
end

if (nargin==0),

   close(gcf);
   close(gcf);

   h0 = figure('Color',[0.8 0.8 0.8], ...
   	       'Colormap',mat0, ...
   	       'FileName','/home/wise-cdr/eran/matlab/NEW/obspl.m', ...
   	       'PaperPosition',[18 180 576 432], ...
   	       'PaperUnits','points', ...
   	       'Position',[802 155 269 314], ...
	       'Tag','Fig1', ...
	       'ToolBar','none');


   h1 = uicontrol('Parent',h0, ...
	          'Units','points', ...
   	          'ListboxTop',0, ...
	          'Position',[22 270 200 26], ...
                  'Style','text', ...
                  'String','Observation Planner', ...
                  'FontSize',20,...
                  'Tag','StaticText1');

   %--- Observatory ---
   [ObsCoo,IDstring,FullName] = observatory_coo('Wise');
   h1 = uicontrol('Parent',h0, ...
	          'Units','points', ...
	          'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	          'ListboxTop',0, ...
	          'Min',1, ...
	          'Position',mat1, ...
	          'String', FullName, ...
                  'UserData', IDstring, ...
	          'Style','popupmenu', ...
	          'Tag','PopupMenu1', ...
	          'Callback','obspl(''ObsCoo'',gcbo);', ...
	          'CreateFcn','', ...
	          'Value',1);

   h1 = uicontrol('Parent',h0, ...
	          'Units','points', ...
   	          'ListboxTop',0, ...
	          'Position',[22 190 175 20], ...
                  'Style','text', ...
                  'String','Date', ...
                  'Tag','StaticText1');

   %--- Day ---
   h2 = uicontrol('Parent',h0, ...
	          'Units','points', ...
	          'BackgroundColor',[1 1 1], ...
	          'Callback','obspl(''Day'',gcbo);', ...
	          'CreateFcn','', ...
	          'ListboxTop',0, ...
	          'CreateFcn','', ...
	          'Position',[22 170 30 26], ...
	          'Style','edit', ...
                  'String',1,...
	          'Tag','EditText1');
   h1 = uicontrol('Parent',h0, ...
	          'Units','points', ...
   	          'ListboxTop',0, ...
	          'Position',[52 170 15 26], ...
                  'Style','text', ...
                  'String','d', ...
                  'Tag','StaticText1');

   %--- Month ---
   h3 = uicontrol('Parent',h0, ...
	          'Units','points', ...
	          'BackgroundColor',[1 1 1], ...
	          'Callback','obspl(''Month'',gcbo);', ...
	          'CreateFcn','', ...
	          'ListboxTop',0, ...
	          'Position',[70 170 30 26], ...
	          'Style','edit', ...
                  'String',1,...
	          'Tag','EditText2');
   h1 = uicontrol('Parent',h0, ...
	          'Units','points', ...
   	          'ListboxTop',0, ...
	          'Position',[100 170 15 26], ...
                  'Style','text', ...
                  'String','m', ...
                  'Tag','StaticText1');

   %--- Year ---
   h4 = uicontrol('Parent',h0, ...
	          'Units','points', ...
	          'BackgroundColor',[1 1 1], ...
	          'ListboxTop',0, ...
	          'Position',[120 170 60 26], ...
	          'Style','edit', ...
	          'Callback','obspl(''Year'',gcbo);', ...
	          'CreateFcn','', ...
                  'String',2001,...
	          'Tag','EditText3');
   h1 = uicontrol('Parent',h0, ...
	          'Units','points', ...
   	          'ListboxTop',0, ...
	          'Position',[180 170 15 26], ...
                  'Style','text', ...
                  'String','y', ...
                  'Tag','StaticText1');

   h1 = uicontrol('Parent',h0, ...
	          'Units','points', ...
   	          'ListboxTop',0, ...
	          'Position',[22 120 220 20], ...
                  'Style','text', ...
                  'String','       R.A.            2000.0               Dec.', ...
                  'Tag','StaticText1');


   %--- RAh ---
   h5 = uicontrol('Parent',h0, ...
	          'Units','points', ...
	          'BackgroundColor',[1 1 1], ...
	          'ListboxTop',0, ...
	          'Position',[22 95 30 26], ...
	          'Style','edit', ...
	          'Callback','obspl(''RAh'',gcbo);', ...
	          'CreateFcn','', ...
                  'String',0,...
	          'Tag','EditText4');
   h1 = uicontrol('Parent',h0, ...
	          'Units','points', ...
   	          'ListboxTop',0, ...
	          'Position',[52 95 15 26], ...
                  'Style','text', ...
                  'String','h', ...
                  'Tag','StaticText1');

   %--- RAm ---
   h6 = uicontrol('Parent',h0, ...
	          'Units','points', ...
	          'BackgroundColor',[1 1 1], ...
	          'ListboxTop',0, ...
	          'Position',[65 95 30 26], ...
	          'Style','edit', ...
	          'Callback','obspl(''RAm'',gcbo);', ...
	          'CreateFcn','', ...
                  'String',0,...
	          'Tag','EditText5');
   h1 = uicontrol('Parent',h0, ...
	          'Units','points', ...
   	          'ListboxTop',0, ...
	          'Position',[95 95 15 26], ...
                  'Style','text', ...
                  'String','m', ...
                  'Tag','StaticText1');

   %--- Dec_sign ---
   [IDstringD, FullNameD,DD] = dec_list;
   h7 = uicontrol('Parent',h0, ...
	          'Units','points', ...
	          'ListboxTop',0, ...
	          'Min',1, ...
	          'Position',[130 95 30 26], ...
	          'String', FullNameD, ...
                  'UserData', IDstringD,...
	          'Style','popupmenu', ...
	          'Tag','PopupMenu2', ...
	          'Callback','obspl(''Dec_sign'',gcbo);', ...
	          'CreateFcn','', ...
	          'Value',1);

   %--- Decd ---
   h8 = uicontrol('Parent',h0, ...
	          'Units','points', ...
	          'BackgroundColor',[1 1 1], ...
	          'ListboxTop',0, ...
	          'Position',[160 95 30 26], ...
	          'Style','edit', ...
	          'Callback','obspl(''Decd'',gcbo);', ...
	          'CreateFcn','', ...
                  'String',0,...
	          'Tag','EditText6');
   h1 = uicontrol('Parent',h0, ...
	          'Units','points', ...
   	          'ListboxTop',0, ...
	          'Position',[190 95 15 26], ...
                  'Style','text', ...
                  'String','o', ...
                  'Tag','StaticText1');

   %--- Decm ---
   h1 = uicontrol('Parent',h0, ...
	          'Units','points', ...
	          'BackgroundColor',[1 1 1], ...
	          'ListboxTop',0, ...
	          'Position',[200 95 30 26], ...
	          'Style','edit', ...
	          'Callback','obspl(''Decm'',gcbo);', ...
	          'CreateFcn','', ...
                  'String',0,...
	          'Tag','EditText7');
   h1 = uicontrol('Parent',h0, ...
	          'Units','points', ...
   	          'ListboxTop',0, ...
	          'Position',[230 95 15 26], ...
                  'Style','text', ...
                  'String','m', ...
                  'Tag','StaticText1');

   %--- Applay ---
   h9 = uicontrol('Parent',h0, ...
	          'Units','points', ...
	          'ListboxTop',0, ...
	          'Position',[20 50 110 25], ...
	          'Callback','obspl(''Daily'',gcbo);', ...
	          'CreateFcn','', ...
                  'String','Daily', ...
	          'Tag','Pushbutton1');

   %--- Applay ---
   h9 = uicontrol('Parent',h0, ...
	          'Units','points', ...
	          'ListboxTop',0, ...
	          'Position',[140 50 110 25], ...
	          'Callback','obspl(''Yearly'',gcbo);', ...
	          'CreateFcn','', ...
                  'String','Yearly', ...
	          'Tag','Pushbutton1');

   %--- Help ---
   h10 = uicontrol('Parent',h0, ...
	          'Units','points', ...
	          'ListboxTop',0, ...
	          'Position',[20 20 100 25], ...
	          'Callback','obspl(''Help'',gcbo);', ...
	          'CreateFcn','', ...
                  'String','Help', ...
	          'Tag','Pushbutton1');

   %--- Hold on ---
   %h11 = uicontrol('Parent',h0, ...
   %	          'Units','points', ...
   %	          'ListboxTop',0, ...
   %	          'Position',[80 20 50 25], ...
   %	          'Callback','obspl(''Holdon'',gcbo);', ...
   %	          'CreateFcn','', ...
   %              'String','Hold on', ...
   %	          'Tag','Pushbutton2');

   %--- Hold off ---
   %h12 = uicontrol('Parent',h0, ...
   %	          'Units','points', ...
   %	          'ListboxTop',0, ...
   %	          'Position',[140 20 50 25], ...
   %	          'Callback','obspl(''Holdoff'',gcbo);', ...
   %	          'CreateFcn','', ...
   %              'String','Hold off', ...
   %	          'Tag','Pushbutton3');

   %--- Exit ---
   h13 = uicontrol('Parent',h0, ...
	          'Units','points', ...
	          'ListboxTop',0, ...
	          'Position',[150 20 100 25], ...
	          'Callback','obspl(''Exit'',gcbo);', ...
	          'CreateFcn','', ...
                  'String','Exit', ...
	          'Tag','Pushbutton3');


   if nargout > 0, 
      fig = h0; 
   end


else
   [Junk,IDstring,FullName] = observatory_coo('Wise');
   [IDstringD, FullNameD,DD] = dec_list;

   switch Keyword
    case 'ObsCoo'
       ObsCooN = get(Handle,'Value');
       ObsCoo = deblank(IDstring(ObsCooN,:));
       [ObsCoo] = observatory_coo(ObsCoo);
    case 'Day'
       Day =  str2num(get(Handle,'String'));
       Date(1) = Day;

    case 'Month'
    Month =  str2num(get(Handle,'String'));
    Date(2) = Month;

    case 'Year'
       Year =  str2num(get(Handle,'String'));
       Date(3) = Year;

    case 'RAh'
       RAh =  str2num(get(Handle,'String'));
       RA(1) = RAh;

    case 'RAm'
       RAm =  str2num(get(Handle,'String'));
       RA(2) = RAm;

    case 'Dec_sign'
       Dec_sign =  get(Handle,'Value');
       Dec(1) = DD(Dec_sign);

    case 'Decd'
       Decd =  str2num(get(Handle,'String'));
       Dec(2) = Decd;

    case 'Decm'
       Decm =  str2num(get(Handle,'String'));
       Dec(3) = Decm;


    case 'Daily'
       figure(2);
       close(2);
       figure(2);
       % obj_obs_cond(ObsCoo, Date, RA, Dec)
       daily_observability(ObsCoo, Date, RA, Dec)

    case 'Yearly'
       figure(2);
       close(2);
       figure(2);
       yearly_observability(Date(3), [RA, Dec], ObsCoo, 0, AirMass);

    case 'Help'
       !netscape http://wise-obs.tau.ac.il/~eran/MATLAB/ObsPlannerHelp.html &
    case 'Exit'
       close(1);
       close(2);

    otherwise
       error('Unknown Keyword type');
   end
end




function [IDstringD, FullNameD,DD] = dec_list;
%---------------------------------------------

IDstringD = strvcat('+',...
                   '-');

FullNameD = strvcat('+',...
                   '-');

DD        = [1;-1];
