Glossary Item Box

NSHelp: Condition Consistency CheckingExperiment PropertiesProcessing Time functionsProcessing Segmentation SettingsProcessing Extraction SettingsWord ExtractionProcessing SummarizationStroke Description

See Also NeuroScript MovAlyzeR Help Send comments on this topic.

External Processing Support

External Processing

Matlab® and other external scripts

MovAlyzeR supports integration with Matlab and other programming environments during processing. This section explains run-time integration (only during processing) of external applications with MovAlyzeR. For information about importing MovAlyzeR output files into other programs like Matlab see Using MovAlyzeR data in Matlab.

Processing of data in MovAlyzeR maybe broken down into the following steps (refer MovAlyzer process flow)

Recording > Time functions > Segmentation > Extraction > Consistency checking > Summarization > Analysis

When external processing of data is enabled, the process flow could be modified to

Time functions > External ScriptSegmentation > External Script > Extraction > External Script > Consistency Checking

External Script may mean either a Matlab script or a Batch file that invokes other programs.

 

Setup external processing

Right click on Experiment name > Properties > Processing > External Apps

No script

MovAlyzeR processes the data using the default internal algorithms.

Matlab® script

Select this option to modify processed data using Matlab. Input the matlab program you intend to use in the editor and save. Matlab must be installed on the computer in order to use this option. See example below.

Batch file

Create a batch file to execute another executable file or invoke a computing engine. The .bat file offers an easy way to launch external programs.

 

Example 1: Using Matlab

How to append data columns to MovAlyzeR's .EXT file


This example will show you how to append user-generated parameters to MovAlyzeR's .EXT file. The .EXT file has all the kinematic parameters extracted from the handwriting sample.

 

Step1: Create and test your matlab program

First we will create a program that reads the  .HWR and .EXT files created by MovAlyzeR. It calculates some simple features from the .HWR file and finally appends them to the .EXT file.

 

Create your matlab program and test it for logic and functionality. MovAlyzeR has limited debugging features. Hence this step is best done in an external environment like Matlab itself.

 

 

MatExample.m Copy Code

function matexample(hwrfile, extfile)

% Program to calculate spiral features and append to MovAlyzeR .EXT file

% hwrfile - File with raw x, y and z data

% extfile - File with parameters extracted by MovAlyzeR

 

% Step1: Read .HWR data

xyzdata = dlmread(hwrfile);

 

% Step2: Use the data to make calculations

% Example calculation1: #samples

NumOfSamples = length(xyzdata);

% Example calculation2: Leftmost X coordinate

LeftXCoord = min(xyzdata(:,1));

 

% Step3: Read EXT file

fExt = fopen(extfile, 'r');

extheader = fgetl(fExt);

extdata = dlmread(extfile, ' ', 1, 0);

fclose(fExt);

% These are the number of parameters in a default MovAlyzeR .EXT file

numextheader = sum(isspace(extheader)) + 1;

% Parameters to append

header = 'NumOfSamples LeftXCoordinate';

numheader = sum(isspace(header)) + 1;

% Final header

outputheader = [extheader ' ' header];

 

% Step4: Open output file

tmpfile = strcat(extfile(1:end-4),'.TMP');

fTmp = fopen(tmpfile, 'w');

 

% Step5: Check each line of EXT file data and update accordingly

trialnumber = str2double( strtok( hwrfile( end-5 : end-4 ) ) );

LARGE = 999999;

if ~isempty(extdata) && fTmp ~= -1

% Output header

fprintf(fTmp, '%s\n', outputheader);

for itrial = 1:length(extdata(:,1))

% Case 1: Trial is not relevant

if extdata(itrial, 1) ~= trialnumber

extdata(itrial, numextheader+1:numextheader+numheader) = -LARGE;

end

% Case 2: Trial is relevant

if extdata(itrial, 1) == trialnumber

extdata(itrial, numextheader+1:numextheader+numheader) = [NumOfSamples LeftXCoord];

end

% Output trial data

fprintf(fTmp, '%f ', extdata(itrial, :));

fprintf(fTmp, '\n');

end

% Close output file

fclose(fTmp);

end

 

% Step6: Delete Extfile, rename TMP file > EXT file

movefile(tmpfile, extfile);

end

Save this file as MatExample.m in the Scripts folder of your experiment. To do this:

In MovAlyzeR, go to Settings > Data Path and Settings > Data Path and copy the {data path}

The Data Path is the location of your experiment folder. The location of the scripts folder is {data path}\scripts

 

Step 2: Enter your program into MovAlyzer

Right click your Experiment Name > Properties > Processing > External Apps

A dialog may pop-up 'MovAlyzeR will now check to see if Matlab is installed'. Click OK to ensure that MovAlyzeR recognizes the Matlab installation.

Under the EXT: Post-Feature Extraction section select Matlab from the Application drop-down menu. Then click on the edit button to open the Script Editor.

 

Here we will enter our second Matlab script. This will parse the HWR and EXT filenames and then call MatExample.m

 

MatDemo.m Copy Code

clear all;

% Get filenames

hwrfile = '%HWR%';

extfile = '%EXT%';

% Set current working directory

scriptfolder = [hwrfile(1:end-30) 'scripts'];

cd(scriptfolder);

% Run MatExample.m

MatExample(hwrfile, extfile);

 

The Browse button in the lower left corner of the Script Editor can be used to open up existing Matlab or BAT files. The existing script that is opened will be saved to the \Scripts folder in the MovAlyzeR user folder.

 

Notice how the HWR file has been referenced as %HWR%. This is a macro to reference MovAlyzeR files in Matlab scripts in the integration environment. MovAlyzeR will expand the reference and fill in the correct path with the filename so the user does not have to keep track of this.

The following references are legal:

%HWR%  Raw coordinates file

%TF%     Time function file with filtered data

%SEG%   Segmented into strokes

%EXT%   Extracted kinematic features

 

Save this script as MatDemo.m. Finally select MatDemo.m from the Script dropdown menu and click OK. Now this Matlab script will be run every time a trial is processed.

 

Step 3: Reprocess your trials in MovAlyzeR

This experiment is now set to append the calculated parameters to the EXT file every time a trial is processed or reprocessed.

 

Original EXT file EXT file with appended parameters

 

 

Similar scripts maybe used to modify the other processing files in MovAlyzeR. See also Using MovAlyzeR data in Matlab

 

WARNING Once a raw data file (.HWR with x, y, z coordinates) has been modified, the data cannot be retrieved. Please backup all your data before modifying the raw data files.

 

Example 2 Using BAT files and executable program in C/C++

Program to calculate the maximum width and height of each stroke and append to EXT file

 

Step 1: Create and test your C program

 

We will write a program in C to read processed data from the TF file, read the segmentation points from the SEG file, calculate the maximum height and width of each stroke and append the results to the EXT file.

 

Example C program Copy Code
/**********************************************************/
/* Program to calculate additional kinematic parameters
and append them to the EXT file of MovAlyzeR. This program
is meant to be used as an external app. It interfaces with
MovAlyzeR using liextension.bat
Features appended:
StrokeWidth - Max horizontal displacement in stroke
StrokeHeight - Max vertical displacement in stroke
*/
/*********************************************************/
#include <iostream>
#include <string>
#include <atlstr.h>
#include <fstream>
#include <cmath>
using namespace std;
int readhwr (const char* fIn, double* x, double* y, double* z);
int readtf (const char* fIn, double* x, double* y);
int readseg (const char* fIn, double* seg, int nseg);
inline double SQR (double val){ return (val*val); }
#define NSMAX 4096
#define NSEGMAX 1000
#define MAXVALUE -999999.
#define MINVALUE 999999.
#define ROUNDUP 0.999
#define PRSMIN 0
#define MINSEGTIME 0.04
int main(int argc, char ** argv)
{
// Show output if debugging is on
BOOL DEBUGOUTPUT = ((int)strtod(argv[9], NULL) == 1) ? TRUE : FALSE;
if(DEBUGOUTPUT)
{
cout
<< "******************************************************" << endl;
cout
<< "* Program to evaluate StrokeWidth, StrokeHeight. *" << endl;
cout
<< "* Calculated parameters appended to EXT file. *" << endl;
cout
<< "* (c) NeuroScript LLC *" << endl;
cout
<< "******************************************************" << endl;
char* list[10];
list[0]
= "Program name";
list[1]
= "File path";
list[2]
= "Experiment";
list[3]
= "Group";
list[4]
= "Subject";
list[5]
= "Condition";
list[6]
= "Trial";
list[7]
= "Hz, Sampling rate";
list[8]
= "lines/cm, Input device resolution";
list[9]
= "Debug ON";
cout
<< "Number of input arguments=" << argc << endl;
for( int i = 0; i < argc ; i++)
cout
<< argv[i] << " " << list[i] << endl;
}
if (argc < 9)
{
cout
<< "Not enough input parameters. Exiting..." << endl;
cout
<< "Press ENTER to exit...";
cin
.get();
exit(0);
}
/*****************************************/
/* Parse input arguments from batch file */
/*****************************************/
string root(argv[1]);
string exp (argv[2]);
string grp (argv[3]);
string sub (argv[4]);
string con (argv[5]);
string trl (argv[6]);
int trial = (int)strtod(argv[6],NULL);
double sec = strtod(argv[7], NULL);
// Convert sampling rate to seconds
sec = (sec != 0)? 1/sec : 0;
double cm = strtod(argv[8], NULL);
// Construct filenames
string hwrfile = root + "\\" + exp + grp + sub + con + trl + ".HWR";
string tffile
= root + "\\" + exp + grp + sub + con + trl + ".TF";
string segfile
= root + "\\" + exp + grp + sub + con + trl + ".SEG";
string extfile
= root + "\\" + exp + grp + sub + con + ".EXT";
string tmpfile
= root + "\\" + exp + grp + sub + con + ".TMP";
// Constants
double maxx = MAXVALUE;
double minx = MINVALUE;
double maxy = MAXVALUE;
double miny = MINVALUE;
// Other variables
int trialinfile;
int i, j, spaces = 0;
int spacesinheader;
string line, temp;
BOOL EXISTS;
// Parameters that will be calculated
string header("StrokeWidth StrokeHeight");
spacesinheader
= 0;
for ( i = (int)header.size()-1 ; i > 0 ; i-- )
{
spacesinheader
+= (header.at(i) == ' ');
}
// Output files
ifstream fExt(extfile.c_str());
ofstream fTmp(tmpfile
.c_str());
// Allocate arrays for coordinate data
double* x = new double [NSMAX];
double* y = new double [NSMAX];
memset ( x, 0, NSMAX
* sizeof(double) );
memset ( y, 0, NSMAX
* sizeof(double) );
int nsam = 0;
// Find number of segments to allocate memory for
ifstream fSeg(segfile.c_str());
int nseg = 0;
if (fSeg.is_open())
{
// Segment header
getline(fSeg, line);
nseg
= (int)strtod(line.c_str(), NULL);
}
fSeg
.close();
nseg
= min(nseg, NSEGMAX);
// Segment array
double* seg = new double [nseg];
memset (seg, 0, nseg
* sizeof(double));
int iseg, segbegin, segend;
// Extracted parameters
// These will be appended to the existing .EXT file
double *strokewidth = new double [nseg];
double *strokeheight = new double [nseg];
memset (strokewidth, 0, nseg
* sizeof(double));
memset (strokeheight, 0, nseg
* sizeof(double));
/********************/
/* Read data points */
/********************/
nsam = readtf (tffile.c_str(), x, y);
nseg
= readseg (segfile.c_str(), seg, nseg );
// Convert seg points in seconds to samples
for ( iseg = 0 ; iseg < nseg ; iseg++)
{
seg [iseg]
/= sec;
}
/*************************/
/* Process every segment */
/*************************/
for ( iseg = 0; iseg < nseg - 1 ; iseg++ )
{
maxx
= MAXVALUE;
minx
= MINVALUE;
maxy
= MAXVALUE;
miny
= MINVALUE;
segbegin
= (int)(seg[iseg] + ROUNDUP);
segend
= (int)(seg[iseg+1] + ROUNDUP);
for ( j = segbegin ; j < segend ; j++ )
{
/* Stroke width */
if ( x[j] > maxx )
maxx
= x[j];
if ( x[j] < minx )
minx
= x[j];
/* Stroke height */
if ( y[j] > maxy )
maxy
= y[j];
if ( y[j] < miny )
miny
= y[j];
}
strokewidth[iseg]
= maxx - minx;
strokeheight[iseg]
= maxy - miny;
}
// Read data from EXT file line by line
// Write to TEMP file after appending parameters calculated in this file
// Copy the entire TEMP file back to EXT file
if ( fExt.is_open() && fTmp.is_open() && nseg > 0)
{
// Read EXT header
getline( fExt, line);
if (line.empty())
{
cout
<< "The EXT file is empty. Press Enter to Exit..." << endl;
cin
.get();
goto Cleanup;
}
else if (line.compare(line.size()-header.size(), line.size()-1, header) == 0)
{
fTmp
<< line << endl;
EXISTS
= TRUE;
}
else
{
fTmp << line << " " << header << endl;
EXISTS
= FALSE;
}
iseg
= 0;
// Output line by line
while ( !getline(fExt, line).eof() )
{
// Read trial number at beginning of line
trialinfile = (int)strtod(line.c_str(), NULL);
// Check if parameters already exist
spaces = 0;
for ( i = (int)line.size()-1 ; i > 0 ; i-- )
{
spaces
+= (line.at(i) == ' ');
}
EXISTS
= (spaces > 29) ? TRUE : FALSE;
// Case 1: Trial is not relevant and has no previous params field
if (trialinfile != trial && !EXISTS)
{
fTmp
<< line;
for (i = 0; i < spacesinheader+1 ; i++)
fTmp
<< " " << MAXVALUE ;
fTmp
<< endl;
}
// Case 2: Trial is not relevant and has previous params field
if (trialinfile != trial && EXISTS)
{
fTmp
<< line << endl;
}
// Case 3: Trial is relevant and has no previous params field
if (trialinfile == trial && !EXISTS)
{
if (nseg > 1)
{
fTmp
<< line << " " << strokewidth[ iseg % (nseg - 1)] <<
" " << strokeheight[ iseg % (nseg - 1)] << endl;
}
else
{
fTmp << line;
for (i = 0; i < spacesinheader+1 ; i++)
fTmp
<< " " << MAXVALUE ;
fTmp
<< endl;
}
iseg
++;
}
// Case 4: Trial is relevant and has previous params field
if (trialinfile == trial && EXISTS)
{
spaces
= 0;
// Match number of spaces in header to number of spaces in current line that was read, i has the required location
for ( i = (int)line.size()-1 ; i > 0 ; i-- )
{
spaces
+= (line.at(i) == ' ');
if (spaces == spacesinheader+1)
break;
}
line
= line.substr(0,i);
if (nseg > 1)
{
fTmp
<< line << " " << strokewidth[ iseg % (nseg - 1)] <<
" " << strokeheight[ iseg % (nseg - 1)] << endl;
}
else
{
fTmp << line;
for (i = 0; i < spacesinheader+1 ; i++)
fTmp
<< " " << MAXVALUE ;
fTmp
<< endl;
}
iseg
++;
}
}
fExt
.close();
fTmp
.close();
}
/* The contents of EXT file were copied to TMP file after appending the parameters.
Delete the EXT file and rename TMP file to EXT file*/
if (DEBUGOUTPUT)
cout
<< "Trial " << trial << ": ";
if ( remove( extfile.c_str() ) == 0 )
{
if ( rename( tmpfile.c_str(), extfile.c_str() ) == 0 )
{
if (DEBUGOUTPUT)
cout
<< argv[0] << " script successful!" << endl;
}
else
{
cout << "Temporary file rename unsuccessful. Check if you have administrative privileges in the data folder:" << argv[1] << endl;
cout
<< "Press ENTER to exit...";
cin
.get();
}
}
else
{
cout << "EXT file deletion unsuccessful. Either EXT file does not exist or you do not have administrative privileges in the data folder:" << argv[1] << endl;
cout
<< "Press ENTER to exit...";
cin
.get();
}
if (DEBUGOUTPUT)
cin
.get();
Cleanup:
if (x) delete [] x;
if (y) delete [] y;
if (seg) delete [] seg;
if (strokewidth) delete [] strokewidth;
if (strokeheight) delete [] strokeheight;
}

/***********************************/
int readtf (const char* fIn, double* x, double* y)
/***********************************/
/* Read time points in from SEG file */
{
ifstream fTF(fIn);
int nsamples = 0, is = 0;
string line;
char * next;
if ( fTF.is_open())
{
getline(fTF, line);
getline(fTF, line);
getline(fTF, line);
getline(fTF, line);
getline(fTF, line);
getline(fTF, line);
// X data header
getline(fTF, line);
nsamples
= (int)strtod(line.c_str(), NULL);
nsamples
= min(nsamples, NSMAX);
// X data
getline(fTF, line);
for (is = 0; is < nsamples; is++)
{
x [is]
= strtod(line.c_str(), &next);
line
= next;
}
// Y data header
getline(fTF, line);
nsamples
= (int)strtod(line.c_str(), NULL);
nsamples
= min(nsamples, NSMAX);
// Y data
getline(fTF, line);
for (is = 0; is < nsamples; is++)
{
y [is]
= strtod(line.c_str(), &next);
line
= next;
}
}
fTF
.close();
return nsamples;
}
/***********************************/
int readseg (const char* fIn, double* seg, int nsegalloc)
/***********************************/
/* Read segmentation points in from SEG file
*/
{
ifstream fSeg(fIn);
int nsegpoints = 0, is = 0;
string line;
char * next;
if (fSeg.is_open())
{
// Segment header
getline(fSeg, line);
nsegpoints
= (int)strtod(line.c_str(), NULL);
nsegpoints
= min(nsegpoints, nsegalloc);
// Segment data
getline(fSeg, line);
for (is = 0; is < nsegpoints; is++)
{
seg[is]
= strtod(line.c_str(), &next);
line
= next;
}
}
fSeg
.close();
return nsegpoints;
}

 

C-function to read raw x, y and z points from MovAlyzeR generated HWR file

ReadHWR Copy Code
int readhwr (const char* fIn, double* x, double* y, double* z)
/* Read points in from HWR data file
fIn: Path of HWR file to read data from
x: Array for x-coordinate data
y: Array for y-coordinate data
z: Array for z-coordinate data
NSMAX: Maximum number of samples to read. Default value = 4096.
*/
{
  
FILE* fp;
  fopen_s(
&fp, fIn, "r");
  
int nsamples = 0;
  
if (fp!=NULL)
  {
     
while (fscanf_s(fp,"%lf %lf %lf",&x[nsamples],&y[nsamples],&z[nsamples]) != EOF && nsamples < NSMAX)
     {
         nsamples
++;
     }
     fclose(fp);
  }
  
return nsamples;
}

 

C-function to read processed x, y and z points from MovAlyzeR generated TF file

ReadTF Copy Code

int readtf (const char* fIn, double* x, double* y)

/* Read time points in from SEG file */

/*

fIn: Path of TF file to read processed data from

x: Array to save processed x coordinates

y: Array to save processed y coordinates

*/

{

    ifstream fTF(fIn);

    int nsamples = 0, is = 0;

    string line;

    char * next;

    if ( fTF.is_open())

    {

        getline(fTF, line);

        getline(fTF, line);

        getline(fTF, line);

        getline(fTF, line);

        getline(fTF, line);

        getline(fTF, line);

// X data header

getline(fTF, line);

nsamples = (int)strtod(line.c_str(), NULL);

nsamples = min(nsamples, NSMAX);

// X data

getline(fTF, line);

for (is = 0; is < nsamples; is++)

{

x [is] = strtod(line.c_str(), &next);

line = next;

}

// Y data header

getline(fTF, line);

nsamples = (int)strtod(line.c_str(), NULL);

nsamples = min(nsamples, NSMAX);

// Y data

getline(fTF, line);

for (is = 0; is < nsamples; is++)

{

y [is] = strtod(line.c_str(), &next);

line = next;

}

}

fTF.close();

return nsamples;

}

 

C-function to read segmentation points from MovAlyzeR generated SEG file

ReadSeg Copy Code

int readseg (const char* fIn, double* seg, int nsegalloc)

/* Read segmentation points in from SEG file */

/*

fIn: Path of SEG file to read segmentation points from

seg: Array to save segmentation data

nsegalloc: Maximum allowed size of segment array

{

    ifstream fSeg(fIn);

    int nsegpoints = 0, is = 0;

    string line;

    char * next;

    if (fSeg.is_open())

    {

        // Segment header

        getline(fSeg, line);

        nsegpoints = (int)strtod(line.c_str(), NULL);

        nsegpoints = min(nsegpoints, nsegalloc);

        // Segment data

        getline(fSeg, line);

        for (is = 0; is < nsegpoints; is++)

        {

            seg[is] = strtod(line.c_str(), &next);

            line = next;

        }

    }

    fSeg.close();

    return nsegpoints;

}

 

Step 2: Compile program into an executable file and put in \Scripts folder  

Copy the executable file into the Scripts folder of the MovAlyzeR User you intend to use.

MovAlyzeR user folder: Open MovAlyzeR > Settings > Data Path and Settings > Path and Settings > Data Path

Scripts folder: UserFolder\scripts

 

Step 3: Create BAT file to launch executable

A batch file (file extension: .BAT)is a collection of MS-DOS commands and is used to execute these commands one after the other. Any command that can be executed in the DOS prompt of a windows computer can be used in a BATCH file.

 

To enter the BAT file, do the following

1. Right-click on the Experiment name > Properties > Processing > External Apps

2. Under the EXT: Post Feature Extraction section, click on the Application drop down menu and select BATCH.

3. Click on the EDIT button to the right to create a new batch file.

4. Enter the following batch program and save it as liextension.bat.

5. Select liextension.bat from the Script drop down menu and click OK.

 

extension.bat Copy Code
@echo off

rem Batch procedure to calculate
rem -> Horizontal Stroke Size
rem
-> Vertical Stroke Size
rem in MovAlyzeR
.
rem Implemented using C in liextension.exe
rem (c) 2009 NeuroScript LLC

rem Parameters obtained from MovAlyzeR
set rootpath
=%1
set experiment
=%2
set group
=%3
set subject
=%4
set condition
=%5
set trialnumber
=%6
set samplingrate
=%7
set deviceresolution
=%8

Rem Set Debug messages ON (1) or OFF (0)
set debug
=1

rem Device name(drive letter) of the file path
set devicename
=%rootpath:~1,2%

rem Change active directory to c drive, d drive etc
%devicename%

rem Extract path to /Scripts folder from rootpath
set scriptdir
=%rootpath:~1,-13%\\scripts
cd
"%scriptdir%"

rem Run External App
liextension
.exe %rootpath% %experiment% %group% %subject% %condition% %trialnumber% %samplingrate% %deviceresolution% %debug%

 

BAT files may be used to launch any other executable file or programming environment. Calls to the .BAT files are also parameterized.

%1  root path

%2  experiment code

%3  group code

%4  subject code

%5  condition code

%6  trial number

%7  sampling rate

%8  device resolution

 

Step 4: Reprocess your trials

Reprocess the trials of the experiment and the additional features will be automatically appended to the .EXT file.

 

Other examples

The following C program opens an existing TF file, reads in the data line by line and deletes the first and last 10 points and then writes the data back to the TF file. The modified TF data can then be used by the segmentation and extraction modules. An appropriate BAT file maybe constructed as described above to use this program.

Modify TF file Copy Code
/* Modify TF file data in MovAlyzeR.
(c) NeuroScript LLC
*/
#include <iostream>
#include <string>
#include <atlstr.h>
#include <fstream>
#include <cmath>
using namespace std;
#define NSMAX 4096
#define MISSING -9999
int main(int argc, char ** argv)
{
if (argc < 10)
{
cout
<< "Not enough input parameters. Valid format to launch the program is " << endl;
cout
<< "tfmod.exe {filepath} {experiment} {group} {subject} {condition} {trial} {sampling rate, Hz}";
cout
<< " {device resolution, lines/cm} {debugmode, 0 or 1}." << endl;
cout
<< "Press Enter to Exit..." << endl;
exit(0);
}
char* list[10];
bool debug;
list[0]
= "Program name";
list[1]
= "File path";
list[2]
= "Experiment";
list[3]
= "Group";
list[4]
= "Subject";
list[5]
= "Condition";
list[6]
= "Trial";
list[7]
= "Hz, Sampling rate";
list[8]
= "lines/cm, Input device resolution";
list[9]
= "Debug";
debug
= (int)strtod(argv[9], NULL) != 0;
if (debug)
{
cout
<< "*******************************" << endl;
cout
<< "* Modify TF file of MovAlyzeR *" << endl;
cout
<< "* (c) NeuroScript LLC *" << endl;
cout
<< "*******************************" << endl;
cout
<< "Number of input arguments=" << argc << endl;
for( int i = 0; i < argc ; i++)
cout
<< argv[i] << " " << list[i] << endl;
}
// Parse input arguments from batch file
string root(argv[1]);
string exp (argv[2]);
string grp (argv[3]);
string sub (argv[4]);
string con (argv[5]);
string trl (argv[6]);
int trial = (int)strtod(argv[6],NULL);
double sec = strtod(argv[7], NULL);
double cm = strtod(argv[8], NULL);
string tffile
= root + "\\" + exp + grp + sub + con + trl + ".TF" ;
string tmpfile
= root + "\\" + exp + grp + sub + con + trl + ".TMP";
// Output files
ifstream fTF(tffile.c_str());
ofstream fTmp(tmpfile
.c_str());
/*****************************/
/* Read filtered data in and */
/* write out to temp file */
/*****************************/
if ( fTF.is_open() && fTmp.is_open())
{
int is, isbegin, isend;
int nsamples;
string lineheader, linedata;
char * headername;
/* TF file parameters:
DON'T UPDATE-- sec, prsmin, beta,
x(cm), y(cm), z
DON'T UPDATE-- Spectrum, V_Spectrum, A_Spectrum, Spectrum_Filtered, V_Spectrum_Filtered, A_Spectrum_Filtered
vx(cm/s), vy(cm/s), vabs(cm/s), ax(cm/s**2), ay(cm/s**2), aabs(cm/s**2), jx(cm/s**3), jy(cm/s**3), jabs(cm/s**3)
*/
int nparam = 21; // Number of params in TF file
int nsamdel = 10; // Number of points to delete from processed x, y and z arrays
int update[21] = {0, 0, 0,
1, 1, 1,
0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1};
// Parameters to update
for (int iparam = 0; iparam < nparam; iparam++)
{
// Read the header
getline(fTF, lineheader);
getline(fTF, linedata);
if (!update[iparam])
{
// Write header and data
fTmp << lineheader << endl;
fTmp
<< linedata << endl;
}
else
{
// #data points
nsamples = (int)strtod(lineheader.c_str(), &headername);
for ( isbegin = 0, is = 0; isbegin < nsamdel && is < nsamples ; is++)
{
isbegin
+= (linedata.at(is) == ' ');
}
isbegin
= is;
for ( isend = 0, is = linedata.size()-1; isend < nsamdel && is > 0 ; is--)
{
isend
+= (linedata.at(is) == ' ');
}
isend
= is;
// Write header and data
fTmp << nsamples-(2*nsamdel) << " " << headername << endl;
fTmp
<< linedata.substr(isbegin, isend - isbegin + 1 ) << endl;
}
}
}
/**********/
/* Output */
/**********/
// Read data from EXT file line by line
// Write to TEMP file after appending parameters calculated in this file
// Copy the entire TEMP file back to EXT file
if ( fTF.is_open() && fTmp.is_open() )
{
fTF
.close();
fTmp
.close();
}
if (debug)
cout
<< "Trial " << trial << ": ";
if ( remove( tffile.c_str() ) == 0 )
{
if ( rename( tmpfile.c_str(), tffile.c_str() ) == 0 )
{
if (debug)
cout
<< argv[0] << " script successful!" << endl;
}
else
{
cout << "Temporary file rename unsuccessful. Check if you have administrative privileges on the data folder:" << argv[1] << endl;
cout
<< "Press ENTER to exit...";
cin
.get();
}
}
else
{
cout << "TF file deletion unsuccessful. Either TF file does not exist or you do not have administrative privileges in the data folder:" << argv[1] << endl;
cout
<< "Press ENTER to exit...";
cin
.get();
}
return 0;
}

 

Points to remember when using external applications for processing

1. The intermediate files are still processed by MovAlyzeR's internal algorithms before they are overwritten by the external program. Care must be taken to maintain the format and conventions of the original files for stable operation of MovAlyzeR.

2. Matlab or the Matlab runtime component are not included with MovAlyzeR. It is the responsibility of the user to install and configure all 3rd party software.

3. The integration environment offers limited tools to debug the scripts. It is best to have a working script outside the MovAlyzeR environment before any integration is attempted.

4. All Matlab and batch scripts used in the processing of a MovAlyzeR experiment are stored in the UserDirectory\Scripts folder and are included in an exported experiment file.

Matlab® is a registered trademark of The MathWorksTM

Disclaimer: All the C code is shown here only for demonstrative purposes and no other claims of suitability to any other purpose are made.

NSHelp: Condition Consistency CheckingExperiment PropertiesProcessing Time functionsProcessing Segmentation SettingsProcessing Extraction SettingsWord ExtractionProcessing SummarizationStroke Description

 

 


© NeuroScript LLC. All Rights Reserved.