File: boinc_api_fortran.cpp

package info (click to toggle)
boinc 8.0.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 106,832 kB
  • sloc: cpp: 167,537; php: 111,699; pascal: 56,262; ansic: 49,284; xml: 18,762; python: 7,938; javascript: 6,538; sh: 5,719; makefile: 2,183; java: 2,041; objc: 1,867; perl: 1,843; sql: 830; lisp: 47; csh: 30
file content (144 lines) | stat: -rw-r--r-- 3,659 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2019 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.

// This file defines a Fortran wrapper to the BOINC API.

// Define this symbol (here or in Makefile) if you want graphics functions
//#define GRAPHICS

// Define this symbol (here or in Makefile) if you want zip/unzip functions
//#define INCLUDE_ZIP

#include "config.h"
#include "util.h"
#include "boinc_api.h"
#ifdef GRAPHICS
#include "graphics_api.h"
#endif
#ifdef INCLUDE_ZIP
#include "boinc_zip.h"
#endif

// helper class that makes a C-string from a character array and length,
// automatically deleted on destruction.
// Fortran strings are passed as character array plus length
//
class STRING_FROM_FORTRAN {
    char* p;
public:
    STRING_FROM_FORTRAN(const char* s, int s_len) {
        p = new char[s_len + 1];
        memcpy(p, s, s_len);
        p[s_len] = 0;
    }
    ~STRING_FROM_FORTRAN() { delete [] p; }
    void strip_whitespace() {
        ::strip_whitespace(p);
    }
    const char* c_str() { return p; }
};

// remove terminating null and pad with blanks a la FORTRAN
//
static void string_to_fortran(char* p, int len) {
    for (int i=strlen(p); i<len; i++) {
        p[i] = ' ';
    }
}

extern "C" {

void boinc_init_() {
    boinc_init();
}

void boinc_finish_(int* status) {
    boinc_finish(*status);
}

#ifdef GRAPHICS
void boinc_init_graphics_(){
    boinc_init_graphics();
}

void boinc_finish_graphics_(){
    boinc_finish_graphics();
}
#endif

void boinc_is_standalone_(int* result) {
    *result = boinc_is_standalone();
}

void boincrf_(const char* s, char* t, int s_len, int t_len) {
    STRING_FROM_FORTRAN sff(s, s_len);
    sff.strip_whitespace();
    boinc_resolve_filename(sff.c_str(), t, t_len);
    string_to_fortran(t, t_len);
}

void boinc_parse_init_data_file_() {
    boinc_parse_init_data_file();
}

void boinc_time_to_checkpoint_(int* result) {
    *result = boinc_time_to_checkpoint();
}

void boinc_checkpoint_completed_() {
    boinc_checkpoint_completed();
}

void boinc_begin_critical_section_() {
    boinc_begin_critical_section();
}

void boinc_end_critical_section_() {
    boinc_end_critical_section();
}

void boinc_fraction_done_(double* d) {
    boinc_fraction_done(*d);
}

void boinc_get_fraction_done_(double* d) {
    *d = boinc_get_fraction_done();
}

void boinc_wu_cpu_time_(double* d_out) {
    boinc_wu_cpu_time(*d_out);
}

void boinc_calling_thread_cpu_time_(double* d) {
    boinc_calling_thread_cpu_time(*d);
}

#ifdef INCLUDE_ZIP
void boinc_zip_(int* zipmode, const char* zipfile,
    const char* path, int zipfile_len, int path_len
) {
    //zipmode = 0 to unzip or 1 to zip. FORTRAN variable of type INTEGER.
    //zipfile, path = FORTRAN variables of type CHARACTER.
    STRING_FROM_FORTRAN zipfileff(zipfile, zipfile_len);
    STRING_FROM_FORTRAN pathff(path, path_len);
    zipfileff.strip_whitespace();
    pathff.strip_whitespace();
    boinc_zip(*zipmode,zipfileff.c_str(),pathff.c_str());
}
#endif

}   // extern "C"