00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "jbltools/kinfit/hbook.h"
00030 #include "jbltools/kinfit/ftypes.h"
00031
00032 #include <string>
00033 #include <algorithm>
00034
00035 using std::max;
00036 using std::min;
00037
00038
00039
00040 void charray_to_fortran (int n,
00041 int charraylen,
00042 const FCharacter *charrayin,
00043 FCharacter *& charrayout) {
00044
00045
00046
00047
00048
00049
00050
00051
00052 const FCharacter *cpin = charrayin;
00053 FCharacter *cpout = charrayout;
00054 FCharacter *cpend = charrayout + charraylen;
00055 FCharacter *cpendend = charrayout + n*charraylen;
00056 if (n > 0 && charraylen > 0) {
00057 do {
00058 while (cpout < cpend && *cpin != '\0') {
00059 *(cpout++) = *(cpin++);
00060 }
00061 while (cpout < cpend) {
00062 *(cpout++) = ' ';
00063 ++cpin;
00064 }
00065 cpend += charraylen;
00066 }
00067 while (cpout < cpendend);
00068 }
00069 }
00070 void charray_from_fortran (int n,
00071 int charraylen,
00072 const FCharacter *charrayin,
00073 FCharacter *& charrayout) {
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 if (n > 0 && charraylen > 0) {
00084 const FCharacter *cpin = charrayin + n*charraylen - 1;
00085 FCharacter *cpout = charrayout + n*charraylen - 1;
00086 FCharacter *cpend = cpout - charraylen;
00087 do {
00088 do {
00089 *(cpout--) = '\0';
00090 --cpin;
00091 }
00092 while (cpout > cpend && (*cpin == ' ' || *cpin == '\0'));
00093 while (cpout > cpend) {
00094 *(cpout--) = *(cpin--);
00095 }
00096 cpend -= charraylen;
00097 }
00098 while (cpout > charrayout-1);
00099 }
00100 }
00101 void string_to_fortran (int n,
00102 unsigned int& charraylen,
00103 const string sarrayin[],
00104 FCharacter *& charrayout) {
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 charraylen = max (charraylen, 1U);
00118 {
00119 for (int i = 0; i < n; ++i) {
00120 charraylen = max (charraylen, sarrayin[i].length());
00121 }
00122 }
00123 charrayout = new FCharacter [n*charraylen+1];
00124 charrayout[n*charraylen] = '\0';
00125 FCharacter *cpout = charrayout;
00126 FCharacter *cpend = charrayout + charraylen;
00127 {
00128 for (int i = 0; i < n; ++i) {
00129 sarrayin [i].copy(cpout, charraylen);
00130 {
00131 for (FCharacter *cp=cpout + sarrayin [i].length(); cp < cpend; ++cp) {
00132 *cp = ' ';
00133 }
00134 }
00135 cpout = cpend;
00136 cpend += charraylen;
00137 }
00138 }
00139 }
00140 void string_to_fortran (unsigned int& charraylen,
00141 const vector<string>& sarrayin,
00142 FCharacter *& charrayout) {
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 int n = sarrayin.size();
00155 charraylen = max (charraylen, 1U);
00156 {
00157 for (int i = 0; i < n; ++i) {
00158 charraylen = max (charraylen, sarrayin[i].length());
00159 }
00160 }
00161 charrayout = new FCharacter [n*charraylen+1];
00162 charrayout[n*charraylen] = '\0';
00163 FCharacter *cpout = charrayout;
00164 FCharacter *cpend = charrayout + charraylen;
00165 {
00166 for (int i = 0; i < n; ++i) {
00167 sarrayin [i].copy(cpout, charraylen);
00168 {
00169 for (FCharacter *cp=cpout + sarrayin [i].length(); cp < cpend; ++cp) {
00170 *cp = ' ';
00171 }
00172 }
00173 cpout = cpend;
00174 cpend += charraylen;
00175 }
00176 }
00177 }
00178 void string_from_fortran (int n,
00179 unsigned int charraylen,
00180 const FCharacter *charrayin,
00181 string sarrayout[]) {
00182
00183
00184
00185
00186
00187
00188
00189
00190 FCharacter *buffer = new FCharacter [charraylen+1];
00191 buffer [charraylen] = '\0';
00192 {
00193 for (int i = 0; i < n; ++i) {
00194 strncpy (buffer, charrayin + i*charraylen, charraylen);
00195 FCharacter *cp = buffer + charraylen - 1;
00196 while (cp > buffer - 1 && (*cp == ' ' || *cp == '\0')) {
00197 *(cp--) = '\0';
00198 }
00199 sarrayout [i] = buffer;
00200 }
00201 }
00202 delete[] buffer;
00203 }
00204 void string_from_fortran (unsigned int charraylen,
00205 const FCharacter *charrayin,
00206 string& sout) {
00207
00208
00209
00210
00211
00212
00213
00214
00215 FCharacter *buffer = new FCharacter [charraylen+1];
00216 buffer [charraylen] = '\0';
00217 strncpy (buffer, charrayin, charraylen);
00218 FCharacter *cp = buffer + charraylen - 1;
00219 while (cp > buffer - 1 && (*cp == ' ' || *cp == '\0')) {
00220 *(cp--) = '\0';
00221 }
00222 sout = buffer;
00223 delete[] buffer;
00224 }
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 void hbookn (FInteger id,
00237 const string& chtitl,
00238 FInteger nvar,
00239 const string& chrzpa,
00240 FInteger nwbuff,
00241 const string chtags[]) {
00242 unsigned int chtagslen = 0;
00243 FCharacter *chtags_ = 0;
00244 string_to_fortran (nvar, chtagslen, chtags, chtags_);
00245 hbookn_ (&id, chtitl.c_str(), &nvar, chrzpa.c_str(), &nwbuff, chtags_,
00246 chtitl.length(), chrzpa.length(), chtagslen);
00247 delete[] chtags_;
00248 }
00249
00250
00251
00252 void hgiven (FInteger id,
00253 string& chtitl,
00254 FInteger& nvar,
00255 string chtag[],
00256 FReal rlow[],
00257 FReal rhigh[]) {
00258 FCharacter chtitl_ [80];
00259 FCharacter *chtag_ = new FCharacter [nvar*10];
00260 hgiven_ (&id, chtitl_, &nvar, chtag_, rlow, rhigh, 80, 10);
00261 string_from_fortran (80, chtitl_, chtitl);
00262 string_from_fortran (nvar, 10, chtag_, chtag);
00263 delete[] chtag_;
00264 }
00265
00266
00267
00268 FInteger hgntv (FInteger id,
00269 const string chvar[],
00270 FInteger nvar,
00271 FInteger irow,
00272 FInteger& ierr) {
00273 unsigned int chvarlen = 1;
00274 FCharacter *chvar_ = 0;
00275 string_to_fortran (nvar, chvarlen, chvar, chvar_);
00276 hgntv_ (&id, chvar_, &nvar, &irow, &ierr, chvarlen);
00277 delete [] chvar_;
00278 return ierr;
00279 }
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290 void hlabel (FInteger id,
00291 FInteger nlab,
00292 string clab[],
00293 const string& chopt) {
00294 unsigned int clablen = 20;
00295 FCharacter *clab_ = 0;
00296 string_to_fortran (nlab, clablen, clab, clab_);
00297 hlabel_ (&id, &nlab, clab_, chopt.c_str(), clablen, chopt.length());
00298 string_from_fortran (nlab, clablen, clab_, clab);
00299 delete[] clab_;
00300 }
00301
00302
00303
00304
00305
00306
00307
00308
00309 void hgive (FInteger id,
00310 string& chtitl,
00311 FInteger& nx,
00312 FReal& xmi,
00313 FReal& xma,
00314 FInteger& ny,
00315 FReal& ymi,
00316 FReal& yma,
00317 FInteger& nwt,
00318 FInteger& loc) {
00319 FCharacter chtitl_ [80];
00320 hgive_ (&id, chtitl_, &nx, &xmi, &xma, &ny, &ymi, &yma, &nwt, &loc, 80);
00321 string_from_fortran (80, chtitl_, chtitl);
00322 }
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333 void hfinam (FInteger id,
00334 const string chpnam[],
00335 FInteger npar) {
00336 unsigned int chpnamlen = 0;
00337 FCharacter *chpnam_ = 0;
00338 string_to_fortran (npar, chpnamlen, chpnam, chpnam_);
00339 hfinam_ (&id, chpnam_, &npar, chpnamlen);
00340 delete[] chpnam_;
00341 }
00342 void hfinam (FInteger id,
00343 const vector<string>& chpnam,
00344 FInteger npar) {
00345 unsigned int chpnamlen = 0;
00346 FCharacter *chpnam_ = 0;
00347 if (static_cast<int>(chpnam.size()) < npar) npar = chpnam.size();
00348 string_to_fortran (chpnamlen, chpnam, chpnam_);
00349 hfinam_ (&id, chpnam_, &npar, chpnamlen);
00350 delete[] chpnam_;
00351 }
00352 void hgfit (FInteger id,
00353 FInteger& nfpar,
00354 FInteger& npfits,
00355 FReal& fitchi,
00356 FReal fitpar [],
00357 FReal fitsig [],
00358 string fitnam[]) {
00359 FCharacter fitnam_ [25*8];
00360 hgfit_ (&id, &nfpar, &npfits, &fitchi, fitpar, fitsig, fitnam_, 8);
00361 string_from_fortran (min (25, nfpar), 8, fitnam_, fitnam);
00362 }
00363
00364
00365
00366
00367
00368
00369
00370
00371 FInteger hlnext (FInteger& idh,
00372 string& chtype,
00373 string& chtitl,
00374 const string& chopt) {
00375 FCharacter chtype_ [2];
00376 FCharacter chtitl_ [80];
00377 hlnext_ (&idh, chtype_, chtitl_, chopt.c_str(), 2, 80, chopt.length());
00378 string_from_fortran (2, chtype_, chtype);
00379 string_from_fortran (2, chtitl_, chtitl);
00380 return idh;
00381 }
00382 FInteger hrdir (FInteger maxdir,
00383 string chdir[],
00384 FInteger &ndir) {
00385 FCharacter *chdir_ = new FCharacter [maxdir*255];
00386 hrdir_ (&maxdir, chdir_, &ndir, 255);
00387 string_from_fortran (ndir, 255, chdir_, chdir);
00388 delete[] chdir_;
00389 return ndir;
00390 }
00391 FInteger hrdir (FInteger maxdir,
00392 string chdir[]) {
00393 FInteger ndir = 0;
00394 FCharacter *chdir_ = new FCharacter [maxdir*255];
00395 hrdir_ (&maxdir, chdir_, &ndir, 255);
00396 string_from_fortran (ndir, 255, chdir_, chdir);
00397 delete[] chdir_;
00398 return ndir;
00399 }
00400 void hmerge (FInteger nfiles,
00401 const string chfin [],
00402 const string& chfout) {
00403 unsigned int chfinlen = 0;
00404 FCharacter *chfin_ = 0;
00405 string_to_fortran (nfiles, chfinlen, chfin, chfin_);
00406 hmerge_ (&nfiles, chfin_, chfout.c_str(), chfinlen, chfout.length());
00407 delete[] chfin_;
00408 }
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419 PAWC_Type pawc_;
00420
00421 int PAWC_Type::Init::count = 0;
00422
00423
00424
00425 HCFITDType hcfitd_;
00426 QUESTType quest_;