Line data Source code
1 : #include "LHAPDF/FortranWrappers.h"
2 : #include <iostream>
3 : #include <string>
4 : #include <cstring>
5 : #include <cassert>
6 : #include <unistd.h>
7 : #include "binreloc.h"
8 :
9 : using namespace std;
10 :
11 :
12 : #define SIZE 499
13 :
14 :
15 : extern "C" {
16 :
17 :
18 : #define fgetdirpath FC_FUNC(getdirpath, GETDIRPATH)
19 : void fgetdirpath(char*, int);
20 :
21 :
22 : #define fgetprefixpath FC_FUNC(getprefixpath, GETPREFIXPATH)
23 : void fgetprefixpath(char* prefixpath, int length) {
24 0 : BrInitError error;
25 0 : br_init_lib(&error);
26 0 : string prefixdir = br_find_prefix(DEFAULTPREFIXPATH);
27 0 : string test1 = prefixdir + "/share/lhapdf";
28 0 : if (access(test1.c_str(), R_OK) != 0) {
29 0 : prefixdir = DEFAULTPREFIXPATH;
30 : }
31 0 : assert(prefixdir.length() <= (unsigned) length);
32 0 : strncpy(prefixpath, prefixdir.c_str(), length);
33 : // Replace null-terminated string convention with Fortran "trailing spaces" convention:
34 0 : for (size_t i = strlen(prefixpath); i < (unsigned) length; ++i) {
35 0 : prefixpath[i] = ' ';
36 : }
37 0 : }
38 :
39 :
40 : #define fgetindexpath FC_FUNC(getindexpath, GETINDEXPATH)
41 : void fgetindexpath(char* indexpath, int length) {
42 0 : char tmp[SIZE+1];
43 0 : tmp[SIZE] = '\0';
44 0 : fgetdirpath(tmp, SIZE);
45 : //for (size_t i = 0; i < SIZE; ++i) {
46 : // tmp[i] = ' ';
47 : //}
48 0 : for (int i = SIZE-1; i >= 0; --i) {
49 0 : if (tmp[i] != ' ') break;
50 0 : tmp[i] = '\0';
51 : }
52 0 : string try1(tmp), try2(tmp);
53 0 : try1 += "/PDFsets.index";
54 0 : try2 += ".index";
55 0 : if (access(try1.c_str(), R_OK) == 0) {
56 0 : assert(try1.length() <= (unsigned) length);
57 0 : strncpy(indexpath, try1.c_str(), length);
58 : } else {
59 0 : assert(try2.length() <= (unsigned) length);
60 0 : strncpy(indexpath, try2.c_str(), length);
61 : }
62 : // Replace null-terminated string convention with Fortran "trailing spaces" convention:
63 0 : for (size_t i = strlen(indexpath); i < (unsigned) length; ++i) {
64 0 : indexpath[i] = ' ';
65 : }
66 0 : }
67 :
68 :
69 : #define fgetdatapath FC_FUNC(getdatapath, GETDATAPATH)
70 : void fgetdatapath(char* datapath, int length) {
71 0 : BrInitError error;
72 0 : br_init_lib(&error);
73 0 : string sharedir = br_find_data_dir(DEFAULTLHAPATH);
74 0 : string tmp = sharedir;
75 0 : string test1 = tmp + "/cteq6.LHpdf";
76 0 : if (access(test1.c_str(), R_OK) != 0) {
77 0 : tmp = string(DEFAULTLHAPATH);
78 0 : }
79 0 : assert(tmp.length() <= (unsigned) length);
80 0 : strncpy(datapath, tmp.c_str(), length);
81 : // Replace null-terminated string convention with Fortran "trailing spaces" convention:
82 0 : for (size_t i = strlen(datapath); i < (unsigned) length; ++i) {
83 0 : datapath[i] = ' ';
84 : }
85 0 : }
86 :
87 :
88 : }
|