#!/bin/sh

# For a given fuse base dir $1 /<owfsmnt>/bus.0/21.*
# Compiles a file of lines of form
# udate temp
# (int UNIX seconds since epoch, whitespace, decimal degrees C)
# in ascending time order for just the samples taken on the current misson.

DIR=$1

SAMPLECOUNTFILE=$DIR/mission/samples
if [ ! -f $SAMPLECOUNTFILE ]; then
    echo $SAMPLECOUNTFILE not found.
    exit 1
fi
NSAMPLES=`cat $SAMPLECOUNTFILE`
if [ "X$NSAMPLES" = "X" ]; then
    echo $SAMPLECOUNTFILE empty.
fi
if [ "$NSAMPLES" -lt 1 ]; then
    echo No samples.
fi

STARTUDATE=`cat $DIR/mission/udate`
SAMPLEMINS=`cat $DIR/mission/frequency`

STARTOFFSET=`expr 31 \* 24 \* 3600`

i=0
u=`expr $STARTUDATE - $STARTOFFSET`
while [ $i -lt $NSAMPLES ];
    do
    echo $u `cat $DIR/log/temperature.$i`
    i=`expr $i + 1`
    u=`expr $u + \( 60 \* $SAMPLEMINS \)`
    done

