//virtual method that will be executed void executeAlgorithm(AlgorithmData& data, AlgorithmContext& context) { //****define algorithm here**** //open native message block std::string nativeHdr="\n*************************NATIVE_OUTPUT*************************\n"; std::cout<<nativeHdr<<std::endl; //open files // input/output directory names specified in configuration file Dataset* input = data.getInputDataset("hist"); Dataset* output = data.getOutputDataset("summaryOut"); //get keyspace elements (files in directory by dimension) Keyspace keyspace = data.getKeyspace(); std::vector<DataKeyElement> names = keyspace.getKeyspaceDimension(DataKeyDimension("NAME")).getElements(); //make summary histogram uint64_t histSummary[4096][4] = {{0}}; long long unsigned int tempSize = 4096 * 4 * sizeof(uint64_t); //... iterate through keys and do work ... for ( std::vector<DataKeyElement>::iterator n=names.begin(); n != names.end(); n++ ) { //print dimension name to stdout std::cout<<*n<<std::endl; //get input data DataKey key = *n; DataFile* file = input->getDataFile(key); char * bytes = file->getBytes(); //make summary histogram uint64_t histTemp[4096][4] = {{0}}; //read input histogram std::memcpy( histTemp, bytes , tempSize ); //add to summary histogram for (int b = 0 ; b < 4 ; ++b) { for (int h = 0 ; h < 4096 ; ++h) { histSummary[h][b] += histTemp[h][b]; } } } //write out summary string std::string outString = "band,"; for (int h=0 ; h < 4096 ; ++h) outString += std::to_string(h) + ","; outString +="\n"; for (int b = 0 ; b < 4 ; ++b){ outString = outString + std::to_string(b+1) + ","; for (int h=0 ; h < 4096 ; ++h){ outString = outString + std::to_string(histSummary[h][b]) + ","; } outString = outString + "\n"; } //write summary to file char* histBytes = new char[outString.length()+1]; std::memcpy ( histBytes, outString.c_str(), outString.length()); long long unsigned int histSize = outString.size() ; DataKey histKey; DataFile* histData = new DataFile(histBytes, histSize, "binary"); output->addDataFile(histKey, histData); //close message block std::cout<<nativeHdr<<std::endl; }
//virtual method that will be executed void executeAlgorithm(AlgorithmData& data, AlgorithmContext& context) { //****define algorithm here**** //open image file // input name specified in configuration file Dataset* input = data.getInputDataset("imageIn"); std::set<DataKey> keys = input->getAllFileKeys(); //... iterate through input keys and do work ... for ( std::set<DataKey>::iterator i = keys.begin(); i != keys.end(); i++ ) { DataKey myKey = *i; DataFile* myFile = input->getDataFile(myKey); int fileSize=myFile->getSize(); char * fileBytes=myFile->getBytes(); //open native message block std::string nativeHdr="\n*************************NATIVE_OUTPUT*************************\n"; std::cout<<nativeHdr<<std::endl; //report image info to stdout std::cout<<" Image Loaded"<<std::endl; std::cout<<" "<<fileSize<<" bytes"<<std::endl; //print original file contents std::cout<<" original file contents: "<<fileBytes; std::vector<WordCount> counter; char *tok; WordCount wc; char mark[] = " .,\n"; int p = 0; int matchflag = 0; int k=0; tok = strtok(fileBytes, mark); while( tok != NULL ){ if(k%2 == 0){ wc.word = tok; } else if(k%2 == 1){ wc.count = atoi(tok); for(p=0; p < counter.size(); p++){ if(strcmp(counter[p].word, wc.word) == 0){ counter[p].count += wc.count; matchflag = 1; break; } } if(matchflag == 0){ counter.push_back(wc); } matchflag = 0; } tok = strtok( NULL, mark); /* 2回目以降 */ k++; } size_t len = counter.size() * (20 + 2); char * textout = (char *)malloc(len + 1); memset(textout, 0, sizeof(textout)); char buf[22]; printf("Answer(size = %d): \n", counter.size()); for(p=0; p < counter.size() - 1; p++){ sprintf(buf, "%s,%d\n", counter[p].word, counter[p].count); strcat(textout, buf); memset(buf, 0, sizeof(buf)); } //print new output file contents printf("%s", textout); //std::cout<<" output file contents: "<<fileBytes; //close message block std::cout<<nativeHdr<<std::endl; // output file in the output folder Dataset* output = data.getOutputDataset("imageOut"); DataFile* fileData = new DataFile(textout, strlen(textout), "testOut.bin"); output->addDataFile(myKey, fileData); } }