package org.autoplot.idlsupport; import java.io.File; import java.io.FileOutputStream; import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import org.das2.datum.Units; import org.das2.datum.UnitsConverter; import org.das2.datum.UnitsUtil; import org.das2.util.monitor.ProgressMonitor; import org.das2.qds.QDataSet; import org.das2.qds.SemanticOps; import org.autoplot.datasource.AbstractDataSourceFormat; import org.das2.qds.DataSetUtil; import org.das2.qds.ops.Ops; /** * Export to idlsav support. rank 0, rank 1 datasets, rank 2 datasets, rank 3 datasets, and rank 2 bundles are supported. * @author jbf */ public class IdlsavDataSourceFormat extends AbstractDataSourceFormat { private void doOne( WriteIDLSav write, QDataSet data, String guessName ) { String su= getParam( "tunits", "t1970" ); QDataSet wds= Ops.valid(data); Object odd; if ( data.rank()==0 ) { odd= data.value(); } else if ( data.rank()==1 ) { double[] dd= new double[data.length()]; for ( int i=0; iInteger.MAX_VALUE ) { throw new IllegalArgumentException("Unable to read large IDLSav files"); } ByteBuffer byteBuffer; try (FileChannel fc = new RandomAccessFile( f, "r" ).getChannel()) { byteBuffer = ByteBuffer.allocate((int) f.length()); fc.read(byteBuffer); } String[] names= reader.readVarNames( byteBuffer ); for ( String n: names ) { QDataSet v= IdlsavDataSource.getArray( reader, byteBuffer, n ); doOne( write, v, n ); } } if ( data.rank()!=1 && data.rank()!=2 && data.rank()!=3 ) { //TODO: I don't think this code is ever used. if ( SemanticOps.isBundle(data) ) { formatRank2Bundle( uri, data, write, mon ); } else { throw new IllegalArgumentException("not supported, rank "+data.rank() ); } } else { QDataSet dep0= (QDataSet) data.property(QDataSet.DEPEND_0); if ( dep0!=null ) { doOne( write,dep0,"dep0" ); } doOne( write,data,"data" ); QDataSet dep1= (QDataSet) data.property(QDataSet.DEPEND_1); if ( dep1!=null ) { doOne( write,dep1,"dep1" ); } } setUri(uri); File f= new File( getResourceURI().toURL().getFile() ); try (FileOutputStream fos = new FileOutputStream(f)) { write.write( fos ); } } @Override public boolean canFormat(QDataSet ds) { return DataSetUtil.isQube(ds) && ( ds.rank()==1 || ds.rank()==2 || ds.rank()==3 ); } @Override public String getDescription() { return "IDL Saveset"; } }