⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gds.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            name = makeUniqueName(cell, cellNames);            cellNames.put(cell, name);        }		outputName(HDR_STRNAME, name, IOTool.getGDSCellNameLenMax());	}	/**	 * Method to output date information	 */	private void outputDate(Date val)	{		short [] date = new short[6];		Calendar cal = Calendar.getInstance();		cal.setTime(val);		int year = cal.get(Calendar.YEAR) - 1900;		date[0] = (short)year;		date[1] = (short)cal.get(Calendar.MONTH);		date[2] = (short)cal.get(Calendar.DAY_OF_MONTH);		date[3] = (short)cal.get(Calendar.HOUR);		date[4] = (short)cal.get(Calendar.MINUTE);		date[5] = (short)cal.get(Calendar.SECOND);		outputShortArray(date, 6);	}	/**	 * Write a simple header, with a fixed length	 * Enter with the header as argument, the routine will output	 * the count, the header, and the argument (if present) in p1.	 */	private void outputHeader(short header, int p1)	{		int type = header & BYTEMASK;		short count = 4;		if (type != DTYP_NONE)		{			switch (header)			{				case HDR_HEADER:				case HDR_LAYER:				case HDR_DATATYPE:				case HDR_TEXTTYPE:				case HDR_STRANS:				case HDR_PRESENTATION:					count = 6;					break;				case HDR_BGNSTR:				case HDR_BGNLIB:					count = HDR_N_BGNLIB;					break;				case HDR_UNITS:					count = HDR_N_UNITS;					break;				default:					System.out.println("No entry for header " + header);					return;			}		}		outputShort(count);		outputShort(header);		if (type == DTYP_NONE) return;		if (count == 6) outputShort((short)p1);		if (count == 8) outputInt(p1);	}	/**	 * Add a name (STRNAME, LIBNAME, etc.) to the file. The header	 * to be used is in header; the string starts at p1	 * if there is an odd number of bytes, then output the 0 at	 * the end of the string as a pad. The maximum length of string is "max"	 */	private void outputName(short header, String p1, int max)	{		outputString(p1, header, max);	}	/**	 * Method to output an angle as part of a STRANS	 */	private void outputAngle(int ang)	{		double gdfloat = ang / 10.0;		outputShort(HDR_N_ANGLE);		outputShort(HDR_ANGLE);		outputDouble(gdfloat);	}	/**	 * Method to output a magnification as part of a STRANS	 */	private void outputMag(double scale)	{		outputShort(HDR_N_MAG);		outputShort(HDR_MAG);		outputDouble(scale);	}	/**	 * Method to output the pairs of XY points to the file	 */ 	private void outputBoundary(PolyBase poly, int layerNumber, int layerType)	{		Point2D [] points = poly.getPoints();		// remove redundant points		Point2D [] newPoints = new Point2D[points.length];		int count = 0;		newPoints[count++] = points[0];		for(int i=1; i<points.length; i++)		{			if (points[i].equals(points[i-1])) continue;			newPoints[count++] = points[i];		}		points = newPoints;		if (count > MAXPOINTS)		{//			getbbox(poly, &lx, &hx, &ly, &hy);//			if (hx-lx > hy-ly)//			{//				if (polysplitvert((lx+hx)/2, poly, &side1, &side2)) return;//			} else//			{//				if (polysplithoriz((ly+hy)/2, poly, &side1, &side2)) return;//			}//			outputBoundary(side1, layerNumber);//			outputBoundary(side2, layerNumber);//			freepolygon(side1);//			freepolygon(side2);			return;		}		int start = 0;		for(;;)		{			// look for a closed section			int sofar = start+1;			for( ; sofar<count; sofar++)				if (points[sofar].getX() == points[start].getX() && points[sofar].getY() == points[start].getY()) break;			if (sofar < count) sofar++;			outputHeader(HDR_BOUNDARY, 0);			outputHeader(HDR_LAYER, layerNumber);			outputHeader(HDR_DATATYPE, layerType);			outputShort((short)(8 * (sofar+1) + 4));			outputShort(HDR_XY);			for (int i = start; i <= sofar; i++)			{				int j = i;				if (i == sofar) j = 0;				outputInt(scaleDBUnit(points[j].getX()));				outputInt(scaleDBUnit(points[j].getY()));			}			outputHeader(HDR_ENDEL, 0);			if (sofar >= count) break;			count -= sofar;			start = sofar;		}	}	private void outputPath(PolyBase poly, int layerNumber, int layerType)	{		outputHeader(HDR_PATH, 0);		outputHeader(HDR_LAYER, layerNumber);		outputHeader(HDR_DATATYPE, layerType);		Point2D [] points = poly.getPoints();		int count = 8 * points.length + 4;		outputShort((short)count);		outputShort(HDR_XY);		for (int i = 0; i < points.length; i ++)		{			outputInt(scaleDBUnit(points[i].getX()));			outputInt(scaleDBUnit(points[i].getY()));		}		outputHeader(HDR_ENDEL, 0);	}	/**	 * Method to add one byte to the file	 */	private void outputByte(byte val)	{		dataBufferGDS[bufferPosition++] = val;		if (bufferPosition >= DSIZE)		{			try			{				dataOutputStream.write(dataBufferGDS, 0, DSIZE);			} catch (IOException e)			{				System.out.println("End of file reached while writing GDS");			}			blockCount++;			bufferPosition = 0;		}	}    private int scaleDBUnit(double dbunit) {        // scale according to technology        double scaled = scaleFactor*dbunit;        // round to nearest nanometer        int unit = (int)Math.round(scaled);        return unit;    }	/*************************** GDS LOW-LEVEL OUTPUT ROUTINES ***************************/	/**	 * Method to add a 2-byte integer to the output	 */	private void outputShort(short val)	{		outputByte((byte)((val>>8)&BYTEMASK));		outputByte((byte)(val&BYTEMASK));	}	/**	 * Method to add a 4-byte integer to the output	 */	private void outputInt(int val)	{		outputShort((short)(val>>16));		outputShort((short)val);	}	/**	 * Method to add an array of 2 byte integers to the output.	 * @param ptr the array.	 * @param n the array length.	 */	private void outputShortArray(short [] ptr, int n)	{		for (int i = 0; i < n; i++) outputShort(ptr[i]);	}	/**	 * Method to add an array of 4 byte integers or floating numbers to the output.	 * @param ptr the array.	 * @param n the array length.	 *///	private void outputIntArray(int [] ptr, int n)//	{//		for (int i = 0; i < n; i++) outputInt(ptr[i]);//	}    private void outputString(String str, short header) {        // The usual maximum length for string is 512, though names etc may need to be shorter        outputString(str, header, 512);    }    /**     * String of n bytes, starting at ptr     * Revised 90-11-23 to convert to upper case (SRP)     */    private void outputString(String str, short header, int max) {        int j = str.length();        if (j > max) j = max;        // round up string length to the nearest integer        if ((j % 2) != 0) {            j = (j / 2)*2 + 2;        }        // pad with a blank        outputShort((short)(4+j));        outputShort(header);        assert( (j%2) == 0);		int i = 0;		if (IOTool.isGDSOutUpperCase())		{			// convert to upper case			for( ; i<str.length(); i++)				outputByte((byte)Character.toUpperCase(str.charAt(i)));		} else		{			for( ; i<str.length(); i++)				outputByte((byte)str.charAt(i));		}		for ( ; i < j; i++)			outputByte((byte)0);	}	/**	 * Method to write a GDSII representation of a double.	 * New conversion code contributed by Tom Valine <tomv@transmeta.com>.	 * @param data the double to process.	 */	public void outputDouble(double data)	{		if (data == 0.0)		{			for(int i=0; i<8; i++) outputByte((byte)0);			return;		}		BigDecimal reg = new BigDecimal(data).setScale(64, BigDecimal.ROUND_HALF_EVEN);		boolean negSign = false;		if (reg.doubleValue() < 0)		{			negSign = true;			reg = reg.negate();		}		int exponent = 64;		for(; (reg.doubleValue() < 0.0625) && (exponent > 0); exponent--)			reg = reg.multiply(new BigDecimal(16.0));		if (exponent == 0) System.out.println("Exponent underflow");		for(; (reg.doubleValue() >= 1) && (exponent < 128); exponent++)			reg = reg.divide(new BigDecimal(16.0), BigDecimal.ROUND_HALF_EVEN);		if (exponent > 127) System.out.println("Exponent overflow");		if (negSign) exponent |= 0x00000080;		BigDecimal f_mantissa = reg.subtract(new BigDecimal(reg.intValue()));		for(int i = 0; i < 56; i++)			f_mantissa = f_mantissa.multiply(new BigDecimal(2.0));		long mantissa = f_mantissa.longValue();		ByteArrayOutputStream baos = new ByteArrayOutputStream();		baos.write(exponent);		for(int i = 6; i >= 0; i--)			baos.write((int)((mantissa >> (i * 8)) & 0xFF));		byte [] result = baos.toByteArray();		for(int i=0; i<8; i++) outputByte(result[i]);	}//	/**//	 * Method to write a GDSII representation of a double.//	 * Original C-Electric code (no longer used).//	 * @param data the double to process.//	 *///	private void outputDouble(double a)//	{//		int [] ret = new int[2];////		// handle default//		if (a == 0)//		{//			ret[0] = 0x40000000;//			ret[1] = 0;//			outputIntArray(ret, 2);//			return;//		}////		// identify sign//		double temp = a;//		boolean negsign = false;//		if (temp < 0)//		{//			negsign = true;//			temp = -temp;//		}////		// establish the excess-64 exponent value//		int exponent = 64;////		// scale the exponent and mantissa//		for (; temp < 0.0625 && exponent > 0; exponent--) temp *= 16.0;////		if (exponent == 0) System.out.println("Exponent underflow");////		for (; temp >= 1 && exponent < 128; exponent++) temp /= 16.0;////		if (exponent > 127) System.out.println("Exponent overflow");////		// set the sign//		if (negsign) exponent |= 0x80;////		// convert temp to 7-byte binary integer//		double top = temp;//		for (int i = 0; i < 24; i++) top *= 2;//		int highmantissa = (int)top;//		double frac = top - highmantissa;//		for (int i = 0; i < 32; i++) frac *= 2;//		ret[0] = highmantissa | (exponent<<24);//		ret[1] = (int)frac;//		outputIntArray(ret, 2);//	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -