lemon-project-template-glpk

annotate deps/glpk/src/glpenv06.c @ 9:33de93886c88

Import GLPK 4.47
author Alpar Juttner <alpar@cs.elte.hu>
date Sun, 06 Nov 2011 20:59:10 +0100
parents
children
rev   line source
alpar@9 1 /* glpenv06.c (standard time) */
alpar@9 2
alpar@9 3 /***********************************************************************
alpar@9 4 * This code is part of GLPK (GNU Linear Programming Kit).
alpar@9 5 *
alpar@9 6 * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
alpar@9 7 * 2009, 2010, 2011 Andrew Makhorin, Department for Applied Informatics,
alpar@9 8 * Moscow Aviation Institute, Moscow, Russia. All rights reserved.
alpar@9 9 * E-mail: <mao@gnu.org>.
alpar@9 10 *
alpar@9 11 * GLPK is free software: you can redistribute it and/or modify it
alpar@9 12 * under the terms of the GNU General Public License as published by
alpar@9 13 * the Free Software Foundation, either version 3 of the License, or
alpar@9 14 * (at your option) any later version.
alpar@9 15 *
alpar@9 16 * GLPK is distributed in the hope that it will be useful, but WITHOUT
alpar@9 17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
alpar@9 18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
alpar@9 19 * License for more details.
alpar@9 20 *
alpar@9 21 * You should have received a copy of the GNU General Public License
alpar@9 22 * along with GLPK. If not, see <http://www.gnu.org/licenses/>.
alpar@9 23 ***********************************************************************/
alpar@9 24
alpar@9 25 #ifdef HAVE_CONFIG_H
alpar@9 26 #include <config.h>
alpar@9 27 #endif
alpar@9 28
alpar@9 29 #include "glpapi.h"
alpar@9 30
alpar@9 31 /***********************************************************************
alpar@9 32 * NAME
alpar@9 33 *
alpar@9 34 * glp_time - determine current universal time
alpar@9 35 *
alpar@9 36 * SYNOPSIS
alpar@9 37 *
alpar@9 38 * glp_long glp_time(void);
alpar@9 39 *
alpar@9 40 * RETURNS
alpar@9 41 *
alpar@9 42 * The routine glp_time returns the current universal time (UTC), in
alpar@9 43 * milliseconds, elapsed since 00:00:00 GMT January 1, 1970. */
alpar@9 44
alpar@9 45 static const int epoch = 2440588; /* = jday(1, 1, 1970) */
alpar@9 46
alpar@9 47 /* POSIX version ******************************************************/
alpar@9 48
alpar@9 49 #if defined(HAVE_SYS_TIME_H) && defined(HAVE_GETTIMEOFDAY)
alpar@9 50
alpar@9 51 #include <sys/time.h>
alpar@9 52 #include <time.h>
alpar@9 53
alpar@9 54 glp_long glp_time(void)
alpar@9 55 { struct timeval tv;
alpar@9 56 struct tm *tm;
alpar@9 57 glp_long t;
alpar@9 58 int j;
alpar@9 59 gettimeofday(&tv, NULL);
alpar@9 60 tm = gmtime(&tv.tv_sec);
alpar@9 61 j = jday(tm->tm_mday, tm->tm_mon + 1, 1900 + tm->tm_year);
alpar@9 62 xassert(j >= 0);
alpar@9 63 t = xlset(j - epoch);
alpar@9 64 t = xlmul(t, xlset(24));
alpar@9 65 t = xladd(t, xlset(tm->tm_hour));
alpar@9 66 t = xlmul(t, xlset(60));
alpar@9 67 t = xladd(t, xlset(tm->tm_min));
alpar@9 68 t = xlmul(t, xlset(60));
alpar@9 69 t = xladd(t, xlset(tm->tm_sec));
alpar@9 70 t = xlmul(t, xlset(1000));
alpar@9 71 t = xladd(t, xlset(tv.tv_usec / 1000));
alpar@9 72 return t;
alpar@9 73 }
alpar@9 74
alpar@9 75 /* Windows version ****************************************************/
alpar@9 76
alpar@9 77 #elif defined(__WOE__)
alpar@9 78
alpar@9 79 #include <windows.h>
alpar@9 80
alpar@9 81 glp_long glp_time(void)
alpar@9 82 { SYSTEMTIME st;
alpar@9 83 glp_long t;
alpar@9 84 int j;
alpar@9 85 GetSystemTime(&st);
alpar@9 86 j = jday(st.wDay, st.wMonth, st.wYear);
alpar@9 87 xassert(j >= 0);
alpar@9 88 t = xlset(j - epoch);
alpar@9 89 t = xlmul(t, xlset(24));
alpar@9 90 t = xladd(t, xlset(st.wHour));
alpar@9 91 t = xlmul(t, xlset(60));
alpar@9 92 t = xladd(t, xlset(st.wMinute));
alpar@9 93 t = xlmul(t, xlset(60));
alpar@9 94 t = xladd(t, xlset(st.wSecond));
alpar@9 95 t = xlmul(t, xlset(1000));
alpar@9 96 t = xladd(t, xlset(st.wMilliseconds));
alpar@9 97 return t;
alpar@9 98 }
alpar@9 99
alpar@9 100 /* portable ISO C version *********************************************/
alpar@9 101
alpar@9 102 #else
alpar@9 103
alpar@9 104 #include <time.h>
alpar@9 105
alpar@9 106 glp_long glp_time(void)
alpar@9 107 { time_t timer;
alpar@9 108 struct tm *tm;
alpar@9 109 glp_long t;
alpar@9 110 int j;
alpar@9 111 timer = time(NULL);
alpar@9 112 tm = gmtime(&timer);
alpar@9 113 j = jday(tm->tm_mday, tm->tm_mon + 1, 1900 + tm->tm_year);
alpar@9 114 xassert(j >= 0);
alpar@9 115 t = xlset(j - epoch);
alpar@9 116 t = xlmul(t, xlset(24));
alpar@9 117 t = xladd(t, xlset(tm->tm_hour));
alpar@9 118 t = xlmul(t, xlset(60));
alpar@9 119 t = xladd(t, xlset(tm->tm_min));
alpar@9 120 t = xlmul(t, xlset(60));
alpar@9 121 t = xladd(t, xlset(tm->tm_sec));
alpar@9 122 t = xlmul(t, xlset(1000));
alpar@9 123 return t;
alpar@9 124 }
alpar@9 125
alpar@9 126 #endif
alpar@9 127
alpar@9 128 /***********************************************************************
alpar@9 129 * NAME
alpar@9 130 *
alpar@9 131 * glp_difftime - compute difference between two time values
alpar@9 132 *
alpar@9 133 * SYNOPSIS
alpar@9 134 *
alpar@9 135 * double glp_difftime(glp_long t1, glp_long t0);
alpar@9 136 *
alpar@9 137 * RETURNS
alpar@9 138 *
alpar@9 139 * The routine glp_difftime returns the difference between two time
alpar@9 140 * values t1 and t0, expressed in seconds. */
alpar@9 141
alpar@9 142 double glp_difftime(glp_long t1, glp_long t0)
alpar@9 143 { return
alpar@9 144 xltod(xlsub(t1, t0)) / 1000.0;
alpar@9 145 }
alpar@9 146
alpar@9 147 /**********************************************************************/
alpar@9 148
alpar@9 149 #if 0
alpar@9 150 int main(void)
alpar@9 151 { glp_long t;
alpar@9 152 glp_ldiv d;
alpar@9 153 int ttt, ss, mm, hh, day, month, year;
alpar@9 154 char s[50];
alpar@9 155 t = glp_time();
alpar@9 156 xprintf("t = %s\n", xltoa(t, s));
alpar@9 157 d = xldiv(t, xlset(1000));
alpar@9 158 ttt = d.rem.lo, t = d.quot;
alpar@9 159 d = xldiv(t, xlset(60));
alpar@9 160 ss = d.rem.lo, t = d.quot;
alpar@9 161 d = xldiv(t, xlset(60));
alpar@9 162 mm = d.rem.lo, t = d.quot;
alpar@9 163 d = xldiv(t, xlset(24));
alpar@9 164 hh = d.rem.lo, t = d.quot;
alpar@9 165 xassert(jdate(t.lo + epoch, &day, &month, &year) == 0);
alpar@9 166 xprintf("%04d-%02d-%02d %02d:%02d:%02d.%03d\n", year, month, day,
alpar@9 167 hh, mm, ss, ttt);
alpar@9 168 return 0;
alpar@9 169 }
alpar@9 170 #endif
alpar@9 171
alpar@9 172 /* eof */