libdas2
das2 core C utilities
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
das1.h File Reference

Das 1 Compatability Utilities. More...

Detailed Description

Das 1 Compatability Utilities.

#include <stdio.h>
#include <das2/util.h>

Go to the source code of this file.

Functions

void _swapBufInPlace (void *pMem, size_t szEach, size_t numItems)
 Swap whole buffers in place.
 
float swapFloat (float rIn)
 Swap single floats, returns new float.
 
int parsetime (const char *string, int *year, int *month, int *mday, int *yday, int *hour, int *minute, double *second)
 Convert most human-parseable time strings to numeric components returns 0 on success and non-zero on failure.
 
double ttime (int *year, int *month, int *mday, int *yday, int *hour, int *minute, double *second)
 Convert time components to double seconds since epoch. More...
 
void emitt (double tt, int *year, int *month, int *mday, int *yday, int *hour, int *minute, double *second)
 convert double seconds since epoch to time components. More...
 
void tnorm (int *year, int *month, int *mday, int *yday, int *hour, int *minute, double *second)
 normalize date and time components NOTE: yday is OUTPUT only. More...
 
void yrdy1958 (int *pYear, int *pDoy, int days_since_1958)
 Return a year and day of year given the number of days past 1958. More...
 
int past_1958 (int year, int day)
 Get the number of days since 1958-01-01 given a year and day of year.
 
void ms2hms (int *pHour, int *pMin, float *pSec, double ms_of_day)
 Return the hours, minutes and seconds of a day given then number of milliseconds since the start of the day. More...
 
int getpkt (char *ph, void *data, int max)
 Read a Tagged Das 1 packet from stdin. More...
 
int fgetpkt (FILE *fin, char *ph, void *data, int max)
 Read a Tagged Das 1 packet from a file object. More...
 
int putpkt (const char *ph, const void *data, int bytes)
 Write das packet to stdout. More...
 

Function Documentation

double ttime ( int *  year,
int *  month,
int *  mday,
int *  yday,
int *  hour,
int *  minute,
double *  second 
)

Convert time components to double seconds since epoch.

Converts time components to a double precision floating point value (seconds since the beginning of 1958, ignoring leap seconds) and normalize inputs. Note that this floating point value should only be used for "internal" purposes. (There's no need to propagate yet another time system, plus I want to be able to change/fix these values.)

There is no accommodation for calendar adjustments, for example the transition from Julian to Gregorian calendar, so I wouldn't recommend using these routines for times prior to the 1800's. Sun IEEE 64-bit floating point preserves millisecond accuracy past the year 3000. For various applications, it may be wise to round to nearest millisecond (or microsecond, etc.) after the value is returned.

Note
that day-of-year (yday) is an output-only parameter for all of these functions. To use day-of-year as input, set month to 1 and pass day-of-year in mday instead.
Warning
This function can change it's input values! The time will be normalized this could change the input time.
void emitt ( double  tt,
int *  year,
int *  month,
int *  mday,
int *  yday,
int *  hour,
int *  minute,
double *  second 
)

convert double seconds since epoch to time components.

emitt (ttime backwards) converts double precision seconds (since the beginning of 1958, ignoring leap seconds) to date and time components.

void tnorm ( int *  year,
int *  month,
int *  mday,
int *  yday,
int *  hour,
int *  minute,
double *  second 
)

normalize date and time components NOTE: yday is OUTPUT only.

To add a day to a time, increment mday as much as needed and then call tnorm.

void yrdy1958 ( int *  pYear,
int *  pDoy,
int  days_since_1958 
)

Return a year and day of year given the number of days past 1958.

This function is useful for years 1958 to 2096, for years greater than 2096 it runs off the end of an internal buffer.

Parameters
[out]pYeara pointer to an integer to receive the 4 digit year number
[out]pDoya pointer to an integer to recieve the day of year number (1 = Jan. 1st)
[in]days_since_1958The number of days since Jan. 1st, 1958
void ms2hms ( int *  pHour,
int *  pMin,
float *  pSec,
double  ms_of_day 
)

Return the hours, minutes and seconds of a day given then number of milliseconds since the start of the day.

Parameters
[out]pHoura pointer to an integer to receive the hour of the day (midnight = 0)
[out]pMina pointer to an integer to receive the minute of the hour.
[out]pSeca pointer to a float to receive the seconds of the minute. Result is (of course) accurate to milliseconds.
[in]ms_of_daythe milliseconds of day value.
int getpkt ( char *  ph,
void *  data,
int  max 
)

Read a Tagged Das 1 packet from stdin.

Parameters
ph8-byte packet header
databuffer,
maxnumber of bytes to read
Returns
number of bytes read
int fgetpkt ( FILE *  fin,
char *  ph,
void *  data,
int  max 
)

Read a Tagged Das 1 packet from a file object.

Parameters
[in]fininput file pointer
[out]phpointer to buffer to receive the 8-byte packet header
[out]databuffer,
[in]maxnumber of bytes to read
Returns
number of bytes read
int putpkt ( const char *  ph,
const void *  data,
int  bytes 
)

Write das packet to stdout.

Parameters
ph8-byte packet header, ex: ":b0:78F2"
databuffer
bytesnumber of bytes to write (why this isn't taken from the packet header I don't know)
Returns
1 on success and 0 on failure