-- program to export a processed DOSY Varian spectrum to the DOSY Toolbox function ValueNamed( name ) local len = string.len( name ) + 1 name = name.." " local line repeat line = string.sub( io.read("*line"), 1, len ) until line == name _ = io.read("*number") -- skip the first number return io.read("*number") end function StringNamed( name ) local len = string.len( name ) + 1 name = name.." " local line repeat line = string.sub( io.read("*line"), 1, len ) until line == name _ = io.read("*number") -- skip the first number return io.read("*line") end function ArrayNamed( name ) local len = string.len( name ) local line T = {} repeat line = string.sub( io.read("*line"), 1, len ) until line == name local n = io.read("*number") -- the first number is the length of the array for i=1,n do T[i] = io.read("*number") end return n, T end -- the main program starts here My = getf "x" local path = pathtofile() local last = 1 while true do local 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.."procpar" ) io.output( path.."dosy.txt" ) -- READING VARIAN DATA -- the following parameters must be found exactly in this order... local DAC_to_G = ValueNamed( "DAC_to_G" ) / 100 -- calibration local DELTA = ValueNamed( "del" ) -- diffusion delta local dosytimecubed = ValueNamed( "dosytimecubed" ) -- ?? local dosygamma = ValueNamed( "dosygamma" ) -- gyromagnetic ratio local delta = ValueNamed( "gt1" ) -- gradient encoding time local n, gzlvl1 = ArrayNamed( "gzlvl1" ) -- gradient strength -- ... otherwise they are not found: in this case, rewrite the script 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) \"Varian Inova\" \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) ", dosygamma, "\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) ", StringNamed( "seqfil" ), "\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) ", dosygamma, "\n") io.write("#Dosytimecubed (double) ", dosytimecubed, "\n") io.write("#Gradient Shape (string) N/A \n") io.write("#Gradient Shape Factor (string) N/A \n") io.write("#Pulse Sequence Type (string) \"Other\" \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( DAC_to_G * gzlvl1[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" )