
;+ ***********************************************************************
; NAME:
;	MENULISTPOS
;
; PURPOSE:
;	Cette procedure contient les WIDGETS pour le listing du contenu
;	d'un fichier de flux ou de position
;	"Button"Listing: F(TIME) du menu principal
;
; CATEGORY:
;	NRH1 Menu
;
; CALLING SEQUENCE:
;	MENULISTPOS
;
; INPUTS:
;	Non
;
; KEYWORD PARAMETERS:
;	Non
;
; OUTPUTS:
;	Non
;
; COMMON BLOCKS:
;	NRH1_GLOBAL
;	NRH1_HELIO
;
; MODIFICATION HISTORY: (bonmartin@obspm.fr)
;	16/11/98 adapte du logiciel XHELIO
;-***********************************************************************

PRO MENULISTPOS_EVENT, ev

common NRH1_GLOBAL,nomfich,fichinfo
common NRH1_HELIO,mainstruct

; on charge les variables locales 
stash = WIDGET_INFO ( ev.top, /CHILD )
WIDGET_CONTROL, stash, GET_UVALUE = state


IF (ev.id EQ state.files(0)) THEN BEGIN ; *** Nom + parametres fichier pos.
        WIDGET_CONTROL,/HOURGLASS
        WIDGET_CONTROL, state.files(0), GET_VALUE = fpos
	err = newlitentete(1, fpos(0), file)
            IF (err EQ 1) THEN RETURN
	fintemp = file.heurfin
	debutemp = file.heurdeb
	pastempo = file.paspix(0) ; Pas de temps entre deux enregistrements
	WIDGET_CONTROL, state.heures, $
		SET_VALUE = [MSH(debutemp), MSH(fintemp)]
	nbpos = file.nbpix(1)/file.facbloc(1)
	options = '# ' + string(indgen(nbpos+1)-1)
	options(0) = 'Toutes'
	WIDGET_CONTROL, state.lis_numpos, SET_VALUE = options
ENDIF

IF(ev.id EQ state.heures) THEN heures = ev.value

IF(ev.id EQ state.lis_numpos) THEN BEGIN
	numpos = WIDGET_INFO(state.lis_numpos, /DROPLIST_SELECT)
	WIDGET_CONTROL, state.lis_numpos, SET_DROPLIST_SELECT = numpos
ENDIF

; bouton de controle

IF ( ev.id EQ state.bgroup_control ) THEN BEGIN 

	IF(ev.value LE 1) THEN BEGIN
		WIDGET_CONTROL, state.files(0), GET_VALUE = fpos

		err = newlitentete(1, fpos(0), file)
            		IF (err EQ 1) THEN RETURN
;	Lecture d'un tableau de positions de type 1D ou 2D
; 	identification du typ
		type = motcle(1, 'LABEL')
		type = STRUPCASE(STRMID(type, 0, 3))
		IF (type EQ 'EST' OR type EQ 'NOR') THEN BEGIN
			err = newlecp1d(4, tabpos, structab, FICHIER=fpos, $
				/oldmode)
			title = strarr(5)
		ENDIF ELSE BEGIN
			err = newlecp2d(4, tabpos, structab, FICHIER=fpos, $
				/oldmode)
			title = strarr(6)
			title(5) = STRCOMPRESS(motcle(1, 'BLOC5'))
		ENDELSE
		close, 4
		IF (err EQ 1) THEN RETURN
		title(0) = STRCOMPRESS(motcle(1, 'BLOC0'))
		title(1) = STRCOMPRESS(motcle(1, 'BLOC1'))
		title(2) = STRCOMPRESS(motcle(1, 'BLOC2'))
		title(3) = STRCOMPRESS(motcle(1, 'BLOC3'))
		title(4) = STRCOMPRESS(motcle(1, 'BLOC4'))
		pastempo = file.paspix(0)
		posinfo = structab.tabe(1:2,*)	; debut/nbre de chaque pos.
		WIDGET_CONTROL, state.heures, GET_VALUE = heures
		numpos = WIDGET_INFO(state.lis_numpos, /DROPLIST_SELECT)
		firstinst = hms(heures(0)) & lastinst = hms(heures(1))
;		Print, "Fichier de positions lu: ", fpos, " Type: ", type

		IF ev.value EQ 1 THEN BEGIN
			savename = fpos + '.sav'
			contents_of_tabpos = title
			timestep = pastempo
			nbarrs = (SIZE(tabpos))(1)
			IF nbarrs EQ 1 THEN BEGIN
				nbrpts = structab.tabe(2)
				starttime = structab.tabe(1)
			ENDIF ELSE BEGIN
				starttime = REFORM( structab.tabe(1, *) )
				nbrpts = REFORM(structab.tabe(2, *) )
			ENDELSE
			SAVE, tabpos, starttime, nbrpts, timestep, $
				contents_of_tabpos, filename=savename
			message = "Data SAVEd in file " + savename
			WIDGET_CONTROL, state.txt_message, SET_VALUE=message, $
				/APPEND
		ENDIF ELSE BEGIN
			IF numpos LE 0 THEN $
				listpos, tabpos, posinfo, pastempo, $
				heures = [firstinst, lastinst], title = title $
			ELSE $
				listpos, tabpos, posinfo, pastempo, $
				heures = [firstinst, lastinst], title= title, $
				numpos = numpos
		ENDELSE
	ENDIF

	IF(ev.value EQ 2) THEN BEGIN
		WIDGET_CONTROL, stash, SET_UVALUE = state
		WIDGET_CONTROL, ev.top, /DESTROY
		RETURN
	ENDIF

ENDIF


; on sauve les modifications
WIDGET_CONTROL, stash, SET_UVALUE = state
END

;************************************************************************
PRO MENULISTPOS

common NRH1_GLOBAL,nomfich,fichinfo
common NRH1_HELIO,mainstruct

Title = "Listing of a 1D parameter file"
;         initialisation du button group

files = lonarr ( 1 ) 

base = WIDGET_BASE (TITLE = title,/FRAME,/COLUMN, XOFFSET = 200,$
                                                  YOFFSET = 200 )
base_file = WIDGET_BASE ( base,/COLUMN,/FRAME )

base_zone = WIDGET_BASE(base, column = 2, /FRAME)

files(0)= CW_pickfile_nrh(base_file, TITLE = 'Fichier:', $
              VALUE = mainstruct.ewfile)

; Les lignes suivantes sont supprimees car files n'est pas initialise
;err = newlitentete(1, files(0), file)

;IF (err EQ 0) THEN BEGIN
;	heure = [MSH(long(file.heurdeb)), MSH(LONG(file.heurfin))]
;	deltat =  file.paspix(0)
;	nbpos = File.nbpix(1)/File.facbloc(1)  ; Nbre de positions ds fichier
;ENDIF ELSE BEGIN
	heure = ['00:00:00', '00:00:00']
	deltat = 0
	nbpos = 0
;ENDELSE

heures = CX_HEURES (base_zone,VALUE=heure)
lab_numpos = WIDGET_LABEL(base_zone, VALUE = "Source #: ")
lis_numpos = WIDGET_DROPLIST(base_zone, VALUE= ['TOUTES', '# 0'])

bgroup_control = CW_BGROUP( base, ['LIST', 'SAVE', 'QUIT'], /ROW)

txt_message = WIDGET_TEXT( base, VALUE = ' ', YSIZE=3, /SCROLL)

state = { base:base,$
          bgroup_control:bgroup_control , heures:heures, $
	  lis_numpos:lis_numpos, files:files, txt_message:txt_message}

WIDGET_CONTROL, WIDGET_INFO ( base, /CHILD ), SET_UVALUE = state 

WIDGET_CONTROL, base ,/REALIZE


XMANAGER,'MENULISTPOS', base,GROUP_LEADER = mainstruct.root, /NO_BLOCK

;stash = WIDGET_INFO ( base, /CHILD )
;WIDGET_CONTROL, stash, GET_UVALUE = state


END


 



