How or what formula to use to find the tidal window (start & end time) base on vsl Eta & HOT (height of tide)? - numbers

I had a working spreadsheet of vessel Eta to various critical Station. Base on vsl initial Eta, she will be arriving at a particular critical area on:
Eta : 02nd Jan 2023 # 19:00LT with required Height of Tide (HOT) of: 2.8m
Above is extract of the spreadsheet & tide table.
Base on vsl Eta : 02nd Jan 2023 # 19:00 & Required HOT: 2.8m (as per the spreadsheet above)
What formula to use in order to get the tidal window / range (start & end time)? Do note at certain days, there are 2 tidal window but I want the tidal window close to the Eta of the vsl. The window close to vsl Eta will be known as ‘Present Window’ & the next following window will be known as ‘Next Window’. Also if throughout the day if the HOT is greater or equal to the required HOT eg: 2.8m, I want the formula to show it as ‘Open Whole day’
I had been doing it manually. Cos I’m not sure what formula or how to get what I want.
Answer as follows:-
1)Present Window: 02nd/1700 to 02nd/2000
2)Next Window: 03rd/0000 to 03rd/0530 (can it be interpolated if possible )
03rd/0500 is 3.0 & 03rd/0600 is 2.6
Therefore 2.8m will be at 03rd/0530
3) If whole day the HOT is greater or equal to the required HOT: ‘Open Whole Day’

Related

UTC to GPS time for finding TOW in Simulink

for my project, I need to calculate TOW (Time of week) in Simulink. I know this can be achieved through conversion of UTC time to GPS time.
I have written a simple m-file in Matlab which does the action for me in Matlab as follow:
date_gps_int = 10000*y + 100*m + d
date_gps_str = int2str(date_gps_int)
date_gps_str_to_serial = datenum(date_gps_str,'yyyymmdd')
date_str_format = datestr(date_gps_str_to_serial,'dd-mmmm-yyyy')
Num_Days = daysact('06-jan-1980',date_str_format)
Num_Weeks = Num_Days/7
TOW = Num_Weeks - 1024
My first intention was to use this as a function in simulink. But apparently because of 'datenum' and 'datestr' it is not possible, since simulink does not handle strings.
Now I am wondering if anyone can help me with this issue. Is there any way to calculate TOW from the UTC date in Matlab without using those predefined functions?
I also tried to write an algorithm for calculating number of days since '6 January 1980' and then calculating number of weeks by dividing that by 7. But since I am not very familiar with leap year calculation and I don't really know the formula for these kinds of calculations, my result differs from real TOW.
I would appreciate if anybody can help me on this.
There are three formats handled by Matlab for time: formatted date strings - what datestr outputs -, serial date - scalar double, what datenum outputs - and date vectors (see datevec). Conversion functions work with these three, and the most convenient way to convert individual variables (year, month, etc) to a date is to build a date vector [yyyy mm dd HH MM SS].
date_gps_str_to_serial = datenum([y m d 0 0 0]); % midnight on day y-m-d
date_Jan_6_1980 = datenum([1980 01 06 0 0 0]); % midnight on Jan 6th, 1980
Num_Days = date_gps_str_to_serial - date_Jan_6_1980;
Now, beware of leap seconds...
GPS time is computed form the time elapsed since Jan 6th 1980. Take the number of seconds elapsed since that day, as measured by the satellites' atomic clocks, divide by (24*3600) to get a number of days, the remainder is the time of the day (in seconds since midnight).
But, once in a while, the International Earth Rotation and Reference Systems Service will decide that a day will last one second longer to accommodate for the slowing of Earth rotation. It may happen twice a year, on June 30th or December 31st. The calculation of GPS time is wrong, because it does not take into account that some days last 86401 seconds (so dividing by 24*3600 does not work) and will advance by 1 second with respect to UTC each time this happens. There has been 18 such days since Jan 6th 1980, so one should subtract 18 seconds from GPS time to find UTC time. The next time a leap second may be added is June 2019.

SSRS 2008 Calculated Chart X-Axis Interval

I am trying to create a chart where the interval on the X-axis will redefine itself depending on the 2 time parameters I have set up for the report; I have a #StartTime and a #StopTime. If the difference between the dates is one day, I want the graph axis to show a mark at each whole hour during that day. But any more than a day then the interval can be automatically determined by the program.
I have manually set the difference between the 2 parameters to be 1 day and set the interval and interval type to "24" and "hours", respectively, which gives me the desired results.
I have tried the following function for the interval:
=IIf(DateDiff("d",Parameters!StartTime.Value,Parameters!StopTime.Value)=1, "24", "Auto")
And I have tried the following function for the interval type:
=IIf(DateDiff("d",Parameters!StartTime.Value,Parameters!StopTime.Value)=1, "Hours", "Auto")
I created 2 random textboxes into which I inserted these functions to test if the functions are actually working, and they are. So I can't figure out why the functions won't execute properly when inserted into the interval properties fields.
Why is this not displaying the desired outcome?
Instead of using the text "Auto", use a Nothing to represent Auto.
eg:
=IIf(DateDiff("d",Parameters!StartTime.Value,Parameters!StopTime.Value)=1, 24, Nothing)
If I recall correctly, you can't change the the axis type at render, which seems like what your trying to do. Honestly I think this might be a case for cheating, make the chart twice, one for each axis type you want, and then conditionally hide them based on a similar Iif statement to the ones you have above.
Other thoughts, 24 is not the interval you want, interval is how much of the x-axis is displayed as tic marks. 1 means 1 tic for every 1 value, 2 means every other one, and 24 if it works would be showing every 24th value (haven't tried it). You want a number interval with a type of hour and an interval of 1 because you want to show every hour. You'll also have to change your x axis to:
=datepart(hour, Fields!YourDateTime.Value)
Otherwise the numbers axis type won't work. You can use similar expressions to create day over day time comparisons. Anyway, good luck!

Create intervals with 'datenum'

I am creating the limits for an equally spaced time series and I need to be able to change the time interval (1min, 5min, 10min, 15min, 30min, 60min etc.). My bounds are opening and closing time of the market. The stocks I am working on trades from 17.00 to 16.15 of the day after.
Here is what I am using:
timevec=datenum(2013,1,1,17,0:1*interval:1395,0)';
% It creates a time vector from 1-1-2013 17.00.00 to 1-2-2013 16.15.00
% spaced by "1min*interval"
The formula to be used is pretty simple but a problem arise if I need to use 10min or 30min as the result would be:
(10min)
02-Jan-2013 15:50:00
02-Jan-2013 16:00:00
02-Jan-2013 16:10:00
(30min)
02-Jan-2013 15:30:00
02-Jan-2013 16:00:00
What I would like to have is an extra interval 16:20:00 for the ten min case and 16:30:00 for the 30min case. The only solution I can come up with is moving the bound to 16:30 and adding an if statement to remove the extra observations in case they are not needed or keep the bound at 16:15:00 and adding an if statement to add the extra observation in case they are needed.
Is there anyway to do a one-line able to treat these two cases?
Matlab creates ranges such that all values are inside the limits. If you want to add one additional value right outside the limits, you can modify the upper limit by adding almost one interval length to the end:
step = 15;
1:step:100+0.99*step
ans =
1 16 31 46 61 76 91 106

Bins in Stata that will work in cem

In Stata is it possible (using the cem command) to create overlapping bins? For example, if a record in my treatment has DATE January 1, 2012, I want a match to be 'true' if a control record's DATE is within 2 days in either direction. I tried coding the bins manually with the treatment dates in the middle but since I have thousands of dates this is taking too long.
Using the above example control cases that would match could have dates December 30, 2011; December 31, 2011; January 1, 2012; January 2, 2012; or January 3, 2012.
You say:
I want a match to be 'true' if a control record's DATE is within 2 days
in either direction.
I have not checked the inner workings of the user-written command cem, but the variable cem_matched
(created after running cem) denotes whether an observation is matched or not and it
seems to depend on the observation belonging to a stratum in which there are
control and treatment observations. If a stratum has controled and treated
observations, they are all considered matched and cem_matched = 1. If not,
then all observations in the stratum have cem_matched = 0. So I do not see very
well how you want to modify this variable using as reference another.
Maybe you want to create the strata using the DATE variable. I'm no expert,
but to my knowledge, an observation must belong exclusively to one stratum or
another (this seems true for cem, at least). Overlapping bins violates this.
Your rule implies observations that could be to the right and left of a
certain cutpoint. From help cem:
. cem age (10 20 30 40 50) education (scott) re74, treatment(treated)
will coarsen the first variable, age into bins of (0-10), (10-20), (20-30), (30-40), (40-50) and (50+).
As you see, non-overlapping bins. What would it do if some overlapped? Where
would it assign the observation, to the bin on the left or to the right?
Some other criteria would be needed.
Maybe you want to discard (or flag) some observations per stratum based on the
DATE variable, after you run cem with other confounding covariates?
I'm not sure. Recall however that date variables in Stata can be computed on. See for example: http://www.ats.ucla.edu/stat/stata/modules/dates.htm
Note: cem is made available running ssc install cem.

MATLAB Change numbers to date

I have time set up as serial dates. Each number corresponds to a day, in order, from 20100101 to 20130611. How do I convert the serial date to a date in the format month-year? I need this because I want to plot data and need the x axis to show the date.
Thanks!
The first step is to convert your date-format into one of the standard Matlab date formats. The best format to use for plots is the "serial date format". The numbers itself are a bit awkward, since they represent the "amount of time after 0/0/0000, in days", which is a huge number. Also, this date actually never existed, making it really weird when you want to work with dates that are BC.
However, the conversion is easy, since your format also counts the days, but you count after 31st of December, 2009. You can convert this using
numeric_date_vec = datenum(2009, 12, 31) + x;
You then plot your data using
plot(numeric_date_vec, y)
and you let Matlab add the date-ticks automatically by calling
datetick('mmm yyyy')
The problem is, the ticks do not update after zooming in. You can either call
datetick('mmm yyyy','keeplimits')
again, after each zooming or panning, or you download datetickzoom from the Matlab file exchange. It takes the same arguments as datetick, but it hooks into the zoom function and updates the ticks automatically.
Edit:
Sometimes, the dateticks are not spaced in any sensible way, then you can either try to zoom in and out a little until it snaps to something good, or you have to set the ticks manually:
% Set ticks to first day of the months in 2010
tick_locations = datenum(2012,[1:12],1);
% Set ticks on x-axis
set(gca, 'XTick', tick_locations)
% Call datetick again to get the right date labels, use option "keepticks"
datetick('mmm yyyy','keeplimits', 'keepticks')
You might have to modify the tick_locations = datenum(2012,[1:12],1) a bit to get the ticks that you want. For instance, you can use
tick_locations = datenum(2012,[1:2:25],1)
to get every second month between Jan 2012 and Jan 2013.
For day number n use
datestr(datenum(2009, 12, 31) + n, 'yyyy-mm')
for example
>> datestr(datenum(2009, 12, 31)+365, 'yyyy-mm')
ans =
2010-12
>> datestr(datenum(2009, 12, 31)+366, 'yyyy-mm')
ans =
2011-01