-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSLIMSearch.java
More file actions
3304 lines (2981 loc) · 140 KB
/
Copy pathSLIMSearch.java
File metadata and controls
3304 lines (2981 loc) · 140 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package es.smr.slim.plugins;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Vector;
import javax.swing.JOptionPane;
import uk.ac.starlink.table.ColumnInfo;
import uk.ac.starlink.table.RowListStarTable;
import es.cab.astronomical.AstronomicalChangeUnit;
import es.cab.astronomical.AstronomicalImagePlus;
import es.cab.astronomical.components.AstronomicalJFrameMASSA;
import es.cab.astronomical.components.AstronomicalPanelManagerMASSA;
import es.cab.astronomical.components.AstronomicalTabbedPaneMASSA;
import es.cab.astronomical.utils.AstronomicalFunctionsGenerics;
import es.cab.astronomical.utils.HistoryAndMacrosUtils;
import es.cab.madcuba.log.Log;
import es.cab.madcuba.utils.MyConstants;
import es.cab.madcuba.utils.MyUtilities;
import es.cab.plugins.WindowsPluginsUtils;
import es.cab.swing.gui.EditorInformationMADCUBA;
import es.smr.slim.DbHSQLDBCreate;
import es.smr.slim.LineSearchPanel;
import es.smr.slim.ModelLTESyntheticMoleculeFit;
import es.smr.slim.MolecularSpecies;
import es.smr.slim.components.simfit.SimFitParametersTable;
import es.smr.slim.beans.DataMolecular;
import es.smr.slim.beans.SearchSlimParams;
import es.smr.slim.calc.RangeH;
import es.smr.slim.utils.ArrayRange;
import es.smr.slim.utils.ImportFileSimulate;
import es.smr.slim.utils.Range;
import es.smr.slim.utils.SlimConstants;
import es.smr.slim.utils.SlimUtilities;
import herschel.share.unit.Frequency;
import herschel.share.unit.Unit;
import ij.IJ;
import ij.Macro;
import ij.WindowManager;
import ij.plugin.PlugIn;
import ij.plugin.frame.Recorder;
/**
* <p>This plugin makes a search of molecules for indicated params.
* The search can make for a range of indicated frequency or for a spectra.
* The params: </p>
* <ul>
* <li>range = this range is frequency list or wavelength list. The arguments can be: *
* <ul>
* <li>The list separate with '#': freq1#freq2#..</li>
* <li>selected_data: Make search about range selected frequency in associated data spectra(selected rows)/cube </li>
* <li>window_active: look the active plot from associated product and it uses the range shows in this plot</li>
* <li>cube_container:(no implement) make search from range frequencies in selected cube in cube container window </li>
* <li>whole: Make search about all possible frequencies (0-Double.Max). </li>
* </ul>
* </li>
* <li>range = this range is frequency list or wavelength list. The arguments is separate freq1#freq2#..</li>
* <li> axislabel = It is the label of type of unit (xAxis) showing (range). The types are:
* <ul>
* <li>frequency</li>
* <li>wavelength</li>
* </ul>
* </li>
* <li> axisunit = It is the label of type of selected unit.
* If the unit label is frequency then it is Hz, MHz, GHz, TGHz
* If the unit label is wavelength thin it is cm, mm, micrometer, nm, ua
* </li>
* <li>molecules = It is the list of molecules in the next format:
* <ul>
* <li>CASE 1: CATALOG$MOLECULE$CRITERIOS#CATALOG$MOLECULE$CRITERIOS#. Ej; JPL$CS$Any$-3$Any$300#CMDS$CS+$Any$Any$Any@300#
* </li>
* <li>CASE 2: CATALOG$MOLECULE#. Ej1: JPL$C*#. Ej2: lovas1992$CS#</li>
* <li>CASE 3: CATALOG$MOLDECULE$DELTA#. Ej: Recomb.Lines$C$1#</li>
* </ul>
* </li>
* <li>searchtype = the arguments are:
* <ul>
* <li>new: it makes a new search in a new tab (DEFAUTL PARAMS)</li>
* <li>add: the result is added to last search.</li>
* <li>update_transitions: In a tab, repeat a search and add new transitions (you can change the frequency range)</li>
* </ul>
* </li>
* <li>datafile = It is the name of associated MADCUBA file</li>
* <li>datatype = It is the type of associated MADCUBA file. It can be SPECTRA OR CUBE (if not exist no problem)</li>
* <li>searchcriteria = list default values molecules, if it not exists any molecule criteria then searched filters with this criteria (format delta_n$ElowMin$ElowMax$logI)</li>
*<li>
* clearsearch = It is true or false. If the parameter doesn't exist then the value is false
* It the parameter is true then the table is empty and the directory with all search files. Too the variables of tab used to search
* It the parameter is false then no make nothing new. (make a search normal)
* </li>
* <li>sql</li>
* <li>where</li>
* <li>rename_molecule</li>
* <li>inputsql</li>
* </ul>
* <p>Methods</p>
* <ul>
* <li>existsResult. Indicated it is found some transitiomn in las Search. Return true or false. Example: call("SLIM_Search.existsResult") </li>
* </ul>
*
* @author blancoscm
*
*/
public class SLIMSearch implements PlugIn
{
private static final String CUBE_CONTAINER = LineSearchPanel.CUBE_CONTAINER;
private static final String SELECTED_DATA = LineSearchPanel.SELECTED_DATA;
private static final String SELECTED_WINDOW = LineSearchPanel.SELECTED_WINDOW;
private static final String SELECTED_WHOLE_RANGE = LineSearchPanel.SELECTED_WHOLE_RANGE;
private static boolean [] existsQn7InCatalogs = null;
private static boolean isFoundNewValues = false;
public void run(String arg) {
String sArg = Macro.getOptions();
boolean isMacro = false;
if(sArg == null || sArg.equals(""))
{
sArg = arg;
} else {
isMacro = true;
}
if(sArg!=null &&(sArg.toLowerCase().equals("help")
|| sArg.toLowerCase().equals("help ")))
{
IJ.log("\n"+this.getClass().getName()+":\n "+getInfo()+"\n");
return;
}
SearchSlimParams params = getParamsPlugin(sArg);
SLIMFRAME slimFrame = ((SLIMFRAME) WindowManager.getFrame(SlimConstants.FRAME_SLIM));// listSlectedMolecules();
LineSearchPanel searchPanel = null;
boolean isSQL = params.getSQL()!=null && !params.getSQL().isEmpty();
isSQL = isSQL || (params.getFileSQL()!=null && !params.getFileSQL().isEmpty());
if(!isSQL&&(params.getArrListMolecules()==null || params.getArrListMolecules().length==0))
{
if(!isMacro && !MyUtilities.showMessageWithNoYesOption(searchPanel,
"No selected molecules for searching?.\n Do you want to search all molecules?", "WARNING: Search All MOlecules"))
return;
else if(isMacro)
EditorInformationMADCUBA.append("Searching all molecules");
}
if(slimFrame==null)
{
IJ.run(SlimConstants.FRAME_SLIMFRAME.replaceAll("_", " "));
slimFrame = ((SLIMFRAME) WindowManager.getFrame(SlimConstants.FRAME_SLIM));
} else {
slimFrame.setVisible(true);
}
double memoryFree = MyUtilities.memoryDiskLinuxInfo()[0];
if(memoryFree<0.5D)
{
String message = "Your computer has less than 0.5GB is posibled the application don't work correctly.";
if (isMacro)
EditorInformationMADCUBA.appendLineError(message);
else if(! MyUtilities.showMessageWithNoYesOption(null, message+"\nDo you want continue?", "Warninig Memory"))
return;
}
IJ.wait(10);
if(slimFrame!=null)
{//TODO ESTO ESTA MAL, DEBERIA FUNCIONAR SIN PANEL SI LANZO DESDE MACRO
searchPanel = slimFrame.getPanelLineSearch();
if(params.getAssociatedFile()==null || params.getAssociatedFile().isEmpty())
{
//GET ACTIVE PRODUCTO
String[] nameFileType = searchPanel.getNameFileMADCUBA();
boolean isConnectTables = false;
if(nameFileType!=null && nameFileType[0]!=null)
{
if (nameFileType[0]!=null)
{
params.setAssociatedFile(nameFileType[0]);
if(slimFrame.getLineSearchResults()==null || slimFrame.getLineSearchResults().getLabelFileFITS()==null || slimFrame.getLineSearchResults().getLabelFileFITS().isEmpty()
|| slimFrame.getLineSearchResults().getDataFileMASSAJ()==null
|| slimFrame.getLineSearchResults().getDataFileMASSAJ().getNameFile()==null
|| slimFrame.getLineSearchResults().getDataFileMASSAJ().getNameFile().isEmpty()){
isConnectTables = true;
}
}
if (nameFileType[1]!=null)
params.setTypeAssociatedFile(nameFileType[1]);
}
//MIRAR SI TIENE EN RESTO DE LOS SITIOS PARA VER SI LO CONECTO O NO, PORQUE ANTES NO ERA NECESARIO, PERO AHORA SI
//DE HECHO HAY QUE PASAR EL NOMBRE, PARA HACERLO, SI SE PASA NOMBRE, HAY QUE COMPRARARLO CON EL DE OTRO SITIO NO CON PANES
// if(params.getAssociatedFile()!=null && searchPanel.isMADCUBA_IJconnected()) {
if(params.getAssociatedFile()!=null && isConnectTables) {
/* nameFileType = searchPanel.getNameMADCUBA_IJconnected();
if (nameFileType[0]!=null)
params.setAssociatedFile(nameFileType[0]);
if (nameFileType[1]!=null)
params.setTypeAssociatedFile(nameFileType[1]);*/
//TENDRIA QUE CONECTARLO
if(slimFrame.getPanelModelLTESimFit()==null)
slimFrame.charguePanelModelLTESimFit();
if(SLIMFRAME.getInstance(false).getPanelModelLTESimFit()!=null)
{
boolean isRecord = Recorder.record;
Recorder.record = false;
try { //ESTO NO LO DEBERIA HACER ANTES DEL SEARCH??
// Log.getInstance().logger.debug("SLIM GENERATE CALL CHANGE DATA");
// String argPlugin = "spectra='"+newFileData[0]+"' asksave=false ismacro="+isMacro;
// IJ.getInstance().runUserPlugIn(ListPluginsNamesSlim.SLIM_CHANGE_DATA,
// ListPluginsNamesSlim.SLIM_CHANGE_DATA, argPlugin, false);
// SLIMChangeData.changeData(isMacro, false, isMacro, slimFrame, nameFileType, true,true,true); //NO CARGAR DATOS
}finally {
Recorder.record = isRecord;
}
nameFileType = SlimUtilities.changeUnitIntensityVelocity(nameFileType,false,true); //FALTARIA TODAVIA OTRA VALIDACION
if(nameFileType==null)
{
EditorInformationMADCUBA.appendLineError("The unit no exists. Indicated name in Modify_Data, Tab 'Operations'");
return;
}
if (nameFileType[0]!=null)
params.setAssociatedFile(nameFileType[0]);
if (nameFileType[1]!=null)
params.setTypeAssociatedFile(nameFileType[1]);
searchPanel.setNameFileMADCUBA(nameFileType, true, false);
SLIMFRAME.getInstance(false).getPanelModelLTESimFit().setHistorySLIM(null);
// slimFrame.getPanelModelLTESimFit().getSimFitter().setListChannelsSpectral(null);
SLIMFRAME.getInstance(false).getPanelModelLTESimFit().getSimFitter().connectToSpectra(nameFileType);
//AUUNQUE AQUI DEBERIA VER SI EXISTE IMPORT PARAMS
SLIMFRAME.getInstance(false).getPanelModelLTESimFit().setTextPixel(SLIMFRAME.getInstance(false).getPanelModelLTESimFit().getSimFitter().getPixelShow(),false);
}
}
// else if(isConnectTables)
// {
//
// }
if(nameFileType==null || params.getAssociatedFile()==null)
{
EditorInformationMADCUBA.appendLineError("No found any data (spectra or cube)");
return;
}
if(slimFrame.getPanelModelLTESimFit()!=null&&slimFrame.getPanelModelLTESimFit().getSimFitter()!=null && slimFrame.getPanelModelLTESimFit().getSimFitter().tabSearchSIMFIT!=null)
{
if(((nameFileType[1]==null && nameFileType[0]!=null) && nameFileType[0].equals(SlimConstants.NAME_FITS_TYPE_CUBE_SYNCHRO_NEW))
||
(nameFileType[1]!=null&&(nameFileType[1].equals(SlimConstants.FITS_TYPE_CUBE_SYNCHRO)||
nameFileType[1].equals(SlimConstants.FITS_TYPE_CUBE)) )
&& slimFrame.getPanelModelLTESimFit().getSimFitter().tabSearchSIMFIT.getTabCount()>=1
&& params.getSearchType().equals("new"))
{
EditorInformationMADCUBA.appendLineError("Can't seach is a new tab for syncronize or cube (only can be one search).");
return;
}
}
} else {
String[] nameFileType = searchPanel.getNameFileMADCUBA();
//MIRAR TAMBIEN DIALOG, PORQUE SE PUEDE HABER CABIADO ESTE Y TODAVIA NO TENER BUSQUEDA
boolean isConnectTables = false;
if(slimFrame.getLineSearchResults()==null || slimFrame.getLineSearchResults().getLabelFileFITS()==null || slimFrame.getLineSearchResults().getLabelFileFITS().isEmpty()
|| slimFrame.getLineSearchResults().getDataFileMASSAJ()==null
|| slimFrame.getLineSearchResults().getDataFileMASSAJ().getNameFile()==null
|| slimFrame.getLineSearchResults().getDataFileMASSAJ().getNameFile().isEmpty()){
isConnectTables = true;
}
if(nameFileType!=null&& nameFileType[0]!=null&&!isConnectTables)
{
if (nameFileType[0]!=null && !params.getAssociatedFile().toLowerCase().equals(nameFileType[0].toLowerCase()))
{
EditorInformationMADCUBA.appendLineError("The datafile different that in SLIM product. Search made in the SLIM product datafile:"+nameFileType[0]+".");
params.setAssociatedFile(nameFileType[0]);
if (nameFileType[1]!=null)
params.setTypeAssociatedFile(nameFileType[1]);
}
// return;
} else {
//MIRAMOS SI ESTA ABIERTO
if(params.getTypeAssociatedFile()!=null && !params.getTypeAssociatedFile().isEmpty())
{
if(params.getTypeAssociatedFile().equals(SlimConstants.FITS_TYPE_SPECTRAL))
{
AstronomicalJFrameMASSA frameMASSA = (AstronomicalJFrameMASSA) WindowManager.getFrame(AstronomicalJFrameMASSA.FRAME_MASSAJ);
boolean existsOpenTable = false;
if (frameMASSA != null )
{
//MIRO TODAS LAS PESTANAS QUE TIENE
AstronomicalTabbedPaneMASSA tabParent= frameMASSA.getTabbed();
AstronomicalTabbedPaneMASSA tabTable= null;
if(tabParent!=null)
{
for (int iParent=0; iParent<tabParent.getTabCount(); iParent++)
{
String sNameTab = tabParent.getTitleAt(iParent);
if(params.getAssociatedFile()!=null &&!params.getAssociatedFile().contains(MyConstants.SEPARATOR_TABS) )
{
if(params.getAssociatedFile().equals(sNameTab))
{
existsOpenTable = true;
tabTable = ((AstronomicalPanelManagerMASSA)tabParent.getComponentAt(iParent)).getTabbebPanel();
String fileAssociated= params.getAssociatedFile()+MyConstants.SEPARATOR_TABS+tabTable.getTitleAt(0);
params.setAssociatedFile(fileAssociated);
break;
} else {
//Les quito las terminaciones
if(sNameTab.endsWith(".fits"))
{
if(!params.getAssociatedFile().endsWith(".fits"))
{
if((params.getAssociatedFile()+".fits").equals(sNameTab))
{
existsOpenTable = true;
tabTable = ((AstronomicalPanelManagerMASSA)tabParent.getComponentAt(iParent)).getTabbebPanel();
String fileAssociated = params.getAssociatedFile()+".fits"+MyConstants.SEPARATOR_TABS+tabTable.getTitleAt(0);
params.setAssociatedFile(fileAssociated);
break;
}
int index = params.getAssociatedFile().lastIndexOf(".");
if(index>0)
{
String fileAssociated = params.getAssociatedFile().substring(0,index);
if((fileAssociated+".fits").equals(sNameTab))
{
existsOpenTable = true;
tabTable = ((AstronomicalPanelManagerMASSA)tabParent.getComponentAt(iParent)).getTabbebPanel();
fileAssociated= (fileAssociated+".fits")+MyConstants.SEPARATOR_TABS+tabTable.getTitleAt(0);
params.setAssociatedFile(fileAssociated);
break;
}
}
}
} else {
int index = params.getAssociatedFile().lastIndexOf(".");
if(index>0)
{
String fileAssociated = params.getAssociatedFile().substring(0,index);
if((fileAssociated).equals(sNameTab))
{
existsOpenTable = true;
tabTable = ((AstronomicalPanelManagerMASSA)tabParent.getComponentAt(iParent)).getTabbebPanel();
fileAssociated= fileAssociated+MyConstants.SEPARATOR_TABS+tabTable.getTitleAt(0);
params.setAssociatedFile(fileAssociated);
break;
}
}
}
}
}
sNameTab+=MyConstants.SEPARATOR_TABS;
tabTable = ((AstronomicalPanelManagerMASSA)tabParent.getComponentAt(iParent)).getTabbebPanel();
for(int iTable=0; iTable<tabTable.getTabCount(); iTable++)
{
String titleTable = tabTable.getTitleAt(iTable);
if(params.getAssociatedFile().equals(titleTable) || params.getAssociatedFile().equals(sNameTab+titleTable) )
{
existsOpenTable = true;
break;
}
}
}
}
if(!existsOpenTable)
{
EditorInformationMADCUBA.appendLineError("The datafile has not been found. Please check it.");
return;
}
}
} else if(params.getTypeAssociatedFile().equals(SlimConstants.FITS_TYPE_CUBE)) {
List<String> namesCubes = WindowsPluginsUtils.getAllNameCubes();
boolean existsOpenCube = false;
for(String name : namesCubes)
{
if(name.equals(params.getAssociatedFile()) ||
name.equals(AstronomicalImagePlus.PREFIX_CUBE+params.getAssociatedFile()) ||
name.equals(params.getAssociatedFile().replaceFirst(AstronomicalImagePlus.PREFIX_PLOT, AstronomicalImagePlus.PREFIX_CUBE))||
name.equals(params.getAssociatedFile().replaceFirst(AstronomicalImagePlus.PREFIX_PLOT, ""))||
name.equals(params.getAssociatedFile().replaceFirst(AstronomicalImagePlus.PREFIX_CUBE, "")))
{
existsOpenCube = true;
break;
}
}
if(!existsOpenCube)
{
EditorInformationMADCUBA.appendLineError("The datafile has not been found. Please check it.");
return;
}
}else if(params.getTypeAssociatedFile().equals(SlimConstants.FITS_TYPE_CUBE_SYNCHRO)) {
} else {
List<String> namesCubes = WindowsPluginsUtils.getAllNameCubes();
boolean existsOpenData = false;
for(String name : namesCubes)
{
if(name.equals(params.getAssociatedFile()) ||
name.equals(AstronomicalImagePlus.PREFIX_CUBE+params.getAssociatedFile()) ||
name.equals(params.getAssociatedFile().replaceFirst(AstronomicalImagePlus.PREFIX_PLOT, AstronomicalImagePlus.PREFIX_CUBE))||
name.equals(params.getAssociatedFile().replaceFirst(AstronomicalImagePlus.PREFIX_PLOT, ""))||
name.equals(params.getAssociatedFile().replaceFirst(AstronomicalImagePlus.PREFIX_CUBE, "")))
{
existsOpenData = true;
break;
}
}
if(!existsOpenData)
{
AstronomicalJFrameMASSA frameMASSA = (AstronomicalJFrameMASSA) WindowManager.getFrame(AstronomicalJFrameMASSA.FRAME_MASSAJ);
if (frameMASSA != null )
{
//MIRO TODAS LAS PESTANAS QUE TIENE
AstronomicalTabbedPaneMASSA tabParent= frameMASSA.getTabbed();
AstronomicalTabbedPaneMASSA tabTable= null;
if(tabParent!=null)
{
for (int iParent=0; iParent<tabParent.getTabCount(); iParent++)
{
String sNameTab = tabParent.getTitleAt(iParent);
sNameTab+=MyConstants.SEPARATOR_TABS;
tabTable = ((AstronomicalPanelManagerMASSA)tabParent.getComponentAt(iParent)).getTabbebPanel();
for(int iTable=0; iTable<tabTable.getTabCount(); iTable++)
{
String titleTable = tabTable.getTitleAt(iTable);
if(params.getAssociatedFile().equals(titleTable) || params.getAssociatedFile().equals(sNameTab+titleTable) )
{
existsOpenData = true;
break;
}
}
}
}
if(!existsOpenData)
{
if(params.getAssociatedFile().equals(SlimConstants.NAME_FITS_TYPE_CUBE_SYNCHRO_NEW) &&
AstronomicalFunctionsGenerics.isSynchronizeCubesconnected())
{
existsOpenData = true;
}
}
}
}
if(!existsOpenData)
{
EditorInformationMADCUBA.appendLineError("The datafile has not been found. Please check it.");
return;
}
}
}
String [] nameFileMAdcube = new String[]{params.getAssociatedFile(), params.getTypeAssociatedFile()};
nameFileMAdcube = SlimUtilities.changeUnitIntensityVelocity(nameFileMAdcube,false,true); //FALTARIA TODAVIA OTRA VALIDACION
if(nameFileMAdcube==null)
{
EditorInformationMADCUBA.appendLineError("The unit no exists. Indicated name in Modify_Data, Tab 'Operations'");
return;
}
searchPanel.setNameFileMADCUBA(nameFileMAdcube, true, false);
if(SLIMFRAME.getInstance(false).getPanelModelLTESimFit()==null)
SLIMFRAME.getInstance(false).charguePanelModelLTESimFit();
if(SLIMFRAME.getInstance(false).getPanelModelLTESimFit()!=null)
{
SLIMFRAME.getInstance(false).getPanelModelLTESimFit().setHistorySLIM(null);
SLIMFRAME.getInstance(false).getPanelModelLTESimFit().getSimFitter().connectToSpectra(nameFileMAdcube);
//AUUNQUE AQUI DEBERIA VER SI EXISTE IMPORT PARAMS
SLIMFRAME.getInstance(false).getPanelModelLTESimFit().setTextPixel(SLIMFRAME.getInstance(false).getPanelModelLTESimFit().getSimFitter().getPixelShow(),false);
}
}
}
//PRIMEO VALIDAOS FICHERO DE DATOS (estaba en doSearch
String [] nameFileMAdcube = new String[]{params.getAssociatedFile(), params.getTypeAssociatedFile()};
if(slimFrame.getPanelModelLTESimFit()!=null&&slimFrame.getPanelModelLTESimFit().getSimFitter()!=null && slimFrame.getPanelModelLTESimFit().getSimFitter().tabSearchSIMFIT!=null)
{
if(((nameFileMAdcube[1]==null && nameFileMAdcube[0]!=null) && nameFileMAdcube[0].equals(SlimConstants.NAME_FITS_TYPE_CUBE_SYNCHRO_NEW))
||
(nameFileMAdcube[1]!=null&&(nameFileMAdcube[1].equals(SlimConstants.FITS_TYPE_CUBE_SYNCHRO)||
nameFileMAdcube[1].equals(SlimConstants.FITS_TYPE_CUBE)) )
&& slimFrame.getPanelModelLTESimFit().getSimFitter().tabSearchSIMFIT.getTabCount()>=1
&& params.getSearchType().equals("new"))
{
EditorInformationMADCUBA.appendLineError("Can't seach is a new tab for syncronize or cube (only can be one search).");
return;
}
}
if(!slimFrame.getPanelModelLTESimFit().changeComboUnitIntensity(nameFileMAdcube))
{
return;
}
//ADD RESULT SEARCH AHORA LO HE METIDO EN LOS IF CORESPONDIENTES; PORQUE SI NO HABIA UN CASO EN EL QUE NO ENTRABA
// if(searchPanel.getNameFileMADCUBA()==null)
// nameFileMAdcube = SlimUtilities.changeUnitIntensityVelocity(nameFileMAdcube,false,true);
//
// if(nameFileMAdcube==null)
// {
// EditorInformationMADCUBA.appendLineError("No search because unit no exists o is not correct. Indicated name in Modify_Data, Tab 'Operations'");
// return;
// }
params.setAssociatedFile(nameFileMAdcube[0]);
params.setTypeAssociatedFile(nameFileMAdcube[1]);
if(!AstronomicalFunctionsGenerics.isCRType3FreqFromMADCUBA_IJ(nameFileMAdcube[0],false))
{
EditorInformationMADCUBA.appendLineError("No search because the data is not in Frequency. Make Resampling");
return;
}
// SlimUtilities.validateVelocityFromMADCUBA_IJ(nameFileMAdcube[0], true);
boolean recordTemp =Recorder.record;
HashSet<String> moleculesUpdate= new HashSet<String>();
HashSet<String> moleculesDelete= new HashSet<String>();
isFoundNewValues = searchPlugin(isMacro, false,params, slimFrame, isSQL, nameFileMAdcube, moleculesUpdate, moleculesDelete,true,true);
if(params.getSearchType().startsWith("update"))
slimFrame.getPanelModelLTESimFit().applySimulateAllSpecies(/*false,*/ true); //ALGO ESTA MAL POR DEBAJO. SEGURAMENTE LOS QUE NO SE HANELIMINADO SU INT. ¿cuidado entonces?¿los tengo que quitar todos?
if(!moleculesUpdate.isEmpty())
for(String molecule : moleculesUpdate)
{
EditorInformationMADCUBA.append(false,"Molecule "+molecule+" is update transitions");
}
if(!moleculesDelete.isEmpty())
for(String molecule : moleculesDelete)
{
EditorInformationMADCUBA.append(false,"Molecule "+molecule+" is not found transitions and it is delete");
}
//INSERTO EL PIXEL
try {
if(!isMacro)
Recorder.record = recordTemp;
else
Recorder.record = false;
HistoryAndMacrosUtils.recordHistory(SLIMFRAME.getInstance(false).panelMolLTESimFit.getHistorySLIM(),HistoryAndMacrosUtils.FITS_TYPE_SLIM,this, params.getArgs(), true);
Macro.setOptions(null);
}finally{
Recorder.record = recordTemp;
}
}
}
public static boolean searchPlugin(boolean isMacro,boolean isSameProduct, SearchSlimParams params, SLIMFRAME slimFrame,
boolean isSQL, String[] nameFileMAdcube,HashSet<String> moleculesUpdate, HashSet<String> moleculesDelete,
boolean isParamsCheck,boolean isWriteEditor)
{
LineSearchPanel searchPanel = slimFrame.getPanelLineSearch();
ArrayRange freqRanges = new ArrayRange();
//MIRO SI LA BD DE DATOS TIENE O NO QN/ y en que catalogos, para que genere bien las sentencias
//y se pueda usar la aplicación en catalogs antiguos
if(existsQn7InCatalogs ==null)
{
existsQn7InCatalogs = new boolean[SlimConstants.CATALOG_LIST_NO_RECOMB.length];
for(int i=0; i< SlimConstants.CATALOG_LIST_NO_RECOMB.length; i++)
{
String catalogTable = SlimConstants.CATALOG_LIST_NO_RECOMB[i];
boolean existQN7 = validateExistsQn7(catalogTable,searchPanel.getDB());
existsQn7InCatalogs [i] = existQN7;
}
}
if(!isSQL)
{ //SI ENGO UNA SQL, REALMENTE NO TENGO QUE RECOGER EL RANGO DE FREQUENCIAS, PORQUE
//SE SUPONE VA INCLUIDO
ArrayList<Double> listFreq = params.getArrListRange();
//CREATE SPECTRAL WHEN IT'S NECESSARY
//CONVERT TFFREQ TO Hz
if(listFreq==null||(params.getArrListRange().isEmpty() && params.getAssociatedFile()!=null && !params.getAssociatedFile().isEmpty()))
{
try {
boolean isWindows = false;
if(params.getListRange().equals(SELECTED_WINDOW))
isWindows = true;
listFreq = AstronomicalFunctionsGenerics.getListRestFrequencyMASSAJ(params.getAssociatedFile(),isWindows,true);//si no hay ninguna selececciona trae todas
// Log.getInstance().logger.debug(listFreq);
params.setArrListRange(listFreq);
params.setLabelAxis("Frequency");
params.setLabelUnitAxis("Hz");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
freqRanges = getFrequencyRangeSelected(listFreq, params.getLabelAxis(), params.getLabelUnitAxis());
}
boolean recordTemp = Recorder.record;
boolean exists = false;
try{
Recorder.record = false;
if(params.isClear())
{//EMPTY VARIABLES TAB (COMO DELETE COMPONENTS) Y DIRECTORIOS
//IF ES NEW NO TENGO QUE VACIAR NADA PORQUE ES COMO SI FUERA CLEAR.
//O VACIO Y PONGA ADD ES OTRA OPCION
//TEngo que vaciar todo
searchPanel.getDialogResults().getTabResults().closeAllTab();
if(slimFrame.getPanelModelLTESimFit()!=null && slimFrame.getPanelModelLTESimFit().sFitter!=null)
{//VACIAR TODO LO QUE NECESITO VACIAS
slimFrame.getPanelModelLTESimFit().sFitter.setIndexListTransition(null);
slimFrame.getPanelModelLTESimFit().sFitter.setNullListTransition();
slimFrame.getPanelModelLTESimFit().sFitter.emptyDataTemp();
if(slimFrame.getPanelModelLTESimFit().sFitter.tabSearchSIMFIT !=null)
slimFrame.getPanelModelLTESimFit().sFitter.tabSearchSIMFIT.closeAllTab() ;
}
}
String[] listMolecules = params.getArrListMolecules();
//SI ES SQL ESTO ES NULO (listMolecules) //A NO SER QUE HAYA OPTADO POR SACARLO
//DE LA SQL
boolean isSearchRecomb = false;
boolean isOtherSearch = false;
ArrayList<DataMolecular> dataMolecules = new ArrayList<DataMolecular>();
RowListStarTable criteriaSearch = null;
HashSet< String> moleculesSearch= new HashSet<String>();
if(!isSQL&&(listMolecules==null || listMolecules.length<1))
{
if(isWriteEditor)
EditorInformationMADCUBA.appendLineError("Not exists search criteria neither molecules");
//PUEDE QUE EN CATALOGO DE RECOMBINACION DEBE EXISTE LA OPCION DE molecules=RECPMB$*$deltaN (implementar)
return false;
} else {
// Log.getInstance().logger.debug(params.getListMolecules());
isOtherSearch =true;
//HAY QUE DEJARLO PORQUE PUEDE VENIR DE FICHERO (AUNQUE LAS SQL NO DEBERIA PODER MEZCLARSE CON EL RESTO)
if(!isSQL &¶ms.getListMolecules()!=null && params.getListMolecules().toUpperCase().contains(SlimConstants.CATALOG_RECOMBINE.toUpperCase()))
isSearchRecomb = true;
if(!isSQL &&listMolecules!=null)
{//NO SE COMO LO HAREMOS CON SQL, PERO DE MOMENTO LO DEJO APARTE
for(int i=0; i<listMolecules.length; i++)
{
String[] slist = MyUtilities.createArraysStringValues(listMolecules[i],MyConstants.SEPARATOR_NIVEL_2);
//LO INSERTO ANIDADO DESDE EL FICHERO, PERO NO CREO SEA LA MEJOR FORMA POR EL WHERE
DataMolecular dataMol = new DataMolecular();
dataMol.setCatalog(slist[0]);
dataMol.setMolecula(slist[1]);
// Log.getInstance().logger.debug("dataMol.getCatalog().toUpperCase()="+dataMol.getCatalog().toUpperCase());
// Log.getInstance().logger.debug("dataMol.SlimConstants.CATALOG_RECOMBINE.toUpperCase()().toUpperCase()="+SlimConstants.CATALOG_RECOMBINE.toUpperCase());
if( !dataMol.getCatalog().toUpperCase().startsWith(SlimConstants.CATALOG_RECOMBINE.toUpperCase()))
{
if(slist.length>2)
{
dataMol.setElow(slist[2]);
}
if(slist.length>3) {
dataMol.setCm_1(slist[3]);
}
if(slist.length>4) {
dataMol.setLog10(slist[4]);
}
if(slist.length>5) {
dataMol.setWHERE("("+slist[5]+")");
}
if(slist.length>6) {
dataMol.setRenameMolecule(slist[6]);
}
if(slist.length==2)
{
if(params.getCriteriaDefault()!=null && !params.getCriteriaDefault().equals(""))
{
String[] criteria = MyUtilities.createArraysStringValues(params.getCriteriaDefault(),MyConstants.SEPARATOR_NIVEL_2);
if(criteria.length>=4)
{
dataMol.setElow(criteria[1]);
dataMol.setCm_1(criteria[2]);
dataMol.setLog10(criteria[3]);
}
}
}
if( params.getArrListWHEREs()!=null
&& i<params.getArrListWHEREs().size())
dataMol.setWHERE("("+params.getArrListWHEREs().get(i)+")");
// else if( params.getWHERE()!=null && ! params.getWHERE().isEmpty())
// dataMol.setWHERE("("+params.getWHERE()+")");
else
dataMol.setWHERE(params.getWHERE());
if( params.getArrListRenameMolec()!=null
&& i<params.getArrListRenameMolec().size())
dataMol.setRenameMolecule(params.getArrListRenameMolec().get(i));
else if(listMolecules.length==1)
dataMol.setRenameMolecule(params.getNewNameMolecule()); // PERO PARA ESTO SOLO PUEDE TENER UNA MOLECULA
else
dataMol.setRenameMolecule("none");
} else if(dataMol.getCatalog().toUpperCase().startsWith(SlimConstants.CATALOG_RECOMBINE.toUpperCase())) {
String deltaN ="Any";
if(slist.length>=3)
{
try{
new Integer(slist[2]);
deltaN=slist[2];
} catch (Exception e) {
}
}
if(deltaN.equals("Any"))
{
if(params.getCriteriaDefault()!=null && !params.getCriteriaDefault().equals(""))
{
String[] criteria = MyUtilities.createArraysStringValues(params.getCriteriaDefault(),MyConstants.SEPARATOR_NIVEL_2);
try{
if(criteria.length>=1)
{
new Integer(criteria[0]);
dataMol.setDelta(criteria[0]);
} else {
dataMol.setDelta("2");
}
} catch (Exception e) {
dataMol.setDelta("2");
}
} else {
dataMol.setDelta("2");
}
} else {
dataMol.setDelta(deltaN);
}
if(dataMol.getMolecula().length()>2)
{
if(dataMol.getMolecula().startsWith("He"))
dataMol.setMolecula("He");
else if(dataMol.getMolecula().startsWith("H"))
dataMol.setMolecula("H");
else if(dataMol.getMolecula().startsWith("C"))
dataMol.setMolecula("C");
else if(dataMol.getMolecula().startsWith("S"))
dataMol.setMolecula("S");
}
}
if(dataMol.getRenameMolecule()!=null && !dataMol.getRenameMolecule().isEmpty()
&& !dataMol.getRenameMolecule().toLowerCase().equals("any")
&& !dataMol.getRenameMolecule().toLowerCase().equals("none"))
{
// moleculesSearch.add(dataMol.getCatalog().toUpperCase()+"-"+dataMol.getRenameMolecule().toUpperCase());//COMO HAGO LO DEL CATALOFO QUE NO TENGO
moleculesSearch.add(dataMol.getRenameMolecule().toUpperCase());//COMO HAGO LO DEL CATALOFO QUE NO TENGO
}
else
moleculesSearch.add(dataMol.getMolecula().toUpperCase());
dataMolecules.add(dataMol);
}
} else {
}
criteriaSearch = generateStarTableCriteria(dataMolecules, params, nameFileMAdcube);
}
if(isSQL)
{
exists = doSearchSQL(isSameProduct,params, searchPanel, criteriaSearch, isMacro, exists,isParamsCheck,moleculesSearch, moleculesUpdate, moleculesDelete);
} else {//VER SI LO HAGO DESDE FICHERO, PERO EN ESE CASO
//SOLO DEBERIA LLEVAR SQLs Y TENDRIA QUE VER COMO HACER CADA UNA
//O LLEVAR SOLO UNA SQL
//VER MAS ADELANTE
if(isSearchRecomb)
exists =doSearchRecombLines(isSameProduct,params, dataMolecules, freqRanges, searchPanel,criteriaSearch,isMacro,moleculesSearch, moleculesUpdate, moleculesDelete,isParamsCheck);
// EditorInformationMADCUBA.append("exists="+exists);
if(isOtherSearch)
{
if(params.getSearchType().toLowerCase().equals("new") && exists)
params.setSearchType("add");
if(isSQL)
exists = doSearchSQL(isSameProduct,params,searchPanel,criteriaSearch,isMacro,exists,isParamsCheck,moleculesSearch, moleculesUpdate, moleculesDelete);
else
exists = doSearch(isSameProduct,params, dataMolecules,freqRanges, searchPanel,criteriaSearch,isMacro,exists,isParamsCheck, moleculesSearch, moleculesUpdate, moleculesDelete);
}
}
if(exists)
{
slimFrame.setTabActived(SLIMFRAME.NAME_TAB_SIMFIT);
}else if( isSQL){
String sRenameMolecule = params.getNewNameMolecule();
String sqlcommand = params.getSQL();
if(sqlcommand!=null && !sqlcommand.isEmpty())
{
if(sRenameMolecule == null || sRenameMolecule.isEmpty())
{
//ME TENGO QUE TRAER EL DE LA SENTENCIA
//CUIDADO CONEL none, que puede venir en rename='none'
int indexCata = sqlcommand.indexOf("cata");
int indexRename = sqlcommand.indexOf("id_rename");
int indexnone = sqlcommand.indexOf("none");
if(indexnone<0 && indexRename>0 && indexCata>0){
sRenameMolecule = sqlcommand.substring(indexCata+6, indexRename-5);
}
} else if(sRenameMolecule.toLowerCase().equals("none")) {
int indexFormula = sqlcommand.indexOf("id_formula=");
// Log.getInstance().logger.debug("-A---indexFormula"+indexFormula);
sRenameMolecule = "";
if(indexFormula>0)
{
sRenameMolecule = sqlcommand.substring(indexFormula+12);
// Log.getInstance().logger.debug("--A--VER QUE FORMULA COJE"+sForm);
indexFormula =sRenameMolecule.indexOf("'");
if(indexFormula<0)
indexFormula =sRenameMolecule.indexOf("$");
// Log.getInstance().logger.debug("--B--VER QUE indexFormula COJE"+indexFormula);
sRenameMolecule = sRenameMolecule.substring(0,indexFormula);
}
}
}
if(sRenameMolecule == null || sRenameMolecule.isEmpty())
EditorInformationMADCUBA.append(false,"Not found new transitions for indicated SQL");
else
EditorInformationMADCUBA.append(false,"Not found new transitions for indicated '"+sRenameMolecule+"'");
}
//INDICATED LAS QUE NO SE HAN REALIZADO LA CONSULTA
if(!isSameProduct&&isWriteEditor)
{
if(moleculesUpdate==null && moleculesDelete==null)
{
for(String molecule : moleculesSearch)
{
if(!molecule.contains("*"))
EditorInformationMADCUBA.append(false,"Not found new transitions for "+molecule);
}
} else if(moleculesUpdate!=null && moleculesDelete!=null){
for(String molecule : moleculesSearch)
{
boolean containsDelete = false;
for(String moleculeD : moleculesDelete)
{
if(moleculeD.toUpperCase().endsWith("-"+molecule.toUpperCase()))
{
containsDelete= true;
break;
}
}
boolean containsUpdate = false;
for(String moleculeU : moleculesUpdate)
{
if(moleculeU.toUpperCase().endsWith("-"+molecule.toUpperCase()))
{
containsUpdate= true;
break;
}
}
if(!molecule.contains("*") && !containsDelete && !containsUpdate)
EditorInformationMADCUBA.append(false,"Not found new transitions for "+molecule);
}
}else if(moleculesUpdate!=null ){
for(String molecule : moleculesSearch)
{
boolean containsUpdate = false;
for(String moleculeU : moleculesUpdate)
{
if(moleculeU.toUpperCase().endsWith("-"+molecule.toUpperCase()))
{
containsUpdate= true;
break;
}
}
if(!molecule.contains("*")&& !containsUpdate)
EditorInformationMADCUBA.append(false,"Not found new transitions for "+molecule);
}
}else if(moleculesDelete!=null ){
for(String molecule : moleculesSearch)
{
boolean containsDelete = false;
for(String moleculeD : moleculesDelete)
{
if(moleculeD.toUpperCase().endsWith("-"+molecule.toUpperCase()))
{
containsDelete= true;
break;
}
}
if(!molecule.contains("*")&&!containsDelete)
EditorInformationMADCUBA.append(false,"Not found new transitions for "+molecule);
}
}
}
}finally{
Recorder.record = recordTemp;
}
return exists;
}
public static MolecularSpecies searchMoleculeSpecies(boolean isMacro, SearchSlimParams params, SLIMFRAME slimFrame,
boolean isSQL, String[] nameFileMAdcube, boolean isParamsCheck,boolean isWriteEditor)
{
LineSearchPanel searchPanel = slimFrame.getPanelLineSearch();
MolecularSpecies molecularSpecies = null;
ArrayRange freqRanges = new ArrayRange();
//MIRO SI LA BD DE DATOS TIENE O NO QN/ y en que catalogos, para que genere bien las sentencias
//y se pueda usar la aplicación en catalogs antiguos
if(existsQn7InCatalogs ==null)
{
existsQn7InCatalogs = new boolean[SlimConstants.CATALOG_LIST_NO_RECOMB.length];
for(int i=0; i< SlimConstants.CATALOG_LIST_NO_RECOMB.length; i++)
{
String catalogTable = SlimConstants.CATALOG_LIST_NO_RECOMB[i];
boolean existQN7 = validateExistsQn7(catalogTable,searchPanel.getDB());
existsQn7InCatalogs [i] = existQN7;
}
}
if(!isSQL)
{ //SI ENGO UNA SQL, REALMENTE NO TENGO QUE RECOGER EL RANGO DE FREQUENCIAS, PORQUE
//SE SUPONE VA INCLUIDO
ArrayList<Double> listFreq = params.getArrListRange();
//CREATE SPECTRAL WHEN IT'S NECESSARY
//CONVERT TFFREQ TO Hz
if(params.getListRange()!=null && params.getListRange().toLowerCase().equals(SELECTED_WHOLE_RANGE))
{
ArrayList<Double> rangeList = new ArrayList<Double>();
rangeList.add(0D);
rangeList.add(Double.MAX_VALUE);//OR 300000 UN PAR DE CEROS MAS
params.setArrListRange(rangeList);
listFreq = params.getArrListRange();
params.setLabelAxis("Frequency");
params.setLabelUnitAxis("Hz");
// isWholeRange = true;
} else if(listFreq==null||(params.getArrListRange().isEmpty() && params.getAssociatedFile()!=null && !params.getAssociatedFile().isEmpty()))
{
try {
boolean isWindows = false;
if(params.getListRange().equals(SELECTED_WINDOW))
isWindows = true;
listFreq = AstronomicalFunctionsGenerics.getListRestFrequencyMASSAJ(params.getAssociatedFile(),isWindows,true);//si no hay ninguna selececciona trae todas
// Log.getInstance().logger.debug(listFreq);
params.setArrListRange(listFreq);
params.setLabelAxis("Frequency");
params.setLabelUnitAxis("Hz");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}