Creating a .RAW input file for LCmodel

Hi, I am trying to use LCmodel to analyze some older Siemens MRS data for which I only have DICOM file, no Siemens *.raw. I want to convert the data to the LCmodel *.RAW file.
Most data are series of spectra, so I would like to put them in *.RAW files with multiple spectra as columns (NDCOLS >1).
So far no luck with either single spectra or series. The *.RAW input format appears to be very finicky. I get ZEROVOX 5 errors again and again.
I tried with/without an extra newline after the last data point, with or without quotes around the FMTDAT and/or ID statements (Jamie’s code would produce without quotes, but LCmodel’s test.RAW file has quotes. I also tried FMTDAT = β€˜(2E1.6)’, FMTDAT = β€˜(2E15.6)’ or FMTDAT = β€˜(2E16.6)’. Nothing works.
Below is the core of the write to RAW Matlab script I wrote based on Jamie Near’s io_writelcmraw.m.

Also, the control files produced in my efforts have the right number of columns, but the LCMgui shows 1 column every time in spite of the NDCOLs = 5 in the RAW parameters.

Can anybody help me get this right?

Thanks

Ronald

N = spectra(1).hdr.fid_size;
data = zeros( M * spectra(1).hdr.fid_size, 2);
idx = 1:N;

for ii = 1:M
idx = (1:N)+(ii-1)*N;
thesedata = spectra(ii).data(:);
if reverse
thesedata = conj(thesedata);
end
data(idx, 1:2) = [real(thesedata), imag(thesedata) ];
end % for ii

% write to .RAW txt file for LCmodel
fid=fopen(filename,β€˜w+’);
fprintf(fid,’ $SEQPAR\n’); % begin sequence paramters
fprintf(fid,’ ECHOT = %-3.1f\n’, 1000*spectra(1).hdr.TE);
fprintf(fid,’ HZPPPM=%-12.4f\n’, spectra(1).hdr.frequency);
fprintf(fid,’ DELTAT=%-15.8f\n’, 1/spectra(1).hdr.sweepwidth );
fprintf(fid,’ NUNFIL=%-6d\n’, N );
fprintf(fid,’ NDCOLS=%-3d\n’, M );
fprintf(fid,’ NDROWS=%-3d\n’, 1 );
fprintf(fid,’ SEQ = β€˜β€™%s’’\n’, sequence );
fprintf(fid,’ $END\n’); % end sequence paramters
fprintf(fid,’ $NMID\n’); % begin format/scale paramters
fprintf(fid,’ ID=’’%s’’\n’, filename(1:20) );
fprintf(fid,’ FMTDAT=’’(2E16.6)’’\n’);
fprintf(fid,’ VOLUME=1.00000\n’);
fprintf(fid,’ TRAMP=1.00000\n’);
fprintf(fid,’ $END\n’); % end format/scale paramters
fprintf(fid,’ % 15.6E % 15.6E\n’, data’); %space after β€œ%” sign forces hanging negative sign
fclose(fid);

Hi Ron,

In Osprey we are using io_lcmwrite (see here). The ’ vs ` might be an issue, depending on which editor you work in. Our function works quite well, you could give it a try?

Cheers,
Georg

Hi Georg,

Thanks for your help. I got things to work. I had errors in bot .RAW and .control file.
In the .RAW file the position of the imaginary data was off by one.
fprintf( fid, β€˜% 15.6E% 15.6E\n’, rdata(ii), idata(ii) ) will work with FMTDAT = β€˜(2E15.6)’

In the control file I changed a lot. I inserted spaces on both sides of each equal sign, changed the order of things a bit etc… Looking at io_lcmwrite and your .control example I see that most of these changes were not important.

A few failures were due to the target directories not existing yet. So along with creating the conrol file I must make the target folder first.

What was important, as you pointed out to me, srcraw is not the place of the .RAW file.
filraw is where this is specified. Using LCgui this variable appeared to be for an output .RAW file made when preprocessing like water suppresion is part of the analysis.

Now I am faced with one last problem. Ideally I would like the command line lcmodel to analyze all my spectra from one file. I have 5 or 7 spectra. With all data consecutive and NDCOLS = 5 the program runs fine, but I get output for only the first spectrum. All references in the β€˜Manual.pdf’ to CSI or other series processing appear to be based on using lcgui. I hope there is some magical control parameter that makes the command line version analyze all five or seven spectra and collect the results in a handy .csv file.

Bye

Ronald

1 Like

Great to hear, Ron.
I imagine that we’ll look into concatenating multiple FIDs into one .RAW file at some point for Osprey, although it’s not a priority at all. Let us know if you get it to work :wink: