0

I have a script where I have multiple folders each with three audio files in them ID#_1, ID#_2, and ID#_3. The user can input a string of different ID#s, one after the other, and then the script recognizes the different IDs and runs the code for each of them.

I have a for loop set up for this -

form Settings comment Enter the IDs of the different subjects sentence subjectIDs endform

numOfSubjects = length(subjectIDs$)/4

for i from 0 to (numOfSubjects - 1)
    subjectID$ = mid$(subjectIDs$, 1 + 4*i, 4 + 4*i)
    outFile$ = subjectID$ + "/SubjectResponseOnsets" + subjectID$ + ".txt"
    path$ = subjectID$ + "/" + subjectID$
    @firstOutput
    @secondOutput
    @thirdOutput'

Each of these procedures is defined previously in the code, and they basically output certain ranges from the audio files out to a text file.

The code seems to work fine and generate the output file correctly when one ID is given, but when I try to run it with more than one ID at a time, only the text file for the first ID is outputted.

The for loop does not seem to be working well, but the code does work fine in the first run.

I would greatly appreciate any help!

4

1 回答 1

0

I don't know if I understood well what your script was trying to do, since the snippet you pasted was incomplete. It's best if you provide code that is executable as is. In this case, you were missing the closing endfor, and you were calling some procedures that were not defined in your snippet (not even as placeholders). I had to write some dummy procedures just to make it run.

Since you also didn't say how your script was failing, it was unclear what needed to be fixed. So I took a stab at making it work.

It sounded as if your ID splitting code was giving you some problems. I took the split procedure from the utils plugin available through CPrAN, which makes inputting the IDs easier (full disclosure: I wrote that plugin).

form Settings
  comment Enter the IDs of the different subjects
  sentence subjectIDs 01 02 03
endform

@split: " ", subjectIDs$
numOfSubjects = split.length

for i to numOfSubjects
  subjectID$ = split.return$[i]
  path$ = subjectID$
  outFile$ = path$ + "/SubjectResponseOnsets" + subjectID$ + ".txt"

  # Make sure output directory exists
  createDirectory: path$

  @firstOutput
  @secondOutput
  @thirdOutput
endfor

procedure firstOutput ()
  appendFileLine: outFile$, "First"
endproc

procedure secondOutput ()
  appendFileLine: outFile$, "Second"
endproc

procedure thirdOutput ()
  appendFileLine: outFile$, "Third"
endproc

# split procedure from the utils CPrAN plugin
# http://cpran.net/plugins/utils
procedure split (.sep$, .str$)
  .seplen = length(.sep$)
  .length = 0
  repeat
    .strlen = length(.str$)
    .sep = index(.str$, .sep$)
    if .sep > 0
      .part$ = left$(.str$, .sep-1)
      .str$ = mid$(.str$, .sep+.seplen, .strlen)
    else
      .part$ = .str$
    endif
    .length = .length+1
    .return$[.length] = .part$
  until .sep = 0
endproc

If this is not what you are having trouble with, you'll have to be more specific.

于 2015-04-03T23:59:34.617 回答