예제 #1
0
파일: server.cpp 프로젝트: asdlei00/ACE
Controller_impl::
~Controller_impl ()
{
    // Write out the current set of asset numbers
    // and clean up all servant instances.
    std::ofstream afile (m_asset_file.in ());
    if (!afile) {
        std::cerr << "Cannot open " << m_asset_file.in () << std::endl;
        assert (0);
    }
    AssetMap::iterator i;
    for (i = m_assets.begin (); i != m_assets.end (); i++) {
        afile << i->first << std::endl;
        if (!afile) {
            std::cerr << "Cannot update " << m_asset_file.in () << std::endl;
            assert (0);
        }
        delete i->second;
    }
    //afile.close ();
    //if (!afile) {
    //    cerr << "Cannot close " << m_asset_file << endl;
    //    assert (0);
    //}
}
예제 #2
0
파일: icpdfrm.cpp 프로젝트: leoheck/astran
/** Constructor */
IcpdFrm::IcpdFrm( wxWindow* parent ):ICPD_frm( parent ){
	wxLog::SetActiveTarget( new wxLogTextCtrl(wx_log));

    new Redirector( wx_log, cout, false);
    new Redirector( wx_log, cerr, true);

	printHeader(cout, "", "");

	string astran_cfg;
    astran_cfg = "astran.cfg";

    wxString astran_path;
    ::wxGetEnv(wxT("ASTRAN_PATH"), &astran_path);

	if (wxDirExists(astran_path)) {
		astran_cfg = string(wxString(astran_path).mb_str()) + "/astran.cfg";

        ifstream afile(astran_cfg.c_str());
        if(afile) {
			executeCommand(string("read \"" + astran_cfg + "\""));
        }
	}

    wxabout = new WxAbout(this);
    wxrules = new WxRules(this);
    wxautocell = new WxAutoCell(this);
    wxcircuit = new WxCircuit(this);
    wxfp = new WxFP(this);
    wxpreferences = new WxPreferences(this);
    refresh();
}
예제 #3
0
void
BcxFile::GetModel( std::vector< s16 >& skeleton_length, const Unit& unit, Ogre::MeshPtr mesh, Ogre::SkeletonPtr skeleton, VectorTexForGenBsx& textures )
{
    u32 offset_to_model_info = GetU32LE(0x04);

    u8 number_of_bones      = GetU8(offset_to_model_info + 0x02);
    u8 number_of_parts      = GetU8(offset_to_model_info + 0x03);
    u8 number_of_animations = GetU8(offset_to_model_info + 0x04);

    //////////////////////////
    // mesh
    //////////////////////////
    u16 offset_to_parts = GetU16LE(offset_to_model_info + 0x1c) + number_of_bones * 4;
    MeshFile file_m(this);
    file_m.GetData(unit.name, offset_to_parts, number_of_parts, mesh, textures);
    //////////////////////////

    //////////////////////////
    // skeleton
    //////////////////////////
    u16 offset_to_bones = GetU16LE(offset_to_model_info + 0x1C);
    SkeletonFile file_s(this);
    file_s.GetData( skeleton_length, offset_to_bones, number_of_bones, skeleton );
    //////////////////////////

    ///////////////////////////////////////////////////
    // animations
    ///////////////////////////////////////////////////
    u32 offset_to_animations = GetU32LE(offset_to_model_info + 0x1C) - 0x80000000 + number_of_bones * 4 + number_of_parts * 0x20;

    AnimationFile afile(this);
    afile.GetData( skeleton_length, unit, offset_to_animations, number_of_animations, 0, skeleton );
}
예제 #4
0
    virtual wxDirTraverseResult OnFile(const wxString& filename)
    {
        wxFileName afile(filename);
        afile.MakeRelativeTo(m_basePath);
        if (afile.GetFullPath().Find(afile.GetPathSeparator()) == wxNOT_FOUND)
            m_files.push_back(filename);

        return wxDIR_CONTINUE;
    }
예제 #5
0
파일: lksdcdb.c 프로젝트: malbanGit/Vide
VOID SDCDBfopen(void)
{
	if (yflag) {
		yfp = afile(linkp->f_idp, "cdb", 1);
		if (yfp == NULL) {
			lkerror("Cannot create SDCDB file");
		}
		mflag = 1;
	}
}
예제 #6
0
File *FileSystem::fopen(const kstring &pathname){
  // parse filename into vector of filename
  const char *cname = pathname.to_char();
  kvector<kstring> path(MAX_FILE_NR);
  //  kvector<kstring> path(1);
  //カレントノードからのパス指定はまだ
  File *invalid_file=new File();
  switch(cname[0]){
  case '/':
    goto from_root;  
    break;
  default:
    kprintf("File::invalid path name is specified \n");
    return invalid_file;
  }
  //ルートからのパス指定
 from_root:
  //  kprintf("len %d \n",pathname.length());
  u32_t cpos,ppos;//パス区切り文字の位置
  ppos = 0;
  cpos = 1;
  u32_t num_file=0;
  /*変な入力されたらおかしくなるかもしれない*/
  while(1){  
    if(cpos==pathname.length() || cname[cpos]=='/' ){
      //      kprintf("pos %d %d \n",cpos,ppos);
      kstring afile(cname+ppos+1,cpos - ppos -1);
      //      kprintf("afile %s \n",afile.to_char());
      path[num_file++]=afile;
      ppos = cpos;
    }
    if(cpos==pathname.length())
      break;
    cpos++;
  }
  path.set_nr_elem(num_file);

  //  kprintf("file name is parsed \n");
  /////////////////////////////////////////
  // for(int i=0;i<path.length();i++){   //
  //   kprintf("%s:",path[i].to_char()); //
  // }                                   //
  //////////////////////////////////////////////////
  // kprintf("\n");                               //
  // kprintf("num files is %d \n",path.length()); //
  //////////////////////////////////////////////////
  Ext2::ext2_inode inode = root_fs->get_inode_path(path);
  if(!inode.is_valid()){
    return invalid_file;
  }
  File *file=new File(path,inode,this);
  //  kprintf("fopen end \n");
  //get_inode
  return file;
}
예제 #7
0
FileClass::FileClass(const char* file){
    fileName = file;
    if (std::ifstream(fileName)){
        std::cout << "File already exists" << std::endl;
    }
    else{
        std::ofstream afile(fileName);
        afile.open(fileName, std::ios::in | std::ios::trunc) ;
        std::cout << " Constructor*********Created file :" << fileName << std::endl ;
        afile.close();
   }
}
예제 #8
0
파일: server.cpp 프로젝트: asdlei00/ACE
Controller_impl::
Controller_impl (
    PortableServer::POA_ptr poa,
    const char *            asset_file)
    :  m_poa (PortableServer::POA::_duplicate (poa)),
       m_asset_file (asset_file)
{
    std::ifstream afile (m_asset_file.in (), std::ios::in|std::ios::out);//, 0666);
    if (!afile) {
        std::cerr << "Cannot open " << m_asset_file.in () << std::endl;
        throw 0;
    }
    CCS::AssetType anum;
    while (afile >> anum)
        m_assets[anum] = 0;
    //afile.close ();
    //if (!afile) {
    //    cerr << "Cannot close " << m_asset_file << endl;
    //    throw 0;
    //}
}
bool PCBMODEL::getModelLabel( const std::string aFileName, TDF_Label& aLabel )
{
    MODEL_MAP::const_iterator mm = m_models.find( aFileName );

    if( mm != m_models.end() )
    {
        aLabel = mm->second;
        return true;
    }

    aLabel.Nullify();

    Handle( TDocStd_Document )  doc;
    m_app->NewDocument( "MDTV-XCAF", doc );

    FormatType modelFmt = fileType( aFileName.c_str() );

    switch( modelFmt )
    {
        case FMT_IGES:
            if( !readIGES( doc, aFileName.c_str() ) )
            {
                std::ostringstream ostr;
                ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
                ostr << "  * readIGES() failed on filename '" << aFileName << "'\n";
                wxLogMessage( "%s\n", ostr.str().c_str() );
                return false;
            }
            break;

        case FMT_STEP:
            if( !readSTEP( doc, aFileName.c_str() ) )
            {
                std::ostringstream ostr;
                ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
                ostr << "  * readSTEP() failed on filename '" << aFileName << "'\n";
                wxLogMessage( "%s\n", ostr.str().c_str() );
                return false;
            }
            break;

        // TODO: implement IDF and EMN converters

        default:
            return false;
    }

    aLabel = transferModel( doc, m_doc );

    if( aLabel.IsNull() )
    {
        std::ostringstream ostr;
        ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
        ostr << "  * could not transfer model data from file '" << aFileName << "'\n";
        wxLogMessage( "%s\n", ostr.str().c_str() );
        return false;
    }

    // attach the PART NAME ( base filename: note that in principle
    // different models may have the same base filename )
    wxFileName afile( aFileName.c_str() );
    std::string pname( afile.GetName().ToUTF8() );
    TCollection_ExtendedString partname( pname.c_str() );
    TDataStd_Name::Set( aLabel, partname );

    m_models.insert( MODEL_DATUM( aFileName, aLabel ) );
    ++m_components;
    return true;
}
예제 #10
0
파일: lkmem.c 프로젝트: Jason-K/sdcc
int summary2(struct area * areap)
{
  if (TARGET_IS_8051) {
    /* only for 8051 target */

    #define EQ(A,B) !as_strcmpi((A),(B))

    char buff[128];
    int toreturn = 0;
    unsigned int j;
    unsigned long int Stack_Start=0, Stack_Size;

    struct area * xp;
    struct area * xstack_xp = NULL;
    FILE * of;

    /*Artifacts used for printing*/
    char start[15], end[15], size[15], max[15];
    char format[]="   %-16.16s %-8.8s %-8.8s %-8.8s %-8.8s\n";
    char line[]="---------------------";

    typedef struct
    {
        unsigned long Start;
        unsigned long End;
        unsigned long Size;
        unsigned long Max;
        char Name[NCPS];
        unsigned long flag;
    } _Mem;

    _Mem Stack={0xff,   0, 0,     1, "STACK",           0x0000};
    _Mem Paged={0xffff, 0, 0,   256, "PAGED EXT. RAM",  A3_PAG};
    _Mem XRam= {0xffff, 0, 0, 65536, "EXTERNAL RAM",    0x0100};
    _Mem Rom=  {0xffff, 0, 0, 65536, "ROM/EPROM/FLASH", 0x0200};

    if(rflag) /*For the DS390*/
    {
        XRam.Max=0x1000000; /*24 bits*/
        XRam.Start=0xffffff;
        Rom.Max=0x1000000;
        Rom.Start=0xffffff;
    }

    /* Open Memory Summary File*/
    of = afile(linkp->f_idp, "mem", 1);
    if (of == NULL)
    {
        lkexit(1);
    }

    xp=areap;
    while (xp)
    {
        if (xp->a_flag & A_CODE)
        {
            if(xp->a_size)
            {
                Rom.Size += xp->a_size;
                if(xp->a_addr < Rom.Start)
                    Rom.Start = xp->a_addr;
                if(xp->a_addr + xp->a_size > Rom.End)
                    Rom.End = xp->a_addr + xp->a_size;
            }
        }

        else if (EQ(xp->a_id, "SSEG"))
        {
            Stack.Size += xp->a_size;
            if(xp->a_addr < Stack.Start)
                Stack.Start = xp->a_addr;
            if(xp->a_addr + xp->a_size > Stack.End)
                Stack.End = xp->a_addr + xp->a_size;
        }

        else if (EQ(xp->a_id, "PSEG"))
        {
            Paged.Size += xp->a_size;
            if(xp->a_addr < Paged.Start)
                Paged.Start = xp->a_addr;
            if(xp->a_addr + xp->a_size > Paged.End)
                Paged.End = xp->a_addr + xp->a_size;
        }

        else if (EQ(xp->a_id, "XSTK"))
        {
            xstack_xp = xp;
            Paged.Size += xp->a_size;
            if(xp->a_addr < Paged.Start)
                Paged.Start = xp->a_addr;
            if(xp->a_addr + xp->a_size > Paged.End)
                Paged.End = xp->a_addr + xp->a_size;
        }

        else if (xp->a_flag & A_XDATA)
        {
            if(xp->a_size)
            {
                XRam.Size += xp->a_size;
                if(xp->a_addr < XRam.Start)
                    XRam.Start = xp->a_addr;
                if(xp->a_addr + xp->a_size > XRam.End)
                    XRam.End = xp->a_addr + xp->a_size;
            }
        }

        xp = xp->a_ap;
    }

    /*Report the Ram totals*/
    fprintf(of, "Internal RAM layout:\n");
    fprintf(of, "      0 1 2 3 4 5 6 7 8 9 A B C D E F");
    for(j=0; j<256; j++)
    {
        if(j%16==0) fprintf(of, "\n0x%02x:|", j);
        fprintf(of, "%c|", idatamap[j]);
    }
    fprintf(of, "\n0-3:Reg Banks, T:Bit regs, a-z:Data, B:Bits, Q:Overlay, I:iData, S:Stack, A:Absolute\n");

    for(j=0; j<256; j++)
    {
        if(idatamap[j]=='S')
        {
            Stack_Start=j;
            break;
        }
    }

    for(j=Stack_Start, Stack_Size=0; j<((iram_size)?iram_size:256); j++)
    {
        if((idatamap[j]=='S')||(idatamap[j]==' ')) Stack_Size++;
        else break;
    }

    xp=areap;
    while (xp)
    {
        if(xp->a_unaloc>0)
        {
            fprintf(of, "\nERROR: Couldn't get %d byte%s allocated"
                        " in internal RAM for area %s.",
                        xp->a_unaloc, xp->a_unaloc>1?"s":"", xp->a_id);
            toreturn=1;
        }
        xp=xp->a_ap;
    }

    /*Report the position of the begining of the stack*/
    if(Stack_Start!=256)
        fprintf(of, "\n%s starts at: 0x%02lx (sp set to 0x%02lx) with %ld bytes available.",
            rflag ? "16 bit mode initial stack" : "Stack", Stack_Start, Stack_Start-1, Stack_Size);
    else
        fprintf(of, "\nI don't have a clue where the stack ended up! Sorry...");

    /*Report about xstack*/
    if (xstack_xp)
    {
        Stack_Start = xstack_xp->a_addr;
        Stack_Size = xstack_xp->a_size;
        fprintf(of, "\nXstack starts at: 0x%04lx with %ld bytes available.",
            Stack_Start, Stack_Size);
    }

    fprintf(of, "\n\nOther memory:\n");
    fprintf(of, format, "Name", "Start", "End", "Size", "Max");
    fprintf(of, format, line, line, line, line, line);

    /*Report Paged XRam totals:*/
    if(Paged.Size==0)
    {
        start[0]=0;/*Empty string*/
        end[0]=0;/*Empty string*/
    }
    else
    {
        sprintf(start, "0x%04lx", Paged.Start);
        sprintf(end,  "0x%04lx", Paged.End-1);
    }
    sprintf(size, "%5lu", Paged.Size);
    sprintf(max, "%5lu", xram_size<0 ? Paged.Max : xram_size<256 ? xram_size : 256);
    fprintf(of, format, Paged.Name, start, end, size, max);

    /*Report XRam totals:*/
    if(XRam.Size==0)
    {
        start[0]=0;/*Empty string*/
        end[0]=0;/*Empty string*/
    }
    else
    {
        sprintf(start, "0x%04lx", XRam.Start);
        sprintf(end,  "0x%04lx", XRam.End-1);
    }
    sprintf(size, "%5lu", XRam.Size);
    sprintf(max, "%5lu", xram_size<0?XRam.Max:xram_size);
    fprintf(of, format, XRam.Name, start, end, size, max);

    /*Report Rom/Flash totals:*/
    if(Rom.Size==0)
    {
        start[0]=0;/*Empty string*/
        end[0]=0;/*Empty string*/
    }
    else
    {
        sprintf(start, "0x%04lx", Rom.Start);
        sprintf(end,  "0x%04lx", Rom.End-1);
    }
    sprintf(size, "%5lu", Rom.Size);
    sprintf(max, "%5lu", code_size<0?Rom.Max:code_size);
    fprintf(of, format, Rom.Name, start, end, size, max);

    /*Report any excess:*/
    if( ((XRam.End) > XRam.Max) ||
        (((int)XRam.Size>xram_size)&&(xram_size>=0)) )
    {
        sprintf(buff, "Insufficient EXTERNAL RAM memory.\n");
        REPORT_ERROR(buff, 1);
    }
    if( ((Rom.End) > Rom.Max) ||
        (((int)Rom.Size>code_size)&&(code_size>=0)) )
    {
        sprintf(buff, "Insufficient ROM/EPROM/FLASH memory.\n");
        REPORT_ERROR(buff, 1);
    }

    fclose(of);
    return toreturn;
  }
  else {
    assert (0);
    return 0;
  }
}
예제 #11
0
파일: lkmem.c 프로젝트: Jason-K/sdcc
int summary(struct area * areap)
{
  if (TARGET_IS_8051 || TARGET_IS_6808) {
    /* only for 8051 and 6808 targets */

    #define EQ(A,B) !as_strcmpi((A),(B))
    #define MIN_STACK 16
    #define REPORT_ERROR(A, H) \
    {\
        fprintf(of, "%s%s", (H)?"*** ERROR: ":"", (A)); \
        fprintf(stderr, "%s%s", (H)?"\n?ASlink-Error-":"",(A)); \
        toreturn=1; \
    }

    #define REPORT_WARNING(A, H) \
    { \
        fprintf(of, "%s%s", (H)?"*** WARNING: ":"", (A)); \
        fprintf(stderr, "%s%s",(H)?"\n?ASlink-Warning-":"", (A)); \
    }

    char buff[128];
    int j, toreturn=0;
    unsigned int Total_Last=0, k;

    struct area * xp;
    FILE * of;

    /*Artifacts used for printing*/
    char start[15], end[15], size[15], max[15];
    char format[]="   %-16.16s %-8.8s %-8.8s %-8.8s %-8.8s\n";
    char line[]="---------------------";

    typedef struct
    {
        unsigned long Start;
        unsigned long Size;
        unsigned long Max;
        char Name[NCPS];
        unsigned long flag;
    } _Mem;

    unsigned int dram[0x100];
    _Mem Ram8051[] = {
        {0,     8,  8,   "REG_BANK_0", 0x0001},
        {0x8,   8,  8,   "REG_BANK_1", 0x0002},
        {0x10,  8,  8,   "REG_BANK_2", 0x0004},
        {0x18,  8,  8,   "REG_BANK_3", 0x0008},
        {0x20,  0,  16,  "BSEG_BYTES", 0x0010},
        {0,     0,  128, "UNUSED",     0x0000},
        {0x7f,  0,  128, "DATA",       0x0020},
        {0,     0,  128, "TOTAL:",     0x0000}
    };

    _Mem IRam8051 =  {0xff,   0,   128, "INDIRECT RAM",       0x0080};
    _Mem Stack8051 = {0xff,   0,     1, "STACK",              0x0000};
    _Mem XRam8051 =  {0xffff, 0, 65536, "EXTERNAL RAM",       0x0100};
    _Mem Rom8051 =   {0xffff, 0, 65536, "ROM/EPROM/FLASH",    0x0200};

    _Mem Ram6808[] = {
        {0,     0,      0,       "REG_BANK_0", 0x0001},
        {0x0,   0,      0,       "REG_BANK_1", 0x0002},
        {0x0,   0,      0,       "REG_BANK_2", 0x0004},
        {0x0,   0,      0,       "REG_BANK_3", 0x0008},
        {0x0,   0,      0,       "BSEG_BYTES", 0x0010},
        {0,     0,      256,    "UNUSED",     0x0000},
        {0xff,  0,      256,    "DATA",       0x0020},
        {0,             0,      256, "TOTAL:",     0x0000}
    };

    _Mem IRam6808 =  {0xff,   0,     0, "INDIRECT RAM",           0x0080};
    _Mem Stack6808 = {0xff,   0,     1, "STACK",                          0x0000};
    _Mem XRam6808 =  {0xffff, 0, 65536, "EXTERNAL RAM",           0x0100};
    _Mem Rom6808 =   {0xffff, 0, 65536, "ROM/EPROM/FLASH",        0x0200};

    _Mem *Ram = NULL;

    _Mem IRam =  {0, 0, 0, "", 0};
    _Mem Stack = {0, 0, 0, "", 0};
    _Mem XRam =  {0, 0, 0, "", 0};
    _Mem Rom =   {0, 0, 0, "", 0};

    if (TARGET_IS_8051) {
        Ram = Ram8051;
	memcpy(&IRam, &IRam8051, sizeof (_Mem));
	memcpy(&Stack, &Stack8051, sizeof (_Mem));
	memcpy(&XRam, &XRam8051, sizeof (_Mem));
	memcpy(&Rom, &Rom8051, sizeof (_Mem));
    }
    else {
        Ram = Ram6808;
	memcpy(&IRam, &IRam6808, sizeof (_Mem));
	memcpy(&Stack, &Stack6808, sizeof (_Mem));
	memcpy(&XRam, &XRam6808, sizeof (_Mem));
	memcpy(&Rom, &Rom6808, sizeof (_Mem));
    }

    if (stacksize == 0) stacksize = MIN_STACK;

    if (TARGET_IS_8051) {
        if(rflag) /*For the DS390*/
        {
            XRam.Max=0x1000000; /*24 bits*/
            XRam.Start=0xffffff;
            Rom.Max=0x1000000;
            Rom.Start=0xffffff;
        }

        if((iram_size<=0)||(iram_size>0x100)) /*Default: 8052 like memory*/
        {
            Ram[5].Max=0x80;
            Ram[6].Max=0x80;
            Ram[7].Max=0x80;
            IRam.Max=0x80;
            iram_size=0x100;
        }
        else if(iram_size<0x80)
        {
            Ram[5].Max=iram_size;
            Ram[6].Max=iram_size;
            Ram[7].Max=iram_size;
            IRam.Max=0;
        }
        else
        {
            Ram[5].Max=0x80;
            Ram[6].Max=0x80;
            Ram[7].Max=0x80;
            IRam.Max=iram_size-0x80;
        }
    }

    for(j=0; j<(int)iram_size; j++) dram[j]=0;
    for(; j<0x100; j++) dram[j]=0x8000; /*Memory not available*/

    /* Open Memory Summary File*/
    of = afile(linkp->f_idp, "mem", 1);
    if (of == NULL)
    {
        lkexit(1);
    }

    xp=areap;
    while (xp)
    {
        /**/ if (EQ(xp->a_id, "REG_BANK_0"))
        {
            Ram[0].Size=xp->a_size;
        }
        else if (EQ(xp->a_id, "REG_BANK_1"))
        {
            Ram[1].Size=xp->a_size;
        }
        else if (EQ(xp->a_id, "REG_BANK_2"))
        {
            Ram[2].Size=xp->a_size;
        }
        else if (EQ(xp->a_id, "REG_BANK_3"))
        {
            Ram[3].Size=xp->a_size;
        }
        else if (EQ(xp->a_id, "BSEG_BYTES"))
        {
            if (TARGET_IS_8051)
            	Ram[4].Size+=xp->a_size;
            else
                Ram[4].Size=xp->a_size;
        }

        else if (EQ(xp->a_id, "SSEG"))
        {
            Stack.Size+=xp->a_size;
            if(xp->a_addr<Stack.Start) Stack.Start=xp->a_addr;
        }

        else if (EQ(xp->a_id, "ISEG"))
        {
            IRam.Size+=xp->a_size;
            if(xp->a_addr<IRam.Start) IRam.Start=xp->a_addr;
        }

        else if (TARGET_IS_8051)
        {
            if(xp->a_flag & A_XDATA)
            {
                if(xp->a_size>0)
                {
                    XRam.Size+=xp->a_size;
                    if(xp->a_addr<XRam.Start) XRam.Start=xp->a_addr;
                }
            }

            else if (EQ(xp->a_id, "BIT_BANK"))
            {
                Ram[4].Size+=xp->a_size;
            }

            else if(xp->a_flag & A_CODE)
            {
                if(xp->a_size>0)
                {
                    Rom.Size+=xp->a_size;
                    if(xp->a_addr<Rom.Start) Rom.Start=xp->a_addr;
                }
            }
        }

        else if(TARGET_IS_6808)
        {
            if ( EQ(xp->a_id, "DSEG") || EQ(xp->a_id, "OSEG") )
            {
                Ram[6].Size+=xp->a_size;
                if(xp->a_addr<Ram[6].Start) Ram[6].Start=xp->a_addr;
            }

            else if( EQ(xp->a_id, "CSEG") || EQ(xp->a_id, "GSINIT") ||
                         EQ(xp->a_id, "GSFINAL") || EQ(xp->a_id, "HOME") )
            {
                Rom.Size+=xp->a_size;
                if(xp->a_addr<Rom.Start) Rom.Start=xp->a_addr;
            }

            else if (EQ(xp->a_id, "XSEG") || EQ(xp->a_id, "XISEG"))
            {
                    XRam.Size+=xp->a_size;
                    if(xp->a_addr<XRam.Start) XRam.Start=xp->a_addr;
            }
        }

        /*If is not a register bank, bit, stack, or idata, then it should be data*/
        else if((TARGET_IS_8051 && xp->a_flag & (A_CODE|A_BIT|A_XDATA))==0)
        {
            if(xp->a_size)
            {
                Ram[6].Size+=xp->a_size;
                if(xp->a_addr<Ram[6].Start) Ram[6].Start=xp->a_addr;
            }
        }

        xp=xp->a_ap;
    }

    for(j=0; j<7; j++)
        for(k=Ram[j].Start; (k<(Ram[j].Start+Ram[j].Size))&&(k<0x100); k++)
            dram[k]|=Ram[j].flag; /*Mark as used*/

    if (TARGET_IS_8051) {
        for(k=IRam.Start; (k<(IRam.Start+IRam.Size))&&(k<0x100); k++)
            dram[k]|=IRam.flag; /*Mark as used*/
    }

    /*Compute the amount of unused memory in direct data Ram.  This is the
    gap between the last register bank or bit segment and the data segment.*/
    for(k=Ram[6].Start-1; (dram[k]==0) && (k>0); k--);
    Ram[5].Start=k+1;
    Ram[5].Size=Ram[6].Start-Ram[5].Start; /*It may be zero (which is good!)*/

    /*Compute the data Ram totals*/
    for(j=0; j<7; j++)
    {
        if(Ram[7].Start>Ram[j].Start) Ram[7].Start=Ram[j].Start;
        Ram[7].Size+=Ram[j].Size;
    }
    Total_Last=Ram[6].Size+Ram[6].Start-1;

    /*Report the Ram totals*/
    fprintf(of, "Direct Internal RAM:\n");
    fprintf(of, format, "Name", "Start", "End", "Size", "Max");

    for(j=0; j<8; j++)
    {
        if((j==0) || (j==7)) fprintf(of, format, line, line, line, line, line);
        if((j!=5) || (Ram[j].Size>0))
        {
            sprintf(start, "0x%02lx", Ram[j].Start);
            if(Ram[j].Size==0)
                end[0]=0;/*Empty string*/
            else
                sprintf(end,  "0x%02lx", j==7?Total_Last:Ram[j].Size+Ram[j].Start-1);
            sprintf(size, "%5lu", Ram[j].Size);
            sprintf(max, "%5lu", Ram[j].Max);
            fprintf(of, format, Ram[j].Name, start, end, size, max);
        }
    }

    if (TARGET_IS_8051) {
        for(k=Ram[6].Start; (k<(Ram[6].Start+Ram[6].Size))&&(k<0x100); k++)
        {
            if(dram[k]!=Ram[6].flag)
            {
                sprintf(buff, "Internal memory overlap starting at 0x%02x.\n", k);
                REPORT_ERROR(buff, 1);
                break;
            }
        }

        if(Ram[4].Size>Ram[4].Max)
        {
            k=Ram[4].Size-Ram[4].Max;
            sprintf(buff, "Insufficient bit addressable memory.  "
                        "%d byte%s short.\n", k, (k==1)?"":"s");
            REPORT_ERROR(buff, 1);
        }

        if(Ram[5].Size!=0)
        {
            sprintf(buff, "%ld bytes in data memory wasted.  "
                        "SDCC link could use: --data-loc 0x%02lx\n",
                        Ram[5].Size, Ram[6].Start-Ram[5].Size);
            REPORT_WARNING(buff, 1);
        }

        if((Ram[6].Start+Ram[6].Size)>Ram[6].Max)
        {
            k=(Ram[6].Start+Ram[6].Size)-Ram[6].Max;
            sprintf(buff, "Insufficient space in data memory.   "
                        "%d byte%s short.\n", k, (k==1)?"":"s");
            REPORT_ERROR(buff, 1);
        }
    }

    /*Report the position of the beginning of the stack*/
    fprintf(of, "\n%stack starts at: 0x%02lx (sp set to 0x%02lx)",
        rflag ? "16 bit mode initial s" : "S", Stack.Start, Stack.Start-1);

    if (TARGET_IS_8051) {
        /*Check that the stack pointer is landing in a safe place:*/
        if( (dram[Stack.Start] & 0x8000) == 0x8000 )
        {
            fprintf(of, ".\n");
            sprintf(buff, "Stack set to unavailable memory.\n");
            REPORT_ERROR(buff, 1);
        }
        else if(dram[Stack.Start])
        {
            fprintf(of, ".\n");
            sprintf(buff, "Stack overlaps area ");
            REPORT_ERROR(buff, 1);
            for(j=0; j<7; j++)
            {
                if(dram[Stack.Start]&Ram[j].flag)
                {
                    sprintf(buff, "'%s'\n", Ram[j].Name);
                    break;
                }
            }
            if(dram[Stack.Start]&IRam.flag)
            {
                sprintf(buff, "'%s'\n", IRam.Name);
            }
            REPORT_ERROR(buff, 0);
        }
        else
        {
            for(j=Stack.Start, k=0; (j<(int)iram_size)&&(dram[j]==0); j++, k++);
            fprintf(of, " with %d bytes available\n", k);
            if ((int)k<stacksize)
            {
                sprintf(buff, "Only %d byte%s available for stack.\n",
                    k, (k==1)?"":"s");
                REPORT_WARNING(buff, 1);
            }
        }
    }

    fprintf(of, "\nOther memory:\n");
    fprintf(of, format, "Name", "Start", "End", "Size", "Max");
    fprintf(of, format, line, line, line, line, line);

    /*Report IRam totals:*/
    if(IRam.Size==0)
    {
        start[0]=0;/*Empty string*/
        end[0]=0;/*Empty string*/
    }
    else
    {
        sprintf(start, "0x%02lx", IRam.Start);
        sprintf(end,  "0x%02lx", IRam.Size+IRam.Start-1);
    }
    sprintf(size, "%5lu", IRam.Size);
    sprintf(max, "%5lu", IRam.Max);
    fprintf(of, format, IRam.Name, start, end, size, max);

    /*Report XRam totals:*/
    if(XRam.Size==0)
    {
        start[0]=0;/*Empty string*/
        end[0]=0;/*Empty string*/
    }
    else
    {
        sprintf(start, "0x%04lx", XRam.Start);
        sprintf(end,  "0x%04lx", XRam.Size+XRam.Start-1);
    }
    sprintf(size, "%5lu", XRam.Size);
    sprintf(max, "%5lu", xram_size<0?XRam.Max:xram_size);
    fprintf(of, format, XRam.Name, start, end, size, max);

    /*Report Rom/Flash totals:*/
    if(Rom.Size==0)
    {
        start[0]=0;/*Empty string*/
        end[0]=0;/*Empty string*/
    }
    else
    {
        sprintf(start, "0x%04lx", Rom.Start);
        sprintf(end,  "0x%04lx", Rom.Size+Rom.Start-1);
    }
    sprintf(size, "%5lu", Rom.Size);
    sprintf(max, "%5lu", code_size<0?Rom.Max:code_size);
    fprintf(of, format, Rom.Name, start, end, size, max);

    /*Report any excess:*/
    if (TARGET_IS_8051) {
        if((IRam.Start+IRam.Size)>(IRam.Max+0x80))
        {
            sprintf(buff, "Insufficient INDIRECT RAM memory.\n");
            REPORT_ERROR(buff, 1);
        }
    }
    if( ((XRam.Start+XRam.Size)>XRam.Max) ||
        (((int)XRam.Size>xram_size)&&(xram_size>=0)) )
    {
        sprintf(buff, "Insufficient EXTERNAL RAM memory.\n");
        REPORT_ERROR(buff, 1);
    }
    if( ((Rom.Start+Rom.Size)>Rom.Max) ||
        (((int)Rom.Size>code_size)&&(code_size>=0)) )
    {
        sprintf(buff, "Insufficient ROM/EPROM/FLASH memory.\n");
        REPORT_ERROR(buff, 1);
    }

    fclose(of);
    return toreturn;
  }
  else {
    assert (0);
    return 0;
  }
}
예제 #12
0
/** unittest for oapackage
 *
 * Returns UNITTEST_SUCCESS if all tests are ok.
 *
 */
int oaunittest (int verbose, int writetests = 0, int randval = 0) {
        double t0 = get_time_ms ();
        const char *bstr = "OA unittest";
        cprintf (verbose, "%s: start\n", bstr);

        srand (randval);

        int allgood = UNITTEST_SUCCESS;

        Combinations::initialize_number_combinations (20);

        /* constructors */
        {
                cprintf (verbose, "%s: interaction matrices\n", bstr);

                array_link al = exampleArray (2);
                Eigen::MatrixXd m1 = array2xfeigen (al);
                Eigen::MatrixXd m2 = arraylink2eigen (array2xf (al));

                Eigen::MatrixXd dm = m1 - m2;
                int sum = dm.sum ();

                myassert (sum == 0, "unittest error: construction of interaction matrices\n");
        }

		cprintf(verbose, "%s: reduceConferenceTransformation\n", bstr);
		myassert(unittest_reduceConferenceTransformation()==0, "unittest unittest_reduceConferenceTransformation failed");

        /* constructors */
        {
                cprintf (verbose, "%s: array manipulation operations\n", bstr);

                test_array_manipulation (verbose);
        }

        /* double conference matrices */
        {
                cprintf (verbose, "%s: double conference matrices\n", bstr);

                array_link al = exampleArray (36, verbose);
                myassert (al.is_conference (2), "check on double conference design type");

                myassert (testLMC0checkDC (al, verbose >= 2), "testLMC0checkDC");

        }

        /* conference matrices */
        {
                cprintf (verbose, "%s: conference matrices\n", bstr);

                int N = 4;
                conference_t ctype (N, N, 0);

                arraylist_t kk;
                array_link al = ctype.create_root ();
                kk.push_back (al);

                for (int extcol = 2; extcol < N; extcol++) {
                        kk = extend_conference (kk, ctype, 0);
                }
                myassert (kk.size () == 1, "unittest error: conference matrices for N=4\n");
        }

        {
                cprintf (verbose, "%s: generators for conference matrix extensions\n", bstr);
                test_conference_candidate_generators (verbose);
        }

        {
                cprintf (verbose, "%s: conference matrix Fvalues\n", bstr);
                array_link al = exampleArray (22, 0);
                if (verbose >= 2)
                        al.show ();
                if (0) {
                        std::vector< int > f3 = al.FvaluesConference (3);
                        if (verbose >= 2) {
                                printf ("F3: ");
                                display_vector (f3);
                                printf ("\n");
                        }
                }

                const int N = al.n_rows;
                jstructconference_t js (N, 4);
                std::vector< int > f4 = al.FvaluesConference (4);
                std::vector< int > j4 = js.Jvalues ();

                if (verbose >= 2) {
                        printf ("j4: ");
                        display_vector (j4);
                        printf ("\n");
                        printf ("F4: ");
                        display_vector (f4);
                        printf ("\n");
                }

                myassert (j4[0] == 28, "unittest error: conference matricex F values: j4[0]\n");
                myassert (f4[0] == 0, "unittest error: conference matricex F values: f4[0] \n");
                myassert (f4[1] == 0, "unittest error: conference matricex F values: j4[1]\n");
        }

        {
                cprintf (verbose, "%s: LMC0 check for arrays in C(4, 3)\n", bstr);

                array_link al = exampleArray (28, 1);
                if (verbose >= 2)
                        al.showarray ();
                lmc_t r = LMC0check (al, verbose);
                if (verbose >= 2)
                        printf ("LMC0check: result %d\n", r);
                myassert (r >= LMC_EQUAL, "LMC0 check\n");

                al = exampleArray (29, 1);
                if (verbose >= 2)
                        al.showarray ();
                r = LMC0check (al, verbose);
                if (verbose >= 2)
                        printf ("LMC0check: result %d (LMC_LESS %d)\n", r, LMC_LESS);
                myassert (r == LMC_LESS, "LMC0 check of example array 29\n");
        }

        {
                cprintf (verbose, "%s: LMC0 check\n", bstr);

                array_link al = exampleArray (31, 1);
                if (verbose >= 2)
                        al.showarray ();
                conference_transformation_t T (al);

                for (int i = 0; i < 80; i++) {
                        T.randomize ();
                        array_link alx = T.apply (al);

                        lmc_t r = LMC0check (alx, verbose);

                        if (verbose >= 2) {
                                printfd ("%d: transformed array: r %d\n", i, r);
                                alx.showarray ();
                        }
                        if (alx == al)
                                myassert (r >= LMC_EQUAL, "result should be LMC_MORE\n");
                        else {
                                myassert (r == LMC_LESS, "result should be LMC_LESS\n");
                        }
                }
        }

        {
                cprintf (verbose, "%s: random transformation for conference matrices\n", bstr);

                array_link al = exampleArray (19, 1);
                conference_transformation_t T (al);
                // T.randomizerowflips();
                T.randomize ();

                conference_transformation_t Ti = T.inverse ();
                array_link alx = Ti.apply (T.apply (al));

                if (0) {
                        printf ("input array:\n");
                        al.showarray ();
                        T.show ();
                        printf ("transformed array:\n");
                        T.apply (al).showarray ();
                        Ti.show ();
                        alx.showarray ();
                }

                myassert (alx == al, "transformation of conference matrix\n");
        }

        /* constructors */
        {
                cprintf (verbose, "%s: constructors\n", bstr);

                array_transformation_t t;
                conference_transformation_t ct;
        }

        /* J-characteristics */
        {
                cprintf (verbose, "%s: J-characteristics\n", bstr);

                array_link al = exampleArray (8, 1);

                const int mm[] = {-1, -1, 0, 0, 8, 16, 0, -1};

                for (int jj = 2; jj < 7; jj++) {
                        std::vector< int > jx = al.Jcharacteristics (jj);
                        int j5max = vectormax (jx, 0);
                        if (verbose >= 2) {
                                printf ("oaunittest: jj %d: j5max %d\n", jj, j5max);
                        }

                        if (j5max != mm[jj]) {
                                printfd ("j5max %d (should be %d)\n", j5max, mm[jj]);
                                allgood = UNITTEST_FAIL;
                                return allgood;
                        }
                }
        }
        {
                cprintf (verbose, "%s: array transformations\n", bstr);

                const int N = 9;
                const int t = 3;
                arraydata_t adataX (3, N, t, 4);

                array_link al (adataX.N, adataX.ncols, -1);
                al.create_root (adataX);

                if (checkTransformationInverse (al))
                        allgood = UNITTEST_FAIL;

                if (checkTransformationComposition (al, verbose >= 2))
                        allgood = UNITTEST_FAIL;

                al = exampleArray (5, 1);
                if (checkTransformationInverse (al))
                        allgood = UNITTEST_FAIL;

                if (checkTransformationComposition (al))
                        allgood = UNITTEST_FAIL;

                for (int i = 0; i < 15; i++) {
                        al = exampleArray (18, 0);
                        if (checkConferenceComposition (al))
                                allgood = UNITTEST_FAIL;
                        if (checkConferenceInverse (al))
                                allgood = UNITTEST_FAIL;
                        al = exampleArray (19, 0);
                        if (checkConferenceComposition (al))
                                allgood = UNITTEST_FAIL;
                        if (checkConferenceInverse (al))
                                allgood = UNITTEST_FAIL;
                }
        }

        {
                cprintf (verbose, "%s: rank \n", bstr);

                const int idx[10] = {0, 1, 2, 3, 4, 6, 7, 8, 9};
                const int rr[10] = {4, 11, 13, 18, 16, 4, 4, 29, 29};
                for (int ii = 0; ii < 9; ii++) {
                        array_link al = exampleArray (idx[ii], 0);
                        myassert (al.is2level (), "unittest error: input array is not 2-level\n");

                        int r = arrayrankColPivQR (array2xf (al));

                        int r3 = (array2xf (al)).rank ();
                        myassert (r == r3, "unittest error: rank of array");

                        if (verbose >= 2) {
                                al.showarray ();
                                printf ("unittest: rank of array %d: %d\n", idx[ii], r);
                        }

                        myassert (rr[ii] == r, "unittest error: rank of example matrix\n");
                }
        }

        {
                cprintf (verbose, "%s: Doptimize \n", bstr);
                const int N = 40;
                const int t = 0;
                arraydata_t arrayclass (2, N, t, 6);
                std::vector< double > alpha (3);
                alpha[0] = 1;
                alpha[1] = 1;
                alpha[2] = 0;
                int niter = 5000;
                double t00 = get_time_ms ();
                DoptimReturn rr = Doptimize (arrayclass, 10, alpha, 0, DOPTIM_AUTOMATIC, niter);

                array_t ss[7] = {3, 3, 2, 2, 2, 2, 2};
                arraydata_t arrayclassmixed (ss, 36, t, 5);
                rr = Doptimize (arrayclassmixed, 10, alpha, 0, DOPTIM_AUTOMATIC, niter);

                cprintf (verbose, "%s: Doptimize time %.3f [s] \n", bstr, get_time_ms () - t00);
        }

        {
                cprintf (verbose, "%s: J-characteristics for conference matrix\n", bstr);

                array_link al = exampleArray (19, 0);
                std::vector< int > j2 = Jcharacteristics_conference (al, 2);
                std::vector< int > j3 = Jcharacteristics_conference (al, 3);

                myassert (j2[0] == 0, "j2 value incorrect");
                myassert (j2[1] == 0, "j2 value incorrect");
                myassert (std::abs (j3[0]) == 1, "j3 value incorrect");

                if (verbose >= 2) {
                        al.showarray ();
                        printf ("j2: ");
                        display_vector (j2);
                        printf ("\n");
                        printf ("j3: ");
                        display_vector (j3);
                        printf ("\n");
                }
        }

        {
                // test PEC sequence
                cprintf (verbose, "%s: PEC sequence\n", bstr);
                for (int ii = 0; ii < 5; ii++) {
                        array_link al = exampleArray (ii, 0);
                        std::vector< double > pec = PECsequence (al);
                        printf ("oaunittest: PEC for array %d: ", ii);
                        display_vector (pec);
                        printf (" \n");
                }
        }

        {
                cprintf (verbose, "%s: D-efficiency test\n", bstr);
                //  D-efficiency near-zero test
                {
                        array_link al = exampleArray (14);
                        double D = al.Defficiency ();
                        std::vector< double > dd = al.Defficiencies ();
                        printf ("D %f, D (method 2) %f\n", D, dd[0]);
                        assert (fabs (D - dd[0]) < 1e-4);
                }
                {
                        array_link al = exampleArray (15);
                        double D = al.Defficiency ();
                        std::vector< double > dd = al.Defficiencies ();
                        printf ("D %f, D (method 2) %f\n", D, dd[0]);
                        assert (fabs (D - dd[0]) < 1e-4);
                        assert (fabs (D - 0.335063) < 1e-3);
                }
        }

        arraydata_t adata (2, 20, 2, 6);
        OAextend oaextendx;
        oaextendx.setAlgorithm ((algorithm_t)MODE_ORIGINAL, &adata);

        std::vector< arraylist_t > aa (adata.ncols + 1);
        printf ("OA unittest: create root array\n");
        create_root (&adata, aa[adata.strength]);

        /** Test extend of arrays **/
        {
                cprintf (verbose, "%s: extend arrays\n", bstr);

                setloglevel (SYSTEM);

                for (int kk = adata.strength; kk < adata.ncols; kk++) {
                        aa[kk + 1] = extend_arraylist (aa[kk], adata, oaextendx);
                        printf ("  extend: column %d->%d: %ld->%ld arrays\n", kk, kk + 1, aa[kk].size (),
                                aa[kk + 1].size ());
                }

                if (aa[adata.ncols].size () != 75) {
                        printf ("extended ?? to %d arrays\n", (int)aa[adata.ncols].size ());
                }
                myassert (aa[adata.ncols].size () == 75, "number of arrays is incorrect");

                aa[adata.ncols].size ();
                setloglevel (QUIET);
        }

        {
                cprintf (verbose, "%s: test LMC check\n", bstr);

                array_link al = exampleArray (1, 1);

                lmc_t r = LMCcheckOriginal (al);

                myassert (r != LMC_LESS, "LMC check of array in normal form");

                for (int i = 0; i < 20; i++) {
                        array_link alx = al.randomperm ();
                        if (alx == al)
                                continue;
                        lmc_t r = LMCcheckOriginal (alx);

                        myassert (r == LMC_LESS, "randomized array cannot be in minimal form");
                }
        }

        {
                /** Test dof **/
                cprintf (verbose, "%s: test delete-one-factor reduction\n", bstr);

                array_link al = exampleArray (4);
                cprintf (verbose >= 2, "LMC: \n");
                al.reduceLMC ();
                cprintf (verbose >= 2, "DOP: \n");
                al.reduceDOP ();
        }

        arraylist_t lst;

        {
                /** Test different methods **/
                cprintf (verbose, "%s: test 2 different methods\n", bstr);

                const int s = 2;
                arraydata_t adata (s, 32, 3, 10);
                arraydata_t adata2 (s, 32, 3, 10);
                OAextend oaextendx;
                oaextendx.setAlgorithm ((algorithm_t)MODE_ORIGINAL, &adata);
                OAextend oaextendx2;
                oaextendx2.setAlgorithm ((algorithm_t)MODE_LMC_2LEVEL, &adata2);

                printf ("OA unittest: test 2-level algorithm on %s\n", adata.showstr ().c_str ());
                std::vector< arraylist_t > aa (adata.ncols + 1);
                create_root (&adata, aa[adata.strength]);
                std::vector< arraylist_t > aa2 (adata.ncols + 1);
                create_root (&adata, aa2[adata.strength]);

                setloglevel (SYSTEM);

                for (int kk = adata.strength; kk < adata.ncols; kk++) {
                        aa[kk + 1] = extend_arraylist (aa[kk], adata, oaextendx);
                        aa2[kk + 1] = extend_arraylist (aa2[kk], adata2, oaextendx2);
                        printf ("  extend: column %d->%d: %ld->%ld arrays, 2-level method %ld->%ld arrays\n", kk,
                                kk + 1, (long) aa[kk].size (), (long)aa[kk + 1].size (), aa2[kk].size (), aa2[kk + 1].size ());

                        if (aa[kk + 1] != aa2[kk + 1]) {
                                printf ("oaunittest: error: 2-level algorithm unequal to original algorithm\n");
                                exit (1);
                        }
                }
                setloglevel (QUIET);

                lst = aa[8];
        }

        {
                cprintf (verbose, "%s: rank calculation using rankStructure\n", bstr);

                for (int i = 0; i < 27; i++) {
                        array_link al = exampleArray (i, 0);
                        if (al.n_columns < 5)
                                continue;
                        al = exampleArray (i, 1);

                        rankStructure rs;
                        rs.verbose = 0;
                        int r = array2xf (al).rank ();
                        int rc = rs.rankxf (al);
                        if (verbose >= 2) {
                                printf ("rank of example array %d: %d %d\n", i, r, rc);
                                if (verbose >= 3) {
                                        al.showproperties ();
                                }
                        }
                        myassert (r == rc, "rank calculations");
                }
        }
        {
                cprintf (verbose, "%s: test dtable creation\n", bstr);

                for (int i = 0; i < 4; i++) {
                        array_link al = exampleArray (5);
                        array_link dtable = createJdtable (al);
                }
        }

        {
                cprintf (verbose, "%s: test Pareto calculation\n", bstr);
                double t0x = get_time_ms ();

                int nn = lst.size ();
                for (int k = 0; k < 5; k++) {
                        for (int i = 0; i < nn; i++) {
                                lst.push_back (lst[i]);
                        }
                }
                Pareto< mvalue_t< long >, long > r = parsePareto (lst, 1);
                cprintf (verbose, "%s: test Pareto %d/%d: %.3f [s]\n", bstr, r.number (), r.numberindices (),
                         (get_time_ms () - t0x));
        }

        {
                cprintf (verbose, "%s: check reduction transformation\n", bstr);
                array_link al = exampleArray (6).reduceLMC ();

                arraydata_t adata = arraylink2arraydata (al);
                LMCreduction_t reduction (&adata);
                reduction.mode = OA_REDUCE;

                reduction.init_state = COPY;
                OAextend oaextend;
                oaextend.setAlgorithm (MODE_ORIGINAL, &adata);
                array_link alr = al.randomperm ();

                array_link al2 = reduction.transformation->apply (al);

                lmc_t tmp = LMCcheck (alr, adata, oaextend, reduction);

                array_link alx = reduction.transformation->apply (alr);

                bool c = alx == al;
                if (!c) {
                        printf ("oaunittest: error: reduction of randomized array failed!\n");
                        printf ("-- al \n");
                        al.showarraycompact ();
                        printf ("-- alr \n");
                        alr.showarraycompact ();
                        printf ("-- alx \n");
                        alx.showarraycompact ();
                        allgood = UNITTEST_FAIL;
                }
        }

        {
                cprintf (verbose, "%s: reduce randomized array\n", bstr);
                array_link al = exampleArray (3);

                arraydata_t adata = arraylink2arraydata (al);
                LMCreduction_t reduction (&adata);

                for (int ii = 0; ii < 50; ii++) {
                        reduction.transformation->randomize ();
                        array_link al2 = reduction.transformation->apply (al);

                        array_link alr = al2.reduceLMC ();
                        if (0) {
                                printf ("\n reduction complete:\n");
                                al2.showarray ();
                                printf ("	--->\n");
                                alr.showarray ();
                        }
                        bool c = (al == alr);
                        if (!c) {
                                printf ("oaunittest: error: reduction of randomized array failed!\n");
                                allgood = UNITTEST_FAIL;
                        }
                }
        }

        /* Calculate symmetry group */
        {
                cprintf (verbose, "%s: calculate symmetry group\n", bstr);

                array_link al = exampleArray (2);
                symmetry_group sg = al.row_symmetry_group ();
                assert (sg.permsize () == sg.permsize_large ().toLong ());

                // symmetry_group
                std::vector< int > vv;
                vv.push_back (0);
                vv.push_back (0);
                vv.push_back (1);
                symmetry_group sg2 (vv);
                assert (sg2.permsize () == 2);
                if (verbose >= 2)
                        printf ("sg2: %ld\n", sg2.permsize ());
                assert (sg2.ngroups == 2);
        }

        /* Test efficiencies */
        {
                cprintf (verbose, "%s: efficiencies\n", bstr);

                std::vector< double > d;
                int vb = 1;

                array_link al;
                if (1) {
                        al = exampleArray (9, vb);
                        al.showproperties ();
                        d = al.Defficiencies (0, 1);
                        if (verbose >= 2)
                                printf ("  efficiencies: D %f Ds %f D1 %f Ds0 %f\n", d[0], d[1], d[2], d[3]);
                        if (fabs (d[0] - al.Defficiency ()) > 1e-10) {
                                printf ("oaunittest: error: Defficiency not good!\n");
                                allgood = UNITTEST_FAIL;
                        }
                }
                al = exampleArray (8, vb);
                al.showproperties ();
                d = al.Defficiencies ();
                if (verbose >= 2)
                        printf ("  efficiencies: D %f Ds %f D1 %f\n", d[0], d[1], d[2]);
                if (fabs (d[0] - al.Defficiency ()) > 1e-10) {
                        printf ("oaunittest: error: Defficiency of examlple array 8 not good!\n");
                }

                al = exampleArray (13, vb);
                if (verbose >= 3) {
                        al.showarray ();
                        al.showproperties ();
                }
                d = al.Defficiencies (0, 1);
                if (verbose >= 2)
                        printf ("  efficiencies: D %f Ds %f D1 %f\n", d[0], d[1], d[2]);

                if ((fabs (d[0] - 0.939014) > 1e-4) || (fabs (d[3] - 0.896812) > 1e-4) || (fabs (d[2] - 1) > 1e-4)) {
                        printf ("ERROR: D-efficiencies of example array 13 incorrect! \n");
                        d = al.Defficiencies (2, 1);
                        printf ("  efficiencies: D %f Ds %f D1 %f Ds0 %f\n", d[0], d[1], d[2], d[3]);

                        allgood = UNITTEST_FAIL;
                        exit (1);
                }

                for (int ii = 11; ii < 11; ii++) {
                        printf ("ii %d: ", ii);
                        al = exampleArray (ii, vb);
                        al.showarray ();
                        al.showproperties ();

                        d = al.Defficiencies ();
                        if (verbose >= 2)
                                printf ("  efficiencies: D %f Ds %f D1 %f\n", d[0], d[1], d[2]);
                }
        }
        {
                cprintf (verbose, "%s: test robustness\n", bstr);

                array_link A (0, 8, 0);
                printf ("should return an error\n  ");
                A.Defficiencies ();

                A = array_link (1, 8, 0);
                printf ("should return an error\n  ");
                A.at (0, 0) = -2;
                A.Defficiencies ();
        }

        {
                cprintf (verbose, "%s: test nauty\n", bstr);

                array_link alr = exampleArray (7, 0);
                if (unittest_nautynormalform (alr, 1) == 0) {
                        printf ("oaunittest: error: unittest_nautynormalform returns an error!\n");
                }
        }

#ifdef HAVE_BOOST
        if (writetests) {
                cprintf (verbose, "OA unittest: reading and writing of files\n");

                boost::filesystem::path tmpdir = boost::filesystem::temp_directory_path ();
                boost::filesystem::path temp = boost::filesystem::unique_path ("test-%%%%%%%.oa");

                const std::string tempstr = (tmpdir / temp).native (); 

                if (verbose >= 2)
                        printf ("generate text OA file: %s\n", tempstr.c_str ());

                int nrows = 16;
                int ncols = 8;
                int narrays = 10;
                arrayfile_t afile (tempstr.c_str (), nrows, ncols, narrays, ATEXT);
                for (int i = 0; i < narrays; i++) {
                        array_link al (nrows, ncols, array_link::INDEX_DEFAULT);                        
                        afile.append_array (al);
                }
                afile.closefile ();

                arrayfile_t af (tempstr.c_str (), 0);
                std::cout << "  " << af.showstr () << std::endl;
                af.closefile ();

                // check read/write of binary file

                arraylist_t ll0;
                ll0.push_back (exampleArray (7));
                ll0.push_back (exampleArray (7).randomcolperm ());
                writearrayfile (tempstr.c_str (), ll0, ABINARY);
                arraylist_t ll = readarrayfile (tempstr.c_str ());
                myassert (ll0.size () == ll.size (), "read and write of arrays: size of list");
                for (size_t i = 0; i < ll0.size (); i++) {
                        myassert (ll0[i] == ll[i], "read and write of arrays: array unequal");
                }

                ll0.resize (0);
                ll0.push_back (exampleArray (24));
                writearrayfile (tempstr.c_str (), ll0, ABINARY_DIFFZERO);
                ll = readarrayfile (tempstr.c_str ());
                myassert (ll0.size () == ll.size (), "read and write of arrays: size of list");
                for (size_t i = 0; i < ll0.size (); i++) {
                        myassert (ll0[i] == ll[i], "read and write of arrays: array unequal");
                }
        }

#endif

        {
                cprintf (verbose, "OA unittest: test nauty\n");
                array_link al = exampleArray (5, 2);
                arraydata_t arrayclass = arraylink2arraydata (al);

                for (int i = 0; i < 20; i++) {
                        array_link alx = al;
                        alx.randomperm ();
                        array_transformation_t t1 = reduceOAnauty (al);
                        array_link alr1 = t1.apply (al);

                        array_transformation_t t2 = reduceOAnauty (alx);
                        array_link alr2 = t2.apply (alx);

                        if (alr1 != alr2)
                                printf ("oaunittest: error: Nauty reductions unequal!\n");
                        allgood = UNITTEST_FAIL;
                }
        }

        cprintf (verbose, "OA unittest: complete %.3f [s]!\n", (get_time_ms () - t0));
        cprintf (verbose, "OA unittest: also run ptest.py to perform checks!\n");

        if (allgood) {
                printf ("OA unittest: all tests ok\n");
                return UNITTEST_SUCCESS;
        } else {
                printf ("OA unittest: ERROR!\n");
                return UNITTEST_FAIL;
        }
}
예제 #13
0
bool PCBMODEL::getModelLabel( const std::string aFileName, TDF_Label& aLabel )
{
    MODEL_MAP::const_iterator mm = m_models.find( aFileName );

    if( mm != m_models.end() )
    {
        aLabel = mm->second;
        return true;
    }

    aLabel.Nullify();

    Handle( TDocStd_Document )  doc;
    m_app->NewDocument( "MDTV-XCAF", doc );

    FormatType modelFmt = fileType( aFileName.c_str() );

    switch( modelFmt )
    {
        case FMT_IGES:
            if( !readIGES( doc, aFileName.c_str() ) )
            {
                std::ostringstream ostr;
#ifdef __WXDEBUG__
                ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
#endif /* __WXDEBUG */
                ostr << "  * readIGES() failed on filename '" << aFileName << "'\n";
                wxLogMessage( "%s", ostr.str().c_str() );
                return false;
            }
            break;

        case FMT_STEP:
            if( !readSTEP( doc, aFileName.c_str() ) )
            {
                std::ostringstream ostr;
#ifdef __WXDEBUG__
                ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
#endif /* __WXDEBUG */
                ostr << "  * readSTEP() failed on filename '" << aFileName << "'\n";
                wxLogMessage( "%s", ostr.str().c_str() );
                return false;
            }
            break;

        case FMT_WRL:
            /* WRL files are preferred for internal rendering,
             * due to superior material properties, etc.
             * However they are not suitable for MCAD export.
             *
             * If a .wrl file is specified, attempt to locate
             * a replacement file for it.
             *
             * If a valid replacement file is found, the label
             * for THAT file will be associated with the .wrl file
             *
             */
            {
                wxFileName wrlName( aFileName );

                wxString basePath = wrlName.GetPath();
                wxString baseName = wrlName.GetName();

                // List of alternate files to look for
                // Given in order of preference
                // (Break if match is found)
                wxArrayString alts;

                // Step files
                alts.Add( "stp" );
                alts.Add( "step" );
                alts.Add( "STP" );
                alts.Add( "STEP" );
                alts.Add( "Stp" );
                alts.Add( "Step" );

                // IGES files
                alts.Add( "iges" );
                alts.Add( "IGES" );
                alts.Add( "igs" );
                alts.Add( "IGS" );

                //TODO - Other alternative formats?

                for( auto alt : alts )
                {
                    wxFileName altFile( basePath, baseName + "." + alt );

                    if( altFile.IsOk() && altFile.FileExists() )
                    {
                        std::string altFileName = altFile.GetFullPath().ToStdString();

                        if( getModelLabel( altFileName, aLabel ) )
                        {
                            return true;
                        }
                    }
                }
            }

            break;

        // TODO: implement IDF and EMN converters

        default:
            return false;
    }

    aLabel = transferModel( doc, m_doc );

    if( aLabel.IsNull() )
    {
        std::ostringstream ostr;
#ifdef __WXDEBUG__
        ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
#endif /* __WXDEBUG */
        ostr << "  * could not transfer model data from file '" << aFileName << "'\n";
        wxLogMessage( "%s", ostr.str().c_str() );
        return false;
    }

    // attach the PART NAME ( base filename: note that in principle
    // different models may have the same base filename )
    wxFileName afile( aFileName.c_str() );
    std::string pname( afile.GetName().ToUTF8() );
    TCollection_ExtendedString partname( pname.c_str() );
    TDataStd_Name::Set( aLabel, partname );

    m_models.insert( MODEL_DATUM( aFileName, aLabel ) );
    ++m_components;
    return true;
}
예제 #14
0
int main(int argc, char** argv){
    if(argc == 5){
        /* Open the graph file */
        std::ifstream gfile(argv[1]);
        std::ifstream afile(argv[2]);
        std::ofstream ofile(argv[3]);

        int num_cols = atoi(argv[4]);

        std::string eline;
        std::unordered_map<std::string,int> labels; // node_label <-- node_id taken from original graph file
        std::unordered_map<int,std::string> rev_labels; // node_id <-- node_label
        
        int node_count = 0;

        if(gfile.is_open()){
            while(getline(gfile, eline)){

                /* get an edge from the file */
                std::istringstream buff(eline);
                std::string from_label, to_label;
                int from, to;

                buff >> from_label;
                buff >> to_label;

                if(labels.find(from_label) == labels.end()) { //if the node is encountered for the first time
                    from = node_count++;
                    labels.insert(std::make_pair(from_label,from)); //index labelled node to a node id
                    rev_labels.insert(std::make_pair(from,from_label)); //index labelled node to a node id
                }

                if(labels.find(to_label) == labels.end()) { //if the node is encountered for the first time
                    to = node_count++;
                    labels.insert(std::make_pair(to_label, to)); //index labelled node to a node id
                    rev_labels.insert(std::make_pair(to,to_label)); //index labelled node to a node id
                }

            }
            gfile.close();

            std::cout << "printing labels : " << std::endl;
            for(auto it=labels.begin(); it != labels.end(); ++it){
                std::cout << it->first << " ->  " << it->second << std::endl;
            }
            std::cout << "printing rev labels : " << std::endl;
            for(auto it=rev_labels.begin(); it != rev_labels.end(); ++it){
                std::cout << it->first << " ->  " << it->second << std::endl;
            }



            if(afile.is_open()){
                while(getline(afile, eline)){

                    /* get an edge from the file */
                    std::istringstream buff(eline);
                    int node_id;
                    std::string orig_label, temp;

                    for(int i = 0; i < num_cols; i++){
                        if(i != 0){
                            ofile << " "; // put space character between values
                        }
                        buff >> node_id;

                        if(rev_labels.find(node_id) != rev_labels.end()) { //if node id in gc format exists in our table
                            orig_label = rev_labels[node_id];
                            ofile << orig_label;
                        }
                        else std::cout<< node_id <<" not in the map" << std::endl;
                    }

                    //write the rest of the columns as it is
                    while((char)buff.peek() != '\n' && buff.good()){
                        ofile << " "; // put space character between values
                        buff >> temp;
                        ofile << temp;
                    }

                    ofile << std::endl; // after reading all values on the line, end the line in output file.
                }
                afile.close();
                ofile.close();
            }
            else std::cout << "Unable to open second input file for reading." << std::endl;
        }
예제 #15
0
bool MP3Header::readMP3( const QString & path )
{
        QFile afile( path );

        if ( afile.open( IO_ReadOnly ) == false )
                return false;

        //  0000 0000 0000 0000 0000 0000 0000 0000
        char tmp[14];
        unsigned long bithdr;
        int trycnt = 0;

        afile.readBlock( &tmp[1], 3 );

        do {
                tmp[0]=tmp[1];
                tmp[1]=tmp[2];
                tmp[2]=tmp[3];
                afile.readBlock(&tmp[3],1);

                if ( trycnt == 0 && tmp[0] == 'I' && tmp[1] == 'D' &&
                     tmp[2] == '3' && tmp[3] <= 0x3 )
                {
                        // some mp3 seem to have the tag at the start of the file
                        // - starts with ID3\0003

                        // look for the possible header

                        while( tmp[0] != -1 )
                        {
                                if ( afile.atEnd() )
                                        return false;
                                afile.readBlock( &tmp[0], 1 );
                        }

                        afile.readBlock( &tmp[1], 3 );
                }

                bithdr = (unsigned long) (
                         ( (tmp[0] & 255) << 24) | ( (tmp[1] & 255) << 16) |
                         ( (tmp[2] & 255) <<  8) | ( (tmp[3] & 255)      )
                        );

                this->sync      = ( bithdr >> 21 ) & 0x7ff;
                this->version   = ( bithdr >> 19 ) & 0x3;
                this->layer     = ( bithdr >> 17 ) & 0x3;
                this->bitrate   = ( bithdr >> 12 ) & 0xf;
                this->freq      = ( bithdr >> 10 ) & 0x3;

                trycnt++;

                if ( trycnt >= 500 )
                        return false;

                }
        while ( this->sync != 0x7ff  ||
                this->version == 1   ||
                this->layer == 0     ||
                this->bitrate == 0xf ||
                this->freq == 3 );

        this->protect = ( bithdr >> 16 ) & 0x1;

        // get index & calc brate from it
        this->bitrate =
                bitrate_tbl[this->version & 1][this->layer - 1][this->bitrate];

        this->freq =
                freq_tbl[this->version][this->freq];

        this->padding   = ( bithdr >> 9 ) & 0x1;
        this->channels  = ( bithdr >> 6 ) & 0x3;
        this->ext       = ( bithdr >> 4 ) & 0x3;
        this->copyright = ( bithdr >> 3 ) & 0x1;
        this->original  = ( bithdr >> 2 ) & 0x1;
        this->emphasis  = ( bithdr & 0x3 );

        int skip = 0;

        // is there a variable bit rate bit
        if ( this->version == 3 )
        {  // mpeg version 1
                if ( this->channels == 3 )
                        skip = 17; // Single Channel
                else
                        skip = 32;
  }
  else { // mpeg version 2 or 2.5
   if(this->channels==3 ) skip = 9; // Single Channel
   else skip = 17;
  }

  // read next twelve bits in
  for(int i=0;i<skip;i++) afile.readBlock(tmp,1);

  afile.readBlock (tmp, 12);

  if(strncmp("Xing",tmp,4)==0) {
     bithdr = (unsigned long)(
        (tmp[4] << 24) |
        (tmp[5] << 16) |
        (tmp[6] <<  8) |
        (tmp[7]      )
     );
     if(bithdr &  1) { // there is frame data
      // get the num of frames
       bithdr = (unsigned long)(
        (tmp[8] << 24) |
        (tmp[9] << 16) |
        (tmp[10] <<  8) |
        (tmp[11]      )
       );

       float framesize = (float)afile.size() / (float)bithdr;
       this->bitrate =
         (int)(( framesize * (float)this->freq)
              /( 1000.0 * ( (this->layer==3) ? 12.0 : 144.0)) );
     }
  }

  this->seconds = (8 * afile.size() ) / 1000;
  if(this->bitrate) this->seconds=this->seconds/this->bitrate;
  else this->seconds=0;

  return true;
}