Created
August 7, 2014 14:40
-
-
Save tolik518/247e3086467c525c1039 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package dataReader; | |
| import java.io.*; | |
| public class Reader | |
| { | |
| public static void main(String[] args) | |
| { | |
| try | |
| { | |
| readFile("TRL1_000.000"); | |
| //readFile("testFile.txt"); | |
| } | |
| catch (Exception e) | |
| { | |
| } | |
| } | |
| public static RandomAccessFile file; | |
| public static void readFile(String fileName) | |
| { | |
| //--------------------------------------------------------------------------------------------------- | |
| //http://imos-toolbox.googlecode.com/svn/wiki/documents/Instruments/RDI/Workhorse_Quartermaster_ADCP/WorkHorse_Commands_and_Output_Data_Format_Nov07.pdf | |
| //https://code.google.com/p/imos-toolbox/wiki/RDI#Teledyne_RDI_supported_instruments | |
| //--------------------------------------------------------------------------------------------------- | |
| long length = 0; | |
| try | |
| { | |
| file = new RandomAccessFile(new File(fileName), "r"); | |
| length = file.length(); | |
| } | |
| catch (FileNotFoundException e) | |
| { | |
| e.printStackTrace(); | |
| } | |
| catch (IOException e) | |
| { | |
| e.printStackTrace(); | |
| } | |
| System.out.println("File name: " + fileName); | |
| System.out.println("File lenght: " + length + " bytes"); | |
| System.out.println(); | |
| //--------------------------------------------------------------------------------------------------- | |
| // Ab hier werden Daten gelesen | |
| // Metadaten / Header | |
| //--------------------------------------------------------------------------------------------------- | |
| //01,02: IdentificationByte | |
| int iIdentificationByte1 = readPosition(00); | |
| int iIdentificationByte2 = readPosition(01); | |
| String sIdentificationByte = String.format("%02X", iIdentificationByte1) +String.format("%02X", iIdentificationByte2); | |
| System.out.println("Headerbyte: 0x" + sIdentificationByte); | |
| if (sIdentificationByte.equals("7F7F")) | |
| { | |
| //03,04: Number of bytes? | |
| int iNumberOfBytes1 = readPosition(02); | |
| int iNumberOfBytes2 = readPosition(03); | |
| String sNumberOfBytes = String.format("%02X", iNumberOfBytes1) + String.format("%02X", iNumberOfBytes2); | |
| System.out.println("Number of bytes: 0x" + sNumberOfBytes); | |
| //06: Number of datatypes | |
| int iNumberDatatypes = readPosition(05); | |
| System.out.println("Number of datatypes: " + iNumberDatatypes); | |
| //7-12; offsets der datentypen | |
| for (int j = 1; j<=iNumberDatatypes; j++) | |
| { | |
| int iDatatypeOffset1 = readPosition(2*j+4); | |
| int iDatatypeOffset2 = readPosition(2*j+5); | |
| System.out.println("Datatype "+j+ " Offset: 0x" + String.format("%02X", iDatatypeOffset1) + String.format("%02X", iDatatypeOffset2)); | |
| } | |
| //Fixed Leader Data Format | |
| //20,21: CPU version | |
| System.out.println(); | |
| int iCpuVersion = readPosition(20); | |
| int iCpuRevision = readPosition(21); | |
| String sVersion = iCpuVersion +"."+ iCpuRevision; | |
| System.out.println("CPU Version: " + sVersion); | |
| //22: System config (binär) | |
| int iSysConfig1 = readPosition(22); | |
| System.out.println("> Configuration"); | |
| // frequency | |
| int iSysConfigFreq = iSysConfig1 & 0b00000111; | |
| int iFrequency = 75; | |
| iFrequency = iFrequency << iSysConfigFreq; /* 000 := 75-kHz / 001 := 150-kHz / 010 := 300-kHz / 011 := 600-kHz / 100 := 1200-kHz / 101 := 2400-kHz */ | |
| System.out.println(" Frequency: " + (iFrequency) +" kHz"); | |
| // concave/convex BEAM PAT. | |
| int iSysConfigCon = iSysConfig1 & 0b00001000; | |
| System.out.println(" Concave beam pat.: " + (iSysConfigCon == 0)); | |
| System.out.println(" Convex beam pat.: " + (iSysConfigCon == 8)); | |
| // Sensor config | |
| int iSysConfigSensor = iSysConfig1 & 0b00110000; | |
| int iSensorConfig = iSysConfigSensor >> 4; | |
| System.out.println(" Sensor config: #"+ iSensorConfig+1); | |
| // XDCR HD | |
| int iSysConfigXDCR = iSysConfig1 & 0b01000000; | |
| int iXDCRAttached = iSysConfigXDCR >> 6; | |
| System.out.println(" XDCR attached: "+ (iXDCRAttached == 1)); | |
| //Beam down/up facing | |
| int iSysConfigBeam = iSysConfig1 & 0b10000000; | |
| int iBeamFacingUp = iSysConfigBeam >> 7; | |
| System.out.println(" Beam facing up: "+ (iBeamFacingUp == 1)); | |
| //23: System config (binär) | |
| int iSysConfig2 = readPosition(23); | |
| //beam angle | |
| int iSysConfigAngle = iSysConfig2 & 0b00000011; | |
| switch(iSysConfigAngle) | |
| { | |
| case 0: | |
| System.out.println(" Beam angle: 15e"); break; | |
| case 1: | |
| System.out.println(" Beam angle: 20e"); break; | |
| case 2: | |
| System.out.println(" Beam angle: 30e"); break; | |
| case 3: | |
| System.out.println(" Beam angle: n/a"); break; | |
| } | |
| //BEAM JANUS CONFIG | |
| int iSysConfigJanus = iSysConfig2 & 0b11110000; | |
| switch(iSysConfigJanus) | |
| { | |
| case 64: | |
| System.out.println(" Beam Configuration: 4 beams, janus"); break; | |
| case 80: | |
| System.out.println(" Beam Configuration: 5 beams, janus"); break; | |
| case 240 : | |
| System.out.println(" Beam Configuration: 5 beams, janus"); break; | |
| } | |
| System.out.println(); | |
| int iProof0 = readPosition(24); | |
| System.out.println("> If this is not 0, then something is broken: " + iProof0); | |
| //25: Lag Length | |
| int iLagDuration = readPosition(25); | |
| System.out.println("Lag lenght: " + String.format("%02d",iLagDuration)); | |
| //26: #Bm / Number of Beams / Number of beams used to calculate velocity data (not physical beams) | |
| int iBeamCount = readPosition(26); | |
| System.out.println("Number of beams: " + String.format("%02d",iBeamCount)); | |
| //27: WN / Number of Cells | |
| int iCellCount = readPosition(27); | |
| System.out.println("Number of cells: " + String.format("%02d",iCellCount) + " depth cells"); | |
| //28,29: WP / Pings Per Ensemble | |
| int iPingsPerEnsemble1 = readPosition(28); | |
| int iPingsPerEnsemble2 = readPosition(29); | |
| String sPingsPerEnsemble = String.format("%02X", iPingsPerEnsemble1) + String.format("%02X", iPingsPerEnsemble2); | |
| System.out.println("Pings per ensemble: " + Integer.parseInt(sPingsPerEnsemble, 16)+" pings"); | |
| //30,31: WS / Depth Cell Length /Range = 1 to 6400 cm /steht scheinbar nicht hexadezimal in der datei | |
| int iDepthCellLength1 = readPosition(30); | |
| int iDepthCellLength2 = readPosition(31); | |
| String iDepthCellLength = String.format("%02X", iDepthCellLength2) + "" + String.format("%02X", iDepthCellLength1); | |
| System.out.println("Depth cell length: "+ Integer.parseInt(iDepthCellLength, 16) +" cm"); | |
| //32,33: WF / Blank after Transmit | |
| int iBlankAfterTransmit1 = readPosition(32); | |
| int iBlankAfterTransmit2 = readPosition(33); | |
| String iBlankAfterTransmit = String.format("%02X", iBlankAfterTransmit2) + "" + String.format("%02X", iBlankAfterTransmit1); | |
| System.out.println("Blank after Transmit: "+ Integer.parseInt(iBlankAfterTransmit, 16) +" cm"); | |
| //34: Signal Processing Mode | |
| int iProof1 = readPosition(34); | |
| System.out.println("> If this is not 1, then something is broken: " + iProof1); | |
| //35: WC / Low Corr Thresh | |
| int iLowCorrThresh = readPosition(35); | |
| System.out.println("Low Corr Thresh: " + iLowCorrThresh); | |
| //36: cr# / No. code reps /Contains the number of code repetitions in the transmit pulse. | |
| int iNoCodeReps = readPosition(36); | |
| System.out.println("No. code reps: " + iNoCodeReps); | |
| //37: WG / %Gd Minimum | |
| int iGdMinimum = readPosition(37); | |
| System.out.println("%Gd Minimum: " + iGdMinimum); | |
| //38,39: WE / Error Velocity Threshold | |
| int iErrorVelocityThreshold1 = readPosition(38); | |
| int iErrorVelocityThreshold2 = readPosition(39); | |
| String iErrorVelocityThreshold = String.format("%02X", iErrorVelocityThreshold2) + "" + String.format("%02X", iErrorVelocityThreshold1); | |
| System.out.println("Error Velocity Threshold : "+ Integer.parseInt(iErrorVelocityThreshold, 16) +" mm/s"); | |
| //40,41,42 Minutes/Seconds/Hundredths | time between ping groups in the ensemble | |
| int iMinutesBetweenPings = readPosition(40); | |
| int iSecondsBetweenPings = readPosition(41); | |
| int iHunderdthsBetweenPings = readPosition(42); | |
| String sMinutesBetweenPings = String.format("%02d", iMinutesBetweenPings); | |
| String sSecondsBetweenPings = String.format("%02d", iSecondsBetweenPings); | |
| String sHunderdthsBetweenPings = String.format("%02d", iHunderdthsBetweenPings); | |
| System.out.println("Time between pings: " + sMinutesBetweenPings+ "min " + sSecondsBetweenPings + "sec " + sHunderdthsBetweenPings +"ms "); | |
| //81-86: Datum | |
| int iYear = readPosition(81); | |
| int iMonth = readPosition(82); | |
| int iDay = readPosition(83); | |
| int iHour = readPosition(84); | |
| int iMinute = readPosition(85); | |
| int iSecond = readPosition(86); | |
| String sYear = String.format("20%2d", iYear); | |
| String sMonth = String.format("%02d", iMonth); | |
| String sDay = String.format("%02d", iDay); | |
| String sHour = String.format("%02d", iHour); | |
| String sMinute = String.format("%02d", iMinute); | |
| String sSecond = String.format("%02d", iSecond); | |
| System.out.println("Date: " + sDay+ "/" + sMonth + "/" +sYear); | |
| System.out.println("Time: " + sHour+ ":" + sMinute + ":" +sSecond); | |
| } | |
| else | |
| { | |
| System.out.print("> Identification byte wurde konnte nicht identifiziert werden. \n"); | |
| } | |
| } | |
| public static int readPosition(int Positon) | |
| { | |
| int iValue =0; | |
| try { | |
| file.seek(Positon); | |
| iValue = file.read(); | |
| //String sValue = String.format("%02X", iValue); | |
| } | |
| catch (IOException e) | |
| { | |
| e.printStackTrace(); | |
| } | |
| return iValue; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment