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

« back to all changes in this revision

Viewing changes to src/lib/libciomr/fndcor.c

  • 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 fndcor.c
3
 
  \ingroup (CIOMR)
4
 
*/
5
 
 
6
 
#include <stdio.h>
7
 
#include <stdlib.h>
8
 
#include <libipv1/ip_lib.h>
9
 
#include <psifiles.h>
10
 
 
11
 
#define DEF_MAXCRR 32000000  /* default maxcor in doubles: used only if
12
 
                              * it can't be read in */
13
 
 
14
 
static void fndcor_abort();
15
 
 
16
 
/*!
17
 
** fndcor(): C translation of the Fortran version, to remove the need to
18
 
**    link the library alloc, which also requires the linking of libparse,
19
 
**    etc, etc...
20
 
**
21
 
**
22
 
** This routine looks for the MEMORY keyword using the new-style input and
23
 
** libipv1.  
24
 
**
25
 
** Arguments: 
26
 
**    \param maxcrb  = long int ptr to hold size of maxcore in bytes
27
 
**    \param infile  = file pointer to input file (eg input.dat)
28
 
**    \param outfile = file pointer to output file (eg output.dat)
29
 
**
30
 
** David Sherrill, February 1994
31
 
** Revised to handle more than 2GB of memory by Ed Valeev, October 2000
32
 
**
33
 
** Revised to return the default if memory keyword is missing and
34
 
** raised the default to 256 MB.  
35
 
** TDC, January 2003
36
 
**
37
 
** \ingroup (CIOMR)
38
 
*/
39
 
 
40
 
void fndcor(long int *maxcrb, FILE *infile, FILE *outfile)
41
 
{
42
 
  char type[20] ;
43
 
  char *s;
44
 
  int count ;
45
 
  long int maxcrr ;           /* maxcor in real words */
46
 
  char *maxcrr_str;           /* string representation of maxcrr */
47
 
  double size ;
48
 
  int errcod ;
49
 
 
50
 
  maxcrr = DEF_MAXCRR ;  /* set maxcor to default first */
51
 
 
52
 
  if(ip_exist("MEMORY",0)) { /* check if the keyword exists */
53
 
    errcod = ip_count("MEMORY", &count, 0) ;
54
 
    if (errcod != IPE_OK) fndcor_abort(infile, outfile) ;
55
 
    else if (errcod == IPE_NOT_AN_ARRAY) { /* Scalar specification of MEMORY */
56
 
      errcod = ip_string("MEMORY", &maxcrr_str, 0);
57
 
      if (errcod != IPE_OK) fndcor_abort(infile, outfile) ;
58
 
      maxcrr = atol(maxcrr_str);
59
 
    }
60
 
    /* Array specification of MEMORY */
61
 
    else if (count == 1) {
62
 
      errcod = ip_string("MEMORY", &maxcrr_str, 0);
63
 
      if (errcod != IPE_OK) fndcor_abort(infile, outfile) ;
64
 
      maxcrr = atol(maxcrr_str);
65
 
    }
66
 
    else if (count == 2) {
67
 
      errcod = ip_data("MEMORY", "%lf", &size, 1, 0) ;
68
 
      if (errcod != IPE_OK) fndcor_abort(infile, outfile) ;
69
 
      errcod = ip_data("MEMORY", "%s", type, 1, 1) ;
70
 
      if (errcod != IPE_OK) fndcor_abort(infile, outfile) ;
71
 
      /* convert string to uppercase */
72
 
      for (s=type; *s!='\0'; s++) {
73
 
        if (*s>='a' && *s <='z') *s = *s + 'A' - 'a';
74
 
      }
75
 
      if ((strcmp(type, "R")==0) || (strcmp(type, "REAL")==0))
76
 
        maxcrr = (long int) size ;
77
 
      else if ((strcmp(type, "I")==0) || (strcmp(type, "INTEGER")==0)) 
78
 
        maxcrr = (long int) (size * sizeof(int) / sizeof(double)) ;
79
 
      else if ((strcmp(type, "B")==0) || (strcmp(type, "BYTES")==0)) 
80
 
        maxcrr = (long int) (size / sizeof(double)) ;
81
 
      else if ((strcmp(type, "KB")==0) || (strcmp(type, "KBYTES")==0)) 
82
 
        maxcrr = (long int) (1000.0 * size / sizeof(double)) ;
83
 
      else if ((strcmp(type, "MB")==0) || (strcmp(type, "MBYTES")==0))
84
 
        maxcrr = (long int) (1000000.0 * size / sizeof(double)) ;
85
 
      else if ((strcmp(type, "GB")==0) || (strcmp(type, "GBYTES")==0))
86
 
        maxcrr = (long int) (1000000000.0 * size / sizeof(double)) ;
87
 
      else {
88
 
        fprintf(outfile, "bad data type, specify one of: \n") ;
89
 
        fprintf(outfile, "REAL, INTEGER, BYTES, KBYTES, MBYTES, or GBYTES\n") ;
90
 
        fndcor_abort(infile, outfile) ;
91
 
      }
92
 
    }
93
 
  }
94
 
  
95
 
  *maxcrb = maxcrr * sizeof(double) ;
96
 
 
97
 
  return;
98
 
}
99
 
 
100
 
 
101
 
static void fndcor_abort(FILE *infile, FILE *outfile)
102
 
{
103
 
   fprintf(stderr, "Error: can't read MEMORY keyword!\n");
104
 
   fprintf(outfile, "Error: can't read MEMORY keyword!\n");
105
 
   ip_done();
106
 
   fclose(infile);
107
 
   fclose(outfile);
108
 
   exit(PSI_RETURN_FAILURE);
109
 
}
110