"***********************************************************************"
" SPENrecon"

"***********************************************************************"

exists('processflg','parameter') :$ex
if ($ex=0)  then create('processflg') endif

if (processflg=0) then 
    "prevent retrieved data file corruption by making a copy"
    cp(curexp+'/acqfil/fid',curexp+'/acqfil/fidtmp')
    rm(curexp+'/acqfil/fid')
    mv(curexp+'/acqfil/fidtmp',curexp+'/acqfil/fid')
    cp(curexp+'/recon/procpar',curexp+'/acqfil/procpartmp')
    cp(curexp+'/acqfil/fid',curexp+'/acqfil/fidtmp')
    write('line3','Backup the data')

    shell('locate --regex \'/MATLAB/MATLAB_Compiler_Runtime/v82\' -l 1'):$MCR_PATH
    $datafile=curexp+'/acqfil'
    $matlabcommand = userdir+'/templates/layout/'+seqfil+'/run_xSPENsegrecon.sh '
    $matlabcommand = $matlabcommand + $MCR_PATH + ' ' + $datafile
    echo($matlabcommand)
    shell($matlabcommand)
    fread(curexp+'/recon/procpar','processed')
    write('line3','Data process finish')
    processflg = 1	
endif


