FUNCTION SMH,Time,arr=arr,str=str,ms=ms,arr3=arr3,arr4=arr4

;+
;************************************************************
;	Function SMH converts input time (seconds) into the
;  string 'hh:mm:ss.msmsms', if keywords arr3 or arr4 are not
;  present. In this former case number of digits in millise-
;  conds is defined by the argument "ms" (default ms=0).
;       If keyword arr3 (arr4) present, then the output vari-
;  able is an array containing hours, minutes and seconds in-
;  cluding (or for the case "arr4" - hours, minutes, integer 
;  parts of ;  seconds, milliseconds). Here is ms=3 default.
;	Input variable must be of double precision.
;	Output variables are floating-point, double precision.
;
;	EXAMPLES:
;	print,smh(hms(22,02,09.923)*3600D,ms=2)
;	-	"22:02:09.923" will be printed. 
;	print,smh(hms(22,02,09.923)*3600D,ms=0)
;	-	"22:02:10" will be printed.
;	print,smh(hms(22,02,09.923)*3600D,/arr4)
;	-	"22.000000  2.0000000  9.0000000  923.00000"
;			    will be printed.
;
;************************************************************
;-


		Timein=abs(double(Time))

		if N_elements(ms) le 0 then begin
if not keyword_set(arr3) and not keyword_set(arr4) then ms=0 $
	else ms=3
		endif else ms=fix(ms)

Timein=double(string(Timein,format=$
	'(f'+string(20+ms)+'.'+string(ms)+')'  ))

Sz=Size(Timein)

        hour = long(Timein)/3600
        minute = long(Timein-3600*hour)/60
        sec = Timein mod 60
	sec_int=double(fix(sec))
	msec=(sec-sec_int)*1d3
	hour=hour mod 24

if (Sz(0) eq 0) then Output="''" else $
	Output=make_array(size=Sz,/string,value="''")

	N_lt_0=where(Time lt 0)
	N_ge_0=where(Time ge 0)

Ms_Format=strcompress('i'+string(ms)+'.'+string(ms),/rem)

Hms_Format="I2.2,':',I2.2,':',I2.2"

	IF ms eq 0 THEN $
Out_Format=["('-',"+Hms_Format+")", "("+Hms_Format+")"] ELSE $
Out_Format=["('-',"+Hms_Format+",'.',"+Ms_Format+")", $
	"("+Hms_Format+",'.',"+Ms_Format+")"]

		CASE 1 OF

keyword_set(arr4): Output=[hour,minute,sec_int,msec]*sign(Time)
keyword_set(arr3): Output=[hour,minute,sec]*sign(Time)

ELSE:	begin
;stop
msec=fix(msec*10.^(ms-3)+0.5*10.^(-ms))

	CASE ms OF

0:	begin

if N_lt_0(0) ne -1 then Output(N_lt_0)=string((transpose( $
	[[hour(N_lt_0)],	$
	[minute(N_lt_0)],	$
	[sec_int(N_lt_0)]])),Format=Out_Format(0))

if N_ge_0(0) ne -1 then Output(N_ge_0)=string((transpose( $
	[[hour(N_ge_0)],	$
	[minute(N_ge_0)],	$
	[sec_int(N_ge_0)]])),Format=Out_Format(1))

	end

ELSE:	begin

if N_lt_0(0) ne -1 then Output(N_lt_0)=string((transpose( $
	[[hour(N_lt_0)],	$
	[minute(N_lt_0)],	$
	[sec_int(N_lt_0)],	$
	[msec(N_lt_0)]])),Format=Out_Format(0))

if N_ge_0(0) ne -1 then Output(N_ge_0)=string((transpose( $
	[[hour(N_ge_0)],	$
	[minute(N_ge_0)],	$
	[sec_int(N_ge_0)],	$
	[msec(N_ge_0)]])),Format=Out_Format(1))

	end
	ENDCASE

		end
		ENDCASE

if n_elements(Output) eq 1 then Output=Output(0)

        	RETURN,Output

	        END
