# HG changeset patch
# User Satyam Pandey <satyampandey0009@gmail.com>
# Date 1457818627 -19800
#      Sun Mar 13 03:07:07 2016 +0530
# Node ID 465fc0bd84d140f2b7342a82e38a307de2386497
# Parent  120bb822c6f4a30217a174f40d28da2b21854976
Bugfix for bug_47026

diff -r 120bb822c6f4 -r 465fc0bd84d1 libinterp/corefcn/defun.cc
--- a/libinterp/corefcn/defun.cc	Sun Feb 28 19:07:24 2016 +0000
+++ b/libinterp/corefcn/defun.cc	Sun Mar 13 03:07:07 2016 +0530
@@ -27,7 +27,7 @@
 #include <sstream>
 #include <iostream>
 #include <string>
-
+#include <cstdio>
 #include "defun.h"
 #include "dynamic-ld.h"
 #include "error.h"
diff -r 120bb822c6f4 -r 465fc0bd84d1 scripts/time/datenum.m
--- a/scripts/time/datenum.m	Sun Feb 28 19:07:24 2016 +0000
+++ b/scripts/time/datenum.m	Sun Mar 13 03:07:07 2016 +0530
@@ -91,81 +91,82 @@
 
 function [days, secs] = datenum (year, month = [], day = [], hour = 0, minute = 0, second = 0)
 
-  ## Days until start of month assuming year starts March 1.
-  persistent monthstart = [306; 337; 0; 31; 61; 92; 122; 153; 184; 214; 245; 275];
-  persistent monthlength = [31; 28; 31; 30; 31; 30; 31; 31; 30; 31; 30; 31];
-
-  if (nargin == 0 || nargin > 6
-      || (nargin > 2 && (ischar (year) || iscellstr (year))))
-    print_usage ();
-  endif
-
-  if (ischar (year) || iscellstr (year))
-    [year, month, day, hour, minute, second] = datevec (year, month);
-  else
-    if (nargin == 1)
-      nc = columns (year);
-      if (nc > 6 || nc < 3)
-        error ("datenum: expected date vector containing [YEAR, MONTH, DAY, HOUR, MINUTE, SECOND]");
-      endif
-      if (nc >= 6) second = year(:,6); endif
-      if (nc >= 5) minute = year(:,5); endif
-      if (nc >= 4) hour   = year(:,4); endif
-      day   = year(:,3);
-      month = year(:,2);
-      year  = year(:,1);
-    endif
-  endif
-
-  if (! (isa (year, "double") && isa (month, "double")
+ 	## Days until start of month assuming year starts March 1.
+ 	persistent monthstart = [306; 337; 0; 31; 61; 92; 122; 153; 184; 214; 245; 275];
+ 	persistent monthlength = [31; 28; 31; 30; 31; 30; 31; 31; 30; 31; 30; 31];
+  
+	if (nargin == 0 || nargin > 6|| (nargin > 2 && (ischar (year) || iscellstr (year))))
+    	print_usage ();
+  	endif
+  	if (ischar (year) || iscellstr (year))
+    	[year, month, day, hour, minute, second] = datevec (year, month);
+		flag = 1;
+  	else
+    	if (nargin == 1 )
+      	nc = columns (year);		
+			if (nc == 6 || nc == 3)
+				
+      			if (nc >= 6) second = year(:,6); endif
+      			if (nc >= 5) minute = year(:,5); endif
+      			if (nc >= 4) hour   = year(:,4); endif
+      			day   = year(:,3);
+      			month = year(:,2);
+      			year  = year(:,1);
+				flag = 1;
+			else
+				flag = 0;
+			endif
+   		endif
+  	endif
+  	
+	if (flag)	
+  		if (! (isa (year, "double") && isa (month, "double")
          && isa (day, "double") && isa (hour, "double")
          && isa (minute, "double") && isa (second, "double")))
-    error ("datenum: all inputs must be of class double");
-  endif
-
-  month(month < 1) = 1;  # For compatibility.  Otherwise allow negative months.
-
-  ## Treat fractional months, by converting the fraction to days
-  if (floor (month) != month)
-    fracmonth = month - floor (month);
-    month = floor (month);
-    if ((mod (month-1,12) + 1) == 2
-        && (floor (year/4) - floor (year/100) + floor (year/400)) != 0)
-      ## leap year
-      day += fracmonth * 29;
-    else
-      day += fracmonth * monthlength ((mod (month-1,12) + 1));
-    endif
-  endif
-
-  ## Set start of year to March by moving Jan. and Feb. to previous year.
-  ## Correct for months > 12 by moving to subsequent years.
-  year += fix ((month-14)/12);
-
-  ## Lookup number of days since start of the current year.
-  if (numel (month) == 1 || numel (day) == 1)
-    ## Allow month or day to be scalar while other values may be vectors or
-    ## matrices.
-    day += monthstart (mod (month-1,12) + 1) + 60;
-    if (numel (month) > 1)
-      day = reshape (day, size (month));
-    endif
-  else
-    day += reshape (monthstart (mod (month-1,12) + 1), size (day)) + 60;
-  endif
-
-  ## Add number of days to the start of the current year. Correct
-  ## for leap year every 4 years except centuries not divisible by 400.
-  day += 365*year + floor (year/4) - floor (year/100) + floor (year/400);
-
-  ## Add fraction representing current second of the day.
-  days = day + (hour + (minute + second/60)/60)/24;
-
-  ## Output seconds if asked so that etime can be more accurate
-  if (isargout (2))
-    secs = day*86400 + hour*3600 + minute*60 + second;
-  endif
-
+    		error ("datenum: all inputs must be of class double");
+ 	 	endif	
+	 	month(month < 1) = 1;  # For compatibility.  Otherwise allow negative months.	
+		 ## Treat fractional months, by converting the fraction to days
+		if (floor (month) != month)
+		   	fracmonth = month - floor (month);
+		  	month = floor (month);
+		   	if ((mod (month-1,12) + 1) == 2
+		       	&& (floor (year/4) - floor (year/100) + floor (year/400)) != 0)
+		    	## leap year
+		     	day += fracmonth * 29;
+		   	else
+		     	day += fracmonth * monthlength ((mod (month-1,12) + 1));
+		   	endif
+		endif	
+		## Set start of year to March by moving Jan. and Feb. to previous year.
+		## Correct for months > 12 by moving to subsequent years.
+		year += fix ((month-14)/12);	
+		## Lookup number of days since start of the current year.
+		if (numel (month) == 1 || numel (day) == 1)
+		   ## Allow month or day to be scalar while other values may be vectors or
+		   ## matrices.
+		   	day += monthstart (mod (month-1,12) + 1) + 60;
+		   	if (numel (month) > 1)
+		     day = reshape (day, size (month));
+		   	endif
+		else
+		   	day += reshape (monthstart (mod (month-1,12) + 1), size (day)) + 60;
+		endif	
+		## Add number of days to the start of the current year. Correct
+		## for leap year every 4 years except centuries not divisible by 400.
+		day += 365*year + floor (year/4) - floor (year/100) + floor (year/400);	
+		## Add fraction representing current second of the day.
+		days = day + (hour + (minute + second/60)/60)/24;	
+		## Output seconds if asked so that etime can be more accurate
+		if (isargout (2))
+		   secs = day*86400 + hour*3600 + minute*60 + second;
+		endif
+	else
+		if (!isnumeric(year))
+			error ("datenum: all inputs must be of class double");
+		endif
+		days=year;
+	endif
 endfunction
 
 
