Search code examples
wolfram-mathematicado-loops

Do loop to run batch analysis of .dat


I'm trying to edit a current Mathematica script, to allow for batch processing. This involves importing a series of files of different names (i.e. different numerical suffixes), and in the end writing different .dat for exporting results. I've tried implementing a Do loop for this (in the example code below, it's set up for files with 980 & 998 suffixes), but somehow Mathematica doesn't recognise the Do loop variable. Would someone be able to help? Or perhaps suggest a way of going about this? Thanks!

Do[
prot=Import[StringForm["dMdt_protein_nve``.dat", i],"Table"];
ions=Import[StringForm["dMdt_ions_nve``.dat", i],"Table"];
water=Import[StringForm["dMdt_water_nve``.dat", i],"Table"];

(* ------------------------------------------------------ *)
(*parameters for spectrum calculation*)

times=Range[0,(nCorr*2-2)*dt,dt]; (*in picoseconds*)
f0=1/(Length[times]*dt); (*in THz*)
freqs=Table[i*f0,{i,0,Length[times]-1}];
wn=freqs*0.01*10^12/c;
prefactor=(2\[Pi] *(e*10^-10*10^12)^2*dt*10^-12*0.01)/(4\[Pi] Epsilon0*kb*300*3*(13.29315*10^-9)^3 c); (*to yield alpha(\[Omega]) \[Times] n(\[Omega]) in 1/cm*)

(* ------------------------------------------------------ *)
(*smart calculation with Fourier transforms for the correlations*)
(*auto-correlations via FT*)

protAC=FTAC[prot,nCorr];
ionsAC=FTAC[ions,nCorr];
waterAC=FTAC[water,nCorr];

(* ------------------------------------------------------ *)
(*(*Save data to file*)*)

Export[StringForm["out_protCCwaterSpec_nve``.dat", i],protCCwaterSpec+waterCCprotSpec "Table"];
,{i,{980,998}}] 






Solution

  • The problem is that StringForm is not a String. Use StringJoin instead. Make sure this works and then add the rest of your code.

    Do[
     Import["dMdt_protein_nve" <> ToString@i <> ".dat", "Table"],
     {i, {980, 998}}]