[Scons-users] Conditional process
Sven Lars Tobias Stål
smp428 at alumni.ku.dk
Sun Jan 25 11:48:24 EST 2015
Thank you William,
sorry for not giving the larger picture. I’ll take a deeper look into aliases, this could be the way to go!
I use SCons to process geophysic data. The data should be processed by a number of programs from the Madagascar package (rsf). I’m using functions defined by the rsf module to process data and export results. Usually, the programs are run in serial and SCons keeps track of dependencies and keep the processing time down as it checks what data that needs to be reconstructed. (As I believe a more typical application of Scons would be).
However, in this (rare) case a data value must be able to control the process flow, and the value can’t be predicted. Until now I’ve split the flow by running first one SCons flow, then a conditional python script (see below), using the os module to call the programs and create output files, then using the result to a second SConstruct script. This is rather annoying and moreover not proper reproducibility, if someone would like to repeat the process to test my findings.
The total flow should look something like this. (I’m not sure this sketchy syntax makes it any clearer):
from rsf.proj import * #Get Fetch, Flow and Result functions
Fetch('inputData')
Flow(outdata,indata,'Program 1')
Flow(outdata,indata,’Program 2 | Program 3')
Fetch(‘geometry.asc’) #Read the parameter that defines how many files to stack
if value = 2
Flow(outdata, every 2’nd file, ‘Program 1 parameter a’) #Stack two files and jump to next
if value = 4
Flow(outdata, every 4’th file, ‘Program 1 parameter b’) #Stack four files and jump to next
Flow(outdata,in data from conditional loop,'Program 1’) #Flow continues...
Result(,data,’plotting program')
End()
Best regards
Tobbe
On 25 Jan 2015, at 16:54 , William Blevins <wblevins001 at gmail.com<mailto:wblevins001 at gmail.com>> wrote:
Tobbe,
I'm not sure why you would want/need to do this, so there may be a better way to achieve your "end goal" if we knew the "why" question.
Consider creating aliases for target creation sets, and simply call "scons <target_alias>" on the command line. Keep in mind that SCons will also build all the necessary dependencies, so SCons may build other targets if necessary.
Alias information: http://www.scons.org/doc/HTML/scons-user/ch25.html
V/R,
William
On Sun, Jan 25, 2015 at 9:48 AM, Sven Lars Tobias Stål <smp428 at alumni.ku.dk<mailto:smp428 at alumni.ku.dk>> wrote:
Dear all,
I’m using SCons to build work flows of Madagascar programs (http://www.ahay.org<http://www.ahay.org/>). I’m new to SCons, so sorry for asking basic questions. I’m grateful for any advice.
I’d like to build files differently based on a variable.
I could easily make a Python script, using os or subprocess to achieve the wanted result, but I’d like to use SCons and implement this process in a larger flow. The loop goes through all file names, check a variable from a list, SN, if it’s 2 it adds the following file and skips i+1. If the variable is 4, it adds the there following files and jump to the file after.
i = 0
while i < len(fL):
shutil.copy2('t'+ fL[i]+'.rsf', iN + fL[i]+'.rsf') #Select trace header files
shutil.copy2('t'+ fL[i]+'.rsf@', iN + fL[i]+'.rsf@')
sL.append(iN + fL[i] + '.rsf')
if SN[i] == 2:
os.popen('sfadd < '+ fL[i] + '.rsf ' + fL[i+1] + \
'.rsf scale=1,1 > ' + iN + fL[i] + '.rsf').read()
i += 2 #Jump to next file
elif SN[i] == 4:
os.popen('sfadd < '+ fL[i] + '.rsf ' + fL[i+1] + '.rsf ' + fL[i+2] + \
'.rsf ' + fL[i+3] + '.rsf scale=1,1,1,1 > ' + iN + fL[i] + '.rsf').read()
i += 4 #Jump to next file
else:
print('Unspecified stack %s' % fL[i]) #Or error
Alternatively, how can I call a python script from SCons so that the input is defined (all files in fL list) but the output depends on the conditional result from the script.
Regards
Tobbe
_______________________________________________
Scons-users mailing list
Scons-users at scons.org<mailto:Scons-users at scons.org>
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
Scons-users at scons.org<mailto:Scons-users at scons.org>
https://pairlist4.pair.net/mailman/listinfo/scons-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20150125/48043152/attachment-0001.html>
More information about the Scons-users
mailing list