after_fctrans.cc 51.6 KB
Newer Older
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1
#ifdef HAVE_CONFIG_H
2
3
4
#include "config.h"
#endif

Uwe Schulzweida's avatar
Uwe Schulzweida committed
5
#ifndef _DMEMORY_H
Uwe Schulzweida's avatar
Uwe Schulzweida committed
6
#include "dmemory.h"
Uwe Schulzweida's avatar
Uwe Schulzweida committed
7
8
#endif

9
10

#include "cdo_int.h"
11
12


Uwe Schulzweida's avatar
Uwe Schulzweida committed
13
14
#ifdef SX
#define  NFFT  1024
Uwe Schulzweida's avatar
Uwe Schulzweida committed
15
#else
Uwe Schulzweida's avatar
Uwe Schulzweida committed
16
#define  NFFT     8
Uwe Schulzweida's avatar
Uwe Schulzweida committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#endif

#ifndef  M_SQRT2
#define  M_SQRT2     1.41421356237309504880
#endif

#define  QUA  0.25
#define  QT5  0.559016994374947

#define  S36  0.587785252292473
#define  S60  0.866025403784437
#define  S72  0.951056516295154

#define  SQ2  0.707106781186547524401

#define  D60  (S60+S60)


35
long get_nfft(void)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
36
{
37
  return (long) NFFT;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
38
39
40
}


41
void fft_set(double *trigs, long *ifax, long n)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
42
{
43
44
45
46
47
  long j, len = n;
  long nhl = n / 2;
  double del = 4.0*asin(1.0) / n;
  double angle;
  for ( long k = 0; k < nhl; k++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
48
49
50
51
52
53
    {
      angle = k * del;
      trigs[2*k  ] = cos(angle);
      trigs[2*k+1] = sin(angle);
    }  

54
55
  long nfax = 0;
  for ( long k = 0; k < 9; ++k ) ifax[k] = 0;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
56
57
58
59
60
61
62
63
64
65
66
67

  ifax[9] = n;

  if    (n % 8 == 0)  { ifax[++nfax] = 8; n /= 8; }
  while (n % 6 == 0)  { ifax[++nfax] = 6; n /= 6; }
  while (n % 5 == 0)  { ifax[++nfax] = 5; n /= 5; }
  while (n % 4 == 0)  { ifax[++nfax] = 4; n /= 4; }
  while (n % 3 == 0)  { ifax[++nfax] = 3; n /= 3; }
  if    (n % 2 == 0)  { ifax[++nfax] = 2; n /= 2; }

  ifax[0] = nfax;

Uwe Schulzweida's avatar
Uwe Schulzweida committed
68
#if defined(CRAY)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
69
70
#pragma _CRI novector
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
71
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
72
73
#pragma vdir novector
#endif
Uwe Schulzweida's avatar
Uwe Schulzweida committed
74
#if defined(__uxp__)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
75
76
#pragma loop scalar
#endif
77
  for ( long k = 0; k < nfax / 2; k++ )
Uwe Schulzweida's avatar
Uwe Schulzweida committed
78
79
80
81
82
83
84
85
    {
      j = ifax[k + 1];
      ifax[k + 1] = ifax[nfax - k];
      ifax[nfax - k] = j;
    }

  if ( n > 8 )
    {
86
      fprintf(stderr, "FFT does not work with len=%ld (n=%ld)!\n", len, n);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
87
88
89
90
      exit(1);
    }
}

Uwe Schulzweida's avatar
cleanup    
Uwe Schulzweida committed
91
static
Uwe Schulzweida's avatar
Uwe Schulzweida committed
92
int rpassc(double *a, double *b, double *c, double *d, double *trigs,
93
94
	   long inc1, long inc2, long inc3, long inc4,
	   long lot, long n, long ifac, long la)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
{
  /*
     rpassc' - performs one pass through data as part;
     of multiple real fft (fourier synthesis) routine;

     a is first real input vector
     b is equivalent to a + la * inc1
     c is first real output vector
     d is equivalent to c + ifac * la * inc2
     trigs  is a precalculated list of sines & cosines
     inc1 is the addressing increment for a;
     inc2 is the addressing increment for c;
     inc3 is the increment between input vectors a;
     inc4 is the increment between output vectors c;
     lot is the number of vectors;
     n is the length of the vectors;
     ifac is the current factor of n;
     la is the product of previous factors;
     ierr is an error indicator:;
     0 - pass completed without error;
     2 - ifac not catered for;
     3 - ifac only catered for if la=n/ifac;
   */

119
120
121
122
123
124
125
126
127
128
  long i0, i1, i2, i3, i4, i5, i6, i7;
  long j0, j1, j2, j3, j4, j5, j6, j7;
  long ia, ib, ic, id, ie, iF;
  long ja, jb, jc, jd, je, jf;
  long i, j, k, l, m, ijk;
  long ibase, jbase;
  long iink, jink;
  long jump;
  long kstop;
  long kb, kc, kd, ke, kf;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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

  double c1, c2, c3, c4, c5;
  double s1, s2, s3, s4, s5;
  double qqrt5;
  double ssin36;
  double ssin72;

  double a10, a11, a20, a21;
  double b10, b11, b20, b21;

  m = n / ifac;
  iink = la * inc1;
  jink = la * inc2;
  jump = (ifac - 1) * jink;
  kstop = (n - ifac) / (2 * ifac);
  ibase = 0;
  jbase = 0;

  switch (ifac)
    {
    case 2:
      {
	double a0m1, b0p1;

	i0 = j0 = 0;
	i1 = i0 + inc1 * (m + m - la);
	j1 = j0 + jink;
	if (la != m)
	  {
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
162
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    c[j0 + j] = a[i0 + i] + a[i1 + i];
		    c[j1 + j] = a[i0 + i] - a[i1 + i];
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	    i0 += iink;
	    iink += iink;
	    i1 -= iink;
	    ibase = 0;
	    jbase += jump;
	    jump += jump + jink;

	    if (i0 != i1)
	      {
		for (k = la; k <= kstop; k += la)
		  {
		    kb = k + k;
		    c1 = trigs[kb  ];
		    s1 = trigs[kb+1];
		    ibase = 0;
		    for (l = 0; l < la; ++l)
		      {
			i = ibase;
			j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
194
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
			for (ijk = 0; ijk < lot; ++ijk)
			  {
			    a0m1 = a[i0 + i] - a[i1 + i];
			    b0p1 = b[i0 + i] + b[i1 + i];

			    c[j0 + j] = a[i0 + i] + a[i1 + i];
			    d[j0 + j] = b[i0 + i] - b[i1 + i];
			    c[j1 + j] = c1 * a0m1 - s1 * b0p1;
			    d[j1 + j] = s1 * a0m1 + c1 * b0p1;
			    i += inc3;
			    j += inc4;
			  }
			ibase += inc1;
			jbase += inc2;
		      }
		    i0 += iink;
		    i1 -= iink;
		    jbase += jump;
		  }		/* End FORK */
		if (i0 > i1)
		  return 0;
	      }			/* End (i0 != i1) */
	    ibase = 0;
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
224
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    c[j0 + j] = a[i0 + i];
		    c[j1 + j] = -b[i0 + i];
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	else			/* (la != m) */
	  {
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
244
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    c[j0 + j] = 2.0 * (a[i0 + i] + a[i1 + i]);
		    c[j1 + j] = 2.0 * (a[i0 + i] - a[i1 + i]);
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	return 0;
      }

    case 3:
      {
	double afa1, a1p2, a1m2, a0mm, a0mp;
	double bfa1, b1p2, b1m2, b0mm, b0mp;

	i0 = j0 = 0;
	i1 = i0 + inc1 * (m + m - la);
	i2 = i1;
	j1 = j0 + jink;
	j2 = j1 + jink;

	if (la != m)
	  {
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
278
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    afa1 = a[i0 + i] - 0.5 * a[i1 + i];
		    bfa1 = S60 * b[i1 + i];

		    c[j0 + j] = a[i0 + i] + a[i1 + i];
		    c[j1 + j] = afa1 - bfa1;
		    c[j2 + j] = afa1 + bfa1;
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	    i0 += iink;
	    iink += iink;
	    i1 += iink;
	    i2 -= iink;
	    jbase += jump;
	    jump += jump + jink;

	    if (i0 != i2)
	      {
		for (k = la; k <= kstop; k += la)
		  {
		    kb = k + k;
		    kc = kb + kb;
		    c1 = trigs[kb  ];
		    s1 = trigs[kb+1];
		    c2 = trigs[kc  ];
		    s2 = trigs[kc+1];
		    ibase = 0;
		    for (l = 0; l < la; ++l)
		      {
			i = ibase;
			j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
317
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
			for (ijk = 0; ijk < lot; ++ijk)
			  {
			    a1p2 = a[i0 + i] - 0.5 * (a[i1 + i] + a[i2 + i]);
			    b1m2 = b[i0 + i] - 0.5 * (b[i1 + i] - b[i2 + i]);
			    a1m2 = S60 * (a[i1 + i] - a[i2 + i]);
			    b1p2 = S60 * (b[i1 + i] + b[i2 + i]);

			    a0mm = a1p2 - b1p2;
			    a0mp = a1p2 + b1p2;
			    b0mm = b1m2 - a1m2;
			    b0mp = b1m2 + a1m2;

			    c[j0 + j] = a[i0 + i] + a[i1 + i] + a[i2 + i];
			    d[j0 + j] = b[i0 + i] + b[i1 + i] - b[i2 + i];
			    c[j1 + j] = c1 * a0mm - s1 * b0mp;
			    d[j1 + j] = s1 * a0mm + c1 * b0mp;
			    c[j2 + j] = c2 * a0mp - s2 * b0mm;
			    d[j2 + j] = s2 * a0mp + c2 * b0mm;
			    i += inc3;
			    j += inc4;
			  }
			ibase += inc1;
			jbase += inc2;
		      }
		    i0 += iink;
		    i1 += iink;
		    i2 -= iink;
		    jbase += jump;
		  }		/* End FORK */
		if (i0 > i2)
		  return 0;
	      }			/* End (i0 != i2) */
	    ibase = 0;
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
357
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    a0mp = 0.5 * a[i0 + i];
		    b0mp = S60 * b[i0 + i];

		    c[j0 + j] = a[i0 + i] + a[i1 + i];
		    c[j1 + j] = a0mp - a[i1 + i] - b0mp;
		    c[j2 + j] = a[i1 + i] - a0mp - b0mp;
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	else			/* (la != m) */
	  {
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
381
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    a0mp = 2.0 * a[i0 + i] - a[i1 + i];
		    b0mp = D60 * b[i1 + i];

		    c[j0 + j] = 2.0 * (a[i0 + i] + a[i1 + i]);
		    c[j1 + j] = a0mp - b0mp;
		    c[j2 + j] = a0mp + b0mp;
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	return 0;
      }

    case 4:
      {
	double a0m1, a0p2, a1p3, a0m2, a1m3, a0p2ma1p3, a0m2pb1p3, a0m2mb1p3;
	double b0p1, b0p2, b1p3, b0m2, b1m3, b0p2pa1m3, b0p2ma1m3, b0m2mb1m3;

	i0 = j0 = 0;
	i1 = i3 = i0 + inc1 * (m + m - la);
	i2 = i1 + inc1 * (m + m);
	j1 = j0 + jink;
	j2 = j1 + jink;
	j3 = j2 + jink;

	if (la != m)
	  {
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
420
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    a0p2 = a[i0 + i] + a[i2 + i];
		    a0m2 = a[i0 + i] - a[i2 + i];

		    c[j0 + j] = a0p2 + a[i1 + i];
		    c[j1 + j] = a0m2 - b[i1 + i];
		    c[j2 + j] = a0p2 - a[i1 + i];
		    c[j3 + j] = a0m2 + b[i1 + i];
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	    i0 += iink;
	    iink += iink;
	    i1 += iink;
	    i2 -= iink;
	    i3 -= iink;
	    jbase += jump;
	    jump += jump + jink;

	    if (i1 != i2)
	      {
		for (k = la; k <= kstop; k += la)
		  {
		    kb = k + k;
		    kc = kb + kb;
		    kd = kc + kb;
		    c1 = trigs[kb  ];
		    s1 = trigs[kb+1];
		    c2 = trigs[kc  ];
		    s2 = trigs[kc+1];
		    c3 = trigs[kd  ];
		    s3 = trigs[kd+1];
		    ibase = 0;
		    for (l = 0; l < la; ++l)
		      {
			i = ibase;
			j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
464
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
			for (ijk = 0; ijk < lot; ++ijk)
			  {
			    a0p2 = a[i0 + i] + a[i2 + i];
			    a0m2 = a[i0 + i] - a[i2 + i];
			    a1p3 = a[i1 + i] + a[i3 + i];
			    a1m3 = a[i1 + i] - a[i3 + i];
			    b0p2 = b[i0 + i] + b[i2 + i];
			    b0m2 = b[i0 + i] - b[i2 + i];
			    b1p3 = b[i1 + i] + b[i3 + i];
			    b1m3 = b[i1 + i] - b[i3 + i];

			    a0p2ma1p3 = a0p2 - a1p3;
			    a0m2pb1p3 = a0m2 + b1p3;
			    a0m2mb1p3 = a0m2 - b1p3;
			    b0p2pa1m3 = b0p2 + a1m3;
			    b0p2ma1m3 = b0p2 - a1m3;
			    b0m2mb1m3 = b0m2 - b1m3;

			    c[j0 + j] = a0p2 + a1p3;
			    d[j0 + j] = b0m2 + b1m3;
			    c[j2 + j] = c2 * a0p2ma1p3 - s2 * b0m2mb1m3;
			    d[j2 + j] = s2 * a0p2ma1p3 + c2 * b0m2mb1m3;
			    c[j1 + j] = c1 * a0m2mb1p3 - s1 * b0p2pa1m3;
			    d[j1 + j] = s1 * a0m2mb1p3 + c1 * b0p2pa1m3;
			    c[j3 + j] = c3 * a0m2pb1p3 - s3 * b0p2ma1m3;
			    d[j3 + j] = s3 * a0m2pb1p3 + c3 * b0p2ma1m3;
			    i += inc3;
			    j += inc4;
			  }
			ibase += inc1;
			jbase += inc2;
		      }
		    i0 += iink;
		    i1 += iink;
		    i2 -= iink;
		    i3 -= iink;
		    jbase += jump;
		  }		/* End FORK */
		if (i1 > i2)
		  return 0;
	      }			/* End (i1 != i2) */
	    ibase = 0;
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
513
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    a0m1 = a[i0 + i] - a[i1 + i];
		    b0p1 = b[i0 + i] + b[i1 + i];

		    c[j0 + j] = a[i0 + i] + a[i1 + i];
		    c[j2 + j] = b[i1 + i] - b[i0 + i];

		    c[j1 + j] = SQ2 * (a0m1 - b0p1);
		    c[j3 + j] = -SQ2 * (a0m1 + b0p1);
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	else			/* (la != m) */
	  {
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
539
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    a0p2 = a[i0 + i] + a[i2 + i];
		    a0m2 = a[i0 + i] - a[i2 + i];

		    c[j0 + j] = 2.0 * (a0p2 + a[i1 + i]);
		    c[j1 + j] = 2.0 * (a0m2 - b[i1 + i]);
		    c[j2 + j] = 2.0 * (a0p2 - a[i1 + i]);
		    c[j3 + j] = 2.0 * (a0m2 + b[i1 + i]);
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	return 0;
      }

    case 5:
      {
	double a1p2, a1m2, a0mm, a0mp, b136, b172, b236, b272;

	i0 = j0 = 0;
	i1 = i4 = i0 + inc1 * (m + m - la);
	i2 = i3 = i1 + inc1 * (m + m);
	j1 = j0 + jink;
	j2 = j1 + jink;
	j3 = j2 + jink;
	j4 = j3 + jink;

	if (la != m)
	  {
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
579
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    a1p2 = QUA * (a[i1 + i] + a[i2 + i]);
		    a1m2 = QT5 * (a[i1 + i] - a[i2 + i]);

		    a0mp = a[i0 + i] - a1p2 + a1m2;
		    a0mm = a[i0 + i] - a1p2 - a1m2;

		    b136 = b[i1 + i] * S36;
		    b172 = b[i1 + i] * S72;
		    b236 = b[i2 + i] * S36;
		    b272 = b[i2 + i] * S72;

		    c[j0 + j] = a[i0 + i] + a[i1 + i] + a[i2 + i];
		    c[j1 + j] = a0mp - b172 - b236;
		    c[j2 + j] = a0mm - b136 + b272;
		    c[j3 + j] = a0mm + b136 - b272;
		    c[j4 + j] = a0mp + b172 + b236;
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	    i0 += iink;
	    iink += iink;
	    i1 += iink;
	    i2 += iink;
	    i3 -= iink;
	    i4 -= iink;
	    jbase += jump;
	    jump += jump + jink;

	    if (i1 != i3)
	      {
		for (k = la; k <= kstop; k += la)
		  {
		    kb = k + k;
		    kc = kb + kb;
		    kd = kc + kb;
		    ke = kd + kb;
		    c1 = trigs[kb  ];
		    s1 = trigs[kb+1];
		    c2 = trigs[kc  ];
		    s2 = trigs[kc+1];
		    c3 = trigs[kd  ];
		    s3 = trigs[kd+1];
		    c4 = trigs[ke  ];
		    s4 = trigs[ke+1];
		    ibase = 0;
		    for (l = 0; l < la; ++l)
		      {
			i = ibase;
			j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
636
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
			for (ijk = 0; ijk < lot; ++ijk)
			  {
			    a10 = (a[i0 + i] - 0.25 * ((a[i1 + i] + a[i4 + i]) +
				                       (a[i2 + i] + a[i3 + i]))) +
			                        QT5 * ((a[i1 + i] + a[i4 + i]) -
				                       (a[i2 + i] + a[i3 + i]));
			    a20 = (a[i0 + i] - 0.25 * ((a[i1 + i] + a[i4 + i]) +
			                	       (a[i2 + i] + a[i3 + i]))) -
			                        QT5 * ((a[i1 + i] + a[i4 + i]) -
				                       (a[i2 + i] + a[i3 + i]));
			    b10 = (b[i0 + i] - 0.25 * ((b[i1 + i] - b[i4 + i]) +
						       (b[i2 + i] - b[i3 + i]))) +
			                        QT5 * ((b[i1 + i] - b[i4 + i]) -
						       (b[i2 + i] - b[i3 + i]));
			    b20 = (b[i0 + i] - 0.25 * ((b[i1 + i] - b[i4 + i]) +
						       (b[i2 + i] - b[i3 + i]))) -
			                        QT5 * ((b[i1 + i] - b[i4 + i]) -
						       (b[i2 + i] - b[i3 + i]));

			    a11 = S72 * (b[i1 + i] + b[i4 + i]) +
			          S36 * (b[i2 + i] + b[i3 + i]);
			    a21 = S36 * (b[i1 + i] + b[i4 + i]) -
			          S72 * (b[i2 + i] + b[i3 + i]);
			    b11 = S72 * (a[i1 + i] - a[i4 + i]) +
			          S36 * (a[i2 + i] - a[i3 + i]);
			    b21 = S36 * (a[i1 + i] - a[i4 + i]) -
			          S72 * (a[i2 + i] - a[i3 + i]);

			    c[j0 + j] = a[i0 + i] + ((a[i1 + i] + a[i4 + i]) +
						     (a[i2 + i] + a[i3 + i]));
			    d[j0 + j] = b[i0 + i] + ((b[i1 + i] - b[i4 + i]) +
						     (b[i2 + i] - b[i3 + i]));
			    c[j1 + j] = c1 * (a10 - a11) - s1 * (b10 + b11);
			    d[j1 + j] = s1 * (a10 - a11) + c1 * (b10 + b11);
			    c[j4 + j] = c4 * (a10 + a11) - s4 * (b10 - b11);
			    d[j4 + j] = s4 * (a10 + a11) + c4 * (b10 - b11);
			    c[j2 + j] = c2 * (a20 - a21) - s2 * (b20 + b21);
			    d[j2 + j] = s2 * (a20 - a21) + c2 * (b20 + b21);
			    c[j3 + j] = c3 * (a20 + a21) - s3 * (b20 - b21);
			    d[j3 + j] = s3 * (a20 + a21) + c3 * (b20 - b21);
			    i += inc3;
			    j += inc4;
			  }
			ibase += inc1;
			jbase += inc2;
		      }
		    i0 += iink;
		    i1 += iink;
		    i2 += iink;
		    i3 -= iink;
		    i4 -= iink;
		    jbase += jump;
		  }		/* End FORK */
		if (i1 > i3)
		  return 0;
	      }			/* End (i1 != i3) */
	    ibase = 0;
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
700
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    c[j0 + j] = a[i0 + i] + a[i1 + i] + a[i2 + i];
		    c[j1 + j] = (QT5 * (a[i0 + i] - a[i1 + i])
			     + (0.25 * (a[i0 + i] + a[i1 + i]) -
				        a[i2 + i])) - (S36 * b[i0 + i] +
						       S72 * b[i1 + i]);
		    c[j4 + j] = -(QT5 * (a[i0 + i] - a[i1 + i]) +
				(0.25 * (a[i0 + i] + a[i1 + i]) - a[i2 + i])) -
		                  (S36 * b[i0 + i] + S72 * b[i1 + i]);
		    c[j2 + j] =  (QT5 * (a[i0 + i] - a[i1 + i]) -
				(0.25 * (a[i0 + i] + a[i1 + i]) - a[i2 + i])) -
		                  (S72 * b[i0 + i] - S36 * b[i1 + i]);
		    c[j3 + j] = -(QT5 * (a[i0 + i] - a[i1 + i]) -
				(0.25 * (a[i0 + i] + a[i1 + i]) - a[i2 + i])) -
		                  (S72 * b[i0 + i] - S36 * b[i1 + i]);
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	else
	  {
	    qqrt5 = 2.0 * QT5;
	    ssin36 = 2.0 * S36;
	    ssin72 = 2.0 * S72;
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
735
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    c[j0 + j] = 2.0 * (a[i0 + i] + a[i1 + i] + a[i2 + i]);
		    c[j1 + j] =(2.0 * (a[i0 + i] - 0.25 * (a[i1 + i] + a[i2 + i])) +
		       qqrt5 * (a[i1 + i] - a[i2 + i])) - (ssin72 * b[i1 + i] +
							   ssin36 * b[i2 + i]);
		    c[j2 + j] =(2.0 * (a[i0 + i] - 0.25 * (a[i1 + i] + a[i2 + i])) -
		       qqrt5 * (a[i1 + i] - a[i2 + i])) - (ssin36 * b[i1 + i] -
							   ssin72 * b[i2 + i]);
		    c[j3 + j] =(2.0 * (a[i0 + i] - 0.25 * (a[i1 + i] + a[i2 + i])) -
		       qqrt5 * (a[i1 + i] - a[i2 + i])) + (ssin36 * b[i1 + i] -
							   ssin72 * b[i2 + i]);
		    c[j4 + j] =(2.0 * (a[i0 + i] - 0.25 * (a[i1 + i] + a[i2 + i])) +
		       qqrt5 * (a[i1 + i] - a[i2 + i])) + (ssin72 * b[i1 + i] +
							   ssin36 * b[i2 + i]);
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	return 0;
      }

    case 6:
      {
	ia = 0;
	ib = ia + (2 * m - la) * inc1;
	ic = ib + 2 * m * inc1;
	id = ic + 2 * m * inc1;
	ie = ic;
	iF = ib;
	ja = 0;
	jb = ja + jink;
	jc = jb + jink;
	jd = jc + jink;
	je = jd + jink;
	jf = je + jink;

	if (la != m)		/* go to 690 */
	  {
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
784
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    c[ja + j] = (a[ia + i] + a[id + i]) + (a[ib + i] + a[ic + i]);
		    c[jd + j] = (a[ia + i] - a[id + i]) - (a[ib + i] - a[ic + i]);
		    c[jb + j] =((a[ia + i] - a[id + i]) +
		          0.5 * (a[ib + i] - a[ic + i])) - S60 * (b[ib + i] +
								  b[ic + i]);
		    c[jf + j] =((a[ia + i] - a[id + i]) +
		          0.5 * (a[ib + i] - a[ic + i])) + S60 * (b[ib + i] +
								  b[ic + i]);
		    c[jc + j] =((a[ia + i] + a[id + i]) -
		          0.5 * (a[ib + i] + a[ic + i])) - S60 * (b[ib + i] -
								  b[ic + i]);
		    c[je + j] =((a[ia + i] + a[id + i]) -
		          0.5 * (a[ib + i] + a[ic + i])) + S60 * (b[ib + i] -
								  b[ic + i]);
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	    ia += iink;
	    iink += iink;
	    ib += iink;
	    ic += iink;
	    id -= iink;
	    ie -= iink;
	    iF -= iink;
	    jbase += jump;
	    jump += jump + jink;

	    if (ic != id)	/* go to 660 */
	      {
		for (k = la; k <= kstop; k += la)
		  {
		    kb = k + k;
		    kc = kb + kb;
		    kd = kc + kb;
		    ke = kd + kb;
		    kf = ke + kb;
		    c1 = trigs[kb  ];
		    s1 = trigs[kb+1];
		    c2 = trigs[kc  ];
		    s2 = trigs[kc+1];
		    c3 = trigs[kd  ];
		    s3 = trigs[kd+1];
		    c4 = trigs[ke  ];
		    s4 = trigs[ke+1];
		    c5 = trigs[kf  ];
		    s5 = trigs[kf+1];
		    ibase = 0;
		    for (l = 0; l < la; ++l)
		      {
			i = ibase;
			j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
843
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
			for (ijk = 0; ijk < lot; ++ijk)
			  {
			    a11 = a[ie + i] + a[ib + i] + a[ic + i] + a[iF + i];
			    a20 = a[ia + i] + a[id + i] - 0.5 * a11;
			    a21 = S60 * ((a[ie + i] + a[ib + i]) -
					 (a[ic + i] + a[iF + i]));
			    b11 = b[ib + i] - b[ie + i] + b[ic + i] - b[iF + i];
			    b20 = b[ia + i] - b[id + i] - 0.5 * b11;
			    b21 = S60 * ((b[ib + i] - b[ie + i]) -
					 (b[ic + i] - b[iF + i]));

			    c[ja + j] = a[ia + i] + a[id + i] + a11;
			    d[ja + j] = b[ia + i] - b[id + i] + b11;
			    c[jc + j] = c2 * (a20 - b21) - s2 * (b20 + a21);
			    d[jc + j] = s2 * (a20 - b21) + c2 * (b20 + a21);
			    c[je + j] = c4 * (a20 + b21) - s4 * (b20 - a21);
			    d[je + j] = s4 * (a20 + b21) + c4 * (b20 - a21);

			    a11 = (a[ie + i] - a[ib + i]) + (a[ic + i] - a[iF + i]);
			    b11 = (b[ie + i] + b[ib + i]) - (b[ic + i] + b[iF + i]);
			    a20 = (a[ia + i] - a[id + i]) - 0.5 * a11;
			    a21 = S60 * ((a[ie + i] - a[ib + i]) -
					 (a[ic + i] - a[iF + i]));
			    b20 = (b[ia + i] + b[id + i]) + 0.5 * b11;
			    b21 = S60 * ((b[ie + i] + b[ib + i]) +
					 (b[ic + i] + b[iF + i]));

			    c[jd + j] = c3 * (a[ia + i] - a[id + i] + a11)
			              - s3 * (b[ia + i] + b[id + i] - b11);
			    d[jd + j] = s3 * (a[ia + i] - a[id + i] + a11)
			              + c3 * (b[ia + i] + b[id + i] - b11);
			    c[jb + j] = c1 * (a20 - b21) - s1 * (b20 - a21);
			    d[jb + j] = s1 * (a20 - b21) + c1 * (b20 - a21);
			    c[jf + j] = c5 * (a20 + b21) - s5 * (b20 + a21);
			    d[jf + j] = s5 * (a20 + b21) + c5 * (b20 + a21);
			    i += inc3;
			    j += inc4;
			  }
			ibase += inc1;
			jbase += inc2;
		      }
		    ia += iink;
		    ib += iink;
		    ic += iink;
		    id -= iink;
		    ie -= iink;
		    iF -= iink;
		    jbase += jump;
		  }
		if (ic > id)
		  return 0;
	      }
	    ibase = 0;
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
903
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
904
905
906
907
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
Uwe Schulzweida's avatar
Uwe Schulzweida committed
908
909
910
911
912
913
914
915
916
917
		    c[ja + j] =  a[ib + i] + (a[ia + i] + a[ic + i]);
		    c[jd + j] =  b[ib + i] - (b[ia + i] + b[ic + i]);
		    c[jb + j] =  (S60 * (a[ia + i] - a[ic + i])) -
		                 (0.5 * (b[ia + i] + b[ic + i]) + b[ib + i]);
		    c[jf + j] = -(S60 * (a[ia + i] - a[ic + i])) -
		                 (0.5 * (b[ia + i] + b[ic + i]) + b[ib + i]);
		    c[jc + j] =   S60 * (b[ic + i] - b[ia + i]) +
		                 (0.5 * (a[ia + i] + a[ic + i]) - a[ib + i]);
		    c[je + j] =   S60 * (b[ic + i] - b[ia + i]) -
		                 (0.5 * (a[ia + i] + a[ic + i]) - a[ib + i]);
Uwe Schulzweida's avatar
Uwe Schulzweida committed
918
919
920
921
922
923
924
925
926
927
928
929
930
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	else
	  {
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
931
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    c[ja + j] = (2.0 * (a[ia + i] + a[id + i])) +
		                (2.0 * (a[ib + i] + a[ic + i]));
		    c[jd + j] = (2.0 * (a[ia + i] - a[id + i])) -
		                (2.0 * (a[ib + i] - a[ic + i]));
		    c[jb + j] = (2.0 * (a[ia + i] - a[id + i]) +
		                       (a[ib + i] - a[ic + i])) -
		                (D60 * (b[ib + i] + b[ic + i]));
		    c[jf + j] = (2.0 * (a[ia + i] - a[id + i]) +
		                       (a[ib + i] - a[ic + i])) +
		                (D60 * (b[ib + i] + b[ic + i]));
		    c[jc + j] = (2.0 * (a[ia + i] + a[id + i]) -
			               (a[ib + i] + a[ic + i])) -
		                (D60 * (b[ib + i] - b[ic + i]));
		    c[je + j] = (2.0 * (a[ia + i] + a[id + i]) -
		                       (a[ib + i] + a[ic + i])) +
                                (D60 * (b[ib + i] - b[ic + i]));
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	return 0;
      }

    case 8:
      {
	double a0p7, a1p5, a2p6, p073, p074, p152;
	double a0m7, a1m5, a2m6, m073, m074, m152;

	if (la != m)
	  return 3;
	i0 = 0;
	i1 = i0 + iink;
	i2 = i1 + iink;
	i3 = i2 + iink;
	i4 = i3 + iink;
	i5 = i4 + iink;
	i6 = i5 + iink;
	i7 = i6 + iink;
	j0 = 0;
	j1 = j0 + jink;
	j2 = j1 + jink;
	j3 = j2 + jink;
	j4 = j3 + jink;
	j5 = j4 + jink;
	j6 = j5 + jink;
	j7 = j6 + jink;

	for (l = 0; l < la; ++l)
	  {
	    i = ibase;
	    j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
990
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
	    for (ijk = 0; ijk < lot; ++ijk)
	      {
		a0p7 = a[i0 + i] + a[i7 + i];
		a0m7 = a[i0 + i] - a[i7 + i];
		a1p5 = a[i1 + i] + a[i5 + i];
		a1m5 = a[i1 + i] - a[i5 + i];
		a2p6 = a[i2 + i] + a[i6 + i];
		a2m6 = a[i2 + i] - a[i6 + i];

		p073 = a0p7 + a[i3 + i];
		m073 = a0p7 - a[i3 + i];

		p074 = 2.0 * (a0m7 + a[i4 + i]);
		m074 = 2.0 * (a0m7 - a[i4 + i]);

		p152 = M_SQRT2 * (a1m5 + a2p6);
		m152 = M_SQRT2 * (a1m5 - a2p6);

		c[j0 + j] = 2.0 * (p073 + a1p5);
		c[j4 + j] = 2.0 * (p073 - a1p5);
		c[j2 + j] = 2.0 * (m073 - a2m6);
		c[j6 + j] = 2.0 * (m073 + a2m6);

		c[j1 + j] = m074 + m152;
		c[j5 + j] = m074 - m152;
		c[j3 + j] = p074 - p152;
		c[j7 + j] = p074 + p152;
		i += inc3;
		j += inc4;
	      }
	    ibase += inc1;
	    jbase += inc2;
	  }
      }
    }
  return 0;
}

Uwe Schulzweida's avatar
cleanup    
Uwe Schulzweida committed
1031
static
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1032
int qpassc(double *a, double *b, double *c, double *d, double *trigs,
1033
1034
	   long inc1, long inc2, long inc3, long inc4,
	   long lot, long n, long ifac, long la)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
{
  /*
     qpassc - performs one pass through data as part
     of multiple real fft (fourier analysis) routine.

     a      is first real input vector
     b      is equivalent to a + ifac * la * inc1
     c      is first real output vector;
     d      is equivalent to c + la * inc2
     trigs  is a precalculated list of sines & cosines
     inc1   is the addressing increment for a
     inc2   is the addressing increment for c
     inc3   is the increment between input vectors a
     inc4   is the increment between output vectors c
     lot    is the number of vectors
     n      is the length of the vectors
     ifac   is the current factor of n
     la     is the product of previous factors
   */

1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
  long i0, i1, i2, i3, i4, i5, i6, i7;
  long j0, j1, j2, j3, j4, j5, j6, j7;
  long ia, ib, ic;
  long ja, jb, jc;
  long i, j, k, l, m, ijk;
  long ibase, jbase;
  long iink, jink;
  long jump;
  long kstop;
  long kb, kc, kd, ke, kf;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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

  double a0, a1, a2, a3;
  double b0, b1, b2, b3;
  double c1, c2, c3, c4, c5;
  double s1, s2, s3, s4, s5;
  double w, x, y, z;

  m = n / ifac;
  iink = la * inc1;
  jink = la * inc2;
  jump = (ifac - 1) * iink;
  kstop = (n - ifac) / (2 * ifac);
  ibase = 0;
  jbase = 0;

  switch (ifac)
    {
    case 2:
      {
	i0 = j0 = 0;
	i1 = i0 + iink;
	j1 = j0 + inc2 * (m + m - la);
	if (la != m)
	  {
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1093
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    c[j0 + j] = a[i0 + i] + a[i1 + i];
		    c[j1 + j] = a[i0 + i] - a[i1 + i];
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	    j0    += jink;
	    jink  += jink;
	    j1    -= jink;
	    ibase += jump;
	    jump  += jump + iink;

	    if (j0 != j1)
	      {
		for (k = la; k <= kstop; k += la)
		  {
		    kb = k + k;
		    c1 = trigs[kb  ];
		    s1 = trigs[kb+1];
		    jbase = 0;
		    for (l = 0; l < la; ++l)
		      {
			i = ibase;
			j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1124
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
			for (ijk = 0; ijk < lot; ++ijk)
			  {
			    c[j0 + j] = a[i0 + i] + c1 * a[i1 + i] + s1 * b[i1 + i];
			    c[j1 + j] = a[i0 + i] - c1 * a[i1 + i] - s1 * b[i1 + i];
			    d[j0 + j] = c1 * b[i1 + i] - s1 * a[i1 + i] + b[i0 + i];
			    d[j1 + j] = c1 * b[i1 + i] - s1 * a[i1 + i] - b[i0 + i];
			    i += inc3;
			    j += inc4;
			  }
			ibase += inc1;
			jbase += inc2;
		      }
		    j0 += jink;
		    j1 -= jink;
		    ibase += jump;
		  }		/* End FORK */
		if (j0 > j1)
		  return 0;
	      }			/* End (i0 != i1) */
	    jbase = 0;
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1151
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    c[j0 + j] = a[i0 + i];
		    d[j1 + j] = -a[i1 + i];
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	else			/* (la != m) */
	  {
	    z = 1.0 / n;
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1172
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    c[j0 + j] = z * (a[i0 + i] + a[i1 + i]);
		    c[j1 + j] = z * (a[i0 + i] - a[i1 + i]);
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	return 0;
      }

    case 3:
      {
	ia = 0;
	ib = ia + iink;
	ic = ib + iink;

	ja = 0;
	jb = ja + inc2 * (m + m - la);
	jc = jb;

	if (la != m)		/* else 390 */
	  {
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1205
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    c[ja + j] = a[ia + i] + a[ib + i] + a[ic + i];
		    c[jb + j] = a[ia + i] - 0.5 * (a[ib + i] + a[ic + i]);
		    d[jb + j] = S60 * (a[ic + i] - a[ib + i]);
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	    ja += jink;
	    jink += jink;
	    jb += jink;
	    jc -= jink;
	    ibase += jump;
	    jump += jump + iink;

	    if (ja != jc)	/* else  360 */
	      {
		for (k = la; k <= kstop; k += la)
		  {
		    kb = k + k;
		    kc = kb + kb;
		    c1 = trigs[kb  ];
		    s1 = trigs[kb+1];
		    c2 = trigs[kc  ];
		    s2 = trigs[kc+1];
		    jbase = 0;
		    for (l = 0; l < la; ++l)
		      {
			i = ibase;
			j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1241
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
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
#pragma vdir nodep
#endif
			for (ijk = 0; ijk < lot; ++ijk)
			  {
			    a1 = c1 * a[ib + i] + s1 * b[ib + i] +
                                 c2 * a[ic + i] + s2 * b[ic + i];
			    b1 = c1 * b[ib + i] - s1 * a[ib + i] +
                                 c2 * b[ic + i] - s2 * a[ic + i];
			    a2 = a[ia + i] - 0.5 * a1;
			    b2 = b[ia + i] - 0.5 * b1;
			    a3 = S60 * (c1 * a[ib + i] + s1 * b[ib + i] -
				        c2 * a[ic + i] - s2 * b[ic + i]);
			    b3 = S60 * (c1 * b[ib + i] - s1 * a[ib + i] -
				        c2 * b[ic + i] + s2 * a[ic + i]);

			    c[ja + j] = a[ia + i] + a1;
			    d[ja + j] = b[ia + i] + b1;
			    c[jb + j] = a2 + b3;
			    d[jb + j] = b2 - a3;
			    c[jc + j] = a2 - b3;
			    d[jc + j] = -b2 - a3;
			    i += inc3;
			    j += inc4;
			  }
			ibase += inc1;
			jbase += inc2;
		      }
		    ja += jink;
		    jb += jink;
		    jc -= jink;
		    ibase += jump;
		  }		/* End FORK */
		if (ja > jc)
		  return 0;
	      }			/* End (ia != ic) */
	    jbase = 0;
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1282
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    /* soweit */
		    c[ja + j] = a[ia + i] + 0.5 * (a[ib + i] - a[ic + i]);
		    d[ja + j] = -S60 * (a[ib + i] + a[ic + i]);
		    c[jb + j] = a[ia + i] - a[ib + i] + a[ic + i];
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	else			/* (la != m) */
	  {
	    z = 1.0 / n;
	    y = S60 / n;
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1306
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    c[ja + j] = z * (a[ia + i] + a[ib + i] + a[ic + i]);
		    c[jb + j] = z * (a[ia + i] - 0.5 * (a[ib + i] + a[ic + i]));
		    d[jb + j] = y * (a[ic + i] - a[ib + i]);
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	return 0;
      }

    case 4:
      {
	double a0p2, a1p3;

	i0 = 0;
	i1 = i0 + iink;
	i2 = i1 + iink;
	i3 = i2 + iink;
	j0 = 0;
	j1 = j0 + inc2 * (m + m - la);
	j2 = j1 + inc2 * (m + m);
	j3 = j1;

	if (la != m)		/*else go to 490 */
	  {
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1343
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    a0p2 = a[i0 + i] + a[i2 + i];
		    a1p3 = a[i1 + i] + a[i3 + i];

		    c[j0 + j] = a0p2 + a1p3;
		    c[j2 + j] = a0p2 - a1p3;

		    c[j1 + j] = a[i0 + i] - a[i2 + i];
		    d[j1 + j] = a[i3 + i] - a[i1 + i];
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	    j0 += jink;
	    jink += jink;
	    j1 += jink;
	    j2 -= jink;
	    j3 -= jink;
	    ibase += jump;
	    jump += jump + iink;

	    if (j1 != j2)	/* else go to 460; */
	      {
		for (k = la; k <= kstop; k += la)
		  {
		    kb = k + k;
		    kc = kb + kb;
		    kd = kc + kb;
		    c1 = trigs[kb  ];
		    s1 = trigs[kb+1];
		    c2 = trigs[kc  ];
		    s2 = trigs[kc+1];
		    c3 = trigs[kd  ];
		    s3 = trigs[kd+1];
		    jbase = 0;
		    for (l = 0; l < la; ++l)
		      {
			i = ibase;
			j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1388
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
#pragma vdir nodep
#endif
			for (ijk = 0; ijk < lot; ++ijk)
			  {
			    a0 = a[i0 + i] + c2 * a[i2 + i] + s2 * b[i2 + i];
			    a2 = a[i0 + i] - c2 * a[i2 + i] - s2 * b[i2 + i];
			    b0 = b[i0 + i] + c2 * b[i2 + i] - s2 * a[i2 + i];
			    b2 = b[i0 + i] - c2 * b[i2 + i] + s2 * a[i2 + i];

			    a1 = c1 * a[i1 + i] + s1 * b[i1 + i] +
                                 c3 * a[i3 + i] + s3 * b[i3 + i];
			    a3 = c1 * a[i1 + i] + s1 * b[i1 + i] -
                                 c3 * a[i3 + i] - s3 * b[i3 + i];
			    b1 = c1 * b[i1 + i] - s1 * a[i1 + i] +
                                 c3 * b[i3 + i] - s3 * a[i3 + i];
			    b3 = c1 * b[i1 + i] - s1 * a[i1 + i] -
                                 c3 * b[i3 + i] + s3 * a[i3 + i];

			    c[j0 + j] = a0 + a1;
			    c[j2 + j] = a0 - a1;
			    d[j0 + j] = b0 + b1;
			    d[j2 + j] = b1 - b0;
			    c[j1 + j] = a2 + b3;
			    c[j3 + j] = a2 - b3;
			    d[j1 + j] = b2 - a3;
			    d[j3 + j] = -b2 - a3;
			    i += inc3;
			    j += inc4;
			  }
			ibase += inc1;
			jbase += inc2;
		      }
		    j0 += jink;
		    j1 += jink;
		    j2 -= jink;
		    j3 -= jink;
		    ibase += jump;
		  }		/* End FORK */
		if (j1 > j2)
		  return 0;
	      }			/* End (i1 != i2) */
	    jbase = 0;
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1435
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    c[j0 + j] =  a[i0 + i] + SQ2 * (a[i1 + i] - a[i3 + i]);
		    c[j1 + j] =  a[i0 + i] - SQ2 * (a[i1 + i] - a[i3 + i]);
		    d[j0 + j] = -a[i2 + i] - SQ2 * (a[i1 + i] + a[i3 + i]);
		    d[j1 + j] =  a[i2 + i] - SQ2 * (a[i1 + i] + a[i3 + i]);
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	else			/* (la != m) */
	  {
	    z = 1.0 / n;
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1458
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    a0p2 = a[i0 + i] + a[i2 + i];
		    a1p3 = a[i1 + i] + a[i3 + i];

		    c[j0 + j] = z * (a0p2 + a1p3);
		    c[j2 + j] = z * (a0p2 - a1p3);
		    c[j1 + j] = z * (a[i0 + i] - a[i2 + i]);
		    d[j1 + j] = z * (a[i3 + i] - a[i1 + i]);
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	return 0;
      }

    case 5:
      {
	double a1p4, a2p3, b1p4, b2p3, a025, b025, asps, bsps, a0pq, b0pq;
	double a1m4, a2m3, b1m4, b2m3, aqrt, bqrt, asms, bsms, a0mq, b0mq;

	i0 = 0;
	i1 = i0 + iink;
	i2 = i1 + iink;
	i3 = i2 + iink;
	i4 = i3 + iink;
	j0 = 0;
	j1 = j0 + inc2 * (m + m - la);
	j2 = j1 + inc2 * (m + m);
	j3 = j2;
	j4 = j1;

	if (la != m)		/* else go to 590; */
	  {
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1502
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    a1p4 = a[i1 + i] + a[i4 + i];
		    a1m4 = a[i1 + i] - a[i4 + i];
		    a2p3 = a[i2 + i] + a[i3 + i];
		    a2m3 = a[i2 + i] - a[i3 + i];

		    a025 = a[i0 + i] - 0.25 * (a1p4 + a2p3);
		    aqrt = QT5 * (a1p4 - a2p3);

		    c[j0 + j] = a[i0 + i] + a1p4 + a2p3;
		    c[j1 + j] = a025 + aqrt;
		    c[j2 + j] = a025 - aqrt;
		    d[j1 + j] = -S72 * a1m4 - S36 * a2m3;
		    d[j2 + j] = -S36 * a1m4 + S72 * a2m3;
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	    j0 += jink;
	    jink += jink;
	    j1 += jink;
	    j2 += jink;
	    j3 -= jink;
	    j4 -= jink;
	    ibase += jump;
	    jump += jump + iink;

	    if (j1 != j3)
	      {
		for (k = la; k <= kstop; k += la)
		  {
		    kb = k + k;
		    kc = kb + kb;
		    kd = kc + kb;
		    ke = kd + kb;
		    c1 = trigs[kb  ];
		    s1 = trigs[kb+1];
		    c2 = trigs[kc  ];
		    s2 = trigs[kc+1];
		    c3 = trigs[kd  ];
		    s3 = trigs[kd+1];
		    c4 = trigs[ke  ];
		    s4 = trigs[ke+1];
		    jbase = 0;
		    for (l = 0; l < la; ++l)
		      {
			i = ibase;
			j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1556
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
#pragma vdir nodep
#endif
			for (ijk = 0; ijk < lot; ++ijk)
			  {
			    a1p4 = c1 * a[i1 + i] + s1 * b[i1 + i] + 
			           c4 * a[i4 + i] + s4 * b[i4 + i];
			    a1m4 = c1 * a[i1 + i] + s1 * b[i1 + i] - 
			           c4 * a[i4 + i] - s4 * b[i4 + i];
			    a2p3 = c2 * a[i2 + i] + s2 * b[i2 + i] + 
			           c3 * a[i3 + i] + s3 * b[i3 + i];
			    a2m3 = c2 * a[i2 + i] + s2 * b[i2 + i] -
			           c3 * a[i3 + i] - s3 * b[i3 + i];
			    b1p4 = c1 * b[i1 + i] - s1 * a[i1 + i] + 
			           c4 * b[i4 + i] - s4 * a[i4 + i];
			    b1m4 = c1 * b[i1 + i] - s1 * a[i1 + i] -
			           c4 * b[i4 + i] + s4 * a[i4 + i];
			    b2p3 = c2 * b[i2 + i] - s2 * a[i2 + i] +
			           c3 * b[i3 + i] - s3 * a[i3 + i];
			    b2m3 = c2 * b[i2 + i] - s2 * a[i2 + i] -
			           c3 * b[i3 + i] + s3 * a[i3 + i];

			    a025 = a[i0 + i] - 0.25 * (a1p4 + a2p3);
			    aqrt = QT5 * (a1p4 - a2p3);
			    b025 = b[i0 + i] - 0.25 * (b1p4 + b2p3);
			    bqrt = QT5 * (b1p4 - b2p3);

			    a0pq = a025 + aqrt;
			    a0mq = a025 - aqrt;
			    b0pq = b025 + bqrt;
			    b0mq = b025 - bqrt;

			    asps = S72 * a1m4 + S36 * a2m3;
			    asms = S36 * a1m4 - S72 * a2m3;
			    bsps = S72 * b1m4 + S36 * b2m3;
			    bsms = S36 * b1m4 - S72 * b2m3;

			    c[j0 + j] = a[i0 + i] + a1p4 + a2p3;
			    c[j1 + j] = a0pq + bsps;
			    c[j2 + j] = a0mq + bsms;
			    c[j3 + j] = a0mq - bsms;
			    c[j4 + j] = a0pq - bsps;
			    d[j0 + j] = b[i0 + i] + b1p4 + b2p3;
			    d[j1 + j] = b0pq - asps;
			    d[j2 + j] = b0mq - asms;
			    d[j3 + j] = -b0mq - asms;
			    d[j4 + j] = -b0pq - asps;
			    i += inc3;
			    j += inc4;
			  }
			ibase += inc1;
			jbase += inc2;
		      }
		    j0 += jink;
		    j1 += jink;
		    j2 += jink;
		    j3 -= jink;
		    j4 -= jink;
		    ibase += jump;
		  }		/* End FORK */
		if (j1 > j3)
		  return 0;
	      }			/* End (jb != jd) */
	    jbase = 0;
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1624
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    a1p4 = a[i1 + i] + a[i4 + i];
		    a1m4 = a[i1 + i] - a[i4 + i];
		    a2p3 = a[i2 + i] + a[i3 + i];
		    a2m3 = a[i2 + i] - a[i3 + i];

		    a025 = a[i0 + i] + 0.25 * (a1m4 - a2m3);
		    aqrt = QT5 * (a1m4 + a2m3);

		    c[j0 + j] = a025 + aqrt;
		    c[j1 + j] = a025 - aqrt;
		    c[j2 + j] = a[i0 + i] - a1m4 + a2m3;
		    d[j0 + j] = -S36 * a1p4 - S72 * a2p3;
		    d[j1 + j] = -S72 * a1p4 + S36 * a2p3;

		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	else
	  {
	    z = 1.0 / n;
	    y = QT5 / n;
	    x = S36 / n;
	    w = S72 / n;

	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1661
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    a1p4 = a[i1 + i] + a[i4 + i];
		    a1m4 = a[i1 + i] - a[i4 + i];
		    a2p3 = a[i2 + i] + a[i3 + i];
		    a2m3 = a[i2 + i] - a[i3 + i];

		    a025 = z * (a[i0 + i] - 0.25 * (a1p4 + a2p3));
		    aqrt = y * (a1p4 - a2p3);

		    c[j0 + j] = z * (a[i0 + i] + a1p4 + a2p3);
		    c[j1 + j] = a025 + aqrt;
		    c[j2 + j] = a025 - aqrt;
		    d[j1 + j] = -w * a1m4 - x * a2m3;
		    d[j2 + j] = w * a2m3 - x * a1m4;
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	return 0;
      }

    case 6:
      {
	double ab1a, ab2a, ab3a, ab4a, ab5a;
	double ab1b, ab2b, ab3b, ab4b, ab5b;
	double a0p3, a1p4, a1p5, a2p4, a2p5;
	double a0m3, a1m4, a1m5, a2m4, a2m5;
	double b1p4, b2p5;
	double b1m4, b2m5;
	double ap05, bp05, ap60, bp60;
	double am05, bm05, am60, bm60;

	i0 = 0;
	i1 = i0 + iink;
	i2 = i1 + iink;
	i3 = i2 + iink;
	i4 = i3 + iink;
	i5 = i4 + iink;
	j0 = 0;
	j1 = j0 + inc2 * (m + m - la);
	j2 = j1 + inc2 * (m + m);
	j3 = j2 + inc2 * (m + m);
	j4 = j2;
	j5 = j1;

	if (la != m)
	  {
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1719
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    a0p3 = a[i0 + i] + a[i3 + i];
		    a0m3 = a[i0 + i] - a[i3 + i];
		    a1p4 = a[i1 + i] + a[i4 + i];
		    a1m4 = a[i1 + i] - a[i4 + i];
		    a2p5 = a[i2 + i] + a[i5 + i];
		    a2m5 = a[i2 + i] - a[i5 + i];

		    c[j0 + j] = a0p3 + a1p4 + a2p5;
		    c[j3 + j] = a0m3 + a2m5 - a1m4;

		    c[j1 + j] = a0m3 - 0.5 * (a2m5 - a1m4);
		    c[j2 + j] = a0p3 - 0.5 * (a1p4 + a2p5);

		    d[j1 + j] = S60 * (-a2m5 - a1m4);
		    d[j2 + j] = S60 * (a2p5 - a1p4);
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	    j0 += jink;
	    jink += jink;
	    j1 += jink;
	    j2 += jink;
	    j3 -= jink;
	    j4 -= jink;
	    j5 -= jink;
	    ibase += jump;
	    jump += jump + iink;

	    if (j2 != j3)
	      {
		for (k = la; k <= kstop; k += la)
		  {
		    kb = k + k;
		    kc = kb + kb;
		    kd = kc + kb;
		    ke = kd + kb;
		    kf = ke + kb;
		    c1 = trigs[kb  ];
		    s1 = trigs[kb+1];
		    c2 = trigs[kc  ];
		    s2 = trigs[kc+1];
		    c3 = trigs[kd  ];
		    s3 = trigs[kd+1];
		    c4 = trigs[ke  ];
		    s4 = trigs[ke+1];
		    c5 = trigs[kf  ];
		    s5 = trigs[kf+1];
		    jbase = 0;
		    for (l = 0; l < la; ++l)
		      {
			i = ibase;
			j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1779
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
#pragma vdir nodep
#endif
			for (ijk = 0; ijk < lot; ++ijk)
			  {
			    ab1a = c1 * a[i1 + i] + s1 * b[i1 + i];
			    ab1b = c1 * b[i1 + i] - s1 * a[i1 + i];
			    ab2a = c2 * a[i2 + i] + s2 * b[i2 + i];
			    ab2b = c2 * b[i2 + i] - s2 * a[i2 + i];
			    ab3a = c3 * a[i3 + i] + s3 * b[i3 + i];
			    ab3b = c3 * b[i3 + i] - s3 * a[i3 + i];
			    ab4a = c4 * a[i4 + i] + s4 * b[i4 + i];
			    ab4b = c4 * b[i4 + i] - s4 * a[i4 + i];
			    ab5a = c5 * a[i5 + i] + s5 * b[i5 + i];
			    ab5b = c5 * b[i5 + i] - s5 * a[i5 + i];

			    a1p4 = ab1a + ab4a;
			    a1m4 = ab1a - ab4a;
			    a2p5 = ab2a + ab5a;
			    a2m5 = ab2a - ab5a;

			    b1p4 = ab1b + ab4b;
			    b1m4 = ab1b - ab4b;
			    b2p5 = ab2b + ab5b;
			    b2m5 = ab2b - ab5b;

			    ap05 = a[i0 + i] + ab3a - 0.5 * (a1p4 + a2p5);
			    bp05 = b[i0 + i] + ab3b - 0.5 * (b1p4 + b2p5);
			    am05 = a[i0 + i] - ab3a - 0.5 * (a2m5 - a1m4);
			    bm05 = -b[i0 + i] + ab3b - 0.5 * (b1m4 - b2m5);

			    ap60 = S60 * (a2p5 - a1p4);
			    bp60 = S60 * (b2p5 - b1p4);
			    am60 = S60 * (-a2m5 - a1m4);
			    bm60 = S60 * (-b2m5 - b1m4);

			    c[j0 + j] = a[i0 + i] + ab3a + a1p4 + a2p5;
			    d[j0 + j] = b[i0 + i] + ab3b + b1p4 + b2p5;
			    c[j1 + j] = am05 - bm60;
			    d[j1 + j] = am60 - bm05;
			    c[j2 + j] = ap05 - bp60;
			    d[j2 + j] = ap60 + bp05;
			    c[j3 + j] = a[i0 + i] - ab3a - a1m4 + a2m5;
			    d[j3 + j] = -b[i0 + i] + ab3b + b1m4 - b2m5;
			    c[j4 + j] = ap05 + bp60;
			    d[j4 + j] = ap60 - bp05;
			    c[j5 + j] = am05 + bm60;
			    d[j5 + j] = am60 + bm05;
			    i += inc3;
			    j += inc4;
			  }
			ibase += inc1;
			jbase += inc2;
		      }
		    j0 += jink;
		    j1 += jink;
		    j2 += jink;
		    j3 -= jink;
		    j4 -= jink;
		    j5 -= jink;
		    ibase += jump;
		  }
		if (j2 > j3)
		  return 0;
	      }
	    jbase = 0;
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1849
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    a1p5 = a[i1 + i] + a[i5 + i];
		    a1m5 = a[i1 + i] - a[i5 + i];
		    a2p4 = a[i2 + i] + a[i4 + i];
		    a2m4 = a[i2 + i] - a[i4 + i];

		    c[j0 + j] =  a[i0 + i] + 0.5 * a2m4 + S60 * a1m5;
		    d[j0 + j] = -a[i3 + i] - 0.5 * a1p5 - S60 * a2p4;
		    c[j1 + j] =  a[i0 + i] - a2m4;
		    d[j1 + j] =  a[i3 + i] - a1p5;
		    c[j2 + j] =  a[i0 + i] + 0.5 * a2m4 - S60 * a1m5;
		    d[j2 + j] = -a[i3 + i] - 0.5 * a1p5 + S60 * a2p4;
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	else
	  {
	    z = 1.0 / n;
	    y = S60 / n;
	    for (l = 0; l < la; ++l)
	      {
		i = ibase;
		j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1880
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
#pragma vdir nodep
#endif
		for (ijk = 0; ijk < lot; ++ijk)
		  {
		    a0p3 = a[i0 + i] + a[i3 + i];
		    a0m3 = a[i0 + i] - a[i3 + i];
		    a1p4 = a[i1 + i] + a[i4 + i];
		    a1m4 = a[i1 + i] - a[i4 + i];
		    a2p5 = a[i2 + i] + a[i5 + i];
		    a2m5 = a[i2 + i] - a[i5 + i];

		    c[j0 + j] = z * (a0p3 + a1p4 + a2p5);
		    c[j3 + j] = z * (a0m3 + a2m5 - a1m4);

		    c[j1 + j] = z * (a0m3 - 0.5 * (a2m5 - a1m4));
		    c[j2 + j] = z * (a0p3 - 0.5 * (a1p4 + a2p5));

		    d[j1 + j] = y * (-a2m5 - a1m4);
		    d[j2 + j] = y * (a2p5 - a1p4);
		    i += inc3;
		    j += inc4;
		  }
		ibase += inc1;
		jbase += inc2;
	      }
	  }
	return 0;
      }

    case 8:
      {
	double a0p4, a1p5, a2p6, a3p7;
	double a0m4, a1m5, a2m6, a3m7;

	if (la != m)
	  return 3;
	i0 = 0;
	i1 = i0 + iink;
	i2 = i1 + iink;
	i3 = i2 + iink;
	i4 = i3 + iink;
	i5 = i4 + iink;
	i6 = i5 + iink;
	i7 = i6 + iink;
	j0 = 0;
	j1 = j0 + jink;
	j2 = j1 + jink;
	j3 = j2 + jink;
	j4 = j3 + jink;
	j5 = j4 + jink;
	j6 = j5 + jink;
	j7 = j6 + jink;
	z = 1.0 / n;
	y = SQ2 / n;

	for (l = 0; l < la; ++l)
	  {
	    i = ibase;
	    j = jbase;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1940
#if defined(SX)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
#pragma vdir nodep
#endif
	    for (ijk = 0; ijk < lot; ++ijk)
	      {
		a0p4 = a[i0 + i] + a[i4 + i];
		a0m4 = a[i0 + i] - a[i4 + i];
		a1p5 = a[i1 + i] + a[i5 + i];
		a1m5 = a[i1 + i] - a[i5 + i];
		a2p6 = a[i2 + i] + a[i6 + i];
		a2m6 = a[i2 + i] - a[i6 + i];
		a3p7 = a[i3 + i] + a[i7 + i];
		a3m7 = a[i3 + i] - a[i7 + i];

		c[j0 + j] =  z * (a0p4 + a1p5 + a2p6 + a3p7);
		c[j7 + j] =  z * (a0p4 - a1p5 + a2p6 - a3p7);

		c[j3 + j] =  z * (a0p4 - a2p6);
		c[j4 + j] =  z * (a3p7 - a1p5);

		c[j1 + j] =  z * a0m4 + y * (a1m5 - a3m7);
		c[j5 + j] =  z * a0m4 - y * (a1m5 - a3m7);
		c[j2 + j] = -z * a2m6 - y * (a1m5 + a3m7);
		c[j6 + j] =  z * a2m6 - y * (a1m5 + a3m7);
		i += inc3;
		j += inc4;
	      }
	    ibase += inc1;
	    jbase += inc2;
	  }
      }
    }
  return 0;
}

/* ====================== */
/* Fast Fourier Transform */
/* ====================== */
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1978
void fc2gp(double *restrict trig, long *restrict ifax, double *restrict fc, double *restrict gp, long nlat, long nlon, long nlev, long nfc)
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
{
  /* fc2gp performs fourier to gridpoint transforms using           */
  /* multiple fast fourier transform of length nlon                 */
  /*                                                                */
  /* fc   - real array of fourier coefficients fc[nlev][nfc][nlat]  */
  /* gp   - real array of gridpoints           gp[nlev][nlat][nlon] */
  /* nlat - Number of latitudes                                     */
  /* nlon - Number of longitudes                                    */
  /* nlev - Number of levels                                        */
  /* nfc  - Number of fourier coefficients on 1 latitude            */

  /* x(j) = sum(k=0,...,n-1)(c(k)*exp(2*i*j*k*pi/nlon))             */
  /*        where c(k) = a(k) + i*b(k) and c(n-k) = a(k)-i*b(k)     */

1993
  if ( ifax[9] != nlon ) fprintf(stderr, "fc2gp: wrong initialization!\n");
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1994

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1995
  long nfax = ifax[0];
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1996

Uwe Schulzweida's avatar
Uwe Schulzweida committed
1997
1998
  long jump = (nlon + 2);
  long lot  = nlev * nlat;
Uwe Schulzweida's avatar
Uwe Schulzweida committed
1999

2000
  long nx = (nlon%2 == 1) ? nlon : nlon+1;
2001
2002
2003
2004
2005
2006
2007
2008
2009
  long nblox = 1 + (lot-1)/NFFT;
  long nvex  = lot - (nblox-1)*NFFT;
  long nvex0 = nvex;

  long nthmax = (nblox < ompNumThreads) ? nblox : ompNumThreads;
  long nvals = lot*jump;

  double *restrict wfc = (double*) Malloc(