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
|
include <mach.h>
include <imhdr.h>
include "vt.h"
# MERGE -- Put together all appropriate daily grams to produce a full
# carrington rotation map. This is done both for the average input images
# and for the absolute value input images. The output of the program is
# 4 images, average image, absolute value image, weight image, ratio of
# first image to second image.
procedure t_merge()
char mergelist[SZ_FNAME] # list of images to be merged
int wavelength, listfd
char inputimage[SZ_FNAME]
pointer inputim
pointer immap()
int imgeti(), open(), fscan()
errchk immap, open
begin
# Get the image name file from the cl and open it.
call clgstr ("mergelist", mergelist, SZ_FNAME)
listfd = open (mergelist, READ_ONLY, TEXT_FILE)
# Get the wavelength from the first image in the mergelist.
if (fscan (listfd) != EOF) {
call gargwrd (inputimage, SZ_FNAME)
inputim = immap (inputimage, READ_ONLY, 0)
wavelength = imgeti (inputim, "WV_LNGTH")
call close (listfd)
} else {
call error (0, "No images in 'mergelist'")
call close (listfd)
return
}
if (wavelength == 8688)
call mergem (mergelist, wavelength)
else
call mergeh (mergelist, wavelength)
end
# MERGEM -- MERGE Magnetograms.
procedure mergem (mergelist, wavelength)
char mergelist[SZ_FNAME] # list of images to be merged
int wavelength # wavelength of images
pointer outputim, outw, outa, outr
pointer outptr, outwptr, outaptr, outrptr
char outputimage[SZ_FNAME], outweight[SZ_FNAME]
char outabs[SZ_FNAME], outratio[SZ_FNAME]
real longout, weight_tbl[SZ_WTBL], bzeroave
int i, mapmonth, mapday, mapyear
real clgetr()
int clgeti()
pointer immap(), imps2r()
errchk immap, imps2r
begin
# Get parameters from the cl.
# Output images.
call clgstr ("outputimage", outputimage, SZ_FNAME)
call clgstr ("outweight", outweight, SZ_FNAME)
call clgstr ("outabs", outabs, SZ_FNAME)
call clgstr ("outratio", outratio, SZ_FNAME)
# Longitude of center of output Carrington rotation map.
longout = clgetr ("longout")
# Month, day, and year of the center of the output map.
mapmonth = clgeti ("mapmonth")
mapday = clgeti ("mapday")
mapyear = clgeti ("mapyear")
# Open output image.
outputim = immap (outputimage, NEW_IMAGE, 0)
# Define some parameters for the output images.
IM_NDIM(outputim) = 2
IM_LEN(outputim, 1) = DIM_XCARMAP
IM_LEN(outputim, 2) = DIM_SQUAREIM
IM_PIXTYPE(outputim) = TY_REAL
# Open the rest of the output images.
outw = immap (outweight, NEW_COPY, outputim)
outa = immap (outabs, NEW_COPY, outputim)
outr = immap (outratio, NEW_COPY, outputim)
# Map the outputimages into memory.
outptr = imps2r (outputim, 1, DIM_XCARMAP, 1, DIM_SQUAREIM)
outwptr = imps2r (outw, 1, DIM_XCARMAP, 1, DIM_SQUAREIM)
outaptr = imps2r (outa, 1, DIM_XCARMAP, 1, DIM_SQUAREIM)
outrptr = imps2r (outr, 1, DIM_XCARMAP, 1, DIM_SQUAREIM)
# Create weight table.
do i = 1,SZ_WTBL
weight_tbl[i] = (cos((real(i-91)+.5)*3.1415926/180.))**4
call mmall (mergelist, Memr[outptr], Memr[outwptr], Memr[outaptr],
outputim, outw, outa, outr, wavelength, weight_tbl, longout,
mapmonth, mapday, mapyear, bzeroave)
# Fill the ratio image.
call imratio (Memr[outptr],Memr[outaptr],Memr[outrptr],DIM_XCARMAP,
DIM_SQUAREIM)
# Write some information out to the image headers.
call imaddr (outputim, "AV_BZERO", bzeroave)
call imaddi (outputim, "WV_LNGTH", wavelength)
call imaddr (outw, "AV_BZERO", bzeroave)
call imaddr (outw, "WV_LNGTH", wavelength)
call imaddb (outw, "WEIGHTS", TRUE)
call imaddr (outa, "AV_BZERO", bzeroave)
call imaddr (outr, "AV_BZERO", bzeroave)
call imaddr (outa, "WV_LNGTH", wavelength)
call imaddr (outr, "WV_LNGTH", wavelength)
call imaddb (outa, "ABS_VALU", TRUE)
call imaddb (outr, "POLARITY", TRUE)
# Weight the data image and the abs image.
call imratio (Memr[outptr],Memr[outwptr],Memr[outptr],DIM_XCARMAP,
DIM_SQUAREIM)
call imratio (Memr[outaptr],Memr[outwptr],Memr[outaptr],DIM_XCARMAP,
DIM_SQUAREIM)
# Close images
call imunmap (outputim)
call imunmap (outw)
call imunmap (outa)
call imunmap (outr)
end
# MERGEH -- MERGE Helium 10830 grams.
procedure mergeh (mergelist, wavelength)
char mergelist[SZ_FNAME] # list of images to merge
int wavelength # wavelength of observation
pointer outputim, outw
pointer outptr, outwptr
char outputimage[SZ_FNAME], outweight[SZ_FNAME]
real longout, weight_tbl[SZ_WTBL], bzeroave
int i, mapmonth, mapday, mapyear
real clgetr()
int clgeti()
pointer immap(), imps2r()
errchk immap, imps2r
begin
# Get parameters from the cl.
# Output images.
call clgstr ("outputimage", outputimage, SZ_FNAME)
call clgstr ("outweight", outweight, SZ_FNAME)
# Longitude of center of output Carrington rotation map.
longout = clgetr ("longout")
# Month, day, and year of the center of the output map.
mapmonth = clgeti ("mapmonth")
mapday = clgeti ("mapday")
mapyear = clgeti ("mapyear")
# Open output image.
outputim = immap (outputimage, NEW_IMAGE, 0)
# Define some parameters for the output images.
IM_NDIM(outputim) = 2
IM_LEN(outputim, 1) = DIM_XCARMAP
IM_LEN(outputim, 2) = DIM_SQUAREIM
IM_PIXTYPE(outputim) = TY_REAL
# Open the other output image.
outw = immap (outweight, NEW_COPY, outputim)
# Map the outputimages into memory.
outptr = imps2r (outputim, 1, DIM_XCARMAP, 1, DIM_SQUAREIM)
outwptr = imps2r (outw, 1, DIM_XCARMAP, 1, DIM_SQUAREIM)
# Create weight table.
do i = 1,SZ_WTBL
weight_tbl[i] = (cos((real(i-91)+.5)*3.1415926/180.))**4
call mhall (mergelist, Memr[outptr], Memr[outwptr], outputim,
outw, wavelength, weight_tbl, longout, mapmonth,
mapday, mapyear, bzeroave)
# Write some information out to the image headers.
call imaddr (outputim, "AV_BZERO", bzeroave)
call imaddi (outputim, "WV_LNGTH", wavelength)
call imaddr (outw, "AV_BZERO", bzeroave)
call imaddr (outw, "WV_LNGTH", wavelength)
call imaddb (outw, "WEIGHTS", TRUE)
# Weight the data image.
call imratio (Memr[outptr],Memr[outwptr],Memr[outptr],DIM_XCARMAP,
DIM_SQUAREIM)
# Close images.
call imunmap (outputim)
call imunmap (outw)
end
# MMALL -- Merge Magnetograms ALL.
# Map in each input image, weight it, figure out where it goes
# and add it to the output image.
procedure mmall (mergelist, outarray, outarrayw, outarraya, outputim,
outw, outa, outr, wavelength, weight_tbl, longout, mapmonth, mapday,
mapyear, bzeroave)
char mergelist[SZ_FNAME] # list of images to be merged
int wavelength # wavelength of observations
real outarray[DIM_XCARMAP, DIM_SQUAREIM] # output data array
real outarrayw[DIM_XCARMAP, DIM_SQUAREIM] # output weights array
real outarraya[DIM_XCARMAP, DIM_SQUAREIM] # output absolute value array
pointer inputim # pointer to input image
pointer outputim # pointer to output image
pointer outw # pointer to weight image
pointer outa # pointer to abs value image
pointer outr # pointer to ratio image
int mapmonth, mapday, mapyear # date of output map
real weight_tbl[SZ_WTBL] # weight table
real longout # longitude of map center
real bzeroave # average b-zero for map
char inputimage[SZ_FNAME], inweight[SZ_FNAME], inabs[SZ_FNAME]
pointer inw, ina, inptr, inwptr, inaptr
int listfd, month, day, year, count
real longin, bzero, bzerosum
int obsdate, temp, i, j
char ltext[SZ_LINE]
int open(), fscan(), imgeti()
real imgetr()
pointer immap(), imgs2i(), imgs2s()
errchk open, immap, imgs2i, imgs2s
begin
count = 0
bzerosum = 0.0
listfd = open (mergelist, READ_ONLY, TEXT_FILE)
# Zero the output images.
do i = 1, DIM_XCARMAP {
do j = 1, DIM_SQUAREIM {
outarray[i,j] = 0.0
outarrayw[i,j] = 0.0
outarraya[i,j] = 0.0
}
}
# Get inputimages from the mergelist until they are all used up.
while (fscan (listfd) != EOF) {
call gargwrd (inputimage, SZ_FNAME)
# Get absolute value image.
if(fscan (listfd) != EOF)
call gargwrd (inabs, SZ_FNAME)
else
call error (0, "wrong number of file names in mergelist")
# Get weight image.
if(fscan (listfd) != EOF)
call gargwrd (inweight, SZ_FNAME)
else
call error (0, "wrong number of file names in mergelist")
# Open input image, its corresponding weight map, and its
# corresponding absolute value map.
inputim = immap (inputimage, READ_ONLY, 0)
inw = immap (inweight, READ_ONLY, 0)
ina = immap (inabs, READ_ONLY, 0)
bzero = imgetr (inputim, "B_ZERO")
bzerosum = bzerosum + bzero
longin = imgetr (inputim, "L_ZERO")
obsdate = imgeti (inputim, "OBS_DATE")
# Check to see that the date is same on the three input images.
temp = imgeti (inw, "OBS_DATE")
if (temp != obsdate) {
call eprintf ("ERROR: date on weight image differs from that ")
call eprintf ("on data image!\n")
break
}
temp = imgeti (ina, "OBS_DATE")
if (temp != obsdate) {
call eprintf ("ERROR: date on abs image differs from that ")
call eprintf ("on data image!\n")
break
}
# Decode month, day, year.
month = obsdate/10000
day = obsdate/100 - 100 * (obsdate/10000)
year = obsdate - 100 * (obsdate/100)
# Pack a name for this date and longitude and then put them out
# into the outputimages' headers.
count = count + 1
call sprintf (ltext, SZ_LINE, "DATE%04d")
call pargi (count)
call imaddi (outputim, ltext, obsdate)
call imaddi (outw, ltext, obsdate)
call imaddi (outa, ltext, obsdate)
call imaddi (outr, ltext, obsdate)
call sprintf (ltext, SZ_LINE, "LONG%04d")
call pargi (count)
call imaddr (outputim, ltext, longin)
call imaddr (outw, ltext, longin)
call imaddr (outa, ltext, longin)
call imaddr (outr, ltext, longin)
# Map the inputimage, the weight map, and abs_image into memory.
inptr = imgs2i (inputim, 1, DIM_SQUAREIM, 1, DIM_SQUAREIM)
inwptr = imgs2s (inw, 1, DIM_SQUAREIM, 1, DIM_SQUAREIM)
inaptr = imgs2i (ina, 1, DIM_SQUAREIM, 1, DIM_SQUAREIM)
# Weight this image and add it to the output image.
call addmweight (Memi[inptr],Mems[inwptr],Memi[inaptr],outarray,
outarrayw, outarraya, weight_tbl, longin, longout,
month, day, year, mapmonth, mapday, mapyear)
# Close this input image.
call imunmap (inputim)
call imunmap (inw)
call imunmap (ina)
} # end of do loop on input images
bzeroave = bzerosum/real(count)
call close (listfd)
end
# MHALL -- Merge Heliumgrams ALL.
# Map in each input image, weight it, figure out where it goes
# and add it to the output image.
procedure mhall (mergelist, outarray, outarrayw, outputim,
outw, wavelength, weight_tbl, longout, mapmonth, mapday,
mapyear, bzeroave)
char mergelist[SZ_FNAME] # list of images to be merged
int wavelength # wavelength of observations
real outarray[DIM_XCARMAP, DIM_SQUAREIM] # output data array
real outarrayw[DIM_XCARMAP, DIM_SQUAREIM] # output weights array
pointer inputim # pointer to input image
pointer outputim # pointer to output image
pointer outw # pointer to weight image
int mapmonth, mapday, mapyear # date of output map
real weight_tbl[SZ_WTBL] # weight table
real longout # longitude of map center
real bzeroave # average b-zero for map
char inputimage[SZ_FNAME], inweight[SZ_FNAME]
pointer inw, inptr, inwptr
int listfd, month, day, year, count
real longin, bzero, bzerosum
int obsdate, temp, i, j
char ltext[SZ_LINE]
real imgetr()
int open(), fscan(), imgeti()
pointer immap(), imgs2i(), imgs2s()
errchk open, immap, imgs2i, imgs2s
begin
count = 0
bzerosum = 0.0
listfd = open (mergelist, READ_ONLY, TEXT_FILE)
# Zero the output images.
do i = 1, DIM_XCARMAP {
do j = 1, DIM_SQUAREIM {
outarray[i,j] = 0.0
outarrayw[i,j] = 0.0
}
}
# Get inputimages from the mergelist until they are all used up.
while (fscan (listfd) != EOF) {
call gargwrd (inputimage, SZ_FNAME)
# Get weight image.
if (fscan (listfd) != EOF)
call gargwrd (inweight, SZ_FNAME)
else
call error (0, "wrong number of file names in mergelist")
# Open input image, its corresponding weight map, and its
# corresponding absolute value map.
inputim = immap (inputimage, READ_ONLY, 0)
inw = immap (inweight, READ_ONLY, 0)
bzero = imgetr (inputim, "B_ZERO")
bzerosum = bzerosum + bzero
longin = imgetr (inputim, "L_ZERO")
obsdate = imgeti (inputim, "OBS_DATE")
# Check to see that the date is same on the three input images.
temp = imgeti (inw, "OBS_DATE")
if (temp != obsdate) {
call eprintf ("ERROR: date on weight image differs from that ")
call eprintf ("on data image!\n")
break
}
# Decode month, day, year.
month = obsdate/10000
day = obsdate/100 - 100 * (obsdate/10000)
year = obsdate - 100 * (obsdate/100)
# Pack a name for this date and longitude and then put them out
# into the outputimages' headers.
count = count + 1
call sprintf (ltext, SZ_LINE, "DATE%04d")
call pargi (count)
call imaddi (outputim, ltext, obsdate)
call imaddi (outw, ltext, obsdate)
call sprintf (ltext, SZ_LINE, "LONG%04d")
call pargi (count)
call imaddr (outputim, ltext, longin)
call imaddr (outw, ltext, longin)
# Map the inputimage, the weight map, and abs_image into memory.
inptr = imgs2i (inputim, 1, DIM_SQUAREIM, 1, DIM_SQUAREIM)
inwptr = imgs2s (inw, 1, DIM_SQUAREIM, 1, DIM_SQUAREIM)
# Weight this image and add it to the output image.
call addhweight (Memi[inptr], Mems[inwptr], outarray, outarrayw,
weight_tbl, longin, longout, month, day, year, mapmonth,
mapday, mapyear)
# Close this input image.
call imunmap (inputim)
call imunmap (inw)
} # end of do loop on input images
bzeroave = bzerosum/real(count)
call close (listfd)
end
# ADDMWEIGHT -- Weight input image by cos(longitude - (L-L0))**4, and add
# it to the output image in the proper place.
procedure addmweight (inim, inwim, inaim, outim, outwim, outaim,
weight_tbl, longin, longout, month, day, year, mapmonth, mapday,
mapyear)
int inim[DIM_SQUAREIM, DIM_SQUAREIM] # input image
short inwim[DIM_SQUAREIM, DIM_SQUAREIM] # input image weights
int inaim[DIM_SQUAREIM, DIM_SQUAREIM] # input absolute image
real outim[DIM_XCARMAP, DIM_SQUAREIM] # outputimage
real outwim[DIM_XCARMAP, DIM_SQUAREIM] # output image weights
real outaim[DIM_XCARMAP, DIM_SQUAREIM] # output absolute image
int month, day, year # date of input image
int mapmonth, mapday, mapyear # date of output image
real weight_tbl[DIM_SQUAREIM] # weight table
real longin, longout # longitudes of images
int p1offset, p2offset, firstpix, lastpix, column, row
int offset, datein, dateout, temp, temp2
int d1900()
begin
# Translate the two dates into julian day numbers to make comparisons
# simpler.
datein = d1900 (month, day, year)
dateout = d1900 (mapmonth, mapday, mapyear)
# Figure out the pixel offset between the first pixel of the input
# image and the first pixel of ther output image.
# Actually, there may be two pixel offsets for a particular image
# corresponding to the correct position of the image and the 360
# degree offset position.
p1offset = mod(abs(int(longin - longout + .5)), 360) # This is one.
p2offset = 360 - p1offset # This is the other.
# Determine which side of the output image center is each of these
# offsets.
if (datein > dateout) {
if (longout > 180) {
if (((longin >= longout) && (longin <= 360)) ||
(longin <= mod((longout + 180.),360.))) {
if (p1offset < 180)
offset = p2offset
else
offset = p1offset
} else {
if (p1offset >= 180)
offset = p2offset
else
offset = p1offset
}
} else {
if ((longin >= longout) && (longin <= (longout + 180))) {
if (p1offset <= 180)
offset = p2offset
else
offset = p1offset
} else {
if (p1offset >= 180)
offset = p2offset
else
offset = p1offset
}
}
} else {
if (longout < 180) {
if (((longin >= (180 + longout)) && (longin <= 360)) ||
(longin <= longout)) {
if (p1offset < 180)
offset = p2offset
else
offset = p1offset
} else {
if (p1offset >= 180)
offset = p2offset
else
offset = p1offset
}
} else {
if ((longin < longout) && (longin > (longout - 180))) {
if (p1offset < 180)
offset = p2offset
else
offset = p1offset
} else {
if (p1offset >= 180)
offset = p2offset
else
offset = p1offset
}
}
}
# Make sure the sign is right
if (datein > dateout)
offset = -offset
# Check for the case that the two longitudes are equal.
if (longin == longout) {
if (abs(datein - dateout) <= 1) {
offset = 0
} else {
call eprintf ("input day too far from center of output map\n")
return
}
}
# Check for the case that the two dates are equal.
if (datein == dateout)
offset = longin - longout
# If the offset is too large then do not use this image.
if (abs(offset) > 240) {
call eprintf ("input day too far from center of output map\n")
return
}
# Determine what part, if not all, of the input image will lie on the
# output image.
firstpix = 1
if (offset < -90)
firstpix = abs(offset+90)
lastpix = DIM_SQUAREIM
if (offset > 90)
lastpix = 180 - (offset - 90)
# Do all 180 columns in the image.
if (offset <= 0)
temp = 91
else
temp = 90
do column = firstpix,lastpix {
do row = 1, DIM_SQUAREIM {
temp2 = column + temp + offset
outim[temp2,row] = outim[temp2, row] +
inim[column, row] * weight_tbl[column]
outwim[temp2,row] = outwim[temp2, row] +
inwim[column, row] * weight_tbl[column]
outaim[temp2,row] = outaim[temp2, row] +
inaim[column, row] * weight_tbl[column]
}
}
end
# ADDHWEIGHT -- Weight input image by cos(longitude - (L-L0))**4, and add
# it to the output image in the proper place. (For 10830 grams)
procedure addhweight (inim, inwim, outim, outwim, weight_tbl, longin, longout,
month, day, year, mapmonth, mapday, mapyear)
int inim[DIM_SQUAREIM, DIM_SQUAREIM] # input image
short inwim[DIM_SQUAREIM, DIM_SQUAREIM] # input image weights
real outim[DIM_XCARMAP, DIM_SQUAREIM] # outputimage
real outwim[DIM_XCARMAP, DIM_SQUAREIM] # output image weights
int month, day, year # date of input image
int mapmonth, mapday, mapyear # date of output image
real weight_tbl[DIM_SQUAREIM] # weight table
real longin, longout # longitudes of images
int p1offset, p2offset, firstpix, lastpix, column, row
int offset, datein, dateout, temp, temp2
int d1900()
begin
# Translate the two dates into julian day numbers to make comparisons
# simpler.
datein = d1900 (month, day, year)
dateout = d1900 (mapmonth, mapday, mapyear)
# Figure out the pixel offset between the first pixel of the input
# image and the first pixel of ther output image.
# Actually, there may be two pixel offsets for a particular image
# corresponding to the correct position of the image and the 360
# degree offset position.
p1offset = mod(abs(int(longin - longout + .5)), 360) # this is one.
p2offset = 360 - p1offset # this is the other.
# Determine which side of the output image center is each of these
# offsets.
if (datein > dateout) {
if (longout > 180) {
if (((longin >= longout) && (longin <= 360)) ||
(longin <= mod((longout + 180.),360.))) {
if (p1offset < 180)
offset = p2offset
else
offset = p1offset
} else {
if (p1offset >= 180)
offset = p2offset
else
offset = p1offset
}
} else {
if ((longin >= longout) && (longin <= (longout + 180))) {
if (p1offset <= 180)
offset = p2offset
else
offset = p1offset
} else {
if (p1offset >= 180)
offset = p2offset
else
offset = p1offset
}
}
} else {
if (longout < 180) {
if (((longin >= (180 + longout)) && (longin <= 360)) ||
(longin <= longout)) {
if (p1offset < 180)
offset = p2offset
else
offset = p1offset
} else {
if (p1offset >= 180)
offset = p2offset
else
offset = p1offset
}
} else {
if ((longin < longout) && (longin > (longout - 180))) {
if (p1offset < 180)
offset = p2offset
else
offset = p1offset
} else {
if (p1offset >= 180)
offset = p2offset
else
offset = p1offset
}
}
}
# Make sure the sign is right.
if (datein > dateout)
offset = -offset
# Check for the case that the two longitudes are equal.
if (longin == longout) {
if (abs(datein - dateout) <= 1) {
offset = 0
} else {
call eprintf ("Input day too far from center of output map.\n")
return
}
}
# Check for the case that the two dates are equal.
if (datein == dateout)
offset = longin - longout
# If the offset is too large then do not use this image.
if (abs(offset) > 240) {
call eprintf ("input day too far from center of output map\n")
return
}
# Determine what part, if not all, of the input image will lie on the
# output image.
firstpix = 1
if (offset < -90)
firstpix = abs(offset+90)
lastpix = DIM_SQUAREIM
if (offset > 90)
lastpix = 180 - (offset - 90)
# Do all 180 columns in the image.
if (offset <= 0)
temp = 91
else
temp = 90
do column = firstpix, lastpix {
do row = 1, DIM_SQUAREIM {
temp2 = column + temp + offset
outim[temp2,row] = outim[temp2, row] +
inim[column, row] * weight_tbl[column]
outwim[temp2,row] = outwim[temp2, row] +
inwim[column, row] * weight_tbl[column]
}
}
end
|