Exemple #1
0
  void show_settings_TabHD()
  {
  	static char tmpHDDir[256];
  	static char tmpHDFile[256];

  	if (mainMenu_bootHD==0)
	    radioButton_boothd_off->setSelected(true);
	  else if (mainMenu_bootHD==1)
	    radioButton_boothd_hddir->setSelected(true);
	  else if (mainMenu_bootHD==2)
	    radioButton_boothd_hdfile->setSelected(true);

	  if (strcmp(uae4all_hard_dir, "")==0)
	    textField_hddir->setText("not selected");
	  else
	  {
	    extractFileName(uae4all_hard_dir, tmpHDDir);
	    textField_hddir->setText(tmpHDDir);
	  }

  	if (strcmp(uae4all_hard_file, "")==0)
  	  textField_hdfile->setText("not selected");
  	else
  	{
  	  extractFileName(uae4all_hard_file, tmpHDFile);
  	  textField_hdfile->setText(tmpHDFile);
  	}
  }
// function that creates a roi map from glm and a previously defined roi in mni
void FunctionalConnectivity::createROIVolume(studyParams &vdb)
{
   // Bring MNI Mask to Subject Space
   char outputFile[500], name[500], regionExtractMapFile[500], roiVolumeFile[500];
   double correlationExtractPercent;
   char prefix[30]="_RFI2";
   
   extractFileName(vdb.mniMask, name);
   for (int t=0;t<strlen(name);t++)
      if (name[t] == '.') name[t] = '_';

   sprintf(outputFile, "%s%s%s.nii", vdb.inputDir, name, vdb.trainFeatureSuffix);
   
   MniToSubject(vdb.rfiFile, vdb.mniMask, vdb.mniTemplate, outputFile, prefix);

   // read Region extract map file and percentage
   correlationExtractPercent = vdb.readedIni.GetDoubleValue("FRIEND", "RegionExtractionMapPerc") / 100.0;
   strcpy(regionExtractMapFile, vdb.readedIni.GetValue("FRIEND", "RegionExtractionMapFile"));
   

   RegionExtraction extractor;
   

   // reading the mappings
   std::map<int, int> mappings;
   extractor.readMappings(regionExtractMapFile, mappings);
   
   sprintf(roiVolumeFile, "%s%s%s%s", vdb.outputDir, "ROIsMap", vdb.trainFeatureSuffix, ".nii");
   
   // Execute segmentation
   extractor.regionsExtraction(outputFile, vdb.glmTOutput, vdb.featuresAllTrainSuffix, roiVolumeFile, mappings, correlationExtractPercent);
}
Exemple #3
0
FUNCTION int main (
	
	int	argc,
	TEXT	*argv[]
)

{
VOID	(*converter) (TEXT *,TEXT *);
TEXT	executable[STRINGSIZ+1];
TEXT	outputFile[STRINGSIZ+1];
int	verbose = TRUE;			/* -v not needed for now */
TEXT	*type;
COUNT	lines, cols;
CODE	ttype;

t_pinit (&lines, &cols, &ttype);
f_force_lower (FALSE);				/* take file names literal */
extractFileName (argv[0], executable);
converter = s_equal (executable, "parconvert") ? convertPar : convertRes;
type = s_equal (executable, "parconvert") ? ".par" : ".res" ;
if (argv[1] == NULL || s_equal(executable, "convert") ||
    s_lseq ("-h", argv[1]) || s_equal ("?", argv[1]))
    {
    printf ("usage: parconvert file, ...\n");
    printf ("usage: resconvert file, ...\n");
    printf ("	converts old PAR and RES files to new format\n");
    exit (1);
    }
else if (s_equal ("-v", argv[1]))		/* not really used anymore */
   {
   verbose = TRUE;
   argv ++;					/* files start at argv[2] */
   }
for (argv++; *argv != NULL; argv++)
    {
    extractFileName (*argv, outputFile);
    if (verbose)
#ifdef VMS
	printf ("  Converting %s to []%s%s.",  *argv, outputFile, type); 
#else
	printf ("  Converting %s to ./%s%s.",  *argv, outputFile, type); 
#endif
    (*converter) (*argv, outputFile);
    printf ("\n");
    }
exit (0);					/* normal termination */
}
Exemple #4
0
	VString VDirAdapter_Unix::getFileName() const
	{
        if (NULL == m_pDir || NULL == m_pDirent)
            return "";
        
        if (!m_bExtractName)
        {
            VString strFilePath = m_pDirent->d_name;
            extractFileName(strFilePath, m_strName, m_strTitle);
        }
        
		return m_strName;
	}
Exemple #5
0
void MainForm::saveHtml(QFile *file)
{
    QString text = textEdit->document()->toHtml().toUtf8();
    QString newDir = extractFilePath(file->fileName()) + extractFileName(file->fileName()) + ".files";
    text.replace("<meta name=\"qrichtext\" content=\"1\" />", "<meta content=\"text/html; charset=utf-8\" http-equiv=\"content-type\" />");
    /*text.replace(workingDir + "output_files",  newDir);
    text.replace("[img src=", "<img src=");
    text.replace(".bmp\"]", ".bmp\">");
    text.replace(".bmp]", ".bmp>");
    QDir dir(workingDir+"output_files");
    dir.rename(workingDir+"output_files", newDir);*/
    file->write(text.toAscii());
}
static void checkfilename(char *current)
{
  char actfile[MAX_PATH];
  extractFileName(current, actfile);
  for(int i=0; i<fileList->getNumberOfElements(); ++i)
  {
    if(!fileList->isDir(i) && !strcasecmp(fileList->getElementAt(i).c_str(), actfile))
    {
      lstFiles->setSelected(i);
      selectedOnStart = i;
      break;
    }
  }
}
void XmlTestReporter::AddFailure(std::ostream& os, DeferredTestResult const& result)
{
    os << ">"; // close <test> element

    for (DeferredTestResult::FailureVec::const_iterator it = result.failures.begin(); 
         it != result.failures.end(); 
         ++it)
    {
        string const escapedMessage = XmlEscape(it->second);
        string fileNoPath = extractFileName(result.failureFile);
        string const message = BuildFailureMessage(fileNoPath, it->first, escapedMessage);

        os << "<failure" << " message=\"" << message << "\"" << "/>";
    }
}
Exemple #8
0
void show_settings_Rom()
{
    static char tmpMainRom[256];
    static char tmpExtRom[256];
    static char tmpKeyRom[256];
    if (strcmp(changed_prefs.romfile, "")==0)
        textField_main_rom->setText("insert Kickstart Rom file");
    else {
        extractFileName(changed_prefs.romfile, tmpMainRom);
        textField_main_rom->setText(tmpMainRom);
    }
    if (strcmp(changed_prefs.romextfile, "")==0)
        textField_ext_rom->setText("not selected");
    else {
        extractFileName(changed_prefs.romextfile, tmpExtRom);
        textField_key_rom->setText(tmpExtRom);
    }
    if (strcmp(changed_prefs.keyfile, "")==0)
        textField_key_rom->setText("not selected");
    else {
        extractFileName(changed_prefs.keyfile, tmpKeyRom);
        textField_key_rom->setText(tmpKeyRom);
    }
}
void transformDicom(char *filename, char *outdir)
{
	TDCMopts opts;
	char auxFile[1024];

	defaultOptions(opts, outdir);

	changeFileExt(filename, "", auxFile);
	extractFileName(auxFile, opts.filename);
//	opts.isVerbose = 2;
	if (0)
	{
		strcpy(opts.indir, filename);
		nii_loadDir(&opts);
	}
	else singleDICOM(&opts, filename);
}
Exemple #10
0
	VString VDirAdapter::getFileName() const
	{
		if (m_hFindFile == INVALID_HANDLE_VALUE)
			return "";

		if (!m_bExtractName)
		{
#ifdef UNICODE
			char szPath[512] = {0};
			::WideCharToMultiByte(CP_UTF8, 0, m_FindFileData.cFileName, MAX_PATH, szPath, sizeof(szPath), nullptr, nullptr);
			VString strFilePath(szPath);
#else
			VString strFilePath = m_FindFileData.cFileName;
#endif
			extractFileName(strFilePath, m_strName, m_strTitle);
		}

		return m_strName;
	}
Exemple #11
0
	bool VDirAdapter::isDots() const
	{
		if (m_hFindFile == INVALID_HANDLE_VALUE)
			return false;

		if (!m_bExtractName)
		{
#ifdef UNICODE
			char szPath[512] = {0};
			::WideCharToMultiByte(CP_UTF8, 0, m_FindFileData.cFileName, MAX_PATH, szPath, sizeof(szPath), nullptr, nullptr);
			VString strPath(szPath);
#else
			VString strPath = m_FindFileData.cFileName;
#endif
			extractFileName(strPath, m_strName, m_strTitle);
		}

		return ((m_FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (m_strName == "." || m_strName == ".."));
	}
/**@brief main entry point of the program

	This program will process the command line arguments pulling the audio
	file and pulling the text transcription (if any)

	It will then use the appropriate engine to perform the lipsync.
**/
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	CoInitializeEx(NULL, COINIT_MULTITHREADED);

	if( argc < 2 )
	{
		usage(std::cerr);
		return -1;
	}

	if( TCHAR_2_wstring(argv[1]).compare(L"/all" ) == 0)
	{
		DIR *dir;
		struct dirent *ent;
		bool filesFound = false;
                
		/* Open directory stream */
		dir = opendir (".");
		if (dir != NULL)
		{
			while ((ent = readdir (dir)) != NULL)
			{
				if (ent->d_type == DT_REG)
				{
					std::wstring strAudioFile = TCHAR_2_wstring(ent->d_name);
					std::wstring outFile, extension;
					extractFileName( strAudioFile, &outFile, &extension);

					if (extension.compare(L"wav") == 0 || extension.compare(L"WAV") == 0)
					{
						// Check for text file with same name
						std::string textFileName = wstring_2_string(outFile) + ".txt";
						struct stat info;
						int status = stat(textFileName.c_str(), &info);
						filesFound = true;

						// lipsync!
						if(status == 0)
						{
							banner(std::cerr, strAudioFile, (TCHAR*)textFileName.c_str());
							run_sapi_textbased_lipsync(strAudioFile, (TCHAR*)textFileName.c_str(), outFile);
						}
						else
						{
							banner(std::cerr, strAudioFile, 0x0);
							run_sapi_textless_lipsync(strAudioFile, outFile);
						}
					}
				}
			}
			closedir (dir);

		}
		else
		{
			printf ("Cannot open directory!\n");
		}

		if (!filesFound)
			printf ("WARNING: No wav files in execution directory found, aborting..\n");
	}
	else
	{
	
		TCHAR *strTextFile = NULL;
		std::wstring strAudioFile = TCHAR_2_wstring(argv[1]);
		std::wstring outFile;
		extractFileName( strAudioFile, &outFile );

		for( int i = 2; i < argc; ++i )
		{
			if( TCHAR_2_wstring(argv[i]).compare(L"-o" ) == 0 )
			{
				if( argc > i + 1 )
				{	
					outFile = TCHAR_2_wstring(argv[++i]);
				}
				else
				{
					std::cout << "Invalid argument";
					CoUninitialize();
					return 0;
				}
			}
			else if( TCHAR_2_wstring(argv[i]).compare(L"-t" ) == 0 )
			{
				if( argc > i + 1 )
				{
					strTextFile = argv[++i];
				}
				else
				{
					std::cout << "Invalid argument";
					CoUninitialize();
					return 0;
				}
			}
			else
			{
				std::cout << "Invalid argument";
				CoUninitialize();
				return 0;
			}
		}

		banner(std::cerr, strAudioFile, strTextFile);	

		// lipsync!
		if (strAudioFile.size() && strTextFile)
		{
			run_sapi_textbased_lipsync(strAudioFile, strTextFile, outFile);
		}
		else if (strAudioFile.size())
		{
			run_sapi_textless_lipsync(strAudioFile, outFile);
		}		
		else
		{
			usage(std::cerr);
		}
	}

	CoUninitialize();
	return (0);
}
CLogSerializer::CLogSerializer(const char* fileName)
{
    m_FilePath.append(fileName);
    Init();
    extractFileName(m_FilePath, m_FileName);//
}
// spark::StreamLogHandler
void spark::StreamLogHandler::logMessage(const char *msg, LogLevel level, const char *category, const LogAttributes &attr) {
    char buf[16];
    // Timestamp
    if (attr.has_time) {
        snprintf(buf, sizeof(buf), "%010u ", (unsigned)attr.time);
        write(buf);
    }
    // Category
    if (category) {
        write("[");
        write(category);
        write("] ");
    }
    // Source file
    if (attr.has_file) {
        // Strip directory path
        const char *s = extractFileName(attr.file);
        write(s); // File name
        if (attr.has_line) {
            write(":");
            snprintf(buf, sizeof(buf), "%d", attr.line); // Line number
            write(buf);
        }
        if (attr.has_function) {
            write(", ");
        } else {
            write(": ");
        }
    }
    // Function name
    if (attr.has_function) {
        // Strip argument and return types for better readability
        size_t n = 0;
        const char *s = extractFuncName(attr.function, &n);
        write(s, n);
        write("(): ");
    }
    // Level
    write(levelName(level));
    write(": ");
    // Message
    if (msg) {
        write(msg);
    }
    // Additional attributes
    if (attr.has_code || attr.has_details) {
        write(" [");
        if (attr.has_code) {
            write("code");
            write(" = ");
            snprintf(buf, sizeof(buf), "%" PRIiPTR, attr.code);
            write(buf);
        }
        if (attr.has_details) {
            if (attr.has_code) {
                write(", ");
            }
            write("details");
            write(" = ");
            write(attr.details);
        }
        write("]");
    }
    write("\r\n");
}
Exemple #15
0
string AppBusiness::getAppHelp()
{
    return formatString("Usage: %s ip\n",
        extractFileName(getAppExeName()).c_str());
}
Exemple #16
0
static int menuLoadLoop(char *curr_path)
{
	char *ret = NULL, *fname = NULL;
	struct dirent **namelist;
	DIR *dir;
	int n, sel = 0;
	int sel_last = 0;
	unsigned long inp = 0;

	min_in_dir=0;
	max_in_dir=SHOW_MAX_FILES;

	// is this a dir or a full path?
	if ((dir = opendir(curr_path)))
		closedir(dir);
	else 
	{
		char *p;
		for (p = curr_path + strlen(curr_path) - 1; p > curr_path && *p != '/'; p--);
		*p = 0;
		fname = p+1;
	}

#ifdef ANDROIDSDL
	n = scandir(curr_path, &namelist, scandir_filter, 0);
#else	
	n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp);
#endif
	
	if (n < 0) 
	{
		// try root
#ifdef ANDROIDSDL
		n = scandir("/", &namelist, scandir_filter, 0);
#else
		n = scandir("/", &namelist, scandir_filter, scandir_cmp);
#endif
		if (n < 0) 
		{
			// oops, we failed
			printf("dir: "); printf(curr_path); printf("\n");
			perror("scandir");
			return 0;
		}
	}
	if (n<10) usleep(70*1024);
	else usleep(40*1024);
	// try to find sel
	if (fname != NULL) 
	{
		int i;
		for (i = 1; i < n; i++) 
		{
			if (strcmp(namelist[i]->d_name, fname) == 0) 
			{
				sel = i - 1;
				break;
			}
		}
	}

	int loaded=0;
	int delay=0;
	SDL_Event event;
	int left=0, right=0, up=0, down=0, hit0=0, hit1=0, hit2=0, hit3=0, hit4=0, hitL=0;
	while(hit0+hit1+hitL==0)
	{
		//unsigned long keys;
		draw_dirlist(curr_path, namelist, n, sel);
		delay ++;
		left=right=up=down=hit0=hit1=hit2=hit3=hit4=hitL=0;
		while (SDL_PollEvent(&event) > 0 && hit0+hit1+hitL==0)
		{
			if (event.type == SDL_KEYDOWN)
			{
				uae4all_play_click();
				switch(event.key.keysym.sym)
				{
					case SDLK_RIGHT: right=1; break;
					case SDLK_LEFT: left=1; break;
					case SDLK_UP: up=1; break;
					case SDLK_DOWN: down=1; break;
					case SDLK_PAGEDOWN: hit0=1; break;
					case SDLK_HOME: hit0=1; break;
					case SDLK_LALT: hit1=1; break;
					case SDLK_LCTRL: hit2=1; break;
					case SDLK_RSHIFT: hit3=1; break;
					case SDLK_RCTRL: hit4=1; break;
					case SDLK_END: hit0=1; break;
					case SDLK_PAGEUP: hit0=1; break;
					case SDLK_l: hitL=1;
				}
			}
			if(up)  { sel--;   if (sel < 0)   sel = n-2; /*usleep(10*1024);*/ }
			if(down)  { sel++;   if (sel > n-2) sel = 0;/*usleep(10*1024);*/}
			if(left)  { sel-=10; if (sel < 0)   sel = 0;/*usleep(10*1024);*/}
			if(hit3)     { sel-=24; if (sel < 0)   sel = 0;/*usleep(10*1024);*/}
			if(right) { sel+=10; if (sel > n-2) sel = n-2;/*usleep(10*1024);*/}
			if(hit4)     { sel+=24; if (sel > n-2) sel = n-2;/*usleep(10*1024);*/}
			if(hit2)     { run_menuFileinfo(namelist[sel+1]->d_name);}
			if(hit0 || hitL)
			{
				if (namelist[sel+1]->d_type == DT_REG) 
				{
					int df;
					int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;
					char *p; 
					char *filename;
					filename=(char*)malloc(newlen);
					strcpy(filename, curr_path);
					p = filename + strlen(filename) - 1;
					while (*p == '/' && p >= filename) *p-- = 0;
					strcat(filename, "/");
					strcat(filename, namelist[sel+1]->d_name);
					printf("Selecting file %s\n",filename);
					switch (menu_load_type)
					{
						case MENU_LOAD_FLOPPY:
							if (current_drive==0){strcpy(uae4all_image_file0,filename);extractFileName(uae4all_image_file0, filename0);df=0;}
							else if(current_drive==1) {strcpy(uae4all_image_file1,filename);extractFileName(uae4all_image_file1, filename1);df=1;}
							else if(current_drive==2) {strcpy(uae4all_image_file2,filename);extractFileName(uae4all_image_file2, filename2);df=2;}
							else if(current_drive==3) {strcpy(uae4all_image_file3,filename);extractFileName(uae4all_image_file3, filename3);df=3;}
							printf("DF0 %s\n",uae4all_image_file0);
							break;
						case MENU_LOAD_HDF:
							if (strstr(filename, ".hdf") == NULL)
								showWarning("HDF file must be selected");
							else
								strcpy(uae4all_hard_file, filename);
							break;
					}
					loaded=1;
					strcpy(currentDir,filename);
					free(filename);
					break;
				}
				else if (namelist[sel+1]->d_type == DT_DIR)
				{
					int newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;
					char *p;
					char *newdir;
					/* Hard file dir is being selected ? (L-key is used to select dir) */
					if ((menu_load_type == MENU_LOAD_HD_DIR) && hitL)
					{
						strcpy(uae4all_hard_dir, curr_path);
						strcat(uae4all_hard_dir, "/");
						strcat(uae4all_hard_dir, namelist[sel+1]->d_name);
						loaded = 1;
						break;
					}
					else
					{
						newdir=(char*)malloc(newlen);
						if (strcmp(namelist[sel+1]->d_name, "..") == 0) 
						{
							char *start = curr_path;
							p = start + strlen(start) - 1;
							while (*p == '/' && p > start) p--;
							while (*p != '/' && p > start) p--;
							if (p <= start) strcpy(newdir, "/");
							else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }
						} 
						else 
						{
							strcpy(newdir, curr_path);
							p = newdir + strlen(newdir) - 1;
							while (*p == '/' && p >= newdir) *p-- = 0;
							strcat(newdir, "/");
							strcat(newdir, namelist[sel+1]->d_name);
						}
						strcpy(currentDir,newdir);
						loaded = menuLoadLoop(newdir);
						free(newdir);
						break;
					}
				} 
			}
			if(hit1)
				break;
		}
	}
	if (n > 0) 
	{
		while(n--) free(namelist[n]);
		free(namelist);
	}

	return loaded;
}
Exemple #17
0
void MainForm::loadFile(const QString &fn, bool loadIntoView)
{
    QCursor oldCursor = cursor();
    setCursor(Qt::WaitCursor);
    if ((fileName != "") && (sideBar->getFileNames().contains(fileName))) {
        sideBar->select(fileName);
        sideBar->clearBlocks();
        for (int i = 0; i < graphicsInput->blocksCount(); i++)
            sideBar->addBlock(graphicsInput->getBlockRectByIndex(i).toRect());
    }
    qreal xrotation = 0;
    QRect crop1(0, 0, 0, 0);
    double scaleFactor = 0.5;
    if (sideBar->fileLoaded(fn)) {
        sideBar->select(fn);
        xrotation = sideBar->getRotation();
        scaleFactor = sideBar->getScale();
        crop1 = sideBar->getCrop1();
    } else {
        //xrotation = sideBar->getRotation();
        //scaleFactor = sideBar->getScale();
    }

    QImage image;
    if ((imageLoaded = image.load(fn))) {
        //pixmap.detach();
        //sideBar->addFile(fn , &image);
        if (settings.getCropLoaded()) {
            if (crop1.height() == 0) {
                CCBuilder * cb = new CCBuilder(image);
                cb->setGeneralBrightness(360);
                cb->setMaximumColorComponent(100);
                QRect r = cb->crop();
                delete cb;
                image = image.copy(r);
                //sideBar->setCrop1(r);
                crop1 = r;
            } else {
                image = image.copy(crop1);
            }
        }

    } else {
        setCursor(oldCursor);
        QMessageBox::critical(this, trUtf8("Image loading error"), trUtf8("Image %1 could not be loaded").arg(fn));
        return;
    }

    if (!loadIntoView) {
        setCursor(oldCursor);
        return;
    }
    if (imageLoaded) {
        fileName = fn;
        setWindowTitle("YAGF - " + extractFileName(fileName));
        graphicsInput->loadImage(image);
        sideBar->addFile(fn , graphicsInput->getImageBy16());
        sideBar->setCrop1(crop1);
        sideBar->setScale(scaleFactor);
        graphicsInput->setViewScale(0.5, xrotation);
        for (int i = 0; i < sideBar->getBlocksCount(); i++)
            graphicsInput->addBlock(sideBar->getBlockByHalf(i));
        graphicsInput->setViewScale(scaleFactor, 0);
        // ((FileToolBar *) m_toolBar)->setRotation(xrotation);
        //  ((FileToolBar *) m_toolBar)->setScale(graphicsInput->getRealScale());
        if (scaleFactor == 1) {
            if (image.width() > 4000)
                scaleImage(0.25);
            else if (image.width() > 2000)
                scaleImage(0.5);
        }
        graphicsInput->setFocus();
    } else {
       // sideBar->addFile(fn);
    }
    scaleFactor = 1;
    setCursor(oldCursor);
}
Exemple #18
0
void SetLastActiveConfig(const char *filename)
{
  extractFileName(filename, last_active_config);
  removeFileExtension(last_active_config);
}
// function that creates a roi map from glm and a previously defined roi in mni
void emotionRoiProcessing::createROIVolume(studyParams &vdb)
{
	// Bring MNI Mask to Subject Space
	char compositeFile[500], outputFile[500], name[500], regionExtractMapFile[500], roiVolumeFile[500], meanFile[500];
	char pngFile[500];
	double correlationExtractPercent;
	stringstream CmdLn;
	char prefix[30] = "_RFI2";
	vector<vector<double>> timeseries;

	// generating the means file
	volume<float> v;

	// preparing timeseries variable
	timeseries.resize(meanCalculation.roiCount());
	for (int i = 0; i < timeseries.size(); i++)
		timeseries[i].resize(vdb.interval.maxIndex());

	// calculating the means
	for (int i = 0; i < vdb.interval.maxIndex(); i++)
	{
		loadVolume(vdb, v, i+1);
		meanCalculation.calculateMeans(v);

		for (int j = 0; j < meanCalculation.roiCount(); j++)
			timeseries[j][i] = meanCalculation.roiMean(j);
	}

	// z normalized
	for (int j = 0; j < timeseries.size(); j++)	znormalise(timeseries[j]);

	// saving the result to file
	sprintf(meanFile, "%s%s_%s%s.txt", vdb.outputDir, vdb.subject, "means", vdb.trainFeatureSuffix);
	fstream Output(meanFile, fstream::in | fstream::out | fstream::trunc);
	for (int i = 0; i < vdb.interval.maxIndex(); i++)
	{
		for (int j = 0; j < timeseries.size(); j++)
			Output << timeseries[j][i] << '\t';
		Output << '\n';
	}
	Output.close();

	// generating the roi means graph png
	fprintf(stderr, "Generating roi means graphic\n");
	changeFileExt(meanFile, ".png", pngFile);
	CmdLn << "fsl_tsplot -i " << meanFile << " -t \"z-normalised roi means plot\" -u 1 --start=1 --finish=" << meanCalculation.roiCount() << " -a ";

	vector<int> roiValues;
	meanCalculation.getRoiValues(roiValues);
	// Building the labels with the intensities of the roi volume file
	int counter=0;
	CmdLn << '\"';
	for (int t = 0; t < roiValues.size(); t++)
	{
		CmdLn << "Intensity " << roiValues[t];
		counter++;
		if (counter < meanCalculation.roiCount())
			CmdLn << ',';
	}
	// completing the command
	CmdLn << '\"';
	CmdLn << " -w 640 -h 144 -o " << pngFile;
	fsl_tsplot((char *)CmdLn.str().c_str());


	extractFileName(vdb.mniMask, name);
	for (int t = 0; t<strlen(name); t++)
	if (name[t] == '.') name[t] = '_';

	sprintf(outputFile, "%s%s%s.nii", vdb.inputDir, name, vdb.trainFeatureSuffix);

	MniToSubject(vdb.maskFile, vdb.mniMask, vdb.mniTemplate, outputFile, prefix);

	// saving a composite file just to assure the side of the roi volume
	sprintf(compositeFile, "%s%s%s.nii", vdb.inputDir, "compositeFile", vdb.trainFeatureSuffix);
	uniteVolumes(vdb.rfiFile, outputFile, compositeFile);

	// read Region extract map file and percentage
	correlationExtractPercent = vdb.readedIni.GetDoubleValue("FRIEND", "PercentageOfBestVoxelsPerROI") / 100.0;
	strcpy(regionExtractMapFile, vdb.readedIni.GetValue("FRIEND", "ROIExtractionMapFile"));


	RegionExtraction extractor;


	// reading the mappings
	std::map<int, int> mappings;
	extractor.readMappings(regionExtractMapFile, mappings);

	sprintf(roiVolumeFile, "%s%s%s%s", vdb.outputDir, "ROIsMap", vdb.trainFeatureSuffix, ".nii");

	// Execute segmentation
	extractor.regionsExtraction(outputFile, vdb.glmTOutput, vdb.featuresAllTrainSuffix, roiVolumeFile, mappings, correlationExtractPercent);

	// calculate initial target values for positive and negative conditions
	if (fileExists(roiVolumeFile))
	{
		meanCalculation.loadReference(roiVolumeFile);
		positiveIndex = meanCalculation.roiIndex(3); // 3 in the intensity value of positive emotion ROI
		negativeIndex = meanCalculation.roiIndex(1); // 1 in the intensity value of negative emotion ROI

		for (int i=1; i <= vdb.interval.maxIndex(); i++)
		{
			float classnum, projection;
			processVolume(vdb, i, classnum, projection);
		}

		char negativeCurveFile[BUFF_SIZE], positiveCurveFile[BUFF_SIZE];
		sprintf(negativeCurveFile, "%s%c%s%s.txt", vdb.outputDir, PATHSEPCHAR, "negative_curve", vdb.trainFeatureSuffix);
		sprintf(positiveCurveFile, "%s%c%s%s.txt", vdb.outputDir, PATHSEPCHAR, "positive_curve", vdb.trainFeatureSuffix);

		positiveActivationLevel.saveCurves(positiveCurveFile);
		negativeActivationLevel.saveCurves(negativeCurveFile);

		vdb.readedIni.SetDoubleValue("FRIEND", "NegativeActivationLevel", negativeActivationLevel.mean);
		vdb.readedIni.SetDoubleValue("FRIEND", "PositiveActivationLevel", positiveActivationLevel.mean);
		vdb.readedIni.SaveFile(vdb.configFileNameRead);
	}
}