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

« back to all changes in this revision

Viewing changes to src/lib/libiwl/buf_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
/*!
 
2
  \file
 
3
  \ingroup IWL
 
4
*/
 
5
#include <cstdio>
 
6
#include <cstdlib>
 
7
#include <libpsio/psio.h>
 
8
extern "C" {
 
9
#include "iwl.h"
 
10
}
 
11
#include "iwl.hpp"
 
12
 
 
13
using namespace psi;
 
14
 
 
15
extern "C" {
 
16
        
 
17
extern FILE *outfile;
 
18
 
 
19
}
 
20
 
 
21
IWL::IWL()
 
22
{
 
23
    /*! set up buffer info */
 
24
    itap_ = -1;
 
25
    bufpos_ = PSIO_ZERO;
 
26
    ints_per_buf_ = IWL_INTS_PER_BUF;
 
27
    cutoff_ = 1.e-14;
 
28
    bufszc_ = 2 * sizeof(int) + ints_per_buf_ * 4 * sizeof(Label) +
 
29
        ints_per_buf_ * sizeof(Value);
 
30
    lastbuf_ = 0;
 
31
    inbuf_ = 0;
 
32
    idx_ = 0;    
 
33
}
 
34
 
 
35
IWL::IWL(PSIO *psio, int itap, double cutoff, int oldfile, int readflag):
 
36
    keep_(true)
 
37
{
 
38
    init(psio, itap, cutoff, oldfile, readflag);
 
39
}
 
40
 
 
41
void IWL::init(PSIO *psio, int itap, double cutoff, int oldfile, int readflag)
 
42
{
 
43
    psio_ = psio;
 
44
    
 
45
    /*! set up buffer info */
 
46
    itap_ = itap;
 
47
    bufpos_ = PSIO_ZERO;
 
48
    ints_per_buf_ = IWL_INTS_PER_BUF;
 
49
    cutoff_ = cutoff;
 
50
    bufszc_ = 2 * sizeof(int) + ints_per_buf_ * 4 * sizeof(Label) +
 
51
        ints_per_buf_ * sizeof(Value);
 
52
    lastbuf_ = 0;
 
53
    inbuf_ = 0;
 
54
    idx_ = 0;
 
55
 
 
56
    /*! make room in the buffer */
 
57
    // labels_ = (Label *) malloc (4 * ints_per_buf_ * sizeof(Label));
 
58
    // values_ = (Value *) malloc (ints_per_buf_ * sizeof(Value));
 
59
    labels_ = new Label[4 * ints_per_buf_];
 
60
    values_ = new Value[ints_per_buf_];
 
61
 
 
62
    /*! open the output file */
 
63
    /*! Note that we assume that if oldfile isn't set, we O_CREAT the file */
 
64
    psio_->open(itap_, oldfile ? PSIO_OPEN_OLD : PSIO_OPEN_NEW);
 
65
    if (oldfile && (psio_->tocscan(itap_, IWL_KEY_BUF) == NULL)) {
 
66
        fprintf(stderr,"iwl_buf_init: Can't open file %d\n", itap_);
 
67
        psio_->close(itap_,0);
 
68
        return;
 
69
    } 
 
70
 
 
71
    /*! go ahead and read a buffer */
 
72
    if (readflag) fetch();
 
73
}
 
74
 
 
75
extern "C" {
 
76
    
 
77
/*!
 
78
** iwl_buf_init()
 
79
**
 
80
**      \param Buf               Buffer to be initialised
 
81
**      \param itape            Filenumber
 
82
**      \param cutoff           Cutoff for keeping integral
 
83
**      \param oldfile          If ==0 create file
 
84
**      \param readflag         If ==1 fetch buffer
 
85
**
 
86
** Prepare a PSI Buffer according to the Integrals
 
87
** With Labels format for reading or writing.  Important to set
 
88
** readflag=1 if opening for reading, since other IWL buffer read
 
89
** routines anticipate that there is already data in the buffer.
 
90
**
 
91
** David Sherrill, March 1995
 
92
** Revised 6/26/96 by CDS for new format
 
93
** \ingroup IWL
 
94
*/
 
95
void iwl_buf_init(struct iwlbuf *Buf, int itape, double cutoff,
 
96
      int oldfile, int readflag)
 
97
{
 
98
 
 
99
  /*! set up buffer info */
 
100
  Buf->itap = itape;
 
101
  Buf->bufpos = PSIO_ZERO;
 
102
  Buf->ints_per_buf = IWL_INTS_PER_BUF;
 
103
  Buf->cutoff = cutoff;
 
104
  Buf->bufszc = 2 * sizeof(int) + Buf->ints_per_buf * 4 * sizeof(Label) +
 
105
    Buf->ints_per_buf * sizeof(Value);
 
106
  Buf->lastbuf = 0;
 
107
  Buf->inbuf = 0;
 
108
  Buf->idx = 0;
 
109
 
 
110
  /*! make room in the buffer */
 
111
  Buf->labels = (Label *) malloc (4 * Buf->ints_per_buf * sizeof(Label));
 
112
  Buf->values = (Value *) malloc (Buf->ints_per_buf * sizeof(Value));
 
113
 
 
114
  /*! open the output file */
 
115
  /*! Note that we assume that if oldfile isn't set, we O_CREAT the file */
 
116
  psio_open(Buf->itap, oldfile ? PSIO_OPEN_OLD : PSIO_OPEN_NEW);
 
117
  if (oldfile && (psio_tocscan(Buf->itap, IWL_KEY_BUF) == NULL)) {
 
118
    fprintf(outfile,"iwl_buf_init: Can't open file %d\n", Buf->itap);
 
119
    psio_close(Buf->itap,0);
 
120
    return;
 
121
  } 
 
122
 
 
123
  /*! go ahead and read a buffer */
 
124
  if (readflag) iwl_buf_fetch(Buf);
 
125
  
 
126
}
 
127
 
 
128
} /* extern "C" */
 
 
b'\\ No newline at end of file'