Skip to content

Commit 93eff73

Browse files
Merge pull request #50 from jazzjaikla/jazz-version-1.2.0.0
Add feature to support Yield Forecast
2 parents 1a02fef + 52ca9be commit 93eff73

File tree

13 files changed

+515
-59
lines changed

13 files changed

+515
-59
lines changed

nbproject/project.properties

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
file.reference.swingx-all-1.6.4.jar=lib\\swingx-all-1.6.4.jar
21
#Tue Jan 11 10:36:12 ICT 2022
32
jnlp.offline-allowed=false
43
javadoc.splitindex=true
@@ -59,8 +58,7 @@ javadoc.additionalparam=
5958
auxiliary.org-netbeans-spi-editor-hints-projects.perProjectHintSettingsFile=nbproject/cfg_hints.xml
6059
javac.classpath=\
6160
${libs.absolutelayout.classpath}:\
62-
${libs.CopyLibs.classpath}:\
63-
${file.reference.swingx-all-1.6.4.jar}
61+
${libs.CopyLibs.classpath}
6462
javadoc.noindex=false
6563
manifest.custom.codebase=
6664
annotation.processing.enabled.in.editor=false

src/DSSATModel/ExperimentType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ public enum ExperimentType {
88
Experimental,
99
Sequential,
1010
Seasonal,
11-
Spatial
11+
Spatial,
12+
Forecast
1213
}

src/DSSATServices/SimulationDefaultService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public void Parse() throws Exception{
3333
case Spatial:
3434
fileName = rootPath + "\\Tools\\XBuild\\Simulate_Spatial.def";
3535
break;
36+
case Forecast:
37+
fileName = rootPath + "\\Tools\\XBuild\\Simulate_Forecast.def";
38+
break;
3639
default:
3740
break;
3841
}

src/Extensions/Utils.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,20 @@ public static Date GetDate(String Header, String value, String field, int fieldL
6969

7070
String tmp = value.substring(start, stop).trim();
7171

72-
if (!tmp.equals("-99")) {
72+
if (!tmp.equals("-99") && !"".equals(tmp)) {
7373
try {
74-
Integer year = Integer.valueOf(tmp.substring(0, 2));
75-
if (year >= 60) {
76-
year += 1900;
77-
} else {
78-
year += 2000;
74+
int yearDigits = tmp.length() == 7 ? 2 : 0;
75+
Integer year = Integer.valueOf(tmp.substring(0, 2 + yearDigits));
76+
77+
if(tmp.length() == 5){
78+
if (year >= 60) {
79+
year += 1900;
80+
} else {
81+
year += 2000;
82+
}
7983
}
80-
int day = Integer.parseInt(tmp.substring(2, 5));
84+
85+
int day = Integer.parseInt(tmp.substring(2 + yearDigits, 5 + yearDigits));
8186

8287
int month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
8388
month[1] += ((year % 4) == 0) ? 1 : 0;
@@ -323,14 +328,18 @@ public static String PadRight(String value, int count, char character) {
323328
}
324329

325330
public static String JulianDate(Date date) {
326-
String d = "";
331+
return JulianDate(date, "yy");
332+
}
333+
334+
public static String JulianDate(Date date, String yearFormat) {
335+
String d;
327336

328337
try {
329338
Calendar ca = Calendar.getInstance();
330339
ca.setTime(date);
331340

332341
Locale l = new Locale("en", "US");
333-
SimpleDateFormat df = new SimpleDateFormat("yy", l);
342+
SimpleDateFormat df = new SimpleDateFormat(yearFormat, l);
334343

335344
d = df.format(date) + PadLeft(((Integer) ca.get(Calendar.DAY_OF_YEAR)).toString(), 3, '0');
336345
} catch (Exception e) {

src/Extensions/Variables.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@ public static BufferedImage getIconImage(Class<?> objectClass){
8383
}
8484

8585
public static String getVersion(){
86-
return "v1.1.0.0";
86+
return "v1.2.0.0";
8787
}
8888
}

src/FileXModel/Simulation.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ public Simulation()
128128
public String FMOPT;
129129
// </editor-fold>
130130

131+
// <editor-fold defaultstate=collapsed" desc"FORECAST">
132+
public Date ENDAT; //End of simulation date
133+
public Integer SDUR; //Maximum duration of one season
134+
public Date FODAT; //Forecast date
135+
public Integer FSTRYR; //Ensenble start year
136+
public Integer FENDYR; //Ensemblelast year
137+
public String FWFILE;//: Forecast weather file
138+
public String FONAME;//: Yield forecast name
139+
// </editor-fold>
140+
131141
@Override
132142
public Simulation clone() throws CloneNotSupportedException {
133143
Simulation sim = (Simulation)super.clone(); // return shallow copy

src/FileXService/GeneralService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public static void Read(File fileName){
2929
general.FileType = ExperimentType.Seasonal;
3030
} else if (xFile.endsWith("GSX")) {
3131
general.FileType = ExperimentType.Spatial;
32+
} else if (xFile.endsWith("FCX")) {
33+
general.FileType = ExperimentType.Forecast;
3234
} else {
3335
general.FileType = ExperimentType.Experimental;
3436
try {
@@ -212,6 +214,9 @@ else if(general.FileType == ExperimentType.Sequential){
212214
else if(general.FileType == ExperimentType.Spatial){
213215
fileXType = "GS";
214216
}
217+
else if(general.FileType == ExperimentType.Forecast){
218+
fileXType = "FC";
219+
}
215220

216221
return fileXType;
217222
}

src/FileXService/SimulationControlService.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package FileXService;
22

3+
import DSSATModel.ExperimentType;
34
import Extensions.Utils;
45
import FileXModel.FileX;
56
import FileXModel.Simulation;
@@ -31,6 +32,7 @@ public static SimulationList Read(String fileName) {
3132
String simNitrogenHeader = "";
3233
String simResidueHeader = "";
3334
String simHarvestHeader = "";
35+
String simForecastHeader = "";
3436

3537
boolean bSimulation = false;
3638
int nSimulation = 0;
@@ -70,6 +72,9 @@ public static SimulationList Read(String fileName) {
7072
} else if (bSimulation && tmp.trim().startsWith("@N HARVEST")) {
7173
simHarvestHeader = tmp.trim();
7274
nSimulation = 10;
75+
} else if (bSimulation && tmp.trim().startsWith("@N SIMDATES")) {
76+
simForecastHeader = tmp.trim();
77+
nSimulation = 11;
7378
}
7479

7580
else if (bSimulation && nSimulation == 1 && !tmp.trim().startsWith("!") && !"".equals(tmp.trim()) && !tmp.trim().startsWith("@ AUTOMATIC MANAGEMENT")) {
@@ -363,6 +368,33 @@ else if (bSimulation && nSimulation == 10 && !tmp.trim().startsWith("!") && !"".
363368
sim.HPCNP = Utils.GetFloat(simHarvestHeader, tmp, "HPCNP", 5);
364369
sim.HPCNR = Utils.GetFloat(simHarvestHeader, tmp, "HPCNR", 5);
365370

371+
if(isAdd) {
372+
simulationList.AddNew(sim);
373+
}
374+
nSimulation = -1;
375+
}
376+
else if (bSimulation && nSimulation == 11 && !tmp.trim().startsWith("!") && !"".equals(tmp.trim()) && !tmp.trim().startsWith("@ AUTOMATIC MANAGEMENT")) {
377+
Simulation sim;
378+
Integer level = Integer.valueOf(tmp.substring(0, 2).trim());
379+
380+
//@N SIMDATES ENDAT SDUR FODAT FSTRYR FENDYR FWFILE FONAME
381+
boolean isAdd = false;
382+
if(!simulationList.IsLevelExists(level)) {
383+
sim = new Simulation();
384+
sim.SetLevel(level);
385+
isAdd = true;
386+
} else {
387+
sim = (Simulation)simulationList.GetAt(level);
388+
}
389+
390+
sim.ENDAT = Utils.GetDate(simForecastHeader, tmp, "ENDAT", 8);
391+
sim.SDUR = Utils.GetInteger(simForecastHeader, tmp, " SDUR", 7);
392+
sim.FODAT = Utils.GetDate(simForecastHeader, tmp, "FODAT", 8);
393+
sim.FSTRYR = Utils.GetInteger(simForecastHeader, tmp, "FSTRYR", 7);
394+
sim.FENDYR = Utils.GetInteger(simForecastHeader, tmp, "FENDYR", 7);
395+
sim.FWFILE = Utils.GetString(simForecastHeader, tmp, "FWFILE", 16);
396+
sim.FONAME = Utils.GetString(simForecastHeader, tmp, "FONAME", tmp.length() - simForecastHeader.indexOf("FONAME"));
397+
366398
if(isAdd) {
367399
simulationList.AddNew(sim);
368400
}
@@ -519,6 +551,22 @@ public static void Extract(PrintWriter pw) {
519551
pw.print(" " + Utils.PadLeft(sim.HPCNP, 5, ' '));
520552
pw.print(" " + Utils.PadLeft(sim.HPCNR, 5, ' '));
521553
pw.println();
554+
555+
556+
if(FileX.general.FileType == ExperimentType.Forecast){
557+
pw.println("@N SIMDATES ENDAT SDUR FODAT FSTRYR FENDYR FWFILE FONAME");
558+
pw.print(Utils.PadLeft(level, 2, ' '));
559+
pw.print(" SI ");
560+
pw.print(" " + Utils.PadLeft(Utils.JulianDate(sim.ENDAT, "yyyy"), 7, ' '));
561+
pw.print(" " + Utils.PadLeft(sim.SDUR, 7, ' '));
562+
pw.print(" " + Utils.PadLeft(Utils.JulianDate(sim.FODAT, "yyyy"), 7, ' '));
563+
pw.print(" " + Utils.PadLeft(sim.FSTRYR, 7, ' '));
564+
pw.print(" " + Utils.PadLeft(sim.FENDYR, 7, ' '));
565+
pw.print(" " + Utils.PadRight(sim.FWFILE, 16, ' '));
566+
pw.print(" " + sim.FONAME);
567+
pw.println();
568+
}
569+
522570
pw.println();
523571
}
524572
}

src/xbuild/GeneralInfoFrame.form

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,12 @@
270270
<Component class="xbuild.Components.XComboBox" name="cbFileType">
271271
<Properties>
272272
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
273-
<StringArray count="4">
273+
<StringArray count="5">
274274
<StringItem index="0" value="Experimental"/>
275275
<StringItem index="1" value="Sequential"/>
276276
<StringItem index="2" value="Seasonal"/>
277277
<StringItem index="3" value="Spatial"/>
278+
<StringItem index="4" value="Forecast"/>
278279
</StringArray>
279280
</Property>
280281
</Properties>

src/xbuild/GeneralInfoFrame.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private void initComponents() {
193193
jXLabel3.setText("Site Code");
194194
jXLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
195195

196-
cbFileType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Experimental", "Sequential", "Seasonal", "Spatial" }));
196+
cbFileType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Experimental", "Sequential", "Seasonal", "Spatial", "Forecast" }));
197197
cbFileType.addActionListener(new java.awt.event.ActionListener() {
198198
public void actionPerformed(java.awt.event.ActionEvent evt) {
199199
cbFileTypeActionPerformed(evt);
@@ -763,6 +763,11 @@ private void cbFileTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
763763
cbCrop.setSelectedIndex(-1);
764764
FileX.general.crop = new Crop();
765765
break;
766+
case "Forecast":
767+
cbCrop.setEnabled(false);
768+
cbCrop.setSelectedIndex(-1);
769+
FileX.general.crop = new Crop();
770+
break;
766771
default:
767772
break;
768773
}
@@ -888,6 +893,8 @@ protected String SetDocumentName() {
888893
doc += ".SNX";
889894
} else if (cbFileType.getSelectedItem().toString().equals("Spatial")) {
890895
doc += ".GSX";
896+
} else if (cbFileType.getSelectedItem().toString().equals("Forecast")) {
897+
doc += ".FCX";
891898
}
892899
} catch (Exception ex) {
893900
}

0 commit comments

Comments
 (0)