Implementation:Google deepmind Mujoco Filetype Detection
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Model_IO, File_Handling |
| Last Updated | 2026-02-15 06:00 GMT |
Overview
Concrete pattern for detecting MuJoCo model file formats from the compile sample utility.
Description
The filetype function in MuJoCo's compile sample extracts the file extension, converts it to lowercase, and maps it to an integer type code. It handles the special case of no extension (type NONE) and unknown extensions (type UNKNOWN).
Usage
Use when implementing model conversion tools that need to distinguish between XML, MJB, and TXT file formats.
Code Reference
Source Location
- Repository: mujoco
- File: sample/compile.cc
- Lines: 72-103
Signature
// Pattern: local helper function
static int filetype(const char* filename);
// Returns: typeXML (1), typeMJB (2), typeTXT (3), typeUNKNOWN (0), typeNONE (4)
Import
// Not a library function - pattern from sample/compile.cc
#include <cctype> // tolower
#include <cstring> // strlen, strcpy
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| filename | const char* | Yes | File path to analyze |
Outputs
| Name | Type | Description |
|---|---|---|
| return | int | Type code: typeXML=1, typeMJB=2, typeTXT=3, typeUNKNOWN=0, typeNONE=4 |
Usage Examples
// Determine input and output formats
int input_type = filetype(argv[1]);
int output_type = argc > 2 ? filetype(argv[2]) : typeNONE;
if (input_type == typeXML) {
m = mj_loadXML(argv[1], NULL, error, 1000);
} else if (input_type == typeMJB) {
m = mj_loadModel(argv[1], NULL);
}
Related Pages
Implements Principle
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment