int cspe::process(const char* namel, const char* namer) { free(left_image); free(right_image); free(image); free(left_image_ups); free(right_image_ups); // Load left image if (file_loader(namel, (char**)&left_image) != 0) return 1; // Load right image if (file_loader(namer, (char**)&right_image) != 0) return 1; if (left_image->sizex == right_image->sizex) sizex = right_image->sizex; else return 1; if (left_image->sizey == right_image->sizey) sizey = right_image->sizey; else return 1; if (ups == 1) { supsample(left_image, (float**)&left_image_ups); supsample(right_image, (float**)&right_image_ups); } else { tofloat(left_image, (float**)&left_image_ups); tofloat(right_image, (float**)&right_image_ups); } long size_b = sizex_ups * sizey_ups * sizeof(float); image = (float*)malloc(size_b); overlap(); return 0; }
// Funcion que se encarga leer archivos de texto devolviendo una cadena con // el contenido de estos. // PRE: 'iniArchivos' es el indice inicial desde donde 'argv' posee nombres // de archivo; 'argc' y 'argv' son los parametros de entrada de la funcion // main. // POST: se devuelve una unica cadena con el contenido completo de archivos. char* cargarTextosDeArchivos(int iniArchivos, int argc, char **argv) { int i; char * texto = ""; // Sensamos cada archivo ingresado y concatenamos su contenido for(i = iniArchivos; i < argc; i++) { // Cargamos contenido de archivo char * texto_tmp = file_loader(argv[i]); // Recalculamos el tamanio del arreglo int len = strlen(texto) + strlen(texto_tmp) + 2; // Solicitamos espacio de memoria nuevo char * texto_alloc = (char *) malloc(len * sizeof(char)); // Copiamos contenido antigui y concatenamos el nuevo strcpy(texto_alloc, texto); if(i > iniArchivos) strcat(texto_alloc, " "); strcat(texto_alloc, texto_tmp); free(texto_tmp); // Liberamos espacio de memoria antiguio if(i > iniArchivos) free(texto); // Asociamos al nuevo arreglo texto = texto_alloc; } return texto; }
void testFileLoader(const char * url) { char * text; char ** words = NULL; int wordsSize = 0; text = file_loader(url); if (text != NULL) { //fputs(text, stdout); } wordsSize = to_words(text, &words); for(int i = 0; i < wordsSize; i++) { fputs("\n", stdout); fputs(words[i], stdout); fputs("\n", stdout); } }
int main(int argc,char **argv) { try { std::string def[] = { #ifdef BOOSTER_LOCALE_WITH_ICU "icu" , #endif #ifndef BOOSTER_LOCALE_NO_STD_BACKEND "std" , #endif #ifndef BOOSTER_LOCALE_NO_POSIX_BACKEND "posix", #endif #ifndef BOOSTER_LOCALE_NO_WINAPI_BACKEND "winapi", #endif }; for(int type = 0 ; type < int(sizeof(def)/sizeof(def[0])) ; type ++ ) { booster::locale::localization_backend_manager tmp_backend = booster::locale::localization_backend_manager::global(); tmp_backend.select(def[type]); booster::locale::localization_backend_manager::global(tmp_backend); backend = def[type]; std::cout << "Testing for backend --------- " << def[type] << std::endl; booster::locale::generator g; g.add_messages_domain("default"); g.add_messages_domain("simple"); g.add_messages_domain("full"); g.add_messages_domain("fall"); if(argc==2) g.add_messages_path(argv[1]); else g.add_messages_path("./"); std::string locales[] = { "he_IL.UTF-8", "he_IL.ISO8859-8" }; for(unsigned i=0;i<sizeof(locales)/sizeof(locales[0]);i++){ std::locale l; if(i==1) { try { l = g(locales[i]); } catch(booster::locale::conv::invalid_charset_error const &e) { std::cout << "Looks like ISO-8859-8 is not supported! skipping" << std::endl; iso_8859_8_not_supported = true; continue; } } else { l = g(locales[i]); } std::cout << " Testing "<<locales[i]<<std::endl; std::cout << " single forms" << std::endl; test_translate("hello","שלום",l,"default"); test_translate("hello","היי",l,"simple"); test_translate("hello","hello",l,"undefined"); test_translate("untranslated","untranslated",l,"default"); // Check removal of old "context" information test_translate("#untranslated","#untranslated",l,"default"); test_translate("##untranslated","##untranslated",l,"default"); test_ctranslate("context","hello","שלום בהקשר אחר",l,"default"); test_translate("#hello","#שלום",l,"default"); std::cout << " plural forms" << std::endl; { test_ntranslate("x day","x days",0,"x ימים",l,"default"); test_ntranslate("x day","x days",1,"יום x",l,"default"); test_ntranslate("x day","x days",2,"יומיים",l,"default"); test_ntranslate("x day","x days",3,"x ימים",l,"default"); test_ntranslate("x day","x days",20,"x יום",l,"default"); test_ntranslate("x day","x days",0,"x days",l,"undefined"); test_ntranslate("x day","x days",1,"x day",l,"undefined"); test_ntranslate("x day","x days",2,"x days",l,"undefined"); test_ntranslate("x day","x days",20,"x days",l,"undefined"); } std::cout << " plural forms with context" << std::endl; { std::string inp = "context"; std::string out = "בהקשר "; test_cntranslate(inp,"x day","x days",0,out+"x ימים",l,"default"); test_cntranslate(inp,"x day","x days",1,out+"יום x",l,"default"); test_cntranslate(inp,"x day","x days",2,out+"יומיים",l,"default"); test_cntranslate(inp,"x day","x days",3,out+"x ימים",l,"default"); test_cntranslate(inp,"x day","x days",20,out+"x יום",l,"default"); test_cntranslate(inp,"x day","x days",0,"x days",l,"undefined"); test_cntranslate(inp,"x day","x days",1,"x day",l,"undefined"); test_cntranslate(inp,"x day","x days",2,"x days",l,"undefined"); test_cntranslate(inp,"x day","x days",20,"x days",l,"undefined"); } } std::cout << " Testing fallbacks" <<std::endl; test_translate("test","he_IL",g("he_IL.UTF-8"),"full"); test_translate("test","he",g("he_IL.UTF-8"),"fall"); std::cout << " Testing automatic conversions " << std::endl; std::locale::global(g("he_IL.UTF-8")); TEST(same_s(bl::translate("hello"))=="שלום"); TEST(same_w(bl::translate(to<wchar_t>("hello")))==to<wchar_t>("שלום")); #ifdef BOOSTER_HAS_CHAR16_T if(backend=="icu" || backend=="std") TEST(same_u16(bl::translate(to<char16_t>("hello")))==to<char16_t>("שלום")); #endif #ifdef BOOSTER_HAS_CHAR32_T if(backend=="icu" || backend=="std") TEST(same_u32(bl::translate(to<char32_t>("hello")))==to<char32_t>("שלום")); #endif } std::cout << "Testing custom file system support" << std::endl; { booster::locale::gnu_gettext::messages_info info; info.language = "he"; info.country = "IL"; info.encoding="UTF-8"; if(argc==2) info.paths.push_back(argv[1]); else info.paths.push_back("./"); info.domains.push_back(bl::gnu_gettext::messages_info::domain("default")); info.callback = file_loader(); std::locale l(std::locale::classic(),booster::locale::gnu_gettext::create_messages_facet<char>(info)); TEST(file_loader_is_actually_called); TEST(bl::translate("hello").str(l)=="שלום"); } if(iso_8859_8_not_supported) { std::cout << "ISO 8859-8 not supported so skipping non-US-ASCII keys" << std::endl; } else { std::cout << "Testing non-US-ASCII keys" << std::endl; std::cout << " UTF-8 keys" << std::endl; { booster::locale::generator g; g.add_messages_domain("default"); if(argc==2) g.add_messages_path(argv[1]); else g.add_messages_path("./"); std::locale l = g("he_IL.UTF-8"); // narrow TEST(bl::gettext("בדיקה",l)=="test"); TEST(bl::gettext("לא קיים",l)=="לא קיים"); // wide std::wstring wtest = bl::conv::to_utf<wchar_t>("בדיקה","UTF-8"); std::wstring wmiss = bl::conv::to_utf<wchar_t>("לא קיים","UTF-8"); TEST(bl::gettext(wtest.c_str(),l)==L"test"); TEST(bl::gettext(wmiss.c_str(),l)==wmiss); l=g("he_IL.ISO-8859-8"); // conversion with substitution TEST(bl::gettext("test-あにま-בדיקה",l)==bl::conv::from_utf("test--בדיקה","ISO-8859-8")); } std::cout << " `ANSI' keys" << std::endl; { booster::locale::generator g; g.add_messages_domain("default/ISO-8859-8"); if(argc==2) g.add_messages_path(argv[1]); else g.add_messages_path("./"); std::locale l = g("he_IL.UTF-8"); // narrow non-UTF-8 keys // match TEST(bl::gettext(bl::conv::from_utf("בדיקה","ISO-8859-8").c_str(),l)=="test"); // conversion TEST(bl::gettext(bl::conv::from_utf("לא קיים","ISO-8859-8").c_str(),l)=="לא קיים"); } } // Test compiles { bl::gettext(""); bl::gettext(L""); bl::dgettext("",""); bl::dgettext("",L""); bl::pgettext("",""); bl::pgettext(L"",L""); bl::dpgettext("","",""); bl::dpgettext("",L"",L""); bl::ngettext("","",1); bl::ngettext(L"",L"",1); bl::dngettext("","","",1); bl::dngettext("",L"",L"",1); bl::npgettext("","","",1); bl::npgettext(L"",L"",L"",1); bl::dnpgettext("","","","",1); bl::dnpgettext("",L"",L"",L"",1); } } catch(std::exception const &e) { std::cerr << "Failed " << e.what() << std::endl; return EXIT_FAILURE; } FINALIZE(); }
//______________________________________________________________________________ void CalibrateTreeTime(Int_t run) { // Main method. // // configuration // // CB //const Bool_t doFit = kTRUE; //const Char_t* treeName = "CaLib_CB_Time_Tree"; //const Int_t nPar = 720; //const Char_t* data_off = "Data.CB.T0"; //const Char_t* data_gain = 0; //const Char_t* calibration = "LH2_Dec_14"; //const Double_t time_limit = 0.1; //const Double_t bad_frac = 0.05; //gIsTAPS = kFALSE; // TAPS const Bool_t doFit = kTRUE; const Char_t* treeName = "CaLib_TAPS_Time_Tree"; const Int_t nPar = 438; const Char_t* data_off = "Data.TAPS.T0"; const Char_t* data_gain = "Data.TAPS.T1"; const Char_t* calibration = "LH2_Dec_14"; const Double_t time_limit = 0.1; const Double_t bad_frac = 0.05; gIsTAPS = kTRUE; // read TAPS config from config file gMaxTAPS = TCReadConfig::GetReader()->GetConfigInt("TAPS.Elements"); // read calibration parameters gOff = new Double_t[nPar]; gGain = new Double_t[nPar]; Int_t set = TCMySQLManager::GetManager()->GetSetForRun(data_off, calibration, run); printf("Reading set %d for run %d of data '%s' for calibration '%s'\n", set, run, data_off, calibration); TCMySQLManager::GetManager()->ReadParameters(data_off, calibration, set, gOff, nPar); if (data_gain) { TCMySQLManager::GetManager()->ReadParameters(data_gain, calibration, set, gGain, nPar); } else { for (Int_t i = 0; i < nPar; i++) gGain[i] = 0.11771; } // debug //for (Int_t i = 0; i < nPar; i++) // printf("%3d %f %f\n", i, gOff[i], gGain[i]); // open the file Int_t r[1] = { run }; TCARFileLoader file_loader(1, r); if (!file_loader.LoadFiles()) gSystem->Exit(1); TFile* f = file_loader.GetFiles()[0]; if (!f) gSystem->Exit(1); // load tree TTree* tree = (TTree*) f->Get(treeName); gEntries = tree->GetEntries(); // reserve memory gElem_1 = new Short_t[gEntries]; gElem_2 = new Short_t[gEntries]; gRaw_Time_1 = new Float_t[gEntries]; gRaw_Time_2 = new Float_t[gEntries]; // create tree reader TTreeReader reader(tree); // configure reader TTreeReaderValue<Short_t> elem_1(reader, "elem_1"); TTreeReaderValue<Short_t> elem_2(reader, "elem_2"); TTreeReaderValue<Float_t> raw_time_1(reader, "raw_time_1"); TTreeReaderValue<Float_t> raw_time_2(reader, "raw_time_2"); // read tree printf("Reading tree\n"); Long64_t n = 0; while (reader.Next()) { // user info if (n && n % 100000 == 0) printf("%lld events processed (%.1f%%)\n", n, 100*(Double_t)n/(Double_t)gEntries); // skip PWO if (gIsTAPS) { if (TCUtils::IsTAPSPWO(*elem_1, gMaxTAPS) || TCUtils::IsTAPSPWO(*elem_2, gMaxTAPS)) continue; } gElem_1[n] = *elem_1; gElem_2[n] = *elem_2; gRaw_Time_1[n] = *raw_time_1; gRaw_Time_2[n] = *raw_time_2; n++; } // update number of entries gEntries = n; // create histogram TH2* hBefore = CreateHisto("before", nPar, gOff); // perform calibration TStopwatch watch; watch.Start(); if (doFit) { printf("Calibrating using fitting\n"); CalibrateFit(nPar, time_limit, bad_frac); } else { printf("Calibrating using minimization\n"); CalibrateMinimize(nPar); } watch.Stop(); watch.Print(); // create histogram TH2* hAfter = CreateHisto("after", nPar, gOff); // save histograms TFile* fout = new TFile(TString::Format("tree_calib_%d.root", run).Data(), "recreate"); hBefore->Write(); hAfter->Write(); delete fout; // save parameters FILE* fout_a = fopen(TString::Format("tree_calib_%d.dat", run).Data(), "w"); for (Int_t i = 0; i < nPar; i++) fprintf(fout_a, "%lf\n", gOff[i]); fclose(fout_a); // clean-up //delete f; //delete tree; delete [] gOff; delete [] gGain; gSystem->Exit(0); }