Closed BrianCollinss closed 5 years ago
Hi @hol430 . Could you please help me with this?
Can you post your .apsimx file?
I want to access sowing date of Sowing from ResetWaterOnSowing.
I used this to check whether today is the planting date, instead of reading sowing date from that manager script. I am not sure if this is the ideal way of doing it.
DateUtilities.DatesEqual(DateUtilities.DMYtoISO(Wheat.SowingDate.ToShortDateString()), Clock.Today)
Try this:
string sowDate = Apsim.GetVariableObject(Parent, "[Sowing].Script.SowDate").Value as string;
if (DateUtilities.DatesEqual(sowDate, Clock.Today))
It compiles of course, but I don't have your met files so have no idea if it works or not.
I got different results with my and your method. I have factors that modify sowing dates. I am not sure which one of our methods reads the 'real' sowing date, i.e. the one after it is modified by the factor.
Something like this should tell you if my method is returning the correct sowing date:
Simulation sim = Apsim.Parent(this, typeof(Simulation)) as Simulation;
string sowDate = Apsim.GetVariableObject(Parent, "[Sowing].Script.SowDate").Value as string;
Summary.WriteMessage(this, "SimulationName=" + sim.Name + ", SowDate=" + sowDate);
if (DateUtilities.DatesEqual(sowDate, Clock.Today))
As long as you know which simulation name is supposed to correspond to which sowing date, this should let you know whether my method is returning the correct sowing date.
Disclaimer: I haven't tested this.
Drew, your method keeps the date as it is in the original Sowing manager script, i.e. it does not take into account the modification of sowing date by factors. I think if I know how to convert date to dd-mmm my method would work fine, I am testing all the date convert functions one by one.
Can you upload your met file so I can run the file? That behaviour sounds like a bug
I did. It is a couple of comments above this.
https://github.com/APSIMInitiative/ApsimX/files/2959469/Badgingarra.Research.Stn.zip
Ah right - I missed that sorry
This is the easiest way I think and it resets on sowing date every year.
string sowDate = Wheat.SowingDate.ToString("dd-MMM");
if (DateUtilities.DatesEqual(sowDate, Clock.Today))
Cheers.
It seems to be working ok for me - if I click on any of the simulations were sowing date has been set to 20-Apr, the script successfully figures out that the sowing date is 20-Apr. And in those sims where the sowing date is 20-May, the script seems to figure that out as well:
Are you seeing different behaviour, or is this not how the script is supposed to work?
You're right. It works as well. Thanks a lot Drew. That was really urgent for me.
I need to set fertilization at sowing and I need to do it without explicitly setting sowing date in fertilisation manager script. So I need to read the sowing date from 'Sowing' manager script. How can I do that? Sowing.Script.SowDate does not work.
'Models.Manager' does not contain a definition for 'Script' and no extension method 'Script' accepting a first argument of type 'Models.Manager' could be found (are you missing a using directive or an assembly reference?). Line number: 40