void 
mexFunction(int nlhs, mxArray *plhs[], 
	    int nrhs, const mxArray *prhs[])
{
   struct keyword *pk;   /* pointer to keyword structure */
   mxArray *pp, *pv;     /* pointer to property and value */
   element_t *pe;        /* pointer to element */
   element_t el;
   int nc, idx;
   char pstr[PS_LEN];    /* property name string */
   char errmsg[ERR_LEN];


   if (nrhs != 2)
      mexErrMsgTxt("set_element_data :  must have exactly two arguments.");

   /* get pointer to input element and make local copy */
   pe = (element_t *)mxGetData(prhs[0]);
   memcpy(&el, pe, sizeof(element_t));

   /* check 2nd argument */
   if ( !mxIsCell(prhs[1]) )
      mexErrMsgTxt("set_element_data :  2nd argument must be cell array.");

   /* get number of cells */
   nc = mxGetNumberOfElements(prhs[1]);
   if (nc % 2)
      mexErrMsgTxt("set_element_data :  2nd argument must consist of propery/value pairs.");

   /* store property/value pairs one-by-one */
   for (idx = 0; idx<nc; idx+=2) {
     
      /* get next property value pair */
      pp = mxGetCell(prhs[1], idx);
      pv = mxGetCell(prhs[1], idx+1);

      /* decode property argument using the hash function in prop_hash.h */
      if ( !mxIsChar(pp) )
	 mexErrMsgTxt("set_element_data :  properties must be character strings.");
      mxGetString(pp, pstr, PS_LEN);
      pk = (struct keyword *)in_word_set(pstr, strlen(pstr));
      if (pk == NULL) {
	 sprintf(errmsg, "set_element_data :  unknown element property -> %s", pstr); 
	 mexErrMsgTxt(errmsg);      
      }

      /* store the property value in internal structure */
      if ( !mxIsEmpty(pv) )
	 (*pk->set_prop_func)(&el, pv);
   }

   /* return element to caller */
   plhs[0] = copy_element_to_array(&el);
}
Beispiel #2
0
static void 
read_box(FILE *fob, mxArray **data, double dbu_to_uu)
{
   mxArray *pstruct;
   mxArray *pprop = NULL;
   uint16_t rtype, rlen;
   int nprop = 0;
   element_t box;
   const char *fields[] = {"internal", "xy", "prop"};


   /* initialize element */
   init_element(&box, GDS_BOX);

   /* output data structure */
   pstruct = mxCreateStructMatrix(1,1, 3, fields);

   /* read element properties */
   while (1) {
      
      if ( read_record_hdr(fob, &rtype, &rlen) )
	 mexErrMsgTxt("gds_read_element (box) :  could not read record header.");

      if (rtype == ENDEL)
	 break;

      switch (rtype) {

         case XY:
	    mxSetFieldByNumber(pstruct, 0, 1, read_xy(fob, rlen, dbu_to_uu));
	    break;

         case LAYER:
	    box.layer = read_layer(fob);
	    break;

         case BOXTYPE:
	    box.dtype = read_type(fob);
	    break;

         case ELFLAGS:
	    box.elflags = read_elflags(fob);
	    box.has |= HAS_ELFLAGS;
	    break;

         case PLEX:
	    box.plex = read_plex(fob);
	    box.has |= HAS_PLEX;
	    break;

         case PROPATTR:
	    pprop = resize_property_structure(pprop, nprop+1);
	    mxSetFieldByNumber(pprop, nprop, 0, read_propattr(fob));
	    break;

         case PROPVALUE:
 	    mxSetFieldByNumber(pprop, nprop, 1, read_propvalue(fob,rlen));
	    nprop += 1;
	    break;

         default:
	    mexPrintf("Unknown record id: 0x%x\n", rtype);
	    mexErrMsgTxt("BOX :  found unknown element property.");
      }
   }

   /* set prop field */
   if ( nprop ) {
      mxSetFieldByNumber(pstruct, 0, 2, pprop);
   }
   else {
      mxSetFieldByNumber(pstruct, 0, 2, empty_matrix());
   }

   /* store structure with element data */
   mxSetFieldByNumber(pstruct, 0, 0, copy_element_to_array(&box));

   /* return data */
   *data = pstruct;
}
Beispiel #3
0
static void 
read_text(FILE *fob, mxArray **data, double dbu_to_uu)
{
   mxArray *pstruct;
   mxArray *pprop = NULL;
   uint16_t rtype, rlen;
   int nprop = 0;
   char tstr[TXTLEN+4];
   element_t text;
   const char *fields[] = {"internal", "xy", "prop", "text"};


   /* initialize element */
   init_element(&text, GDS_TEXT);

   /* output data structure */
   pstruct = mxCreateStructMatrix(1,1, 4, fields);

   /* read element properties */
   while (1) {
      
      if ( read_record_hdr(fob, &rtype, &rlen) )
	 mexErrMsgTxt("gds_read_element (text) :  could not read record header.");

      if (rtype == ENDEL)
	 break;

      switch (rtype) {

         case STRING:
	    if ( read_string(fob, tstr, rlen) )
	       mexErrMsgTxt("gds_read_element (text) :  could not read string.");
	    struct_set_string(pstruct, 3, tstr);
	    break;

         case TEXTTYPE:
	    text.dtype = read_type(fob);
	    break;

         case XY:
	    mxSetFieldByNumber(pstruct, 0, 1, read_xy(fob, rlen, dbu_to_uu));
	    break;

         case LAYER:
	    text.layer = read_layer(fob);
	    break;

         case PATHTYPE:
	    text.ptype = read_type(fob);
	    text.has |= HAS_PTYPE;
	    break;

         case WIDTH:
	    text.width = dbu_to_uu * read_width(fob);
	    text.has |= HAS_WIDTH;
	    break;

         case PRESENTATION:
	    if ( read_word(fob, &text.present) )
	       mexErrMsgTxt("gds_read_element (text) :  could not read presentation data.");
	    text.has |= HAS_PRESTN;
	    break;

         case STRANS:
	    if ( read_word(fob, &text.strans.flags) )
	       mexErrMsgTxt("gds_read_element (text) :  could not read strans data.");
	    text.has |= HAS_STRANS;
	    break;

         case MAG:
	    if ( read_real8(fob, &text.strans.mag) )
	       mexErrMsgTxt("gds_read_element (text) :  could not read magnification.");
	    text.has |= HAS_MAG;
	    break;

         case ANGLE:
	    if ( read_real8(fob, &text.strans.angle) )
	       mexErrMsgTxt("gds_read_element (text) :  could not read angle.");
	    text.has |= HAS_ANGLE;
	    break;

         case ELFLAGS:
	    text.elflags = read_elflags(fob);
	    text.has |= HAS_ELFLAGS;
	    break;

         case PLEX:
	    text.plex = read_plex(fob);
	    text.has |= HAS_PLEX;
	    break;

         case PROPATTR:
	    pprop = resize_property_structure(pprop, nprop+1);
	    mxSetFieldByNumber(pprop, nprop, 0, read_propattr(fob));
	    break;

         case PROPVALUE:
 	    mxSetFieldByNumber(pprop, nprop, 1, read_propvalue(fob,rlen));
	    nprop += 1;
	    break;

         default:
	    mexPrintf("Unknown record id: 0x%x\n", rtype);
	    mexErrMsgTxt("TEXT :  found unknown element property.");
      }
   }

   /* set prop field */
   if ( nprop ) {
      mxSetFieldByNumber(pstruct, 0, 2, pprop);
   }
   else {
      mxSetFieldByNumber(pstruct, 0, 2, empty_matrix());
   }

   /* store structure with element data */
   mxSetFieldByNumber(pstruct, 0, 0, copy_element_to_array(&text));

   /* return data */
   *data = pstruct;
}
Beispiel #4
0
static void 
read_aref(FILE *fob, mxArray **data, double dbu_to_uu)
{
   mxArray *pstruct;
   mxArray *pprop = NULL;
   uint16_t rtype, rlen;
   int nprop = 0;
   element_t aref;
   const char *fields[] = {"internal", "xy", "prop"};


   /* initialize element */
   init_element(&aref, GDS_AREF);

   /* output data structure */
   pstruct = mxCreateStructMatrix(1,1, 3, fields);

   /* read element properties */
   while (1) {
      
      if ( read_record_hdr(fob, &rtype, &rlen) )
	 mexErrMsgTxt("gds_read_element (aref) :  could not read record header.");

      if (rtype == ENDEL)
	 break;

      switch (rtype) {

         case XY:
            mxSetFieldByNumber(pstruct, 0, 1, read_xy(fob, rlen, dbu_to_uu));
 	    break;

         case SNAME:
	    if ( read_string(fob, aref.sname, rlen) )
	       mexErrMsgTxt("gds_read_element (sref) :  could not read structure name.");
	    break;

         case COLROW:
	    read_colrow(fob, &aref.nrow, &aref.ncol);
	    break;
	    
         case STRANS:
	    if ( read_word(fob, &aref.strans.flags) )
	       mexErrMsgTxt("gds_read_element (aref) :  could not read strans data.");
	    aref.has |= HAS_STRANS;
	    break;

         case MAG:
	    if ( read_real8(fob, &aref.strans.mag) )
	       mexErrMsgTxt("gds_read_element (aref) :  could not read magnification.");
	    aref.has |= HAS_MAG;
	    break;

         case ANGLE:
	    if ( read_real8(fob, &aref.strans.angle) )
	       mexErrMsgTxt("gds_read_element (aref) :  could not read angle.");
	    aref.has |= HAS_ANGLE;
	    break;

         case ELFLAGS:
	    aref.elflags = read_elflags(fob);
	    aref.has |= HAS_ELFLAGS;
	    break;

         case PLEX:
	    aref.plex = read_plex(fob);
	    aref.has |= HAS_PLEX;
	    break;

         case PROPATTR:
	    pprop = resize_property_structure(pprop, nprop+1);
	    mxSetFieldByNumber(pprop, nprop, 0, read_propattr(fob));
	    break;

         case PROPVALUE:
 	    mxSetFieldByNumber(pprop, nprop, 1, read_propvalue(fob,rlen));
	    nprop += 1;
	    break;

         default:
	    mexPrintf("Unknown record id: 0x%x\n", rtype);
	    mexErrMsgTxt("AREF :  found unknown element property.");
      }
   }

   /* set prop field */
   if ( nprop ) {
      mxSetFieldByNumber(pstruct, 0, 2, pprop);
   }
   else {
      mxSetFieldByNumber(pstruct, 0, 2, empty_matrix());
   }

   /* store structure with element data */
   mxSetFieldByNumber(pstruct, 0, 0, copy_element_to_array(&aref));

   /* return data */
   *data = pstruct;
} 
Beispiel #5
0
static void 
read_sref(FILE *fob, mxArray **data, double dbu_to_uu)
{
   mxArray *pstruct;
   mxArray *pprop = NULL;
   mxArray *pa;
   double *pd;
   tList xylist;
   uint16_t rtype, rlen;
   int nprop = 0;
   int mtotal = 0;
   int k, m, nle;
   element_t sref;
   const char *fields[] = {"internal", "xy", "prop"};
   xy_block vertex;


   /* initialize element */
   init_element(&sref, GDS_SREF);

   /* output data structure */
   pstruct = mxCreateStructMatrix(1,1, 3, fields);

   /* create a list for the XY data record(s) */
   if ( create_list(&xylist) == -1 )
      mexErrMsgTxt("gds_read_element (sref) :  could not create list for XY records.");

   /* read element properties */
   while (1) {
      
      if ( read_record_hdr(fob, &rtype, &rlen) )
	 mexErrMsgTxt("gds_read_element (sref) :  could not read record header.");

      if (rtype == ENDEL)
	 break;

      switch (rtype) {

         case XY:
	    m = rlen / (2*sizeof(int32_t));
	    vertex.mxy = m;
	    vertex.xy = read_xy2(fob, m, dbu_to_uu);
	    list_insert_object(xylist, &vertex, sizeof(xy_block), AFTER);
	    mtotal += m;
	    break;

         case SNAME:
	    if ( read_string(fob, sref.sname, rlen) )
	       mexErrMsgTxt("gds_read_element (sref) :  could not read structure name.");
	    break;

         case STRANS:
	    if ( read_word(fob, &sref.strans.flags) )
	       mexErrMsgTxt("gds_read_element (sref) :  could not read strans data.");
	    sref.has |= HAS_STRANS;
	    break;

         case MAG:
	    if ( read_real8(fob, &sref.strans.mag) )
	       mexErrMsgTxt("gds_read_element (sref) :  could not read magnification.");
	    sref.has |= HAS_MAG;
	    break;

         case ANGLE:
	    if ( read_real8(fob, &sref.strans.angle) )
	       mexErrMsgTxt("gds_read_element (sref) :  could not read angle.");
	    sref.has |= HAS_ANGLE;
	    break;

         case ELFLAGS:
	    sref.elflags = read_elflags(fob);
	    sref.has |= HAS_ELFLAGS;
	    break;

         case PLEX:
	    sref.plex = read_plex(fob);
	    sref.has |= HAS_PLEX;
	    break;

         case PROPATTR:
	    pprop = resize_property_structure(pprop, nprop+1);
	    mxSetFieldByNumber(pprop, nprop, 0, read_propattr(fob));
	    break;

         case PROPVALUE:
 	    mxSetFieldByNumber(pprop, nprop, 1, read_propvalue(fob,rlen));
	    nprop += 1;
	    break;

         default:
	    mexPrintf("Unknown record id: 0x%x\n", rtype);
	    mexErrMsgTxt("SREF :  found unknown element property.");
      }
   }

   /* catenate XY records */
   nle = list_entries(xylist);
   if ( !nle )
      mexErrMsgTxt("gds_read_element (sref) :  element has no XY record.");
   pa = mxCreateDoubleMatrix(mtotal,2, mxREAL);
   pd = mxGetData(pa);
   list_head(xylist);
   for (k=0; k<nle; k++) {
      get_current_object(xylist, &vertex, sizeof(xy_block));
      memcpy(pd, vertex.xy, 2*vertex.mxy*sizeof(double));
      pd += 2*vertex.mxy;
      mxFree(vertex.xy);
   }
   mxSetFieldByNumber(pstruct, 0, 1, pa);
   erase_list_entries(xylist);
   delete_list(&xylist);

   /* set prop field */
   if ( nprop ) {
      mxSetFieldByNumber(pstruct, 0, 2, pprop);
   }
   else {
      mxSetFieldByNumber(pstruct, 0, 2, empty_matrix());
   }

   /* store structure with element data */
   mxSetFieldByNumber(pstruct, 0, 0, copy_element_to_array(&sref));

   /* return data */
   *data = pstruct;
} 
Beispiel #6
0
static void 
read_path(FILE *fob, mxArray **data, double dbu_to_uu) 
{
   mxArray *pstruct;
   mxArray *pprop = NULL;
   mxArray *pc;
   tList xylist;
   uint16_t rtype, rlen;
   int nprop = 0;
   int nle, k;
   element_t path;
   const char *fields[] = {"internal", "xy", "prop"};


   /* initialize element */
   init_element(&path, GDS_PATH);

   /* output data structure */
   pstruct = mxCreateStructMatrix(1,1, 3, fields);

   /* create a list for the XY data record(s) */
   if ( create_list(&xylist) == -1 )
      mexErrMsgTxt("gds_read_element (path) :  could not create list for XY records.");

   /* read element properties */
   while (1) {
      
      if ( read_record_hdr(fob, &rtype, &rlen) )
	 mexErrMsgTxt("gds_read_element (path) :  could not read record header.");

      if (rtype == ENDEL)
	 break;

      switch (rtype) {

         case XY:
	    if ( list_insert(xylist, read_xy(fob, rlen, dbu_to_uu), AFTER) == -1)
	       mexErrMsgTxt("gds_read_element (path) :  list insertion failed.");
	    break;

         case LAYER:
	    path.layer = read_layer(fob);
	    break;

         case PATHTYPE:
	    path.ptype = read_type(fob);
	    path.has |= HAS_PTYPE;
	    break;

         case WIDTH:
	    path.width = dbu_to_uu * (double)read_width(fob);
	    path.has |= HAS_WIDTH;
	    break;

         case BGNEXTN:
	    path.bgnextn = dbu_to_uu * read_extn(fob);
	    path.has |= HAS_BGNEXTN;
	    break;

         case ENDEXTN:
	    path.endextn = dbu_to_uu * read_extn(fob);
	    path.has |= HAS_ENDEXTN;
	    break;

         case DATATYPE:
	    path.dtype = read_type(fob);
	    break;

         case ELFLAGS:
	    path.elflags = read_elflags(fob);
	    path.has |= HAS_ELFLAGS;
	    break;

         case PLEX:
	    path.plex = read_plex(fob);
	    path.has |= HAS_PLEX;
	    break;

         case PROPATTR:
	    pprop = resize_property_structure(pprop, nprop+1);
	    mxSetFieldByNumber(pprop, nprop, 0, read_propattr(fob));
	    break;

         case PROPVALUE:
 	    mxSetFieldByNumber(pprop, nprop, 1, read_propvalue(fob,rlen));
	    nprop += 1;
	    break;

         default:
	    mexPrintf("Unknown record id: 0x%x\n", rtype);
	    mexErrMsgTxt("PATH :  found unknown element property.");
      }
   }

   /* cell array with XY records */
   nle = list_entries(xylist);
   if ( !nle )
      mexErrMsgTxt("gds_read_element (path) :  element has no XY record.");
   pc = mxCreateCellMatrix(1, nle);
   list_head(xylist);
   for (k=0; k<nle; k++)
      mxSetCell(pc, k, (mxArray *)get_current_entry(xylist, NULL));
   mxSetFieldByNumber(pstruct, 0, 1, pc);

   /* set prop field */
   if ( nprop ) {
      mxSetFieldByNumber(pstruct, 0, 2, pprop);
   }
   else {
      mxSetFieldByNumber(pstruct, 0, 2, empty_matrix());
   }

   /* store structure with element data */
   mxSetFieldByNumber(pstruct, 0, 0, copy_element_to_array(&path));

   /* return data */
   *data = pstruct;
}