;PRO GET_MASS
;
;PURPOSE: This script will open up the MASS files containing the CN2 values
;	  and dig out the values

function return_mass_spread,min1,hr1,date1,min2,hr2,date2

Mass_Dir='/a/pippin01/Volumes/u08/lsst/CPanalysis/MASS/'
Mass_file=Mass_Dir+'SpreadSheetNumbers'

CN2=dblarr(13,1553)

  readcol,Mass_file,date,time,CN2_temp05,CN2_temp1,CN2_temp2,$
	CN2_temp4,CN2_temp8,CN2_temp16,format='a,a,f,f,f,f,f,f'

  for j=0, N_elements(time)-1 do begin
 
     time_arr=strsplit(time(j),':',/extract)
     date_arr=strsplit(date(j),'/',/extract)
     CN2(0,j)=CN2_temp05(j)
     CN2(1,j)=CN2_temp1(j)
     CN2(2,j)=CN2_temp2(j)
     CN2(3,j)=CN2_temp4(j)
     CN2(4,j)=CN2_temp8(j)
     CN2(5,j)=CN2_temp16(j) 
     yr_val=valid_num(date_arr(0),year)
     month_val=valid_num(date_arr(1),month)
     date_val=valid_num(date_arr(0),date)                                
     sec_val=valid_num(time_arr(2),secs)
     min_val=valid_num(time_arr(1),mins)
     hr_val=valid_num(time_arr(0),hrs)
     CN2(6,j)=year       	;Year
     CN2(7,j)=month		;Month
     CN2(8,j)=date       	;Date
     CN2(9,j)=hrs		;Hour
     CN2(10,j)=mins		;Minute
     CN2(11,j)=secs		;Second
     juldate,[CN2(6,j),CN2(7,j),CN2(8,j),CN2(9,j),CN2(10,j),CN2(11,j)],jd
     CN2(12,j)=double(jd)
   endfor

if hr1 ne hr2 then begin
  region=where(((CN2(10,*) gt min1) and (CN2(9,*) eq hr1) and $
	        (CN2(8,*) eq date1))$
	    or ((CN2(10,*) lt min2) and (CN2(9,*) eq hr2) and $
		(CN2(8,*) eq date2)))
endif else begin
  region=where(((CN2(10,*) gt min1) and (CN2(9,*) eq hr1) and $
	        (CN2(8,*) eq date1))$
            and ((CN2(10,*) lt min2) and (CN2(9,*) eq hr2) and $
	        (CN2(8,*) eq date2)))
endelse

if region(0) ne -1 then begin
  startreg=region(0)
  stopreg=region(n_elements(region)-1)
  return,double(CN2(*,startreg:stopreg))
endif else begin
  b=fltarr(13,1)
  return,b
endelse

end


