Home > matutils > sunUpDown.m

sunUpDown

PURPOSE ^

%%%%%%

SYNOPSIS ^

function sunupdown=sunUpDown(datemjd,lat,long,buffer)

DESCRIPTION ^

%%%%%%
function that returns 1 if the sun is up and 0 if the sun is down for a
given lat long (in degrees) and mjd CJC 18/5/2010
Inputs datemjd
 latitude (degrees)
 longitude (degrees)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function sunupdown=sunUpDown(datemjd,lat,long,buffer)
0002 %%%%%%%
0003 %function that returns 1 if the sun is up and 0 if the sun is down for a
0004 %given lat long (in degrees) and mjd CJC 18/5/2010
0005 %Inputs datemjd
0006 % latitude (degrees)
0007 % longitude (degrees)
0008 [year,month,day,hour,minute,second]=mjd2date(datemjd(1));
0009 
0010 date = datenum(year,month,day,hour,minute,second);
0011 [rhr,rmin,shr,smin]=sunrise(day,month,year,lat,long);
0012 MJD_rise = date2mjd(year, month, day, rhr, rmin, 0); %sun rise in MJD
0013 MJD_set =  date2mjd(year, month, day, shr, smin, 0); %sun set in MJD
0014 MJD_risePrev=MJD_rise-1;
0015 MJD_setPrev=MJD_set-1;
0016 MJD_riseNext=MJD_rise+1;
0017 MJD_setNext=MJD_set+1;
0018 
0019 sunvec=[MJD_risePrev MJD_setPrev MJD_rise MJD_set MJD_riseNext MJD_setNext];
0020 sunvecSort=sort(sunvec);
0021 
0022 if(sunvecSort(1)==MJD_setPrev)
0023    sort1= (datemjd>(sunvecSort(1)+((buffer/60)/24))) & (datemjd<(sunvecSort(2)-((buffer/60)/24)))  ; %sundown
0024    sort2= (datemjd>(sunvecSort(2)-((buffer/60)/24))) & (datemjd<(sunvecSort(3)+((buffer/60)/24)))  ; %sunup
0025    sort3= (datemjd>(sunvecSort(3)+((buffer/60)/24))) & (datemjd<(sunvecSort(4)-((buffer/60)/24)))  ; %sundown
0026    sort4= (datemjd>(sunvecSort(4)-((buffer/60)/24))) & (datemjd<(sunvecSort(5)+((buffer/60)/24)))  ; %sunup
0027    sort5= (datemjd>(sunvecSort(5)+((buffer/60)/24))) & (datemjd<(sunvecSort(6)-((buffer/60)/24)))  ; %sundown
0028    sort6= datemjd>(sunvecSort(6)-((buffer/60)/24))   ; %sunup
0029    sunup=sort2|sort4|sort6;
0030    sundown=sort1|sort3|sort5;
0031 else if(sunvecSort(1)==MJD_risePrev)
0032    sort1= datemjd>(sunvecSort(1)-((buffer/60)/24)) & (datemjd<(sunvecSort(2)+((buffer/60)/24)))  ; %sunup
0033    sort2= datemjd>(sunvecSort(2)+((buffer/60)/24)) & (datemjd<(sunvecSort(3)-((buffer/60)/24)))  ; %sundown
0034    sort3= datemjd>(sunvecSort(3)-((buffer/60)/24)) & (datemjd<(sunvecSort(4)+((buffer/60)/24)))  ; %sunup
0035    sort4= datemjd>(sunvecSort(4)+((buffer/60)/24)) & (datemjd<(sunvecSort(5)-((buffer/60)/24)))  ; %sundown
0036    sort5= datemjd>(sunvecSort(5)-((buffer/60)/24)) & (datemjd<(sunvecSort(6)+((buffer/60)/24)))  ; %sunup
0037    sort6= datemjd>(sunvecSort(6)+((buffer/60)/24))   ; %sundown
0038    sunup=sort1|sort3|sort5;
0039    sundown=sort2|sort4|sort6;
0040    end    
0041 end
0042 
0043 
0044 sunupdown =sunup; %positive when the sun is up
0045

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005