OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
unix2ydhmsf.c
Go to the documentation of this file.
1 #include <timeutils.h>
2 #include <genutils.h>
3 
4 /* -------------------------------------------------------------- */
5 /* unix2ydhmsf() - converts secs since 1/1/70 to YYYYDDDHHMMSSFFF */
6 
7 /* -------------------------------------------------------------- */
8 char * unix2ydhmsf(double usec, char zone) {
9  struct tm *ts;
10  time_t itime;
11  static char string[17];
12 
13  if(usec == BAD_FLT) {
14  return("Undefined time");
15  }
16 
17  itime = (time_t) usec;
18  switch (zone) {
19  case 'G': ts = gmtime(&itime);
20  break;
21  case 'L': ts = localtime(&itime);
22  break;
23  default:
24  fprintf(stderr, "-E- %s line %d: ", __FILE__, __LINE__);
25  fprintf(stderr, "Bad timezone argument passed to ydhmsf().\n");
26  exit(1);
27 
28  }
29  sprintf(string, "%d%03d%02d%02d%02d%03.0f",
30  ts->tm_year + 1900,
31  ts->tm_yday + 1,
32  ts->tm_hour,
33  ts->tm_min,
34  ts->tm_sec,
35  floor(1000 * (usec - itime)));
36  return (string);
37 }
38 
39 
float tm[MODELMAX]
char * unix2ydhmsf(double usec, char zone)
Definition: unix2ydhmsf.c:8
#define BAD_FLT
Definition: jplaeriallib.h:19