!/* ! * Copyright(C) 2008 by Lingyun Yang ! * lingyun(.dot.]yang@gmail.com ! * http://www.lingyunyang.com ! * ! * Please get permission from Lingyun Yang before you redistribute this file. ! * ! * Version: $Id: c_tpsa_interface.F90,v 1.13 2009-06-24 09:06:43 frs Exp $ ! */ module dabnew !$$$$ use da_arrays use dabnew_b !$$$$ implicit none public ! integer,private,parameter:: lsw=1 ! integer,private,parameter::nmax=400,lsw=1 ! real(dp),private,parameter::tiny=c_1d_20 character(120),private :: line #ifdef _WIN32_DLL !DEC$ ATTRIBUTES DLLIMPORT :: ad_tra, ad_shift, ad_print, ad_save_block, ad_read_block !DEC$ ATTRIBUTES DLLIMPORT :: ad_fill_ran, ad_nvar, ad_length, ad_derivative !DEC$ ATTRIBUTES DLLIMPORT :: ad_subst, ad_cos, ad_sin, ad_log, ad_exp, ad_sqrt, ad_abs !DEC$ ATTRIBUTES DLLIMPORT :: ad_div_c, ad_c_div, ad_mult_const, ad_add_const !DEC$ ATTRIBUTES DLLIMPORT :: ad_div, ad_mult, ad_sub, ad_reset, ad_pok, ad_pek !DEC$ ATTRIBUTES DLLIMPORT :: ad_var, ad_truncate, ad_const, ad_count, ad_free, ad_add !DEC$ ATTRIBUTES DLLIMPORT :: ad_copy, ad_clean, ad_alloc, ad_reserve, ad_init, ad_elem DLL_IMPORT ad_tra, ad_shift, ad_print, ad_save_block, ad_read_block DLL_IMPORT ad_fill_ran, ad_nvar, ad_length, ad_derivative DLL_IMPORT ad_subst, ad_cos, ad_sin, ad_log, ad_exp, ad_sqrt, ad_abs DLL_IMPORT ad_div_c, ad_c_div, ad_mult_const, ad_add_const DLL_IMPORT ad_div, ad_mult, ad_sub, ad_reset, ad_pok, ad_pek DLL_IMPORT ad_var, ad_truncate, ad_const, ad_count, ad_free, ad_add DLL_IMPORT ad_copy, ad_clean, ad_alloc, ad_reserve, ad_init, ad_elem ,ad_resetvars #endif private trx_cpp contains !done subroutine daini(nd,nv,k) implicit none ! integer, intent(in) :: nd,nv,nd2,k integer nd,nv,k,last_nv if(lingyun_yang) then !%%%% if(last_tpsa==1.and.lielib_print(10)==0) then call ad_nvar(last_nv) call ad_resetvars(last_nv) endif call danum0(nd,nv) call ad_init(nv, nd) call ad_reserve(lda) ! write(6,*) " LDA Lingyun ", lda last_tpsa=1 else !%%%% call daini_b(nd,nv,k) ! last_tpsa=2 done in daini_b endif !%%%% end subroutine daini !done subroutine daall0(i) implicit none ! integer, intent(in) :: i integer i if(lingyun_yang) then !%%%% call ad_alloc(i) else !%%%% call daall0_b(i) endif !%%%% end subroutine daall0 !done subroutine daall1(i,ccc,n0,nv) implicit none ! integer, intent(in) :: i integer i,n0, nv character(10) ccc if(lingyun_yang) then !%%%% call ad_alloc(i) else !%%%% call daall1_b(i,ccc,n0,nv) endif !%%%% end subroutine daall1 subroutine daclean(ina,value) implicit none integer ina ! real(dp) value ! ! if(lingyun_yang) then !%%%% call ad_clean(ina, value) else !%%%% call daclean_b(ina, value) endif !%%%% return end subroutine daclean !done subroutine daadd(i,j,k) implicit none ! integer, intent(in) :: i,j,k integer i,j,k integer itmp !write(*,*) k ! if j!= k and i != k, then optimize if(lingyun_yang) then !%%%% call ad_alloc(itmp) call ad_copy(i, itmp) call ad_add(itmp, j) call ad_copy(itmp, k) call ad_free(itmp) else !%%%% call daadd_b(i,j,k) endif !%%%% end subroutine daadd !done subroutine dacon(i,r) implicit none ! integer, intent(in) :: i ! real(dp), intent(in) :: r integer i real(dp) r if(lingyun_yang) then !%%%% call ad_const(i, r) else !%%%% call dacon_b(i,r) endif !%%%% end subroutine dacon !done subroutine dadal(idal,j) implicit none integer j ! integer, intent(in) :: j integer,dimension(:)::idal integer k if(lingyun_yang) then !%%%% do k=1,j call ad_free(idal(k)) enddo else !%%%% call dadal_b(idal,j) endif !%%%% end subroutine dadal !done subroutine dadal1(idal) implicit none integer idal ! integer, intent(inout) :: idal if(lingyun_yang) then !%%%% call ad_free(idal) else !%%%% call dadal1_b(idal) endif !%%%% end subroutine dadal1 !done subroutine count_da(idal) implicit none ! integer, intent(inout) :: idal integer idal !call ad_all(i) if(lingyun_yang) then !%%%% call ad_count(idal) else !%%%% call count_da_b(idal) endif !%%%% end subroutine count_da !done subroutine davar(ina,ckon,i) implicit none ! integer, intent(in) :: ina,i integer ina,i real(dp), intent(in) :: ckon if(lingyun_yang) then !%%%% call ad_var(ina, ckon, i-1) else !%%%% call davar_b(ina,ckon,i) endif !%%%% end subroutine davar ! done subroutine danot(not) implicit none ! integer, intent(in) :: not integer not if(lingyun_yang) then !%%%% print *, 'ERROR: This is not used in new TPSA routines.' STOP else !%%%% call danot_b(not) endif !%%%% end subroutine danot !done subroutine datrunc(ina, imd, inb) implicit none ! integer, intent(in) :: ina,imd,inb integer ina,imd,inb if(lingyun_yang) then !%%%% call ad_copy(ina, inb) ! truncate imd and above. call ad_truncate(inb, imd) else !%%%% call datrunc_b(ina, imd, inb) endif !%%%% end subroutine datrunc ! done subroutine daeps(deps) implicit none real(dp) deps ! real(dp), intent(inout) :: deps if(lingyun_yang) then !%%%% print *, 'ERROR: We use machine dependent eps instead.' if (depseps) then cn=cn+1 write(iunit,'(I6,2X,G21.14,I5,4X,18(2i2,1X))') cn,value,ioa,(j(iii),iii=1,c_%nv) !ETIENNE write(iunit,*) value endif enddo j=0 write(iunit,'(A)') ' ' deallocate(j) else !%%%% call dapri_b(ina,iunit) endif !%%%% end subroutine dapri subroutine dapri77(ina,iunit) implicit none ! INTEGER ina,iunit integer i,ina,ipresent,illa,iunit,iii,ioa,cn real(dp) value integer, allocatable :: j(:) character(10) c10,k10 if(lingyun_yang) then !%%%% ipresent=1 call dacycle(ina,ipresent,value,illa) allocate(j(c_%nv)) cn=0 do i=1,illa call dacycle(ina,i,value,illa,j) if(abs(value)<=eps) then cn=cn+1 endif enddo if(cn==illa) then illa=0 endif j=0 write(iunit,'(/1X,A,A,I5,A,I5,A,I5/1X,A/)') " Lingyun ",', NO =',c_%no,', NV =',c_%nv,', INA =',ina,& '*********************************************' if(illa.ne.0) write(iunit,'(A)') ' I COEFFICIENT ORDER EXPONENTS' if(illa.eq.0) write(iunit,'(A)') ' ALL COMPONENTS ZERO ' c10=' NO =' k10=' NV =' i=0 write(iunit,'(A10,I6,A10,I6)') c10,c_%no,k10,c_%nv cn=0 do i=1,illa call dacycle(ina,i,value,illa,j) ioa=0 do iii=1,c_%nv ioa= j(iii)+ioa enddo if(abs(value)>eps) then cn=cn+1 write(iunit,501) ioa,value,(j(iii),iii=1,c_%nv) endif enddo 501 format(' ', i3,1x,g23.16,1x,100(1x,i2)) 502 format(' ', i5,1x,g23.16,1x,100(1x,i2)) j=0 write(iunit,502) -cn,zero,(j(iii),iii=1,c_%nv) deallocate(j) else !%%%% call dapri77_b(ina,iunit) endif !%%%% end subroutine dapri77 subroutine dashift(ina,inc,ishift) implicit none integer ina,inc,ishift,itmp real(dp) eps if(lingyun_yang) then !%%%% call ad_alloc(itmp) eps = 1e-20 call ad_shift(ina, ishift, itmp, eps) call ad_copy(itmp, inc) call ad_free(itmp) else !%%%% call dashift_b(ina,inc,ishift) endif !%%%% end subroutine dashift subroutine darea(ina,iunit) implicit none integer ina,iunit integer ii,iin,i,nno,io,iwarin,iwarnv,iwarno,io1 character(10) c10 integer,dimension(lnv)::j real(dp) c if(lingyun_yang) then !%%%% read(iunit,'(A10)') c10 read(iunit,'(18X,I4)') nno read(iunit,'(A10)') c10 read(iunit,'(A10)') c10 read(iunit,'(A10)') c10 iin = 0 ! 10 continue iin = iin + 1 read(iunit,'(I6,2X,G21.14,I5,4X,18(2i2,1X))') ii,c,io,(j(i),i=1,c_%nv) if(ii.eq.0) goto 20 !ETIENNE read(iunit,*) c !ETIENNE if(ii.ne.iin) then iwarin = 1 endif io1 = 0 do i=1,c_%nv io1 = io1 + j(i) enddo ! if(io1.ne.io) then iwarnv = 1 goto 10 endif if(io.gt.c_%no) then ! IF(IWARNO.EQ.0) PRINT*,'WARNING IN DAREA, FILE ', ! * 'CONTAINS HIGHER ORDERS THAN VECTOR ' iwarno = 1 goto 10 endif ! call ad_pok(ina, j, c_%nv, c) goto 10 ! 20 continue ! return else !%%%% call darea_b(ina,iunit) endif !%%%% end subroutine darea subroutine darea77(ina,iunit) implicit none integer ina,iunit integer nojoh,nvjoh,ii,iche,k,i character(10) c10,k10 integer,dimension(lnv)::j real(dp) c if(lingyun_yang) then !%%%% read(iunit,'(A10)') c10 read(iunit,'(A10)') c10 read(iunit,'(A10)') c10 read(iunit,'(A10)') c10 read(iunit,'(A10)') c10 read(iunit,'(A10,I6,A10,I6)') c10,nojoh,k10,nvjoh 10 continue read(iunit,*) ii,c,(j(k),k=1,nvjoh) if(ii.lt.0) goto 20 do i=c_%nv+1,nvjoh if(j(i).ne.0) goto 10 enddo iche=0 do i=1,c_%nv iche=iche+j(i) enddo if(iche.gt.c_%no) goto 10 call ad_pok(ina, j, c_%nv, c) goto 10 20 continue else !%%%% call darea77_b(ina,iunit) endif !%%%% end subroutine darea77 ! done ! subroutine dainf(inc,inoc,invc,ipoc,ilmc,illc) ! implicit none ! integer inc,inoc,invc,ipoc,ilmc,illc ! if(lingyun_yang) then !%%%% ! write(6,*) " FILL_UNI of Sagan only in Berz" ! STOP 666 ! else !%%%% ! call dainf_b(inc,inoc,invc,ipoc,ilmc,illc) ! endif !%%%% ! end subroutine dainf subroutine datra(idif,ina,inc) implicit none integer idif,ina,inc,itmp if(lingyun_yang) then !%%%% call ad_alloc(itmp) call ad_tra(ina,idif-1,itmp) call ad_copy(itmp, inc) call ad_free(itmp) else !%%%% call datra_b(idif,ina,inc) endif !%%%% end subroutine datra ! done subroutine daran(ina,cm,xran) implicit none integer ina real(dp) cm,xran if(lingyun_yang) then !%%%% call ad_fill_ran(ina,cm,xran) else !%%%% call daran_b(ina,cm,xran) endif !%%%% end subroutine daran subroutine dacycle(ina,ipresent,value,illa,j) implicit none integer illa,ina,ipresent integer,optional,dimension(:)::j real(dp) value if(lingyun_yang) then !%%%% call ad_length(ina, illa) if(.not.present(j)) return call ad_elem(ina, ipresent, j, value) else !%%%% call dacycle_b(ina,ipresent,value,illa,j) endif !%%%% end subroutine dacycle subroutine dawritefile(ina) implicit none integer ina,n, nvar,i integer, allocatable :: j(:) real(dp),allocatable :: v(:) ! get real length of ina, without zeros in the tail call ad_length(ina, n) ! how many call ad_nvar(nvar) allocate(j(n*nvar),v(n)) call ad_read_block(ina, v, j, n) do i=1,n write(6,'(1x,e15.8,5(1x,i4))') v(i),j((i-1)*nvar+1:i*nvar) enddo ! for compare call ad_print(ina) deallocate(j,v) end subroutine dawritefile subroutine dareadfile(ina) implicit none integer ina end subroutine dareadfile end module dabnew !$$$$