I read two lines with Year, Julian day (year), hour, minute and observation.
I pull out the appropriate variables using sscanf:
sscanf(tide_str1.c_str(), "%d %d %d %d %Lf", &y1, &j1, &h1, &m1, &obs1); sscanf(tide_str2.c_str(), "%d %d %d %d %Lf", &y2, &j2, &h2, &m2, &obs2);
For this particular data set, values are: 2011 083 23 22 1.1
Then I create and populate the tm structure and run mktime, with cout calls during the day between them and changes from 083 to 364.
int y1=2011, j1=83, h1=23, m1=22; struct tm time_struct = {0, 0, 0, 0, 0, 0, 0, 0, 0}, *time_ptr = &time_struct; time_t tv_min; time_struct.tm_year = y1 - 1900; time_struct.tm_yday = j1; cout << time_struct.tm_yday << endl; time_struct.tm_hour = h1; time_struct.tm_min = m1; time_struct.tm_isdst = -1; cout << time_struct.tm_yday << endl; tv_min = mktime(time_ptr); cout << time_struct.tm_yday << endl;
Why? Is it because tm_mday and tm_mon are set to 0? At first I tried not to initialize everything to zero, but then mktime returned -1. What should I do differently if I only know the year, and not the month and month?