00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 from os.path import isfile, join,abspath
00034 from repro.functions.RushFunctions import sfbin_method
00035 from SCons.Tool import Tool
00036
00037 import re
00038
00039
00040
00041
00042
00043 def matlab_gen( source, target, env, for_signature ):
00044
00045 matfuncs = env['matfuncs']
00046
00047 paths = env.Split( env.get('matpath',[]) )
00048
00049 if isinstance(matfuncs, str):
00050 matfuncs = matfuncs.split(';')
00051
00052 if paths:
00053 env['MATPATH'] = "addpath('%s');" %("','".join(paths))
00054 env['MATFUNCS'] = ";".join( matfuncs )
00055
00056 if env.get('DATAPATH'):
00057 env['ENV']['DATAPATH'] = env['DATAPATH']
00058
00059 MATLABSTR = '$MATLAB $MATLABOPTS -r "$MATPATH$MATFUNCS; quit"'
00060
00061 return MATLABSTR
00062
00063
00064
00065
00066
00067
00068 def matlab_emitter( target, source, env ):
00069
00070 re_mat_func = re.compile("^(.*)\(.*\)$")
00071
00072 matfuncs = env['matfuncs']
00073
00074 paths = env.Split( env.get('matpath',[]) )
00075 paths.append('.')
00076 env['MATPATH'] = "addpath('%s');" %("','".join([abspath(p) for p in paths]))
00077
00078 if isinstance(matfuncs, str):
00079 matfuncs = matfuncs.split(';')
00080
00081 for func in matfuncs:
00082 funcs = re_mat_func.findall(func)
00083 if not funcs:
00084 continue
00085 func = funcs[0]
00086 for path in ['.'] + paths:
00087 mfile = join(path,"%(func)s.m" %vars())
00088 if isfile( mfile ):
00089 source.append(mfile)
00090
00091 env['MATFUNCS'] = ";".join( matfuncs )
00092
00093 sfbin_method( env, target )
00094
00095 return target, source
00096
00097
00098
00099
00100
00101 def generate(env):
00102
00103 env['MATLAB'] = 'matlab'
00104 env['MATLABOPTS'] = '-nojvm -nosplash'
00105
00106 mb = env.Builder( generator=matlab_gen,
00107 emitter=matlab_emitter,
00108 suffix='.mat',
00109 src_suffix='.mat'
00110 )
00111
00112 env['BUILDERS']['Matlab'] = mb
00113
00114
00115
00116
00117
00118 def exists( env ):
00119 return env.Detect('matlab')
00120
00121