diff --git a/src/main/java/edu/sc/seis/TauP/Arrival.java b/src/main/java/edu/sc/seis/TauP/Arrival.java index c3b5d159..e56f71b2 100644 --- a/src/main/java/edu/sc/seis/TauP/Arrival.java +++ b/src/main/java/edu/sc/seis/TauP/Arrival.java @@ -614,7 +614,7 @@ public void writeJSON(PrintWriter pw, String indent) throws IOException { } else { pw.write(innerIndent+" "+JSONWriter.valueToString("error")+": "+JSONWriter.valueToString("geometrical speading not finite")+","+NL); } - pw.write(innerIndent+" "+JSONWriter.valueToString("refltranpsv")+": "+JSONWriter.valueToString((float)getReflTransPSV())+NL); + pw.write(innerIndent+" "+JSONWriter.valueToString("refltranpsv")+": "+JSONWriter.valueToString((float)getReflTransPSV())+", "+NL); pw.write(innerIndent+" "+JSONWriter.valueToString("refltransh")+": "+JSONWriter.valueToString((float)getReflTransSH())+NL); pw.write(innerIndent+"}"); } catch (TauPException e) { diff --git a/src/test/java/edu/sc/seis/TauP/CmdLineOutputTest.java b/src/test/java/edu/sc/seis/TauP/CmdLineOutputTest.java index a47bb784..b2c64ba7 100644 --- a/src/test/java/edu/sc/seis/TauP/CmdLineOutputTest.java +++ b/src/test/java/edu/sc/seis/TauP/CmdLineOutputTest.java @@ -5,6 +5,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import org.json.JSONObject; +import org.json.JSONTokener; import org.junit.jupiter.api.Test; import java.io.BufferedOutputStream; @@ -112,6 +114,10 @@ public class CmdLineOutputTest { "taup wkbj --help", }; + String[] jsonTestCmds = new String[] { + "taup time -h 10 -ph P -deg 35 --json", + }; + String versionCmd = "taup --version"; String[] docCmds = new String[] { @@ -144,6 +150,7 @@ public void regenSavedOutput() throws Exception { allList.addAll(Arrays.asList(velplotTestCmds)); allList.addAll(Arrays.asList(reflTransPlotTestCmds)); allList.addAll(Arrays.asList(phaseDescribeTestCmds)); + allList.addAll(Arrays.asList(jsonTestCmds)); for (String cmd : allList) { System.err.println(cmd); saveTestOutputToFile(cmd); @@ -318,6 +325,11 @@ public void testTauPReflTransplot() throws Exception { runTests(reflTransPlotTestCmds); } + + @Test + public void testTauPJSON() throws Exception { + runJsonTests(jsonTestCmds); + } @Test public void testTauPTable() throws Exception { // this one takes a lot of memory @@ -330,6 +342,12 @@ public void runTests(String[] cmds) throws Exception { } } + public void runJsonTests(String[] cmds) throws Exception { + for (int i = 0; i < cmds.length; i++) { + testJsonCmd(cmds[i]); + } + } + public void runCmd(String cmd) throws Exception { String[] s = cmd.split(" +"); String tool = s[0]; @@ -371,6 +389,19 @@ public void testCmd(String cmd) throws Exception { origErr.println("Done with " + cmd); } + public void testJsonCmd(String cmd) throws Exception { + setUpStreams(); + assertEquals(0, outContent.toByteArray().length, "sysout is not empty"); + runCmd(cmd); + BufferedReader prior = getPriorOutput(cmd); + BufferedReader current = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(outContent.toByteArray()))); + JSONTokener jsonIn = new JSONTokener(prior); + JSONObject priorJson = new JSONObject(jsonIn); + JSONTokener currentIn = new JSONTokener(current); + JSONObject currentJson = new JSONObject(currentIn); + assertTrue(priorJson.similar(currentJson), currentJson.toString(2)); + } + /** * test loading prior results text file from test resources. Kind of a meta-test... :) * @throws Exception diff --git a/src/test/resources/edu/sc/seis/TauP/cmdLineTest/taup_time_-h_10_-ph_P_-deg_35_--json b/src/test/resources/edu/sc/seis/TauP/cmdLineTest/taup_time_-h_10_-ph_P_-deg_35_--json new file mode 100644 index 00000000..9524aaed --- /dev/null +++ b/src/test/resources/edu/sc/seis/TauP/cmdLineTest/taup_time_-h_10_-ph_P_-deg_35_--json @@ -0,0 +1,25 @@ +{ + "model": "iasp91", + "sourcedepth": 10, + "receiverdepth": 0, + "phases": [ "P" ], + "arrivals": [ + { + "distdeg": 35, + "phase": "P", + "time": 412.4329, + "rayparam": 8.613012, + "takeoff": 26.741543, + "incident": 26.69624, + "puristdist": 35, + "puristname": "P", + "amp": { + "factorpsv": 2.0197284E-9, + "factorsh": 0, + "geospread": 8.546455E-9, + "refltranpsv": 0.9386537, + "refltransh": 0 + } + } + ] +} diff --git a/src/test/resources/edu/sc/seis/TauP/cmdLineTest/taup_time_-h_10_-ph_ttall_-deg_35_-mod_ak135_--json b/src/test/resources/edu/sc/seis/TauP/cmdLineTest/taup_time_-h_10_-ph_ttall_-deg_35_-mod_ak135_--json index 9d29ab7e..dda711b7 100644 --- a/src/test/resources/edu/sc/seis/TauP/cmdLineTest/taup_time_-h_10_-ph_ttall_-deg_35_-mod_ak135_--json +++ b/src/test/resources/edu/sc/seis/TauP/cmdLineTest/taup_time_-h_10_-ph_ttall_-deg_35_-mod_ak135_--json @@ -17,7 +17,7 @@ "factorpsv": 2.2448705E-9, "factorsh": 0, "geospread": 9.4910035E-9, - "refltranpsv": 0.93945855 + "refltranpsv": 0.93945855, "refltransh": 0 } }, @@ -34,7 +34,7 @@ "factorpsv": -1.0049341E-9, "factorsh": 0, "geospread": 6.4029417E-9, - "refltranpsv": -0.6233852 + "refltranpsv": -0.6233852, "refltransh": 0 } }, @@ -51,7 +51,7 @@ "factorpsv": 6.4090083E-10, "factorsh": 0, "geospread": 4.5169624E-9, - "refltranpsv": 0.5635634 + "refltranpsv": 0.5635634, "refltransh": 0 } }, @@ -68,7 +68,7 @@ "factorpsv": -5.602378E-10, "factorsh": 0, "geospread": 8.134539E-9, - "refltranpsv": -0.27355075 + "refltranpsv": -0.27355075, "refltransh": 0 } }, @@ -85,7 +85,7 @@ "factorpsv": 1.3256608E-10, "factorsh": -0, "geospread": -1.9293809E-9, - "refltranpsv": -0.27290586 + "refltranpsv": -0.27290586, "refltransh": 0 } }, @@ -102,7 +102,7 @@ "factorpsv": 2.6919594E-10, "factorsh": -0, "geospread": -3.71326E-9, - "refltranpsv": -0.28794637 + "refltranpsv": -0.28794637, "refltransh": 0 } }, @@ -119,7 +119,7 @@ "factorpsv": -5.6609734E-11, "factorsh": 0, "geospread": 2.3569615E-9, - "refltranpsv": -0.09539752 + "refltranpsv": -0.09539752, "refltransh": 0 } }, @@ -136,7 +136,7 @@ "factorpsv": -1.3889002E-10, "factorsh": 0, "geospread": 5.318295E-9, - "refltranpsv": -0.10372825 + "refltranpsv": -0.10372825, "refltransh": 0 } }, @@ -153,7 +153,7 @@ "factorpsv": 3.416083E-10, "factorsh": 0, "geospread": 4.892863E-9, - "refltranpsv": 0.2773089 + "refltranpsv": 0.2773089, "refltransh": 0 } }, @@ -170,7 +170,7 @@ "factorpsv": -8.8572594E-10, "factorsh": -9.559001E-10, "geospread": -2.9885563E-9, - "refltranpsv": 0.90920216 + "refltranpsv": 0.90920216, "refltransh": 0.98123634 } }, @@ -187,7 +187,7 @@ "factorpsv": 4.1380797E-9, "factorsh": 0, "geospread": 1.3097071E-8, - "refltranpsv": 0.96927536 + "refltranpsv": 0.96927536, "refltransh": 0 } }, @@ -204,7 +204,7 @@ "factorpsv": 1.1673663E-11, "factorsh": 1.2368819E-9, "geospread": 3.867232E-9, - "refltranpsv": 0.009260394 + "refltranpsv": 0.009260394, "refltransh": 0.9811842 } }, @@ -221,7 +221,7 @@ "factorpsv": -1.1158017E-9, "factorsh": -0, "geospread": -5.35934E-9, - "refltranpsv": 0.82694024 + "refltranpsv": 0.82694024, "refltransh": 0 } }, @@ -238,7 +238,7 @@ "factorpsv": -2.5531965E-9, "factorsh": -0, "geospread": -8.364679E-9, - "refltranpsv": 0.93639153 + "refltranpsv": 0.93639153, "refltransh": 0 } }, @@ -255,7 +255,7 @@ "factorpsv": 7.988524E-11, "factorsh": 0, "geospread": 8.102375E-10, - "refltranpsv": 0.39160898 + "refltranpsv": 0.39160898, "refltransh": 0 } }, @@ -272,7 +272,7 @@ "factorpsv": 1.2438949E-9, "factorsh": -0, "geospread": -8.27238E-9, - "refltranpsv": -0.46129176 + "refltranpsv": -0.46129176, "refltransh": 0 } }, @@ -289,7 +289,7 @@ "factorpsv": -8.1902435E-10, "factorsh": -8.249301E-10, "geospread": -3.3388534E-9, - "refltranpsv": 0.7525268 + "refltranpsv": 0.7525268, "refltransh": 0.7579531 } }, @@ -306,7 +306,7 @@ "factorpsv": 1.0724646E-9, "factorsh": 9.91436E-10, "geospread": 4.542847E-9, - "refltranpsv": 0.72423136 + "refltranpsv": 0.72423136, "refltransh": 0.6695131 } }, @@ -323,7 +323,7 @@ "factorpsv": -4.3499293E-10, "factorsh": -5.341819E-10, "geospread": -1.5133576E-9, - "refltranpsv": 0.8817859 + "refltranpsv": 0.8817859, "refltransh": 1.0828545 } }, @@ -340,7 +340,7 @@ "factorpsv": 1.5740333E-12, "factorsh": -6.924226E-12, "geospread": -7.743721E-10, - "refltranpsv": -0.0062357215 + "refltranpsv": -0.0062357215, "refltransh": 0.02743115 } }, @@ -357,7 +357,7 @@ "factorpsv": -5.583343E-10, "factorsh": 2.9569622E-9, "geospread": 2.7051914E-9, - "refltranpsv": -0.63316786 + "refltranpsv": -0.63316786, "refltransh": 3.3532836 } }, @@ -374,7 +374,7 @@ "factorpsv": 1.95126E-11, "factorsh": 0, "geospread": 1.9792763E-9, - "refltranpsv": 0.0391568 + "refltranpsv": 0.0391568, "refltransh": 0 } }, @@ -391,7 +391,7 @@ "factorpsv": -2.5029583E-11, "factorsh": 0, "geospread": 2.5453137E-9, - "refltranpsv": -0.039058067 + "refltranpsv": -0.039058067, "refltransh": 0 } }, @@ -408,7 +408,7 @@ "factorpsv": 3.6171706E-13, "factorsh": 0, "geospread": 6.49183E-10, - "refltranpsv": 0.0022130962 + "refltranpsv": 0.0022130962, "refltransh": 0 } }, @@ -425,7 +425,7 @@ "factorpsv": -2.4197686E-10, "factorsh": -6.5053596E-10, "geospread": -2.0617155E-9, - "refltranpsv": 0.360054 + "refltranpsv": 0.360054, "refltransh": 0.9679771 } }, @@ -442,7 +442,7 @@ "factorpsv": 1.6212206E-12, "factorsh": 0, "geospread": 1.6025435E-9, - "refltranpsv": 0.0040181926 + "refltranpsv": 0.0040181926, "refltransh": 0 } }, @@ -459,7 +459,7 @@ "factorpsv": -1.1651941E-11, "factorsh": 0, "geospread": 2.0197959E-9, - "refltranpsv": -0.022913383 + "refltranpsv": -0.022913383, "refltransh": 0 } }, @@ -476,7 +476,7 @@ "factorpsv": -8.4029674E-13, "factorsh": 0, "geospread": 1.4995897E-9, - "refltranpsv": -0.0022256593 + "refltranpsv": -0.0022256593, "refltransh": 0 } }, @@ -493,7 +493,7 @@ "factorpsv": 2.7018132E-12, "factorsh": 0, "geospread": 2.1195457E-9, - "refltranpsv": 0.003910525 + "refltranpsv": 0.003910525, "refltransh": 0 } }, @@ -510,7 +510,7 @@ "factorpsv": 1.5691697E-13, "factorsh": 0, "geospread": 1.3950303E-9, - "refltranpsv": 3.4507122E-4 + "refltranpsv": 3.4507122E-4, "refltransh": 0 } }, @@ -527,7 +527,7 @@ "factorpsv": -1.1094422E-10, "factorsh": 0, "geospread": 5.4908333E-10, - "refltranpsv": -0.80253667 + "refltranpsv": -0.80253667, "refltransh": 0 } }, @@ -544,7 +544,7 @@ "factorpsv": -3.7748006E-11, "factorsh": 0, "geospread": 3.769393E-10, - "refltranpsv": -0.39775994 + "refltranpsv": -0.39775994, "refltransh": 0 } }, @@ -561,7 +561,7 @@ "factorpsv": 1.6563683E-13, "factorsh": 0, "geospread": 1.6232624E-9, - "refltranpsv": 3.130334E-4 + "refltranpsv": 3.130334E-4, "refltransh": 0 } }