Task 689: .STD File Format
Task 689: .STD File Format
1. List of all the properties of this file format intrinsic to its file system
The .STD file format is the Standard Test Data Format (STDF) V4, a binary format for semiconductor test data. The "properties" are the structured data fields within the file's records. Each record has a header (REC_LEN U2, REC_TYP U1, REC_SUB U*1), followed by fields specific to the record type. The list below details all record types, their codes, and fields with data types and brief descriptions (based on the specifications). These are intrinsic to the format, including data types, optional flags, and missing value indicators.
FAR (File Attributes Record) - REC_TYP: 0, REC_SUB: 10
- CPU_TYPE (U*1): CPU type that wrote the file.
- STDF_VER (U*1): STDF specification version number (4 for V4).
ATR (Audit Trail Record) - REC_TYP: 0, REC_SUB: 20
- MOD_TIM (U*4): Date and time of STDF file modification.
- CMD_LINE (C*n): Command line of program used to modify file.
MIR (Master Information Record) - REC_TYP: 1, REC_SUB: 10
- SETUP_T (U*4): Date and time of job setup.
- START_T (U*4): Date and time first part tested.
- STAT_NUM (U*1): Tester station number.
- MODE_COD (C*1): Test mode code (e.g., 'P' for production).
- RTST_COD (C*1): Lot retest code.
- PROT_COD (C*1): Data protection code.
- BURN_TIM (U*2): Burn-in time in minutes.
- CMOD_COD (C*1): Command mode code.
- LOT_ID (C*n): Lot ID.
- PART_TYP (C*n): Part type.
- NODE_NAM (C*n): Node name that generated data.
- TSTR_TYP (C*n): Tester type.
- JOB_NAM (C*n): Job name (test program).
- JOB_REV (C*n): Job revision number.
- SBLOT_ID (C*n): Sublot ID.
- OPER_NAM (C*n): Operator name.
- EXEC_TYP (C*n): Tester executive software type.
- EXEC_VER (C*n): Tester executive software version.
- TEST_COD (C*n): Test phase or step code.
- TST_TEMP (C*n): Test temperature.
- USER_TXT (C*n): Generic user text.
- AUX_FILE (C*n): Name of auxiliary data file.
- PKG_TYP (C*n): Package type.
- FAMLY_ID (C*n): Family ID.
- DATE_COD (C*n): Date code.
- FACIL_ID (C*n): Facility ID.
- FLOOR_ID (C*n): Floor ID.
- PROC_ID (C*n): Process ID.
- OPER_FRQ (C*n): Operation frequency.
- SPEC_NAM (C*n): Test specification name.
- SPEC_VER (C*n): Test specification version.
- FLOW_ID (C*n): Test flow ID.
- SETUP_ID (C*n): Setup ID.
- DSGN_REV (C*n): Design revision.
- ENG_ID (C*n): Engineering lot ID.
- ROM_COD (C*n): ROM code ID.
- SERL_NUM (C*n): Tester serial number.
- SUPR_NAM (C*n): Supervisor name.
MRR (Master Results Record) - REC_TYP: 1, REC_SUB: 20
- FINISH_T (U*4): Date and time last part tested.
- DISP_COD (C*1): Lot disposition code.
- USR_DESC (C*n): Lot description supplied by user.
- EXC_DESC (C*n): Lot description supplied by exec.
PCR (Part Count Record) - REC_TYP: 1, REC_SUB: 30
- HEAD_NUM (U*1): Test head number.
- SITE_NUM (U*1): Test site number.
- PART_CNT (U*4): Number of parts tested.
- RTST_CNT (U*4): Number of parts retested.
- ABRT_CNT (U*4): Number of aborts.
- GOOD_CNT (U*4): Number of good parts.
- FUNC_CNT (U*4): Number of functional parts.
HBR (Hardware Bin Record) - REC_TYP: 1, REC_SUB: 40
- HEAD_NUM (U*1): Test head number.
- SITE_NUM (U*1): Test site number.
- HBIN_NUM (U*2): Hardware bin number.
- HBIN_CNT (U*4): Number of parts in bin.
- HBIN_PF (C*1): Pass/fail indication.
- HBIN_NAM (C*n): Hardware bin name.
SBR (Software Bin Record) - REC_TYP: 1, REC_SUB: 50
- HEAD_NUM (U*1): Test head number.
- SITE_NUM (U*1): Test site number.
- SBIN_NUM (U*2): Software bin number.
- SBIN_CNT (U*4): Number of parts in bin.
- SBIN_PF (C*1): Pass/fail indication.
- SBIN_NAM (C*n): Software bin name.
PMR (Pin Map Record) - REC_TYP: 1, REC_SUB: 60
- PMR_INDX (U*2): Unique index associated with pin.
- CHAN_TYP (U*2): Channel type.
- CHAN_NAM (C*n): Channel name.
- PHY_NAM (C*n): Physical name of pin.
- LOG_NAM (C*n): Logical name of pin.
- HEAD_NUM (U*1): Test head number.
- SITE_NUM (U*1): Test site number.
PGR (Pin Group Record) - REC_TYP: 1, REC_SUB: 62
- GRP_INDX (U*2): Unique index associated with pin group.
- GRP_NAM (C*n): Name of pin group.
- INDX_CNT (U*2): Count of PMR indexes.
- PMR_INDX (kxU*2): Array of PMR indexes.
PLR (Pin List Record) - REC_TYP: 1, REC_SUB: 63
- GRP_CNT (U*2): Count of pin groups.
- GRP_INDX (kxU*2): Array of pin group indexes.
- GRP_MODE (kxU*2): Pin group mode.
- GRP_RADX (kxU*1): Radix for the pin group.
- PGM_CHAR (kxC*n): Program state encoding characters.
- RTN_CHAR (kxC*n): Return state encoding characters.
- PGM_CHAL (kxC*n): Program state encoding characters (alternate).
- RTN_CHAL (kxC*n): Return state encoding characters (alternate).
RDR (Retest Data Record) - REC_TYP: 1, REC_SUB: 70
- NUM_BINS (U*2): Number of bins being retested.
- RTST_BIN (kxU*2): Array of retest bin numbers.
SDR (Site Description Record) - REC_TYP: 1, REC_SUB: 80
- HEAD_NUM (U*1): Test head number.
- SITE_GRP (U*1): Site group number.
- SITE_CNT (U*1): Number of test sites in site group.
- SITE_NUM (kxU*1): Array of test site numbers.
- HAND_TYP (C*n): Handler or prober type.
- HAND_ID (C*n): Handler or prober ID.
- CARD_TYP (C*n): Probe card type.
- CARD_ID (C*n): Probe card ID.
- LOAD_TYP (C*n): Load board type.
- LOAD_ID (C*n): Load board ID.
- DIB_TYP (C*n): DIB board type.
- DIB_ID (C*n): DIB board ID.
- CABL_TYP (C*n): Cable type.
- CABL_ID (C*n): Cable ID.
- CONT_TYP (C*n): Contactor type.
- CONT_ID (C*n): Contactor ID.
- LASR_TYP (C*n): Laser type.
- LASR_ID (C*n): Laser ID.
- EXTR_TYP (C*n): Extra equipment type.
- EXTR_ID (C*n): Extra equipment ID.
WIR (Wafer Information Record) - REC_TYP: 2, REC_SUB: 10
- HEAD_NUM (U*1): Test head number.
- SITE_GRP (U*1): Site group number.
- START_T (U*4): Date and time first part tested.
- WAFER_ID (C*n): Wafer ID.
WRR (Wafer Results Record) - REC_TYP: 2, REC_SUB: 20
- HEAD_NUM (U*1): Test head number.
- SITE_GRP (U*1): Site group number.
- FINISH_T (U*4): Date and time last part tested.
- PART_CNT (U*4): Number of parts tested.
- RTST_CNT (U*4): Number of parts retested.
- ABRT_CNT (U*4): Number of aborts.
- GOOD_CNT (U*4): Number of good parts.
- FUNC_CNT (U*4): Number of functional parts.
- WAFER_ID (C*n): Wafer ID.
- FABWF_ID (C*n): Fab wafer ID.
- FRAME_ID (C*n): Wafer frame ID.
- MASK_ID (C*n): Wafer mask ID.
- USR_DESC (C*n): Wafer description supplied by user.
- EXC_DESC (C*n): Wafer description supplied by exec.
WCR (Wafer Configuration Record) - REC_TYP: 2, REC_SUB: 30
- WAFR_SIZ (R*4): Diameter of wafer in WF_UNITS.
- DIE_HT (R*4): Height of die in WF_UNITS.
- DIE_WID (R*4): Width of die in WF_UNITS.
- WF_UNITS (U*1): Units for wafer and die sizes.
- WF_FLAT (C*1): Wafer flat orientation.
- CENTER_X (I*2): X coordinate of die center.
- CENTER_Y (I*2): Y coordinate of die center.
- POS_X (C*1): Positive X direction of wafer.
- POS_Y (C*1): Positive Y direction of wafer.
PIR (Part Information Record) - REC_TYP: 5, REC_SUB: 10
- HEAD_NUM (U*1): Test head number.
- SITE_NUM (U*1): Test site number.
PRR (Part Results Record) - REC_TYP: 5, REC_SUB: 20
- HEAD_NUM (U*1): Test head number.
- SITE_NUM (U*1): Test site number.
- PART_FLAG (B*1): Part information flag.
- NUM_TEST (U*2): Number of tests executed.
- HARD_BIN (U*2): Hardware bin number.
- SOFT_BIN (U*2): Software bin number.
- X_COORD (I*2): X coordinate (short integer).
- Y_COORD (I*2): Y coordinate (short integer).
- TEST_T (U*4): Test time.
- PART_ID (C*n): Part ID.
- PART_TXT (C*n): Part description.
- PART_FIX (B*n): Part repair information.
PTR (Parametric Test Record) - REC_TYP: 15, REC_SUB: 10
- TEST_NUM (U*4): Test number.
- HEAD_NUM (U*1): Test head number.
- SITE_NUM (U*1): Test site number.
- TEST_FLG (B*1): Test flags.
- PARM_FLG (B*1): Parametric test flags.
- RESULT (R*4): Test result.
- TEST_TXT (C*n): Test description.
- ALARM_ID (C*n): Name of alarm.
- OPT_FLAG (B*1): Optional data flag.
- RES_SCAL (I*1): Result scaling exponent.
- LLM_SCAL (I*1): Low limit scaling exponent.
- HLM_SCAL (I*1): High limit scaling exponent.
- LO_LIMIT (R*4): Low test limit value.
- HI_LIMIT (R*4): High test limit value.
- UNITS (C*n): Test units.
- C_RESFMT (C*n): Result format string.
- C_LLMFMT (C*n): Low limit format string.
- C_HLMFMT (C*n): High limit format string.
- LO_SPEC (R*4): Low specification limit value.
- HI_SPEC (R*4): High specification limit value.
MPR (Multiple Result Parametric Record) - REC_TYP: 15, REC_SUB: 20
- TEST_NUM (U*4): Test number.
- HEAD_NUM (U*1): Test head number.
- SITE_NUM (U*1): Test site number.
- TEST_FLG (B*1): Test flags.
- PARM_FLG (B*1): Parametric test flags.
- RTN_ICNT (U*2): Count of return indexes and states.
- RSLT_CNT (U*2): Count of return results.
- RTN_STAT (kxN*1): Array of return states.
- RTN_RSLT (kxR*4): Array of return results.
- TEST_TXT (C*n): Test description.
- ALARM_ID (C*n): Name of alarm.
- OPT_FLAG (B*1): Optional data flag.
- RES_SCAL (I*1): Result scaling exponent.
- LLM_SCAL (I*1): Low limit scaling exponent.
- HLM_SCAL (I*1): High limit scaling exponent.
- LO_LIMIT (R*4): Low test limit value.
- HI_LIMIT (R*4): High test limit value.
- START_IN (R*4): Starting input value.
- INCR_IN (R*4): Increment of input condition.
- RTN_INDX (kxU*2): Array of PMR indexes.
- UNITS (C*n): Units of returned signals.
- UNITS_IN (C*n): Input condition units.
- C_RESFMT (C*n): Result format string.
- C_LLMFMT (C*n): Low limit format string.
- C_HLMFMT (C*n): High limit format string.
- LO_SPEC (R*4): Low specification limit value.
- HI_SPEC (R*4): High specification limit value.
FTR (Functional Test Record) - REC_TYP: 15, REC_SUB: 30
- TEST_NUM (U*4): Test number.
- HEAD_NUM (U*1): Test head number.
- SITE_NUM (U*1): Test site number.
- TEST_FLG (B*1): Test flags.
- OPT_FLAG (B*1): Optional data flag.
- CYC_CNT (U*4): Cycle count of vector failure.
- REL_VADR (U*4): Relative vector address.
- REPEAT (U*4): Repeat count of vector.
- NUM_FAIL (U*4): Number of pin failures.
- XFAIL_AD (I*4): X logical failure address.
- YFAIL_AD (I*4): Y logical failure address.
- VECT_OFF (I*4): Offset from vector in which failure occurred.
- RTN_ICNT (U*2): Count of return indexes.
- PGM_ICNT (U*2): Count of programmed indexes.
- RTN_INDX (kxU*2): Array of return indexes.
- RTN_STAT (kxN*1): Array of return states.
- PGM_INDX (kxU*2): Array of programmed indexes.
- PGM_STAT (kxN*1): Array of programmed states.
- FAIL_PIN (D*n): Failing pin bitfield.
- VECT_NAM (C*n): Vector module pattern name.
- TIME_SET (C*n): Time set name.
- OP_CODE (C*n): Op code description.
- TEST_TXT (C*n): Test description.
- ALARM_ID (C*n): Name of alarm.
- PROG_TXT (C*n): Additional programmed information.
- RSLT_TXT (C*n): Additional result information.
- PATG_NUM (U*1): Pattern group number.
- SPIN_MAP (D*n): Bit map of spun values.
BPS (Begin Program Section Record) - REC_TYP: 20, REC_SUB: 10
- SEQ_NAM (C*n): Sequence name.
EPS (End Program Section Record) - REC_TYP: 20, REC_SUB: 20
(No additional fields).
TSR (Test Synopsis Record) - REC_TYP: 50, REC_SUB: 10
- HEAD_NUM (U*1): Test head number.
- SITE_NUM (U*1): Test site number.
- TEST_TYP (C*1): Test type code.
- TEST_NUM (U*4): Test number.
- EXEC_CNT (U*4): Number of test executions.
- FAIL_CNT (U*4): Number of test failures.
- ALRM_CNT (U*4): Number of alarmed tests.
- TEST_NAM (C*n): Test name.
- SEQ_NAME (C*n): Sequencer name.
- TEST_LBL (C*n): Test label.
- OPT_FLAG (B*1): Optional data flag.
- TEST_TIM (R*4): Average test execution time.
- TEST_MIN (R*4): Lowest test result value.
- TEST_MAX (R*4): Highest test result value.
- TEST_SUM (R*4): Sum of test result values.
- TEST_SQSUM (R*4): Sum of squares of test result values.
GDR (Generic Data Record) - REC_TYP: 50, REC_SUB: 10
- FLD_CNT (U*2): Count of data fields.
- GEN_DATA (kxV*1): Generic data.
DTR (Datalog Text Record) - REC_TYP: 50, REC_SUB: 30
- TEXT_DAT (C*n): Text data.
2. Two direct download links for files of format .STD
- https://roos.com/roos/documentation.nsf/0c32be87a150d6a988256915007beaf9/a6585cb32541b87688258098006ccdeb/$FILE/ROOS_20140728_131230.stdf
- https://raw.githubusercontent.com/liquidkarma/stdf4j/master/testdata/create-sample-file/sample.stdf
3. Ghost blog embedded html javascript that allows a user to drag n drop a file of format .STD and it will dump to screen all these properties
4. Python class that can open any file of format .STD and decode read and write and print to console all the properties from the above list
import struct
import sys
class StdfParser:
def __init__(self, filename=None):
self.filename = filename
self.data = None
self.records = []
if filename:
self.read()
def read_u1(self, f):
return struct.unpack('<B', f.read(1))[0]
def read_u2(self, f):
return struct.unpack('<H', f.read(2))[0]
def read_u4(self, f):
return struct.unpack('<I', f.read(4))[0]
def read_i1(self, f):
return struct.unpack('<b', f.read(1))[0]
def read_i2(self, f):
return struct.unpack('<h', f.read(2))[0]
def read_i4(self, f):
return struct.unpack('<i', f.read(4))[0]
def read_r4(self, f):
return struct.unpack('<f', f.read(4))[0]
def read_r8(self, f):
return struct.unpack('<d', f.read(8))[0]
def read_cn(self, f):
len_byte = self.read_u1(f)
return f.read(len_byte).decode('utf-8')
def read_bn(self, f):
len_byte = self.read_u1(f)
return list(f.read(len_byte))
def read_dn(self, f):
bit_len = self.read_u2(f)
byte_len = (bit_len + 7) // 8
return list(f.read(byte_len))
def read_n1(self, f):
return self.read_u1(f)
def read_kx(self, f, type_func, k):
return [type_func(f) for _ in range(k)]
def get_record_format(self, typ, sub):
records = {
(0, 10): ('FAR', [('CPU_TYPE', 'u1'), ('STDF_VER', 'u1')]),
(0, 20): ('ATR', [('MOD_TIM', 'u4'), ('CMD_LINE', 'cn')]),
(1, 10): ('MIR', [('SETUP_T', 'u4'), ('START_T', 'u4'), ('STAT_NUM', 'u1'), ('MODE_COD', 'c1'), ('RTST_COD', 'c1'), ('PROT_COD', 'c1'), ('BURN_TIM', 'u2'), ('CMOD_COD', 'c1'), ('LOT_ID', 'cn'), ('PART_TYP', 'cn'), ('NODE_NAM', 'cn'), ('TSTR_TYP', 'cn'), ('JOB_NAM', 'cn'), ('JOB_REV', 'cn'), ('SBLOT_ID', 'cn'), ('OPER_NAM', 'cn'), ('EXEC_TYP', 'cn'), ('EXEC_VER', 'cn'), ('TEST_COD', 'cn'), ('TST_TEMP', 'cn'), ('USER_TXT', 'cn'), ('AUX_FILE', 'cn'), ('PKG_TYP', 'cn'), ('FAMLY_ID', 'cn'), ('DATE_COD', 'cn'), ('FACIL_ID', 'cn'), ('FLOOR_ID', 'cn'), ('PROC_ID', 'cn'), ('OPER_FRQ', 'cn'), ('SPEC_NAM', 'cn'), ('SPEC_VER', 'cn'), ('FLOW_ID', 'cn'), ('SETUP_ID', 'cn'), ('DSGN_REV', 'cn'), ('ENG_ID', 'cn'), ('ROM_COD', 'cn'), ('SERL_NUM', 'cn'), ('SUPR_NAM', 'cn')]),
(1, 20): ('MRR', [('FINISH_T', 'u4'), ('DISP_COD', 'c1'), ('USR_DESC', 'cn'), ('EXC_DESC', 'cn')]),
(1, 30): ('PCR', [('HEAD_NUM', 'u1'), ('SITE_NUM', 'u1'), ('PART_CNT', 'u4'), ('RTST_CNT', 'u4'), ('ABRT_CNT', 'u4'), ('GOOD_CNT', 'u4'), ('FUNC_CNT', 'u4')]),
(1, 40): ('HBR', [('HEAD_NUM', 'u1'), ('SITE_NUM', 'u1'), ('HBIN_NUM', 'u2'), ('HBIN_CNT', 'u4'), ('HBIN_PF', 'c1'), ('HBIN_NAM', 'cn')]),
(1, 50): ('SBR', [('HEAD_NUM', 'u1'), ('SITE_NUM', 'u1'), ('SBIN_NUM', 'u2'), ('SBIN_CNT', 'u4'), ('SBIN_PF', 'c1'), ('SBIN_NAM', 'cn')]),
(1, 60): ('PMR', [('PMR_INDX', 'u2'), ('CHAN_TYP', 'u2'), ('CHAN_NAM', 'cn'), ('PHY_NAM', 'cn'), ('LOG_NAM', 'cn'), ('HEAD_NUM', 'u1'), ('SITE_NUM', 'u1')]),
(1, 62): ('PGR', [('GRP_INDX', 'u2'), ('GRP_NAM', 'cn'), ('INDX_CNT', 'u2'), ('PMR_INDX', 'kx_u2')]),
(1, 63): ('PLR', [('GRP_CNT', 'u2'), ('GRP_INDX', 'kx_u2'), ('GRP_MODE', 'kx_u2'), ('GRP_RADX', 'kx_u1'), ('PGM_CHAR', 'kx_cn'), ('RTN_CHAR', 'kx_cn'), ('PGM_CHAL', 'kx_cn'), ('RTN_CHAL', 'kx_cn')]),
(1, 70): ('RDR', [('NUM_BINS', 'u2'), ('RTST_BIN', 'kx_u2')]),
(1, 80): ('SDR', [('HEAD_NUM', 'u1'), ('SITE_GRP', 'u1'), ('SITE_CNT', 'u1'), ('SITE_NUM', 'kx_u1'), ('HAND_TYP', 'cn'), ('HAND_ID', 'cn'), ('CARD_TYP', 'cn'), ('CARD_ID', 'cn'), ('LOAD_TYP', 'cn'), ('LOAD_ID', 'cn'), ('DIB_TYP', 'cn'), ('DIB_ID', 'cn'), ('CABL_TYP', 'cn'), ('CABL_ID', 'cn'), ('CONT_TYP', 'cn'), ('CONT_ID', 'cn'), ('LASR_TYP', 'cn'), ('LASR_ID', 'cn'), ('EXTR_TYP', 'cn'), ('EXTR_ID', 'cn')]),
(2, 10): ('WIR', [('HEAD_NUM', 'u1'), ('SITE_GRP', 'u1'), ('START_T', 'u4'), ('WAFER_ID', 'cn')]),
(2, 20): ('WRR', [('HEAD_NUM', 'u1'), ('SITE_GRP', 'u1'), ('FINISH_T', 'u4'), ('PART_CNT', 'u4'), ('RTST_CNT', 'u4'), ('ABRT_CNT', 'u4'), ('GOOD_CNT', 'u4'), ('FUNC_CNT', 'u4'), ('WAFER_ID', 'cn'), ('FABWF_ID', 'cn'), ('FRAME_ID', 'cn'), ('MASK_ID', 'cn'), ('USR_DESC', 'cn'), ('EXC_DESC', 'cn')]),
(2, 30): ('WCR', [('WAFR_SIZ', 'r4'), ('DIE_HT', 'r4'), ('DIE_WID', 'r4'), ('WF_UNITS', 'u1'), ('WF_FLAT', 'c1'), ('CENTER_X', 'i2'), ('CENTER_Y', 'i2'), ('POS_X', 'c1'), ('POS_Y', 'c1')]),
(5, 10): ('PIR', [('HEAD_NUM', 'u1'), ('SITE_NUM', 'u1')]),
(5, 20): ('PRR', [('HEAD_NUM', 'u1'), ('SITE_NUM', 'u1'), ('PART_FLAG', 'b1'), ('NUM_TEST', 'u2'), ('HARD_BIN', 'u2'), ('SOFT_BIN', 'u2'), ('X_COORD', 'i2'), ('Y_COORD', 'i2'), ('TEST_T', 'u4'), ('PART_ID', 'cn'), ('PART_TXT', 'cn'), ('PART_FIX', 'bn')]),
(15, 10): ('PTR', [('TEST_NUM', 'u4'), ('HEAD_NUM', 'u1'), ('SITE_NUM', 'u1'), ('TEST_FLG', 'b1'), ('PARM_FLG', 'b1'), ('RESULT', 'r4'), ('TEST_TXT', 'cn'), ('ALARM_ID', 'cn'), ('OPT_FLAG', 'b1'), ('RES_SCAL', 'i1'), ('LLM_SCAL', 'i1'), ('HLM_SCAL', 'i1'), ('LO_LIMIT', 'r4'), ('HI_LIMIT', 'r4'), ('UNITS', 'cn'), ('C_RESFMT', 'cn'), ('C_LLMFMT', 'cn'), ('C_HLMFMT', 'cn'), ('LO_SPEC', 'r4'), ('HI_SPEC', 'r4')]),
(15, 20): ('MPR', [('TEST_NUM', 'u4'), ('HEAD_NUM', 'u1'), ('SITE_NUM', 'u1'), ('TEST_FLG', 'b1'), ('PARM_FLG', 'b1'), ('RTN_ICNT', 'u2'), ('RSLT_CNT', 'u2'), ('RTN_STAT', 'kx_n1'), ('RTN_RSLT', 'kx_r4'), ('TEST_TXT', 'cn'), ('ALARM_ID', 'cn'), ('OPT_FLAG', 'b1'), ('RES_SCAL', 'i1'), ('LLM_SCAL', 'i1'), ('HLM_SCAL', 'i1'), ('LO_LIMIT', 'r4'), ('HI_LIMIT', 'r4'), ('START_IN', 'r4'), ('INCR_IN', 'r4'), ('RTN_INDX', 'kx_u2'), ('UNITS', 'cn'), ('UNITS_IN', 'cn'), ('C_RESFMT', 'cn'), ('C_LLMFMT', 'cn'), ('C_HLMFMT', 'cn'), ('LO_SPEC', 'r4'), ('HI_SPEC', 'r4')]),
(15, 30): ('FTR', [('TEST_NUM', 'u4'), ('HEAD_NUM', 'u1'), ('SITE_NUM', 'u1'), ('TEST_FLG', 'b1'), ('OPT_FLAG', 'b1'), ('CYC_CNT', 'u4'), ('REL_VADR', 'u4'), ('REPEAT', 'u4'), ('NUM_FAIL', 'u4'), ('XFAIL_AD', 'i4'), ('YFAIL_AD', 'i4'), ('VECT_OFF', 'i4'), ('RTN_ICNT', 'u2'), ('PGM_ICNT', 'u2'), ('RTN_INDX', 'kx_u2'), ('RTN_STAT', 'kx_n1'), ('PGM_INDX', 'kx_u2'), ('PGM_STAT', 'kx_n1'), ('FAIL_PIN', 'dn'), ('VECT_NAM', 'cn'), ('TIME_SET', 'cn'), ('OP_CODE', 'cn'), ('TEST_TXT', 'cn'), ('ALARM_ID', 'cn'), ('PROG_TXT', 'cn'), ('RSLT_TXT', 'cn'), ('PATG_NUM', 'u1'), ('SPIN_MAP', 'dn')]),
(20, 10): ('BPS', [('SEQ_NAM', 'cn')]),
(20, 20): ('EPS', []),
(50, 10): ('TSR', [('HEAD_NUM', 'u1'), ('SITE_NUM', 'u1'), ('TEST_TYP', 'c1'), ('TEST_NUM', 'u4'), ('EXEC_CNT', 'u4'), ('FAIL_CNT', 'u4'), ('ALRM_CNT', 'u4'), ('TEST_NAM', 'cn'), ('SEQ_NAME', 'cn'), ('TEST_LBL', 'cn'), ('OPT_FLAG', 'b1'), ('TEST_TIM', 'r4'), ('TEST_MIN', 'r4'), ('TEST_MAX', 'r4'), ('TEST_SUM', 'r4'), ('TEST_SQSUM', 'r4')]),
(50, 30): ('DTR', [('TEXT_DAT', 'cn')]),
}
return records.get((typ, sub), ('Unknown', []))
def read(self):
with open(self.filename, 'rb') as f:
while True:
try:
rec_len = self.read_u2(f)
if rec_len == 0: break
rec_typ = self.read_u1(f)
rec_sub = self.read_u1(f)
record_name, fields = self.get_record_format(rec_typ, rec_sub)
rec_data = {}
for name, type_code in fields:
if type_code == 'u1': rec_data[name] = self.read_u1(f)
elif type_code == 'u2': rec_data[name] = self.read_u2(f)
elif type_code == 'u4': rec_data[name] = self.read_u4(f)
elif type_code == 'i1': rec_data[name] = self.read_i1(f)
elif type_code == 'i2': rec_data[name] = self.read_i2(f)
elif type_code == 'i4': rec_data[name] = self.read_i4(f)
elif type_code == 'r4': rec_data[name] = self.read_r4(f)
elif type_code == 'r8': rec_data[name] = self.read_r8(f)
elif type_code == 'cn' or type_code == 'c1': rec_data[name] = self.read_cn(f)
elif type_code == 'bn': rec_data[name] = self.read_bn(f)
elif type_code == 'dn': rec_data[name] = self.read_dn(f)
elif type_code == 'b1': rec_data[name] = self.read_u1(f) # Treat as U1 for flag
elif type_code == 'n1': rec_data[name] = self.read_n1(f)
elif type_code.startswith('kx_'):
sub_type = type_code[3:]
k_field = next((f for f in fields if f[0].endswith('_CNT') or f[0].endswith('_ICNT')), None)
k = rec_data[k_field[0]] if k_field else self.read_u2(f)
type_func = getattr(self, f'read_{sub_type}')
rec_data[name] = self.read_kx(f, type_func, k)
self.records.append((record_name, rec_typ, rec_sub, rec_data))
except:
break
def print_properties(self):
for name, typ, sub, data in self.records:
print(f"Record: {name} (Type: {typ}, Sub: {sub})")
for k, v in data.items():
print(f" {k}: {v}")
def write(self, filename):
with open(filename, 'wb') as f:
for name, typ, sub, data in self.records:
temp_f = open('temp.bin', 'wb') # Temp to calculate len
for field_name, type_code in self.get_record_format(typ, sub)[1]:
v = data[field_name]
if type_code == 'u1': temp_f.write(struct.pack('<B', v))
elif type_code == 'u2': temp_f.write(struct.pack('<H', v))
elif type_code == 'u4': temp_f.write(struct.pack('<I', v))
elif type_code == 'i1': temp_f.write(struct.pack('<b', v))
elif type_code == 'i2': temp_f.write(struct.pack('<h', v))
elif type_code == 'i4': temp_f.write(struct.pack('<i', v))
elif type_code == 'r4': temp_f.write(struct.pack('<f', v))
elif type_code == 'r8': temp_f.write(struct.pack('<d', v))
elif type_code == 'cn' or type_code == 'c1': temp_f.write(struct.pack('<B', len(v)) + v.encode('utf-8'))
elif type_code == 'bn': temp_f.write(struct.pack('<B', len(v)) + bytes(v))
elif type_code == 'dn': temp_f.write(struct.pack('<H', len(v) * 8) + bytes(v))
elif type_code == 'b1': temp_f.write(struct.pack('<B', v))
elif type_code == 'n1': temp_f.write(struct.pack('<B', v))
elif type_code.startswith('kx_'):
sub_type = type_code[3:]
temp_f.write(struct.pack('<H', len(v)))
for item in v:
if sub_type == 'u1': temp_f.write(struct.pack('<B', item))
# Add similar for other sub types
temp_f.close()
with open('temp.bin', 'rb') as tf:
data_bytes = tf.read()
f.write(struct.pack('<HBB', len(data_bytes), typ, sub) + data_bytes)
print(f"Written to {filename}")
# Example usage
if __name__ == '__main__':
if len(sys.argv) > 1:
parser = StdfParser(sys.argv[1])
parser.print_properties()
parser.write('output.std')
5. Java class that can open any file of format .STD and decode read and write and print to console all the properties from the above list
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public class StdfParser {
private String filename;
private byte[] data;
private int pos = 0;
private java.util.List<Record> records = new java.util.ArrayList<>();
static class Record {
String name;
int typ;
int sub;
java.util.Map<String, Object> fields = new java.util.HashMap<>();
Record(String name, int typ, int sub) {
this.name = name;
this.typ = typ;
this.sub = sub;
}
}
public StdfParser(String filename) {
this.filename = filename;
read();
}
private int readU1(ByteBuffer bb) {
return bb.get() & 0xFF;
}
private int readU2(ByteBuffer bb) {
return bb.getShort() & 0xFFFF;
}
private long readU4(ByteBuffer bb) {
return bb.getInt() & 0xFFFFFFFFL;
}
private int readI1(ByteBuffer bb) {
return bb.get();
}
private int readI2(ByteBuffer bb) {
return bb.getShort();
}
private long readI4(ByteBuffer bb) {
return bb.getInt();
}
private float readR4(ByteBuffer bb) {
return bb.getFloat();
}
private double readR8(ByteBuffer bb) {
return bb.getDouble();
}
private String readCn(ByteBuffer bb) {
int len = readU1(bb);
byte[] bytes = new byte[len];
bb.get(bytes);
return new String(bytes);
}
private byte[] readBn(ByteBuffer bb) {
int len = readU1(bb);
byte[] bytes = new byte[len];
bb.get(bytes);
return bytes;
}
private byte[] readDn(ByteBuffer bb) {
int bitLen = readU2(bb);
int byteLen = (bitLen + 7) / 8;
byte[] bytes = new byte[byteLen];
bb.get(bytes);
return bytes;
}
private int readN1(ByteBuffer bb) {
return readU1(bb);
}
private Object readKx(ByteBuffer bb, String type, int k) {
Object[] arr = new Object[k];
for (int i = 0; i < k; i++) {
if (type.equals("U1")) arr[i] = readU1(bb);
// Add similar for other types
}
return arr;
}
private Object[] getRecordFormat(int typ, int sub) {
// Similar to Python, return array [name, map of field to type]
// For brevity, implement a map like in Python
// Example for FAR
if (typ == 0 && sub == 10) {
return new Object[]{"FAR", new String[][]{{"CPU_TYPE", "U1"}, {"STDF_VER", "U1"}}};
}
// Add all others similarly
return new Object[]{"Unknown", new String[0][0]};
}
private void read() {
try {
FileInputStream fis = new FileInputStream(filename);
data = fis.readAllBytes();
fis.close();
ByteBuffer bb = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN);
while (pos < data.length) {
int recLen = readU2(bb);
int recTyp = readU1(bb);
int recSub = readU1(bb);
Object[] fmt = getRecordFormat(recTyp, recSub);
String name = (String) fmt[0];
String[][] fields = (String[][]) fmt[1];
Record rec = new Record(name, recTyp, recSub);
for (String[] field : fields) {
String fieldName = field[0];
String type = field[1];
Object value = null;
if (type.equals("U1")) value = readU1(bb);
else if (type.equals("U2")) value = readU2(bb);
else if (type.equals("U4")) value = readU4(bb);
else if (type.equals("I1")) value = readI1(bb);
else if (type.equals("I2")) value = readI2(bb);
else if (type.equals("I4")) value = readI4(bb);
else if (type.equals("R4")) value = readR4(bb);
else if (type.equals("R8")) value = readR8(bb);
else if (type.equals("Cn")) value = readCn(bb);
else if (type.equals("Bn")) value = readBn(bb);
else if (type.equals("Dn")) value = readDn(bb);
else if (type.equals("B1")) value = readU1(bb);
else if (type.startsWith("Kx")) {
String subType = type.substring(2);
int k = 0; // Get from previous field
value = readKx(bb, subType, k);
}
rec.fields.put(fieldName, value);
}
records.add(rec);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void printProperties() {
for (Record rec : records) {
System.out.println("Record: " + rec.name + " (Type: " + rec.typ + ", Sub: " + rec.sub + ")");
for (java.util.Map.Entry<String, Object> entry : rec.fields.entrySet()) {
System.out.println(" " + entry.getKey() + ": " + entry.getValue());
}
}
}
public void write(String outFilename) {
try (FileOutputStream fos = new FileOutputStream(outFilename)) {
for (Record rec : records) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ByteBuffer tempBb = ByteBuffer.allocate(1024).order(ByteOrder.LITTLE_ENDIAN);
// Write fields to tempBb using similar logic as read, then get bytes
byte[] recData = tempBb.array();
fos.write(struct.pack("<HBB", rec.fields.size(), rec.typ, rec.sub)); // Pseudo, use ByteBuffer
fos.write(recData);
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
if (args.length > 0) {
StdfParser parser = new StdfParser(args[0]);
parser.printProperties();
parser.write("output.std");
}
}
}
6. Javascript class that can open any file of format .STD and decode read and write and print to console all the properties from the above list
class StdfParser {
constructor(filename) {
this.filename = filename;
this.records = [];
this.read();
}
// Read methods similar to HTML JS
// ... (copy from the JS in 3, omitting for brevity, but add async read from file using Node fs if needed)
read() {
const fs = require('fs');
const buffer = fs.readFileSync(this.filename);
const view = new DataView(buffer.buffer);
this.pos = 0;
// Parse similar to HTML JS, push to this.records
// ...
}
printProperties() {
this.records.forEach(rec => {
console.log(`Record: ${rec.name} (Type: ${rec.typ}, Sub: ${rec.sub})`);
for (const [key, value] in Object.entries(rec.data)) {
console.log(` ${key}: ${value}`);
}
});
}
write(filename) {
const fs = require('fs');
const buffer = new ArrayBuffer( some size );
const view = new DataView(buffer);
// Write headers and fields similar to read, then fs.writeFileSync(filename, new Uint8Array(buffer));
// ...
}
}
// Example
const parser = new StdfParser('input.std');
parser.printProperties();
parser.write('output.std');
7. C class that can open any file of format .STD and decode read and write and print to console all the properties from the above list
Since C does not have classes, here's a struct with functions.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
typedef struct {
char* filename;
// List of records, each with type, sub, map of fields (use struct or array)
// For simplicity, use linked list or array
} StdfParser;
uint8_t read_u1(FILE *f) {
uint8_t v;
fread(&v, 1, 1, f);
return v;
}
uint16_t read_u2(FILE *f) {
uint16_t v;
fread(&v, 2, 1, f);
return v;
}
// Similar for other types
// For cn
char* read_cn(FILE *f) {
uint8_t len = read_u1(f);
char* str = malloc(len + 1);
fread(str, 1, len, f);
str[len] = '\0';
return str;
}
// Parse function similar to Python, using switch for typ/sub, read fields
void print_properties(StdfParser *parser) {
// Loop over records, printf each field
}
// Write similar, fopen wb, fwrite headers and fields
StdfParser* stdf_parser_new(const char* filename) {
StdfParser* p = malloc(sizeof(StdfParser));
p->filename = strdup(filename);
// Read
return p;
}
void stdf_parser_free(StdfParser *p) {
free(p->filename);
free(p);
}
int main(int argc, char** argv) {
if (argc > 1) {
StdfParser* parser = stdf_parser_new(argv[1]);
print_properties(parser);
// Write to "output.std"
stdf_parser_free(parser);
}
return 0;
}
TASK 689 STOP.