Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
443 changes: 395 additions & 48 deletions docs/next-js/components/loading/LocalNetCDFMeta.tsx

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/next-js/components/loading/MetaNetCDFButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function ObjectViewer({
];

return (
<div className="grid grid-cols-1 md:grid-cols-[auto_1fr] gap-x-4 gap-y-2 text-sm">
<div className="grid grid-cols-1 md:grid-cols-[auto_1fr] gap-x-4 gap-y-2 text-sm w-full">
{orderedKeys.map((key) => {
const value = data[key];
const isDefault = defaultAttributes.includes(key);
Expand All @@ -46,12 +46,12 @@ function ObjectViewer({
<div
className={`${
isDefault ? 'font-semibold' : 'text-foreground opacity-95'
}`}
} break-words`}
>
{key}:
</div>
<div
className="whitespace-pre-wrap break-words pl-4 md:pl-0 text-muted-foreground"
className="whitespace-pre-wrap break-all pl-4 md:pl-0 text-muted-foreground min-w-0"
style={{ overflowWrap: 'anywhere' }}
>
{typeof value === 'object'
Expand Down Expand Up @@ -101,7 +101,7 @@ export function MetaNetCDFButtons({
Variables
</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-[600px] max-h-[80vh] overflow-y-auto">
<DialogContent className="w-[95vw] max-w-[800px] max-h-[80vh] overflow-y-auto">
<DialogHeader>
<DialogTitle>Variables</DialogTitle>
<DialogDescription>
Expand All @@ -121,7 +121,7 @@ export function MetaNetCDFButtons({
Global Attributes
</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-[600px] max-h-[80vh] overflow-y-auto">
<DialogContent className="w-[95vw] max-w-[800px] max-h-[80vh] overflow-y-auto">
<DialogHeader>
<DialogTitle>Global Attributes</DialogTitle>
<DialogDescription>
Expand All @@ -141,7 +141,7 @@ export function MetaNetCDFButtons({
Full Metadata
</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-[600px] max-h-[80vh] overflow-y-auto">
<DialogContent className="w-[95vw] max-w-[800px] max-h-[80vh] overflow-y-auto">
<DialogHeader>
<DialogTitle>Full Metadata</DialogTitle>
<DialogDescription>
Expand Down
36 changes: 36 additions & 0 deletions scripts/build-wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ if [ ! -f "$INSTALL_DIR/lib/libhdf5.a" ]; then
-DHDF5_ENABLE_TESTS=OFF \
-DCMAKE_C_BYTE_ORDER=LITTLE_ENDIAN \
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant. IS the default setting

-DHDF5_DISABLE_COMPILER_WARNINGS=ON \
-DHDF5_ENABLE_Z_LIB_SUPPORT=ON \
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant

-DHDF5_ENABLE_ZLIB_SUPPORT=ON \
-DALLOW_UNSUPPORTED=ON \
-DH5_ZLIB_HEADER="zlib.h" \
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't exist

-DZLIB_ROOT="$INSTALL_DIR" \
-DZLIB_INCLUDE_DIR="$INSTALL_DIR/include" \
-DZLIB_LIBRARY="$INSTALL_DIR/lib/libz.a"
Expand Down Expand Up @@ -356,6 +360,8 @@ if [ ! -f "$INSTALL_DIR/lib/libnetcdf.a" ]; then
-DBUILD_UTILITIES=OFF \
-DBUILD_TESTING=OFF \
-DENABLE_TESTS=OFF \
-DENABLE_FILTER_DEFLATE=ON \
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't exist

-DENABLE_ZLIB=ON \
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant

-DCMAKE_C_BYTE_ORDER=LITTLE_ENDIAN \
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant. IS the default setting

-DWORDS_BIGENDIAN=OFF \
-DHDF5_USE_STATIC_LIBRARIES=ON \
Expand Down Expand Up @@ -596,6 +602,34 @@ int nc_def_var_endian_wrapper(int ncid, int varid, int endian) {
return nc_def_var_endian(ncid, varid, endian);
}

// =========================
// Groups
// =========================
EMSCRIPTEN_KEEPALIVE
int nc_inq_grps_wrapper(int ncid, int* numgrps, int* grpids) {
return nc_inq_grps(ncid, numgrps, grpids);
}

EMSCRIPTEN_KEEPALIVE
int nc_inq_grp_ncid_wrapper(int ncid, const char* grp_name, int* grp_ncid) {
return nc_inq_grp_ncid(ncid, grp_name, grp_ncid);
}

EMSCRIPTEN_KEEPALIVE
int nc_inq_grpname_wrapper(int ncid, char* name) {
return nc_inq_grpname(ncid, name);
}

EMSCRIPTEN_KEEPALIVE
int nc_inq_grp_parent_wrapper(int ncid, int* parent_ncid) {
return nc_inq_grp_parent(ncid, parent_ncid);
}

EMSCRIPTEN_KEEPALIVE
int nc_inq_grp_full_ncid_wrapper(int ncid, const char* full_name, int* grp_ncid) {
return nc_inq_grp_full_ncid(ncid, full_name, grp_ncid);
}

// =========================
// Attributes
// =========================
Expand Down Expand Up @@ -976,6 +1010,7 @@ EOF
log "Creating C wrapper for NetCDF functions..."

log "Compiling WASM module with emcc..."

check_command emcc netcdf_wrapper.c \
-I"$INSTALL_DIR/include" \
-L"$INSTALL_DIR/lib" \
Expand All @@ -991,6 +1026,7 @@ check_command emcc netcdf_wrapper.c \
-s EXPORTED_FUNCTIONS='["_malloc","_free"]' \
-s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_MEMORY=16777216 \
-s ERROR_ON_UNDEFINED_SYMBOLS=0 \
--pre-js "$PROJECT_ROOT/bindings/pre.js" \
--post-js "$PROJECT_ROOT/bindings/post.js" \
-O2 \
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export const NC_CONSTANTS = {
// Error codes
NC_NOERR: 0,
NC_ERANGE: -60,

// File modes
NC_NOWRITE: 0,
Expand Down
61 changes: 57 additions & 4 deletions src/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export class Group {
constructor(
protected netcdf: NetCDF4,
public readonly name: string,
protected groupId: number
protected groupId: number,
protected parent?: Group
) {}

// Attribute methods
Expand Down Expand Up @@ -150,7 +151,7 @@ export class Group {

createGroup(name: string): Group {
// For simplicity, groups use the same ncid for now
const group = new Group(this.netcdf, name, this.groupId);
const group = new Group(this.netcdf, name, this.groupId, this);
this.groups[name] = group;
return group;
}
Expand All @@ -162,8 +163,60 @@ export class Group {

// Get group path (Python-like)
get path(): string {
if (this.name === '') return '/';
return `/${this.name}`;
if (!this.parent) return '/';
const parentPath = this.parent.path;
return parentPath === '/' ? `/${this.name}` : `${parentPath}/${this.name}`;
}

async load(): Promise<void> {
// 1. Dimensions
const dims = await this.netcdf.getDims(this.path);
for (const key in this.dimensions) delete this.dimensions[key];

for (const [name, d] of Object.entries(dims)) {
this.dimensions[name] = new Dimension(name, d.size, false);
}

// 2. Variables
const vars = await this.netcdf.getVariables(this.path);
for (const key in this.variables) delete this.variables[key];

for (const [name, v] of Object.entries(vars)) {
const info = await this.netcdf.getVariableInfo(v.id, this.path);
const dimNames = info.dims.map((d: any) => d.name);

const variable = new Variable(
this.netcdf,
name,
info.dtype,
dimNames,
v.id,
this.groupId
);

if (info.attributes) {
for (const [k, val] of Object.entries(info.attributes)) {
variable.setAttr(k, val);
}
}
this.variables[name] = variable;
}

// 3. Subgroups
const groups = await this.netcdf.getGroups(this.groupId);
for (const key in this.groups) delete this.groups[key];

for (const [name, grpid] of Object.entries(groups)) {
const group = new Group(this.netcdf, name, grpid, this);
await group.load();
this.groups[name] = group;
}

// 4. Attributes
const attrs = await this.netcdf.getGlobalAttributes(this.path);
for (const [k, v] of Object.entries(attrs)) {
this.setAttr(k, v);
}
}

toString(): string {
Expand Down
Loading