/*------------------------------------------------------------------*/ int nx_initgroupdir(void *handle){ int status; NXhandle hfil; hfil = (NXhandle)handle; status = NXinitgroupdir(hfil); if(status == NX_OK){ return 1; } else { return 0; } }
/* Outputs the contents of a NeXus group */ int NXBdir(NXhandle fileId) { int status, dataType, dataRank, dataDimensions[NX_MAXRANK], length; NXname name, nxclass, nxurl; if (NXinitgroupdir(fileId) != NX_OK) return NX_ERROR; do { status = NXgetnextentry(fileId, name, nxclass, &dataType); if (status == NX_ERROR) break; if (status == NX_OK) { if (strncmp(nxclass, "CDF", 3) == 0) { ; } else if (strcmp(nxclass, "SDS") == 0) { printf(" NX Data : %s", name); if (NXopendata(fileId, name) != NX_OK) return NX_ERROR; if (NXgetinfo (fileId, &dataRank, dataDimensions, &dataType) != NX_OK) return NX_ERROR; if (NXclosedata(fileId) != NX_OK) return NX_ERROR; PrintDimensions(dataRank, dataDimensions); printf(" "); PrintType(dataType); printf("\n"); } else { length = sizeof(nxurl); if (NXisexternalgroup(fileId, name, nxclass, nxurl, length) == NX_OK) { printf(" NX external Group: %s (%s), linked to: %s \n", name, nxclass, nxurl); } else { printf(" NX Group : %s (%s)\n", name, nxclass); if ((status = NXopengroup(fileId, name, nxclass)) != NX_OK) { return status; } PrintGroupAttributes(fileId, name); if ((status = NXclosegroup(fileId)) != NX_OK) { return status; } } } } } while (status == NX_OK); return status; }
/* Searches group for the requested data item */ int FindData(NXhandle fileId, char *dataName) { int status, dataType; NXname name, nxclass; NXinitgroupdir(fileId); do { status = NXgetnextentry(fileId, name, nxclass, &dataType); if (status == NX_ERROR) return NX_ERROR; if (status == NX_OK) { if (StrEq(dataName, name)) { if (!strncmp(nxclass, "SDS", 3)) { /* Data has class "SDS" */ return NX_OK; } else { printf("NX_ERROR: %s is not data\n", dataName); return NX_ERROR; } } } } while (status != NX_EOD); printf("NX_ERROR: %s does not exist\n", dataName); return NX_EOD; }
static char *field_generator(const char *text, int state) { struct name_item *item, *t_item; static struct name_item *names = NULL, *last_item = NULL; char *res; int status, dataType; NXname name, nxclass; if (!state) { item = names; while (item != NULL) { if (item->name != NULL) { free(item->name); item->name = NULL; } t_item = item; item = item->next; t_item->next = NULL; free(t_item); } last_item = names = NULL; char matchtext[256], absdir[256], tmppath[256], prefix[256]; prefix[0] = '\0'; char *ptr = rindex(text+1, '/'); if (ptr != NULL) { strncpy(prefix, text, ptr-text+1); prefix[ptr-text+1] = '\0'; } parsepath(text, absdir, matchtext); /* check if we've got a dir already */ NXMDisableErrorReporting(); strcpy(tmppath, absdir); strcat(tmppath, "/"); strcat(tmppath, matchtext); status = NXopengrouppath(the_fileId, tmppath); if (status == NX_OK) { strcpy(absdir, tmppath); strcpy(matchtext, ""); if (strlen(text) > 0 && text[strlen(text)-1] != '/') { strcpy(prefix, text); strcat(prefix, "/"); } } else { /* if not go into the dir part */ status = NXopengrouppath(the_fileId, absdir); } NXMEnableErrorReporting(); if (status == NX_ERROR) return NULL; if (NXinitgroupdir(the_fileId) != NX_OK) return NULL; do { status = NXgetnextentry(the_fileId, name, nxclass, &dataType); if (status == NX_ERROR) break; if (status == NX_OK) { if (strncmp(nxclass, "CDF", 3) == 0) { ; } else if (strncmp(name, matchtext, strlen(matchtext)) == 0) { item = (struct name_item *) malloc(sizeof(struct name_item)); item->name = (char *)calloc(256, 1); strcpy(item->name, prefix); strcat(item->name, name); if (strcmp(nxclass, "SDS") != 0) { strcat(item->name, "/"); } item->next = NULL; if (last_item == NULL) { names = item; } else { last_item->next = item; } last_item = item; } } } while (status == NX_OK); NXopengrouppath(the_fileId, path); last_item = names; } if (last_item != NULL) { res = strdup(last_item->name); last_item = last_item->next; } else { res = NULL; } return res; }