Calculation using if then in command window?
chemgoof
SumOrgno3_tot= (soasjday-floor(soasjday))>0.24999999999 && (soasjday-floor(soasjday))<0.83333333333 ? Sumorgno3_tot[p,6479]-sumorgno3_tot[p-1] : SumOrgno3_tot
So basically it says that if the sun is up (fraction of day = 0.25-0.84), then I want the last reported number before then (p-1) subtracted from the rest of the wave. This helps me to say when night starts, then sumorgno3_tot starts from 0 again.
I want to do this for a wave covering 45 days rather than go through 45 times and subtracting the p-1. S for instance, below is some sample data. When jday > 0.25 then orgno3_tot = 0. I then want sumorgno3_tot at that point to be sumorgno3_tot - 0.0302465
Does this make sense?
Sample data
OrgNO3_tot sumOrgNO3_tot SOASJDay
0.00094628 0.0279438 154.229
0.00108462 0.0290284 154.236
0.00121807 0.0302465 154.243
0 0.0302465 154.25
0 0.0302465 154.257
0 0.0302465 154.264
0 0.0302465 154.271
0 0.0302465 154.278
Not really ??? I can not seem to be able to read past the wave names to understand what is happening mathematically. Can you boil this down to a math problem with waves wA, wB, wC, ... or something equivalent and easier to start. Also, I do not see where 45 waves come to play here. Finally, are you missing an index of p on soasjday in the conditional test (or is soasjday a variable value not a wave)?
I might recommend to do this also to help readability and stick with the bounds you want to use ...
wSum_tot = ((wjday[p] - vfloor) <= 0.25) || ((wjday[p] - vfloor) >= 0.84) ? wSum_tot[p] : wSum_tot[p,endp] - wSum_tot[p-1]
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
January 24, 2014 at 04:54 pm - Permalink
So if we rename the waves Wa Wb Wc, then when Wc-floor(Wc)>0.25 and Wc-floor(Wc)<0.833333333, then Wb=0, otherwise, Wb=Wb[p-1]+Wa[p] so the 2nd column starts at 0 til each nightfall then it starts adding up the Wa values. I want a lump sum (Wb) of the nighttime values of the Wa.
In the example above (see data below), when Wa = 0 is when Wc falls in the >=0.25 and <=0.8333333. So 0.0279438 then 0.0279438+0.00108462=0.0290284 (Wb[p-1]-Wa[p]=Wb[p]) then 0.0290284+0.00121807=0.0302465 then the sun comes up so 0.0302465-0.0302465=0. This takes place til the end of the 45 day series.
As a side note, we did this study in Centerville, AL! Hot and humid created some interesting problems with our instruments. (Saw you were at Huntsville)
Thanks for the help.
Wa Wb Wc
0.00094628 0.0279438 154.229
0.00108462 0.0290284 154.236
0.00121807 0.0302465 154.243
0.00000000 0.0302465 154.25
0.00000000 0.0302465 154.257
0.00000000 0.0302465 154.264
0.00000000 0.0302465 154.271
0.00000000 0.0302465 154.278
January 26, 2014 at 04:20 pm - Permalink
Also, I wonder how your code handles the starting point of the waves. I am surprised you do not get an exception for wave out of range when you try to do the Wb[p-1] at point p = 0. Unless you are starting at daylight so the first starting points are all zero and never get considered???
I suggest again that you might want to use the OR test rather than the AND logic.
Then, you are staying true to the cutoffs (0.25 and 0.84) rather than approximating them.
Also, since Wc has a known floor, why not just subtract it out up front and test the result?? The code would run faster and be a bit clearer to read.
Wsc = Wc - floor(Wc)
Wb = ((Wsc >= 0.25) || (Wsc <= 0.84)) ? TRUE : FALSE
As for the hot summer days in Centerville ... I wonder what happened to your instruments over the last week during the state freeze. :-)
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
January 26, 2014 at 07:22 pm - Permalink