Skip to content

Commit 938a7b6

Browse files
committed
Add easy way to find scalar time stamps; fix bug in whereby array subsets not managed correctly when writing data
1 parent f79c5bb commit 938a7b6

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

bgs/geophys/library/Data/ImagCDF/ImagCDF.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,16 +588,26 @@ public ImagCDFVariableTS findVectorTimeStamps ()
588588
* @return the element index or a -ve number if there is no scalar element in the file */
589589
public int findScalarElement ()
590590
{
591-
int count;
592-
593-
for (count=0; count<elements.length; count++)
591+
for (int count=0; count<elements.length; count++)
594592
{
595593
if (elements[count].isScalarGeomagneticData())
596594
return count;
597595
}
598596
return -1;
599597
}
600598

599+
/** find the timestamps for scalar data which may be the same as
600+
* those for vector data, or may not exist
601+
* @return a time stamp object or null if there is no scalar data
602+
*/
603+
public ImagCDFVariableTS findScalarTimeStamps ()
604+
{
605+
int scalar_index = findScalarElement();
606+
if (scalar_index < 0) return null;
607+
ImagCDFVariable scalar_element = getElement(scalar_index);
608+
return findTimeStamps(scalar_element);
609+
}
610+
601611
/** get the element code string corresponding to the given vector and scalar elements
602612
* @param vector_indices the indexes to the vector elements
603613
* @param scalar_index the index to the scalar element OR -ve for no scalar index

bgs/geophys/library/Data/ImagCDF/ImagCDFLowLevel.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,15 @@ public void addData (Variable var, int rec_no, double data [])
333333
public void addData (Variable var, int rec_no, double data [], int data_offset, int data_length)
334334
throws CDFException
335335
{
336-
var.putHyperData (rec_no, data_length, 1, new long [] {data_offset}, new long [] {data_length}, new long [] {0}, data);
336+
double data_slice [];
337+
if (data_offset != 0 || data_length != data.length)
338+
{
339+
// we need to slice the data - I can't see a way to do this with the Java CDF library
340+
data_slice = new double [data_length];
341+
System.arraycopy(data, data_offset, data_slice, 0, data_length);
342+
}
343+
else data_slice = data;
344+
var.putHyperData (rec_no, data_length, 1, new long [] {0}, new long [] {data_length}, new long [] {0}, data_slice);
337345
}
338346

339347
/** put a time stamp into a record in the CDF file
@@ -368,7 +376,15 @@ public void addTimeStamp (Variable var, int rec_no, long data [])
368376
public void addTimeStamp (Variable var, int rec_no, long data [], int data_offset, int data_length)
369377
throws CDFException
370378
{
371-
var.putHyperData (rec_no, data_length, 1, new long [] {data_offset}, new long [] {data_length}, new long [] {0}, data);
379+
long data_slice [];
380+
if (data_offset != 0 || data_length != data.length)
381+
{
382+
// we need to slice the data - I can't see a way to do this with the Java CDF library
383+
data_slice = new long [data_length];
384+
System.arraycopy(data, data_offset, data_slice, 0, data_length);
385+
}
386+
else data_slice = data;
387+
var.putHyperData (rec_no, data_length, 1, new long [] {0}, new long [] {data_length}, new long [] {0}, data_slice);
372388
}
373389

374390

0 commit comments

Comments
 (0)