summaryrefslogtreecommitdiff
path: root/Ganlib/src/ganmod.f90
diff options
context:
space:
mode:
Diffstat (limited to 'Ganlib/src/ganmod.f90')
-rw-r--r--Ganlib/src/ganmod.f9089
1 files changed, 89 insertions, 0 deletions
diff --git a/Ganlib/src/ganmod.f90 b/Ganlib/src/ganmod.f90
new file mode 100644
index 0000000..0882995
--- /dev/null
+++ b/Ganlib/src/ganmod.f90
@@ -0,0 +1,89 @@
+!
+!-----------------------------------------------------------------------
+!
+!Purpose:
+! Dispatch to a calculation module in GANLIB. ANSI-C interoperable.
+!
+!Copyright:
+! Copyright (C) 2009 Ecole Polytechnique de Montreal
+! This library is free software; you can redistribute it and/or
+! modify it under the terms of the GNU Lesser General Public
+! License as published by the Free Software Foundation; either
+! version 2.1 of the License, or (at your option) any later version.
+!
+!Author(s): A. Hebert
+!
+!-----------------------------------------------------------------------
+!
+integer(c_int) function ganmod(cmodul, nentry, hentry, ientry, jentry, &
+ kentry, hparam_c) bind(c)
+!
+ use GANLIB
+ implicit none
+!----
+! subroutine arguments
+!----
+ character(kind=c_char), dimension(*) :: cmodul
+ integer(c_int), value :: nentry
+ character(kind=c_char), dimension(13,*) :: hentry
+ integer(c_int), dimension(nentry) :: ientry, jentry
+ type(c_ptr), dimension(nentry) :: kentry
+ character(kind=c_char), dimension(73,*) :: hparam_c
+!----
+! local variables
+!----
+ integer :: i, ier
+ character :: hmodul*12, hsmg*131, hparam*72
+ character(len=12), allocatable :: hentry_f(:)
+ type FIL_file_array
+ type(FIL_file), pointer :: my_file
+ end type FIL_file_array
+ type(FIL_file_array), pointer :: my_file_array(:)
+!
+ allocate(hentry_f(nentry),my_file_array(nentry))
+ call STRFIL(hmodul, cmodul)
+ do i=1,nentry
+ call STRFIL(hentry_f(i), hentry(1,i))
+ if((ientry(i) >= 3).and.(ientry(i) <= 5)) then
+! open a Fortran file.
+ call STRFIL(hparam, hparam_c(1,i))
+ my_file_array(i)%my_file=>FILOPN(hparam,jentry(i),ientry(i)-1,0)
+ if(.not.associated(my_file_array(i)%my_file)) then
+ write(hsmg,'(29hganmod: unable to open file '',a12,2h''.)') hentry_f(i)
+ call XABORT(hsmg)
+ endif
+ kentry(i)=c_loc(my_file_array(i)%my_file)
+ endif
+ enddo
+! ----------------------------------------------------------
+ ganmod=GANDRV(hmodul,nentry,hentry_f,ientry,jentry,kentry)
+! ----------------------------------------------------------
+ do i=1,nentry
+ if(jentry(i) == -2) then
+! destroy a LCM object or a Fortran file.
+ if(ientry(i) <= 2) then
+ call LCMCL(kentry(i),2)
+ kentry(i)=c_null_ptr
+ else if((ientry(i) >= 3).and.(ientry(i) <= 5)) then
+ ier=FILCLS(my_file_array(i)%my_file,2)
+ if(ier < 0) then
+ write(hsmg,'(32hganmod: unable to destroy file '',a12,2h''.)') hentry_f(i)
+ call XABORT(hsmg)
+ endif
+ kentry(i)=c_null_ptr
+ endif
+ else
+! close a Fortran file.
+ if((ientry(i) >= 3).and.(ientry(i) <= 5)) then
+ ier=FILCLS(my_file_array(i)%my_file,1)
+ if(ier < 0) then
+ write(hsmg,'(30hganmod: unable to close file '',a12,2h''.)') hentry_f(i)
+ call XABORT(hsmg)
+ endif
+ endif
+ endif
+ enddo
+ deallocate(my_file_array,hentry_f)
+ flush(6)
+ return
+end function ganmod