0
$\begingroup$

I have a folder with many .dat files to analize, say

name_1.dat

name_2.dat

name_3.dat

. . .

name_n.dat

I also have an auxiliary property.dat file, which is a joint table with all the names:

name_1 property_1 property_2 property_3 ... property_m

name_2 property_1 property_2 property_3 ... property_m

name_3 property_1 property_2 property_3 ... property_m

. . .

name_n property_1 property_2 property_3 ... property_m

with specific properties of those previous .dat files I mentioned but their names are not ordered as in the folder, they are like

name_10 property_1 property_2 property_3 ... property_m

name_8 property_1 property_2 property_3 ... property_m

name_1 property_1 property_2 property_3 ... property_m

. . .

name_n property_1 property_2 property_3 ... property_m

. . .

name_5 property_1 property_2 property_3 ... property_m

I need to do cycle to process the data in the files but at the same time I need the properties of the other file to perform the analysis. During the cycle I need also to save individually the newly processed files and to write another file with the results, like

name_1 new_property_1

name_2 new_property_2

name_3 new_property_3

. . .

name_n new_property_n

Could someone give me a hint on how to do that?

$\endgroup$
  • $\begingroup$ Look up Module, Import, Do, and Export. $\endgroup$ – b3m2a1 Mar 18 '17 at 23:51
1
$\begingroup$

You have data files

dfile = FileNames["name_*.dat"];

One approach uses a loop. We derive property & output file names from the input (dat) filename using StringReplace[] & process as we go.

Do[
 (* set names *)
 pfile = StringReplace[dfile[[jf]], {".dat"->" property_1 property_2 property_3 ... property_m"}];
 ofile = StringReplace[dfile[[jf]], {".dat"->" new_property_1"}];
 (* get data *)
 ddata = Import[dfile[[jf]]];
 pdata = Import[pfile];

 (* process ... *)

 (* dump *)
 Export[ofile, results],
 {, jf, 1, Length@dfile}
];

Should get you started.

Preparation is key; having data as StringJoin["Name_", IntegerString[#, 10, 2], ".dat"]& /@ Range[Length@data]; can save a lot of time.

There is an obvious functional approach.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.