JAGSの出力ファイル名にランダムなプレフィクスをつける [仕事]
農林水産研究情報総合センターの並列計算システムでJAGSを使うのに便利なように、JAGSの出力ファイル名にランダムなプレフィクスをつけるパッチを書いてみた。もっとも、かなりテキトーである。
*** JAGS-1.0.3-orig/src/terminal/parser.yy 2008-07-17 21:09:30.000000000 +0900 --- JAGS-1.0.3/src/terminal/parser.yy 2009-10-30 22:18:07.000000000 +0900 *************** *** 761,770 **** void doAllCoda (std::string const &stem) { /* Open index file */ std::ostringstream indstream; ! indstream << stem << "index.txt"; std::string indname = indstream.str(); std::ofstream ind(indname.c_str()); if (!ind) { --- 761,776 ---- void doAllCoda (std::string const &stem) { + const unsigned short num_rand = 8; + std::string rand_prefix = "ABCDEFGH"; + srand((unsigned) time(NULL)); + for (unsigned short i = 0; i < num_rand; i++) { + rand_prefix[i] = rand() % 26 + 'A'; + } /* Open index file */ std::ostringstream indstream; ! indstream << rand_prefix << stem << "index.text"; std::string indname = indstream.str(); std::ofstream ind(indname.c_str()); if (!ind) { *************** *** 776,782 **** for (unsigned int n = 0; n < console->nchain(); ++n) { /* Open output file */ std::ostringstream outstream; ! outstream << stem << "chain" << n + 1 << ".txt"; std::string outname = outstream.str(); std::ofstream *out = new std::ofstream(outname.c_str()); if (*out) { --- 782,788 ---- for (unsigned int n = 0; n < console->nchain(); ++n) { /* Open output file */ std::ostringstream outstream; ! outstream << rand_prefix << stem << "chain" << n + 1 << ".txt"; std::string outname = outstream.str(); std::ofstream *out = new std::ofstream(outname.c_str()); if (*out) { *************** *** 801,810 **** void doCoda (ParseTree const *var, std::string const &stem) { /* Open index file */ std::ostringstream indstream; ! indstream << stem << "index.txt"; std::string indname = indstream.str(); std::ofstream ind(indname.c_str()); if (!ind) { --- 807,822 ---- void doCoda (ParseTree const *var, std::string const &stem) { + const unsigned short num_rand = 8; + std::string rand_prefix = "ABCDEFGH"; + srand((unsigned) time(NULL)); + for (unsigned short i = 0; i < num_rand; i++) { + rand_prefix[i] = rand() % 26 + 'A'; + } /* Open index file */ std::ostringstream indstream; ! indstream << rand_prefix << stem << "index.txt"; std::string indname = indstream.str(); std::ofstream ind(indname.c_str()); if (!ind) { *************** *** 816,822 **** for (unsigned int n = 0; n < console->nchain(); ++n) { /* Open output file */ std::ostringstream outstream; ! outstream << stem << "chain" << n + 1 << ".txt"; std::string outname = outstream.str(); std::ofstream *out = new std::ofstream(outname.c_str()); --- 828,834 ---- for (unsigned int n = 0; n < console->nchain(); ++n) { /* Open output file */ std::ostringstream outstream; ! outstream << rand_prefix << stem << "chain" << n + 1 << ".txt"; std::string outname = outstream.str(); std::ofstream *out = new std::ofstream(outname.c_str());
タグ:jags
コメント 0