Page 1 of 1

extract chromatographic signals saved in a struc of dirs

Posted: Tue Jun 05, 2012 1:23 pm
by alba
Dear all,

I have been trying to program a macro to obtain .csv of the chromatography signals for a set of .D files. I have used a macro from Gasman sent in another (similar/previous) topic.

However, I have some problems. I was able to program it with a simple structure of files, that is:

For example:

C:\Temp\Run1.D
C:\Temp\Run2.D
C:\Temp\Run3.D

Code: Select all


Name MYCSVALL

Local cols,runtime,signal,i,j,k

!************************************
! Create the file with the list

! I couldn't do it like this (I don't know why...):
!ListDir$ = "dir>" + "c:\Temp\list.txt" + " /A:D /B"
!ExecNoWait ListDir$ !Execute a command "ListDir$" in cmd.exe

! I do it with a .bat file saved in \CORE

ChDir "c:\HPCHEM\CORE"
ExecNoWait ListDir.bat

!!!!!! Contents of the .bat file
!!!!!! cd c:\Temp
!!!!!! dir>list.txt /A:D /B

!************************************
! Commands to set CWD as the one where the files are

Open "ListDir.bat" For Input as #4
Input Using #4, "L", FilesDir$ ! Entire line read into string
FilesDir$ = FilesDir$[4:len(FilesDir$)]
ChDir FilesDir$
Close #4

!************************************
! Commands to find the total number of .D files in the directory

Queue$ = FindFile$(GetCWD$() + "\*.D",,",")
TotalFiles = 1
Repeat
   Queue$ = Queue$[Instr(Queue$,",") + 1:len(Queue$)]
   TotalFiles = TotalFiles + 1
Until (Instr(Queue$,",") = 0)

!************************************
        Open "list.txt" For Input as #5
   For k = 1 to TotalFiles
      Input Using #5, "L", FileName$ ! Entire line read into string   
      !Print FileName$      
      File FileName$
      LoadSignal ,"A",, ChromReg
      FileNameSignal$ = "c:\Temp\" + FileName$ + "\Signal"
      !Print FileNameSignal$
      For j=1 to RegSize(Chromreg)
           cols=DataCols (Chromreg[j])
           Open FileNameSignal$ + Val$(j)+".csv" For Output as #6
           Print "Saving " + FileNameSignal$ + Val$(j) + ".csv"
           For i=1 To cols
                runtime = Data (Chromreg[j],0,i)
                signal = Data (Chromreg[j],1,i)
                print#6,runtime,",",signal
           Next i
           Close#6
      Next j
      DelReg ChromReg
   Next k
        Close #5

Print "Finished"

EndMacro

But I would like to get similar results for files structure like this one (e.g.):

C:\Temp\120516\Run1.D
C:\Temp\120516\Run2.D
C:\Temp\120516\Run3.D
C:\Temp\120517\Run1.D
C:\Temp\120517\Run2.D
C:\Temp\120517\Run3.D
C:\Temp\120518\Run1.D
C:\Temp\120518\Run2.D
C:\Temp\120518\Run3.D

I feel I'm fighting against a simple problem but I don't know how to solve it with Chemstation language. Could anyone help me? The main idea is that I want to dig into several directories...

Thanks in advance for your help.

Re: extract chromatographic signals saved in a struc of dirs

Posted: Thu Jun 07, 2012 8:27 am
by aceto_81
I'm not sure what listdir.bat is doing, but you should be able to get a list of dirs, and then run a for loop through the dirs list, while the for loop for files is nested in the dir loop.

Ace