Пример #1
0
int main(int argc, char* arg[])
{
    printf("Map & DBC Extractor\n");
    printf("===================\n\n");

    HandleArgs(argc, arg);

    // Open MPQs
    LoadCommonMPQFiles();

    // Extract dbc
    if (CONF_extract & EXTRACT_DBC)
        ExtractDBCFiles();

    if (CONF_extract & EXTRACT_CAMERA)
        ExtractCameraFiles();

    // Extract maps
    if (CONF_extract & EXTRACT_MAP)
        ExtractMapsFromMpq();

    // Close MPQs
    CloseMPQFiles();

    return 0;
}
Пример #2
0
SaneWinMain( argc, argv )
{
   int result;
	PBANNER banner = NULL;
	if( !HandleArgs( argc, argv ) )
      return 0;

	if( !l.back_color )
      l.back_color = 0xFF000000;
	if( !l.text_color )
      l.text_color = 0xFFFFFFFF;

	result = CreateBanner2Extended( NULL, &banner, l.text
											, (l.flags.bYesNo?BANNER_OPTION_YESNO:0)
											 |( l.flags.bOkayCancel?BANNER_OPTION_OKAYCANCEL:0)
											 |( l.flags.bTop?BANNER_TOP:0)
											 |((l.flags.bYesNo||l.flags.bOkayCancel)?0:BANNER_CLICK)
											 |((l.timeout)?BANNER_TIMEOUT:0)
											 |((l.flags.bDead)?BANNER_DEAD:0)
											 |((l.flags.bAlpha)?BANNER_ALPHA:0)
											, l.timeout
											, l.text_color
											, l.back_color
											, l.lines
											, l.columns
											, l.display );

	{
		int result2 = WaitForBanner2( banner );
      lprintf( WIDE( "result is %d" ), result,result2 );
		return result;
	}

   return 0;
}
Пример #3
0
int main(int argc, char * arg[])
{
    printf("Map & DBC Extractor\n");
    printf("===================\n\n");

    HandleArgs(argc, arg);

    uint32 build = 0;

    // Open MPQs
    LoadCommonMPQFiles();

    if (CONF_extract & EXTRACT_DBC)
    {
        // Extract DBC Files.
        ExtractDBCFiles();
    }

    if (CONF_extract & EXTRACT_MAP)
    {
        printf("Loading files.. \n");

        // Extract maps
        ExtractMapsFromMpq(build);
    }

    // Close MPQs
    CloseMPQFiles();

    return 0;
}
Пример #4
0
/**
 * @brief
 *
 * @param argc
 * @param argv
 * @return int
 */
int main(int argc, char** argv)
{
    printf("mangos-zero DBC & map (version %s) extractor\n\n", MAP_VERSION_MAGIC);

    if (!HandleArgs(argc, argv))
    {
        return 1;
    }

    // Open MPQs
    LoadCommonMPQFiles();

    // Extract dbc
    if (CONF_extract & EXTRACT_DBC)
        { ExtractDBCFiles(); }

    // Extract maps
    if (CONF_extract & EXTRACT_MAP)
        { ExtractMapsFromMpq(); }

    // Close MPQs
    CloseMPQFiles();

    return 0;
}
Пример #5
0
int main(int argc, char* argv[])
{
    system("pause");
    Cache = new CacheClass();
    MPQHandler = new MPQManager();
    MPQHandler->Initialize();
    uint32 threads = 4;
    std::set<uint32> mapIds;
    bool debug = false;

    if (!HandleArgs(argc, argv, threads, mapIds, debug))
    {
        PrintUsage();
        return -1;
    }

    ExtractAllMaps(mapIds, threads, debug);
    return 0;
}
Пример #6
0
int main(int argc, char * arg[])
{
    printf("Map & DBC Extractor\n");
    printf("===================\n\n");

    HandleArgs(argc, arg);

    int FirstLocale = -1;
    uint32 build = 0;

    for (int i = 0; i < LOCALES_COUNT; ++i)
    {
        TCHAR tmp1[512];
        _stprintf(tmp1, _T("%s/Data/%s/locale-%s.MPQ"), input_path, Locales[i], Locales[i]);

        //Open MPQs
        if (!LoadLocaleMPQFile(i))
        {
            if (GetLastError() != ERROR_PATH_NOT_FOUND)
                printf("Unable to load %s locale archives!\n", Locales[i]);
            continue;
        }

        printf("Detected locale: %s\n", Locales[i]);
        if ((CONF_extract & EXTRACT_DBC) == 0)
        {
            FirstLocale = i;
            build = ReadBuild(i);
            if (build > CONF_TargetBuild)
            {
                printf("Base locale-%s.MPQ has build higher than target build (%u > %u), nothing extracted!\n", Locales[i], build, CONF_TargetBuild);
                return 0;
            }

            printf("Detected client build: %u\n", build);
            break;
        }

        //Extract DBC files
        uint32 tempBuild = ReadBuild(i);
        printf("Detected client build %u for locale %s\n", tempBuild, Locales[i]);
        if (tempBuild > CONF_TargetBuild)
        {
            printf("Base locale-%s.MPQ has build higher than target build (%u > %u), nothing extracted!\n", Locales[i], tempBuild, CONF_TargetBuild);
            continue;
        }

        ExtractDBCFiles(i, FirstLocale < 0);
        ExtractDB2Files(i, FirstLocale < 0);

        if (FirstLocale < 0)
        {
            FirstLocale = i;
            build = tempBuild;
        }

        //Close MPQs
        SFileCloseArchive(LocaleMpq);
    }

    if (FirstLocale < 0)
    {
        printf("No locales detected\n");
        return 0;
    }

    if (CONF_extract & EXTRACT_MAP)
    {
        printf("Using locale: %s\n", Locales[FirstLocale]);

        // Open MPQs
        LoadLocaleMPQFile(FirstLocale);
        LoadCommonMPQFiles(build);

        // Extract maps
        ExtractMapsFromMpq(build);

        // Close MPQs
        SFileCloseArchive(WorldMpq);
        SFileCloseArchive(LocaleMpq);
    }

    return 0;
}
Пример #7
0
return_val Init( void )
{
    return_val          error;
    const char *        const *list;
    const char          *name;
    hash_entry_data     key_entry;

    error = RC_OKAY;

    OutputDest = STDOUT_FILENO;
    ChangePrintDest( OutputDest );

    relocSections.first = NULL;
    relocSections.last = NULL;
    if( !MsgInit() ) {
        // MsgInit does its own error message printing
        return( RC_ERROR );
    }
    MemOpen();

    error = HandleArgs();
    if( error != RC_OKAY ) {
        return( error );
    }

    openFiles();
    initGlobals();
    error = initHashTables();
    if( error != RC_OKAY ) {
        PrintErrorMsg( error, WHERE_INIT_HASH_TABLES );
        return( error );
    }
    error = initServicesUsed();
    if( error != RC_OKAY ) {
        // initServicesUsed does its own error message printing
        return( error );
    }
    error = initSectionTables();
    if( error != RC_OKAY ) {
        PrintErrorMsg( error, WHERE_CREATE_SEC_TABLES );
        return( error );
    }
    if( Options & PRINT_PUBLICS ) {
        CreatePublicsArray();
    }
    if( IsMasmOutput() ) {
        CommentString = MASM_COMMENT_STRING;
    }
    if( IsIntelx86() ) {
        SkipRefTable = HashTableCreate( RECOGNITION_TABLE_SIZE, HASH_STRING_IGNORECASE );
        if( SkipRefTable != NULL ) {
            for( list = intelSkipRefList; (name = *list) != NULL; ++list ) {
                key_entry.key.u.string = name;
                key_entry.data.u.string = *list;
                error = HashTableInsert( SkipRefTable, &key_entry );
                if( error != RC_OKAY ) {
                    break;
                }
            }
        }
    }
    if( LabelChar == 0 ) {
        if( IsMasmOutput() ) {
            LabelChar = 'L';
        } else {
            LabelChar = 'X';
        }
    }
    return( error );
}
Пример #8
0
void Init( void )
{
    char                cmd_line[ CMD_LINE_LEN ];
    return_val          error;
    char                **list;

    OutputDest = STDOUT_FILENO;
    ChangePrintDest( OutputDest );

    relocSections.first = NULL;
    relocSections.last = NULL;
    if( !MsgInit() ) {
        // MsgInit does its own error message printing
        exit( -1 );
    }
    MemOpen();

    getcmd( cmd_line );
    HandleArgs( cmd_line );

    openFiles();
    initGlobals();
    error = initHashTables();
    if( error == OKAY ) {
        error = initServicesUsed();
        if( error == OKAY ) {
            error = initSectionTables();
            if( error != OKAY ) {
                // free hash tables and services
                MemClose();
                LeaveProgram( error, WHERE_CREATE_SEC_TABLES );
            }
        } else {
            // free hash tables
            CloseFiles();
            FreeHashTables();
            // initServicesUsed does its own error message printing
            exit( error );
        }
    } else {
        CloseFiles();
        MemClose();
        LeaveProgram( error, WHERE_INIT_HASH_TABLES );
    }
    if( Options & PRINT_PUBLICS ) {
        CreatePublicsArray();
    }
    if( IsMasmOutput() ) {
        CommentString = MASM_COMMENT_STRING;
    }
    if( IsIntelx86() ) {
        SkipRefTable = HashTableCreate( RECOGNITION_TABLE_SIZE, HASH_STRING,
                                        (hash_table_comparison_func) stricmp );
        if( SkipRefTable ) {
            list = intelSkipRefList;
            while( *list ) {
                error = HashTableInsert( SkipRefTable, (hash_value) *list,
                                         (hash_data) *list );
                if( error != OKAY ) break;
                list++;
            }
        }
    }

    if( !LabelChar ) {
        if( IsMasmOutput() ) {
            LabelChar = 'L';
        } else {
            LabelChar = 'X';
        }
    }
}
Пример #9
0
int main(int argc, char * arg[])
{
    printf("Map & DBC Extractor\n");
    printf("===================\n\n");

    HandleArgs(argc, arg);

    int FirstLocale = -1;

    for (int i = 0; i < LANG_COUNT; i++)
    {
        char tmp1[512];
        sprintf(tmp1, "%s/Data/%s/locale-%s.MPQ", input_path, langs[i], langs[i]);
        if (FileExists(tmp1))
        {
            printf("Detected locale: %s\n", langs[i]);

            //Open MPQs
            LoadLocaleMPQFiles(i);

            if((extract & EXTRACT_DBC) == 0)
            {
                FirstLocale = i;
                break;
            }

            //Extract DBC files
            if(FirstLocale < 0)
            {
                ExtractDBCFiles(i, true);
                FirstLocale = i;
            }
            else
                ExtractDBCFiles(i, false);

            //Close MPQs
            CloseMPQFiles();
        }
    }

    if(FirstLocale < 0)
    {
        printf("No locales detected\n");
        return 0;
    }

    if (extract & EXTRACT_MAP)
    {
        printf("Using locale: %s\n", langs[FirstLocale]);

        // Open MPQs
        LoadLocaleMPQFiles(FirstLocale);
        LoadCommonMPQFiles();

        // Extract maps
        ExtractMapsFromMpq();

        // Close MPQs
        CloseMPQFiles();
    }

    return 0;
}
Пример #10
0
int main(int argc, char * arg[])
{
    printf("Map & DBC Extractor\n");
    printf("===================\n\n");

    HandleArgs(argc, arg);

    int FirstLocale = -1;
    uint32 build = 0;

    for (int i = 0; i < LANG_COUNT; i++)
    {
        std::string filename = Trinity::StringFormat("%s/Data/%s/locale-%s.MPQ", input_path, langs[i], langs[i]);
        if (boost::filesystem::exists(filename))
        {
            printf("Detected locale: %s\n", langs[i]);

            //Open MPQs
            LoadLocaleMPQFiles(i);

            if((CONF_extract & EXTRACT_DBC) == 0)
            {
                FirstLocale = i;
                build = ReadBuild(FirstLocale);
                printf("Detected client build: %u\n", build);
                break;
            }

            //Extract DBC files
            if(FirstLocale < 0)
            {
                FirstLocale = i;
                build = ReadBuild(FirstLocale);
                printf("Detected client build: %u\n", build);
                ExtractDBCFiles(i, true);
            }
            else
                ExtractDBCFiles(i, false);

            //Close MPQs
            CloseMPQFiles();
        }
    }

    if(FirstLocale < 0)
    {
        printf("No locales detected\n");
        return 0;
    }

    if (CONF_extract & EXTRACT_CAMERA)
    {
        printf("Using locale: %s\n", langs[FirstLocale]);

        // Open MPQs
        LoadLocaleMPQFiles(FirstLocale);
        LoadCommonMPQFiles();

        ExtractCameraFiles(FirstLocale, true);
        // Close MPQs
        CloseMPQFiles();
    }

    if (CONF_extract & EXTRACT_MAP)
    {
        printf("Using locale: %s\n", langs[FirstLocale]);

        // Open MPQs
        LoadLocaleMPQFiles(FirstLocale);
        LoadCommonMPQFiles();

        // Extract maps
        ExtractMapsFromMpq(build);

        // Close MPQs
        CloseMPQFiles();
    }

    return 0;
}
Пример #11
0
int main(int argc, char* arg[])
{
    printf("Map & DBC Extractor\n");
    printf("===================\n\n");

    HandleArgs(argc, arg);

    int FirstLocale = -1;
    uint32 build = 0;

    for (int i = 0; i < LANG_COUNT; i++)
    {
        char tmp1[512];
        sprintf(tmp1, "%s/Data/%s/locale-%s.MPQ", input_path, langs[i], langs[i]);
        if (FileExists(tmp1))
        {
            printf("Detected locale: %s\n", langs[i]);

            //Open MPQs
            LoadLocaleMPQFiles(i);

            if ((CONF_extract & EXTRACT_DBC) == 0)
            {
                FirstLocale = i;
                build = ReadBuild(FirstLocale);
                if (build==17520)
				{
					build = 18273;
				}
                printf("Detected client build: %u\n", build);
                break;
            }

            //Extract DBC files
            if (FirstLocale < 0)
            {
                FirstLocale = i;
                build = ReadBuild(FirstLocale);
                if (build==17520)
				{
					build = 18273;
				}
                printf("Detected client build: %u\n", build);
                ExtractDBCFiles(i, true);
            }
            else
                ExtractDBCFiles(i, false);

            //Close MPQs
            CloseArchives();
        }
    }

    if (FirstLocale < 0)
    {
        printf("No locales detected\n");
        return 0;
    }

    if (CONF_extract & EXTRACT_MAP)
    {
        printf("Using locale: %s\n", langs[FirstLocale]);

        // Open MPQs
        LoadBaseMPQFiles();
        LoadLocaleMPQFiles(FirstLocale);

        // Extract maps
        ExtractMapsFromMpq(build, FirstLocale);

        // Close MPQs
        CloseArchives();
    }

    return 0;
}
Пример #12
0
void D_DoomMain(void)
{
    GameMission_t gamemission;
    int p;

    I_AtExit(D_HexenQuitMessage, false);
    startepisode = 1;
    autostart = false;
    startskill = sk_medium;
    startmap = 1;
    gamemode = commercial;

    I_PrintBanner(PACKAGE_STRING);

    // Initialize subsystems

    ST_Message("V_Init: allocate screens.\n");
    V_Init();

    // Load defaults before initing other systems
    ST_Message("M_LoadDefaults: Load system defaults.\n");
    D_BindVariables();

#ifdef _WIN32

    //!
    // @platform windows
    // @vanilla
    //
    // Save configuration data and savegames in c:\hexndata,
    // allowing play from CD.
    //

    cdrom = M_ParmExists("-cdrom");
#endif

    if (cdrom)
    {
        M_SetConfigDir("c:\\hexndata\\");
    }
    else
    {
        M_SetConfigDir(NULL);
    }

    D_SetDefaultSavePath();
    M_SetConfigFilenames("hexen.cfg", PROGRAM_PREFIX "hexen.cfg");
    M_LoadDefaults();

    I_AtExit(M_SaveDefaults, false);


    // Now that the savedir is loaded from .CFG, make sure it exists
    CreateSavePath();

    ST_Message("Z_Init: Init zone memory allocation daemon.\n");
    Z_Init();

    // haleyjd: removed WATCOMC

    ST_Message("W_Init: Init WADfiles.\n");

    iwadfile = D_FindIWAD(IWAD_MASK_HEXEN, &gamemission);

    if (iwadfile == NULL)
    {
        I_Error("Game mode indeterminate. No IWAD was found. Try specifying\n"
                "one with the '-iwad' command line parameter.");
    }

    D_AddFile(iwadfile);
    W_CheckCorrectIWAD(hexen);
    D_IdentifyVersion();
    D_SetGameDescription();
    AdjustForMacIWAD();

    HandleArgs();

    I_PrintStartupBanner(gamedescription);

    ST_Message("MN_Init: Init menu system.\n");
    MN_Init();

    ST_Message("CT_Init: Init chat mode data.\n");
    CT_Init();

    InitMapMusicInfo();         // Init music fields in mapinfo

    ST_Message("S_InitScript\n");
    S_InitScript();

    ST_Message("SN_InitSequenceScript: Registering sound sequences.\n");
    SN_InitSequenceScript();
    ST_Message("I_Init: Setting up machine state.\n");
    I_CheckIsScreensaver();
    I_InitTimer();
    I_InitJoystick();
    I_InitSound(false);
    I_InitMusic();

#ifdef FEATURE_MULTIPLAYER
    ST_Message("NET_Init: Init networking subsystem.\n");
    NET_Init();
#endif
    D_ConnectNetGame();

    S_Init();
    S_Start();

    ST_Message("ST_Init: Init startup screen.\n");
    ST_Init();

    // Show version message now, so it's visible during R_Init()
    ST_Message("R_Init: Init Hexen refresh daemon");
    R_Init();
    ST_Message("\n");

    //if (M_CheckParm("-net"))
    //    ST_NetProgress();       // Console player found

    ST_Message("P_Init: Init Playloop state.\n");
    P_Init();

    // Check for command line warping. Follows P_Init() because the
    // MAPINFO.TXT script must be already processed.
    WarpCheck();

    ST_Message("D_CheckNetGame: Checking network game status.\n");
    D_CheckNetGame();

    ST_Message("SB_Init: Loading patches.\n");
    SB_Init();

    ST_Done();

    if (autostart)
    {
        ST_Message("Warp to Map %d (\"%s\":%d), Skill %d\n",
                   WarpMap, P_GetMapName(startmap), startmap, startskill + 1);
    }

    CheckRecordFrom();

    p = M_CheckParm("-record");
    if (p && p < myargc - 1)
    {
        G_RecordDemo(startskill, 1, startepisode, startmap, myargv[p + 1]);
        H2_GameLoop();          // Never returns
    }

    p = M_CheckParmWithArgs("-playdemo", 1);
    if (p)
    {
        singledemo = true;      // Quit after one demo
        G_DeferedPlayDemo(demolumpname);
        H2_GameLoop();          // Never returns
    }

    p = M_CheckParmWithArgs("-timedemo", 1);
    if (p)
    {
        G_TimeDemo(demolumpname);
        H2_GameLoop();          // Never returns
    }

    //!
    // @arg <s>
    // @vanilla
    //
    // Load the game in savegame slot s.
    //

    p = M_CheckParmWithArgs("-loadgame", 1);
    if (p)
    {
        G_LoadGame(atoi(myargv[p + 1]));
    }

    if (gameaction != ga_loadgame)
    {
        UpdateState |= I_FULLSCRN;
        BorderNeedRefresh = true;
        if (autostart || netgame)
        {
            G_StartNewInit();
            G_InitNew(startskill, startepisode, startmap);
        }
        else
        {
            H2_StartTitle();
        }
    }
    H2_GameLoop();              // Never returns
}
Пример #13
0
int main(int argc, char* argv[])
{
    _setmaxstdio(2048);
    uint32 threads = 4, extractFlags = 0;
    std::set<uint32> mapIds;

    if (!HandleArgs(argc, argv, threads, mapIds, Constants::Debug, extractFlags))
    {
        PrintUsage();
        return -1;
    }

    if (extractFlags == 0)
    {
        printf("You must provide valid extract flags.\n");
        PrintUsage();
        return -1;
    }

    Cache = new CacheClass();
    MPQHandler = new MPQManager();
    MPQHandler->Initialize();

    if (extractFlags & Constants::EXTRACT_FLAG_DBC)
        ExtractDBCs();

    if (extractFlags & Constants::EXTRACT_FLAG_MMAPS)
        ExtractMMaps(mapIds, threads);

    if (extractFlags & Constants::EXTRACT_FLAG_GOB_MODELS)
        ExtractGameobjectModels();

    if (extractFlags & Constants::EXTRACT_FLAG_TEST)
    {
        float start[] = { 16226.200195f, 16257.000000f, 13.202200f };
        float end[] = { 16245.725586f, 16382.465820f, 47.384956f };

        //
        float m_spos[3];
        m_spos[0] = -start[1];
        m_spos[1] = start[2];
        m_spos[2] = -start[0];

        //
        float m_epos[3];
        m_epos[0] = -end[1];
        m_epos[1] = end[2];
        m_epos[2] = -end[0];

        //
        dtQueryFilter m_filter;
        m_filter.setIncludeFlags(Constants::POLY_AREA_ROAD | Constants::POLY_AREA_TERRAIN);
        m_filter.setExcludeFlags(Constants::POLY_AREA_WATER);

        //
        float m_polyPickExt[3];
        m_polyPickExt[0] = 2.5f;
        m_polyPickExt[1] = 2.5f;
        m_polyPickExt[2] = 2.5f;

        //
        dtPolyRef m_startRef;
        dtPolyRef m_endRef;

        FILE* mmap = fopen("mmaps/001.mmap", "rb");
        dtNavMeshParams params;
        int count = fread(&params, sizeof(dtNavMeshParams), 1, mmap);
        fclose(mmap);
        if (count != 1)
        {
            printf("main: Error reading from .mmap\n");
            return 0;
        }

        dtNavMesh* navMesh = new dtNavMesh();
        dtNavMeshQuery* navMeshQuery = new dtNavMeshQuery();

        navMesh->init(&params);
        for (int i = 0; i <= 32; ++i)
        {
            for (int j = 0; j <= 32; ++j)
            {
                char buff[100];
                sprintf(buff, "mmaps/001%02i%02i.mmtile", i, j);
                LoadTile(navMesh, buff);
            }
        }
        
        navMeshQuery->init(navMesh, 2048);

        float nearestPt[3];

        navMeshQuery->findNearestPoly(m_spos, m_polyPickExt, &m_filter, &m_startRef, nearestPt);
        navMeshQuery->findNearestPoly(m_epos, m_polyPickExt, &m_filter, &m_endRef, nearestPt);

        if ( !m_startRef || !m_endRef )
        {
            std::cerr << "Could not find any nearby poly's (" << m_startRef << "," << m_endRef << ")" << std::endl;
            return 0;
        }

        int hops;
        dtPolyRef* hopBuffer = new dtPolyRef[8192];
        dtStatus status = navMeshQuery->findPath(m_startRef, m_endRef, m_spos, m_epos, &m_filter, hopBuffer, &hops, 8192);
        
        int resultHopCount;
        float* straightPath = new float[2048*3];
        unsigned char* pathFlags = new unsigned char[2048];
        dtPolyRef* pathRefs = new dtPolyRef[2048];

        status = navMeshQuery->findStraightPath(m_spos, m_epos, hopBuffer, hops, straightPath, pathFlags, pathRefs, &resultHopCount, 2048);
        std::vector<Vector3> FinalPath;
        FinalPath.reserve(resultHopCount);
        for (uint32 i = 0; i < resultHopCount; ++i)
        {
            Vector3 finalV = Utils::ToWoWCoords(Vector3(straightPath[i * 3 + 0], straightPath[i * 3 + 1], straightPath[i * 3 + 2]));
            FinalPath.push_back(finalV);
            printf("Point %f %f %f\n", finalV.x, finalV.y, finalV.z);
        }
    }

    return 0;
}
Пример #14
0
int main(int argc, char *argv[]) {
  CommandLine cl;
  MathRandom<MathMersenneTwister> rng;
  Error error;
  ya_check_debug();

  YA_MatD input_matrix;
  YA_MatD output_matrix;

  // Parse the command line
  HandleArgs(cl,argc,argv,&error);

  string outputfile="";
  if (cl.argsize(' ')>0) {
    load(cl.argstring(' ',0),input_matrix);
    if (cl.argsize(' ')>1)
      outputfile=cl.argstring(' ',1);
  } else
    read(cin,input_matrix);

  // Select rows
  if (cl['r']) {
    output_matrix=input_matrix(YA_RowI(cl.argstring('r',0)),":");
    input_matrix=output_matrix;
  }
  
  // Select cols
  if (cl['c']) {
    output_matrix=input_matrix(":",YA_RowI(cl.argstring('c',0)));
    input_matrix=output_matrix;
  }

  // Reorder rows using modulus
  else if (cl['z']) {
    ya_sizet mod=cl.argint('z',0);
    if (mod==0)
      error.generate_error(0,"vm_slice","Cannot specify a mod_num of 0.");
    if (input_matrix.rows()%mod!=0) {
      error.buffer() << "When using -z, the number of rows in the matrix "
                     << "must be evenly divisible by the mod_num.";
      error.addbuf(0,"vm_slice");
    }
    YA_VecI row_order(input_matrix.rows());
    ya_sizet offset=input_matrix.rows()/mod;
    for (ya_sizet i=0; i<input_matrix.rows(); i++) {
      div_t index=div(int(i),int(mod));
      row_order(i)=index.quot+index.rem*offset;
    }
    output_matrix=input_matrix(row_order,":");
  } else    
    output_matrix=input_matrix;

  ya_sizet file_format=YA_DEFAULT_IO;
  if (cl['t'])
    file_format=YA_PRETTY_IO;
  if (cl['b'])
    file_format=YA_BINARY_IO;

  // Random subset
  if (cl['s']) {
    double percent=cl.argdouble('s',0);
    if (percent>1)
      error.generate_error(0,"mat_convert",
        "Random percentage must be between 0 and 1");
    YA_RowI rand_perm(randperm(output_matrix.rows(),rng));
    output_matrix=copy(output_matrix(rand_perm,":"));
    ya_sizet cut_frac=ya_sizet(percent*output_matrix.rows());
    if (cl.argstring('s',1)!="NO_OUTPUT")
      save(cl.argstring('s',1),
           output_matrix(vmcount(cut_frac,":",output_matrix.rows()-1),":"),
           file_format);
    output_matrix=copy(output_matrix(vmcount(cut_frac),":"));
  }

  if (cl['q'])
    ip_transpose(output_matrix);

  if (outputfile=="")
    write(cout,output_matrix,file_format);
  else
    save(outputfile,output_matrix,file_format);
  return 0;
}