8
#include <libipv1/ip_lib.h>
11
#define DEF_MAXCRR 32000000 /* default maxcor in doubles: used only if
12
* it can't be read in */
14
static void fndcor_abort();
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,
22
** This routine looks for the MEMORY keyword using the new-style input and
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)
30
** David Sherrill, February 1994
31
** Revised to handle more than 2GB of memory by Ed Valeev, October 2000
33
** Revised to return the default if memory keyword is missing and
34
** raised the default to 256 MB.
40
void fndcor(long int *maxcrb, FILE *infile, FILE *outfile)
45
long int maxcrr ; /* maxcor in real words */
46
char *maxcrr_str; /* string representation of maxcrr */
50
maxcrr = DEF_MAXCRR ; /* set maxcor to default first */
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);
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);
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';
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)) ;
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) ;
95
*maxcrb = maxcrr * sizeof(double) ;
101
static void fndcor_abort(FILE *infile, FILE *outfile)
103
fprintf(stderr, "Error: can't read MEMORY keyword!\n");
104
fprintf(outfile, "Error: can't read MEMORY keyword!\n");
108
exit(PSI_RETURN_FAILURE);