Single Script To Start New Log Every 12 Hours


hschir

Recommended Posts

Hi M,

I currently have a daily log sequence that starts a new log (excel) log file at midnight and runs through to 23:59 after which it creates the next days log file.

beginlogging(Field_Sensor_Log)

// loop forever:

while (1)

waituntil(23h59m)

delay(60)

// set logging file name:

logging.Field_Sensor_Log.strFileName = "C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Log_Files_Field\Daily_Field_Log_" + formatdatetime("%y_%m_%d",SysTime()) + ".csv "

// and repeat

endwhile

I am collecting weather variables water temperature variables and evaporation variables so I need to separate daylight data from night time data as midnight to midnight data makes it difficult to analyse the data e.g. water temperature where you're likely to see odd sort of trends in the analysis as lower temperatures occur either side of day time temperatures.

My question is simply this:

Is it possible in a single sequence to:

1. Start a daily log at 6:00 AM have it finish a 5:59PM called "Daily_Field_Log_Day" + formatdatetime("%y_%m_%d",SysTime()) + ".csv " and

2. at 6:00 PM on the same day begin a new log called "Daily_Field_Log_Night" + formatdatetime("%y_%m_%d",SysTime()) + ".csv " that ends at 5:59 AM the next morning, and then repeat 1 ?

I know I could create two independant log files but that gets a bit messy and laborious ...

Link to comment
Share on other sites

Sure. Though truthfully, I don't like the sequence method for doing daily log files. It's much easier to simply pick a channel that's being polled often and put the logging rename portion of the script in its event. Also, you could just redo your sequence as:


while(1)
logging.Field_Sensor_Log.strFileName = "C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Log_Files_Field\Daily_Field_Log_" + formatdatetime("%y_%m_%d",SysTime()) + ".csv "
delay(1)
endwhile
[/CODE]

The sequence will basically do nothing 99.9% of the time, until the end of the day at which point it will change the file. I'd probably set the sequence to priority 0. Yeah it seems like a waste of CPU, but really unless you are doing really heavy duty data analysis your CPU is never running full bore, so the extra few cycles to do this every second really aren't going to make a difference.

Now to your question. You can use the same trick. You just need to figure out whether it's "night" or "day":

[CODE]
while(1)
private tod = systime() % 86400
if ((tod >= 6 * 3600) && (tod < 18*3600))
logging.Field_Sensor_Log.strFileName = "C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Log_Files_Field\Daily_Field_Log_Day" + formatdatetime("%y_%m_%d",SysTime()) + ".csv "
else
logging.Field_Sensor_Log.strFileName = "C:\Users\hschiret\Documents\UNE_MonoEvap_Project\Log_Files_Field\Daily_Field_Log_Night" + formatdatetime("%y_%m_%d",SysTime()) + ".csv "
endif
delay(1)
endwhile
[/CODE]

The systime()%86400 just gets us the number of seconds in the day. The if compares that to 6 and 18 hours, and sets the file name appropriately. If you wanted to be fancy you could actually combine all that code into a single line! But it'd be a whole lot less readable.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.