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

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

Mass_Dir='/nfs/slac/g/ki/ki08/lsst/CPanalysis/MASS/'

Mass_files=['orig_turb_data0', 'orig_turb_data1', 'orig_turb_data2',$
'orig_turb_data4', 'orig_turb_data8','orig_turb_data16']


CN2=dblarr(13,1553)

for i=0, N_elements(Mass_files)-1 do begin

  readcol,Mass_Dir+Mass_files(i),date,time,CN2_temp,format='a,a,f'

  for j=0, N_elements(time)-1 do begin
 
     time_arr=strsplit(time(j),':',/extract)
     date_arr=strsplit(date(j),'/',/extract)
     CN2(i,j)=CN2_temp(j)
     CN2(6,j)=date_arr(0)	;Year
     CN2(7,j)=date_arr(1)	;Month
     CN2(8,j)=date_arr(2)	;Date
     CN2(9,j)=time_arr(0)	;Hour
     CN2(10,j)=time_arr(1)	;Minute
     CN2(11,j)=time_arr(2)	;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
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


