Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 4c88a1f

Browse files
author
Nicolas Cornu
authored
Remove sdprintf (#255)
* Get rid of sdprintf * Relevant test+cmake
1 parent 9b47f2b commit 4c88a1f

File tree

9 files changed

+38
-540
lines changed

9 files changed

+38
-540
lines changed

coreneuron/apps/main1.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ THE POSSIBILITY OF SUCH DAMAGE.
5050
#include "coreneuron/io/nrnoptarg.hpp"
5151
#include "coreneuron/io/prcellstate.hpp"
5252
#include "coreneuron/utils/nrnmutdec.h"
53-
#include "coreneuron/utils/sdprintf.h"
5453
#include "coreneuron/utils/nrn_stats.h"
5554
#include "coreneuron/io/nrnreport.hpp"
5655
#include "coreneuron/gpu/nrn_acc_manager.hpp"

coreneuron/io/mk_mech.cpp

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ THE POSSIBILITY OF SUCH DAMAGE.
3838
#include "coreneuron/mechanism/register_mech.hpp"
3939
#include "coreneuron/nrniv/nrniv_decl.h"
4040
#include "coreneuron/utils/nrn_assert.h"
41-
#include "coreneuron/utils/sdprintf.h"
4241
#include "coreneuron/mechanism/mech/cfile/cabvars.h"
4342
#include "coreneuron/io/nrn2core_direct.h"
4443
#include "coreneuron/coreneuron.hpp"
@@ -85,39 +84,42 @@ void mk_mech(const char* datpath) {
8584
mk_mech();
8685
return;
8786
}
88-
char fnamebuf[1024];
89-
sd_ptr fname = sdprintf(fnamebuf, sizeof(fnamebuf), "%s/%s", datpath, "bbcore_mech.dat");
90-
std::ifstream fs(fname);
91-
92-
if (!fs.good()) {
93-
fprintf(stderr, "Error: couldn't find bbcore_mech.dat file in the dataset directory \n");
94-
fprintf(
95-
stderr,
96-
" Make sure to pass full directory path of dataset using -d DIR or --datpath=DIR \n");
97-
}
98-
99-
nrn_assert(fs.good());
100-
mk_mech(fs);
101-
fs.close();
87+
{
88+
std::string fname = std::string(datpath) + "/bbcore_mech.dat";
89+
std::ifstream fs(fname);
90+
91+
if (!fs.good()) {
92+
fprintf(stderr, "Error: couldn't find bbcore_mech.dat file in the dataset directory \n");
93+
fprintf(
94+
stderr,
95+
" Make sure to pass full directory path of dataset using -d DIR or --datpath=DIR \n");
96+
}
10297

103-
fname = sdprintf(fnamebuf, sizeof(fnamebuf), "%s/%s", datpath, "byteswap1.dat");
104-
FILE* f = fopen(fname, "r");
105-
if (!f) {
106-
fprintf(stderr, "Error: couldn't find byteswap1.dat file in the dataset directory \n");
98+
nrn_assert(fs.good());
99+
mk_mech(fs);
100+
fs.close();
107101
}
108-
nrn_assert(f);
109-
// file consists of int32_t binary 1 . After reading can decide if
110-
// binary info in files needs to be byteswapped.
111-
int32_t x;
112-
nrn_assert(fread(&x, sizeof(int32_t), 1, f) == 1);
113-
nrn_need_byteswap = 0;
114-
if (x != 1) {
115-
BYTEHEADER;
116-
nrn_need_byteswap = 1;
117-
BYTESWAP(x, int32_t);
118-
nrn_assert(x == 1);
102+
103+
{
104+
std::string fname = std::string(datpath) + "/byteswap1.dat";
105+
FILE* f = fopen(fname.c_str(), "r");
106+
if (!f) {
107+
fprintf(stderr, "Error: couldn't find byteswap1.dat file in the dataset directory \n");
108+
}
109+
nrn_assert(f);
110+
// file consists of int32_t binary 1 . After reading can decide if
111+
// binary info in files needs to be byteswapped.
112+
int32_t x;
113+
nrn_assert(fread(&x, sizeof(int32_t), 1, f) == 1);
114+
nrn_need_byteswap = 0;
115+
if (x != 1) {
116+
BYTEHEADER;
117+
nrn_need_byteswap = 1;
118+
BYTESWAP(x, int32_t);
119+
nrn_assert(x == 1);
120+
}
121+
fclose(f);
119122
}
120-
fclose(f);
121123
}
122124

123125
// we are embedded in NEURON, get info as stringstream from nrnbbcore_write.cpp

coreneuron/io/nrn_setup.hpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ THE POSSIBILITY OF SUCH DAMAGE.
3232
#include <string>
3333
#include "coreneuron/sim/multicore.hpp"
3434
#include "coreneuron/io/nrn_filehandler.hpp"
35-
#include "coreneuron/utils/sdprintf.h"
3635

3736
namespace coreneuron {
3837
static bool do_not_open;
@@ -129,17 +128,15 @@ inline void* phase_wrapper_w(NrnThread* nt) {
129128
data_dir = restore_path_w;
130129
}
131130

132-
sd_ptr fname = sdprintf(fnamebuf, sizeof(fnamebuf),
133-
std::string("%s/%d_" + getPhaseName<P>() + ".dat").c_str(),
134-
data_dir, gidgroups_w[i]);
131+
std::string fname = std::string(data_dir) + "/" + std::to_string(gidgroups_w[i]) + "_" + getPhaseName<P>() + ".dat";
135132

136133
// Avoid trying to open the gid_gap.dat file if it doesn't exist when there are no
137134
// gap junctions in this gid
138-
if (P == gap && !file_reader_w[i].file_exist(fname)) {
135+
if (P == gap && !file_reader_w[i].file_exist(fname.c_str())) {
139136
file_reader_w[i].close();
140137
} else {
141138
// if no file failed to open or not opened at all
142-
file_reader_w[i].open(fname, byte_swap_w);
139+
file_reader_w[i].open(fname.c_str(), byte_swap_w);
143140
}
144141
}
145142
read_phase_aux<P>(file_reader_w[i], imult_w[i], *nt);

coreneuron/io/prcellstate.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ THE POSSIBILITY OF SUCH DAMAGE.
3333
#include "coreneuron/sim/multicore.hpp"
3434
#include "coreneuron/io/nrn_setup.hpp"
3535
#include "coreneuron/network/netcon.hpp"
36-
#include "coreneuron/utils/sdprintf.h"
3736
#include "coreneuron/nrniv/nrniv_decl.h"
3837
#include "coreneuron/utils/nrn_assert.h"
3938
#include "coreneuron/coreneuron.hpp"
@@ -281,8 +280,8 @@ int prcellstate(int gid, const char* suffix) {
281280
if (ps.output_index_ == gid) {
282281
// found it so create a <gid>_<suffix>.corenrn file
283282
char buf[200];
284-
sd_ptr filename = sdprintf(buf, sizeof(buf), "%d_%s.corenrn", gid, suffix);
285-
FILE* f = fopen(filename, "w");
283+
std::string filename = std::to_string(gid) + "_" + suffix + ".corenrn";
284+
FILE* f = fopen(filename.c_str(), "w");
286285
assert(f);
287286
fprintf(f, "gid = %d\n", gid);
288287
fprintf(f, "t = %.*g\n", precision, nt._t);

coreneuron/utils/sdprintf.cpp

Lines changed: 0 additions & 107 deletions
This file was deleted.

coreneuron/utils/sdprintf.h

Lines changed: 0 additions & 147 deletions
This file was deleted.

0 commit comments

Comments
 (0)