1      logical function spcart_init(lmaxin,normalize,all_spherical)
2c $Id$
3*::cr::7
4*--------------------------------------------------*
5* COPYRIGHT (C) 1994, 1995, 1996, 1997, 1998, 1999 *
6*         Pacific Northwest National Laboratory,   *
7*         Battelle Memorial Institute.             *
8*--------------------------------------------------*
9*------------> All Rights Reserved <---------------*
10*--------------------------------------------------*
11*
12* initialization of spherical to cartesian tranformation array
13*... stored on heap.
14*... stored up to lmax values
15*...
16*   spcart(iccart,icsp,l)  =>
17*                          spcart((lmax+1)*(lmax+2)/2,1:2*lmax+1,0:lmax)
18*    lmax = 5 h functions  => size = 21*11*6 = 1386
19*   store array 34% sparse for simplicity.  1386 doubles is 11 Kbytes.
20*
21      implicit none
22#include "stdio.fh"
23#include "errquit.fh"
24#include "mafdecls.fh"
25#include "spcartP.fh"
26c::passed
27      integer lmaxin    ! [input] init transformed values up to lmaxin
28      logical normalize ! [input] normalize the coefficients for
29*                                 integral transformations
30*                         true for integral transformations
31*                         false for ECP integral computations
32*
33      logical all_spherical ! [input] generate all spherical components
34*                                     e.g., 6 d sphericals etc.
35*
36      external bd_spcart  ! needed for cray T3D to link properly
37*
38      logical spcart_terminate
39      external spcart_terminate
40c::local
41      integer size_sp2c         ! size of array
42      integer l_block_size      ! size of compressed array
43      integer lval, l2, ls
44c
45*rak:: temporary
46      if (all_spherical) call errquit
47     &      ('spcart_init: all spherical components not working yet',
48     &      911, UNKNOWN_ERR)
49c
50      if (sph_cart_init.eq.SPH_CART_INIT_VALUE) then
51        if (lmaxin.gt.lmax_init) then
52          if (.not.spcart_terminate()) call errquit
53     &          ('spcart_init: error terminating old spcart_init',911,
54     &          UNKNOWN_ERR)
55        else
56          spcart_init = .true.
57          return           ! initialization already done to cover lmaxin
58        endif
59      endif
60*
61      if (all_spherical) then
62        sph_cart_allsph = .true.
63      else
64        sph_cart_allsph = .false.
65      endif
66*
67      call defNxyz(lmaxin)
68c
69      size_sp2c = lmaxin+1
70      size_sp2c = size_sp2c*(2*lmaxin+1)
71      size_sp2c = size_sp2c*(((lmaxin+1)*(lmaxin+2))/2)
72c
73      active_sp2c =
74     &      ma_alloc_get(mt_dbl,size_sp2c,'sph 2 cart trans array',
75     &      h_sp2c,k_sp2c)
76      if (.not.active_sp2c)  call errquit
77     &      ('spcart_init: alloc_get failed for size',size_sp2c,
78     &       MEM_ERR)
79      call dcopy(size_sp2c,0.0d00,0,dbl_mb(k_sp2c),1)
80c
81* generate transformation matricies by recursion
82      call xlmcoeff(lmaxin,dbl_mb(k_sp2c),normalize)
83* generate all spherical components
84      call xlm_coeff_full(lmaxin,dbl_mb(k_sp2c),normalize)
85* allocate memory for index array
86      active_sp2c_lindx = ma_alloc_get(
87     &      mt_int,(lmaxin+1),' ptrs array xlm sph 2 cart ',
88     &      h_sp2c_lindx,k_sp2c_lindx)
89      if (.not.active_sp2c_lindx) call errquit
90     &      ('spcart_init: alloc_get failed (index) ',911, MEM_ERR)
91      call ifill((lmaxin+1),0,int_mb(k_sp2c_lindx),1)
92* allocate memory for index array for inverse transform
93      active_invsp2c_lindx = ma_alloc_get(
94     &      mt_int,(lmaxin+1),
95     &      ' ptrs array inverse xlm sph 2 cart ',
96     &      h_invsp2c_lindx,k_invsp2c_lindx)
97      if (.not.active_invsp2c_lindx) call errquit
98     &      ('spcart_init: alloc_get failed (index) ',911, MEM_ERR)
99      call ifill((lmaxin+1),0,int_mb(k_invsp2c_lindx),1)
100* determine size of compressed transformation arrays
101      l_block_size = 0
102      do 00100 lval=0,Lmaxin
103        l2 = (((lval+1)*(lval+2))/2)
104        ls = (2*lval+1)
105        l_block_size = l_block_size + l2*ls
10600100 continue
107* allocate memory for compressed transformation arrays
108      active_sp2c_cmp = ma_alloc_get
109     &      (mt_dbl,l_block_size,'sph 2 cart trans array cmp',
110     &      h_sp2c_cmp,k_sp2c_cmp)
111      if (.not. active_sp2c_cmp) call errquit
112     &      ('spcart_init: alloc_get failed (array cmp) ',911, MEM_ERR)
113      call dcopy(l_block_size,0.0d00,0,dbl_mb(k_sp2c_cmp),1)
114* allocate memory for compressed inverse transformation arrays
115      active_invsp2c_cmp = ma_alloc_get
116     &      (mt_dbl,l_block_size,'sph 2 cart trans array cmp',
117     &      h_invsp2c_cmp,k_invsp2c_cmp)
118      if (.not. active_invsp2c_cmp) call errquit
119     &      ('spcart_init: alloc_get failed (inv array cmp) ',911,
120     &      MEM_ERR)
121      call dcopy(l_block_size,0.0d00,0,dbl_mb(k_invsp2c_cmp),1)
122* allocate memory for scale vector
123      active_cart_norm_scale= ma_alloc_get
124     &      (mt_dbl,(2*lmaxin+1)*(lmaxin+1),
125     &      'sph 2 cart scale arryy ',
126     &      h_cart_norm_scale,k_cart_norm_scale)
127      if (.not. active_cart_norm_scale) call errquit
128     &      ('spcart_init: alloc_get failed (array scale) ',911,
129     &      MEM_ERR)
130      call dcopy(((2*lmaxin+1)*(lmaxin+1)),0.0d00,0,
131     &    dbl_mb(k_cart_norm_scale),1)
132* set normalize scale vector so cartesian vectors of transformation
133* matrix are normalized to unity
134      call xlm_cart_norm_scale(lmaxin,dbl_mb(k_sp2c),
135     &      dbl_mb(k_cart_norm_scale))
136* set up pointers and copy recursion array to compressed
137* transformation arrays
138      call xlm_ptrs(lmaxin,dbl_mb(k_sp2c),
139     &      dbl_mb(k_sp2c_cmp),l_block_size,int_mb(k_sp2c_lindx))
140      if (lmaxin.ge.1) then
141        call xlm_ptrs_fix_p(dbl_mb(int_mb((k_sp2c_lindx+1))),3,1)
142      endif
143*      do lval=0,Lmaxin
144*        write(6,*)' before '
145*        call spcart_print_dtrans(lval)
146*      enddo
147*
148* form inverse array
149*
150      call xlm_ptrsinv(lmaxin,
151     &      dbl_mb(k_invsp2c_cmp),
152     &      l_block_size,
153     &      int_mb(k_invsp2c_lindx))
154c
155* free up recursion copy of transformation matricies
156      if (.not.ma_free_heap(h_sp2c)) call errquit
157     &    ('spcart_init: free heap failed (array) ',911, MEM_ERR)
158      active_sp2c = .false.
159      k_sp2c = 0
160      h_sp2c = 0
161c
162*      do lval=0,Lmaxin
163*        write(6,*)' after '
164*        call spcart_print_dtrans(lval)
165*        call spcart_print_invdtrans(lval)
166*      enddo
167c
168      sph_cart_init = Sph_Cart_Init_Value
169      lmax_init = lmaxin
170      spcart_init = .true.
171c
172Cedo#if defined(LINUX)
173Cedo      trust_dgemm = .true.
174Cedo#endif
175c
176      end
177*.......................................................................
178      logical function spcart_terminate()
179      implicit none
180#include "mafdecls.fh"
181#include "errquit.fh"
182#include "spcartP.fh"
183c
184c terminates spcart data structure and initialization
185c
186      if (sph_cart_init.eq.SPH_CART_INIT_VALUE) then
187        spcart_terminate = .true.
188        if (active_sp2c) then
189          spcart_terminate = spcart_terminate .and.
190     &        ma_free_heap(h_sp2c)
191          active_sp2c = .false.
192          k_sp2c = 0
193          h_sp2c = 0
194        endif
195        if (active_sp2c_cmp) then
196          spcart_terminate = spcart_terminate .and.
197     &        ma_free_heap(h_sp2c_cmp)
198          active_sp2c_cmp = .false.
199          k_sp2c_cmp = 0
200          h_sp2c_cmp = 0
201        endif
202        if (active_sp2c_lindx) then
203          spcart_terminate = spcart_terminate .and.
204     &        ma_free_heap(h_sp2c_lindx)
205          active_sp2c_lindx = .false.
206          k_sp2c_lindx = 0
207          h_sp2c_lindx = 0
208        endif
209        if (active_invsp2c_cmp) then
210          spcart_terminate = spcart_terminate .and.
211     &        ma_free_heap(h_invsp2c_cmp)
212          active_invsp2c_cmp = .false.
213          k_invsp2c_cmp = 0
214          h_invsp2c_cmp = 0
215        endif
216        if (active_invsp2c_lindx) then
217          spcart_terminate = spcart_terminate .and.
218     &        ma_free_heap(h_invsp2c_lindx)
219          active_invsp2c_lindx = .false.
220          k_invsp2c_lindx = 0
221          h_invsp2c_lindx = 0
222        endif
223        if (active_cart_norm_scale) then
224          spcart_terminate = spcart_terminate .and.
225     &        ma_free_heap(h_cart_norm_scale)
226          active_cart_norm_scale = .false.
227          k_cart_norm_scale = 0
228          h_cart_norm_scale = 0
229        endif
230        if (.not.spcart_terminate) call errquit
231     &      (' error freeing heap in spcart_terminate',911, MEM_ERR)
232        sph_cart_init = 0
233        trust_dgemm = .false.
234      else
235        spcart_terminate = .false.
236      endif
237      end
238*.......................................................................
239      subroutine xlm_coeff_full(Ld,D,normalize)
240      implicit none
241*   not implemented yet
242      integer Ld
243      double precision D(*)
244      logical normalize
245      end
246*.......................................................................
247* set up pointer information
248      subroutine xlm_ptrs(Ld,D,Dcmp,ldcmp,Dindex)
249      implicit none
250#include "stdio.fh"
251#include "errquit.fh"
252#include "mafdecls.fh"
253#include "spcartP.fh"
254c
255c::passed
256      integer Ld        ! [input] Lmax for how spcart_* was initialized
257      integer ldcmp     ! [input] length of compressed transformation
258*                                 arrays
259*
260*. . . . . . . . . . . . . . . . . . . . ! [input] transformation matrix
261      double precision D((((Ld+1)*(Ld+2))/2),-Ld:Ld,0:Ld)
262c
263      double precision Dcmp(ldcmp)  ! [output] compressed transformation
264*                                              arrays
265*
266      integer Dindex(0:Ld)          ! [output] pointer for lth transform
267*                                              array in compressed array
268c
269c::local
270      integer lval, isp, icart
271      integer icount
272c
273      if (sph_cart_allsph) call errquit
274     &      ('xlm_ptrs: all spherical components not working yet',911,
275     &      MEM_ERR)
276c
277c
278      icount = 0
279      do 00100 lval = 0,Ld
280        Dindex(lval) = k_sp2c_cmp + icount ! set pointer in index array
281        do 00200 isp = -lval,lval
282          do 00300 icart = 1,(((lval+1)*(lval+2))/2)
283            icount = icount + 1
284            Dcmp(icount) = D(icart,isp,lval) ! form separate D(xyz,sph)
285*                                              arrays
28600300     continue
28700200   continue
28800100 continue
289*      call spcart_print_both(D,ld)
290      end
291*.......................................................................
292* set up pointer information for inverse array
293      subroutine xlm_ptrsinv(Ld,Dinvcmp,lDinvcmp,Dindex)
294      implicit none
295#include "stdio.fh"
296#include "errquit.fh"
297#include "mafdecls.fh"
298#include "spcartP.fh"
299c
300c::passed
301      integer Ld       ! [input] Lmax for how spcart_* was initialized
302      integer lDinvcmp ! [input] length of compressed inverse
303*                                transformation arrays
304*
305      double precision Dinvcmp(lDinvcmp) ! [output] compressed inverse
306*                                                   transformation
307*                                                   arrays
308*
309      integer Dindex(0:Ld) ! [output] pointer for lth inverse transform
310*                                     array in compressed array
311c
312c::local
313      integer lval, ld2s, icount, l2s
314      integer k_ov, h_ov, k_scr, h_scr
315c
316      if (sph_cart_allsph) call errquit
317     &      ('xlm_ptrs: all spherical components not working yet',911,
318     &      UNKNOWN_ERR)
319c
320      ld2s = (((ld+1)*(ld+2))/2)
321      if (.not.ma_push_get(mt_dbl,ld2s*ld2s,
322     &    'xlm_ptrsinv overlap',h_ov,k_ov)) call errquit
323     &    ('xlm_ptrsinv: could not allocate overlap',911, MEM_ERR)
324      call dcopy((ld2s*ld2s),0.0d00,0,dbl_mb(k_ov),1)
325      if (.not.ma_push_get(mt_dbl,ld2s*(2*ld+1),
326     &    'xlm_ptrsinv scratch',h_scr,k_scr)) call errquit
327     &    ('xlm_ptrsinv: could not allocate scratch',911, MEM_ERR)
328      call dcopy((ld2s*(2*ld+1)),0.0d00,0,dbl_mb(k_scr),1)
329      icount = 1
330      do 00100 lval = 0,Ld
331        Dindex(lval) =
332     &        k_invsp2c_cmp + icount - 1 ! set pointer in index array
333        l2s = (((lval+1)*(lval+2))/2)
334        call spcart_cart_overlap(lval,l2s,dbl_mb(k_ov))
335*        write(6,*)' xlm_ptrsinv verify 1', l2s, lval
336*        if (.not. ma_verify_allocator_stuff()) stop ' xlm_ptrsinv'
337        call xlm_ptrsinva(l2s,lval,dbl_mb(k_ov),Dinvcmp(icount),
338     &      dbl_mb(k_scr))
339*        write(6,*)' xlm_ptrsinv verify 2', l2s, lval
340*        if (.not. ma_verify_allocator_stuff()) stop ' xlm_ptrsinv'
341        icount = icount + l2s*(2*lval+1)
34200100 continue
343      if (.not.ma_pop_stack(h_scr)) call errquit
344     &      ('xlm_ptrsinv: could not pop_stack for overlap',911,
345     &      MEM_ERR)
346      if (.not.ma_pop_stack(h_ov)) call errquit
347     &      ('xlm_ptrsinv: could not pop_stack for overlap',911,
348     &      MEM_ERR)
349      end
350*.......................................................................
351      subroutine xlm_ptrsinva(l2s,lval,overlap,Dinv,scr)
352      implicit none
353#include "mafdecls.fh"
354#include "spcartP.fh"
355      integer l2s,lval
356      double precision Dinv(-lval:lval,l2s)
357      double precision scr(-lval:lval,l2s)
358      double precision overlap(l2s,l2s)
359      integer s,c1, c2
360      double precision val
361c::statement function ----- start
362      integer iic,iis,iil
363      double precision Dtrans
364      Dtrans(iic,iis,iil) =
365     &      dbl_mb((int_mb(k_sp2c_lindx+iil))+
366     &      ((iis+iil)*(iil+1)*(iil+2)/2)
367     &      + iic - 1)
368c::statement function ----- end
369
370* transpose Dtrans
371      do s = -lval,lval
372        do c1 = 1,l2s
373          scr(s,c1) = Dtrans(c1,s,lval)
374          Dinv(s,c1) = 0.0d00
375        enddo
376      enddo
377*      write(6,*)' inside forming Dinv '
378*      call spcart_print_dtrans(lval)
379*      write(6,*)' transpose scr '
380*      call output(scr,1,(2*lval+1),1,l2s,(2*lval+1),l2s,1)
381* Dinv(sph,cart) = [Dtrans(cart,sph]^+ overlap(cart,cart)
382* Dinv(sph,cart) = scr(sph,cart)*overlap(cart,cart)
383      do s = -lval,lval
384        do c1 = 1,l2s
385          val = 0.0d00
386          do c2 = 1,l2s
387             val = val + scr(s,c2)*overlap(c2,c1)
388          enddo
389          Dinv(s,c1) = val
390        enddo
391      enddo
392c
393*      call dgemm('n','n',
394*     &    (2*lval+1),(2*lval+1),l2s,
395*     &    1.0d00,
396*     &    Dinv,(2*lval+1),
397*     &    dbl_mb(((int_mb(k_sp2c_lindx+lval)))),l2s,
398*     &    0.0d00,scr,(2*lval+1))
399*      write(6,*)' dinv*d'
400*      call output(scr,1,(2*lval+1),1,(2*lval+1),(2*lval+1),(2*lval+1),1)
401      end
402*.......................................................................
403      subroutine xlm_cart_norm_scale(Ld,D,cart_scale)
404      implicit none
405c::passed
406      integer Ld        ! [input] Lmax for how spcart_* was initialized
407      double precision
408     &      D((((Ld+1)*(Ld+2))/2),-Ld:Ld,0:Ld) ! [input] transformation
409*                                                        matrix
410      double precision cart_scale(-Ld:Ld,0:Ld)
411c::local
412      integer l,c,s,l2s
413      double precision norm
414      call dcopy ((2*Ld+1)*(Ld+1),0.0d00,0,cart_scale,1)
415
416      do l = 0,Ld
417        l2s = (l+1)*(l+2)/2
418        do s = (-l),l
419          norm = 0.0d00
420          do c = 1,l2s
421            norm = norm + D(c,s,l)*D(c,s,l)
422          enddo
423*          write(6,*)'norm', norm, '  l,s,c',l,s,c
424*          if (norm.gt.1.0d-10) then
425          norm = sqrt(1.0d00/norm)
426*          else
427*            write(6,*)'scarry norm', norm, '  l,s,c',l,s,c
428*            norm = 1.0d00
429*          endif
430          cart_scale(s,l) = norm
431        enddo
432      enddo
433      end
434*.......................................................................
435*rak:      subroutine xlm_ptrs_phase(Dp,l2p,lp)
436*rak:      implicit none
437*rak:      integer l2p, lp
438*rak:      double precision Dp(l2p,-lp:lp)
439*rak:      integer lc, ls
440*rak:      logical scale_it
441*rak:      double precision dmaxval
442*rak:      integer dmaxindx
443*rak:c
444*rak:      do ls = -lp,lp
445*rak:        scale_it = .false.
446*rak:        dmaxval  = abs(Dp(1,ls))
447*rak:        dmaxindx = 1
448*rak:        do lc = 2,l2p
449*rak:          if (dmaxval.lt.abs(Dp(lc,ls))) then
450*rak:            dmaxval = abs(Dp(lc,ls))
451*rak:            dmaxindx = lc
452*rak:          endif
453*rak:        enddo
454*rak:        if (Dp(dmaxindx,ls).lt.0.0d00) scale_it = .true.
455*rak:c
456*rak:        if (scale_it) then
457*rak:          do lc = 1,l2p
458*rak:            Dp(lc,ls) = -1.0d00*Dp(lc,ls)
459*rak:          enddo
460*rak:        endif
461*rak:      enddo
462*rak:      end
463*.......................................................................
464      subroutine xlm_ptrs_fix_p(Dp,l2p,lp)
465      implicit none
466#include "errquit.fh"
467      integer l2p,lp
468      integer count_val, lc, ls
469      double precision Dp(l2p,-lp:lp)
470c
471      double precision dpdp(3)
472c
473      count_val = 0
474      do ls = -lp,lp
475        do lc = 1,l2p
476          if (Dp(lc,ls).ne.0.0d00) then
477            count_val = count_val + 1
478            if (count_val.gt.3) then
479              write(6,*)' count_val range is 1<3'
480              write(6,*)' count_val out of range ',count_val
481              call errquit('fix p: error',911, MEM_ERR)
482            endif
483            dpdp(count_val) = Dp(lc,ls)
484*            if (dpdp(count_val).lt.0.0d00)
485*     &            dpdp(count_val) = -dpdp(count_val)
486          endif
487          Dp(lc,ls) = 0.0d00
488        enddo
489      enddo
490      Dp(1,-1) = dpdp(1)
491      Dp(2, 0) = dpdp(2)
492      Dp(3, 1) = dpdp(3)
493c
494      end
495*.......................................................................
496*rak:      subroutine spcart_print_both(D,ld)
497*rak:      implicit none
498*rak:#include "mafdecls.fh"
499*rak:#include "errquit.fh"
500*rak:#include "spcartP.fh"
501*rak:      integer ld
502*rak:      double precision D((((Ld+1)*(Ld+2))/2),-Ld:Ld,0:Ld) ! [input] transformation matrix
503*rak:c
504*rak:      integer lval,l2s, ic, is
505*rak:      double precision diff
506*rak:c::statement function ----- start
507*rak:      integer iic,iis,iil
508*rak:      double precision Dtrans
509*rak:      Dtrans(iic,iis,iil) =
510*rak:     &    dbl_mb((int_mb(k_sp2c_lindx+iil))+
511*rak:     &           ((iis+iil)*(iil+1)*(iil+2)/2)
512*rak:     &           + iic - 1)
513*rak:c::statement function ----- end
514*rak:c
515*rak:      do lval = 0,ld
516*rak:        write(6,*)' d matrix '
517*rak:        l2s = (lval+1)*(lval+2)/2
518*rak:        do is = -lval,lval
519*rak:          do ic = 1,l2s
520*rak:            diff = D(ic,is,lval)-Dtrans(ic,is,lval)
521*rak:            write(6,*)
522*rak:     &            lval,is,ic,D(ic,is,lval),Dtrans(ic,is,lval),diff
523*rak:          enddo
524*rak:        enddo
525*rak:      enddo
526*rak:      end
527*.......................................................................
528      subroutine spcart_print_dtrans(ld)
529      implicit none
530#include "mafdecls.fh"
531#include "spcartP.fh"
532      integer ld
533c
534      write(6,*)' spcart trans matrix used for Lval =',ld
535      call output(dbl_mb((int_mb(k_sp2c_lindx+ld))),1,
536     &    ((ld+1)*(ld+2)/2),1,(2*ld+1),
537     &    ((ld+1)*(ld+2)/2),(2*ld+1),1)
538      end
539*.......................................................................
540      subroutine spcart_print_invdtrans(ld)
541      implicit none
542#include "mafdecls.fh"
543#include "errquit.fh"
544#include "spcartP.fh"
545      integer ld
546c
547      write(6,*)' spcart inverse trans matrix used for Lval =',ld
548      call output(dbl_mb((int_mb(k_invsp2c_lindx+ld))),1,
549     &    (2*ld+1),1,((ld+1)*(ld+2)/2),
550     &    (2*ld+1),((ld+1)*(ld+2)/2),1)
551      end
552*.......................................................................
553      integer function spcart_trns_ptr(lval,lcart,lsp)
554c return pointer in ma to transformation matrix for lval
555      implicit none
556#include "errquit.fh"
557#include "mafdecls.fh"
558#include "spcartP.fh"
559
560      integer lval  ! [input] l-value of requested matrix
561      integer lcart ! [output] number of cartesian components
562      integer lsp   ! [output] number of spherical components
563c
564      if (sph_cart_init.ne.SPH_CART_INIT_VALUE) call errquit
565     &    ('spcart_trns_ptr: spcart not initialized properly',
566     &    sph_cart_init, MEM_ERR)
567c
568      spcart_trns_ptr = int_mb(k_sp2c_lindx+lval)
569      lcart = ((lval+1)*(lval+2))/2
570      if (sph_cart_allsph) then
571        lsp = lcart
572      else
573        lsp = 2*lval+1
574      endif
575      end
576*.......................................................................
577      Block data bd_spcart
578
579#include "spcartP.fh"
580
581      data h_sp2c            /0/
582      data k_sp2c            /0/
583      data h_sp2c_cmp        /0/
584      data k_sp2c_cmp        /0/
585      data h_invsp2c_cmp     /0/
586      data k_invsp2c_cmp     /0/
587      data lmax_init         /0/
588      data h_cart_norm_scale /0/
589      data k_cart_norm_scale /0/
590      data sph_cart_init     /0/
591      data h_sp2c_lindx      /0/
592      data k_sp2c_lindx      /0/
593      data h_invsp2c_lindx   /0/
594      data k_invsp2c_lindx   /0/
595      data sph_cart_allsph        /.false./
596      data active_sp2c            /.false./
597      data active_sp2c_cmp        /.false./
598      data active_invsp2c_cmp     /.false./
599      data active_sp2c_lindx      /.false./
600      data active_invsp2c_lindx   /.false./
601      data active_cart_norm_scale /.false./
602      data trust_dgemm            /.false./
603      end
604*.......................................................................
605      subroutine spcart_a_s(blockin, blockout, ndima, ls,
606     &      ngls, in_place, print_info)
607      implicit none
608c
609c  transforms a block of integrals with the Ls function is the slowest
610c  dimension: e.g., blockin(ndima,L2s,ngls)
611c
612#include "mafdecls.fh"
613#include "errquit.fh"
614#include "spcartP.fh"
615c
616c: passed
617      integer ndima  ! [input] leading dimension of block
618      integer ls     ! [input] angular momentum of block
619      integer ngls   ! [input] general contraction length of ls block
620      double precision
621     &      blockin (ndima,((ls+1)*(ls+2)/2),ngls) ! [input] matrix
622      double precision
623     &      blockout(ndima,-ls:ls,ngls) ! [output] matrix
624      logical
625     &      in_place ! [input] true if blockin and block out are
626*                              the same pointer
627      logical print_info ! [input] print info
628c: local
629      double precision sumg
630      integer i,j,k,g
631      integer L2s
632c::statement function ----- start
633      integer iic,iis,iil
634      double precision Dtrans
635      Dtrans(iic,iis,iil) =
636     &    dbl_mb((int_mb(k_sp2c_lindx+iil))+
637     &           ((iis+iil)*(iil+1)*(iil+2)/2)
638     &           + iic - 1)
639c::statement function ----- end
640c
641*rak:      write(6,*)'a_s,(ndima,l2s) ndima = ',ndima,'   ls = ',ls
642*rak:      write(6,*)' trans matrix used '
643*rak:      call output(dbl_mb((int_mb(k_sp2c_lindx+ls))),1,
644*rak:     &    ((ls+1)*(ls+2)/2),1,(2*ls+1),
645*rak:     &    ((ls+1)*(ls+2)/2),(2*ls+1),1)
646c
647      if (sph_cart_init.ne.SPH_CART_INIT_VALUE) call errquit
648     &    ('spcart_a_s: spcart not initialized properly',
649     &    sph_cart_init, UNKNOWN_ERR)
650c
651      if (ls.lt.2) then
652c...        ((ls+1)*(ls+2)/2)) = 2*ls + 1
653        call dcopy((ndima*(2*ls+1)*ngls),blockin,1,blockout,1)
654        return
655CBERT else
656CBERT   call dcopy((ndima*(2*ls+1)*ngls),0.0d00,0,blockout,1)
657      endif
658c
659      if (in_place) then
660        write (6,*)' in place transformations are not ready yet '
661      endif
662c
663*      call spcart_print_Dtrans(ls)
664c
665      if (ls.eq.2) then
666        call spcart_a_sd(blockin,blockout,ndima,ngls,
667     &      in_place,print_info)
668        return
669      else if (ls.eq.3) then
670        call spcart_a_sf(blockin,blockout,ndima,ngls,
671     &      in_place,print_info)
672        return
673      else if (ls.eq.4) then
674        call spcart_a_sg(blockin,blockout,ndima,ngls,
675     &      in_place,print_info)
676        return
677      else if (ls.eq.5) then
678        call spcart_a_sh(blockin,blockout,ndima,ngls,
679     &      in_place,print_info)
680        return
681      endif
682c
683c
684c:old<dgemm call for blockin(ndima,l2s)*dtrans(l2s,2l+1) =
685*                                                  blockout(ndima,2l+1)>
686c dgemm call for blockin(ndima,l2s,ngls)*dtrans(l2s,2l+1) =
687*                                             blockout(ndima,2l+1,ngls)
688c
689      L2s = ((ls+1)*(ls+2)/2)
690      if (trust_dgemm) then
691        do  g=1,ngls
692          call dgemm('n','n',ndima,(2*ls+1),L2s,1.0d00,
693     &          blockin(1,1,g),ndima,
694     &          dbl_mb(int_mb(k_sp2c_lindx+Ls)),L2s,
695     &          0.0d00,blockout(1,1,g),ndima)
696        enddo
697        return
698      endif
699c
700c
701c  blockout(ndima,2l+1,ngls) =
702*                       blockin(ndima,l2s,ngls)*d_spcart(l2s,2l+1,lp=ls)
703c
704      call dcopy((ndima*(2*ls+1)*ngls),0.0d00,0,blockout,1)
705      L2s = ((ls+1)*(ls+2)/2)
706      do g = 1,ngls
707        do j=(-ls),ls
708          do i=1,ndima
709            sumg = 0.0d00
710            do k = 1,L2s
711              sumg = sumg + blockin(i,k,g)*Dtrans(k,j,Ls)
712            enddo
713            blockout(i,j,g) = sumg
714          enddo
715        enddo
716      enddo
717      end
718*.......................................................................
719C>
720C> \brief Transform a block of 1-electron integrals with angular
721C> momentum <i>ls</i>
722C>
723C> This routine transforms integrals of a specific angular momentum
724C> <i>ls</i>, where <i>ls</i> specifies the leading dimension. As the
725C> required transformation is different for different angular momenta
726C> this routine essentially figures out which transformation routine to
727C> call for the given angular momentum.
728C>
729      subroutine spcart_s_a(blockin, blockout, ndima,
730     &      ls, ngls, in_place, print_info)
731      implicit none
732c
733c  transforms a block of "integrals" with the ls function is the
734c  leading dimension; e.g., blockin(L2s,ndima)
735c
736#include "mafdecls.fh"
737#include "errquit.fh"
738#include "spcartP.fh"
739c
740c: passed
741      integer ndima  !< [Input] leading dimension of block
742      integer ls     !< [Input] angular momentum of block
743      integer ngls   !< [Input] general contraction length of ls block
744      double precision
745     &      blockin (((ls+1)*(ls+2)/2),ngls,ndima) !< [Input] Cartesian
746                                                   !< integrals
747      double precision
748     &      blockout(-ls:ls,ngls,ndima) !< [Output] spherical harmonic
749                                        !< integrals
750      logical in_place   !< [Input] true if blockin and block out are
751                         !< the same pointer
752      logical print_info !< [Input] print info
753c: local
754      integer i,j,k,g
755      integer L2s
756c::statement function ----- start
757      integer iic,iis,iil
758      double precision Dtrans
759      Dtrans(iic,iis,iil) =
760     &    dbl_mb((int_mb(k_sp2c_lindx+iil))+
761     &           ((iis+iil)*(iil+1)*(iil+2)/2)
762     &           + iic - 1)
763c::statement function ----- end
764c
765*rak:      write(6,*)'s_a,(l2s,ndima) ndima = ',ndima,'   ls = ',ls
766*rak:      write(6,*)' trans matrix used '
767*rak:      call output(dbl_mb((int_mb(k_sp2c_lindx+ls))),1,
768*rak:     &    ((ls+1)*(ls+2)/2),1,(2*ls+1),
769*rak:     &    ((ls+1)*(ls+2)/2),(2*ls+1),1)
770c
771      if (sph_cart_init.ne.SPH_CART_INIT_VALUE) call errquit
772     &    ('spcart_s_a: spcart not initialized properly',
773     &    sph_cart_init, UNKNOWN_ERR)
774c
775      if (ls.lt.2) then
776c...        ((ls+1)*(ls+2)/2)) = 2*ls + 1
777        call dcopy((ndima*(2*ls+1)*ngls),blockin,1,blockout,1)
778        return
779CBERT else
780CBERT   call dcopy((ndima*(2*ls+1)*ngls),0.0d00,0,blockout,1)
781      endif
782c
783      if (in_place) then
784        write (6,*)' in place transformations are not ready yet '
785      endif
786c
787*      call spcart_print_Dtrans(ls)
788c
789      if (ls.eq.2) then
790        call spcart_sd_a(blockin,blockout,ndima,ngls,
791     &      in_place,print_info)
792        return
793      else if (ls.eq.3) then
794        call spcart_sf_a(blockin,blockout,ndima,ngls,
795     &      in_place,print_info)
796        return
797      else if (ls.eq.4) then
798        call spcart_sg_a(blockin,blockout,ndima,ngls,
799     &      in_place,print_info)
800        return
801      else if (ls.eq.5) then
802        call spcart_sh_a(blockin,blockout,ndima,ngls,
803     &      in_place,print_info)
804        return
805      endif
806      if (ngls.eq.1 .and. trust_dgemm) then
807c
808c only works for ngls = 1 right now
809c dgemm call for:
810c  Transpose(d_spcart(l2s,2l+1))*blockin(l2s,ndima) =
811*                                                   blockout(2l+1,ndima)
812c
813        L2s = ((ls+1)*(ls+2)/2)
814        call dgemm('t','n',(2*ls+1),ndima,L2s,1.0d00,
815     &        dbl_mb(int_mb(k_sp2c_lindx+Ls)),L2s,
816     &        blockin,L2s,0.0d00,blockout,(2*ls+1))
817        return
818      endif
819c
820c blockout(2l+1,ngls,ndima) =
821*                       blockin(l2s,ngls,ndima)*d_spcart(l2s,2l+1,lp=ls)
822c
823      L2s = ((ls+1)*(ls+2)/2)
824      call dcopy((ndima*(2*ls+1)*ngls),0.0d00,0,blockout,1)
825      do j=1,ndima
826        do g=1,ngls
827          do i=(-ls),ls
828            do k = 1,L2s
829              blockout(i,g,j) = blockout(i,g,j) +
830     &              blockin(k,g,j)*Dtrans(k,i,Ls)
831            enddo
832          enddo
833        enddo
834      enddo
835      end
836*.......................................................................
837      subroutine spcart_a_s_b(blockin, blockout, ndima, ndimb,
838     &      ls, ngls,
839     &      in_place,print_info)
840      implicit none
841c
842c  transforms a block of "integrals" with the ls function is ordered
843c  between a leading dimension and trailing dimension.
844c  e.g., blockin(nidima,L2s,ndimb)
845c
846#include "mafdecls.fh"
847#include "errquit.fh"
848#include "spcartP.fh"
849c
850c: passed
851      integer ndima  ! [input] leading dimension of block
852      integer ndimb  ! [input] tailing dimension of block
853      integer ls     ! [input] angular momentum of block
854      integer ngls   ! [input] general contraction length of ls block
855      double precision blockin (ndima,((ls+1)*(ls+2)/2),ngls,ndimb)
856*                                                      ! [input] matrix
857*
858      double precision
859     &      blockout(ndima,-ls:ls,ngls,ndimb) ! [output] matrix
860      logical
861     &      in_place     ! [input] true if blockin and blockout are
862*                                  the same pointer
863*
864      logical print_info ! [input] print info
865c: local
866      integer i,j,k,g
867      integer m
868      integer L2s
869c::statement function ----- start
870      integer iic,iis,iil
871      double precision Dtrans
872      Dtrans(iic,iis,iil) =
873     &    dbl_mb((int_mb(k_sp2c_lindx+iil))+
874     &           ((iis+iil)*(iil+1)*(iil+2)/2)
875     &           + iic - 1)
876c::statement function ----- end
877c
878*rak:      write(6,*)'a_s,(ndima,l2s,ndimb) ndima = ',ndima,
879*rak:     &      '   ls = ',ls,'  ndimb = ',ndimb
880*rak:      write(6,*)' trans matrix used '
881*rak:      call output(dbl_mb((int_mb(k_sp2c_lindx+ls))),1,
882*rak:     &    ((ls+1)*(ls+2)/2),1,(2*ls+1),
883*rak:     &    ((ls+1)*(ls+2)/2),(2*ls+1),1)
884c
885      if (sph_cart_init.ne.SPH_CART_INIT_VALUE) call errquit
886     &    ('spcart_a_s_b: spcart not initialized properly',
887     &    sph_cart_init, UNKNOWN_ERR)
888c
889      if (ls.lt.2) then
890c...        ((ls+1)*(ls+2)/2)) = 2*ls + 1
891        call dcopy((ndima*ndimb*(2*ls+1)*ngls),blockin,1,blockout,1)
892        return
893CBERT else
894CBERT   call dcopy((ndima*ndimb*(2*ls+1)*ngls),0.0d00,0,blockout,1)
895      endif
896c
897      if (in_place) then
898        write (6,*)' in place transformations are not ready yet '
899      endif
900c
901*      call spcart_print_Dtrans(ls)
902c
903      if (ls.eq.2) then
904        call spcart_a_sd_b(blockin,blockout,ndima,ndimb,ngls,
905     &      in_place,print_info)
906        return
907      else if (ls.eq.3) then
908        call spcart_a_sf_b(blockin,blockout,ndima,ndimb,ngls,
909     &      in_place,print_info)
910        return
911      else if (ls.eq.4) then
912        call spcart_a_sg_b(blockin,blockout,ndima,ndimb,ngls,
913     &      in_place,print_info)
914        return
915      else if (ls.eq.5) then
916        call spcart_a_sh_b(blockin,blockout,ndima,ndimb,ngls,
917     &      in_place,print_info)
918        return
919      endif
920c
921      if (ngls.eq.1 .and. trust_dgemm) then
922c
923c dgemm for all ndimb only if ngls == 1
924c
925        L2s = ((ls+1)*(ls+2)/2)
926        do m = 1,ndimb
927          call dgemm('n','n',ndima,(2*ls+1),L2s,
928     &          1.0d00,blockin(1,1,1,m),ndima,
929     &          dbl_mb(int_mb(k_sp2c_lindx+Ls)),L2s,
930     &          0.0d00,blockout(1,1,1,m),ndima)
931        enddo
932        return
933      endif
934c
935      call dcopy((ndima*ndimb*(2*ls+1)*ngls),0.0d00,0,blockout,1)
936      L2s = ((ls+1)*(ls+2)/2)
937      do  m = 1,ndimb
938        do  g=1,ngls
939          do  j=(-ls),ls
940            do  k = 1,L2s
941              do  i=1,ndima
942                blockout(i,j,g,m) = blockout(i,j,g,m) +
943     &                blockin(i,k,g,m)*Dtrans(k,j,Ls)
944              enddo
945            enddo
946          enddo
947        enddo
948      enddo
949      end
950*.......................................................................
951      subroutine spcart_a_sd(blockin, blockout, ndima, ngls,
952     &    in_place, print_info)
953      implicit none
954c
955c  transforms a block of integrals where the d function is the slowest
956c  dimension; e.g., blockin(ndima,6) and blockout(ndima,5)
957c
958#include "mafdecls.fh"
959#include "errquit.fh"
960#include "spcartP.fh"
961c
962c: passed
963      integer ndima  ! [input] leading dimension of block
964      integer ngls   ! [input] general contraction length of ls block
965      double precision blockin (ndima,6,ngls)    ! [input] matrix
966      double precision blockout(ndima,-2:2,ngls) ! [output] matrix
967      logical
968     &      in_place     ! [input] true if blockin and block out are
969*                                  the same pointer
970*
971      logical print_info ! [input] print info
972c: local
973      integer i,g
974*rak:      integer ls     ! [fixed at 2] angular momentum of block
975      double precision dt2m2, dt5m1, dt10, dt40, dt60, dt31, dt12, dt42
976      double precision bin1, bin2, bin3, bin4, bin5, bin6
977      double precision sinm2, sinm1, sin0, sinp1, sinp2
978      logical print_debug
979c::statement function ----- start
980      integer iic,iis,iil
981      double precision Dtrans
982      Dtrans(iic,iis,iil) =
983     &    dbl_mb((int_mb(k_sp2c_lindx+iil))+
984     &           ((iis+iil)*(iil+1)*(iil+2)/2)
985     &           + iic - 1)
986c::statement function ----- end
987      print_debug = .true.
988c
989      if (print_info.and.print_debug) then
990        write(6,*)' insize spcart_a_sd'
991        write(6,*)' spcart_a_sd:ndima = ',ndima
992        write(6,*)' spcart_a_sd:ngls  = ',ngls
993      endif
994      if (print_info) call spcart_print_dtrans(2)
995c
996*rak:      ls=2
997*rak:      write(6,*)'a_s,(ndima,l2s) ndima = ',ndima,'   ls = ',ls
998*rak:      write(6,*)' trans matrix used '
999*rak:      call output(dbl_mb((int_mb(k_sp2c_lindx+ls))),1,
1000*rak:     &    ((ls+1)*(ls+2)/2),1,(2*ls+1),
1001*rak:     &    ((ls+1)*(ls+2)/2),(2*ls+1),1)
1002c
1003      if (sph_cart_init.ne.SPH_CART_INIT_VALUE) call errquit
1004     &    ('spcart_a_sd: spcart not initialized properly',
1005     &    sph_cart_init, UNKNOWN_ERR)
1006c
1007      if (in_place) then
1008        write (6,*)' in place transformations are not ready yet '
1009      endif
1010c  spint(-2) = cint(2)*dtrans(2,-2,2)
1011c  spint(-1) = cint(5)*dtrans(5,-1,2)
1012c  spint( 0) = cint(1)*dtrans(1,0,2) + cint(4)*dtrans(4,0,2)
1013*              + cint(6)*dtrans(6,0,2)
1014c  spint( 1) = cint(3)*dtrans(3,1,2)
1015c  spint( 2) = cint(1)*dtrans(1,2,2) + cint(4)*dtrans(4,2,2)
1016      dt2m2 = dtrans(2,-2,2)
1017      dt5m1 = dtrans(5,-1,2)
1018      dt10  = dtrans(1, 0,2)
1019      dt40  = dtrans(4, 0,2)
1020      dt60  = dtrans(6, 0,2)
1021      dt31  = dtrans(3, 1,2)
1022      dt12  = dtrans(1, 2,2)
1023      dt42  = dtrans(4, 2,2)
1024      do g=1,ngls
1025        do i=1,ndima
1026#ifdef DEBUG
1027          if (print_info.and.print_debug)
1028     &        write(6,*)' spcart_a_sd:g,i',g,i
1029#endif
1030          bin1 = blockin(i,1,g)
1031          bin4 = blockin(i,4,g)
1032#ifdef DEBUG
1033          if (print_info.and.print_debug) then
1034            write(6,11111)' spcart_a_sd:cart ints 1 xx',bin1,g,i
1035            write(6,11111)' spcart_a_sd:cart ints 2 xy',bin2,g,i
1036            write(6,11111)' spcart_a_sd:cart ints 3 xz',bin3,g,i
1037            write(6,11111)' spcart_a_sd:cart ints 4 yy',bin4,g,i
1038            write(6,11111)' spcart_a_sd:cart ints 6 zz',bin6,g,i
1039          endif
1040#endif
1041          blockout(i,-2,g) = blockin(i,2,g)*dt2m2
1042          blockout(i,-1,g) = blockin(i,5,g)*dt5m1
1043          blockout(i, 0,g) = bin1*dt10+bin4*dt40+blockin(i,6,g)*dt60
1044          blockout(i, 1,g) = blockin(i,3,g)*dt31
1045          blockout(i, 2,g) = bin1*dt12+bin4*dt42
1046#ifdef DEBUG
1047          if (print_info.and.print_debug) then
1048            write(6,11111)' spcart_a_sd:sph ints -2',sinm2,g,i
1049            write(6,11111)' spcart_a_sd:sph ints -1',sinm1,g,i
1050            write(6,11111)' spcart_a_sd:sph ints  0',sin0,g,i
1051            write(6,11111)' spcart_a_sd:sph ints +1',sinp1,g,i
1052            write(6,11111)' spcart_a_sd:sph ints +2',sinp2,g,i
1053          endif
1054#endif
1055        enddo
1056      enddo
1057      if (print_info.and.print_debug)
1058     &    write(6,*)' exiting spcart_a_sd'
105911111 format(1x,a,1pd20.10,i5,i5)
1060      end
1061*.......................................................................
1062C>
1063C> \brief Transforms a block of 1-electron integrals of D-functions
1064C>
1065C> This routine transforms a block of integrals where the functions
1066C> corresponding to the leading dimension are Cartesian D-functions
1067C> on input and spherical harmonic D-functions on output.
1068C>
1069      subroutine spcart_sd_a(blockin, blockout, ndima, ngls,
1070     &    in_place, print_info)
1071      implicit none
1072c
1073c  transforms a block of integrals where the d function is the fastest
1074c  dimension; e.g., blockin(6,ndima) and blockout(5,ndima)
1075c
1076#include "mafdecls.fh"
1077#include "errquit.fh"
1078#include "spcartP.fh"
1079c
1080c: passed
1081      integer ndima  !< [Input] leading dimension of block
1082      integer ngls   !< [Input] general contraction length of ls block
1083      double precision blockin (6,ngls,ndima)    !< [Input] matrix
1084      double precision blockout(-2:2,ngls,ndima) !< [Output] matrix
1085      logical in_place   !< [Input] true if blockin and block out are
1086                         !< the same pointer
1087      logical print_info !< [Input] print info
1088c: local
1089      integer i,g
1090*rak:      integer ls     ! [fixed at 2] angular momentum of block
1091      double precision dt2m2, dt5m1, dt10, dt40, dt60, dt31, dt12, dt42
1092      double precision bin1, bin2, bin3, bin4, bin5, bin6
1093      double precision sinm2, sinm1, sin0, sinp1, sinp2
1094c::statement function ----- start
1095      integer iic,iis,iil
1096      double precision Dtrans
1097      Dtrans(iic,iis,iil) =
1098     &    dbl_mb((int_mb(k_sp2c_lindx+iil))+
1099     &           ((iis+iil)*(iil+1)*(iil+2)/2)
1100     &           + iic - 1)
1101c::statement function ----- end
1102      if (print_info) then
1103        write(6,*)' insize spcart_sd_a'
1104        write(6,*)' spcart_sd_a:ndima = ',ndima
1105        write(6,*)' spcart_sd_a:ngls  = ',ngls
1106        call spcart_print_dtrans(2)
1107      endif
1108c
1109*rak:      ls=2
1110*rak:      write(6,*)'a_s,(ndima,l2s) ndima = ',ndima,'   ls = ',ls
1111*rak:      write(6,*)' trans matrix used '
1112*rak:      call output(dbl_mb((int_mb(k_sp2c_lindx+ls))),1,
1113*rak:     &    ((ls+1)*(ls+2)/2),1,(2*ls+1),
1114*rak:     &    ((ls+1)*(ls+2)/2),(2*ls+1),1)
1115c
1116      if (sph_cart_init.ne.SPH_CART_INIT_VALUE) call errquit
1117     &    ('spcart_sd_a: spcart not initialized properly',
1118     &    sph_cart_init, UNKNOWN_ERR)
1119c
1120      if (in_place) then
1121        write (6,*)' in place transformations are not ready yet '
1122      endif
1123c  spint(-2) = cint(2)*dtrans(2,-2,2)
1124c  spint(-1) = cint(5)*dtrans(5,-1,2)
1125c  spint( 0) = cint(1)*dtrans(1,0,2) + cint(4)*dtrans(4,0,2)
1126*              + cint(6)*dtrans(6,0,2)
1127c  spint( 1) = cint(3)*dtrans(3,1,2)
1128c  spint( 2) = cint(1)*dtrans(1,2,2) + cint(4)*dtrans(4,2,2)
1129      dt2m2 = dtrans(2,-2,2)
1130      dt5m1 = dtrans(5,-1,2)
1131      dt10  = dtrans(1, 0,2)
1132      dt40  = dtrans(4, 0,2)
1133      dt60  = dtrans(6, 0,2)
1134      dt31  = dtrans(3, 1,2)
1135      dt12  = dtrans(1, 2,2)
1136      dt42  = dtrans(4, 2,2)
1137      do i=1,ndima
1138        do g=1,ngls
1139          bin1 = blockin(1,g,i)
1140          bin2 = blockin(2,g,i)
1141          bin3 = blockin(3,g,i)
1142          bin4 = blockin(4,g,i)
1143          bin5 = blockin(5,g,i)
1144          bin6 = blockin(6,g,i)
1145          if (print_info) then
1146            write(6,11111)' spcart_sd_a:cart ints 1 xx',bin1,g,i
1147            write(6,11111)' spcart_sd_a:cart ints 2 xy',bin2,g,i
1148            write(6,11111)' spcart_sd_a:cart ints 3 xz',bin3,g,i
1149            write(6,11111)' spcart_sd_a:cart ints 4 yy',bin4,g,i
1150            write(6,11111)' spcart_sd_a:cart ints 5 yz',bin5,g,i
1151            write(6,11111)' spcart_sd_a:cart ints 6 zz',bin6,g,i
1152          endif
1153          sinm2 = bin2*dt2m2
1154          sinm1 = bin5*dt5m1
1155          sin0  = bin1*dt10 +
1156     &            bin4*dt40 +
1157     &            bin6*dt60
1158          sinp1 = bin3*dt31
1159          sinp2 = bin1*dt12 +
1160     &            bin4*dt42
1161          blockout(-2,g,i) = sinm2
1162          blockout(-1,g,i) = sinm1
1163          blockout( 0,g,i) = sin0
1164          blockout( 1,g,i) = sinp1
1165          blockout( 2,g,i) = sinp2
1166          if (print_info) then
1167            write(6,11111)' spcart_sd_a:sph ints -2',sinm2,g,i
1168            write(6,11111)' spcart_sd_a:sph ints -1',sinm1,g,i
1169            write(6,11111)' spcart_sd_a:sph ints  0',sin0,g,i
1170            write(6,11111)' spcart_sd_a:sph ints +1',sinp1,g,i
1171            write(6,11111)' spcart_sd_a:sph ints +2',sinp2,g,i
1172          endif
1173        enddo
1174      enddo
1175      if (print_info)
1176     &    write(6,*)' exiting spcart_sd_a'
117711111 format(1x,a,1pd20.10,i5,i5)
1178      end
1179*.......................................................................
1180      subroutine spcart_a_sd_b(blockin, blockout,
1181     &    ndima, ndimb, ngls, in_place, print_info)
1182      implicit none
1183c
1184c  transforms a block of integrals where the d function is the middle
1185c  dimension; e.g., blockin(ndima,6,ndimb) and blockout(ndima,5,ndimb)
1186c
1187#include "mafdecls.fh"
1188#include "errquit.fh"
1189#include "spcartP.fh"
1190c
1191c: passed
1192      integer ndima  ! [input] leading dimension of block
1193      integer ndimb  ! [input] trailing dimension of block
1194      integer ngls   ! [input] general contraction length of ls block
1195      double precision
1196     &      blockin (ndima, 6   ,ngls,ndimb) ! [input] matrix
1197      double precision
1198     &      blockout(ndima, -2:2,ngls,ndimb) ! [output] matrix
1199      logical
1200     &      in_place     ! [input] true if blockin and block out are
1201*                                  the same pointer
1202      logical print_info ! [input] print info
1203c: local
1204      integer i,j,g
1205*rak:      integer ls     ! [fixed at 2] angular momentum of block
1206      double precision dt2m2, dt5m1, dt10, dt40, dt60, dt31, dt12, dt42
1207      double precision bin1, bin2, bin3, bin4, bin5, bin6
1208      double precision sinm2, sinm1, sin0, sinp1, sinp2
1209c::statement function ----- start
1210      integer iic,iis,iil,i1
1211      double precision Dtrans
1212      Dtrans(iic,iis,iil) =
1213     &    dbl_mb((int_mb(k_sp2c_lindx+iil))+
1214     &           ((iis+iil)*(iil+1)*(iil+2)/2)
1215     &           + iic - 1)
1216c::statement function ----- end
1217      if (print_info) then
1218        write(6,*)' insize spcart_a_sd_b'
1219        write(6,*)' spcart_a_sd_b:ndima = ',ndima
1220        write(6,*)' spcart_a_sd_b:ngls  = ',ngls
1221        write(6,*)' spcart_a_sd_b:ndimb = ',ndimb
1222        call spcart_print_dtrans(2)
1223      endif
1224c
1225*rak:      ls=2
1226*rak:      write(6,*)'a_s,(ndima,l2s) ndima = ',ndima,'   ls = ',ls
1227*rak:      write(6,*)' trans matrix used '
1228*rak:      call output(dbl_mb((int_mb(k_sp2c_lindx+ls))),1,
1229*rak:     &    ((ls+1)*(ls+2)/2),1,(2*ls+1),
1230*rak:     &    ((ls+1)*(ls+2)/2),(2*ls+1),1)
1231c
1232      if (sph_cart_init.ne.SPH_CART_INIT_VALUE) call errquit
1233     &    ('spcart_a_sd_b: spcart not initialized properly',
1234     &    sph_cart_init, UNKNOWN_ERR)
1235c
1236      if (in_place) then
1237        write (6,*)' in place transformations are not ready yet '
1238      endif
1239c  spint(-2) = cint(2)*dtrans(2,-2,2)
1240c  spint(-1) = cint(5)*dtrans(5,-1,2)
1241c  spint( 0) = cint(1)*dtrans(1,0,2) + cint(4)*dtrans(4,0,2)
1242*              + cint(6)*dtrans(6,0,2)
1243c  spint( 1) = cint(3)*dtrans(3,1,2)
1244c  spint( 2) = cint(1)*dtrans(1,2,2) + cint(4)*dtrans(4,2,2)
1245      dt2m2 = dtrans(2,-2,2)
1246      dt5m1 = dtrans(5,-1,2)
1247      dt10  = dtrans(1, 0,2)
1248      dt40  = dtrans(4, 0,2)
1249      dt60  = dtrans(6, 0,2)
1250      dt31  = dtrans(3, 1,2)
1251      dt12  = dtrans(1, 2,2)
1252      dt42  = dtrans(4, 2,2)
1253      do j=1,ndimb
1254        do g=1,ngls
1255#define CHUNK 4
1256!DEC$ LOOP COUNT AVG=CHUNK
1257          do i1=1,ndima,CHUNK
1258          do i=i1,min(i1+CHUNK-1,ndima)
1259#ifdef DEBUG
1260            if (print_info)
1261     &          write(6,*)' spcart_a_sd_b:j,g,i',j,g,i
1262#endif
1263            bin1 = blockin(i,1,g,j)
1264            bin2 = blockin(i,2,g,j)
1265            bin3 = blockin(i,3,g,j)
1266            bin4 = blockin(i,4,g,j)
1267            bin5 = blockin(i,5,g,j)
1268            bin6 = blockin(i,6,g,j)
1269#ifdef DEBUG
1270            if (print_info) then
1271              write(6,11111)' spcart_a_sd_b:cart ints 1 xx',bin1,j,g,i
1272              write(6,11111)' spcart_a_sd_b:cart ints 2 xy',bin2,j,g,i
1273              write(6,11111)' spcart_a_sd_b:cart ints 3 xz',bin3,j,g,i
1274              write(6,11111)' spcart_a_sd_b:cart ints 4 yy',bin4,j,g,i
1275              write(6,11111)' spcart_a_sd_b:cart ints 5 yz',bin5,j,g,i
1276              write(6,11111)' spcart_a_sd_b:cart ints 6 zz',bin6,j,g,i
1277            endif
1278#endif
1279            sinm2 = bin2*dt2m2
1280            sinm1 = bin5*dt5m1
1281            sin0  = bin1*dt10 +
1282     &              bin4*dt40 +
1283     &              bin6*dt60
1284            sinp1 = bin3*dt31
1285            sinp2 = bin1*dt12 +
1286     &              bin4*dt42
1287            blockout(i,-2,g,j) = sinm2
1288            blockout(i,-1,g,j) = sinm1
1289            blockout(i, 0,g,j) = sin0
1290            blockout(i, 1,g,j) = sinp1
1291            blockout(i, 2,g,j) = sinp2
1292#ifdef DEBUG
1293            if (print_info) then
1294              write(6,11111)' spcart_a_sd_b:sph ints -2',sinm2,j,g,i
1295              write(6,11111)' spcart_a_sd_b:sph ints -1',sinm1,j,g,i
1296              write(6,11111)' spcart_a_sd_b:sph ints  0',sin0,j,g,i
1297              write(6,11111)' spcart_a_sd_b:sph ints +1',sinp1,j,g,i
1298              write(6,11111)' spcart_a_sd_b:sph ints +2',sinp2,j,g,i
1299            endif
1300#endif
1301          enddo
1302          enddo
1303        enddo
1304      enddo
1305      if (print_info)
1306     &    write(6,*)' exiting spcart_a_sd_b'
130711111 format(1x,a,1pd20.10,i5,i5,i5)
1308      end
1309*.......................................................................
1310      subroutine spcart_a_sf(blockin, blockout, ndima, ngls,
1311     &    in_place, print_info)
1312      implicit none
1313c
1314c  transforms a block of integrals where the f function is the slowest
1315c  dimension; e.g., blockin(ndima,10) and blockout(ndima,7)
1316c
1317#include "mafdecls.fh"
1318#include "errquit.fh"
1319#include "spcartP.fh"
1320c
1321c: passed
1322      integer ndima  ! [input] leading dimension of block
1323      integer ngls   ! [input] general contraction length of ls block
1324      double precision blockin (ndima,10,ngls)    ! [input] matrix
1325      double precision blockout(ndima,-3:3,ngls)  ! [output] matrix
1326      logical in_place  ! [input] true if blockin and block out are
1327*                                 the same pointer
1328      logical print_info ! [input] print info
1329c: local
1330      integer i,g
1331*rak:      integer ls     ! [fixed at 3] angular momentum of block
1332      double precision dt2_m3, dt7_m3, dt5_m2, dt2_m1, dt7_m1, dt9_m1
1333      double precision dt3_0, dt8_0, dt10_0, dt1_1, dt4_1, dt6_1
1334      double precision dt3_2, dt8_2, dt1_3, dt4_3
1335      double precision bin1, bin2, bin3, bin4, bin5, bin6
1336      double precision bin7, bin8, bin9, bin10
1337c::statement function ----- start
1338      integer iic,iis,iil,i1
1339      double precision Dtrans
1340      Dtrans(iic,iis,iil) =
1341     &    dbl_mb((int_mb(k_sp2c_lindx+iil))+
1342     &           ((iis+iil)*(iil+1)*(iil+2)/2)
1343     &           + iic - 1)
1344c::statement function ----- end
1345c
1346*rak:      ls=3
1347*rak:      write(6,*)'a_s,(ndima,l2s) ndima = ',ndima,'   ls = ',ls
1348*rak:      write(6,*)' trans matrix used '
1349*rak:      call output(dbl_mb((int_mb(k_sp2c_lindx+ls))),1,
1350*rak:     &    ((ls+1)*(ls+2)/2),1,(2*ls+1),
1351*rak:     &    ((ls+1)*(ls+2)/2),(2*ls+1),1)
1352c
1353      if (sph_cart_init.ne.SPH_CART_INIT_VALUE) call errquit
1354     &    ('spcart_a_sf:spcart not initialized properly',
1355     &    sph_cart_init, UNKNOWN_ERR)
1356c
1357      if (in_place) then
1358        write (6,*)' in place transformations are not ready yet '
1359      endif
1360*   spint(-3) = cint(2)*dtrans(2,-3,3) + cint(7)*dtrans(7,-3,3)
1361*   spint(-2) = cint(5)*dtrans(5,-2,3)
1362*   spint(-1) = cint(2)*dtrans(2,-1,3) + cint(7)*dtrans(7,-1,3) + cint(9)*dtrans(9,-1,3)
1363*   spint( 0) = cint(3)*dtrans(3,0,3) + cint(8)*dtrans(8,0,3) + cint(10)*dtrans(10,0,3)
1364*   spint( 1) = cint(1)*dtrans(1,1,3) + cint(4)*dtrans(4,1,3) + cint(6)*dtrans(6,1,3)
1365*   spint( 2) = cint(3)*dtrans(3,2,3) + cint(8)*dtrans(8,2,3)
1366*   spint( 3) = cint(1)*dtrans(1,3,3) + cint(4)*dtrans(4,3,3)
1367      dt2_m3 = dtrans(2,-3,3)
1368      dt7_m3 = dtrans(7,-3,3)
1369      dt5_m2 = dtrans(5,-2,3)
1370      dt2_m1 = dtrans(2,-1,3)
1371      dt7_m1 = dtrans(7,-1,3)
1372      dt9_m1 = dtrans(9,-1,3)
1373      dt3_0  = dtrans(3,0,3)
1374      dt8_0  = dtrans(8,0,3)
1375      dt10_0 = dtrans(10,0,3)
1376      dt1_1  = dtrans(1,1,3)
1377      dt4_1  = dtrans(4,1,3)
1378      dt6_1  = dtrans(6,1,3)
1379      dt3_2  = dtrans(3,2,3)
1380      dt8_2  = dtrans(8,2,3)
1381      dt1_3  = dtrans(1,3,3)
1382      dt4_3  = dtrans(4,3,3)
1383c
1384      do g=1,ngls
1385#define CHUNK 4
1386!DEC$ LOOP COUNT AVG=CHUNK
1387          do i1=1,ndima,CHUNK
1388          do i=i1,min(i1+CHUNK-1,ndima)
1389          bin1 = blockin(i,1,g)
1390          bin2 = blockin(i,2,g)
1391          bin3 = blockin(i,3,g)
1392          bin4 = blockin(i,4,g)
1393          bin5 = blockin(i,5,g)
1394          bin6 = blockin(i,6,g)
1395          bin7 = blockin(i,7,g)
1396          bin8 = blockin(i,8,g)
1397          bin9 = blockin(i,9,g)
1398          bin10 = blockin(i,10,g)
1399          blockout(i,-3,g) = bin2*dt2_m3 + bin7*dt7_m3
1400          blockout(i,-2,g) = bin5*dt5_m2
1401          blockout(i,-1,g) = bin2*dt2_m1 + bin7*dt7_m1 + bin9*dt9_m1
1402          blockout(i, 0,g) = bin3*dt3_0 + bin8*dt8_0 + bin10*dt10_0
1403          blockout(i, 1,g) = bin1*dt1_1 + bin4*dt4_1 + bin6*dt6_1
1404          blockout(i, 2,g) = bin3*dt3_2 + bin8*dt8_2
1405          blockout(i, 3,g) = bin1*dt1_3 + bin4*dt4_3
1406        enddo
1407        enddo
1408      enddo
1409      end
1410*.......................................................................
1411      subroutine spcart_sf_a(blockin, blockout, ndima, ngls,
1412     &    in_place, print_info)
1413      implicit none
1414c
1415c  transforms a block of integrals where the f function is the fastest dimension
1416c  e.g., blockin(10,ndima) and blockout(7,ndima)
1417c
1418#include "mafdecls.fh"
1419#include "errquit.fh"
1420#include "spcartP.fh"
1421c
1422c: passed
1423      integer ndima  ! [input] leading dimension of block
1424      integer ngls   ! [input] general contraction length of ls block
1425      double precision blockin (10,ngls,ndima)    ! [input] matrix
1426      double precision blockout(-3:3,ngls,ndima)  ! [output] matrix
1427      logical in_place  ! [input] true if blockin and block out are the same pointer
1428      logical print_info ! [input] print info
1429c: local
1430      integer i,g
1431*rak:      integer ls     ! [fixed at 3] angular momentum of block
1432      double precision dt2_m3, dt7_m3, dt5_m2, dt2_m1, dt7_m1, dt9_m1
1433      double precision dt3_0, dt8_0, dt10_0, dt1_1, dt4_1, dt6_1
1434      double precision dt3_2, dt8_2, dt1_3, dt4_3
1435      double precision bin1, bin2, bin3, bin4, bin5, bin6
1436      double precision bin7, bin8, bin9, bin10
1437c::statement function ----- start
1438      integer iic,iis,iil
1439      double precision Dtrans
1440      Dtrans(iic,iis,iil) =
1441     &    dbl_mb((int_mb(k_sp2c_lindx+iil))+
1442     &           ((iis+iil)*(iil+1)*(iil+2)/2)
1443     &           + iic - 1)
1444c::statement function ----- end
1445c
1446*rak:      ls=3
1447*rak:      write(6,*)'a_s,(ndima,l2s) ndima = ',ndima,'   ls = ',ls
1448*rak:      write(6,*)' trans matrix used '
1449*rak:      call output(dbl_mb((int_mb(k_sp2c_lindx+ls))),1,
1450*rak:     &    ((ls+1)*(ls+2)/2),1,(2*ls+1),
1451*rak:     &    ((ls+1)*(ls+2)/2),(2*ls+1),1)
1452c
1453      if (sph_cart_init.ne.SPH_CART_INIT_VALUE) call errquit
1454     &    ('spcart_sf_a: spcart not initialized properly',
1455     &    sph_cart_init, UNKNOWN_ERR)
1456c
1457      if (in_place) then
1458        write (6,*)' in place transformations are not ready yet '
1459      endif
1460*   spint(-3) = cint(2)*dtrans(2,-3,3) + cint(7)*dtrans(7,-3,3)
1461*   spint(-2) = cint(5)*dtrans(5,-2,3)
1462*   spint(-1) = cint(2)*dtrans(2,-1,3) + cint(7)*dtrans(7,-1,3) + cint(9)*dtrans(9,-1,3)
1463*   spint( 0) = cint(3)*dtrans(3,0,3) + cint(8)*dtrans(8,0,3) + cint(10)*dtrans(10,0,3)
1464*   spint( 1) = cint(1)*dtrans(1,1,3) + cint(4)*dtrans(4,1,3) + cint(6)*dtrans(6,1,3)
1465*   spint( 2) = cint(3)*dtrans(3,2,3) + cint(8)*dtrans(8,2,3)
1466*   spint( 3) = cint(1)*dtrans(1,3,3) + cint(4)*dtrans(4,3,3)
1467      dt2_m3 = dtrans(2,-3,3)
1468      dt7_m3 = dtrans(7,-3,3)
1469      dt5_m2 = dtrans(5,-2,3)
1470      dt2_m1 = dtrans(2,-1,3)
1471      dt7_m1 = dtrans(7,-1,3)
1472      dt9_m1 = dtrans(9,-1,3)
1473      dt3_0  = dtrans(3,0,3)
1474      dt8_0  = dtrans(8,0,3)
1475      dt10_0 = dtrans(10,0,3)
1476      dt1_1  = dtrans(1,1,3)
1477      dt4_1  = dtrans(4,1,3)
1478      dt6_1  = dtrans(6,1,3)
1479      dt3_2  = dtrans(3,2,3)
1480      dt8_2  = dtrans(8,2,3)
1481      dt1_3  = dtrans(1,3,3)
1482      dt4_3  = dtrans(4,3,3)
1483c
1484      do i=1,ndima
1485        do g=1,ngls
1486          bin1  = blockin( 1,g,i)
1487          bin2  = blockin( 2,g,i)
1488          bin3  = blockin( 3,g,i)
1489          bin4  = blockin( 4,g,i)
1490          bin5  = blockin( 5,g,i)
1491          bin6  = blockin( 6,g,i)
1492          bin7  = blockin( 7,g,i)
1493          bin8  = blockin( 8,g,i)
1494          bin9  = blockin( 9,g,i)
1495          bin10 = blockin(10,g,i)
1496          blockout(-3,g,i) = bin2*dt2_m3 + bin7*dt7_m3
1497          blockout(-2,g,i) = bin5*dt5_m2
1498          blockout(-1,g,i) = bin2*dt2_m1 + bin7*dt7_m1 + bin9*dt9_m1
1499          blockout( 0,g,i) = bin3*dt3_0 + bin8*dt8_0 + bin10*dt10_0
1500          blockout( 1,g,i) = bin1*dt1_1 + bin4*dt4_1 + bin6*dt6_1
1501          blockout( 2,g,i) = bin3*dt3_2 + bin8*dt8_2
1502          blockout( 3,g,i) = bin1*dt1_3 + bin4*dt4_3
1503        enddo
1504      enddo
1505      end
1506*.......................................................................
1507      subroutine spcart_a_sf_b(blockin, blockout,
1508     &    ndima, ndimb, ngls, in_place, print_info)
1509      implicit none
1510c
1511c  transforms a block of integrals where the f function is the middle dimension
1512c  e.g., blockin(ndima,10,ndimb) and blockout(ndima,7,ndimb)
1513c
1514#include "mafdecls.fh"
1515#include "errquit.fh"
1516#include "spcartP.fh"
1517c
1518c: passed
1519      integer ndima  ! [input] leading dimension of block
1520      integer ndimb  ! [input] trailing dimension of block
1521      integer ngls   ! [input] general contraction length of ls block
1522      double precision blockin (ndima,10,ngls,ndimb)    ! [input] matrix
1523      double precision blockout(ndima,-3:3,ngls,ndimb)  ! [output] matrix
1524      logical in_place  ! [input] true if blockin and block out are the same pointer
1525      logical print_info ! [input] print info
1526c: local
1527      integer i,j,g
1528*rak:      integer ls     ! [fixed at 3] angular momentum of block
1529      double precision dt2_m3, dt7_m3, dt5_m2, dt2_m1, dt7_m1, dt9_m1
1530      double precision dt3_0, dt8_0, dt10_0, dt1_1, dt4_1, dt6_1
1531      double precision dt3_2, dt8_2, dt1_3, dt4_3
1532      double precision bin1, bin2, bin3, bin4, bin5, bin6
1533      double precision bin7, bin8, bin9, bin10
1534c::statement function ----- start
1535      integer iic,iis,iil
1536      double precision Dtrans
1537      Dtrans(iic,iis,iil) =
1538     &    dbl_mb((int_mb(k_sp2c_lindx+iil))+
1539     &           ((iis+iil)*(iil+1)*(iil+2)/2)
1540     &           + iic - 1)
1541c::statement function ----- end
1542c
1543*rak:      ls=3
1544*rak:      write(6,*)'a_s,(ndima,l2s) ndima = ',ndima,'   ls = ',ls
1545*rak:      write(6,*)' trans matrix used '
1546*rak:      call output(dbl_mb((int_mb(k_sp2c_lindx+ls))),1,
1547*rak:     &    ((ls+1)*(ls+2)/2),1,(2*ls+1),
1548*rak:     &    ((ls+1)*(ls+2)/2),(2*ls+1),1)
1549c
1550      if (sph_cart_init.ne.SPH_CART_INIT_VALUE) call errquit
1551     &    ('spcart_a_sf_b: spcart not initialized properly',
1552     &    sph_cart_init, UNKNOWN_ERR)
1553c
1554      if (in_place) then
1555        write (6,*)' in place transformations are not ready yet '
1556      endif
1557*   spint(-3) = cint(2)*dtrans(2,-3,3) + cint(7)*dtrans(7,-3,3)
1558*   spint(-2) = cint(5)*dtrans(5,-2,3)
1559*   spint(-1) = cint(2)*dtrans(2,-1,3) + cint(7)*dtrans(7,-1,3) + cint(9)*dtrans(9,-1,3)
1560*   spint( 0) = cint(3)*dtrans(3,0,3) + cint(8)*dtrans(8,0,3) + cint(10)*dtrans(10,0,3)
1561*   spint( 1) = cint(1)*dtrans(1,1,3) + cint(4)*dtrans(4,1,3) + cint(6)*dtrans(6,1,3)
1562*   spint( 2) = cint(3)*dtrans(3,2,3) + cint(8)*dtrans(8,2,3)
1563*   spint( 3) = cint(1)*dtrans(1,3,3) + cint(4)*dtrans(4,3,3)
1564      dt2_m3 = dtrans(2,-3,3)
1565      dt7_m3 = dtrans(7,-3,3)
1566      dt5_m2 = dtrans(5,-2,3)
1567      dt2_m1 = dtrans(2,-1,3)
1568      dt7_m1 = dtrans(7,-1,3)
1569      dt9_m1 = dtrans(9,-1,3)
1570      dt3_0  = dtrans(3,0,3)
1571      dt8_0  = dtrans(8,0,3)
1572      dt10_0 = dtrans(10,0,3)
1573      dt1_1  = dtrans(1,1,3)
1574      dt4_1  = dtrans(4,1,3)
1575      dt6_1  = dtrans(6,1,3)
1576      dt3_2  = dtrans(3,2,3)
1577      dt8_2  = dtrans(8,2,3)
1578      dt1_3  = dtrans(1,3,3)
1579      dt4_3  = dtrans(4,3,3)
1580c
1581      do j=1,ndimb
1582        do g=1,ngls
1583          do i=1,ndima
1584            bin1  = blockin(i, 1,g,j)
1585            bin2  = blockin(i, 2,g,j)
1586            bin3  = blockin(i, 3,g,j)
1587            bin4  = blockin(i, 4,g,j)
1588            bin5  = blockin(i, 5,g,j)
1589            bin6  = blockin(i, 6,g,j)
1590            bin7  = blockin(i, 7,g,j)
1591            bin8  = blockin(i, 8,g,j)
1592            bin9  = blockin(i, 9,g,j)
1593            bin10 = blockin(i,10,g,j)
1594            blockout(i,-3,g,j) = bin2*dt2_m3 + bin7*dt7_m3
1595            blockout(i,-2,g,j) = bin5*dt5_m2
1596            blockout(i,-1,g,j) =
1597     &                         bin2*dt2_m1 + bin7*dt7_m1 + bin9*dt9_m1
1598            blockout(i, 0,g,j) =
1599     &                         bin3*dt3_0 + bin8*dt8_0 + bin10*dt10_0
1600            blockout(i, 1,g,j) =
1601     &                         bin1*dt1_1 + bin4*dt4_1 + bin6*dt6_1
1602            blockout(i, 2,g,j) = bin3*dt3_2 + bin8*dt8_2
1603            blockout(i, 3,g,j) = bin1*dt1_3 + bin4*dt4_3
1604          enddo
1605        enddo
1606      enddo
1607      end
1608*.......................................................................
1609      subroutine spcart_a_sg(blockin, blockout, ndima, ngls,
1610     &    in_place, print_info)
1611      implicit none
1612c
1613c  transforms a block of integrals where the g function is the slowest dimension
1614c  e.g., blockin(ndima,15) and blockout(ndima,9)
1615c
1616#include "mafdecls.fh"
1617#include "errquit.fh"
1618#include "spcartP.fh"
1619c
1620c: passed
1621      integer ndima  ! [input] leading dimension of block
1622      integer ngls   ! [input] general contraction length of ls block
1623      double precision blockin (ndima,15,ngls)   ! [input] matrix
1624      double precision blockout(ndima,-4:4,ngls) ! [output] matrix
1625      logical in_place  ! [input] true if blockin and block out are the same pointer
1626      logical print_info ! [input] print info
1627c: local
1628      integer i,g
1629      double precision dt2_m4, dt7_m4, dt5_m3, dt12_m3
1630      double precision dt2_m2, dt7_m2, dt9_m2, dt5_m1, dt12_m1, dt14_m1
1631      double precision dt1_0, dt4_0, dt6_0, dt11_0, dt13_0, dt15_0
1632      double precision dt3_1, dt8_1, dt10_1
1633      double precision dt1_2, dt6_2, dt11_2, dt13_2
1634      double precision dt3_3, dt8_3, dt1_4, dt4_4, dt11_4
1635      double precision bin1, bin2, bin3, bin4, bin5, bin6
1636      double precision bin7, bin8, bin9, bin10
1637      double precision bin11, bin12, bin13, bin14, bin15
1638*rak:      integer ls     ! [fixed at 4] angular momentum of block
1639c::statement function ----- start
1640      integer iic,iis,iil
1641      double precision Dtrans
1642      Dtrans(iic,iis,iil) =
1643     &    dbl_mb((int_mb(k_sp2c_lindx+iil))+
1644     &           ((iis+iil)*(iil+1)*(iil+2)/2)
1645     &           + iic - 1)
1646c::statement function ----- end
1647c
1648*rak:      ls=4
1649*rak:      write(6,*)'a_s,(ndima,l2s) ndima = ',ndima,'   ls = ',ls
1650*rak:      write(6,*)' trans matrix used '
1651*rak:      call output(dbl_mb((int_mb(k_sp2c_lindx+ls))),1,
1652*rak:     &    ((ls+1)*(ls+2)/2),1,(2*ls+1),
1653*rak:     &    ((ls+1)*(ls+2)/2),(2*ls+1),1)
1654c
1655      if (sph_cart_init.ne.SPH_CART_INIT_VALUE) call errquit
1656     &    ('spcart_a_sg: spcart not initialized properly',
1657     &    sph_cart_init, UNKNOWN_ERR)
1658c
1659      if (in_place) then
1660        write (6,*)' in place transformations are not ready yet '
1661      endif
1662c
1663c  spint(-4) = cint(2)*dtrans(2,-4,4) + cint(7)*dtrans(7,-4,4)
1664c  spint(-3) = cint(5)*dtrans(5,-3,4) + cint(12)*dtrans(12,-3,4)
1665c  spint(-2) = cint(2)*dtrans(2,-2,4) + cint(7)*dtrans(7,-2,4) + cint(9)*dtrans(9,-2,4)
1666c  spint(-1) = cint(5)*dtrans(5,-1,4) + cint(12)*dtrans(12,-1,4) + cint(14)*dtrans(14,-1,4)
1667c  spint( 0) = cint(1)*dtrans(1,0,4)   + cint(4)*dtrans(4,0,4)   + cint(6)*dtrans(6,0,4)
1668c            + cint(11)*dtrans(11,0,4) + cint(13)*dtrans(13,0,4) + cint(15)*dtrans(15,0,4)
1669c  spint( 1) = cint(3)*dtrans(3,1,4) + cint(8)*dtrans(8,1,4) + cint(10)*dtrans(10,1,4)
1670c  spint( 2) = cint(1)*dtrans(1,2,4) + cint(6)*dtrans(6,2,4) + cint(11)*dtrans(11,2,4)
1671c            + cint(13)*dtrans(13,2,4)
1672c  spint( 3) = cint(3)*dtrans(3,3,4) + cint(8)*dtrans(8,3,4)
1673c  spint( 4) = cint(1)*dtrans(1,4,4) + cint(4)*dtrans(4,4,4) + cint(11)*dtrans(11,4,4)
1674c
1675      dt2_m4  = dtrans(2,-4,4)
1676      dt7_m4  = dtrans(7,-4,4)
1677      dt5_m3  = dtrans(5,-3,4)
1678      dt12_m3 = dtrans(12,-3,4)
1679      dt2_m2  = dtrans(2,-2,4)
1680      dt7_m2  = dtrans(7,-2,4)
1681      dt9_m2  = dtrans(9,-2,4)
1682      dt5_m1  = dtrans(5,-1,4)
1683      dt12_m1 = dtrans(12,-1,4)
1684      dt14_m1 = dtrans(14,-1,4)
1685      dt1_0   = dtrans(1,0,4)
1686      dt4_0   = dtrans(4,0,4)
1687      dt6_0   = dtrans(6,0,4)
1688      dt11_0  = dtrans(11,0,4)
1689      dt13_0  = dtrans(13,0,4)
1690      dt15_0  = dtrans(15,0,4)
1691      dt3_1   = dtrans(3,1,4)
1692      dt8_1   = dtrans(8,1,4)
1693      dt10_1  = dtrans(10,1,4)
1694      dt1_2   = dtrans(1,2,4)
1695      dt6_2   = dtrans(6,2,4)
1696      dt11_2  = dtrans(11,2,4)
1697      dt13_2  = dtrans(13,2,4)
1698      dt3_3   = dtrans(3,3,4)
1699      dt8_3   = dtrans(8,3,4)
1700      dt1_4   = dtrans(1,4,4)
1701      dt4_4   = dtrans(4,4,4)
1702      dt11_4  = dtrans(11,4,4)
1703      do g=1,ngls
1704        do i=1,ndima
1705          bin1  = blockin(i, 1,g)
1706          bin2  = blockin(i, 2,g)
1707          bin3  = blockin(i, 3,g)
1708          bin4  = blockin(i, 4,g)
1709          bin5  = blockin(i, 5,g)
1710          bin6  = blockin(i, 6,g)
1711          bin7  = blockin(i, 7,g)
1712          bin8  = blockin(i, 8,g)
1713          bin9  = blockin(i, 9,g)
1714          bin10 = blockin(i,10,g)
1715          bin11 = blockin(i,11,g)
1716          bin12 = blockin(i,12,g)
1717          bin13 = blockin(i,13,g)
1718          bin14 = blockin(i,14,g)
1719          bin15 = blockin(i,15,g)
1720c
1721          blockout(i,-4,g) = bin2*dt2_m4  + bin7*dt7_m4
1722          blockout(i,-3,g) = bin5*dt5_m3  + bin12*dt12_m3
1723          blockout(i,-2,g) = bin2*dt2_m2  + bin7*dt7_m2   +
1724     &                       bin9*dt9_m2
1725          blockout(i,-1,g) = bin5*dt5_m1  + bin12*dt12_m1 +
1726     &                       bin14*dt14_m1
1727          blockout(i, 0,g) = bin1*dt1_0   + bin4*dt4_0    +
1728     &                       bin6*dt6_0   + bin11*dt11_0  +
1729     &                       bin13*dt13_0 + bin15*dt15_0
1730          blockout(i, 1,g) = bin3*dt3_1   + bin8*dt8_1    +
1731     &                       bin10*dt10_1
1732          blockout(i, 2,g) = bin1*dt1_2   + bin6*dt6_2    +
1733     &                       bin11*dt11_2 + bin13*dt13_2
1734          blockout(i, 3,g) = bin3*dt3_3   + bin8*dt8_3
1735          blockout(i, 4,g) = bin1*dt1_4   + bin4*dt4_4    +
1736     &                       bin11*dt11_4
1737        enddo
1738      enddo
1739      end
1740*.......................................................................
1741      subroutine spcart_sg_a(blockin, blockout, ndima, ngls,
1742     &    in_place, print_info)
1743      implicit none
1744c
1745c  transforms a block of integrals where the g function is the fastest dimension
1746c  e.g., blockin(15,ndima) and blockout(9,ndima)
1747c
1748#include "mafdecls.fh"
1749#include "errquit.fh"
1750#include "spcartP.fh"
1751c
1752c: passed
1753      integer ndima  ! [input] leading dimension of block
1754      integer ngls   ! [input] general contraction length of ls block
1755      double precision blockin (15,ngls,ndima)   ! [input] matrix
1756      double precision blockout(-4:4,ngls,ndima) ! [output] matrix
1757      logical in_place  ! [input] true if blockin and block out are the same pointer
1758      logical print_info ! [input] print info
1759c: local
1760      integer i,g
1761      double precision dt2_m4, dt7_m4, dt5_m3, dt12_m3
1762      double precision dt2_m2, dt7_m2, dt9_m2, dt5_m1, dt12_m1, dt14_m1
1763      double precision dt1_0, dt4_0, dt6_0, dt11_0, dt13_0, dt15_0
1764      double precision dt3_1, dt8_1, dt10_1
1765      double precision dt1_2, dt6_2, dt11_2, dt13_2
1766      double precision dt3_3, dt8_3, dt1_4, dt4_4, dt11_4
1767      double precision bin1, bin2, bin3, bin4, bin5, bin6
1768      double precision bin7, bin8, bin9, bin10
1769      double precision bin11, bin12, bin13, bin14, bin15
1770*rak:      integer ls     ! [fixed at 4] angular momentum of block
1771c::statement function ----- start
1772      integer iic,iis,iil
1773      double precision Dtrans
1774      Dtrans(iic,iis,iil) =
1775     &    dbl_mb((int_mb(k_sp2c_lindx+iil))+
1776     &           ((iis+iil)*(iil+1)*(iil+2)/2)
1777     &           + iic - 1)
1778c::statement function ----- end
1779c
1780*rak:      ls=4
1781*rak:      write(6,*)'a_s,(ndima,l2s) ndima = ',ndima,'   ls = ',ls
1782*rak:      write(6,*)' trans matrix used '
1783*rak:      call output(dbl_mb((int_mb(k_sp2c_lindx+ls))),1,
1784*rak:     &    ((ls+1)*(ls+2)/2),1,(2*ls+1),
1785*rak:     &    ((ls+1)*(ls+2)/2),(2*ls+1),1)
1786c
1787      if (sph_cart_init.ne.SPH_CART_INIT_VALUE) call errquit
1788     &    ('spcart_sg_a: spcart not initialized properly',
1789     &    sph_cart_init, UNKNOWN_ERR)
1790c
1791      if (in_place) then
1792        write (6,*)' in place transformations are not ready yet '
1793      endif
1794c
1795c  spint(-4) = cint(2)*dtrans(2,-4,4) + cint(7)*dtrans(7,-4,4)
1796c  spint(-3) = cint(5)*dtrans(5,-3,4) + cint(12)*dtrans(12,-3,4)
1797c  spint(-2) = cint(2)*dtrans(2,-2,4) + cint(7)*dtrans(7,-2,4) + cint(9)*dtrans(9,-2,4)
1798c  spint(-1) = cint(5)*dtrans(5,-1,4) + cint(12)*dtrans(12,-1,4) + cint(14)*dtrans(14,-1,4)
1799c  spint( 0) = cint(1)*dtrans(1,0,4)   + cint(4)*dtrans(4,0,4)   + cint(6)*dtrans(6,0,4)
1800c            + cint(11)*dtrans(11,0,4) + cint(13)*dtrans(13,0,4) + cint(15)*dtrans(15,0,4)
1801c  spint( 1) = cint(3)*dtrans(3,1,4) + cint(8)*dtrans(8,1,4) + cint(10)*dtrans(10,1,4)
1802c  spint( 2) = cint(1)*dtrans(1,2,4) + cint(6)*dtrans(6,2,4) + cint(11)*dtrans(11,2,4)
1803c            + cint(13)*dtrans(13,2,4)
1804c  spint( 3) = cint(3)*dtrans(3,3,4) + cint(8)*dtrans(8,3,4)
1805c  spint( 4) = cint(1)*dtrans(1,4,4) + cint(4)*dtrans(4,4,4) + cint(11)*dtrans(11,4,4)
1806c
1807      dt2_m4  = dtrans(2,-4,4)
1808      dt7_m4  = dtrans(7,-4,4)
1809      dt5_m3  = dtrans(5,-3,4)
1810      dt12_m3 = dtrans(12,-3,4)
1811      dt2_m2  = dtrans(2,-2,4)
1812      dt7_m2  = dtrans(7,-2,4)
1813      dt9_m2  = dtrans(9,-2,4)
1814      dt5_m1  = dtrans(5,-1,4)
1815      dt12_m1 = dtrans(12,-1,4)
1816      dt14_m1 = dtrans(14,-1,4)
1817      dt1_0   = dtrans(1,0,4)
1818      dt4_0   = dtrans(4,0,4)
1819      dt6_0   = dtrans(6,0,4)
1820      dt11_0  = dtrans(11,0,4)
1821      dt13_0  = dtrans(13,0,4)
1822      dt15_0  = dtrans(15,0,4)
1823      dt3_1   = dtrans(3,1,4)
1824      dt8_1   = dtrans(8,1,4)
1825      dt10_1  = dtrans(10,1,4)
1826      dt1_2   = dtrans(1,2,4)
1827      dt6_2   = dtrans(6,2,4)
1828      dt11_2  = dtrans(11,2,4)
1829      dt13_2  = dtrans(13,2,4)
1830      dt3_3   = dtrans(3,3,4)
1831      dt8_3   = dtrans(8,3,4)
1832      dt1_4   = dtrans(1,4,4)
1833      dt4_4   = dtrans(4,4,4)
1834      dt11_4  = dtrans(11,4,4)
1835      do i=1,ndima
1836        do g=1,ngls
1837          bin1  = blockin( 1,g,i)
1838          bin2  = blockin( 2,g,i)
1839          bin3  = blockin( 3,g,i)
1840          bin4  = blockin( 4,g,i)
1841          bin5  = blockin( 5,g,i)
1842          bin6  = blockin( 6,g,i)
1843          bin7  = blockin( 7,g,i)
1844          bin8  = blockin( 8,g,i)
1845          bin9  = blockin( 9,g,i)
1846          bin10 = blockin(10,g,i)
1847          bin11 = blockin(11,g,i)
1848          bin12 = blockin(12,g,i)
1849          bin13 = blockin(13,g,i)
1850          bin14 = blockin(14,g,i)
1851          bin15 = blockin(15,g,i)
1852c
1853          blockout(-4,g,i) = bin2*dt2_m4  + bin7*dt7_m4
1854          blockout(-3,g,i) = bin5*dt5_m3  + bin12*dt12_m3
1855          blockout(-2,g,i) = bin2*dt2_m2  + bin7*dt7_m2   +
1856     &                       bin9*dt9_m2
1857          blockout(-1,g,i) = bin5*dt5_m1  + bin12*dt12_m1 +
1858     &                       bin14*dt14_m1
1859          blockout( 0,g,i) = bin1*dt1_0   + bin4*dt4_0    +
1860     &                       bin6*dt6_0   + bin11*dt11_0  +
1861     &                       bin13*dt13_0 + bin15*dt15_0
1862          blockout( 1,g,i) = bin3*dt3_1   + bin8*dt8_1    +
1863     &                       bin10*dt10_1
1864          blockout( 2,g,i) = bin1*dt1_2   + bin6*dt6_2    +
1865     &                       bin11*dt11_2 + bin13*dt13_2
1866          blockout( 3,g,i) = bin3*dt3_3   + bin8*dt8_3
1867          blockout( 4,g,i) = bin1*dt1_4   + bin4*dt4_4    +
1868     &                       bin11*dt11_4
1869        enddo
1870      enddo
1871      end
1872*.......................................................................
1873      subroutine spcart_a_sg_b(blockin, blockout,
1874     &    ndima, ndimb, ngls, in_place, print_info)
1875      implicit none
1876c
1877c  transforms a block of integrals where the g function is the middle dimension
1878c  e.g., blockin(ndima,15,ndimb) and blockout(ndima,9,ndimb)
1879c
1880#include "mafdecls.fh"
1881#include "errquit.fh"
1882#include "spcartP.fh"
1883c
1884c: passed
1885      integer ndima  ! [input] leading dimension of block
1886      integer ndimb  ! [input] trailing dimension of block
1887      integer ngls   ! [input] general contraction length of ls block
1888      double precision blockin (ndima,15,ngls,ndimb)   ! [input] matrix
1889      double precision blockout(ndima,-4:4,ngls,ndimb) ! [output] matrix
1890      logical in_place  ! [input] true if blockin and block out are the same pointer
1891      logical print_info ! [input] print info
1892c: local
1893      integer i,j,g
1894      double precision dt2_m4, dt7_m4, dt5_m3, dt12_m3
1895      double precision dt2_m2, dt7_m2, dt9_m2, dt5_m1, dt12_m1, dt14_m1
1896      double precision dt1_0, dt4_0, dt6_0, dt11_0, dt13_0, dt15_0
1897      double precision dt3_1, dt8_1, dt10_1
1898      double precision dt1_2, dt6_2, dt11_2, dt13_2
1899      double precision dt3_3, dt8_3, dt1_4, dt4_4, dt11_4
1900      double precision bin1, bin2, bin3, bin4, bin5, bin6
1901      double precision bin7, bin8, bin9, bin10
1902      double precision bin11, bin12, bin13, bin14, bin15
1903*rak:      integer ls     ! [fixed at 4] angular momentum of block
1904c::statement function ----- start
1905      integer iic,iis,iil
1906      double precision Dtrans
1907      Dtrans(iic,iis,iil) =
1908     &    dbl_mb((int_mb(k_sp2c_lindx+iil))+
1909     &           ((iis+iil)*(iil+1)*(iil+2)/2)
1910     &           + iic - 1)
1911c::statement function ----- end
1912c
1913*rak:      ls=4
1914*rak:      write(6,*)'a_s,(ndima,l2s) ndima = ',ndima,'   ls = ',ls
1915*rak:      write(6,*)' trans matrix used '
1916*rak:      call output(dbl_mb((int_mb(k_sp2c_lindx+ls))),1,
1917*rak:     &    ((ls+1)*(ls+2)/2),1,(2*ls+1),
1918*rak:     &    ((ls+1)*(ls+2)/2),(2*ls+1),1)
1919c
1920      if (sph_cart_init.ne.SPH_CART_INIT_VALUE) call errquit
1921     &    ('spcart_a_sg_b: spcart not initialized properly',
1922     &    sph_cart_init, UNKNOWN_ERR)
1923c
1924      if (in_place) then
1925        write (6,*)' in place transformations are not ready yet '
1926      endif
1927c
1928c  spint(-4) = cint(2)*dtrans(2,-4,4) + cint(7)*dtrans(7,-4,4)
1929c  spint(-3) = cint(5)*dtrans(5,-3,4) + cint(12)*dtrans(12,-3,4)
1930c  spint(-2) = cint(2)*dtrans(2,-2,4) + cint(7)*dtrans(7,-2,4) + cint(9)*dtrans(9,-2,4)
1931c  spint(-1) = cint(5)*dtrans(5,-1,4) + cint(12)*dtrans(12,-1,4) + cint(14)*dtrans(14,-1,4)
1932c  spint( 0) = cint(1)*dtrans(1,0,4)   + cint(4)*dtrans(4,0,4)   + cint(6)*dtrans(6,0,4)
1933c            + cint(11)*dtrans(11,0,4) + cint(13)*dtrans(13,0,4) + cint(15)*dtrans(15,0,4)
1934c  spint( 1) = cint(3)*dtrans(3,1,4) + cint(8)*dtrans(8,1,4) + cint(10)*dtrans(10,1,4)
1935c  spint( 2) = cint(1)*dtrans(1,2,4) + cint(6)*dtrans(6,2,4) + cint(11)*dtrans(11,2,4)
1936c            + cint(13)*dtrans(13,2,4)
1937c  spint( 3) = cint(3)*dtrans(3,3,4) + cint(8)*dtrans(8,3,4)
1938c  spint( 4) = cint(1)*dtrans(1,4,4) + cint(4)*dtrans(4,4,4) + cint(11)*dtrans(11,4,4)
1939c
1940      dt2_m4  = dtrans(2,-4,4)
1941      dt7_m4  = dtrans(7,-4,4)
1942      dt5_m3  = dtrans(5,-3,4)
1943      dt12_m3 = dtrans(12,-3,4)
1944      dt2_m2  = dtrans(2,-2,4)
1945      dt7_m2  = dtrans(7,-2,4)
1946      dt9_m2  = dtrans(9,-2,4)
1947      dt5_m1  = dtrans(5,-1,4)
1948      dt12_m1 = dtrans(12,-1,4)
1949      dt14_m1 = dtrans(14,-1,4)
1950      dt1_0   = dtrans(1,0,4)
1951      dt4_0   = dtrans(4,0,4)
1952      dt6_0   = dtrans(6,0,4)
1953      dt11_0  = dtrans(11,0,4)
1954      dt13_0  = dtrans(13,0,4)
1955      dt15_0  = dtrans(15,0,4)
1956      dt3_1   = dtrans(3,1,4)
1957      dt8_1   = dtrans(8,1,4)
1958      dt10_1  = dtrans(10,1,4)
1959      dt1_2   = dtrans(1,2,4)
1960      dt6_2   = dtrans(6,2,4)
1961      dt11_2  = dtrans(11,2,4)
1962      dt13_2  = dtrans(13,2,4)
1963      dt3_3   = dtrans(3,3,4)
1964      dt8_3   = dtrans(8,3,4)
1965      dt1_4   = dtrans(1,4,4)
1966      dt4_4   = dtrans(4,4,4)
1967      dt11_4  = dtrans(11,4,4)
1968      do j=1,ndimb
1969        do g=1,ngls
1970          do i=1,ndima
1971            bin1  = blockin(i, 1,g,j)
1972            bin2  = blockin(i, 2,g,j)
1973            bin3  = blockin(i, 3,g,j)
1974            bin4  = blockin(i, 4,g,j)
1975            bin5  = blockin(i, 5,g,j)
1976            bin6  = blockin(i, 6,g,j)
1977            bin7  = blockin(i, 7,g,j)
1978            bin8  = blockin(i, 8,g,j)
1979            bin9  = blockin(i, 9,g,j)
1980            bin10 = blockin(i,10,g,j)
1981            bin11 = blockin(i,11,g,j)
1982            bin12 = blockin(i,12,g,j)
1983            bin13 = blockin(i,13,g,j)
1984            bin14 = blockin(i,14,g,j)
1985            bin15 = blockin(i,15,g,j)
1986c
1987            blockout(i,-4,g,j) = bin2*dt2_m4  + bin7*dt7_m4
1988            blockout(i,-3,g,j) = bin5*dt5_m3  + bin12*dt12_m3
1989            blockout(i,-2,g,j) = bin2*dt2_m2  + bin7*dt7_m2   +
1990     &                           bin9*dt9_m2
1991            blockout(i,-1,g,j) = bin5*dt5_m1  + bin12*dt12_m1 +
1992     &                           bin14*dt14_m1
1993            blockout(i, 0,g,j) = bin1*dt1_0   + bin4*dt4_0    +
1994     &                           bin6*dt6_0   + bin11*dt11_0  +
1995     &                           bin13*dt13_0 + bin15*dt15_0
1996            blockout(i, 1,g,j) = bin3*dt3_1   + bin8*dt8_1    +
1997     &                           bin10*dt10_1
1998            blockout(i, 2,g,j) = bin1*dt1_2   + bin6*dt6_2    +
1999     &                           bin11*dt11_2 + bin13*dt13_2
2000            blockout(i, 3,g,j) = bin3*dt3_3   + bin8*dt8_3
2001            blockout(i, 4,g,j) = bin1*dt1_4   + bin4*dt4_4    +
2002     &                           bin11*dt11_4
2003          enddo
2004        enddo
2005      enddo
2006      end
2007*.......................................................................
2008      subroutine spcart_a_sh(blockin, blockout, ndima, ngls,
2009     &    in_place, print_info)
2010      implicit none
2011c
2012c  transforms a block of integrals where the h function is the fastest dimension
2013c  e.g., blockin(ndima,21) and blockout(ndima,11)
2014c
2015#include "mafdecls.fh"
2016#include "errquit.fh"
2017#include "spcartP.fh"
2018c
2019c: passed
2020      integer ndima  ! [input] leading dimension of block
2021      integer ngls   ! [input] general contraction length of ls block
2022      double precision blockin (ndima,21,ngls)   ! [input] matrix
2023      double precision blockout(ndima,-5:5,ngls) ! [output] matrix
2024      logical in_place  ! [input] true if blockin and block out are the same pointer
2025      logical print_info ! [input] print info
2026c: local
2027      integer i,g
2028      double precision dt2_m5, dt7_m5, dt16_m5, dt5_m4, dt12_m4, dt2_m3
2029      double precision dt7_m3, dt9_m3, dt16_m3, dt18_m3, dt5_m2, dt12_m2
2030      double precision dt14_m2, dt2_m1, dt7_m1, dt9_m1, dt16_m1, dt18_m1
2031      double precision dt20_m1, dt3_0, dt8_0, dt10_0, dt17_0, dt19_0
2032      double precision dt21_0, dt1_1, dt4_1, dt6_1, dt11_1, dt13_1
2033      double precision dt15_1, dt3_2, dt10_2, dt17_2, dt19_2, dt1_3
2034      double precision dt4_3, dt6_3, dt11_3, dt13_3, dt3_4, dt8_4
2035      double precision dt17_4, dt1_5, dt4_5, dt11_5
2036      double precision bin1, bin2, bin3, bin4, bin5, bin6
2037      double precision bin7, bin8, bin9, bin10
2038      double precision bin11, bin12, bin13, bin14, bin15
2039      double precision bin16, bin17, bin18, bin19, bin20, bin21
2040*rak:      integer ls     ! [fixed at 5] angular momentum of block
2041c::statement function ----- start
2042      integer iic,iis,iil
2043      double precision Dtrans
2044      Dtrans(iic,iis,iil) =
2045     &    dbl_mb((int_mb(k_sp2c_lindx+iil))+
2046     &           ((iis+iil)*(iil+1)*(iil+2)/2)
2047     &           + iic - 1)
2048c::statement function ----- end
2049c
2050*rak:      ls=5
2051*rak:      write(6,*)'a_s,(ndima,l2s) ndima = ',ndima,'   ls = ',ls
2052*rak:      write(6,*)' trans matrix used '
2053*rak:      call output(dbl_mb((int_mb(k_sp2c_lindx+ls))),1,
2054*rak:     &    ((ls+1)*(ls+2)/2),1,(2*ls+1),
2055*rak:     &    ((ls+1)*(ls+2)/2),(2*ls+1),1)
2056c
2057      if (sph_cart_init.ne.SPH_CART_INIT_VALUE) call errquit
2058     &    ('spcart_sh_a: spcart not initialized properly',
2059     &    sph_cart_init, UNKNOWN_ERR)
2060c
2061      if (in_place) then
2062        write (6,*)' in place transformations are not ready yet '
2063      endif
2064c
2065c  spint(-5) = cint(2)*dtrans(2,-5,5) + cint(7)*dtrans(7,-5,5) + cint(16)*dtrans(16,-5,5)
2066c  spint(-4) = cint(5)*dtrans(5,-4,5) + cint(12)*dtrans(12,-4,5)
2067c  spint(-3) = cint(2)*dtrans(2,-3,5) + cint(7)*dtrans(7,-3,5) + cint(9)*dtrans(9,-3,5)
2068c            + cint(16)*dtrans(16,-3,5) + cint(18)*dtrans(18,-3,5)
2069c  spint(-2) = cint(5)*dtrans(5,-2,5) + cint(12)*dtrans(12,-2,5) + cint(14)*dtrans(14,-2,5)
2070c  spint(-1) = cint(2)*dtrans(2,-1,5) + cint(7)*dtrans(7,-1,5) + cint(9)*dtrans(9,-1,5)
2071c            + cint(16)*dtrans(16,-1,5) + cint(18)*dtrans(18,-1,5) + cint(20)*dtrans(20,-1,5)
2072c  spint( 0) = cint(3)*dtrans(3,0,5) + cint(8)*dtrans(8,0,5) + cint(10)*dtrans(10,0,5)
2073c            + cint(17)*dtrans(17,0,5) + cint(19)*dtrans(19,0,5) + cint(21)*dtrans(21,0,5)
2074c  spint( 1) = cint(1)*dtrans(1,1,5)   + cint(4)*dtrans(4,1,5)   + cint(6)*dtrans(6,1,5)
2075c            + cint(11)*dtrans(11,1,5) + cint(13)*dtrans(13,1,5) + cint(15)*dtrans(15,1,5)
2076c  spint( 2) = cint(3)*dtrans(3,2,5) + cint(10)*dtrans(10,2,5) + cint(17)*dtrans(17,2,5)
2077c            + cint(19)*dtrans(19,2,5)
2078c  spint( 3) = cint(1)*dtrans(1,3,5) + cint(4)*dtrans(4,3,5) + cint(6)*dtrans(6,3,5)
2079c            + cint(11)*dtrans(11,3,5) + cint(13)*dtrans(13,3,5)
2080c  spint( 4) = cint(3)*dtrans(3,4,5) + cint(8)*dtrans(8,4,5) + cint(17)*dtrans(17,4,5)
2081c  spint( 5) = cint(1)*dtrans(1,4,5) + cint(4)*dtrans(4,4,5) + cint(11)*dtrans(11,4,5)
2082c
2083      dt2_m5  = dtrans(2,-5,5)
2084      dt7_m5  = dtrans(7,-5,5)
2085      dt16_m5 = dtrans(16,-5,5)
2086      dt5_m4  = dtrans(5,-4,5)
2087      dt12_m4 = dtrans(12,-4,5)
2088      dt2_m3  = dtrans(2,-3,5)
2089      dt7_m3  = dtrans(7,-3,5)
2090      dt9_m3  = dtrans(9,-3,5)
2091      dt16_m3 = dtrans(16,-3,5)
2092      dt18_m3 = dtrans(18,-3,5)
2093      dt5_m2  = dtrans(5,-2,5)
2094      dt12_m2 = dtrans(12,-2,5)
2095      dt14_m2 = dtrans(14,-2,5)
2096      dt2_m1  = dtrans(2,-1,5)
2097      dt7_m1  = dtrans(7,-1,5)
2098      dt9_m1  = dtrans(9,-1,5)
2099      dt16_m1 = dtrans(16,-1,5)
2100      dt18_m1 = dtrans(18,-1,5)
2101      dt20_m1 = dtrans(20,-1,5)
2102      dt3_0   = dtrans(3,0,5)
2103      dt8_0   = dtrans(8,0,5)
2104      dt10_0  = dtrans(10,0,5)
2105      dt17_0  = dtrans(17,0,5)
2106      dt19_0  = dtrans(19,0,5)
2107      dt21_0  = dtrans(21,0,5)
2108      dt1_1   = dtrans(1,1,5)
2109      dt4_1   = dtrans(4,1,5)
2110      dt6_1   = dtrans(6,1,5)
2111      dt11_1  = dtrans(11,1,5)
2112      dt13_1  = dtrans(13,1,5)
2113      dt15_1  = dtrans(15,1,5)
2114      dt3_2   = dtrans(3,2,5)
2115      dt10_2  = dtrans(10,2,5)
2116      dt17_2  = dtrans(17,2,5)
2117      dt19_2  = dtrans(19,2,5)
2118      dt1_3   = dtrans(1,3,5)
2119      dt4_3   = dtrans(4,3,5)
2120      dt6_3   = dtrans(6,3,5)
2121      dt11_3  = dtrans(11,3,5)
2122      dt13_3  = dtrans(13,3,5)
2123      dt3_4   = dtrans(3,4,5)
2124      dt8_4   = dtrans(8,4,5)
2125      dt17_4  = dtrans(17,4,5)
2126      dt1_5   = dtrans(1,5,5)
2127      dt4_5   = dtrans(4,5,5)
2128      dt11_5  = dtrans(11,5,5)
2129      do g=1,ngls
2130        do i=1,ndima
2131          bin1  = blockin(i, 1,g)
2132          bin2  = blockin(i, 2,g)
2133          bin3  = blockin(i, 3,g)
2134          bin4  = blockin(i, 4,g)
2135          bin5  = blockin(i, 5,g)
2136          bin6  = blockin(i, 6,g)
2137          bin7  = blockin(i, 7,g)
2138          bin8  = blockin(i, 8,g)
2139          bin9  = blockin(i, 9,g)
2140          bin10 = blockin(i,10,g)
2141          bin11 = blockin(i,11,g)
2142          bin12 = blockin(i,12,g)
2143          bin13 = blockin(i,13,g)
2144          bin14 = blockin(i,14,g)
2145          bin15 = blockin(i,15,g)
2146          bin16 = blockin(i,16,g)
2147          bin17 = blockin(i,17,g)
2148          bin18 = blockin(i,18,g)
2149          bin19 = blockin(i,19,g)
2150          bin20 = blockin(i,20,g)
2151          bin21 = blockin(i,21,g)
2152c
2153          blockout(i,-5,g) = bin2*dt2_m5  + bin7*dt7_m5   +
2154     &                       bin16*dt16_m5
2155          blockout(i,-4,g) = bin5*dt5_m4  + bin12*dt12_m4
2156          blockout(i,-3,g) = bin2*dt2_m3  + bin7*dt7_m3   +
2157     &                       bin9*dt9_m3  + bin16*dt16_m3 +
2158     &                       bin18*dt18_m3
2159          blockout(i,-2,g) = bin5*dt5_m2  + bin12*dt12_m2 +
2160     &                       bin14*dt14_m2
2161          blockout(i,-1,g) = bin2*dt2_m1  + bin7*dt7_m1   +
2162     &                       bin9*dt9_m1  + bin16*dt16_m1 +
2163     &                       bin18*dt18_m1+ bin20*dt20_m1
2164          blockout(i, 0,g) = bin3*dt3_0   + bin8*dt8_0    +
2165     &                       bin10*dt10_0 + bin17*dt17_0  +
2166     &                       bin19*dt19_0 + bin21*dt21_0
2167          blockout(i, 1,g) = bin1*dt1_1   + bin4*dt4_1    +
2168     &                       bin6*dt6_1   + bin11*dt11_1  +
2169     &                       bin13*dt13_1 + bin15*dt15_1
2170          blockout(i, 2,g) = bin3*dt3_2   + bin10*dt10_2  +
2171     &                       bin17*dt17_2 + bin19*dt19_2
2172          blockout(i, 3,g) = bin1*dt1_3   + bin4*dt4_3    +
2173     &                       bin6*dt6_3   + bin11*dt11_3  +
2174     &                       bin13*dt13_3
2175          blockout(i, 4,g) = bin3*dt3_4   + bin8*dt8_4    +
2176     &                       bin17*dt17_4
2177          blockout(i, 5,g) = bin1*dt1_5   + bin4*dt4_5    +
2178     &                       bin11*dt11_5
2179        enddo
2180      enddo
2181      end
2182*.......................................................................
2183      subroutine spcart_sh_a(blockin, blockout, ndima, ngls,
2184     &    in_place, print_info)
2185      implicit none
2186c
2187c  transforms a block of integrals where the h function is the fastest dimension
2188c  e.g., blockin(21,ndima) and blockout(11,ndima)
2189c
2190#include "mafdecls.fh"
2191#include "errquit.fh"
2192#include "spcartP.fh"
2193c
2194c: passed
2195      integer ndima  ! [input] leading dimension of block
2196      integer ngls   ! [input] general contraction length of ls block
2197      double precision blockin (21,ngls,ndima)   ! [input] matrix
2198      double precision blockout(-5:5,ngls,ndima) ! [output] matrix
2199      logical in_place  ! [input] true if blockin and block out are the same pointer
2200      logical print_info ! [input] print info
2201c: local
2202      integer i,g
2203      double precision dt2_m5, dt7_m5, dt16_m5, dt5_m4, dt12_m4, dt2_m3
2204      double precision dt7_m3, dt9_m3, dt16_m3, dt18_m3, dt5_m2, dt12_m2
2205      double precision dt14_m2, dt2_m1, dt7_m1, dt9_m1, dt16_m1, dt18_m1
2206      double precision dt20_m1, dt3_0, dt8_0, dt10_0, dt17_0, dt19_0
2207      double precision dt21_0, dt1_1, dt4_1, dt6_1, dt11_1, dt13_1
2208      double precision dt15_1, dt3_2, dt10_2, dt17_2, dt19_2, dt1_3
2209      double precision dt4_3, dt6_3, dt11_3, dt13_3, dt3_4, dt8_4
2210      double precision dt17_4, dt1_5, dt4_5, dt11_5
2211      double precision bin1, bin2, bin3, bin4, bin5, bin6
2212      double precision bin7, bin8, bin9, bin10
2213      double precision bin11, bin12, bin13, bin14, bin15
2214      double precision bin16, bin17, bin18, bin19, bin20, bin21
2215*rak:      integer ls     ! [fixed at 5] angular momentum of block
2216c::statement function ----- start
2217      integer iic,iis,iil
2218      double precision Dtrans
2219      Dtrans(iic,iis,iil) =
2220     &    dbl_mb((int_mb(k_sp2c_lindx+iil))+
2221     &           ((iis+iil)*(iil+1)*(iil+2)/2)
2222     &           + iic - 1)
2223c::statement function ----- end
2224c
2225*rak:      ls=5
2226*rak:      write(6,*)'a_s,(ndima,l2s) ndima = ',ndima,'   ls = ',ls
2227*rak:      write(6,*)' trans matrix used '
2228*rak:      call output(dbl_mb((int_mb(k_sp2c_lindx+ls))),1,
2229*rak:     &    ((ls+1)*(ls+2)/2),1,(2*ls+1),
2230*rak:     &    ((ls+1)*(ls+2)/2),(2*ls+1),1)
2231c
2232      if (sph_cart_init.ne.SPH_CART_INIT_VALUE) call errquit
2233     &    ('spcart_sh_a: spcart not initialized properly',
2234     &    sph_cart_init, UNKNOWN_ERR)
2235c
2236      if (in_place) then
2237        write (6,*)' in place transformations are not ready yet '
2238      endif
2239c
2240c  spint(-5) = cint(2)*dtrans(2,-5,5) + cint(7)*dtrans(7,-5,5) + cint(16)*dtrans(16,-5,5)
2241c  spint(-4) = cint(5)*dtrans(5,-4,5) + cint(12)*dtrans(12,-4,5)
2242c  spint(-3) = cint(2)*dtrans(2,-3,5) + cint(7)*dtrans(7,-3,5) + cint(9)*dtrans(9,-3,5)
2243c            + cint(16)*dtrans(16,-3,5) + cint(18)*dtrans(18,-3,5)
2244c  spint(-2) = cint(5)*dtrans(5,-2,5) + cint(12)*dtrans(12,-2,5) + cint(14)*dtrans(14,-2,5)
2245c  spint(-1) = cint(2)*dtrans(2,-1,5) + cint(7)*dtrans(7,-1,5) + cint(9)*dtrans(9,-1,5)
2246c            + cint(16)*dtrans(16,-1,5) + cint(18)*dtrans(18,-1,5) + cint(20)*dtrans(20,-1,5)
2247c  spint( 0) = cint(3)*dtrans(3,0,5) + cint(8)*dtrans(8,0,5) + cint(10)*dtrans(10,0,5)
2248c            + cint(17)*dtrans(17,0,5) + cint(19)*dtrans(19,0,5) + cint(21)*dtrans(21,0,5)
2249c  spint( 1) = cint(1)*dtrans(1,1,5)   + cint(4)*dtrans(4,1,5)   + cint(6)*dtrans(6,1,5)
2250c            + cint(11)*dtrans(11,1,5) + cint(13)*dtrans(13,1,5) + cint(15)*dtrans(15,1,5)
2251c  spint( 2) = cint(3)*dtrans(3,2,5) + cint(10)*dtrans(10,2,5) + cint(17)*dtrans(17,2,5)
2252c            + cint(19)*dtrans(19,2,5)
2253c  spint( 3) = cint(1)*dtrans(1,3,5) + cint(4)*dtrans(4,3,5) + cint(6)*dtrans(6,3,5)
2254c            + cint(11)*dtrans(11,3,5) + cint(13)*dtrans(13,3,5)
2255c  spint( 4) = cint(3)*dtrans(3,4,5) + cint(8)*dtrans(8,4,5) + cint(17)*dtrans(17,4,5)
2256c  spint( 5) = cint(1)*dtrans(1,4,5) + cint(4)*dtrans(4,4,5) + cint(11)*dtrans(11,4,5)
2257c
2258      dt2_m5  = dtrans(2,-5,5)
2259      dt7_m5  = dtrans(7,-5,5)
2260      dt16_m5 = dtrans(16,-5,5)
2261      dt5_m4  = dtrans(5,-4,5)
2262      dt12_m4 = dtrans(12,-4,5)
2263      dt2_m3  = dtrans(2,-3,5)
2264      dt7_m3  = dtrans(7,-3,5)
2265      dt9_m3  = dtrans(9,-3,5)
2266      dt16_m3 = dtrans(16,-3,5)
2267      dt18_m3 = dtrans(18,-3,5)
2268      dt5_m2  = dtrans(5,-2,5)
2269      dt12_m2 = dtrans(12,-2,5)
2270      dt14_m2 = dtrans(14,-2,5)
2271      dt2_m1  = dtrans(2,-1,5)
2272      dt7_m1  = dtrans(7,-1,5)
2273      dt9_m1  = dtrans(9,-1,5)
2274      dt16_m1 = dtrans(16,-1,5)
2275      dt18_m1 = dtrans(18,-1,5)
2276      dt20_m1 = dtrans(20,-1,5)
2277      dt3_0   = dtrans(3,0,5)
2278      dt8_0   = dtrans(8,0,5)
2279      dt10_0  = dtrans(10,0,5)
2280      dt17_0  = dtrans(17,0,5)
2281      dt19_0  = dtrans(19,0,5)
2282      dt21_0  = dtrans(21,0,5)
2283      dt1_1   = dtrans(1,1,5)
2284      dt4_1   = dtrans(4,1,5)
2285      dt6_1   = dtrans(6,1,5)
2286      dt11_1  = dtrans(11,1,5)
2287      dt13_1  = dtrans(13,1,5)
2288      dt15_1  = dtrans(15,1,5)
2289      dt3_2   = dtrans(3,2,5)
2290      dt10_2  = dtrans(10,2,5)
2291      dt17_2  = dtrans(17,2,5)
2292      dt19_2  = dtrans(19,2,5)
2293      dt1_3   = dtrans(1,3,5)
2294      dt4_3   = dtrans(4,3,5)
2295      dt6_3   = dtrans(6,3,5)
2296      dt11_3  = dtrans(11,3,5)
2297      dt13_3  = dtrans(13,3,5)
2298      dt3_4   = dtrans(3,4,5)
2299      dt8_4   = dtrans(8,4,5)
2300      dt17_4  = dtrans(17,4,5)
2301      dt1_5   = dtrans(1,5,5)
2302      dt4_5   = dtrans(4,5,5)
2303      dt11_5  = dtrans(11,5,5)
2304      do i=1,ndima
2305        do g=1,ngls
2306          bin1  = blockin( 1,g,i)
2307          bin2  = blockin( 2,g,i)
2308          bin3  = blockin( 3,g,i)
2309          bin4  = blockin( 4,g,i)
2310          bin5  = blockin( 5,g,i)
2311          bin6  = blockin( 6,g,i)
2312          bin7  = blockin( 7,g,i)
2313          bin8  = blockin( 8,g,i)
2314          bin9  = blockin( 9,g,i)
2315          bin10 = blockin(10,g,i)
2316          bin11 = blockin(11,g,i)
2317          bin12 = blockin(12,g,i)
2318          bin13 = blockin(13,g,i)
2319          bin14 = blockin(14,g,i)
2320          bin15 = blockin(15,g,i)
2321          bin16 = blockin(16,g,i)
2322          bin17 = blockin(17,g,i)
2323          bin18 = blockin(18,g,i)
2324          bin19 = blockin(19,g,i)
2325          bin20 = blockin(20,g,i)
2326          bin21 = blockin(21,g,i)
2327c
2328          blockout(-5,g,i) = bin2*dt2_m5  + bin7*dt7_m5   +
2329     &                       bin16*dt16_m5
2330          blockout(-4,g,i) = bin5*dt5_m4  + bin12*dt12_m4
2331          blockout(-3,g,i) = bin2*dt2_m3  + bin7*dt7_m3   +
2332     &                       bin9*dt9_m3  + bin16*dt16_m3 +
2333     &                       bin18*dt18_m3
2334          blockout(-2,g,i) = bin5*dt5_m2  + bin12*dt12_m2 +
2335     &                       bin14*dt14_m2
2336          blockout(-1,g,i) = bin2*dt2_m1  + bin7*dt7_m1   +
2337     &                       bin9*dt9_m1  + bin16*dt16_m1 +
2338     &                       bin18*dt18_m1+ bin20*dt20_m1
2339          blockout( 0,g,i) = bin3*dt3_0   + bin8*dt8_0    +
2340     &                       bin10*dt10_0 + bin17*dt17_0  +
2341     &                       bin19*dt19_0 + bin21*dt21_0
2342          blockout( 1,g,i) = bin1*dt1_1   + bin4*dt4_1    +
2343     &                       bin6*dt6_1   + bin11*dt11_1  +
2344     &                       bin13*dt13_1 + bin15*dt15_1
2345          blockout( 2,g,i) = bin3*dt3_2   + bin10*dt10_2  +
2346     &                       bin17*dt17_2 + bin19*dt19_2
2347          blockout( 3,g,i) = bin1*dt1_3   + bin4*dt4_3    +
2348     &                       bin6*dt6_3   + bin11*dt11_3  +
2349     &                       bin13*dt13_3
2350          blockout( 4,g,i) = bin3*dt3_4   + bin8*dt8_4    +
2351     &                       bin17*dt17_4
2352          blockout( 5,g,i) = bin1*dt1_5   + bin4*dt4_5    +
2353     &                       bin11*dt11_5
2354        enddo
2355      enddo
2356      end
2357*.......................................................................
2358      subroutine spcart_a_sh_b(blockin, blockout,
2359     &    ndima, ndimb, ngls, in_place, print_info)
2360      implicit none
2361c
2362c  transforms a block of integrals where the g function is the middle dimension
2363c  e.g., blockin(ndima,21,ndimb) and blockout(ndima,11,ndimb)
2364c
2365#include "mafdecls.fh"
2366#include "errquit.fh"
2367#include "spcartP.fh"
2368c
2369c: passed
2370      integer ndima  ! [input] leading dimension of block
2371      integer ndimb  ! [input] trailing dimension of block
2372      integer ngls   ! [input] general contraction length of ls block
2373      double precision blockin (ndima,21,ngls,ndimb)   ! [input] matrix
2374      double precision blockout(ndima,-5:5,ngls,ndimb) ! [output] matrix
2375      logical in_place  ! [input] true if blockin and block out are the same pointer
2376      logical print_info ! [input] print info
2377c: local
2378      integer i,j,g
2379      double precision dt2_m5, dt7_m5, dt16_m5, dt5_m4, dt12_m4, dt2_m3
2380      double precision dt7_m3, dt9_m3, dt16_m3, dt18_m3, dt5_m2, dt12_m2
2381      double precision dt14_m2, dt2_m1, dt7_m1, dt9_m1, dt16_m1, dt18_m1
2382      double precision dt20_m1, dt3_0, dt8_0, dt10_0, dt17_0, dt19_0
2383      double precision dt21_0, dt1_1, dt4_1, dt6_1, dt11_1, dt13_1
2384      double precision dt15_1, dt3_2, dt10_2, dt17_2, dt19_2, dt1_3
2385      double precision dt4_3, dt6_3, dt11_3, dt13_3, dt3_4, dt8_4
2386      double precision dt17_4, dt1_5, dt4_5, dt11_5
2387      double precision bin1, bin2, bin3, bin4, bin5, bin6
2388      double precision bin7, bin8, bin9, bin10
2389      double precision bin11, bin12, bin13, bin14, bin15
2390      double precision bin16, bin17, bin18, bin19, bin20, bin21
2391*rak:      integer ls     ! [fixed at 5] angular momentum of block
2392c::statement function ----- start
2393      integer iic,iis,iil
2394      double precision Dtrans
2395      Dtrans(iic,iis,iil) =
2396     &    dbl_mb((int_mb(k_sp2c_lindx+iil))+
2397     &           ((iis+iil)*(iil+1)*(iil+2)/2)
2398     &           + iic - 1)
2399c::statement function ----- end
2400c
2401*rak:      ls=5
2402*rak:      write(6,*)'a_s,(ndima,l2s) ndima = ',ndima,'   ls = ',ls
2403*rak:      write(6,*)' trans matrix used '
2404*rak:      call output(dbl_mb((int_mb(k_sp2c_lindx+ls))),1,
2405*rak:     &    ((ls+1)*(ls+2)/2),1,(2*ls+1),
2406*rak:     &    ((ls+1)*(ls+2)/2),(2*ls+1),1)
2407c
2408      if (sph_cart_init.ne.SPH_CART_INIT_VALUE) call errquit
2409     &    ('spcart_a_sh_b: spcart not initialized properly',
2410     &    sph_cart_init, UNKNOWN_ERR)
2411c
2412      if (in_place) then
2413        write (6,*)' in place transformations are not ready yet '
2414      endif
2415c
2416c  spint(-5) = cint(2)*dtrans(2,-5,5) + cint(7)*dtrans(7,-5,5) + cint(16)*dtrans(16,-5,5)
2417c  spint(-4) = cint(5)*dtrans(5,-4,5) + cint(12)*dtrans(12,-4,5)
2418c  spint(-3) = cint(2)*dtrans(2,-3,5) + cint(7)*dtrans(7,-3,5) + cint(9)*dtrans(9,-3,5)
2419c            + cint(16)*dtrans(16,-3,5) + cint(18)*dtrans(18,-3,5)
2420c  spint(-2) = cint(5)*dtrans(5,-2,5) + cint(12)*dtrans(12,-2,5) + cint(14)*dtrans(14,-2,5)
2421c  spint(-1) = cint(2)*dtrans(2,-1,5) + cint(7)*dtrans(7,-1,5) + cint(9)*dtrans(9,-1,5)
2422c            + cint(16)*dtrans(16,-1,5) + cint(18)*dtrans(18,-1,5) + cint(20)*dtrans(20,-1,5)
2423c  spint( 0) = cint(3)*dtrans(3,0,5) + cint(8)*dtrans(8,0,5) + cint(10)*dtrans(10,0,5)
2424c            + cint(17)*dtrans(17,0,5) + cint(19)*dtrans(19,0,5) + cint(21)*dtrans(21,0,5)
2425c  spint( 1) = cint(1)*dtrans(1,1,5)   + cint(4)*dtrans(4,1,5)   + cint(6)*dtrans(6,1,5)
2426c            + cint(11)*dtrans(11,1,5) + cint(13)*dtrans(13,1,5) + cint(15)*dtrans(15,1,5)
2427c  spint( 2) = cint(3)*dtrans(3,2,5) + cint(10)*dtrans(10,2,5) + cint(17)*dtrans(17,2,5)
2428c            + cint(19)*dtrans(19,2,5)
2429c  spint( 3) = cint(1)*dtrans(1,3,5) + cint(4)*dtrans(4,3,5) + cint(6)*dtrans(6,3,5)
2430c            + cint(11)*dtrans(11,3,5) + cint(13)*dtrans(13,3,5)
2431c  spint( 4) = cint(3)*dtrans(3,4,5) + cint(8)*dtrans(8,4,5) + cint(17)*dtrans(17,4,5)
2432c  spint( 5) = cint(1)*dtrans(1,4,5) + cint(4)*dtrans(4,4,5) + cint(11)*dtrans(11,4,5)
2433c
2434      dt2_m5  = dtrans(2,-5,5)
2435      dt7_m5  = dtrans(7,-5,5)
2436      dt16_m5 = dtrans(16,-5,5)
2437      dt5_m4  = dtrans(5,-4,5)
2438      dt12_m4 = dtrans(12,-4,5)
2439      dt2_m3  = dtrans(2,-3,5)
2440      dt7_m3  = dtrans(7,-3,5)
2441      dt9_m3  = dtrans(9,-3,5)
2442      dt16_m3 = dtrans(16,-3,5)
2443      dt18_m3 = dtrans(18,-3,5)
2444      dt5_m2  = dtrans(5,-2,5)
2445      dt12_m2 = dtrans(12,-2,5)
2446      dt14_m2 = dtrans(14,-2,5)
2447      dt2_m1  = dtrans(2,-1,5)
2448      dt7_m1  = dtrans(7,-1,5)
2449      dt9_m1  = dtrans(9,-1,5)
2450      dt16_m1 = dtrans(16,-1,5)
2451      dt18_m1 = dtrans(18,-1,5)
2452      dt20_m1 = dtrans(20,-1,5)
2453      dt3_0   = dtrans(3,0,5)
2454      dt8_0   = dtrans(8,0,5)
2455      dt10_0  = dtrans(10,0,5)
2456      dt17_0  = dtrans(17,0,5)
2457      dt19_0  = dtrans(19,0,5)
2458      dt21_0  = dtrans(21,0,5)
2459      dt1_1   = dtrans(1,1,5)
2460      dt4_1   = dtrans(4,1,5)
2461      dt6_1   = dtrans(6,1,5)
2462      dt11_1  = dtrans(11,1,5)
2463      dt13_1  = dtrans(13,1,5)
2464      dt15_1  = dtrans(15,1,5)
2465      dt3_2   = dtrans(3,2,5)
2466      dt10_2  = dtrans(10,2,5)
2467      dt17_2  = dtrans(17,2,5)
2468      dt19_2  = dtrans(19,2,5)
2469      dt1_3   = dtrans(1,3,5)
2470      dt4_3   = dtrans(4,3,5)
2471      dt6_3   = dtrans(6,3,5)
2472      dt11_3  = dtrans(11,3,5)
2473      dt13_3  = dtrans(13,3,5)
2474      dt3_4   = dtrans(3,4,5)
2475      dt8_4   = dtrans(8,4,5)
2476      dt17_4  = dtrans(17,4,5)
2477      dt1_5   = dtrans(1,5,5)
2478      dt4_5   = dtrans(4,5,5)
2479      dt11_5  = dtrans(11,5,5)
2480      do j=1,ndimb
2481        do g=1,ngls
2482          do i=1,ndima
2483            bin1  = blockin(i, 1,g,j)
2484            bin2  = blockin(i, 2,g,j)
2485            bin3  = blockin(i, 3,g,j)
2486            bin4  = blockin(i, 4,g,j)
2487            bin5  = blockin(i, 5,g,j)
2488            bin6  = blockin(i, 6,g,j)
2489            bin7  = blockin(i, 7,g,j)
2490            bin8  = blockin(i, 8,g,j)
2491            bin9  = blockin(i, 9,g,j)
2492            bin10 = blockin(i,10,g,j)
2493            bin11 = blockin(i,11,g,j)
2494            bin12 = blockin(i,12,g,j)
2495            bin13 = blockin(i,13,g,j)
2496            bin14 = blockin(i,14,g,j)
2497            bin15 = blockin(i,15,g,j)
2498            bin16 = blockin(i,16,g,j)
2499            bin17 = blockin(i,17,g,j)
2500            bin18 = blockin(i,18,g,j)
2501            bin19 = blockin(i,19,g,j)
2502            bin20 = blockin(i,20,g,j)
2503            bin21 = blockin(i,21,g,j)
2504c
2505            blockout(i,-5,g,j) = bin2*dt2_m5  + bin7*dt7_m5   +
2506     &                           bin16*dt16_m5
2507            blockout(i,-4,g,j) = bin5*dt5_m4  + bin12*dt12_m4
2508            blockout(i,-3,g,j) = bin2*dt2_m3  + bin7*dt7_m3   +
2509     &                           bin9*dt9_m3  + bin16*dt16_m3 +
2510     &                           bin18*dt18_m3
2511            blockout(i,-2,g,j) = bin5*dt5_m2  + bin12*dt12_m2 +
2512     &                           bin14*dt14_m2
2513            blockout(i,-1,g,j) = bin2*dt2_m1  + bin7*dt7_m1   +
2514     &                           bin9*dt9_m1  + bin16*dt16_m1 +
2515     &                           bin18*dt18_m1+ bin20*dt20_m1
2516            blockout(i, 0,g,j) = bin3*dt3_0   + bin8*dt8_0    +
2517     &                           bin10*dt10_0 + bin17*dt17_0  +
2518     &                           bin19*dt19_0 + bin21*dt21_0
2519            blockout(i, 1,g,j) = bin1*dt1_1   + bin4*dt4_1    +
2520     &                           bin6*dt6_1   + bin11*dt11_1  +
2521     &                           bin13*dt13_1 + bin15*dt15_1
2522            blockout(i, 2,g,j) = bin3*dt3_2   + bin10*dt10_2  +
2523     &                           bin17*dt17_2 + bin19*dt19_2
2524            blockout(i, 3,g,j) = bin1*dt1_3   + bin4*dt4_3    +
2525     &                           bin6*dt6_3   + bin11*dt11_3  +
2526     &                           bin13*dt13_3
2527            blockout(i, 4,g,j) = bin3*dt3_4   + bin8*dt8_4    +
2528     &                           bin17*dt17_4
2529            blockout(i, 5,g,j) = bin1*dt1_5   + bin4*dt4_5    +
2530     &                           bin11*dt11_5
2531          enddo
2532        enddo
2533      enddo
2534      end
2535*.......................................................................
2536C>
2537C> \brief Transform 1-electron integrals from Cartesian to spherical
2538C> harmonic basis functions
2539C>
2540C> Even if a basis set is specified as spherical harmonic in the input
2541C> the code actually calculates the integrals in terms of Cartesian
2542C> functions. Hence an additional transformation step is needed to
2543C> obtain the specified integrals in spherical harmonics. This routine
2544C> controls that transformation for various angular momenta.
2545C>
2546      subroutine spcart_tran1e(
2547     &    buf, scr,
2548     &    nbf_xr,nbf_xc,type_r,ngen_r,
2549     &    nbf_sr,nbf_sc,type_c,ngen_c,
2550     &    print)
2551      implicit none
2552#include "stdio.fh"
2553#include "errquit.fh"
2554c
2555c
2556c
2557c routine that transforms a 1e cartesian block buf_cart(nbf_xr,nbf_xc) to
2558c    a spherical block buf_sph(nbf_sr,nbf_sc)
2559c
2560c  x --> implies cartesian
2561c  s --> implies spherical
2562c  r --> implies row
2563c  c --> implies column
2564c
2565c  remember that a Ov block for ish and jsh is
2566c      from the integral api Ov(jbf_lo:jbf_hi,ibf_lo,ibf_hi)
2567c
2568c
2569c Can use a special call setting type_? to 0 for basis sets that
2570c are mixed   i_bas is spherical and j_bas is not dimensions
2571c are not based on type only actions.
2572c
2573c
2574      integer nbf_xr !< [input] number of rows of cartesian block
2575      integer nbf_xc !< [input] number of columns of cartesian block
2576      integer nbf_sr !< [input] number of rows of spherical block
2577      integer nbf_sc !< [input] number of columns of spherical block
2578      integer ngen_r !< [input] general contraction length for rows
2579      integer ngen_c !< [input] general contraction length for columns
2580      integer type_r !< [input] angular momentem for rows
2581      integer type_c !< [input] angular momentem for columns
2582      double precision buf(*) !< [input/output] cartesian block on input
2583                              !< and spherical block on output
2584      double precision scr(*) !< [scratch] use to hold half transformed block
2585      logical print           !< [input] print integrals at each stage of the
2586                              !< transformation (cart/half/spherical)
2587c:: local
2588      integer ngen_rc
2589      logical problem_sp
2590      ngen_rc = ngen_r*ngen_c
2591c... more error checking
2592      problem_sp = (type_r.eq.-1).and.(ngen_r.gt.1)
2593      problem_sp = problem_sp.or.((type_c.eq.-1).and.(ngen_c.gt.1))
2594      if (problem_sp) then
2595        write(6,*)' spcart_tran1e: sp function error '
2596        write(6,*)' sp function block passed with more ',
2597     &      'than one general contraction: ',
2598     &      'this is not allowed in NWChem'
2599        write(6,*)' type r',type_r
2600        write(6,*)' ngen r',ngen_r
2601        write(6,*)' type c',type_c
2602        write(6,*)' ngen c',ngen_c
2603        call errquit('spcart_tran1e: fatal error',911, UNKNOWN_ERR)
2604      endif
2605c
2606      if (type_r.lt.2.and.type_c.lt.2) then
2607c.................................. neither c or r need to be transformed
2608c                                   (X,Y) X is s, p, or l and Y is s, p, or l
2609        if (print) then
2610          write(luout,*)
2611     &        ' cartesian matrix and spherical matrix the same '
2612          call output(buf,1,nbf_xr*ngen_r,1,nbf_xc*ngen_c,
2613     &          nbf_xr*ngen_r,nbf_xc*ngen_c,1)
2614        endif
2615c
2616      elseif (type_r.lt.2.and.type_c.ge.2) then
2617c.................................. c needs to be transformed
2618* print cartesian matrix
2619* buf is buf(spherical,cartesian)
2620        if (print) then
2621          write(luout,*)' cartesian matrix '
2622          call output(buf,1,nbf_xr*ngen_r,1,nbf_xc*ngen_c,
2623     &          nbf_xr*ngen_r,nbf_xc*ngen_c,1)
2624        endif
2625* scr is buf(spherical,cartesian) ! copy it
2626        call dcopy((nbf_xr*nbf_xc*ngen_rc),buf,1,scr,1)
2627        if (nbf_xr.ne.nbf_sr) call errquit
2628     &      ('spcart_tran1e: nbf_xr.ne.nbf_sr  (xr-sr) =',
2629     &      (nbf_xr-nbf_sr), UNKNOWN_ERR)
2630        call spcart_a_s(scr,buf,(ngen_r*nbf_sr),type_c,ngen_c,
2631     &      .false.,print)
2632        if (print) then
2633          write(luout,*)' spherical matrix '
2634          call output(buf,1,ngen_r*nbf_sr,1,ngen_c*nbf_sc,
2635     &          ngen_r*nbf_sr,ngen_c*nbf_sc,1)
2636        endif
2637      elseif (type_r.ge.2.and.type_c.lt.2) then
2638c.................................. r needs to be transformed
2639* print cartesian matrix
2640* buf is buf(cartesian,cartesian)
2641        if (print) then
2642          write(luout,*)' cartesian matrix '
2643          call output(buf,1,ngen_r*nbf_xr,1,ngen_c*nbf_xc,
2644     &          ngen_r*nbf_xr,ngen_c*nbf_xc,1)
2645        endif
2646* scr is buf(spherical,cartesian) ! copy it
2647        call dcopy((ngen_rc*nbf_xr*nbf_xc),buf,1,scr,1)
2648        if (nbf_xc.ne.nbf_sc) call errquit
2649     &      ('spcart_tran1e: nbf_xc.ne.nbf_sc  (xc-sc) =',
2650     &      (nbf_xc-nbf_sc), UNKNOWN_ERR)
2651        call spcart_s_a(scr,buf,ngen_c*nbf_sc,type_r,ngen_r,
2652     &      .false.,print)
2653        if (print) then
2654          write(luout,*)' spherical matrix '
2655          call output(buf,1,ngen_r*nbf_sr,1,ngen_c*nbf_sc,
2656     &          ngen_r*nbf_sr,ngen_c*nbf_sc,1)
2657        endif
2658      elseif (type_r.ge.2.and.type_c.ge.2) then
2659c.................................. both r and c need to be transformed
2660* print cartesian matrix
2661* buf is buf(cartesian,cartesian)
2662        if (print) then
2663          write(luout,*)' cartesian matrix '
2664          call output(buf,1,ngen_r*nbf_xr,1,ngen_c*nbf_xc,
2665     &          ngen_r*nbf_xr,ngen_c*nbf_xc,1)
2666        endif
2667*
2668*... buf(xr,xc) -> scr(xr,sc) : scr is half transformed matrix
2669        call spcart_a_s(buf,scr,ngen_r*nbf_xr,type_c,ngen_c,
2670     &      .false.,print)
2671* print half transformed matrix
2672        if (print) then
2673          write(luout,*)' half cartesian half spherical matrix '
2674          call output(scr,1,ngen_r*nbf_xr,1,ngen_c*nbf_sc,
2675     &          ngen_r*nbf_xr,ngen_c*nbf_sc,1)
2676        endif
2677*
2678*... scr(xr,sc) -> buf(sr,sc)
2679        call spcart_s_a(scr,buf,ngen_c*nbf_sc,type_r,ngen_r,
2680     &      .false.,print)
2681* print spherical block
2682        if (print) then
2683          write(luout,*)' spherical matrix '
2684          call output(buf,1,ngen_r*nbf_sr,1,ngen_c*nbf_sc,
2685     &          ngen_r*nbf_sr,ngen_c*nbf_sc,1)
2686        endif
2687      else
2688        write(luout,*) ' case not possible '
2689        call errquit('spcart_tran1e: should never get here ? ',911,
2690     &       UNKNOWN_ERR)
2691      endif
2692c
2693      end
2694*.......................................................................
2695      subroutine spcart_bra2etran(
2696     &    buf, scr,
2697     &    nbf_xj,nbf_xi,
2698     &    nbf_sj,nbf_si,
2699     &    type_j,type_i,
2700     &    ngen_j,ngen_i,
2701     &    ndim_ket,
2702     &    print)
2703      implicit none
2704#include "stdio.fh"
2705#include "errquit.fh"
2706c
2707c routine that transforms a 2e cartesian block buf_cart(ndim_ket,nbf_xj,nbf_xi) to
2708c    a spherical block buf_sph(ndim_ket,nbf_sj,nbf_si)
2709c
2710c  x --> implies cartesian
2711c  s --> implies spherical
2712c
2713c  remember that a 2e block for ish jsh for any k/l sh is
2714c      from the integral api ERI(ndim_ket,jbf_lo:jbf_hi,ibf_lo,ibf_hi)
2715c
2716c row-j col-i
2717c
2718c  blockin(ndim_ket,jxR,ixR)*trans = blockout(ndim_ket,jsR,isR)
2719c
2720c
2721      integer nbf_xj, nbf_xi  ! [input] size of cartesian block
2722      integer nbf_sj, nbf_si  ! [input] size of spherical block
2723      integer type_j, type_i  ! [input] angular momentem for j and i
2724      integer ngen_j, ngen_i  ! [input] general contraction length for j and i
2725      integer ndim_ket
2726      double precision buf(*) ! [input/output] cartesian block on input
2727*.............................!   and spherical block on output
2728      double precision scr(*) ! [scratch] use to hold half transformed block
2729      logical print           ! [input} print integrals at each stage of the
2730*.............................!   transformation (cart/half/spherical)
2731*::local
2732      logical problem_sp
2733      integer ngen_ij, sxi, sxj, ssi, ssj
2734c
2735      if(print) then
2736         write(6,*)' bra2etran '
2737         write(6,*)'bra2: nbf_xj, nbf_xi :',nbf_xj, nbf_xi
2738         write(6,*)'bra2: nbf_sj, nbf_si :',nbf_sj, nbf_si
2739         write(6,*)'bra2: type_j, type_i :',type_j, type_i
2740         write(6,*)'bra2: ngen_j, ngen_i :',ngen_j, ngen_i
2741         write(6,*)'bra2: ndim_ket       :',ndim_ket
2742      endif
2743c... more error checking
2744      problem_sp = (type_j.eq.-1).and.(ngen_j.gt.1)
2745      problem_sp = problem_sp.or.((type_i.eq.-1).and.(ngen_i.gt.1))
2746      if (problem_sp) then
2747        write(6,*)' spcart_bra2etran: sp function error '
2748        write(6,*)' sp function block passed with more ',
2749     &      'than one general contraction: ',
2750     &      'this is not allowed in NWChem'
2751        write(6,*)' type j',type_j
2752        write(6,*)' ngen j',ngen_j
2753        write(6,*)' type i',type_i
2754        write(6,*)' ngen i',ngen_i
2755        call errquit('spcart_bra2etran: fatal error',911, UNKNOWN_ERR)
2756      endif
2757c
2758      ngen_ij = ngen_i*ngen_j
2759      sxi = nbf_xi*ngen_i
2760      sxj = nbf_xj*ngen_j
2761      ssi = nbf_si*ngen_i
2762      ssj = nbf_sj*ngen_j
2763c
2764      if (type_j.lt.2.and.type_i.lt.2) then
2765c.................................. neither i or j need to be transformed
2766c                                   (X,Y) X is s, p, or l and Y is s, p, or l
2767        if (print) then
2768          write(luout,*)
2769     &        ' cartesian matrix and spherical matrix the same '
2770          call slice_am_print(ndim_ket,sxj,sxi,buf,
2771     &        ' (ket:j-cart/s:i-cart/s')
2772        endif
2773      elseif (type_j.lt.2.and.type_i.ge.2) then
2774*...................ERI(ndim_ket,jbf_lo:jbf_hi,ibf_lo,ibf_hi)
2775c.................................. i needs to be transformed
2776* print cartesian matrix
2777* buf is buf(ndim_ket,j_spherical,i_cartesian)
2778        if (print) then
2779          write(luout,*)' (ket:j-spherical:i-cartesian) matrix '
2780          call slice_am_print(ndim_ket,ssj,sxi,buf,
2781     &          ' (ket:j-spherical:i-cartesian) matrix ')
2782        endif
2783* scr is buf(ndim_ket,j_spherical,i_cartesian) ! copy it
2784*...................ERI(ndim_ket,jbf_lo:jbf_hi,ibf_lo,ibf_hi)
2785        call dcopy((ndim_ket*ssj*sxi),buf,1,scr,1)
2786        if (nbf_xj.ne.nbf_sj) call errquit
2787     &      ('spcart_bra2etran: nbf_xj.ne.nbf_sj  (xj-sj) =',
2788     &      (nbf_xj-nbf_sj), UNKNOWN_ERR)
2789        call spcart_a_s(scr,buf,(ndim_ket*ssj),
2790     &        type_i,ngen_i,.false.,print)
2791        if (print) then
2792          write(luout,*)' (ket:j-spherical:i-shperical) matrix '
2793          call slice_am_print(ndim_ket,ssj,ssi,buf,
2794     &          ' (ket:j-spherical:i-shperical) matrix ')
2795        endif
2796      elseif (type_j.ge.2.and.type_i.lt.2) then
2797*...................ERI(ndim_ket,jbf_lo:jbf_hi,ibf_lo,ibf_hi)
2798c.................................. j needs to be transformed
2799* print cartesian matrix
2800* buf is buf(ndim_ket,j_cartesian,i_spherical)
2801        if (print) then
2802          write(luout,*)' (ket:j-cartesian:i-spherical) matrix '
2803          call slice_am_print(ndim_ket,sxj,ssi,buf,
2804     &          ' (ket:j-cartesian:i-spherical) matrix ')
2805        endif
2806* buf is buf(ndim_ket,j_cartesian,i_spherical)
2807* scr is buf(ndim_ket,j_cartesian,i_spherical) ! copy it
2808        call dcopy((ndim_ket*sxj*ssi),buf,1,scr,1)
2809        if (nbf_xi.ne.nbf_si) call errquit
2810     &      ('spcart_bra2etran: nbf_xc.ne.nbf_sc  (xi-si) =',
2811     &      (nbf_xi-nbf_si), UNKNOWN_ERR)
2812        call spcart_a_s_b(scr,buf,ndim_ket,ssi,
2813     &        type_j,ngen_j,.false.,print)
2814        if (print) then
2815          write(luout,*)' (ket:j-spherical:i-spherical) matrix '
2816          call slice_am_print(ndim_ket,ssj,ssi,buf,
2817     &          ' (ket:j-spherical:i-spherical) matrix ')
2818        endif
2819      elseif (type_j.ge.2.and.type_i.ge.2) then
2820*...................ERI(ndim_ket,jbf_lo:jbf_hi,ibf_lo,ibf_hi)
2821c........................ both j and i need to be transformed
2822* print cartesian matrix
2823* buf is buf(ndim_ket,j_cartesian,i_cartesian)
2824        if (print) then
2825          write(luout,*)' (ket:j-cartesian:i-cartesian) matrix '
2826          call slice_am_print(ndim_ket,sxj,sxi,buf,
2827     &          ' (ket:j-cartesian:i-cartesian) matrix ')
2828        endif
2829*
2830*... buf(ndim_ket,xj,xi) -> scr(xj,si) : scr is half transformed matrix
2831        call spcart_a_s(buf,scr,(ndim_ket*sxj),
2832     &        type_i,ngen_i,.false.,print)
2833* print half transformed matrix
2834        if (print) then
2835          write(luout,*)' (ket:j-cartesian:i-spherical) matrix '
2836          call slice_am_print(ndim_ket,sxj,ssi,scr,
2837     &          ' (ket:j-cartesian:i-spherical) matrix ')
2838        endif
2839*
2840*... scr(xj,si) -> buf(sj,si)
2841        call spcart_a_s_b(scr,buf,ndim_ket,ssi,
2842     &        type_j,ngen_j,.false.,print)
2843* print spherical block
2844        if (print) then
2845          write(luout,*)' (ket:j-spherical:i-spherical) matrix '
2846          call slice_am_print(ndim_ket,ssj,ssi,buf,
2847     &          ' (ket:j-spherical:i-spherical) matrix ')
2848        endif
2849c
2850      else
2851        write(luout,*) ' case not possible '
2852        call errquit('spcart_bra2etran: should never get here ? ',911,
2853     &       UNKNOWN_ERR)
2854      endif
2855c
2856      end
2857*.......................................................................
2858      subroutine spcart_ket2etran(
2859     &    buf, scr,
2860     &    nbf_xl,nbf_xk,
2861     &    nbf_sl,nbf_sk,
2862     &    type_l,type_k,
2863     &    ngen_l,ngen_k,
2864     &    ndim_bra,
2865     &    print)
2866      implicit none
2867#include "stdio.fh"
2868#include "errquit.fh"
2869c
2870c routine that transforms a 2e cartesian block
2871c     buf_cart(nbf_xl,nbf_xk,ndim_bra) to
2872c    a spherical block buf_sph(nbf_sl,nbf_sk,ndim_bra)
2873c
2874c  x --> implies cartesian
2875c  s --> implies spherical
2876c
2877c  remember that a 2e block for ksh lsh for any i(j)sh is
2878c      from the integral api ERI(lbf_lo:lbf_hi,kbf_lo,kbf_hi,ndim_bra)
2879c
2880c row-l col-k
2881c
2882c  blockin(lxR,kxR,ndim_bra)*trans = blockout(lsR,ksR,ndim_bra)
2883c
2884c
2885      integer nbf_xl, nbf_xk  ! [input] size of cartesian block
2886      integer nbf_sl, nbf_sk  ! [input] size of spherical block
2887      integer type_l, type_k  ! [input] angular momentem for l and k
2888      integer ngen_l, ngen_k  ! [input] general contraction length for l and k
2889      integer ndim_bra
2890      double precision buf(*) ! [input/output] cartesian block on input
2891*.............................!   and spherical block on output
2892      double precision scr(*) ! [scratch] use to hold half transformed block
2893      logical print           ! [input} print integrals at each stage of the
2894*.............................!   transformation (cart/half/spherical)
2895*::local
2896      logical problem_sp
2897      integer ngen_kl, sxl, sxk, ssl, ssk
2898c
2899      if(print) then
2900         write(6,*)' ket2etran '
2901         write(6,*)'ket2: nbf_xl, nbf_xk :',nbf_xl, nbf_xk
2902         write(6,*)'ket2: nbf_sl, nbf_sk :',nbf_sl, nbf_sk
2903         write(6,*)'ket2: type_l, type_k :',type_l, type_k
2904         write(6,*)'ket2: ngen_l, ngen_k :',ngen_l, ngen_k
2905         write(6,*)'ket2: ndim_bra       :',ndim_bra
2906      endif
2907c... more error checking
2908      problem_sp = (type_l.eq.-1).and.(ngen_l.gt.1)
2909      problem_sp = problem_sp.or.((type_k.eq.-1).and.(ngen_k.gt.1))
2910      if (problem_sp) then
2911        write(6,*)' spcart_ket2etran: sp function error '
2912        write(6,*)' sp function block passed with more ',
2913     &      'than one general contraction: ',
2914     &      'this is not allowed in NWChem'
2915        write(6,*)' type l',type_l
2916        write(6,*)' ngen l',ngen_l
2917        write(6,*)' type k',type_k
2918        write(6,*)' ngen k',ngen_k
2919        call errquit('spcart_ket2etran: fatal error',911,
2920     &       UNKNOWN_ERR)
2921      endif
2922c
2923c
2924      ngen_kl = ngen_l * ngen_k
2925      sxl = nbf_xl*ngen_l
2926      sxk = nbf_xk*ngen_k
2927      ssl = nbf_sl*ngen_l
2928      ssk = nbf_sk*ngen_k
2929c
2930      if (type_l.lt.2.and.type_k.lt.2) then
2931c.................................. neither k or l need to be transformed
2932c                                   (X,Y) X is s, p, or l and Y is s, p, or l
2933*...................ERI(lbf_lo:lbf_hi,kbf_lo,kbf_hi,ndim_bra)
2934        if (print) then
2935          write(luout,*)
2936     &        ' cartesian matrix and spherical matrix the same '
2937          call slice_ma_print(ndim_bra,sxl,sxk,buf,
2938     &          ' cartesian matrix and spherical matrix the same ')
2939        endif
2940      elseif (type_l.lt.2.and.type_k.ge.2) then
2941*...................ERI(lbf_lo:lbf_hi,kbf_lo,kbf_hi,ndim_bra)
2942c.................................. k needs to be transformed
2943* print cartesian matrix
2944* buf is buf(spherical,cartesian,ndim_bra)
2945        if (print) then
2946          write(luout,*)' (spherical:cartesian:bra) matrix '
2947          call slice_ma_print(ndim_bra,ssl,sxk,buf,
2948     &          ' (l-spherical:k-cartesian:bra) matrix ')
2949        endif
2950* scr is buf(l_spherical,k_cartesian,ndim_bra) ! copy it
2951*...................ERI(lbf_lo:lbf_hi,kbf_lo,kbf_hi,ndim_bra)
2952        call dcopy((ndim_bra*ssl*sxk),buf,1,scr,1)
2953        if (nbf_xl.ne.nbf_sl) call errquit
2954     &      ('spcart_ket2etran: nbf_xl.ne.nbf_sl  (xl-sl) =',
2955     &      (nbf_xl-nbf_sl), UNKNOWN_ERR)
2956        call spcart_a_s_b(scr,buf,ssl,ndim_bra,
2957     &        type_k,ngen_k,.false.,print)
2958        if (print) then
2959          write(luout,*)' (l-spherical:k-shperical:bra) matrix '
2960          call slice_ma_print(ndim_bra,ssl,ssk,buf,
2961     &          ' (l-spherical:k-shperical:bra) matrix ')
2962        endif
2963      elseif (type_l.ge.2.and.type_k.lt.2) then
2964*...................ERI(lbf_lo:lbf_hi,kbf_lo,kbf_hi,ndim_bra)
2965c.................................. l needs to be transformed
2966* print cartesian matrix
2967* buf is buf(l_cartesian,k_spherical,ndim_bra)
2968        if (print) then
2969          write(luout,*)' (l-cartesian:k-spherical:bra) matrix '
2970          call slice_ma_print(ndim_bra,sxl,ssk,buf,
2971     &          ' (l-cartesian:k-spherical:bra) matrix ')
2972        endif
2973* buf is buf(l_cartesian,k_spherical,ndim_bra)
2974* scr is buf(l_cartesian,k_spherical,ndim_bra)
2975        call dcopy((ndim_bra*sxl*ssk),buf,1,scr,1)
2976        if (nbf_xk.ne.nbf_sk) call errquit
2977     &      ('spcart_ket2etran: nbf_xk.ne.nbf_sk  (xk-sk) =',
2978     &      (nbf_xk-nbf_sk), UNKNOWN_ERR)
2979        call spcart_s_a(scr,buf,(ndim_bra*ssk),
2980     &        type_l,ngen_l,.false.,print)
2981        if (print) then
2982          write(luout,*)' (l-spherical:k-spherical:bra) matrix '
2983          call slice_ma_print(ndim_bra,ssl,ssk,buf,
2984     &          ' (l-spherical:k-spherical:bra) matrix ')
2985        endif
2986      elseif (type_l.ge.2.and.type_k.ge.2) then
2987*...................ERI(lbf_lo:lbf_hi,kbf_lo,kbf_hi,ndim_bra)
2988c........................ both k and l need to be transformed
2989* print cartesian matrix
2990* buf is buf(l_cartesian,k_cartesian,ndim_bra)
2991        if (print) then
2992          write(luout,*)' (l-cartesian:k-cartesian:bra) matrix '
2993          call slice_ma_print(ndim_bra,sxl,sxk,buf,
2994     &          ' (l-cartesian:k-cartesian:bra) matrix ')
2995        endif
2996*
2997*... buf(xl,xk) -> scr(sl,xk,ndim_bra,) : scr is half transformed matrix
2998        call spcart_s_a(buf,scr,(sxk*ndim_bra),
2999     &        type_l,ngen_l,.false.,print)
3000* print half transformed matrix
3001        if (print) then
3002          write(luout,*)' (l-spherical:k-cartesian:bra) matrix '
3003          call slice_ma_print(ndim_bra,sxl,ssk,scr,
3004     &          ' (l-cartesian:k-spherical:bra) matrix ')
3005        endif
3006*
3007*... scr(sl,xk) -> buf(sl,sk)
3008        call spcart_a_s_b(scr,buf,ssl,ndim_bra,
3009     &        type_k,ngen_k,.false.,print)
3010* print spherical block
3011        if (print) then
3012          write(luout,*)' (l-spherical:k-spherical:bra) matrix '
3013          call slice_ma_print(ndim_bra,ssl,ssk,buf,
3014     &          ' (l-spherical:k-spherical:bra) matrix ')
3015        endif
3016c
3017      else
3018        write(luout,*) ' case not possible '
3019        call errquit('spcart_ket2etran: should never get here ? ',911,
3020     &       UNKNOWN_ERR)
3021      endif
3022c
3023      end
3024      subroutine slice_am_print(na,ni,nj,M,msg)
3025      implicit none
3026*
3027* routine to print 2d slices(i,j) of a matrix dimensioned
3028*
3029*  Matrix(na,ni,nj)
3030*
3031#include "stdio.fh"
3032#include "errquit.fh"
3033#include "mafdecls.fh"
3034      integer na, ni, nj           ! [input] matrix dimensions
3035      double precision M(na,ni,nj) ! [input] matrix to print
3036      character*(*) msg            ! [input] message for output
3037c
3038      integer h_slice, k_slice
3039      integer a,i,j,cnt
3040c
3041      if (.not.ma_push_get(mt_dbl,(ni*nj),
3042     &      'slice_am_print scratch',h_slice,k_slice))
3043     &      call errquit
3044     &      ('slice_am_print: could not allocate (push) slice',911,
3045     &      UNKNOWN_ERR)
3046c
3047      write(luout,*)' sliced matrix output ',msg
3048      write(luout,*)na,' slices to be printed ',msg
3049      do a=1,na
3050        call dcopy((ni*nj),0.0d00,0,dbl_mb(k_slice),1)
3051        cnt = k_slice
3052        do i=1,ni
3053          do j=1,nj
3054            dbl_mb(cnt) = M(a,i,j)
3055            cnt = cnt + 1
3056          enddo
3057        enddo
3058        write(luout,*)' slice ',a,' ',msg
3059        call output(dbl_mb(k_slice),1,ni,1,nj,ni,nj,1)
3060      enddo
3061c
3062      if (.not.ma_pop_stack(h_slice))call errquit
3063     &      ('slice_am_print: could not deallocate (pop) slice',911,
3064     &      MEM_ERR)
3065c
3066      end
3067      subroutine slice_ma_print(na,ni,nj,M,msg)
3068      implicit none
3069*
3070* routine to print 2d slices(i,j) of a matrix dimensioned
3071*
3072*  Matrix(ni,nj,na)
3073*
3074#include "stdio.fh"
3075      integer na, ni, nj           ! [input] matrix dimensions
3076      double precision M(ni,nj,na) ! [input] matrix to print
3077      character*(*) msg            ! [input] message for output
3078c
3079      integer a
3080      write(luout,*)' sliced matrix output ',msg
3081      write(luout,*)na,' slices to be printed ',msg
3082      do a=1,na
3083        write(luout,*)' slice ',a,' ',msg
3084        call output(M(1,1,a),1,ni,1,nj,ni,nj,1)
3085      enddo
3086      end
3087      subroutine slice_amb_print(na,nb,ni,nj,M,msg)
3088*
3089* routine to print 2d slices(i,j) of a matrix dimensioned
3090*
3091*  Matrix(na,ni,nj,nb)
3092*
3093#include "stdio.fh"
3094#include "errquit.fh"
3095#include "mafdecls.fh"
3096      integer na, nb, ni, nj          ! [input] matrix dimensions
3097      double precision M(na,ni,nj,nb) ! [input] matrix to print
3098      character*(*) msg               ! [input] message for output
3099c
3100      integer h_slice, k_slice
3101      integer a,i,j,b,cnt
3102c
3103      if (.not.ma_push_get(mt_dbl,(ni*nj),
3104     &      'slice_amb_print scratch',h_slice,k_slice))
3105     &      call errquit
3106     &      ('slice_amb_print: could not allocate (push) slice',911,
3107     &      MEM_ERR)
3108c
3109      write(luout,*)' sliced matrix output ',msg
3110      write(luout,*)(na*nb),' slices to be printed ',msg
3111      do a=1,na
3112        do b=1,nb
3113          call dcopy((ni*nj),0.0d00,0,dbl_mb(k_slice),1)
3114          cnt = k_slice
3115          do i=1,ni
3116            do j=1,nj
3117              dbl_mb(cnt) = M(a,i,j,b)
3118              cnt = cnt + 1
3119            enddo
3120          enddo
3121          write(luout,*)' slice ',a,b,' ',msg
3122          call output(dbl_mb(k_slice),1,ni,1,nj,ni,nj,1)
3123        enddo
3124      enddo
3125c
3126      if (.not.ma_pop_stack(h_slice))call errquit
3127     &      ('slice_amb_print: could not deallocate (pop) slice',911,
3128     &      MEM_ERR)
3129c
3130      end
3131      subroutine spcart_cart_overlap(lval,rankov,overlap)
3132      implicit none
3133*
3134* compute the cartsian overlap matrix for a given type of basis function
3135* This matrix is used to form the inverse of dtrans
3136*
3137#include "stdio.fh"
3138#include "errquit.fh"
3139#include "mafdecls.fh"
3140#include "basdeclsP.fh"
3141      integer lval
3142      integer rankov
3143      double precision overlap(rankov,rankov)
3144*
3145      double precision double_dummy
3146      double precision xyz(3)
3147      double precision zeta, coef
3148      integer h_scr,k_scr
3149      integer scr_size
3150*
3151*      write(6,*)' spcart_cart_overlap verify 1',' lval   = ',lval,
3152*     &      ' rankov = ',rankov
3153*      if (.not. ma_verify_allocator_stuff())
3154*     &    stop ' spcart_cart_overlap '
3155      call dcopy (3,0.0d00,0,xyz,1)  ! do it at the origin
3156      zeta  = 1.2345d00
3157      coef = 1.0d00
3158*
3159* normalize exponents just like in integrals
3160      call nmcoef(zeta,coef,lval,1,BasNorm_STD)
3161*
3162      scr_size = 200000
3163*      write(6,*)' spcart_cart_overlap verify 2',' lval   = ',lval,
3164*     &      ' rankov = ',rankov
3165*      if (.not. ma_verify_allocator_stuff())
3166*     &    stop ' spcart_cart_overlap '
3167      call hf1(xyz,zeta,coef,1,1,lval,
3168     &    xyz,zeta,coef,1,1,lval,
3169     &    xyz,double_dummy,double_dummy,1,
3170     &    overlap,double_dummy,double_dummy,
3171     &    (rankov*rankov),
3172     &    .true.,.false.,.false.,.false.,
3173     &    .true.,
3174     &    double_dummy,scr_size)
3175      scr_size = max(scr_size,5000)
3176*      write(6,*)' spcart_cart_overlap verify 3',' lval   = ',lval,
3177*     &      ' rankov = ',rankov
3178*      if (.not. ma_verify_allocator_stuff())
3179*     &    stop ' spcart_cart_overlap '
3180*      write(6,*)' scr_size is ',scr_size
3181      if (.not.ma_push_get(mt_dbl,scr_size,
3182     &    'spcart overlap scratch buffer',
3183     &    h_scr,k_scr)) call errquit
3184     &    ('spcart_cart_overlap: could not allocate scratch buffer',
3185     &    911, MEM_ERR)
3186      call dcopy(scr_size,0.0d00,0,dbl_mb(k_scr),1)
3187*      write(6,*)' spcart_cart_overlap verify 4',' lval   = ',lval,
3188*     &      ' rankov = ',rankov
3189*      if (.not. ma_verify_allocator_stuff())
3190*     &    stop ' spcart_cart_overlap '
3191      call dcopy((rankov*rankov),0.0d00,0,overlap,1)
3192*      write(6,*)' spcart_cart_overlap verify 5',' lval   = ',lval,
3193*     &      ' rankov = ',rankov
3194*      if (.not. ma_verify_allocator_stuff())
3195*     &    stop ' spcart_cart_overlap '
3196*      write(6,*)' calling hf1 '
3197      call hf1(xyz,zeta,coef,1,1,lval,
3198     &    xyz,zeta,coef,1,1,lval,
3199     &    xyz,double_dummy,double_dummy,1,
3200     &    overlap,double_dummy,double_dummy,
3201     &    (rankov*rankov),
3202     &    .true.,.false.,.false.,.false.,
3203     &    .false.,
3204     &    dbl_mb(k_scr),scr_size)
3205*      write(6,*)' spcart_cart_overlap verify 6',' lval   = ',lval,
3206*     &      ' rankov = ',rankov
3207*      if (.not. ma_verify_allocator_stuff())
3208*     &    stop ' spcart_cart_overlap '
3209      if (.not.ma_pop_stack(h_scr))call errquit
3210     &    ('spcart_cart_overlap: could not pop_stack scratch buffer',
3211     &    911, MEM_ERR)
3212*-debug-s
3213*      write(luout,*)' overlap matrix for lval = ',lval
3214*      call output(overlap,1,rankov,1,rankov,rankov,rankov,1)
3215*-debug-s
3216      end
3217
3218*.......................................................................
3219*rak:      subroutine spcart_all(blockin, blockout,li,lj,lk,ll,ni,nj,nk,nl)
3220*rak:      implicit none
3221*rak:c
3222*rak:c  transforms a block of integrals with loop level crap
3223*rak:c
3224*rak:#include "mafdecls.fh"
3225*rak:#include "errquit.fh"
3226*rak:#include "spcartP.fh"
3227*rak:c: functions
3228*rak:c: passed
3229*rak:      integer li, lj, lk, ll
3230*rak:      integer di, dj, dk, dl
3231*rak:      integer L2i, L2j, L2k, L2l
3232*rak:      integer ni, nj, nk, nl
3233*rak:      double precision blockin(
3234*rak:     &    ((ll+1)*(ll+2)/2)*nl,
3235*rak:     &    ((lk+1)*(lk+2)/2)*nk,
3236*rak:     &    ((lj+1)*(lj+2)/2)*nj,
3237*rak:     &    ((li+1)*(li+2)/2)*ni)
3238*rak:      double precision blockout(
3239*rak:     &    (2*ll+1)*nl,
3240*rak:     &    (2*lk+1)*nk,
3241*rak:     &    (2*lj+1)*nj,
3242*rak:     &    (2*li+1)*ni)
3243*rak:*rak:      double precision blockin(
3244*rak:*rak:     &    ((ll+1)*(ll+2)/2),nl,
3245*rak:*rak:     &    ((lk+1)*(lk+2)/2),nk,
3246*rak:*rak:     &    ((lj+1)*(lj+2)/2),nj,
3247*rak:*rak:     &    ((li+1)*(li+2)/2),ni)
3248*rak:*rak:      double precision blockout(
3249*rak:*rak:     &    -ll:ll,nl,
3250*rak:*rak:     &    -lk:lk,nk,
3251*rak:*rak:     &    -lj:lj,nj,
3252*rak:*rak:     &    -li:li,ni)
3253*rak:      integer i,j,k,l,ig,jg,kg,lg,is,js,ks,ls
3254*rak:      integer in_x_i,in_x_j,in_x_k,in_x_l
3255*rak:      integer in_s_i,in_s_j,in_s_k,in_s_l
3256*rak:      integer sizeblocks
3257*rak:c
3258*rak:      double precision sum, sumadd
3259*rak:c
3260*rak:c::statement function ----- start
3261*rak:      integer iic,iis,iil
3262*rak:      integer sfi,sfj,sfll
3263*rak:      integer sf_indx, sf_inds
3264*rak:      double precision Dtrans
3265*rak:      Dtrans(iic,iis,iil) =
3266*rak:     &    dbl_mb((int_mb(k_sp2c_lindx+iil))+
3267*rak:     &           ((iis+iil)*(iil+1)*(iil+2)/2)
3268*rak:     &           + iic - 1)
3269*rak:      sf_indx(sfi,sfj,sfll) = (sfj-1)*(sfll+1)*(sfll+2)/2 + sfi
3270*rak:      sf_inds(sfi,sfj,sfll) = (sfj-1)*(2*sfll+1) + sfi + sfll + 1
3271*rak:c::statement function ----- end
3272*rak:*rak:      ls=4
3273*rak:*rak:      write(6,*)'a_s,(ndima,l2s) ndima = ',ndima,'   ls = ',ls
3274*rak:*rak:      write(6,*)' trans matrix used '
3275*rak:*rak:      call output(dbl_mb((int_mb(k_sp2c_lindx+ls))),1,
3276*rak:*rak:     &    ((ls+1)*(ls+2)/2),1,(2*ls+1),
3277*rak:*rak:     &    ((ls+1)*(ls+2)/2),(2*ls+1),1)
3278*rak:c
3279*rak:      if (sph_cart_init.ne.SPH_CART_INIT_VALUE) call errquit
3280*rak:     &    ('spcart_a_sg_b: spcart not initialized properly',
3281*rak:     &    sph_cart_init)
3282*rak:c
3283*rak:c
3284*rak:      write(6,*)' *** Li *** ',Li
3285*rak:      call spcart_print_dtrans(Li)
3286*rak:      write(6,*)' *** Lj *** ',Lj
3287*rak:      call spcart_print_dtrans(Lj)
3288*rak:      write(6,*)' *** Lk *** ',Lk
3289*rak:      call spcart_print_dtrans(Lk)
3290*rak:      write(6,*)' *** Ll *** ',Ll
3291*rak:      call spcart_print_dtrans(Ll)
3292*rak:      sizeblocks = ni*(2*li+1)
3293*rak:      sizeblocks = sizeblocks*nj*(2*lj+1)
3294*rak:      sizeblocks = sizeblocks*nk*(2*lk+1)
3295*rak:      sizeblocks = sizeblocks*nl*(2*ll+1)
3296*rak:      call dfill(sizeblocks,0.0d00,blockout,1)
3297*rak:      l2i = (li+1)*(li+2)/2
3298*rak:      l2j = (lj+1)*(lj+2)/2
3299*rak:      l2k = (lk+1)*(lk+2)/2
3300*rak:      l2l = (lj+1)*(lj+2)/2
3301*rak:      do ig = 1,ni
3302*rak:        do jg = 1,nj
3303*rak:          do kg = 1,nk
3304*rak:            do lg = 1,nk
3305*rak:              do is = -li,li
3306*rak:                do js = -lj,lj
3307*rak:                  do ks = -lk,lk
3308*rak:                    do ls = -ll,ll
3309*rak:                      sum = 0.0d00
3310*rak:                      do i = 1,l2i
3311*rak:                        di = Dtrans(i,is,Li)
3312*rak:                        do j = 1,l2j
3313*rak:                          dj = Dtrans(j,js,Lj)
3314*rak:                          do k = 1,l2k
3315*rak:                            dk = Dtrans(k,ks,Lk)
3316*rak:                            do l = 1,l2l
3317*rak:                              dl = Dtrans(l,ls,Ll)
3318*rak:*                              sumadd = di*dj*dk*dl*
3319*rak:*     &                            blockin(l,lg,k,kg,j,jg,i,ig)
3320*rak:                              in_x_l = sf_indx(l,lg,Ll)
3321*rak:                              in_x_k = sf_indx(k,kg,Lk)
3322*rak:                              in_x_j = sf_indx(j,jg,Lj)
3323*rak:                              in_x_i = sf_indx(i,ig,Li)
3324*rak:                              sumadd = di*dj*dk*dl*
3325*rak:     &                            blockin(in_x_l,in_x_k,in_x_j,in_x_i)
3326*rak:                              sum = sum + sumadd
3327*rak:                            enddo
3328*rak:                          enddo
3329*rak:                        enddo
3330*rak:                      enddo
3331*rak:*                      blockout(ls,lg,ks,kg,js,jg,is,ig) = sum
3332*rak:                      in_s_l = sf_inds(ls,lg,Ll)
3333*rak:                      in_s_k = sf_inds(ks,kg,Lk)
3334*rak:                      in_s_j = sf_inds(js,jg,Lj)
3335*rak:                      in_s_i = sf_inds(is,ig,Li)
3336*rak:                      blockout(in_s_l,in_s_k,in_s_j,in_s_i) = sum
3337*rak:                    enddo
3338*rak:                  enddo
3339*rak:                enddo
3340*rak:              enddo
3341*rak:            enddo
3342*rak:          enddo
3343*rak:        enddo
3344*rak:      enddo
3345*rak:      end
3346*.......................................................................
3347      subroutine spcart_2ctran(buf,scr,lscr,
3348     &    nbfxi,nbfsi,typei,ngeni,trani,
3349     &    nbfxj,nbfsj,typej,ngenj,tranj,
3350     &    printit)
3351      implicit none
3352#include "stdio.fh"
3353#include "errquit.fh"
3354*
3355* routine to transform a 1e or 2e 2 center block of integrals
3356* block(jlo:jhi,:ilo:ihi)
3357*
3358      double precision buf(*)! [input/output] cartesian/shperical ints.
3359      integer lscr           ! [input] length of scratch array
3360      double precision
3361     &        scr(lscr)      ! [scratch] scratch array
3362      integer nbfxi          ! [input] no. of cartesian basis funcs:ish
3363      integer nbfsi          ! [input] no. of spherical basis funcs:ish
3364      integer typei          ! [input] angular momentum type:ish
3365      integer ngeni          ! [input] number general contractions:ish
3366      integer nbfxj          ! [input] no. of cartesian basis funcs:jsh
3367      integer nbfsj          ! [input] no. of spherical basis funcs:jsh
3368      integer typej          ! [input] angular momentum type:jsh
3369      integer ngenj          ! [input] number general contractions:jsh
3370      logical trani          ! [input] true -> transform ish block
3371      logical tranj          ! [input] true -> transform jsh block
3372      logical printit        ! [input] true -> print transform steps
3373*::local
3374      integer dimij, dimXX, dimSS
3375      integer dimj, dimi
3376      logical problem_sp
3377      logical FF, FT
3378      FF = .false.
3379      FT = .true.
3380      problem_sp =
3381     &    (typei.eq.-1).and.(ngeni.gt.1)
3382      problem_sp = problem_sp.and.
3383     &    (typej.eq.-1).and.(ngenj.gt.1)
3384      if (problem_sp) then
3385        write(luout,*)' spcart_2ctran: sp function error '
3386        write(luout,*)' sp function block passed with more ',
3387     &      'than one genereal contraction: ',
3388     &      'this is not allowed in NWChem'
3389        write(luout,*)' type i ',typei
3390        write(luout,*)' ngen i ',ngeni
3391        write(luout,*)' type j ',typej
3392        write(luout,*)' ngen j ',ngenj
3393        call errquit('spcart_2ctran: fatal error',911, UNKNOWN_ERR)
3394      endif
3395*
3396* sanity checking for spherical transforms
3397*
3398      if (trani.and.typei.ge.2.and.nbfxi.le.nbfsi) then
3399        write(luout,*)' sanity check error on i shell info'
3400        write(luout,*)' shell type     : ',typei
3401        write(luout,*)' cartesian size :',nbfxi
3402        write(luout,*)' spherical size :',nbfsi
3403        call errquit('spcart_2ctran:i: fatal error',911, UNKNOWN_ERR)
3404      endif
3405      if (tranj.and.typej.ge.2.and.nbfxj.le.nbfsj) then
3406        write(luout,*)' sanity check error on j shell info'
3407        write(luout,*)' shell type     : ',typej
3408        write(luout,*)' cartesian size :',nbfxj
3409        write(luout,*)' spherical size :',nbfsj
3410        call errquit('spcart_2ctran:j: fatal error',911, UNKNOWN_ERR)
3411      endif
3412*
3413* Check for all s, p, sp shells (e.g., no transform required).
3414*
3415      dimXX = nbfxi * nbfxj
3416      dimSS = nbfsi * nbfsj
3417      if (dimXX.eq.dimSS) return
3418*
3419* check scratch size
3420*
3421      dimij = nbfxi * ngeni * nbfxj * ngenj
3422      if (dimij.gt.lscr) then
3423        write(luout,*)' dimij   :',dimij
3424        write(luout,*)' lscr    :',lscr
3425        call errquit
3426     &      ('spcart_2ctran: error in scratch size for',911, MEM_ERR)
3427      endif
3428*
3429* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3430* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3431      if (trani.and.tranj) then
3432* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3433* buf(cartj,carti) --> scr(cartj,sphri)
3434        dimj = nbfxj*ngenj
3435        call spcart_a_s(buf,scr,dimj,typei,ngeni,FF,printit)
3436* scr(cartj,sphri) --> buf(sphrj,sphri)
3437        dimi = nbfsi*ngeni
3438        call spcart_s_a(scr,buf,dimi,typej,ngenj,FF,printit)
3439* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3440* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3441      elseif (trani) then
3442* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3443* buf(cartj,carti) --> scr(cartj,sphri)
3444        dimj = nbfxj*ngenj
3445        call spcart_a_s(buf,scr,dimj,typei,ngeni,FF,printit)
3446* scr(cartj,sphri) --> buf(cartj,sphri)
3447        dimij = nbfxj*ngenj * nbfsi*ngeni
3448        call dcopy(dimij,scr,1,buf,1)
3449* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3450* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3451      elseif (tranj) then
3452* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3453* buf(cartj,carti) --> scr(sphrj,carti)
3454        dimi = nbfxi*ngeni
3455        call spcart_s_a(buf,scr,dimi,typej,ngenj,FF,printit)
3456* scr(sphrj,carti) --> buf(sphrj,carti)
3457        dimij = nbfsj*ngenj * nbfxi*ngeni
3458        call dcopy(dimij,scr,1,buf,1)
3459* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3460* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3461      else
3462        write(luout,*)' no basis sets need to be transformed '
3463        call errquit('spcart_2ctran: fatal error ',911, MEM_ERR)
3464      endif
3465*
3466      end
3467*.......................................................................
3468      subroutine spcart_2cBtran(buf,scr,lscr,
3469     &    nbfxi,nbfsi,typei,ngeni,trani,
3470     &    nbfxj,nbfsj,typej,ngenj,tranj,
3471     &    nblocks,printit)
3472      implicit none
3473#include "stdio.fh"
3474#include "errquit.fh"
3475*
3476* routine to transform multiple 1e or 2e 2 center blocks of integrals
3477* buf(jlo:jhi,:ilo:ihi,nblocks)
3478*
3479      integer lscr           ! [input] length of scratch array
3480      double precision
3481     &        scr(lscr)      ! [scratch] scratch array
3482      integer nbfxi          ! [input] no. of cartesian basis funcs:ish
3483      integer nbfsi          ! [input] no. of spherical basis funcs:ish
3484      integer typei          ! [input] angular momentum type:ish
3485      integer ngeni          ! [input] number general contractions:ish
3486      integer nbfxj          ! [input] no. of cartesian basis funcs:jsh
3487      integer nbfsj          ! [input] no. of spherical basis funcs:jsh
3488      integer typej          ! [input] angular momentum type:jsh
3489      integer ngenj          ! [input] number general contractions:jsh
3490      logical trani          ! [input] true -> transform ish block
3491      logical tranj          ! [input] true -> transform jsh block
3492      logical printit        ! [input] true -> print transform steps
3493      integer nblocks        ! [input] number of blocks [intdim,nblock]
3494      double precision       ! [input/output] cartesian/shperical ints.
3495     &    buf((nbfxi*ngeni*nbfxj*ngenj),nblocks)
3496*::local
3497      integer dimij
3498      integer dimXX,dimSS
3499      integer iblock
3500      logical problem_sp
3501      logical FF, FT
3502      FF = .false.
3503      FT = .true.
3504      problem_sp =
3505     &    (typei.eq.-1).and.(ngeni.gt.1)
3506      problem_sp = problem_sp.and.
3507     &    (typej.eq.-1).and.(ngenj.gt.1)
3508      if (problem_sp) then
3509        write(luout,*)' spcart_2cBtran: sp function error '
3510        write(luout,*)' sp function block passed with more ',
3511     &      'than one genereal contraction: ',
3512     &      'this is not allowed in NWChem'
3513        write(luout,*)' type i ',typei
3514        write(luout,*)' ngen i ',ngeni
3515        write(luout,*)' type j ',typej
3516        write(luout,*)' ngen j ',ngenj
3517        call errquit('spcart_2cBtran: fatal error',911, UNKNOWN_ERR)
3518      endif
3519*
3520* sanity checking for spherical transforms
3521*
3522      if (trani.and.typei.ge.2.and.nbfxi.le.nbfsi) then
3523        write(luout,*)' sanity check error on i shell info'
3524        write(luout,*)' shell type     : ',typei
3525        write(luout,*)' cartesian size :',nbfxi
3526        write(luout,*)' spherical size :',nbfsi
3527        call errquit('spcart_2cBtran:i: fatal error',911, UNKNOWN_ERR)
3528      endif
3529      if (tranj.and.typej.ge.2.and.nbfxj.le.nbfsj) then
3530        write(luout,*)' sanity check error on j shell info'
3531        write(luout,*)' shell type     : ',typej
3532        write(luout,*)' cartesian size :',nbfxj
3533        write(luout,*)' spherical size :',nbfsj
3534        call errquit('spcart_2cBtran:j: fatal error',911, UNKNOWN_ERR)
3535      endif
3536*
3537* Check for all s, p, sp shells (e.g., no transform required).
3538*
3539      dimXX = nbfxi * nbfxj
3540      dimSS = nbfsi * nbfsj
3541      if (dimXX.eq.dimSS) return
3542*
3543* check scratch size
3544*
3545      dimij = nbfxi * ngeni * nbfxj * ngenj
3546      dimij = dimij * nblocks
3547      if (dimij.gt.lscr) then
3548        write(luout,*)' dimij   :',dimij
3549        write(luout,*)' lscr    :',lscr
3550        call errquit
3551     &      ('spcart_2cBtran: error in scratch size for',911, MEM_ERR)
3552      endif
3553*
3554* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3555* transform each block independently
3556* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3557      do iblock = 1 , nblocks
3558        call spcart_2ctran(buf(1,iblock),scr,lscr,
3559     &      nbfxi,nbfsi,typei,ngeni,trani,
3560     &      nbfxj,nbfsj,typej,ngenj,tranj,
3561     &      printit)
3562      enddo
3563* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3564* move each spherical block block down in buf
3565* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3566      dimXX = nbfxi * nbfxj
3567      dimXX = dimXX * ngeni * ngenj
3568      dimSS = nbfsi * nbfsj
3569      dimSS = dimSS * ngeni * ngenj
3570      call int_c2s_mv(buf,dimXX,dimSS,nblocks,
3571     &    scr,lscr,'spcart_2cBtran')
3572* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3573      end
3574*.......................................................................
3575      subroutine spcart_3ctran(buf,scr,lscr,
3576     &    nbfxi,nbfsi,typei,ngeni,trani,
3577     &    nbfxj,nbfsj,typej,ngenj,tranj,
3578     &    nbfxk,nbfsk,typek,ngenk,trank,
3579     &    printit)
3580      implicit none
3581#include "stdio.fh"
3582#include "errquit.fh"
3583*::passed
3584*
3585* routine to transform a 1e or 2e 3 center block of integrals
3586* block(klo:khi,jlo:jhi,:ilo:ihi)
3587*
3588      double precision buf(*)! [input/output] cartesian/shperical ints.
3589      integer lscr           ! [input] length of scratch array
3590      double precision
3591     &        scr(lscr)      ! [scratch] scratch array
3592      integer nbfxi          ! [input] no. of cartesian basis funcs:ish
3593      integer nbfsi          ! [input] no. of spherical basis funcs:ish
3594      integer typei          ! [input] angular momentum type:ish
3595      integer ngeni          ! [input] number general contractions:ish
3596      integer nbfxj          ! [input] no. of cartesian basis funcs:jsh
3597      integer nbfsj          ! [input] no. of spherical basis funcs:jsh
3598      integer typej          ! [input] angular momentum type:jsh
3599      integer ngenj          ! [input] number general contractions:jsh
3600      integer nbfxk          ! [input] no. of cartesian basis funcs:ksh
3601      integer nbfsk          ! [input] no. of spherical basis funcs:ksh
3602      integer typek          ! [input] angular momentum type:ksh
3603      integer ngenk          ! [input] number general contractions:ksh
3604      logical trani          ! [input] true -> transform ish block
3605      logical tranj          ! [input] true -> transform jsh block
3606      logical trank          ! [input] true -> transform ksh block
3607      logical printit        ! [input] true -> print transform steps
3608*::local
3609      integer dimXXX  ! size of full cartesian block
3610      integer dimSSS  ! size of full spherical block
3611      integer dimkj, dimji, dimijk  ! intermediate sizes
3612      integer dimk, dimi            ! intermediate sizes
3613      logical problem_sp
3614      logical FF, FT
3615      FF = .false.
3616      FT = .true.
3617      problem_sp =
3618     &    (typei.eq.-1).and.(ngeni.gt.1)
3619      problem_sp = problem_sp.and.
3620     &    (typej.eq.-1).and.(ngenj.gt.1)
3621      problem_sp = problem_sp.and.
3622     &    (typek.eq.-1).and.(ngenk.gt.1)
3623      if (problem_sp) then
3624        write(luout,*)' spcart_3ctran: sp function error '
3625        write(luout,*)' sp function block passed with more ',
3626     &      'than one genereal contraction: ',
3627     &      'this is not allowed in NWChem'
3628        write(luout,*)' type i ',typei
3629        write(luout,*)' ngen i ',ngeni
3630        write(luout,*)' type j ',typej
3631        write(luout,*)' ngen j ',ngenj
3632        write(luout,*)' type k ',typek
3633        write(luout,*)' ngen k ',ngenk
3634        call errquit('spcart_3ctran: fatal error',911, UNKNOWN_ERR)
3635      endif
3636*
3637* sanity checking for spherical transforms
3638*
3639      if (trani.and.typei.ge.2.and.nbfxi.le.nbfsi) then
3640        write(luout,*)' sanity check error on i shell info'
3641        write(luout,*)' shell type     : ',typei
3642        write(luout,*)' cartesian size :',nbfxi
3643        write(luout,*)' spherical size :',nbfsi
3644        call errquit('spcart_3ctran:i: fatal error',911, UNKNOWN_ERR)
3645      endif
3646      if (tranj.and.typej.ge.2.and.nbfxj.le.nbfsj) then
3647        write(luout,*)' sanity check error on j shell info'
3648        write(luout,*)' shell type     : ',typej
3649        write(luout,*)' cartesian size :',nbfxj
3650        write(luout,*)' spherical size :',nbfsj
3651        call errquit('spcart_3ctran:j: fatal error',911, UNKNOWN_ERR)
3652      endif
3653      if (trank.and.typek.ge.2.and.nbfxk.le.nbfsk) then
3654        write(luout,*)' sanity check error on k shell info'
3655        write(luout,*)' shell type     : ',typek
3656        write(luout,*)' cartesian size :',nbfxk
3657        write(luout,*)' spherical size :',nbfsk
3658        call errquit('spcart_3ctran:k: fatal error',911, UNKNOWN_ERR)
3659      endif
3660*
3661* Check for all s, p, sp shells (e.g., no transform required).
3662*
3663      dimXXX = nbfxi * nbfxj * nbfxk
3664      dimSSS = nbfsi * nbfsj * nbfsk
3665      if (dimXXX.eq.dimSSS) return
3666*
3667* check scratch size
3668*
3669      dimijk = nbfxi * ngeni * nbfxj * ngenj * nbfxk * ngenk
3670      if (dimijk.gt.lscr) then
3671        write(luout,*)' dimijk  :',dimijk
3672        write(luout,*)' lscr    :',lscr
3673        call errquit
3674     &      ('spcart_3ctran: error in scratch size for',911,
3675     &       UNKNOWN_ERR)
3676      endif
3677*
3678* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3679* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3680      if (trani.and.tranj.and.trank) then
3681* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3682* buf(cartk,cartj,carti) --> scr(cartk,cartj,sphri)
3683        dimkj = nbfxk*ngenk*nbfxj*ngenj
3684        call spcart_a_s(buf,scr,dimkj,typei,ngeni,FF,printit)
3685* scr(cartk,cartj,sphri) --> buf(sphrk,cartj,sphri)
3686        dimji = nbfxj*ngenj*nbfsi*ngeni
3687        call spcart_s_a(scr,buf,dimji,typek,ngenk,FF,printit)
3688* buf(sphrk,cartj,sphri) --> scr(sphrk,sphrj,sphri)
3689        dimk = nbfsk*ngenk
3690        dimi = nbfsi*ngeni
3691        call spcart_a_s_b(buf,scr,dimk,dimi,typej,ngenj,FF,printit)
3692* scr(sphrk,sphrj,sphri) --> buf(sphrk,sphrj,sphri)
3693        dimijk = nbfsk*ngenk * nbfsj*ngenj * nbfsi*ngeni
3694        call dcopy(dimijk,scr,1,buf,1)
3695* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3696* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3697      elseif (trani.and.trank) then
3698* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3699* buf(cartk,cartj,carti) --> scr(cartk,cartj,sphri)
3700        dimkj = nbfxk*ngenk*nbfxj*ngenj
3701        call spcart_a_s(buf,scr,dimkj,typei,ngeni,FF,printit)
3702* scr(cartk,cartj,sphri) --> buf(sphrk,cartj,sphri)
3703        dimji = nbfxj*ngenj*nbfsi*ngeni
3704        call spcart_s_a(scr,buf,dimji,typek,ngenk,FF,printit)
3705* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3706* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3707      elseif (trani.and.tranj) then
3708* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3709* buf(cartk,cartj,carti) --> scr(cartk,cartj,sphri)
3710        dimkj = nbfxk*ngenk*nbfxj*ngenj
3711        call spcart_a_s(buf,scr,dimkj,typei,ngeni,FF,printit)
3712* scr(cartk,cartj,sphri) --> buf(cartk,sphrj,sphri)
3713        dimk = nbfxk*ngenk
3714        dimi = nbfsi*ngeni
3715        call spcart_a_s_b(scr,buf,dimk,dimi,typej,ngenj,FF,printit)
3716* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3717* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3718      elseif (tranj.and.trank) then
3719* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3720* buf(cartk,cartj,carti) --> scr(sphrk,cartj,carti)
3721        dimji = nbfxi*ngeni*nbfxj*ngenj
3722        call spcart_s_a(buf,scr,dimji,typek,ngenk,FF,printit)
3723* scr(sphrk,cartj,carti) --> buf(sphrk,sphrj,carti)
3724        dimk = nbfsk*ngenk
3725        dimi = nbfxi*ngeni
3726        call spcart_a_s_b(scr,buf,dimk,dimi,typej,ngenj,FF,printit)
3727* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3728* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3729      elseif (trani) then
3730* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3731* buf(cartk,cartj,carti) --> scr(cartk,cartj,sphri)
3732        dimkj = nbfxk*ngenk*nbfxj*ngenj
3733        call spcart_a_s(buf,scr,dimkj,typei,ngeni,FF,printit)
3734* scr(cartk,cartj,sphri) --> buf(cartk,cartj,sphri)
3735        dimijk = nbfxk*ngenk * nbfxj*ngenj * nbfsi*ngeni
3736        call dcopy(dimijk,scr,1,buf,1)
3737* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3738* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3739      elseif (tranj) then
3740* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3741* buf(cartk,cartj,carti) --> scr(cartk,sphrj,carti)
3742        dimk = nbfxk*ngenk
3743        dimi = nbfxi*ngeni
3744        call spcart_a_s_b(buf,scr,dimk,dimi,typej,ngenj,FF,printit)
3745* scr(cartk,sphrj,carti) --> buf(cartk,sphrj,carti)
3746        dimijk = nbfxk*ngenk * nbfsj*ngenj * nbfxi*ngeni
3747        call dcopy(dimijk,scr,1,buf,1)
3748* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3749* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3750      elseif (trank) then
3751* buf(cartk,cartj,carti) --> scr(sphrk,cartj,carti)
3752        dimji = nbfxi*ngeni*nbfxj*ngenj
3753        call spcart_s_a(buf,scr,dimji,typek,ngenk,FF,printit)
3754* scr(sphrk,cartj,carti) --> buf(sphrk,cartj,carti)
3755        dimijk = nbfsk*ngenk * nbfxj*ngenj * nbfxi*ngeni
3756        call dcopy(dimijk,scr,1,buf,1)
3757      else
3758        write(luout,*)' no basis sets need to be transformed '
3759        call errquit('spcart_3ctran: fatal error ',911, UNKNOWN_ERR)
3760      endif
3761*
3762      end
3763*.......................................................................
3764      subroutine spcart_3cBtran(buf,scr,lscr,
3765     &    nbfxi,nbfsi,typei,ngeni,trani,
3766     &    nbfxj,nbfsj,typej,ngenj,tranj,
3767     &    nbfxk,nbfsk,typek,ngenk,trank,
3768     &    nblocks,printit)
3769      implicit none
3770#include "stdio.fh"
3771#include "errquit.fh"
3772*
3773* routine to transform multiple 1e or 2e 3 center blocks of integrals
3774* buf(klo:khi,jlo:jhi,:ilo:ihi,nblocks)
3775*
3776      integer lscr           ! [input] length of scratch array
3777      double precision
3778     &        scr(lscr)      ! [scratch] scratch array
3779      integer nbfxi          ! [input] no. of cartesian basis funcs:ish
3780      integer nbfsi          ! [input] no. of spherical basis funcs:ish
3781      integer typei          ! [input] angular momentum type:ish
3782      integer ngeni          ! [input] number general contractions:ish
3783      integer nbfxj          ! [input] no. of cartesian basis funcs:jsh
3784      integer nbfsj          ! [input] no. of spherical basis funcs:jsh
3785      integer typej          ! [input] angular momentum type:jsh
3786      integer ngenj          ! [input] number general contractions:jsh
3787      integer nbfxk          ! [input] no. of cartesian basis funcs:ksh
3788      integer nbfsk          ! [input] no. of spherical basis funcs:ksh
3789      integer typek          ! [input] angular momentum type:ksh
3790      integer ngenk          ! [input] number general contractions:ksh
3791      logical trani          ! [input] true -> transform ish block
3792      logical tranj          ! [input] true -> transform jsh block
3793      logical trank          ! [input] true -> transform ksh block
3794      logical printit        ! [input] true -> print transform steps
3795      integer nblocks        ! [input] number of blocks [intdim,nblock]
3796      double precision       ! [input/output] cartesian/shperical ints.
3797     &    buf((nbfxi*ngeni*nbfxj*ngenj*nbfxk*ngenk),nblocks)
3798*::local
3799      integer dimijk
3800      integer dimXXX,dimSSS
3801      integer iblock
3802      logical problem_sp
3803      logical FF, FT
3804      FF = .false.
3805      FT = .true.
3806      problem_sp =
3807     &    (typei.eq.-1).and.(ngeni.gt.1)
3808      problem_sp = problem_sp.and.
3809     &    (typej.eq.-1).and.(ngenj.gt.1)
3810      problem_sp = problem_sp.and.
3811     &    (typek.eq.-1).and.(ngenk.gt.1)
3812      if (problem_sp) then
3813        write(luout,*)' spcart_3cBtran: sp function error '
3814        write(luout,*)' sp function block passed with more ',
3815     &      'than one genereal contraction: ',
3816     &      'this is not allowed in NWChem'
3817        write(luout,*)' type i ',typei
3818        write(luout,*)' ngen i ',ngeni
3819        write(luout,*)' type j ',typej
3820        write(luout,*)' ngen j ',ngenj
3821        write(luout,*)' type k ',typek
3822        write(luout,*)' ngen k ',ngenk
3823        call errquit('spcart_3cBtran: fatal error',911, UNKNOWN_ERR)
3824      endif
3825*
3826* sanity checking for spherical transforms
3827*
3828      if (trani.and.typei.ge.2.and.nbfxi.le.nbfsi) then
3829        write(luout,*)' sanity check error on i shell info'
3830        write(luout,*)' shell type     : ',typei
3831        write(luout,*)' cartesian size :',nbfxi
3832        write(luout,*)' spherical size :',nbfsi
3833        call errquit('spcart_3cBtran:i: fatal error',911, UNKNOWN_ERR)
3834      endif
3835      if (tranj.and.typej.ge.2.and.nbfxj.le.nbfsj) then
3836        write(luout,*)' sanity check error on j shell info'
3837        write(luout,*)' shell type     : ',typej
3838        write(luout,*)' cartesian size :',nbfxj
3839        write(luout,*)' spherical size :',nbfsj
3840        call errquit('spcart_3cBtran:j: fatal error',911, UNKNOWN_ERR)
3841      endif
3842      if (trank.and.typek.ge.2.and.nbfxk.le.nbfsk) then
3843        write(luout,*)' sanity check error on k shell info'
3844        write(luout,*)' shell type     : ',typek
3845        write(luout,*)' cartesian size :',nbfxk
3846        write(luout,*)' spherical size :',nbfsk
3847        call errquit('spcart_3cBtran:k: fatal error',911, UNKNOWN_ERR)
3848      endif
3849*
3850* Check for all s, p, sp shells (e.g., no transform required).
3851*
3852      dimXXX = nbfxi * nbfxj * nbfxk
3853      dimSSS = nbfsi * nbfsj * nbfsk
3854      if (dimXXX.eq.dimSSS) return
3855*
3856* check scratch size
3857*
3858      dimijk = nbfxi * ngeni * nbfxj * ngenj * nbfxk * ngenk
3859      dimijk = dimijk * nblocks
3860      if (dimijk.gt.lscr) then
3861        write(luout,*)' dimijk  :',dimijk
3862        write(luout,*)' lscr    :',lscr
3863        call errquit
3864     &      ('spcart_3cBtran: error in scratch size for',911,
3865     &       UNKNOWN_ERR)
3866      endif
3867*
3868* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3869* transform each block independently
3870* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3871      do iblock = 1 , nblocks
3872        call spcart_3ctran(buf(1,iblock),scr,lscr,
3873     &      nbfxi,nbfsi,typei,ngeni,trani,
3874     &      nbfxj,nbfsj,typej,ngenj,tranj,
3875     &      nbfxk,nbfsk,typek,ngenk,trank,
3876     &      printit)
3877      enddo
3878* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3879* move each spherical block block down in buf
3880* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3881      dimXXX = nbfxi * nbfxj * nbfxk
3882      dimXXX = dimXXX * ngeni * ngenj * ngenk
3883      dimSSS = nbfsi * nbfsj * nbfsk
3884      dimSSS = dimSSS * ngeni * ngenj * ngenk
3885      call int_c2s_mv(buf,dimXXX,dimSSS,nblocks,
3886     &    scr,lscr,'spcart_3cBtran')
3887* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3888      end
3889