-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatprep.f
More file actions
2006 lines (1945 loc) · 71.6 KB
/
catprep.f
File metadata and controls
2006 lines (1945 loc) · 71.6 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
c catprep - read final tile mdex file and generate catalog & reject
c output files
c
c vsn 1.0 B90112: initial version
c 1.1 B90116: added option to keep source_id & src columns; added
c option to qualify for catalog on W1&W2 both above
c separate S/N threshold; removed cc_flags from catalog
c decision
c 1.2 B90124: fixed bug in output "\Nsrc" line; added table header
c line identifying version and date/time of run
c 1.3 B90202: added option "-t" to intercept table header line with
c "\ artifact bitmasks from", replace pathname with
c "/Volumes/tyto1/Ab_masks_v1/unwise-<tileID>-msk.fits"
c 1.4 B90207: added IRSA-formatted output options "-ci" and "-ri";
c decoupled the four output options; coded final column
c retention; added "-v" option for 2-char version ID to
c be imnplanted into "source_id"; removed "-n1" option;
c added "glon" & "glat" to end of data rows
c 1.41 B90207: fixed bug in IRSA C/R bar placements
c 1.5 B90212: renamed elon & elat to elon_avg & elat_avg, added new
c elon & elat obtained from stationary ra & dec, and
c moved p column to the end of the row
c 1.55 B90518: include "n" in null removal from bar files
c 1.6 B90525: include "primary" flag in cat/rej separation; added
c "-pc" flag to include "p" column in cat output.
c 1.61 B90525: fixed possible NaN in glat and elat
c 1.7 B90906: installed SOFA-based eq2gal
c 1.8 B90909: force PMRA and PMDec to F10.5 format, clip to
c range -99.99999 to 99.99999
c 1.82 B91128: changed source name & collision handling; add one
c digit of precision to RA & Dec; tweak least
c significant digits to resolve name conflicts
c 1.82 B91128: changed source name & collision handling; back to
c previous names, but append "a" to first source with
c colliding name if there is a "b" or more; buffer
c output lines in memory until termination to do this.
c 1.83 B91228: eliminate w?fitr [note: not implemented after all]
c 1.84 C00110: add cross-referenced unwise_objid to output
c 1.85 C00116: append "r02" to unwise_objid; NOTE: this will be
c ONLY for processing CatWISE data that used the r02
c version of the unWISE catalog
c
c=======================================================================
c
Integer*4 MaxFld, MaxRows
Parameter (MaxFld = 1000, MaxRows = 500000)
c
Character*2500 Line, OutLine, OutLines(MaxRows)
Character*500 InFNam, OutCnam, OutRnam, OutCInam, OutRInam,
+ NLnam, UnWnam
Character*50 MaskPath
Character*25 Field(MaxFld), FieldC(MaxFld), FieldR(MaxFld)
Character*24 GalStr, EclStr
Character*21 NamStr
Character*20 names(MaxRows), nam! dynamic allocation won't work
Character*16 unWobjID(MaxRows)
Character*11 Vsn, NumStr
Character*8 CDate, CTime, tileID
Character*4 Flag, Flag0
Character*2 vc
Real *8 wsnr, minw1snr, minw2snr, ra, dec, minw1w2snr,
+ GaLong, GaLat, EcLong, EcLat, pm
Integer*4 IArgC, LNBlnk, nHead, nArg, nArgs, IFa(MaxFld),
+ IFb(MaxFld), NF, nSrcHdr, n, k, i, nSrc, nCout,
+ nRout, nNamCollisn, nAppChar, wccmap, wabmap,
+ LenHdrNsrc, IFaC(MaxFld), IFbC(MaxFld), NFC,
+ IFaR(MaxFld), IFbR(MaxFld), NFR, nSrcUnW, mdetID
Logical*4 NeedHelp, SanityChk, GotIn, GotOut1, GotOut2, dbg,
+ GoCat, Good1, Good2, Good12, DoMaskNam, GotOutI1,
+ GotOutI2, CatPcol, Peq1, IzCat(MaxRows), GotUX
c
Data Vsn/'1.85 C00116'/, nSrc/0/, nHead/0/, SanityChk/.true./,
+ GotIn,GotOut1,GotOut2/3*.false./, nSrcHdr/-9/, dbg/.false./,
+ nCout,nRout/2*0/, nNamCollisn/0/, minw1w2snr/5.0d0/,
+ minw1snr,minw2snr/2*5.0d0/, LenHdrNsrc/14/, vc/'a0'/
+ DoMaskNam/.false./, tileID/'DayNinny'/, GotUX/.false./
+ MaskPath/'/Volumes/tyto1/Ab_masks_v1/'/, nSrcUnW/0/,
+ GotOutI1,GotOutI2/2*.false./, CatPcol/.false./,
+ IzCat/MaxRows*.false./
c
Common / VDT / CDate, CTime, Vsn
c
namelist / catprepin / MaskPath, minw1snr, minw1w2snr, minw2snr,
+ vc
c
c=======================================================================
c
nArgs = IArgc()
NeedHelp = (nArgs .lt. 6)
1 If (NeedHelp) then
print *,'catprep vsn ', Vsn
print *
print *,'Usage: catprep <flags specifications>'
print *
print *,'Where the following specifications are REQUIRED:'
print *,' -i name of a final tile mdex file'
print *,' -x name of the mdetID/unwise_objid xref file'
print *
print *,'and at least one of the following flags and '
+ //'specifications is REQUIRED:'
print *,' -c name of the output CatWISE catalog file'
print *,' -r name of the output CatWISE reject file'
print *,' -ci name of the output iRSA CatWISE catalog file'
print *,' -ri name of the output IRSA CatWISE reject file'
print *
print *,'The OPTIONAL flags are:'
print *,' -v 2-char version code ("a0")'
print *,' -s1 minimum w1snr (5)'
print *,' -s2 minimum w2snr (5)'
print *,' -s12 minimum snr in w1 & w2 together (5)'
print *,' -n name of a catprepin namelist file'
print *,' -t tile ID for use in bitmask name'
print *,' -pc include "p" column at end of catalog rows (F)'
print *,' -d enable debug mode'
Print *
stop
end if
c - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
c
call signon('catprep')
c
NArg = 0
2 NArg = NArg + 1
call GetArg(NArg,Flag)
Flag0 = Flag
call UpCase(Flag)
c ! input CatWISE file
If (Flag .eq. '-I') then
call NextNarg(NArg,Nargs)
Call GetArg(NArg,InFNam)
if (Access(InFNam(1:LNBlnk(InFNam)),' ') .ne. 0) then
print *
print *,'ERROR: file not found: ', InFNam(1:LNBlnk(InFNam))
print *
NeedHelp = .True.
Go to 1
end if
GotIn = .true.
c ! mdetID/unwise_objid xref file
else if (Flag .eq. '-X') then
call NextNarg(NArg,Nargs)
Call GetArg(NArg,UnWnam)
if (Access(UnWnam(1:LNBlnk(UnWnam)),' ') .ne. 0) then
print *
print *,'ERROR: file not found: ', UnWnam(1:LNBlnk(UnWnam))
print *
NeedHelp = .True.
Go to 1
end if
GotUX = .true.
c ! Turn debug prints on
else if (Flag .eq. '-D') then
dbg = .true.
print *,'Debug prints enabled'
c ! include "p" col in cat
else if (Flag .eq. '-PC') then
CatPcol = .true.
if (dbg) print *,'include "p" col in cat'
c
else if (Flag .eq. '-C') then
call NextNarg(NArg,Nargs)
Call GetArg(NArg,OutCNam)
if (Index(OutCnam,'.tbl') .eq. 0)
+ OutCnam = OutCnam(1:LNBlnk(OutCnam))//'.tbl'
if (Access(OutCnam(1:LNBlnk(OutCnam)),' ') .eq. 0) then
print *
print *,'ERROR: Output file already exists: ',
+ OutCnam(1:LNBlnk(OutCnam))
print *
NeedHelp = .True.
Go to 1
end if
GotOut1 = .true.
c
else if (Flag .eq. '-R') then
call NextNarg(NArg,Nargs)
Call GetArg(NArg,OutRNam)
if (Index(OutRnam,'.tbl') .eq. 0)
+ OutRnam = OutRnam(1:LNBlnk(OutRnam))//'.tbl'
if (Access(OutRnam(1:LNBlnk(OutRnam)),' ') .eq. 0) then
print *
print *,'ERROR: Output file already exists: ',
+ OutRnam(1:LNBlnk(OutRnam))
print *
NeedHelp = .True.
Go to 1
end if
GotOut2 = .true.
c
else if (Flag .eq. '-CI') then
call NextNarg(NArg,Nargs)
Call GetArg(NArg,OutCINam)
if (Access(OutCInam(1:LNBlnk(OutCInam)),' ') .eq. 0) then
print *
print *,'ERROR: Output file already exists: ',
+ OutCInam(1:LNBlnk(OutCInam))
print *
NeedHelp = .True.
Go to 1
end if
GotOutI1 = .true.
c
else if (Flag .eq. '-RI') then
call NextNarg(NArg,Nargs)
Call GetArg(NArg,OutRINam)
if (Access(OutRInam(1:LNBlnk(OutRInam)),' ') .eq. 0) then
print *
print *,'ERROR: Output file already exists: ',
+ OutRInam(1:LNBlnk(OutRInam))
print *
NeedHelp = .True.
Go to 1
end if
GotOutI2 = .true.
c
else if (Flag .eq. '-N') then
call NextNarg(NArg,Nargs)
Call GetArg(NArg,NLNam)
if (Access(NLNam(1:LNBlnk(NLNam)),' ') .ne. 0) then
print *
print *,'ERROR: File not found: ', NLNam(1:LNBlnk(NLNam))
print *
NeedHelp = .True.
Go to 1
end if
open(10, file = NLnam)
read(10, catprepin, end = 3017, err = 3018)
write (6, catprepin)
close(10)
c
else if (Flag .eq. '-V') then
call NextNarg(NArg,Nargs)
call GetArg(NArg,vc)
if (dbg) print *, 'version code: ', vc
c
else if (Flag .eq. '-S1') then
call NextNarg(NArg,Nargs)
call GetArg(NArg,NumStr)
read (NumStr, *, err=3007) minw1snr
if (dbg) print *, 'minimum w1snr: ', minw1snr
c
else if (Flag .eq. '-S2') then
call NextNarg(NArg,Nargs)
call GetArg(NArg,NumStr)
read (NumStr, *, err=3008) minw2snr
if (dbg) print *, 'minimum w2snr: ', minw2snr
c
else if (Flag .eq. '-S12') then
call NextNarg(NArg,Nargs)
call GetArg(NArg,NumStr)
read (NumStr, *, err=3008) minw1w2snr
if (dbg) print *, 'minimum w1w2snr: ', minw1w2snr
c
else if (Flag .eq. '-T') then
call NextNarg(NArg,Nargs)
call GetArg(NArg,tileID)
doMaskNam = .true.
if (dbg) print *, 'tile ID: ', tileID
c
Else
print *,'ERROR: unrecognized command-line specification: '
+ //Flag0
end if
c
If (NArg .lt. NArgs) Go to 2
if (.not.GotIn) then
print *, 'ERROR: no input file specified ("-i")'
NeedHelp = .True.
Go to 1
end if
if (.not.GotUX) then
print *,
+ 'ERROR: no mdetID/unwise_objid xref file specified ("-x")'
NeedHelp = .True.
Go to 1
end if
if (.not.(GotOut1 .or. GotOut2 .or. GotOutI1 .or. GotOutI2)) then
print *, 'ERROR: no output files specified'
NeedHelp = .True.
Go to 1
end if
c
c - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
c ! Read mdetID/unwise_objid xref
open(10, file = UnWnam)
read (10,'(a)', end = 3019, err = 3020) Line
if (index(Line, 'Nsrcs =') .eq. 0) then
print *,'ERROR: bad spec for mdetID/unwise_objid xref file'
call exit(64)
end if
read(Line(9:18),'(i10)', end = 3019, err = 3020) nSrcUnW
if (dbg) print *,'No. unWISE sources:', nSrcUnW
read (10,'(a)', end = 3019, err = 3020) Line
if (index(Line,'unwise_objid') .eq. 0) then
print *,'ERROR: bad spec for mdetID/unwise_objid xref file'
call exit(64)
end if
read (10,'(a)', end = 3019, err = 3020) Line
do 50 n = 1, nSrcUnW
read (10,'(a)', end = 3019, err = 3020) Line
unWobjID(n) = Line(9:24)
50 continue
close(10)
c
c - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
c ! Sanity Check
open (10, file = InFNam)
80 read (10,'(a)', end = 3000) Line
if (Line(1:1) .eq. '\') go to 80
call GetFlds(Line,Field,IFa,IFb,NF)
rewind(10)
c
if (SanityChk) then
if (NF .ne. 204) then
print *,'ERROR: input is not a two-band final-tile mdex file'
print *,' no. of fields =', NF,'; should be 204'
call exit(64)
end if
c ! verify some fields in mdex file
call ChkFld(Field(3), 'ra',3)
call ChkFld(Field(4), 'dec',4)
call ChkFld(Field(5), 'sigra',5)
call ChkFld(Field(6), 'sigdec',6)
call ChkFld(Field(7), 'sigradec',7)
call ChkFld(Field(8), 'w1x',8)
call ChkFld(Field(9), 'w1y',9)
call ChkFld(Field(10),'w2x',10)
call ChkFld(Field(11),'w2y',11)
end if
c
if (GotOut1) open(20, file = OutCnam)
if (GotOut2) open(22, file = OutRnam)
if (GotOutI1) open(24, file = OutCInam)
if (GotOutI2) open(26, file = OutRInam)
c ! process header lines
90 read (10, '(a)', end=500) Line
if (Line(1:1) .eq. '\') then
if (doMaskNam) then
if (index(Line,'artifact bitmasks from') .gt. 0) then
Line = '\ artifact bitmasks from '
+ //MaskPath(1:lnblnk(MaskPath))//'unwise-'
+ //tileID//'-msk.fits'
if (dbg) print *,'Header bitmask line: "'
+ //Line(1:lnblnk(Line))//'"'
end if
end if
if (GotOut1) write(20,'(a)') Line(1:lnblnk(Line))
if (GotOut2) write(22,'(a)') Line(1:lnblnk(Line))
if ((index(Line,'\Nsrc =') .gt. 0) .and. (nSrcHdr .lt. 0)) then
LenHdrNsrc = lnblnk(Line)
n = index(Line,'=') + 1
read (Line(n:lnblnk(Line)), *, err = 3002) nSrcHdr
if (nSrcHdr .gt. MaxRows) then
print *,'ERROR: Header \nSrc line: "'
+ //Line(1:lnblnk(Line))//'", greater than MaxRows:',
+ MaxRows
print *,'Increase the MaxRows parameter in catprep'
call exit(64)
end if
if (dbg) print *,'Header \nSrc line: "'
+ //Line(1:lnblnk(Line))//'"'
end if
go to 90
end if
if (Line(1:1) .eq. '|') then
nHead = nHead + 1
if (nHead .eq. 1) then
if (GotOut1) write(20,'(a)') '\ catprep vsn '//Vsn//' run on '
+ //CDate//' at '//CTime
if (GotOut2) write(22,'(a)') '\ catprep vsn '//Vsn//' run on '
+ //CDate//' at '//CTime
Line(IFa(8):IFb(8)) = '| wx '
Line(IFa(9):IFb(9)) = '| wy '
Line(IFa(171):IFb(171)) = '| elon_avg '
Line(IFa(173):IFb(173)) = '| elat_avg '
OutLine = '| source_name '//Line(IFa(1):IFb(1))
+ //Line(IFa(3):IFb(9))//Line(IFa(12):IFb(34))
+ //Line(IFa(37):IFb(38))//Line(IFa(40):IFb(43))
+ //Line(IFa(45):IFb(48))//Line(IFa(50):IFb(121))
+ //Line(IFa(135):IFb(186))//Line(IFa(188):IFb(203))
+ //'| glon | glat | elon | elat '
+ //'| unwise_objid | P |'
if (GotOut2) write(22,'(a)') OutLine(1:lnblnk(OutLine))
call GetFlds(OutLine,FieldR,IFaR,IFbR,NFR)
OutLine = '| source_name '//Line(IFa(1):IFb(1))
+ //Line(IFa(3):IFb(9))//Line(IFa(12):IFb(34))
+ //Line(IFa(37):IFb(38))//Line(IFa(40):IFb(43))
+ //Line(IFa(45):IFb(48))//Line(IFa(50):IFb(121))
+ //Line(IFa(135):IFb(186))//Line(IFa(188):IFb(203))
+ //'| glon | glat | elon | elat '
+ //'| unwise_objid |'
if (CatPcol) OutLine = OutLine(1:lnblnk(OutLine))//' P |'
if (GotOut1) write(20,'(a)') OutLine(1:lnblnk(OutLine))
call GetFlds(OutLine,FieldC,IFaC,IFbC,NFC)
end if
if (nHead .eq. 2) then
OutLine = '| char '//Line(IFa(1):IFb(1))
+ //Line(IFa(3):IFb(9))//Line(IFa(12):IFb(34))
+ //Line(IFa(37):IFb(38))//Line(IFa(40):IFb(43))
+ //Line(IFa(45):IFb(48))//Line(IFa(50):IFb(121))
+ //Line(IFa(135):IFb(186))//Line(IFa(188):IFb(203))
+ //'| double | double | double | double '
+ //'| char | int |'
if (GotOut2) write(22,'(a)') OutLine(1:lnblnk(OutLine))
OutLine = '| char '//Line(IFa(1):IFb(1))
+ //Line(IFa(3):IFb(9))//Line(IFa(12):IFb(34))
+ //Line(IFa(37):IFb(38))//Line(IFa(40):IFb(43))
+ //Line(IFa(45):IFb(48))//Line(IFa(50):IFb(121))
+ //Line(IFa(135):IFb(186))//Line(IFa(188):IFb(203))
+ //'| double | double | double | double '
+ //'| char |'
if (CatPcol) OutLine = OutLine(1:lnblnk(OutLine))//' int |'
if (GotOut1) write(20,'(a)') OutLine(1:lnblnk(OutLine))
end if
if (nHead .eq. 3) then
OutLine = '| -- '//Line(IFa(1):IFb(1))
+ //Line(IFa(3):IFb(9))//Line(IFa(12):IFb(34))
+ //Line(IFa(37):IFb(38))//Line(IFa(40):IFb(43))
+ //Line(IFa(45):IFb(48))//Line(IFa(50):IFb(121))
+ //Line(IFa(135):IFb(186))//Line(IFa(188):IFb(203))
+ //'| deg | deg | deg | deg '
+ //'| - | - |'
if (GotOut2) write(22,'(a)') OutLine(1:lnblnk(OutLine))
OutLine = '| -- '//Line(IFa(1):IFb(1))
+ //Line(IFa(3):IFb(9))//Line(IFa(12):IFb(34))
+ //Line(IFa(37):IFb(38))//Line(IFa(40):IFb(43))
+ //Line(IFa(45):IFb(48))//Line(IFa(50):IFb(121))
+ //Line(IFa(135):IFb(186))//Line(IFa(188):IFb(203))
+ //'| deg | deg | deg | deg '
+ //'| - |'
if (CatPcol) OutLine = OutLine(1:lnblnk(OutLine))//' - |'
if (GotOut1) write(20,'(a)') OutLine(1:lnblnk(OutLine))
end if
if (nHead .eq. 4) then
OutLine = '| -- '//Line(IFa(1):IFb(1))
+ //Line(IFa(3):IFb(9))//Line(IFa(12):IFb(34))
+ //Line(IFa(37):IFb(38))//Line(IFa(40):IFb(43))
+ //Line(IFa(45):IFb(48))//Line(IFa(50):IFb(121))
+ //Line(IFa(135):IFb(186))//Line(IFa(188):IFb(203))
+ //'| -- | -- | -- | -- '
+ //'| null | null|'
if (GotOut2) write(22,'(a)') OutLine(1:lnblnk(OutLine))
OutLine = '| -- '//Line(IFa(1):IFb(1))
+ //Line(IFa(3):IFb(9))//Line(IFa(12):IFb(34))
+ //Line(IFa(37):IFb(38))//Line(IFa(40):IFb(43))
+ //Line(IFa(45):IFb(48))//Line(IFa(50):IFb(121))
+ //Line(IFa(135):IFb(186))//Line(IFa(188):IFb(203))
+ //'| -- | -- | -- | -- '
+ //'| null |'
if (CatPcol) OutLine = OutLine(1:lnblnk(OutLine))//' null|'
if (GotOut1) write(20,'(a)') OutLine(1:lnblnk(OutLine))
end if
go to 90
end if
c
c - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
c ! Generate sexagesimal name
nSrc = nSrc + 1
k = 3
Read(Line(IFA(k):IFB(k)), *, err = 3001) ra
k = 4
Read(Line(IFA(k):IFB(k)), *, err = 3001) dec
call SexagesNam(ra, dec, nam)
100 if (nSrc .gt. 1) then
nAppChar = 97 ! we could probably speed this
110 do 120 k = 1, nSrc-1 ! search up by not starting from
If (nam .eq. names(k)) then ! the top every time, but the pgm
if (nAppChar .eq. 97) then ! is pretty fast, so what the heck
nNamCollisn = nNamCollisn + 1
OutLines(k)(21:21) = achar(nAppChar)
end if
nAppChar = nAppChar + 1
nam(20:20) = achar(nAppChar)
go to 110
end if
120 continue
end if
names(nSrc) = nam
NamStr = ' '//nam
c ! get galactic coordinates
call Cel2Gal(ra, dec, GaLong, GaLat)
write(GalStr,'(2f12.6)') GaLong, GaLat
call Cel2Ec(ra, dec, EcLong, EcLat)
write(EclStr,'(2f12.7)') EcLong, EcLat
c ! implant version code
k = index(Line,'-')
Line(k+3:k+9) = Line(k:k+6)
Line(k:k+2) = '_'//vc
c
c - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
c ! Check eligibility for catalog
k = 204
Peq1 = (index(Line(IFA(k):IFB(k)),'1') .ne. 0) ! check primary code
if (.not.Peq1) then
GoCat = .false.
go to 150
end if
c
k = 20
if (index(Line(IFA(k):IFB(k)),'null') .eq. 0) then
Read(Line(IFA(k):IFB(k)), *, err = 3001) wsnr
else
wsnr = 0.0d0
end if
k = 200
if (index(Line(IFA(k):IFB(k)),'null') .eq. 0) then
Read(Line(IFA(k):IFB(k)), *, err = 3001) wabmap
else
wabmap = 0
end if
Good1 = (wsnr .ge. minw1snr) .and. (wabmap .eq. 0)
c
Good12 = (wsnr .ge. minw1w2snr) .and. (wabmap .eq. 0)
k = 21
if (index(Line(IFA(k):IFB(k)),'null') .eq. 0) then
Read(Line(IFA(k):IFB(k)), *, err = 3001) wsnr
else
wsnr = 0.0d0
end if
k = 202
if (index(Line(IFA(k):IFB(k)),'null') .eq. 0) then
Read(Line(IFA(k):IFB(k)), *, err = 3001) wabmap
else
wabmap = 0
end if
Good2 = (wsnr .ge. minw2snr) .and. (wabmap .eq. 0)
c
Good12 = Good12 .and. (wsnr .ge. minw1w2snr) .and. (wabmap .eq. 0)
c
GoCat = Good1 .or. Good2 .or. Good12
c
150 read (Line(IFa(137):IFb(137)),*,err=3021) mdetID
c
if (GoCat) then
IzCat(nSrc) = .true.
OutLine = NamStr//Line(IFa(1):IFb(1))
+ //Line(IFa(3):IFb(9))//Line(IFa(12):IFb(34))
+ //Line(IFa(37):IFb(38))//Line(IFa(40):IFb(43))
+ //Line(IFa(45):IFb(48))//Line(IFa(50):IFb(121))
+ //Line(IFa(135):IFb(186))//Line(IFa(188):IFb(203))
+ //GalStr//EclStr//' '//unWobjID(mdetID)//'r02'
if (CatPcol)
+ OutLine = OutLine(1:lnblnk(OutLine))//Line(IFa(204):IFb(204))
if (index(OutLine(IFaC(126):IFbC(126)), 'null') .eq. 0) then
read (OutLine(IFaC(126):IFbC(126)), *) pm ! force PMRA to F10.5
if (pm .lt. -99.99999) pm = -99.99999 ! NOTE PMRA now in col 126
if (pm .gt. 99.99999) pm = 99.99999
write(OutLine(IFaC(126):IFbC(126)), '(F10.5)') pm
end if
if (index(OutLine(IFaC(127):IFbC(127)), 'null') .eq. 0) then
read (OutLine(IFaC(127):IFbC(127)), *) pm ! force PMDec to F10.5
if (pm .lt. -99.99999) pm = -99.99999 ! NOTE PMDec now in col 127
if (pm .gt. 99.99999) pm = 99.99999
write(OutLine(IFaC(127):IFbC(127)), '(F10.5)') pm
end if
c if (GotOut1) write(20,'(a)') OutLine(1:lnblnk(OutLine)) ! JWF B91128
OutLines(nSrc) = OutLine ! JWF B91128
else
OutLine = NamStr//Line(IFa(1):IFb(1))
+ //Line(IFa(3):IFb(9))//Line(IFa(12):IFb(34))
+ //Line(IFa(37):IFb(38))//Line(IFa(40):IFb(43))
+ //Line(IFa(45):IFb(48))//Line(IFa(50):IFb(121))
+ //Line(IFa(135):IFb(186))//Line(IFa(188):IFb(203))
+ //GalStr//EclStr//' '//unWobjID(mdetID)//'r02'
+ //Line(IFa(204):IFb(204))
if (index(OutLine(IFaC(126):IFbC(126)), 'null') .eq. 0) then
read (OutLine(IFaC(126):IFbC(126)), *) pm ! force PMRA to F10.5
if (pm .lt. -99.99999) pm = -99.99999 ! NOTE PMRA now in col 126
if (pm .gt. 99.99999) pm = 99.99999
write(OutLine(IFaC(126):IFbC(126)), '(F10.5)') pm
end if
if (index(OutLine(IFaC(127):IFbC(127)), 'null') .eq. 0) then
read (OutLine(IFaC(127):IFbC(127)), *) pm ! force PMDec to F10.5
if (pm .lt. -99.99999) pm = -99.99999 ! NOTE PMDec now in col 127
if (pm .gt. 99.99999) pm = 99.99999
write(OutLine(IFaC(127):IFbC(127)), '(F10.5)') pm
end if
c if (GotOut2) write(22,'(a)') OutLine(1:lnblnk(OutLine)) ! JWF B91128
OutLines(nSrc) = OutLine ! JWF B91128
end if
c
go to 90
c
c - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
c ! update source counts in output headers
500 print *,' No. data rows processed: ', nSrc
c
do 1000 i = 1, nSrc
OutLine = OutLines(i)
if (IzCat(i)) then
if (GotOut1) write(20,'(a)') OutLine(1:lnblnk(OutLine))
nCout = nCout + 1
if (GotOutI1) then
do 600 k = 1, NFC
OutLine(IFaC(k):IFaC(k)) = '|'
600 continue
610 k = index(OutLine,'null')
if (k .gt. 0) then
OutLine(k:k+3) = ' '
go to 610
end if
615 Line = ''
n = 0
do 620 k = 1, lnblnk(OutLine)
if (OutLine(k:k) .ne. ' ') then
n = n + 1
Line(n:n) = OutLine(k:k)
end if
620 continue
k = index(Line,'|n|')
if (k .gt. 0) then
Line(k+1:k+1) = ' '
OutLine = Line
go to 615
end if
write (24,'(a)') Line(1:lnblnk(Line))//'|'
end if
else
if (GotOut2) write(22,'(a)') OutLine(1:lnblnk(OutLine))
nRout = nRout + 1
if (GotOutI2) then
do 700 k = 1, NFR
OutLine(IFaR(k):IFaR(k)) = '|'
700 continue
710 k = index(OutLine,'null')
if (k .gt. 0) then
OutLine(k:k+3) = ' '
go to 710
end if
715 Line = ''
n = 0
do 720 k = 1, lnblnk(OutLine)
if (OutLine(k:k) .ne. ' ') then
n = n + 1
Line(n:n) = OutLine(k:k)
end if
720 continue
k = index(Line,'|n|')
if (k .gt. 0) then
Line(k+1:k+1) = ' '
OutLine = Line
go to 715
end if
write (26,'(a)') Line(1:lnblnk(Line))//'|'
end if
end if
1000 continue
c
if (GotOut1) then
close(20)
open (20, file = OutCnam, access = 'DIRECT', recl = 1,
+ form = 'UNFORMATTED', status = 'OLD', err = 3003)
write (NumStr,'(I6)') nCout
do 1050 n = 1, LenHdrNsrc-7
Write(20, rec = 7+n) ' '
1050 continue
do 1100 n = 1, 6
Write(20, rec = 7+n) NumStr(n:n)
1100 continue
end if
c
1200 if (GotOut2) then
close(22)
open (22, file = OutRnam, access = 'DIRECT', recl = 1,
+ form = 'UNFORMATTED', status = 'OLD', err = 3004)
write (NumStr,'(I6)') nRout
do 1250 n = 1, LenHdrNsrc-7
Write(22, rec = 7+n) ' '
1250 continue
do 1300 n = 1, 6
Write(22, rec = 7+n) NumStr(n:n)
1300 continue
end if
c
1400 if (nSrc .ne. nSrcHdr) then
print *,
+ 'ERROR: this does not match the header "\nSrc" value: ',nSrcHdr
1401 n = index(InFNam,'/')
if (n .gt. 0) then
do 1402 i = 1, n
InFNam(i:i) = ' '
1402 continue
go to 1401
end if
InFNam = AdjustL(InFNam)
open (33, file = 'ERROR_MESSAGE-'
+ //InFNam(1:lnblnk(InFNam))//'.txt')
write (33,'(a)') 'ERROR: source count mismatch'
write (33,'(a,i9)') 'header "\nSrc" value:', nSrcHdr
write (33,'(a,i9)') 'actual source count: ', nSrc
end if
if (GotOut1 .or. GotOutI1)
+ print *,' No. output catalog sources: ', nCout
if (GotOut2 .or. GotOutI2)
+ print *,' No. output reject sources: ', nRout
if (nNamCollisn .gt. 0) print *,
+ ' No. output name collisions: ', nNamCollisn
c
print *
call signoff('catprep')
stop
c
c - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
c ! error handling
3000 print *,'ERROR: end-of-file encountered during sanity check'
call exit(64)
c
3001 print *,'ERROR: read error on mdex column ', k,', source #', nSrc
call exit(64)
c
3002 print *,'ERROR: read error on "\nSrc" in header:'
print *,' ',Line
call exit(64)
c
3003 print *,'ERROR: couldn''t update output catalog file header'
+ //' for record count'
go to 1200
c
3004 print *,'ERROR: couldn''t update output reject file header'
+ //' for record count'
go to 1400
c
3007 print *,'ERROR: bad "-s1" specification: ', NumStr
call exit(64)
c
3008 print *,'ERROR: bad "-s2" specification: ', NumStr
call exit(64)
c
3017 print *,'ERROR: EoF encountered in catprepin namelist file'
call exit(64)
c
3018 print *,'ERROR: read error encountered in catprepin namelist file'
call exit(64)
c
3019 print *,'ERROR: EoF encountered in mdetID/unwise_objid xref file'
call exit(64)
c
3020 print *,'ERROR: read error encountered in mdetID/unwise_objid'
+ //' xref file'
call exit(64)
c
3021 print *,'ERROR: read error on mdetID for data row no.', nSrc
call exit(64)
c
stop
end
c
c=======================================================================
c
subroutine ChkFld(Fld1, Fld2, k)
c
character*(*) Fld1, Fld2
integer*4 k, lnblnk
c
if (Fld1 .ne. Fld2) then
print *,'ERROR: input field no.',k,' expected to be ',
+ Fld2(1:lnblnk(Fld2)),'; got ',Fld1(1:lnblnk(Fld2))
call exit(64)
end if
c
return
c
end
c
c=======================================================================
c
subroutine GetFlds(ColNam,Field,IFa,IFb,NF)
c-----------------------------------------------------------------------
c
c Get fields in a table-file header line
c
c-----------------------------------------------------------------------
Integer*4 MaxFld
Parameter (MaxFld = 1000)
c
character*2500 ColNam
Character*300 Line
character*25 Field(MaxFld)
integer*4 IFa(MaxFld), IFb(MaxFld), NF, N, M, L, K, LNBlnk,
+ LastErr
c
c-----------------------------------------------------------------------
c
N = 0
K = 0
LastErr = 0
do 100 M = 1, LNBlnk(ColNam)
if (ColNam(M:M) .eq. '|') then
N = N + 1
NF = N - 1
if (N .gt. 1) IFb(N-1) = M-1
if (N .gt. MaxFld) return
IFa(N) = M
do 10 L = 1, 25
Field(N)(L:L) = ' '
10 continue
K = 0
else
if (ColNam(M:M) .ne. ' ') then
K = K + 1
if (K .le. 25) then
Field(N)(K:K) = ColNam(M:M)
else
if (LastErr .ne. N) then
write(Line,*) N
Line = 'GetFlds - Table column name no. '
+ //Line(1:lnblnk(Line))//' longer than 25 '
+ //'characters: '//Field(N)//'....; excess ignored'
print *,Line(1:lnblnk(line))
LastErr = N
end if
end if
end if
end if
100 continue
c
return
end
c
c=======================================================================
c
Subroutine NextNarg(NArg,NArgs)
c
integer NArg, NArgs
c
c-----------------------------------------------------------------------
c
if (NArg .lt. NArgs) then
NArg = NArg + 1
return
else
print *,'ERROR: expected another argument but none found'
call exit(64)
end if
return
end
c
c=======================================================================
c
subroutine upcase(string)
character*(*) string
integer*4 j, lnblnk
c
do 10 j = 1,lnblnk(string)
if(string(j:j) .ge. "a" .and. string(j:j) .le. "z") then
string(j:j) = achar(iachar(string(j:j)) - 32)
end if
10 continue
return
end
c
c=======================================================================
c
subroutine SignOn(pgmnam)
c
c *** signon- routine which provides sign-on and sign-off messages
c (orig by John Fowler- mod by Howard McCallon-041214-SIRTF)
c
c inputs: pgmnam = program name [call arg]
c
c outputs: message to stdout
c
character*(*) pgmnam
character vsn*11,cdate*8,ctime*8,Fmt*11,FLen*4
integer*4 onoff,jdate(3),jtime(3),lnblnk
real*4 dummyt,second(2),etime
c
common /vdt/ cdate,ctime,vsn
c##
onoff = 1
c
c i. obtain date
c
100 cdate = '00-00-00'
call idate(jdate) ! Linux call
c
jdate(3) = mod(jdate(3), 100)
write(cdate(1:2), '(i2)') jdate(2)
write(cdate(4:5), '(i2)') jdate(1)
write(cdate(7:8), '(i2)') jdate(3)
c
if(cdate(4:4) .eq. ' ') cdate(4:4) = '0'
if(cdate(7:7) .eq. ' ') cdate(7:7) = '0'
c
c ii. obtain time
c
ctime = '00:00:00'
call itime(jtime)
write(ctime(1:2), '(i2)') jtime(1)
write(ctime(4:5), '(i2)') jtime(2)
write(ctime(7:8), '(i2)') jtime(3)
c
if(ctime(4:4) .eq. ' ') ctime(4:4) = '0'
if(ctime(7:7) .eq. ' ') ctime(7:7) = '0'
c
c iii. set up format for pgmnam
c
write(Flen,'(I4)') lnblnk(pgmnam)
Fmt = '(A'//Flen//'$)'
c
c iv. write out results
c
write(*,Fmt) pgmnam
if(onoff .eq. 1) then ! sign on
write(*,301) vsn,cdate,ctime
else ! sign off
dummyt = etime(second)
write(*,302) vsn,cdate,ctime,second
endif
301 format(' version: ',a11,' - execution begun on ',a8,' at ',a8)
302 format(' version: ',a11,' - execution ended on ',a8,' at ',a8
* /1x,f9.2,' cpu seconds used;',f8.2,' system seconds used.')
c
return
c
entry SignOff(pgmnam)
OnOff = 2
go to 100
c
end
c
c=======================================================================
c
subroutine SexagesNam(ra, dec, nam)
c
c Jhhmmss.ss+ddmmss.s
c 1234567890123456789
c
character*20 nam, tmpstr
real*8 ra, dec, tSec, aSec
integer*4 nHH, nMM, nTmp, nDeg, nMin
c
c-----------------------------------------------------------------------
c
nHH = ra/15.0d0
nMM = 4.0d0*(ra - 15.0d0*dfloat(nHH))
tSec = 240.0d0*(ra - 15.0d0*dfloat(nHH) - dfloat(nMM)/4.0d0)
c
nDeg = dabs(dec)
nMin = 60.0d0*(dabs(dec) - dfloat(nDeg))
aSec = 3600.0d0*(dabs(dec) - dfloat(nDeg) - dfloat(nMin)/60.0d0)
c
write(tmpstr,'(i2.2)') nHH
nam = 'J'//tmpstr
write(tmpstr,'(i2.2)') nMM
nam = nam(1:lnblnk(nam))//tmpstr
write(tmpstr,'(f6.3)') tSec
if (tmpstr(1:1) .eq. ' ') tmpstr(1:1) = '0'
nam = nam(1:lnblnk(nam))//tmpstr(1:5)
c
if (dec .ge. 0.0d0) then
nam(11:11) = '+'
else
nam(11:11) = '-'
end if
c
write(tmpstr,'(i2.2)') nDeg
nam = nam(1:lnblnk(nam))//tmpstr
write(tmpstr,'(i2.2)') nMin
nam = nam(1:lnblnk(nam))//tmpstr
write(tmpstr,'(f6.3)') aSec
if (tmpstr(1:1) .eq. ' ') tmpstr(1:1) = '0'
nam = nam(1:lnblnk(nam))//tmpstr(1:4)
c
return
end
c
c=======================================================================
c
subroutine Cel2Ec(RA, Dec, Long, Lat)
c
real*8 RA, Dec, Long, Lat, SOb, Cob, X, Y, Z, d2r,
+ cRA, cDec, sRA, sDec, X2, Y2
c
c Obliquity in J2000: 23.43927944 deg = 8.4381406d4 arcsec
c
data d2r/1.745329252d-2/, cOb, sOb/0.917482143d0, 0.397776969d0/
c
c Ref: Celest Mech Dyn Astr (2011) 110:293–304
c DOI 10.1007/s10569-011-9352-4
c SPECIAL REPORT
c The IAU 2009 system of astronomical constants:
c the report of the IAU working group on numerical
c standards for Fundamental Astronomy
c https://link.springer.com/content/pdf/10.1007%2Fs10569-011-9352-4.pdf
c
c-----------------------------------------------------------------------
c
cRA = dcos(d2r*RA)
cDec = dcos(d2r*Dec)
sRA = dsin(d2r*RA)
sDec = dsin(d2r*Dec)
c
X = sDec
Y = -cDec*sRA
Z = cDec*cRA
c
X2 = X*Cob + Y*Sob