Skip to content

Commit f831c8a

Browse files
StefanStefan
authored andcommitted
added jcamp location
1 parent a1604e2 commit f831c8a

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

lib/src/main/java/de/unikoeln/chemie/nmr/io/NmredataReader.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ private void analyze2DSpectrum(String spectrumblock, String[] nucleus, NmreData
287287
StringTokenizer st=new StringTokenizer(spectrumblock,lineseparator);
288288
double[] freq=null;
289289
String location=null;
290+
String jcampLocation=null;
290291
String jcamp=null;
291292
int peakcount=0;
292293
Map<NoteDescriptor, String> descriptors=new HashMap<>();
@@ -297,6 +298,8 @@ private void analyze2DSpectrum(String spectrumblock, String[] nucleus, NmreData
297298
freq=new double[]{Double.parseDouble(line.substring(7)),Double.parseDouble(line.substring(7))};
298299
}else if(line.startsWith("Spectrum_Location=")){
299300
location=line.substring(line.indexOf("=")+1);
301+
}else if(line.startsWith("Jcamp_location=")){
302+
jcampLocation=line.substring(line.indexOf("=")+1);
300303
}else if(line.startsWith("Spectrum_Jcamp=") && data.getVersion().compareTo(NmreData.NmredataVersion.ONEPOINTONE)>0){
301304
jcamp=line.substring(line.indexOf("=")+1);
302305
}else if(line.matches(".*/.*") && (!line.contains("=") || line.indexOf("=")>line.indexOf("/"))){
@@ -397,6 +400,10 @@ private void analyze2DSpectrum(String spectrumblock, String[] nucleus, NmreData
397400
spectrum.setPeakTable(peakTable);
398401
NoteDescriptor noteDescriptor=new NoteDescriptor("Spectrum_Location");
399402
spectrum.setNote(noteDescriptor, location);
403+
if(jcampLocation!=null) {
404+
NoteDescriptor jcampLocationDescriptor=new NoteDescriptor("Jcamp_location");
405+
spectrum.setNote(jcampLocationDescriptor, jcampLocation);
406+
}
400407
NoteDescriptor jcampDescriptor=new NoteDescriptor("Spectrum_Jcamp");
401408
spectrum.setNote(jcampDescriptor, jcamp);
402409
for(NoteDescriptor descriptor : descriptors.keySet()){

lib/src/main/java/de/unikoeln/chemie/nmr/io/NmredataWriter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ public void write(NmreData data, NmredataVersion version, Map<Object,Object> pro
140140
for(Spectrum spectrum : data.getSpectra()){
141141
StringBuffer spectrumbuffer=new StringBuffer();
142142
NoteDescriptor noteDescriptor=new NoteDescriptor("Spectrum_Location");
143-
spectrumbuffer.append("Spectrum_Location="+((Note)spectrum.getNotes(noteDescriptor).get(0)).getValue()+endofline+"\r\n");//TODO
143+
spectrumbuffer.append("Spectrum_Location="+((Note)spectrum.getNotes(noteDescriptor).get(0)).getValue()+endofline+"\r\n");
144+
NoteDescriptor jcamplocationNoteDescriptor=new NoteDescriptor("Jcamp_location");
145+
if(spectrum.getNotes(jcamplocationNoteDescriptor)!=null)
146+
spectrumbuffer.append("Jcamp_location="+((Note)spectrum.getNotes(jcamplocationNoteDescriptor).get(0)).getValue()+endofline+"\r\n");
144147
NoteDescriptor jcampDescriptor=new NoteDescriptor("Spectrum_Jcamp");
145148
if(data.getVersion().compareTo(NmreData.NmredataVersion.ONEPOINTONE)>0 && spectrum.getNotes(jcampDescriptor)!=null && spectrum.getNotes(jcampDescriptor).size()>0 && ((Note)spectrum.getNotes(jcampDescriptor).get(0)).getValue()!=null)
146149
spectrumbuffer.append("Spectrum_Jcamp="+((Note)spectrum.getNotes(jcampDescriptor).get(0)).getValue()+endofline+"\r\n");

lib/src/test/java/de/unikoeln/chemie/nmr/NmredataWriterTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public void testWriteSelectiveTocsy() throws JCAMPException, CloneNotSupportedEx
7676
data.addSpectrum(new SelectiveNMR1DSpectrum(new OrderedArrayData(new double[] {1}, CommonUnit.hertz), new ArrayData(new double[] {1}, CommonUnit.intensity), 0, 0, "1H", "1H"));
7777
((NMRSpectrum)data.getSpectra().get(0)).setPeakTable((Peak1D[])peaks);
7878
((NMRSpectrum)data.getSpectra().get(0)).setNote(new NoteDescriptor("Spectrum_Location"),"test");
79+
((NMRSpectrum)data.getSpectra().get(0)).setNote(new NoteDescriptor("Jcamp_location"),"jcamptest");
7980
((NMRSpectrum)data.getSpectra().get(0)).setNote(new NoteDescriptor("CorType"),"test");
8081
data.setVersion(NmredataVersion.ONEPOINTONE);
8182
File testfile=new File(System.getProperty("java.io.tmpdir")+"/test.nmredata.sd");
@@ -88,7 +89,7 @@ public void testWriteSelectiveTocsy() throws JCAMPException, CloneNotSupportedEx
8889
fos.close();
8990
System.out.print(fos.toString());
9091
Assert.assertTrue(fos.toString().contains("NMREDATA_1D_1H_D_1H"));
91-
92+
Assert.assertTrue(fos.toString().contains("Jcamp_location=jcamptest"));
9293
}
9394

9495
public static void writeStandardFile() throws JCAMPException, CloneNotSupportedException, CDKException, IOException{

0 commit comments

Comments
 (0)