File: emrslts.x

package info (click to toggle)
iraf-rvsao 2.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 16,456 kB
  • sloc: ansic: 963; lisp: 651; fortran: 397; makefile: 27
file content (1321 lines) | stat: -rw-r--r-- 36,037 bytes parent folder | download
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
# File rvsao/Emvel/emrslts.x
# March 27, 2015
# By Jessica Mink, Harvard-Smithsonian Center for Astrophysics

# Copyright(c) 2009-2015 Smithsonian Astrophysical Observatory
# You may do anything you like with this file except remove this copyright.
# The Smithsonian Astrophysical Observatory makes no representations about
# the suitability of this software for any purpose.  It is provided "as is"
# without express or implied warranty.

#  Log radial velocity from emission line shift

include	<imhdr.h>
include	"../lib/rvsao.h"
include	"../lib/emv.h"
define	SZ_MONTH	3
define	SZ_YEAR		40

procedure emrslts (specfile, mspec, image, rmode0)

char	specfile[ARB]	# Name of spectrum file
int	mspec		# Spectrum number in multispec file (else 0)
pointer	image		# Header structure for spectrum
int	rmode0		# Report format (1=normal,2=one-line...)

int	i, j
char	wch[8]		# Line weight indicator
double	emz		# z from emission lines
double	xcz		# z from cross-correlation
double	spz		# z from cross-correlation and emission
double	spexvel		# Emission line template cross-correlation velocity
double	spexerr		# Emission line template cross-correlation error
int	iczexvel	# Emission line template cross-correlation velocity
int	iczexerr	# Emission line template cross-correlation error
double	spexr		# Emission line template cross-correlation R-value
int	rmode		# Report format (1=normal,2=one-line)
char	instrument[10]
char	lbr, rbr
int	ibr, ibl

bool	verbose, clgetb()
double	ra, dec, ut, dj, hdj
double	twt, wt, exptime, alt, az, ha, lat, sha,cha,slat,clat,sdec,cdec,epoch
double	ac,dpi,tpi,rcon, rdec, rha, dindef, dwdp, wl1, pix1, pix2
int	mm,dd,yyyy, itemp, lspec
char	month[SZ_YEAR]
char	nolines[SZ_LINE]
char	nodate[SZ_LINE]
char	kra[8]
char	kha[8]
char	kdec[8]
int	icz,iczxc,iczem,icze,iczxce,iczeme
int	strcmp(), strlen()
char	ssvcor[16]
double	wcs_p2w(), wcs_w2p()
int	imaccf(), stridx()
char	spchar[8]

include	"../lib/emv.com"
include	"../lib/rvsao.com"
include	"../lib/results.com"
include	"../lib/lineinfo.com"

begin

# Return if no log file, including STDOUT
	if (nlogfd < 1)
	    return

	dindef = INDEFD
        lbr = char (91)
        rbr = char (93)
	ibr = 0
	ibl = 0
	verbose = clgetb ("verbose")
        if (!verbose) return
	call strcpy ("JanFebMarAprMayJunJulAugSepOctNovDec",month, SZ_YEAR)
	call strcpy ("No emission lines found\n", nolines, SZ_LINE)
	call strcpy (" (No observation date)", nodate, SZ_LINE)
	call strcpy ("RA", kra, 8)
	call strcpy ("DEC", kdec, 8)
	call strcpy ("HA", kha, 8)

	call juldate (image, ut, dj, hdj, debug)

	mm = INDEFI
	dd = INDEFI
	yyyy = INDEFI
	if (imaccf (image, "DATE-OBS") == YES)
	    call imgdate (image, "DATE-OBS", mm, dd, yyyy)
	else if (imaccf (image, "DATE") == YES)
	    call imgdate (image, "DATE", mm, dd, yyyy)

	if (spvel != dindef) {
	    icz = idnint (spvel)
	    icze = idnint (sperr)
	    }
	else {
	    icz = 0
	    icze = 0
	    }

	if (spxvel != dindef) {
	    iczxc = idnint (spxvel)
	    iczxce = idnint (spxerr)
	    }
	else {
	    iczxc = 0
	    iczxce = 0
	    }

	if (spevel != dindef) {
	    iczem = idnint (spevel)
	    iczeme = idnint (speerr)
	    }
	else {
	    iczem = 0
	    iczeme = 0
	    }

# Set emission line template velocity, if there is one
	spexvel = 0.0
	spexerr = 0.0
	spexr = 0.0
	iczexvel = 0
	iczexerr = 0
	if (strlen (cortemp) > 0 && ntemp > 0) {
	    do itemp = 1, ntemp {
		if (strcmp (cortemp,tempid[1,itemp]) == 0) {
		    spexvel = zvel[itemp]
		    spexerr = czerr[itemp]
		    iczexvel = int (zvel[itemp])
		    iczexerr = int (czerr[itemp])
		    spexr = czr[itemp]
		    }
		}
	    }
	else {
	    spexvel = spxvel
	    spexerr = spxerr
	    if (spxvel != dindef) {
		iczexvel = int (spxvel)
		iczexerr = int (spxerr)
		}
	    else {
		iczexvel = 0
		iczexerr = 0
		}
	    spexr = spxr
	    }

	lspec = strlen (specid)

# Set up spectrum number in specid
#	if (mspec > 0) {
#	    call sprintf (specid,SZ_PATHNAME,"%s[%d]")
#		call pargstr (specfile)
#		call pargi (mspec)
#	    }
#	else
#	    call strcpy (specfile,specid,SZ_PATHNAME)

	if (debug) {
	    call printf ("EMRSLTS: ready to print results\n")
	    call flush (STDOUT)
	    }

# Set separating character to tab if report mode is less than 0
	if (rmode0 >= 0) {
	    call strcpy (" ", spchar, 8)
	    rmode = rmode0
	    }
	else {
	    call strcpy ("\t", spchar, 8)
	    rmode = -rmode0
	    }

# Convert brackets to spaces in all one-line report modes
	if (rmode > 0) {
            ibr = stridx (rbr, specid)
            if (ibr > 0)
                specid[ibr] = ' '
            ibl = stridx (lbr, specid)
            if (ibl > 0)
                specid[ibl] = ' '
	    }

	if (rmode < 2 || rmode == 10) {

#	Read position of object from spectrum header
	    ra = dindef
	    call imgdpar (image,kra,ra)
	    dec = dindef
	    call imgdpar (image,kdec,dec)
	    epoch = 1950.d0
	    call imgdpar (image,"EPOCH",epoch)
	    call imgdpar (image,"EQUINOX",epoch)

	    call printf ("\n")
	    call flush (STDOUT)

#	Set type and source of velocity correction to center of solar system
	    switch (svcor) {
		case NONE:
		    call strcpy ("BCV",ssvcor,16)
		case HCV:
		    call strcpy ("HCV",ssvcor,16)
		case BCV:
		    call strcpy ("BCV",ssvcor,16)
		case FHCV:
		    call strcpy ("File HCV",ssvcor,16)
		case FBCV:
		    if (specvb) 
			call strcpy ("File BCV",ssvcor,16)
		    else
			call strcpy ("File HCV",ssvcor,16)
		default:
		    call strcpy ("BCV",ssvcor,16)
		}

#	Log object information
	    do j = 1, nlogfd {
		if (rmode < 2) {
		call fprintf(logfd[j], "File: %s\n")
		    call pargstr (specid)
		if (ra != dindef && dec != dindef) {
		    call fprintf(logfd[j], "Object: %s  RA: %011.2h Dec: %010.1h %.1f\n")
			call pargstr (specname)
			call pargd (ra)
			call pargd (dec)
			call pargd (epoch)
		    }
		else {
		    call fprintf(logfd[j], "Object: %s  (No position)\n")
			call pargstr (specname)
		    }

		if (debug) {
		    call flush (STDOUT)
		    }
		if (dd != INDEFI && mm != INDEFI && yyyy != INDEFI) {
		    call fprintf(logfd[j], "Observed %4d-%3.3s-%02d %011.2h = JD %.4f %s: %6.2f\n")
			call pargi (yyyy)
			call pargstr (month[(mm - 1) * SZ_MONTH + 1])
			call pargi (dd)
			call pargd (ut)
			call pargd (dj)
			call pargstr (ssvcor)
			call pargd (spechcv)
		    }
		else {
		    call fprintf(logfd[j], "%s %s: %6.2f\n")
			call pargstr (nodate)
			call pargstr (ssvcor)
			call pargd (spechcv)
		    }
		call flush (logfd[j])

	#  Print combined velocity
		if (spvel != dindef) {
		    spz = spvel / c0
		    call fprintf(logfd[j],
		    "Combined vel = %8.2f +- %7.2f km/sec, z= %6.4f \n")
			call pargd (spvel)
			call pargd (sperr)
			call pargd (spz)
		    call flush (logfd[j])
		    }

	# Print cross-correlation velocity
		if (spxvel != dindef) {
		    xcz = spxvel / c0
		    call fprintf(logfd[j],
		    "Correlation vel = %8.2f +- %7.2f km/sec, z= %6.4f R= %6.1f \n")
			call pargd (spxvel)
			call pargd (spxerr)
			call pargd (xcz)
			call pargd (spxr)
		    call flush (logfd[j])
		    }

	# Print emission line velocity
		if (spevel != dindef) {
		    emz = spevel / c0
		    call fprintf(logfd[j],
		    "Emission vel = %8.2f +- %7.2f km/sec, z= %6.4f for %d/%d lines\n")
			call pargd (spevel)
			call pargd (speerr)
			call pargd (emz)
			call pargi (nfit)
			call pargi (nfound)
		    call flush (logfd[j])
		    }
		}

	# Print emission line information if any were found
		if (nfound > 0) {
		    twt = 0.d0
		    do i = 1, nfound {
			wt = emparams[10,1,i]
			if (wt != 0.d0)
			    twt = twt + 1.d0 / (wt * wt)
			}
		    call fprintf(logfd[j], "\nLine  Rest lam  Obs. lam    ")
		    call fprintf(logfd[j], "Pixel     z         vel    dvel")
		    if (rmode == 1)
			call fprintf(logfd[j], "    eqw    wt\n")
		    else
			call fprintf(logfd[j], "    eqw    eqe    wt\n")
		    do i = 1, nfound {
			wtobs[i] = emparams[10,1,i]
			if (wtobs[i] > 0) {
			    if (override[i] < 0)
				call strcpy ("-",wch,8)
			    else if (override[i] > 0)
				call strcpy ("+",wch,8)
			    else
				call strcpy (" ",wch,8)
			    }
			else if (linedrop[i] > 0) {
			    call sprintf(wch,8,"X%d")
				call pargi (linedrop[i])
			    }
			else
			    call strcpy ("X",wch,8)
			call fprintf(logfd[j],"%4s   %7.2f   %7.2f  %7.2f")
			    call pargstr (nmobs[1,i])
			    call pargd (wlrest[i])
			    call pargd (wlobs[i])
			    call pargd (emparams[4,1,i])
			wt = emparams[10,1,i]
			if (wt != 0.d0)
			    wt = (1.d0 / (wt * wt)) / twt
			if (rmode == 1 || rmode == 10)
			    call fprintf (logfd[j],"  %6.4f  %8.2f %7.2f %6.2f %6.3f %s\n")
			else
			    call fprintf (logfd[j],"  %6.4f  %8.2f %7.2f %6.2f %6.2f %6.3f %s\n")
			    call pargd (emparams[9,1,i])
			    call pargd ((c0*emparams[9,1,i]) + spechcv)
			    call pargd (c0*emparams[9,2,i])
			    call pargd (emparams[7,1,i])
			if (rmode == 0)
			    call pargd (emparams[7,2,i])
			    call pargd (wt)
			    call pargstr (wch)
			}
		    }
		else {
		    call fprintf(logfd[j], nolines)
		    }
		}
	    }

# Single line report
	else if (rmode == 2 || rmode == 5) {
	    call imgspar (image,"INSTRUME",instrument,8)
	    if (strlen (instrument) == 0)
		call strcpy ("________", instrument, 8)
	    do j = 1, nlogfd {
		if (lspec > 32) {
		    call fprintf(logfd[j],"%s")
			call pargstr (specid)
		    }
		else {
		    call fprintf(logfd[j],"%-32.32s")
			call pargstr (specid)
		    }
		call fprintf(logfd[j],"%s%-8.8s%s%-16.16s%s%13.5f")
		    call pargstr (spchar)
		    call pargstr (instrument)
		    call pargstr (spchar)
		    call pargstr (IM_TITLE(image))
		    call pargstr (spchar)
		    call pargd (dj)
		call fprintf(logfd[j],"%s%6d%s%3d")
		    call pargstr (spchar)
		    call pargi (iczem)
		    call pargstr (spchar)
		    call pargi (iczeme)
		call fprintf(logfd[j],"%s%6d%s%3d%s%5.1f")
		    call pargstr (spchar)
		    if (rmode == 2) {
			call pargi (iczxc)
			call pargstr (spchar)
			call pargi (iczxce)
			call pargstr (spchar)
			call pargd (spxr)
			}
		    else {
			call pargi (iczexvel)
			call pargstr (spchar)
			call pargi (iczexerr)
			call pargstr (spchar)
			call pargd (spexr)
			}
		call fprintf(logfd[j],"%s%6d%s%3d%sE%s%2d%s%2d")
		    call pargstr (spchar)
		    call pargi (icz)
		    call pargstr (spchar)
		    call pargi (iczxce)
		    call pargstr (spchar)
		    call pargstr (spchar)
		    call pargi (nfound)
		    call pargstr (spchar)
		    call pargi (nfit)
		if (nfit > 0) {
		    do i = 1, nfound {
			wtobs[i] = emparams[10,1,i]
			if (wtobs[i] > 0 && override[i] >= 0) {
			    call fprintf(logfd[j], "%s%s(%7.2f)")
				call pargstr (spchar)
				call pargstr (nmobs[1,i])
				call pargd (wlrest[i])
			    }
			}
		    }
		call fprintf(logfd[j], "\n")
		}
	    }

# Single line report with one velocity per possible line
	else if (rmode == 3 || rmode == 6 || rmode == 9 || rmode == 11) {
	    call imgspar (image,"INSTRUMEN",instrument, 9)
	    if (strlen (instrument) == 0)
		call strcpy ("_________", instrument, 9)
	    call aclrd (velline,MAXREF)

#	Compute individual line velocities from shift
	    if (nfound > 0) {
		do i = 1, nfound {
		    wtobs[i] = emparams[10,1,i]
		    if (wtobs[i] > 0 && override[i] >= 0) {
			do j = 1, nref {
			    if (wlref[j] == wlrest[i]) {
				if (rmode == 9)
				    velline[j] = wlobs[i] - wlref[j]
				else if (rmode == 11) {
				    pix1 = wcs_w2p (wlref[j])
				    pix2 = wcs_w2p (wlobs[i])
				    velline[j] = pix2 - pix1
				    }
				else
				    velline[j] = (c0 * emparams[9,1,i]) + spechcv
				}
			    }
			}
		    }
		}

	# Print one-line report
	    do j = 1, nlogfd {
		if (lspec > 32) {
		    call fprintf(logfd[j],"%s")
			call pargstr (specid)
		    }
		else {
		    call fprintf(logfd[j],"%-32.32s")
			call pargstr (specid)
		    }
		call fprintf(logfd[j],"%s%-9.9s%s%-16.16s%s%13.5f")
		    call pargstr (spchar)
		    call pargstr (instrument)
		    call pargstr (spchar)
		    call pargstr (IM_TITLE(image))
		    call pargstr (spchar)
		    call pargd (dj)
		if (rmode < 9) {
		    call fprintf(logfd[j],"%s%8.2f%s%6.2f")
			call pargstr (spchar)
			call pargd (spevel)
			call pargstr (spchar)
			call pargd (speerr)
		    call fprintf(logfd[j],"%s%8.2f%s%6.2f%s%5.1f")
			call pargstr (spchar)
		    if (rmode == 3) {
			call pargd (spxvel)
			call pargstr (spchar)
			call pargd (spxerr)
			call pargstr (spchar)
			call pargd (spxr)
			}
		    else {
			call pargd (spexvel)
			call pargstr (spchar)
			call pargd (spexerr)
			call pargstr (spchar)
			call pargd (spexr)
			}
		    call fprintf(logfd[j],"%s%8.2f%s%6.2f%sE")
			call pargstr (spchar)
			call pargd (spvel)
			call pargstr (spchar)
			call pargd (sperr)
			call pargstr (spchar)
		    }
		call fprintf(logfd[j],"%s%2d%s%2d")
		    call pargstr (spchar)
		    call pargi (spnl)
		    call pargstr (spchar)
		    call pargi (spnlf)
		do i = 1, nref {
		    call fprintf (logfd[j],"%s%9.3f")
			call pargstr (spchar)
			call pargd (velline[i])
		    }
		call fprintf(logfd[j], "\n")
		}
	    }

# Single line report with velocity, error, height, width, and equivalent width
# for each emission line
	else if (rmode == 4 || rmode == 7) {
	    call imgspar (image,"INSTRUME",instrument,8)
	    if (strlen (instrument) == 0)
		call strcpy ("________", instrument, 8)
	    call aclrd (velline,MAXREF)
	    call aclrd (errline,MAXREF)
	    call aclrd (htline,MAXREF)
	    call aclrd (widline,MAXREF)
	    call aclrd (eqwline,MAXREF)
	    call aclrd (eqeline,MAXREF)

#	Compute individual line velocities from shift
	    if (nfound > 0) {
		do i = 1, nfound {
		    wtobs[i] = emparams[10,1,i]
		    if (wtobs[i] > 0 && override[i] >= 0) {
			do j = 1, nref {
			    if (wlref[j] == wlrest[i]) {
				velline[j] = (c0 * emparams[9,1,i]) + spechcv
				errline[j] = c0 * emparams[9,2,i]
				htline[j] = emparams[5,1,i]
				wl1 = wcs_p2w (emparams[4,1,i] - 1.d0)
				dwdp = wlobs[i] - wl1
				widline[j] = emparams[6,1,i] * dwdp
				eqwline[j] = emparams[7,1,i]
				eqeline[j] = emparams[7,2,i]
				}
			    }
			}
		    }
		}

	# Get sky position
	    ra = 99.d0
	    call imgdpar (image,kra,ra)
	    dec = 99.d0
	    call imgdpar (image,kdec,dec)
	    ha = 99.d0
	    call imgdpar (image,kha,ha)
	    lat = 99.d0
	    call imgdpar (image,"SITELAT",lat)

	    if (debug) {
		call printf ("EMRSLTS: RA: %011.2h Dec: %010.1h HA: %011.2h Lat: %010.1h\n")
		    call pargd (ra)
		    call pargd (dec)
		    call pargd (ha)
		    call pargd (lat)
		}

	# Compute altitude and azimuth
	    if (ha < 12.d0 && ha > -12.d0 && dec <= 90.d0 && dec >= -90.d0 &&
 		lat >= -90.d0 && lat <= 90.d0) {
		dpi = 3.1415926535897932d0
		tpi = 6.283185307179588d0
		rcon = 1.74532925199433d-2
		rha = ha * 15.d0 * rcon
		if (rha == 0)
		    rha = 1.d-5
		sha = sin (rha)
		cha = cos (rha)
		rdec = dec * rcon
		sdec = sin (rdec)
		cdec = cos (rdec)
		slat = sin (lat)
		clat = cos (lat)
		ac = (clat * sdec) - (slat * cdec * cha)
		az = atan (-cdec * sha / abs (ac))
		if (ac < 0) az = dpi - az
		if (az < 0) az = tpi + az
		ac = -cdec * sha / sin (az)
		alt = atan ((slat * sdec) + (clat * cdec * cha) / abs (ac))
		if (ac < 0) alt = dpi - alt
		az = az / rcon
		alt = alt / rcon
		}
	    else {
		alt = 0.d0
		az = 0.d0
		}

	    exptime = 0.d0
	    call imgdpar (image,"EXPTIME",exptime)

	# Print one-line report
	    do j = 1, nlogfd {
		if (lspec > 32) {
		    call fprintf(logfd[j],"%s")
			call pargstr (specid)
		    }
		else {
		    call fprintf(logfd[j],"%-32.32s")
			call pargstr (specid)
		    }
		call fprintf(logfd[j],"%s%-8.8s%s%-16.16s")
		    call pargstr (spchar)
		    call pargstr (instrument)
		    call pargstr (spchar)
		    call pargstr (IM_TITLE(image))
		call fprintf(logfd[j],"%s%011.2h%s%010.1h%s%5.1f%s%5.1f")
		    call pargstr (spchar)
		    call pargd (ra)
		    call pargstr (spchar)
		    call pargd (dec)
		    call pargstr (spchar)
		    call pargd (az)
		    call pargstr (spchar)
		    call pargd (alt)
		call fprintf(logfd[j],"%s%13.5f%s%6.1f")
		    call pargstr (spchar)
		    call pargd (dj)
		    call pargstr (spchar)
		    call pargd (exptime)
		call fprintf(logfd[j],"%s%8.2f%s%6.2f%s%8.2f%s%6.2f%s%5.1f")
		    call pargstr (spchar)
		    call pargd (spevel)
		    call pargstr (spchar)
		    call pargd (speerr)
		    call pargstr (spchar)
		    call pargd (spexvel)
		    call pargstr (spchar)
		    call pargd (spexerr)
		    call pargstr (spchar)
		    call pargd (spexr)
		call fprintf(logfd[j],"%s%8.2f%s%6.2f%s%2d%s%2d")
		    call pargstr (spchar)
		    call pargd (spvel)
		    call pargstr (spchar)
		    call pargd (sperr)
		    call pargstr (spchar)
		    call pargi (spnl)
		    call pargstr (spchar)
		    call pargi (spnlf)
		do i = 1, nref {
		    if (rmode == 4)
			call fprintf (logfd[j],"%s%8.2f%s%6.2f%s%9.2f%s%5.2f%s%6.2f")
		    else
			call fprintf (logfd[j],"%s%8.2f%s%6.2f%s%9.2f%s%5.2f%s%6.2f%s%6.2f")
			call pargstr (spchar)
			call pargd (velline[i])
			call pargstr (spchar)
			call pargd (errline[i])
			call pargstr (spchar)
			call pargd (htline[i])
			call pargstr (spchar)
			call pargd (widline[i])
			call pargstr (spchar)
			call pargd (eqwline[i])
		    if (rmode == 7)
			call pargd (eqeline[i])
		    }
		call fprintf(logfd[j], "\n")
		}
	    }

# Single line report with line offset, error, height, width, and
# equivalent width for each emission line
	else if (rmode == 8) {
	    call imgspar (image,"INSTRUME",instrument,8)
	    if (strlen (instrument) == 0)
		call strcpy ("________", instrument, 8)
	    call aclrd (velline,MAXREF)
	    call aclrd (errline,MAXREF)
	    call aclrd (htline,MAXREF)
	    call aclrd (widline,MAXREF)
	    call aclrd (eqwline,MAXREF)
	    call aclrd (eqeline,MAXREF)

#	Compute individual line velocities from shift
	    if (nfound > 0) {
		do j = 1, nref {
		    velline[j] = 0.0
		    htline[j] = 0.0
		    widline[j] = 0.0
		    errline[j] = 0.0
		    eqwline[j] = 0.0
		    eqeline[j] = 0.0
		    }
		do i = 1, nfound {
		    wtobs[i] = emparams[10,1,i]
		    if (wtobs[i] > 0 && override[i] >= 0) {
			do j = 1, nref {
			    if (wlref[j] == wlrest[i]) {
				velline[j] = wlobs[i] - wlrest[i]
				htline[j] = emparams[5,1,i]
				wl1 = wcs_p2w (emparams[4,1,i] - 1.d0)
				dwdp = wlobs[i] - wl1
				widline[j] = emparams[6,1,i] * dwdp
				errline[j] = emparams[4,2,i] * dwdp
				eqwline[j] = emparams[7,1,i]
				eqeline[j] = emparams[7,2,i]
				}
			    }
			}
		    }
		}

	# Get sky position
	    ra = 99.d0
	    call imgdpar (image,kra,ra)
	    dec = 99.d0
	    call imgdpar (image,kdec,dec)
	    ha = 99.d0
	    call imgdpar (image,kha,ha)
	    lat = 99.d0
	    call imgdpar (image,"SITELAT",lat)

	    if (debug) {
		call printf ("EMRSLTS: RA: %011.2h Dec: %010.1h HA: %011.2h Lat: %010.1h\n")
		    call pargd (ra)
		    call pargd (dec)
		    call pargd (ha)
		    call pargd (lat)
		}

	# Compute altitude and azimuth
	    if (ha < 12.d0 && ha > -12.d0 && dec <= 90.d0 && dec >= -90.d0 &&
 		lat >= -90.d0 && lat <= 90.d0) {
		dpi = 3.1415926535897932d0
		tpi = 6.283185307179588d0
		rcon = 1.74532925199433d-2
		rha = ha * 15.d0 * rcon
		if (rha == 0)
		    rha = 1.d-5
		sha = sin (rha)
		cha = cos (rha)
		rdec = dec * rcon
		sdec = sin (rdec)
		cdec = cos (rdec)
		slat = sin (lat)
		clat = cos (lat)
		ac = (clat * sdec) - (slat * cdec * cha)
		az = atan (-cdec * sha / abs (ac))
		if (ac < 0) az = dpi - az
		if (az < 0) az = tpi + az
		ac = -cdec * sha / sin (az)
		alt = atan ((slat * sdec) + (clat * cdec * cha) / abs (ac))
		if (ac < 0) alt = dpi - alt
		az = az / rcon
		alt = alt / rcon
		}
	    else {
		alt = 0.d0
		az = 0.d0
		}

	    exptime = 0.d0
	    call imgdpar (image,"EXPTIME",exptime)

	# Print one-line report
	    do j = 1, nlogfd {
		if (lspec > 32) {
		    call fprintf(logfd[j],"%s")
			call pargstr (specid)
		    }
		else {
		    call fprintf(logfd[j],"%-32.32s")
			call pargstr (specid)
		    }
		call fprintf(logfd[j],"%s%-8.8s%s%-16.16s")
		    call pargstr (spchar)
		    call pargstr (instrument)
		    call pargstr (spchar)
		    call pargstr (IM_TITLE(image))
		call fprintf(logfd[j],"%s%011.2h%s%010.1h%s%5.1f%s%5.1f")
		    call pargstr (spchar)
		    call pargd (ra)
		    call pargstr (spchar)
		    call pargd (dec)
		    call pargstr (spchar)
		    call pargd (az)
		    call pargstr (spchar)
		    call pargd (alt)
		call fprintf(logfd[j],"%s%13.5f%s%6.1f")
		    call pargstr (spchar)
		    call pargd (dj)
		    call pargstr (spchar)
		    call pargd (exptime)
		call fprintf(logfd[j],"%s%2d%s%2d")
		    call pargstr (spchar)
		    call pargi (spnl)
		    call pargstr (spchar)
		    call pargi (spnlf)
		do i = 1, nref {
		    call fprintf (logfd[j],"%s%8.3f%s%8.4f%s%6.4f%s%9.2f%s%6.3f%s%6.2f%s%6.2f")
			call pargstr (spchar)
			call pargd (wlref[i])
			call pargstr (spchar)
			call pargd (velline[i])
			call pargstr (spchar)
			call pargd (errline[i])
			call pargstr (spchar)
			call pargd (htline[i])
			call pargstr (spchar)
			call pargd (widline[i])
			call pargstr (spchar)
			call pargd (eqwline[i])
			call pargstr (spchar)
			call pargd (eqeline[i])
		    }
		call fprintf(logfd[j], "\n")
		}
	    }

# For echelle with more precision, fewer lines
	else if (rmode == 12) {
	    do j = 1, nlogfd {
		call fprintf(logfd[j], "# %s")
		    call pargstr (specid)
		if (dd != INDEFI && mm != INDEFI && yyyy != INDEFI) {
		    call fprintf(logfd[j], "%4d-%3.3s-%02d %011.2h %.4f")
			call pargi (yyyy)
			call pargstr (month[(mm - 1) * SZ_MONTH + 1])
			call pargi (dd)
			call pargd (ut)
			call pargd (dj)
		    }
		else {
		    call fprintf(logfd[j], nodate)
		    }
		call fprintf(logfd[j], " %8.4f %7.4f %d/%d\n")
			call pargd (spevel)
			call pargd (speerr)
			call pargi (nfit)
			call pargi (nfound)

	# Print emission line information if any were found
		if (nfound > 0) {
		    twt = 0.d0
		    do i = 1, nfound {
			wt = emparams[10,1,i]
			if (wt != 0.d0)
			    twt = twt + 1.d0 / (wt * wt)
			}
		    call fprintf(logfd[j], "#Rest wl  Obs. wl   Line Order Pixel       Vel    Dvel     Eqw    Wt\n")
		    do i = 1, nfound {
			wtobs[i] = emparams[10,1,i]
			if (wtobs[i] > 0) {
			    if (override[i] < 0)
				call strcpy ("-",wch,8)
			    else if (override[i] > 0)
				call strcpy ("+",wch,8)
			    else
				call strcpy (" ",wch,8)
			    }
			else if (linedrop[i] > 0) {
			    call sprintf(wch,8,"X%d")
				call pargi (linedrop[i])
			    }
			else
			    call strcpy ("X",wch,8)
			call fprintf(logfd[j],"%9.4f%s%9.4f%s%4s%s%3d%s%9.4f")
			    call pargd (wlrest[i])
			    call pargstr (spchar)
			    call pargd (wlobs[i])
			    call pargstr (spchar)
			    call pargstr (nmobs[1,i])
			    call pargstr (spchar)
			    call pargi (mspec)
			    call pargstr (spchar)
			    call pargd (emparams[4,1,i])
			wt = emparams[10,1,i]
			if (wt != 0.d0)
			    wt = (1.d0 / (wt * wt)) / twt
			call fprintf (logfd[j],"%s%8.4f%s%6.4f%s%8.2f%s%5.3f%s%s\n")
			    call pargstr (spchar)
			    call pargd ((c0*emparams[9,1,i]) + spechcv)
			    call pargstr (spchar)
			    call pargd (c0*emparams[9,2,i])
			    call pargstr (spchar)
			    call pargd (emparams[7,1,i])
			    call pargstr (spchar)
			    call pargd (wt)
			    call pargstr (spchar)
			    call pargstr (wch)
			}
		    }
		else {
		    call fprintf(logfd[j], nolines)
		    }
		}
	    }
	if (ibr > 0)
	    specid[ibr] = ']'
	if (ibl > 0)
	    specid[ibl] = '['
end

procedure emrshead (rmode0)

int	rmode0		# Report format (1=normal,2=one-line...)

int	i, j
int	rmode
char	spchar[8]
char	uscore[40]
char	tstring[16]

include	"../lib/emv.com"
include	"../lib/rvsao.com"
include	"../lib/results.com"

begin
	if (rmode0 >= 0) {
	    call strcpy (" ", spchar, 8)
	    rmode = rmode0
	    }
	else {
	    call strcpy ("\t", spchar, 8)
	    rmode = -rmode0
	    }
	call strcpy ("--------------------------------", uscore, 40)

	# Print one-line report
	if (rmode == 2 || rmode == 5) {
	    do j = 1, nlogfd {
		call fprintf(logfd[j],"%-32.32s%s%-8.8s%s%-16.16s")
		    call pargstr ("specid")
		    call pargstr (spchar)
		    call pargstr ("instrument")
		    call pargstr (spchar)
		    call pargstr ("title")
		call fprintf(logfd[j],"%s%-13.13s%s%-5.5s%s%3.3s")
		    call pargstr (spchar)
		    call pargstr ("Julian Date")
		    call pargstr (spchar)
		    call pargstr ("emvel")
		    call pargstr (spchar)
		    call pargstr ("emerr")
		if (rmode == 3) {
		    call fprintf(logfd[j],"%s%-6.6s%s%3.3s%s%-5.5s")
			call pargstr (spchar)
			call pargstr ("xcvel")
			call pargstr (spchar)
			call pargstr ("xcerr")
			call pargstr (spchar)
			call pargstr ("xcr")
		    }
		else {
		    call fprintf(logfd[j],"%s%-6.6s%s%3.3s%s%-5.5s")
			call pargstr (spchar)
			call pargstr ("xcevel")
			call pargstr (spchar)
			call pargstr ("xcever")
			call pargstr (spchar)
			call pargstr ("xcer")
		    }
		call fprintf(logfd[j],"%s%6.6s%s%3.3s%s%1.1s%s%2.2s%s%2.2s")
		    call pargstr (spchar)
		    call pargstr ("velocity")
		    call pargstr (spchar)
		    call pargstr ("verr")
		    call pargstr (spchar)
		    call pargstr ("E")
		    call pargstr (spchar)
		    call pargstr ("nl")
		    call pargstr (spchar)
		    call pargstr ("nf")
		do i = 1, nref {
		    call sprintf (tstring,16,"line%02d(rest)")
			call pargi (i)
		    call fprintf (logfd[j],"%s%12s")
			call pargstr (spchar)
			call pargstr (tstring)
		    }
		call fprintf(logfd[j], "\n")

		call fprintf(logfd[j],"%32.32s%s%8.8s%s%16.16s")
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		call fprintf(logfd[j],"%s%13.13s%s%6.6s%s%3.3s")
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		call fprintf(logfd[j],"%s%6.6s%s%3.3s%s%5.5s")
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		call fprintf(logfd[j],"%s%6.6s%s%3.3s%s%1.1s%s%2.2s%s%2.2s")
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		do i = 1, nref {
		    call fprintf (logfd[j],"%s%12.12s")
			call pargstr (spchar)
			call pargstr (uscore)
		    }
		call fprintf(logfd[j], "\n")
		}
	    }
	else if (rmode == 3 || rmode == 6) {
	    do j = 1, nlogfd {
		call fprintf(logfd[j],"%-32.32s%s%-8.8s%s%-16.16s")
		    call pargstr ("specid")
		    call pargstr (spchar)
		    call pargstr ("instrument")
		    call pargstr (spchar)
		    call pargstr ("title")
		call fprintf(logfd[j],"%s%-13.13s%s%-8.8s%s%6.6s")
		    call pargstr (spchar)
		    call pargstr ("Julian Date")
		    call pargstr (spchar)
		    call pargstr ("emvel")
		    call pargstr (spchar)
		    call pargstr ("emverr")
		    if (rmode == 3) {
			call fprintf(logfd[j],"%s%-8.8s%s%6.6s%s%-5.5s")
			    call pargstr (spchar)
			    call pargstr ("xcvel")
			    call pargstr (spchar)
			    call pargstr ("xcverr")
			    call pargstr (spchar)
			    call pargstr ("xcr")
			}
		    else {
			call fprintf(logfd[j],"%s%-8.8s%s%6.6s%s%-5.5s")
			    call pargstr (spchar)
			    call pargstr ("xcevel")
			    call pargstr (spchar)
			    call pargstr ("xcever")
			    call pargstr (spchar)
			    call pargstr ("xcer")
			}
		call fprintf(logfd[j],"%s%8.8s%s%6.6s%s%1.1s%s%2.2s%s%2.2s")
		    call pargstr (spchar)
		    call pargstr ("velocity")
		    call pargstr (spchar)
		    call pargstr ("velerr")
		    call pargstr (spchar)
		    call pargstr ("E")
		    call pargstr (spchar)
		    call pargstr ("nl")
		    call pargstr (spchar)
		    call pargstr ("nf")
		do i = 1, nref {
		    call sprintf (tstring,16,"lin%02dvel")
			call pargi (i)
		    call fprintf (logfd[j],"%s%8s")
			call pargstr (spchar)
			call pargstr (tstring)
		    }
		call fprintf(logfd[j], "\n")

		call fprintf(logfd[j],"%32.32s%s%8.8s%s%16.16s")
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		call fprintf(logfd[j],"%s%13.13s%s%8.8s%s%6.6s")
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		call fprintf(logfd[j],"%s%8.8s%s%6.6s%s%5.5s")
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		call fprintf(logfd[j],"%s%8.8s%s%6.6s%s%1.1s%s%2.2s%s%2.2s")
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		do i = 1, nref {
		    call fprintf (logfd[j],"%s%8.8s")
			call pargstr (spchar)
			call pargstr (uscore)
		    }
		call fprintf(logfd[j], "\n")
		}
	    }
	else if (rmode == 4 || rmode == 8) {
	    do j = 1, nlogfd {
		call fprintf(logfd[j],"%-32.32s%s%8s%s%-16.16s")
		    call pargstr ("specid")
		    call pargstr (spchar)
		    call pargstr ("instrume")
		    call pargstr (spchar)
		    call pargstr ("title")
		call fprintf(logfd[j],"%s%-11.11s%s%-10.10s%s%-5.5s%s%-5.5s")
		    call pargstr (spchar)
		    call pargstr ("ra")
		    call pargstr (spchar)
		    call pargstr ("dec")
		    call pargstr (spchar)
		    call pargstr ("az")
		    call pargstr (spchar)
		    call pargstr ("alt")
		call fprintf(logfd[j],"%s%-13.13s%s%6.6s")
		    call pargstr (spchar)
		    call pargstr ("Julian Date")
		    call pargstr (spchar)
		    call pargstr ("exposure")
		if (rmode == 4) {
		    call fprintf(logfd[j],"%s%-8.8s%s%-6.6s%s%-8.8s%s%-6.6s%s%-5.5s")
			call pargstr (spchar)
			call pargstr ("emvel")
			call pargstr (spchar)
			call pargstr ("emerr")
			call pargstr (spchar)
			call pargstr ("xcvel")
			call pargstr (spchar)
			call pargstr ("xcerr")
			call pargstr (spchar)
			call pargstr ("xcr")
		    call fprintf(logfd[j],"%s%8.8s%s%6.6s")
			call pargstr (spchar)
			call pargstr ("velocity")
			call pargstr (spchar)
			call pargstr ("velerr")
		    }
		call fprintf(logfd[j],"%s%2.2s%s%2.2s")
		    call pargstr (spchar)
		    call pargstr ("nl")
		    call pargstr (spchar)
		    call pargstr ("nf")
		do i = 1, nref {
		    if (rmode == 8) {
			call fprintf (logfd[j],"%swlrest%02d%swlshft%02d")
			    call pargstr (spchar)
			    call pargi (i)
			    call pargstr (spchar)
			    call pargi (i)
			}
		    else if (rmode == 9) {
			call fprintf (logfd[j],"%swlshft%02d ")
			    call pargstr (spchar)
			    call pargi (i)
			}
		    else if (rmode == 11) {
			call fprintf (logfd[j],"%spxshft%02d")
			    call pargstr (spchar)
			    call pargi (i)
			}
		    else {
			call fprintf (logfd[j],"%slinvel%02d")
			    call pargstr (spchar)
			    call pargi (i)
			}
		    call fprintf (logfd[j],"%slerr%02d%slht%02d    %slwd%02d%sleqw%02d")
			call pargstr (spchar)
			call pargi (i)
			call pargstr (spchar)
			call pargi (i)
			call pargstr (spchar)
			call pargi (i)
			call pargstr (spchar)
			call pargi (i)
		    }
		call fprintf(logfd[j], "\n")
		}
	    do j = 1, nlogfd {
		call fprintf(logfd[j],"%32.32s%s%8.8s%s%16.16s")
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		call fprintf(logfd[j],"%s%11.11s%s%10.10s%s%5.5s%s%5.5s")
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		call fprintf(logfd[j],"%s%13.13s%s%6.6s")
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		if (rmode == 4) {
		    call fprintf(logfd[j],"%s%8.8s%s%6.6s%s%8.8s%s%6.6s%s%5.5s")
			call pargstr (spchar)
			call pargstr (uscore)
			call pargstr (spchar)
			call pargstr (uscore)
			call pargstr (spchar)
			call pargstr (uscore)
			call pargstr (spchar)
			call pargstr (uscore)
			call pargstr (spchar)
			call pargstr (uscore)
		    call fprintf(logfd[j],"%s%8.8s%s%6.6s")
			call pargstr (spchar)
			call pargstr (uscore)
			call pargstr (spchar)
			call pargstr (uscore)
		    }
		call fprintf(logfd[j],"%s%2.2s%s%2.2s")
		    call pargstr (spchar)
		    call pargstr (uscore)
		    call pargstr (spchar)
		    call pargstr (uscore)
		do i = 1, nref {
		    if (rmode == 9 || rmode == 11) {
			call fprintf (logfd[j],"%s%8.8s")
			    call pargstr (spchar)
			    call pargstr (uscore)
			}
		    else {
			call fprintf (logfd[j],"%s%8.8s%s%6.6s%s%9.9s%s%5.5s%s%6.6s")
			    call pargstr (spchar)
			    call pargstr (uscore)
			    call pargstr (spchar)
			    call pargstr (uscore)
			    call pargstr (spchar)
			    call pargstr (uscore)
			    call pargstr (spchar)
			    call pargstr (uscore)
			    call pargstr (spchar)
			    call pargstr (uscore)
			}
		    }
		call fprintf(logfd[j], "\n")
		}
	    }


end

# Aug 12 1992	Correctly print z, not 1+z for fit velocities
# Dec  2 1993	Print spectrum number if multispec file

# Apr  8 1993	Set speed of light locally

# Apr 13 1994	Remove unused variables k0, k1 and rlim
# Apr 22 1994	Remove unused variable gwidth
# Apr 25 1994	Declare month as char
# May 17 1994	Add second option for single-line output format
# Jun 15 1994	Add third output option for per-line velocities
# Aug  3 1994	Change common and header from fquot to rvsao
# Aug 10 1994	Fix ut time
# Aug 17 1994	Add weight per line for mode 1 report
# Aug 22 1994	Don't add weight if zero

# Feb  9 1995	Give 2 decimal places for all velocities
# Feb 15 1995	Add heliocentric vel. correction to individual line velocities
# Apr  3 1995	Add fourth output option for single-line per-line velocities
# Apr  5 1995	Add sky coordinates, alt/az and exposure time to 4th option
# Apr 10 1995	Fix alt/az
# May 15 1995	Change all sz_fname to sz_pathname, which is longer
# Jul 13 1995	Get Julian Date from JULDATE instead of JULDAY
# Jul 13 1995	Get UT from JULDATE
# Jul 19 1995	Handle INDEF values for SPVEL and SPXVEL
# Sep 21 1995	Handle INDEF value for SPEVEL

# Jan 15 1997	Add HDJ to JULDATE arguments
# Feb 12 1997	Add modes 5 and 6 to plot emission line template velocity
# May  2 1997	Always test against dindef, not INDEFD
# May  6 1997	Print messages if no position or no observation date
# May 19 1997	Add height and width to mode 4 report
# May 19 1997	Use CORTEMP parameter instead of inline template name
# May 21 1997	Reinitialize all line parameter arrays for each spectrum
# May 22 1997	If CORTEMP is null string, use best template
# Sep 25 1997	Add null print line so this works in Digital Unix
# Sep 25 1997	In mode 1, put file name on separate line
# Oct  1 1997	Print rejection code in mode 1 if line is dropped from fit
# Oct  6 1997	Fix bug in mode 1 BCV flag code
# Dec 17 1997   Change order of date from dd-mmm-yyyy to yyyy-mmm-dd
# Dec 17 1997   Use EQUINOX if it is present instead of EPOCH

# May 21 1999	Read DATE if DATE-OBS is no found
# Jul 22 1999	Put _ in null strings
# Jul 23 1999	Add report mode 5, same as 4, but with tabs
# Jul 23 1999	Add emrshead() to print report heading

# Jun  8 2000	Add equivalent width error to new report modes 0 and 7
# Oct  3 2000	Add Mode 8 to print wavelength shifts

# Jan 30 2001	Fix bug in Mode 8 printed wavelength 
# Aug  7 2001	Add Mode 10 to print only line information

# May 11 2005	Print 3 decimal places in output mode 9 shifts
# May 19 2005	Add mode 11 to print line shifts in pixels
# Jul 14 2005	Initialize ibr and ibl
# Mar 18 2008	Add mode 12 for high precision echelle velocities
# May 30 2008	Use strings more efficiently for IRAF Solaris limits

# May 20 2009	Return immediately if not logging results

# Mar 27 2015	Link to header and common files in lib/