Page 1 of 1

FileAppend loop in macro

Posted: Thu Jun 05, 2014 3:09 pm
by CPC
Is there a way to automatically append a dplot file with all *.csv files in a directory?

I have a batch script that will execute a dplot macro within every sub-folder of a directory. Inside each of those sub-folders are several .csv files with different names that need to be combined into one dplot file. For the macro to be useful more than one individual folder, I need a way to combine all of the csv files. It seems that FileAppend() will not accept a wildcard (i.e. FileAppend(*.csv)). Is there some other way to loop through all csv files and append them to one dplot graph?

Posted: Thu Jun 05, 2014 3:42 pm
by DPlotAdmin
Yes.

ForFilesIn("*.csv",A)
NextFile

will append all .CSV files in the current directory to the active document.

Posted: Wed Aug 27, 2014 7:34 am
by CPC
David,

I have been successfully using append with ForFilesIn for several different macros, but I have run into a strange problem with the one that I am working on now. I'm not sure exactly what is going on, but I'll describe it as best as I can.

For some reason, data that is not part of any file (that I can find) is appearing when I try to append several displacement .grfs into one file. If I drag the individual graphs in by hand, everything works out fine, but if I read them in with a ForFilesIn loop, strange data appears and none of the data that I expect is there. I would expect to see three displacement curves, each starting from x=0 and going to x=0.03. Instead, I see 12 curves with data that swings back and forth between positive and negative x-values. Even more confusing is the fact that there is another loop in the macro that does the exact same thing (for my velocity graphs) and it works out fine. Have you seen anything like this before?



Here is the entire macro in case you can see something that I am doing wrong:

FileType(4)

ForFilesIn("*postfilter*.csv")
EditTruncate(0,0.03)
EditEqualInts(1,5e-6,1)
EditFilter("bandpass",1,1,10,49900,0,1)
EditSubtractMean()
Integrate()
EditErase()
Integrate()
EditErase()
XAxisLabel("Time (s)")
YAxisLabel("Local Displacement (m)")
FileSaveAs(1,".grf")
VAR_B=Request("fname")
Title1("VAR_B Local Displacement")
Title2("")
FileSaveAs(1,"|TITLE1|.grf")
FileClose()
NextFile

ForFilesIn("*Displacement.grf",A)
NextFile
Title1("Local Displacement")
Title2("")
Legend(1,"0.11 AFV")
Legend(2,"0.2 AFV")
Legend(3,"0.4AFV")
XAxisLabel("Time (s)")
YAxisLabel("Displacement (m)")
FileSaveAs(4,"Local Displacement.csv")
FileClose()

ForFilesIn("*postfilter*.csv")
EditTruncate(0,0.3)
Integrate()
EditErase()
XAxisLabel("Time (s)")
YAxisLabel("Velocity (m/s)")
FileSaveAs(1,".grf")
VAR_B=Request("fname")
Title1("VAR_B Velocity")
Title2("")
Title3("")
FileSaveAs(1,"|TITLE1|.grf")
FileClose()
NextFile

ForFilesIn("*Velocity*.grf",A)
NextFile
Title1("Velocity")
Title2("")
Legend(1,"0.11 AFV")
Legend(2,"0.2 AFV")
Legend(3,"0.4 AFV")
XAxisLabel("Time (s)")
YAxisLabel("Velocity (m/s)")
FileSaveAs(4,"Velocity.csv")
FileClose()

FileExit()

Posted: Wed Aug 27, 2014 11:27 am
by CPC
I have been picking through the files, and I have some further information. It seems that the EditEqualInts command generating the phantom data that I am seeing. If I drag one of the "Local Disp.grf" generated by the macro into Dplot, it shows my data as I would expect. However, if I open the same file with a text editor, I see the 4 phantom curves that are showing up when I tried to append all of the "Local Disp.grf" files into one. I'm guessing that the EditEqualInts command is generating these extra columns of data, but how does Dplot know what my curve is supposed to look like when I open a file by itself, but it gets confused when I read them in through the macro? Could it be something that I am doing wrong in the macro?

Posted: Wed Aug 27, 2014 2:53 pm
by DPlotAdmin
Thanks for the detailed post. I'm on the road at the moment but will look into this as soon as I can.

Posted: Thu Oct 09, 2014 1:15 pm
by CPC
I was just wondering if you have had time to look into this issue?

Posted: Thu Oct 09, 2014 6:12 pm
by DPlotAdmin
Yes, but haven't solved it yet. Sorry this is taking so long.

Posted: Fri Oct 10, 2014 6:01 am
by CPC
No problem. I hadn't thought about my question in a while and just wanted to check in.