-- program to export a processed DOSY Bruker spectrum to the DOSY Toolbox gamma = 267524618.573 -- hydrogen gyromagnetic constant local path = pathtofile() last = 1 while true do slash = string.find( path, "/", last + 1 ) if not slash then break end last = slash end path = string.sub( path, 1, last ) -- path to the folder io.input( path.."acqus" ) local line repeat line = string.sub( io.read("*line"), 1, 5 ) -- delays "d0, d1..." until line == "##$D=" local delay = {} for i=0,20 do delay[i] = io.read("*number") -- unit = seconds end repeat line = string.sub( io.read("*line"), 1, 5 ) -- pulses "p0, p1..." until line == "##$P=" local pulse = {} for i=0,30 do pulse[i] = io.read("*number") -- unit = us (microseconds) end repeat line = io.read("*line") local beginning = string.sub( line, 1, 11 ) -- pulseprogram until beginning == "##$PULPROG=" pulse_program = string.sub( line, string.find(line,"<")+1, string.find(line,">")-1 ) delta = 1e-6 * pulse[30] -- small delta (gradient pulse), in units of seconds if string.find( pulse_program, "bp" ) then delta = 2 * delta end DELTA = delay[20] -- big delta (time for diffusion) local D_d = DELTA - delta / 3 print( "DELTA = ", DELTA ) print( "delta = ", delta ) print( "DELTA' = ", D_d ) print( "gamma = ", gamma ) local dosyconstant = gamma*gamma * delta*delta * D_d print( "dosyconstant = ", dosyconstant ) io.input( path.."difflist" ) -- Bruker file that contains the values of gradient strength G = {} local n = 0 while true do local found = io.read("*number") -- gradient strength if not found then break end n = n + 1 G[n] = found * 0.01 end My = getf "x" io.output( path.."dosy.txt" ) io.write("## DOSY Toolbox data file \n") io.write("## ************ File and Data Information ********************** \n") io.write("#Binary File Name (null) \n") io.write("#Data Class (string) \"Spectra\" \n") io.write("#Complex Data (string) \"No\" \n") io.write("#Data Origin (string) \"iNMR\" \n") io.write("#Data Type (string) \"DOSY data\" \n") io.write("#DOSY Toolbox Format Version (string) \"0.1\" \n") io.write("#Number Of Arrays (integer) 1 \n") io.write("#Spectrometer/Data System (string) \"Bruker Avance\" \n") io.write("#Title (string) ", title(), "\n") io.write("## ************ Matrix Format ********************************** \n") io.write("#Complex Data (string) \"No\" \n") io.write("#Number Of Rows (integer) ", n, "\n") io.write("#Points Per Row (integer) ", My.size, "\n") io.write("#Y Axis Definition (string) \"Gradient Amplitude\" \n") io.write("## ************ Acquisition Parameters ********************************** \n") io.write("#Acquisition Time (double; s) ", My.size / (My.width*My.MHz), "\n") io.write("#Complex Points Acquired (integer) ", My.size, "\n") io.write("#Gyromagnetic Ratio (double; rad s^-1 T-1) ", gamma, "\n") io.write("#Lowest Frequency (double; ppm) ", My.start, "\n") io.write("#Observe Frequency (double; MHz) ", My.MHz, " \n") io.write("#Observe Nucleus (string) \"", My.mass, "-", My.atom, "\"\n") io.write("#Spectral Width (double; ppm) ", My.width, "\n") io.write("#Pulse Sequence Name (string) ", pulse_program, "\n") io.write("## ************ Processing parameters ********************************** \n") io.write("#Fourier Number (integer) ", My.size, "\n") io.write("#Left Phase (double; degree; Phase at extreme left) 0 \n") io.write("#Right Phase (double; degree; Zeroth order) 0 \n") io.write("## ************ Gradient parameters ********************************** \n") io.write("#Diffusion Delay (double; s; DELTA) ", DELTA, "\n") io.write("#Diffusion Encoding Time (double; s; delta) ", delta, "\n") io.write("#Dosygamma (double) ", gamma, "\n") io.write("#Gradient Shape (string) N/A \n") io.write("#Gradient Shape Factor (string) N/A \n") io.write("#Pulse Sequence Type (string) \"Unipolar\" \n") io.write("#Tau (null) \n") io.write("## ************ Arrays ********************************** \n") io.write("#Gradient Amplitude ["..n.."] (double data 1; T/m)\n") for i = 1,n do io.write( G[i], "\n" ) end print( n, "gradient values saved" ) region( 9999, -9999, 9999, -9999 ) local T = copy() local NumPoints = T.x * T.y io.write("#Data Points ["..NumPoints.."] (double) \n") for i = 1,NumPoints do io.write(T[i], "\n") end io.close( ) -- closing and saving the output file print( NumPoints, "points saved" )