next up previous
Next: Limitations Up: Viewmol Manual Previous: Data files

Programming Your Own Input Routine

VIEWMOL can be easily extended to read outputs of other programmes. All you have to do is to write a subroutine which extracts the data from the output file. You have to use the routines for dynamical memory allocation. These are three routines:

Arrays with more than one dimension require a special treatment. They cannot easily expanded if memory becomes low, because the address of one array element depends on the array bounds. For dealing with such arrays the subroutines indarr(i,j,k,maxi,maxj), cphist(source,dest,maxk_source,maxk_dest,maxj), and cpmo(source,dest,max_source,max_dest) are provided. indarr calculates the address of an element i, j, k in the array dimensioned with maxi and maxj. For use with two dimensional arrays set maxj to zero.

cphist copies the data from the three dimensional hist array (see below) to another destination or vice versa. This routine should be used when extending the memory for the optimization history data. You allocate first memory for a temporary array using getmem. Then you copy the contents of the array hist to the temporary array using cphist. Now you can expand the array hist with the routine expmem. Finally you copy back the contents of the hist array using cphist and free the memory of the temporary array with fremem.

cpmo copies the data from the MO array to another destination or vice versa. It works exactly the same way as cphist, but for two-dimensional arrays.

The following code fragment contains an example for using the dynamical memory allocation. You can also look in the data reading subroutines always provided.

c
c      Cartesian coordinates are saved in arrays x(), y() and
c      z(). The pointers to these arrays are ipx, ipy and ipz.
c      These arrays are real*4 arrays.
c
       mna=50                   ! default number of atoms
       call getmem(ipx,mna,4)   ! allocate memory for arrays
       call getmem(ipy,mna,4)
       call getmem(ipz,mna,4)
       i=1
    10 read(7,*) x(i),y(i),z(i) ! read data from file
       i=i+1
       if (i.gt.mna) then       ! more atoms than we have
                                ! expected
         mna=mna+50             ! make maximum number of
                                ! atoms larger
         call expmem(ipx,mna,4) ! and expand arrays
         call expmem(ipy,mna,4)
         call expmem(ipz,mna,4)
       endif
       goto 10                  ! continue with next atom

The second example demonstrates the use of the indarr and the
cphist routines.

c
c      Optimization history data are saved in three dimensio-
c      nal array hist(6,na,mnh). This array is a real*4 array.
c      Na is the known number of atoms, mnh is the still
c      unknown number of optimization history sets (ohs).
c
       pointer(iphelp,help)       ! define iphelp as pointer
                                  ! on array help
       dimension help(*)          ! make help being an array
       mnh=20                     ! default number of ohs
       call getmem(iphist,6*na*mnh,4) ! allocate memory for
                                      ! array hist
       i=1
    10 do 20 j=1,na
    20 read(7,*) (hist(indarr(k,j,i,6,na)),k=1,6)
                                  ! read data from file
       i=i+1
       if (i.gt.mnh) then         ! more ohs than we have
                                  ! expected
         call getmem(iphelp,6*na*mnh,4) ! allocate memory for
                                        ! temporary array
         call cphist(hist,help,mnh,mnh,na) ! copy hist to
                                           ! help
         mnh=mnh+20               ! make mnh larger
         call expmem(iphist,6*na*mnh,4) ! expand array hist
         call cphist(help,hist,mnh-20,mnh,na) ! copy help to
                                  ! hist with new dimensions
         call fremem(iphelp)      ! free array help
       endif
       goto 10                    ! next ohs

The data you have to read in in your own input routine are (all arrays are one dimensional, exceptions are noted):

Your data reading subroutine has to be called from subroutine input (see source code). You have to specify a letter for your data format (currently d, g, m, o, p, and t are used). Then you can extend the input handler. The existence of your input file (the name you typed on the command line is in variable file) is checked before the corresponding input subroutine is called. You should open and close your file in the corresponding subroutine. If your file contains an unique identifier you may check it before calling your subroutine to make sure that you call the right one.



next up previous
Next: Limitations Up: Viewmol Manual Previous: Data files



Jörg-Rüdiger Hill
Thu May 25 19:30:50 PDT 1995