~ubuntu-branches/ubuntu/karmic/psicode/karmic

« back to all changes in this revision

Viewing changes to src/lib/libdpd/file4_init.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck, Michael Banck, Daniel Leidert
  • Date: 2009-02-23 00:12:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090223001202-rutldoy3dimfpesc
Tags: 3.4.0-1
* New upstream release.

[ Michael Banck ]
* debian/patches/01_DESTDIR.dpatch: Refreshed.
* debian/patches/02_FHS.dpatch: Removed, applied upstream.
* debian/patches/03_debian_docdir: Likewise.
* debian/patches/04_man.dpatch: Likewise.
* debian/patches/06_466828_fix_gcc_43_ftbfs.dpatch: Likewise.
* debian/patches/07_464867_move_executables: Fixed and refreshed.
* debian/patches/00list: Adjusted.
* debian/control: Improved description.
* debian/patches-held: Removed.
* debian/rules (install/psi3): Do not ship the ruby bindings for now.

[ Daniel Leidert ]
* debian/rules: Fix txtdir via DEB_MAKE_INSTALL_TARGET.
* debian/patches/01_DESTDIR.dpatch: Refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*! \file
 
2
    \ingroup DPD
 
3
    \brief Enter brief description of file here 
 
4
*/
 
5
#include <cstdio>
 
6
#include <cstdlib>
 
7
#include <cstring>
 
8
#include <libpsio/psio.h>
 
9
#include "dpd.h"
 
10
#define EXTERN
 
11
#include "dpd.gbl"
 
12
 
 
13
extern "C" {
 
14
 
 
15
/* dpd_file4_init(): Prepares a dpd four-index file on disk for
 
16
** reading/writing.
 
17
**
 
18
** Arguments:
 
19
**   dpdfile4 *File: A pointer to the dpdfile4 to be initialized.
 
20
**   int filenum: The PSI unit number for this file.
 
21
**   int irrep: The irrep of this quantity.
 
22
**   int pqnum: The index combination for the bra indices for the
 
23
**              data as it will be stored on disk.
 
24
**   int rsnum: The index combination for the ket indices for the
 
25
**              data as it will be stored on disk.
 
26
**   char *label: A string labelling for this buffer.
 
27
*/
 
28
 
 
29
int dpd_file4_init(dpdfile4 *File, int filenum, int irrep, int pqnum,
 
30
                   int rsnum,  const char *label)
 
31
{
 
32
  int i;
 
33
  int maxrows, rowtot, coltot;
 
34
  unsigned int priority;
 
35
  struct dpd_file4_cache_entry *this_entry;
 
36
  psio_address irrep_ptr;
 
37
  
 
38
  File->dpdnum = dpd_default;
 
39
  File->params = &(dpd_list[dpd_default].params4[pqnum][rsnum]);
 
40
 
 
41
  strcpy(File->label,label);
 
42
  File->filenum = filenum;
 
43
  File->my_irrep = irrep;
 
44
 
 
45
  this_entry = dpd_file4_cache_scan(filenum, irrep, pqnum, rsnum, label, dpd_default);
 
46
  if(this_entry != NULL) {
 
47
    File->incore = 1;
 
48
    File->matrix = this_entry->matrix;
 
49
  }
 
50
  else {
 
51
    File->incore = 0;
 
52
    File->matrix = (double ***) malloc(File->params->nirreps*sizeof(double **));
 
53
  }
 
54
 
 
55
  /* Construct logical subfile pointers */
 
56
  File->lfiles = (psio_address *) malloc(File->params->nirreps *
 
57
                                         sizeof(psio_address));
 
58
  File->lfiles[0] = PSIO_ZERO;
 
59
  for(i=1; i < File->params->nirreps; i++) {
 
60
 
 
61
    rowtot = File->params->rowtot[i-1];
 
62
    coltot = File->params->coltot[(i-1)^irrep];
 
63
 
 
64
    if(coltot) {
 
65
      /* number of rows for which we can compute the address offset directly */
 
66
      maxrows = DPD_BIGNUM/(coltot*sizeof(double)); 
 
67
      if(maxrows < 1) {
 
68
        fprintf(stderr, "\nLIBDPD Error: each row of %s is too long to compute an address.\n",
 
69
                File->label);
 
70
        dpd_error("dpd_file4_init", stderr);
 
71
      }
 
72
    }
 
73
    else maxrows = DPD_BIGNUM;
 
74
 
 
75
    /* compute the file offset by increments */
 
76
    irrep_ptr = File->lfiles[i-1];
 
77
    for(; rowtot > maxrows; rowtot -= maxrows)
 
78
      irrep_ptr = psio_get_address(irrep_ptr, maxrows*coltot*sizeof(double));
 
79
    irrep_ptr = psio_get_address(irrep_ptr, rowtot*coltot*sizeof(double));
 
80
 
 
81
    File->lfiles[i] = irrep_ptr;
 
82
  }
 
83
 
 
84
  /* Put this file4 into cache if requested */
 
85
  if(dpd_main.cachefiles[filenum] && dpd_main.cachelist[pqnum][rsnum]) 
 
86
    {
 
87
      /* Get the file4's cache priority */
 
88
      if(dpd_main.cachetype == 1)
 
89
        priority = dpd_file4_cache_get_priority(File);
 
90
      else priority = 0;
 
91
 
 
92
      dpd_file4_cache_add(File, priority); 
 
93
 
 
94
      /* Make sure this cache entry can't be deleted until we're done */
 
95
      dpd_file4_cache_lock(File);
 
96
    }
 
97
 
 
98
  return 0;
 
99
}
 
100
 
 
101
} /* extern "C" */