Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
11 | - | 1 | package org.geoscope.JSpec; |
2 | |||
3 | //import java.awt.Frame; |
||
4 | //import javax.swing.JFileChooser; |
||
5 | |||
6 | import java.io.BufferedInputStream; |
||
7 | import java.io.BufferedReader; |
||
8 | import java.io.DataOutputStream; |
||
9 | import java.io.File; |
||
10 | import java.io.FileInputStream; |
||
11 | //import java.io.FileNotFoundException; |
||
12 | import java.io.FileWriter; |
||
13 | //import java.io.IOException; |
||
14 | import java.io.InputStream; |
||
15 | import java.io.InputStreamReader; |
||
16 | import java.io.PrintWriter; |
||
17 | import java.util.ArrayList; |
||
18 | import java.util.HashSet; |
||
19 | import java.util.Iterator; |
||
20 | |||
21 | //import javax.swing.JOptionPane; |
||
22 | |||
23 | import com.martiansoftware.jsap.*; |
||
24 | |||
25 | |||
26 | |||
27 | |||
28 | public class JSpec { |
||
29 | private static References References; |
||
30 | public static void main(String[] args) throws Exception { |
||
31 | |||
32 | |||
33 | JSAP jsap = new JSAP(); |
||
34 | |||
35 | FlaggedOption opt0 = new FlaggedOption("jspec.ini") |
||
36 | .setStringParser(JSAP.STRING_PARSER) |
||
37 | .setShortFlag('j') |
||
38 | .setLongFlag("jspec.ini") |
||
39 | .setAllowMultipleDeclarations(false) |
||
40 | .setRequired(true); |
||
41 | |||
42 | opt0.setHelp("The JSpec.ini file to use"); |
||
43 | jsap.registerParameter(opt0); |
||
44 | |||
45 | FlaggedOption opt1 = new FlaggedOption("png_save_dir") |
||
46 | .setStringParser(JSAP.STRING_PARSER) |
||
47 | .setShortFlag('p') |
||
48 | .setLongFlag("png_save_dir") |
||
49 | .setAllowMultipleDeclarations(false) |
||
50 | .setRequired(true); |
||
51 | |||
52 | opt1.setHelp("The Directory to save the png"); |
||
53 | jsap.registerParameter(opt1); |
||
54 | |||
55 | |||
56 | FlaggedOption opt2 = new FlaggedOption("legende") |
||
57 | .setStringParser(JSAP.STRING_PARSER) |
||
58 | .setShortFlag('l') |
||
59 | .setLongFlag("legende") |
||
60 | .setAllowMultipleDeclarations(false) |
||
61 | .setRequired(false); |
||
62 | |||
63 | opt2.setHelp("The legend of the spectrum"); |
||
64 | jsap.registerParameter(opt2); |
||
65 | |||
66 | |||
67 | FlaggedOption opt3 = new FlaggedOption("dataless") |
||
68 | .setStringParser(JSAP.STRING_PARSER) |
||
69 | .setShortFlag('d') |
||
70 | .setLongFlag("dataless") |
||
71 | .setAllowMultipleDeclarations(true) |
||
72 | .setRequired(true); |
||
73 | |||
74 | opt3.setHelp("The dataless to use"); |
||
75 | jsap.registerParameter(opt3); |
||
76 | |||
77 | |||
78 | UnflaggedOption opt4 = new UnflaggedOption("miniseed_1") |
||
79 | .setStringParser(JSAP.STRING_PARSER) |
||
80 | .setList(true) |
||
81 | .setListSeparator(',') |
||
82 | .setRequired(true); |
||
83 | |||
84 | opt4.setHelp("The miniseed files to use for the first group"); |
||
85 | jsap.registerParameter(opt4); |
||
86 | |||
87 | |||
88 | UnflaggedOption opt5 = new UnflaggedOption("miniseed_2") |
||
89 | .setStringParser(JSAP.STRING_PARSER) |
||
90 | .setDefault("") |
||
91 | .setList(true) |
||
92 | .setListSeparator(',') |
||
93 | .setRequired(false); |
||
94 | |||
95 | opt5.setHelp("The miniseed files to use for the second group"); |
||
96 | jsap.registerParameter(opt5); |
||
97 | |||
98 | |||
99 | |||
100 | |||
101 | JSAPResult config = jsap.parse(args); |
||
102 | if (!config.success()) { |
||
103 | |||
104 | System.err.println(); |
||
105 | |||
106 | // print out specific error messages describing the problems |
||
107 | // with the command line, THEN print usage, THEN print full |
||
108 | // help. This is called "beating the user with a clue stick." |
||
109 | for (java.util.Iterator errs = config.getErrorMessageIterator(); |
||
110 | errs.hasNext();) { |
||
111 | System.err.println("Error: " + errs.next()); |
||
112 | } |
||
113 | |||
114 | System.err.println(); |
||
115 | System.err.println("Usage: java " |
||
116 | + JSpec.class.getName()); |
||
117 | System.err.println(" " |
||
118 | + jsap.getUsage()); |
||
119 | System.err.println(); |
||
120 | System.err.println(jsap.getHelp()); |
||
121 | System.exit(1); |
||
122 | } |
||
123 | |||
124 | |||
125 | |||
126 | // On a donner tout les bons arguments |
||
127 | |||
128 | // Ce test sera a priori toujours vrai car 1 dataless est necessaire au bon fonctionnement... |
||
129 | if (config.getStringArray("dataless").length==1) { |
||
130 | // les infos du premier groupe |
||
131 | System.out.println("dataless groupe 1"); |
||
132 | System.out.println(config.getStringArray("dataless")[0]); |
||
133 | |||
134 | System.out.println("Fichiers miniseed groupe 1"); |
||
135 | |||
136 | String[] miniseed_1 = config.getStringArray("miniseed_1"); |
||
137 | System.out.println("On va traiter "+miniseed_1.length+" fichiers"); |
||
138 | |||
139 | MSeed_Group mseed_group =new MSeed_Group(); |
||
140 | |||
141 | References= new References(config.getString("jspec.ini"),config.getString("png_save_dir"),config.getString("legende"),config.getString("legende")); |
||
142 | |||
143 | |||
144 | //ArrayList<MSeed_File> hash_miniseed = new ArrayList<MSeed_File>(); |
||
145 | |||
146 | // MSeed_File[] tablo_Mseed_files=null; |
||
147 | |||
148 | if (miniseed_1.length == 1) |
||
149 | {//Dans le cas d'un seul fichier, on ne fait pas de moyenne |
||
150 | //MSeed_File mseed_file= new MSeed_File(new File(miniseed_1[0]).getAbsoluteFile(),new File(config.getStringArray("dataless")[0]).getAbsoluteFile(), new File(config.getString("jspec.ini")).getAbsoluteFile(), new File(config.getString("png_save_dir")).getAbsoluteFile().getPath(),config.getString("legende") ); |
||
151 | MSeed_File mseed_file = new MSeed_File(new File(miniseed_1[0]).getAbsoluteFile(),new File(config.getStringArray("dataless")[0]).getAbsoluteFile(), References); |
||
152 | |||
153 | mseed_file.parse_mseed(); |
||
154 | mseed_file.to_sac(); |
||
155 | mseed_file.read_dataless_3(); |
||
156 | |||
157 | mseed_file.spec(); |
||
158 | |||
159 | mseed_file.plot_spec(); |
||
160 | mseed_file.clean(); |
||
161 | //System.out.println("on a fini"); |
||
162 | |||
163 | } |
||
164 | else |
||
165 | { |
||
166 | |||
167 | // On est dans le cas d'un groupe de plus d'un fichier miniseed. |
||
168 | |||
169 | int nb_fichiers_miniseed=miniseed_1.length; |
||
170 | |||
171 | for (int j = 0; j < nb_fichiers_miniseed; ++j) { |
||
172 | // On va traiter le fichier machin |
||
173 | System.out.println("Debut de traitement du fichier :"+j+" /"+nb_fichiers_miniseed); |
||
174 | |||
175 | MSeed_File Mseed_tmp = new MSeed_File(new File(miniseed_1[j]).getAbsoluteFile(),new File(config.getStringArray("dataless")[0]).getAbsoluteFile(), References); |
||
176 | Mseed_tmp.parse_mseed(); |
||
177 | Mseed_tmp.to_sac(); |
||
178 | Mseed_tmp.read_dataless_3(); |
||
179 | Mseed_tmp.spec(); |
||
180 | |||
181 | //On rajoute l'objet miniseed au hash |
||
182 | //hash_miniseed.add(Mseed_tmp); |
||
183 | mseed_group.add_MSeed_file(Mseed_tmp); |
||
184 | |||
185 | //test.plot_spec(); |
||
186 | } |
||
187 | //moyenne_les_spectres_et_sauve(hash_miniseed); |
||
188 | |||
189 | // On va créer un instance de l'objet qui fait les moyennes et les graphes |
||
190 | |||
191 | ArrayList<MSeed_Group> liste_des_mseed_groupes= new ArrayList<MSeed_Group>(); |
||
192 | liste_des_mseed_groupes.add(mseed_group); |
||
193 | |||
194 | Spec_Trace traceur = new Spec_Trace(liste_des_mseed_groupes, References); |
||
195 | |||
196 | traceur.do_collections_group_means(); |
||
197 | traceur.do_graphs(); |
||
198 | |||
199 | |||
200 | // maintenant que les calculs ont été fait, on peut virer les fichiers temporaires |
||
201 | |||
202 | for ( MSeed_Group tmp_mseed_group : liste_des_mseed_groupes) { |
||
203 | tmp_mseed_group.clean(); |
||
204 | } |
||
205 | |||
206 | } |
||
207 | } |
||
208 | else if (config.getStringArray("dataless").length==2) { |
||
209 | |||
210 | // les infos du premier groupe |
||
211 | System.out.println("dataless groupe 1"); |
||
212 | System.out.println(config.getStringArray("dataless")[0]); |
||
213 | |||
214 | System.out.println("Fichiers miniseed groupe 1"); |
||
215 | String[] miniseed_1 = config.getStringArray("miniseed_1"); |
||
216 | int nb_fichiers_miniseed_1=miniseed_1.length; |
||
217 | for (int j = 0; j < nb_fichiers_miniseed_1; ++j) { |
||
218 | System.out.println(miniseed_1[j]); |
||
219 | } |
||
220 | |||
221 | // les infos du deuxieme groupe |
||
222 | System.out.println("dataless groupe 2"); |
||
223 | System.out.println(config.getStringArray("dataless")[1]); |
||
224 | |||
225 | System.out.println("Fichiers miniseed groupe 2"); |
||
226 | String[] miniseed_2 = config.getStringArray("miniseed_2"); |
||
227 | |||
228 | int nb_fichiers_miniseed_2=miniseed_2.length; |
||
229 | |||
230 | for (int j = 0; j < nb_fichiers_miniseed_2; ++j) { |
||
231 | System.out.println(miniseed_2[j]); |
||
232 | } |
||
233 | } |
||
234 | else if (config.getStringArray("dataless").length==3) { |
||
235 | //On est dans le cas de trois groupes de fichiers avec 3 dataless |
||
236 | } |
||
237 | |||
238 | |||
239 | //System.err.println("Usage: JSpec [-legende \"legend of the graph\"] -png_save_dir png_save_directory -jspec.ini jspec_ini_file -dataless dataless_file -miniseed miniseed_file"); |
||
240 | |||
241 | |||
242 | |||
243 | |||
244 | |||
245 | // MSeed_File test = new MSeed_File(new File(miniseed_string).getAbsoluteFile(),new File(dataless_string).getAbsoluteFile(), new File(jspec_ini_string).getAbsoluteFile(), new File(png_save_dir_string).getAbsoluteFile().getPath(),legende_string ); |
||
246 | // |
||
247 | // |
||
248 | // // test.get_location_code_and_station_name(); |
||
249 | // // |
||
250 | // // if (!test.is_location_code()) { |
||
251 | // // System.out.println("Il va falloir mettre un location code"); |
||
252 | // // } |
||
253 | // |
||
254 | // test.parse_mseed(); |
||
255 | // test.to_sac(); |
||
256 | // test.read_dataless_3(); |
||
257 | // |
||
258 | // test.spec(); |
||
259 | // test.plot_spec(); |
||
260 | // test.clean(); |
||
261 | // System.exit(0); |
||
262 | |||
263 | } |
||
264 | |||
265 | |||
266 | |||
267 | |||
268 | } |