D
deskcheck1
Guest
I have a text file that lists weather data from years 1900-2015. I need to only select
a specific date range for each year from 2001 to 2015.
How do I specify a date range, for example, I only want daily data from 5/24/2006 through 10/20/2006?
Another issue: how to select specify date range that spans multiple years? For example,
from 11/25/2004 to 5/5/2005?
So far here's what I'm doing:
Do While wReader.EndOfStream = False
wLine = wReader.ReadLine()
yr = CInt(Mid(wLine, 1, 6))
mo = CInt(Mid(wLine, 7, 4))
dy = CInt(Mid(wLine, 11, 4))
tmax = CSng(Mid(wLine, 21, 6))
tmin = CSng(Mid(wLine, 27, 6))
tave = (tmax + tmin) / 2
Dim plant_date = PlantMth + PlantDay / 100 ' format month.day
Dim harvest_date = HarvMth + HarvDay / 100 ' format month.day
mydate = mo + dy / 100 ' format month.day
currDate = New DateTime(yr, mo, dy)
'Get date range: plant date to harvest date
If yr > 2000 And yr <= 2015 Then
If (yr = PlantYr4Digit And yr = HarvestYr4Digit) And (mydate >= plant_date And mydate <= harvest_date) Then
'Calculate daily PHU
phu_today = tave - CropMinTemp 'why it's reading at 5/25/2006???
If phu_today < 0 Then phu_today = 0 ' negative PHUs not allowed
phu_oper_cum(i) = phu_today
If (i = 0) Then
phu_oper_running_total(i) = phu_oper_running_total(i) + phu_today
Else
phu_oper_running_total(i) = phu_oper_running_total(i - 1) + phu_today
End If
sum = dt_oper.AsEnumerable().Sum(Function(row) row.Field(Of Single)("phu"))
dt_oper.Rows.Add(phu_today, sum)
i = i + 1
If i > growingDays Then i = growingDays
End If
End If
Loop
Sample text file (Fixed-Width)
2001 06 28 0.0029.51019.80000.94
2001 06 29 0.0032.06021.01000.04
2001 06 30 0.0031.17022.16008.16
2001 07 01 0.0029.81022.14001.27
2001 07 02 0.0031.82022.43000.12
2001 07 03 0.0030.43022.74015.08
2001 07 04 0.0030.88023.07006.87
2001 07 05 0.0030.72023.97003.27
2001 07 06 0.0031.64023.30000.05
....etc....
2006 04 29 0.0026.02017.55000.01
2006 04 30 0.0024.42020.77004.72
2006 05 01 0.0025.84020.11001.23
2006 05 02 0.0026.97017.48000.00
2006 05 03 0.0027.65016.41000.03
2006 05 04 0.0028.45018.00000.04
2006 05 05 0.0028.92019.59000.27
....etc...
My If statements don't seem to hold true for each year. Can't figure out how to fix it.
Appreciate any help.
Marilyn Gambone
Continue reading...
a specific date range for each year from 2001 to 2015.
How do I specify a date range, for example, I only want daily data from 5/24/2006 through 10/20/2006?
Another issue: how to select specify date range that spans multiple years? For example,
from 11/25/2004 to 5/5/2005?
So far here's what I'm doing:
Do While wReader.EndOfStream = False
wLine = wReader.ReadLine()
yr = CInt(Mid(wLine, 1, 6))
mo = CInt(Mid(wLine, 7, 4))
dy = CInt(Mid(wLine, 11, 4))
tmax = CSng(Mid(wLine, 21, 6))
tmin = CSng(Mid(wLine, 27, 6))
tave = (tmax + tmin) / 2
Dim plant_date = PlantMth + PlantDay / 100 ' format month.day
Dim harvest_date = HarvMth + HarvDay / 100 ' format month.day
mydate = mo + dy / 100 ' format month.day
currDate = New DateTime(yr, mo, dy)
'Get date range: plant date to harvest date
If yr > 2000 And yr <= 2015 Then
If (yr = PlantYr4Digit And yr = HarvestYr4Digit) And (mydate >= plant_date And mydate <= harvest_date) Then
'Calculate daily PHU
phu_today = tave - CropMinTemp 'why it's reading at 5/25/2006???
If phu_today < 0 Then phu_today = 0 ' negative PHUs not allowed
phu_oper_cum(i) = phu_today
If (i = 0) Then
phu_oper_running_total(i) = phu_oper_running_total(i) + phu_today
Else
phu_oper_running_total(i) = phu_oper_running_total(i - 1) + phu_today
End If
sum = dt_oper.AsEnumerable().Sum(Function(row) row.Field(Of Single)("phu"))
dt_oper.Rows.Add(phu_today, sum)
i = i + 1
If i > growingDays Then i = growingDays
End If
End If
Loop
Sample text file (Fixed-Width)
2001 06 28 0.0029.51019.80000.94
2001 06 29 0.0032.06021.01000.04
2001 06 30 0.0031.17022.16008.16
2001 07 01 0.0029.81022.14001.27
2001 07 02 0.0031.82022.43000.12
2001 07 03 0.0030.43022.74015.08
2001 07 04 0.0030.88023.07006.87
2001 07 05 0.0030.72023.97003.27
2001 07 06 0.0031.64023.30000.05
....etc....
2006 04 29 0.0026.02017.55000.01
2006 04 30 0.0024.42020.77004.72
2006 05 01 0.0025.84020.11001.23
2006 05 02 0.0026.97017.48000.00
2006 05 03 0.0027.65016.41000.03
2006 05 04 0.0028.45018.00000.04
2006 05 05 0.0028.92019.59000.27
....etc...
My If statements don't seem to hold true for each year. Can't figure out how to fix it.
Appreciate any help.
Marilyn Gambone
Continue reading...