View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
NickHK[_3_] NickHK[_3_] is offline
external usenet poster
 
Posts: 415
Default Using known arrays to calculate an array of new values

Brett,
Did you try the code I posted ?
It <should take the original array (time, qty) and adjust to the minimum
number of specified intervals (15 minutes was the example) required to cover
the sampling period.
Each qty value is adjusted by simple linear relationship. So the last qty
figure will (probably) be a projection.

But one thing strike me is that the is no reason why there should any linear
relationship between Time and rainfall.
Surely at Time "t", Precipitation is "p". There is no reason to suppose what
it would have been at t +/- 1 minute. I'm sure you know you're doing, so
then a linear relationship is easiset. I'm no maths expert, but maybe a
"least squares" solution would be better.

When you say "array", do you mean an array in memeory, or an excel range of
data ? It does matter too much, but it is easier to know where the data
resides.

NickHK


"Brett"
groups.com...

Nick,
I am not sure if I follow the code, I am fairly new to this. The code
will have to read in measured data from a worksheet (random time,
cumulative precip. amount) in sequential time. Thus creating a 2-d
array. I have gotten this far. See attached code, the next step is to
create the fixed interval array using the start time , end time, and
time interval. At this point the array is only 1d, the next step is too
loop through the new time interval array and compare values to the
measured array. Perhaps using linear interpolation to calculate the
cumulative precip. and the given time interval. These corresponding
values would be saved in a 2-d array perhaps named Interval_precip. or
something. Another alternative to using linear interpolation would be
to simply take the measured precip. amount at the nearest value less
than the interval time.
Like this
T_meas P_meas T_int P_int(this value is
calculated from meas)
1 0 0 0
8 1 15 1
16 2 30 4
22 3 45 5
29 4 60 6
36 5 etc...
53 6
etc....
The code I have thus far is attached, I really appreciate your help!
Thanks
Brett

Sub get_15_min_data()
' This program was written to convert varying interval tipping bucket
rain gage data into fixed 15 min interval data
'Declare all variables

Dim count_m As Integer
Dim calc_i As Integer
Dim start_time As Double
Dim end_time As Double
Dim Measured_array()
Dim Interval_array()
Dim interval_row As Integer
Dim time_meas As Double
Dim Cum_meas As Double
Dim time_int As Double
Dim cum_int As Double
Dim row As Integer
Dim i As Integer
Application.ScreenUpdating = False


Dim interval As Double
interval = Cells(3, 3).Value
'First loop counts the number of measured times and cumulative precip.
for the measured_array
count_m = 0
row = 5

Do Until Cells(row, 1).Value = ""
row = row + 1

count_m = count_m + 1
Loop

ReDim Measured_array(1 To (count_m + 4), 1 To 2)

'Fill the measured_array with values from worksheet

For i = 1 To (count_m)
For j = 1 To 2

Measured_array(i, j) = Cells(i + 4, j).Value
Next j
Next i

'test to see if the proper array was created
Range("L:m").Value = Measured_array
'now we need to create an array with the fixed interval times and
cumulative precip. that is calculated
start_time = Cells(1, 3).Value
end_time = Cells(2, 3).Value
interval_row = (end_time - start_time) / interval
ReDim Interval_array(1 To interval_row, 1 To 2)
' For now the code will not include a linear interpolation it will
check if the interval time is less than_
' the measured time, if so the the interval_time precip is = to the
measured time precip, if the interval time is
'greater than than measured time
'i= measured precip row
'j=measured precip column
'Ti= interval precip. time
'Pi= interval precip. rainfall cumulative inches
i = 1
j = 1
For i = 1 To count_m
For time_int = start_time To end_time Step interval
If Time_int < Measured_array(i, 1).Value Then cum_int=
For pi = 1 To 2



End Sub