/* * The Npic library * * Copyright (C) 2003 Edouard Thiel * * This library is free software under the terms of the * GNU Lesser General Public License (LGPL) version 2.1. */ /* DO NOT EDIT !!! Generated by npic-templa from "files_nmask.ct" */ /* * files_nmask.c - 18/12/2008 * * Read or write masks for distance transforms or medial axis */ #include #define MAXBUF 65536 /*--------------------- P U B L I C - I N T E R F A C E ----------------------*/ /* * Write mask in file according to its extension. * Do nothing if mask is not ok. * * Return NPIC_SUCCESS, else error code. Verbose. */ int NpicWriteMask (Npic_mask *m, const char *filename) { Npic_file_hints h; int k, res; if (NpicMaskIsOK (m, __func__) != NPIC_SUCCESS) return NPIC_ERR_NOT_OK; /* After this call, memory must be freed with NpicFileFreeHints() */ k = NpicFileParseHints (filename, &h); if (k != NPIC_SUCCESS) NpicError (__func__, k, ": file \"%s\".\n", filename); if (strcmp (h.extension, ".nmask") == 0) res = NpicWriteNMASK (m, h.realname, h.comp); else res = NpicError (__func__, NPIC_ERR_BAD_EXT, ": file \"%s\".\n Known extensions are: " NPIC_KNOWN_MASK_EXT, h.realname); /* Free memory */ NpicFileFreeHints (&h); return res; } /* * Read mask from file according to its extension and create appropriate mask. * * Return mask on success, else return NULL. Verbose. */ Npic_mask *NpicReadMask (const char *filename) { Npic_mask *nm = NULL; Npic_file_hints h; int k; /* After this call, memory must be freed with NpicFileFreeHints() */ k = NpicFileParseHints (filename, &h); if (k != NPIC_SUCCESS) NpicError (__func__, k, ": file \"%s\".\n", filename); if (strcmp (h.extension, ".nmask") == 0) nm = NpicReadNMASK (h.realname, h.comp); else NpicError (__func__, NPIC_ERR_BAD_EXT, ": file \"%s\".\n Known extensions are: " NPIC_KNOWN_MASK_EXT, h.realname); /* Free memory */ NpicFileFreeHints (&h); return nm; } /* * Print mask informations according to its extension. * * Return NPIC_SUCCESS, else error code. Verbose. */ int NpicInfoMask (const char *filename) { Npic_file_hints h; int k, res; /* After this call, memory must be freed with NpicFileFreeHints() */ k = NpicFileParseHints (filename, &h); if (k != NPIC_SUCCESS) NpicError (__func__, k, ": file \"%s\".\n", filename); if (strcmp (h.extension, ".nmask") == 0) res = NpicInfoNMASK (h.realname, h.comp); else res = NPIC_ERR_BAD_EXT; /* Free memory */ NpicFileFreeHints (&h); return res; } /* * Read mask from file according to its extension, check in its properties if it * is a distance mask, create appropriate mask and add G-symmetries if needed. * * Return mask on success, else return NULL. Verbose. */ Npic_mask *NpicReadDistanceMask (const char *filename) { Npic_mask *m1; const char *nat, *addsym; m1 = NpicReadMask (filename); if (m1 == NULL) return NULL; /* Nature of mask: Distance, MedialAxis, Convolution, Unknown */ nat = NpicMaskGetPropD (m1, "Nature", "Unknown"); if (strcmp (nat, "Distance") != 0) { NpicError (__func__, NPIC_ERROR, ": file \"%s\".\n Bad property value in \"Nature: %s\", expect \"Distance\"\n", filename, nat); NpicDestroyMask (m1); return NULL; } /* Add symmetries: GSymToHalfMask, None */ addsym = NpicMaskGetPropD (m1, "AddSym", "None"); if (strcmp (addsym, "GSymToHalfMask") == 0) { Npic_mask *m2 = NpicCompHalfMask (m1); NpicMaskCopyProps (m2, m1); NpicMaskAddProp (m2, "AddSym", "None"); NpicDestroyMask (m1); m1 = m2; } else if (strcmp (addsym, "None") != 0) { NpicError (__func__, NPIC_ERROR, ": file \"%s\".\n Bad property value in \"AddSym: %s\", " "expect \"GSymToHalfMask\" or \"None\"\n", filename, addsym); NpicDestroyMask (m1); return NULL; } return m1; } /* * Read mask from file according to its extension, check in its properties if it * is a medial axis mask (a.k.a MLut or neighbourhood test), create appropriate * mask. * * The "RVerified" text property stores the largest verified radius. If absent, * or less than the largest radius, the latter is stored. * * Return mask on success, else return NULL. Verbose. */ Npic_mask *NpicReadMedialAxisMask (const char *filename) { Npic_mask *m1; const char *nat, *rad; char s[200]; int i; m1 = NpicReadMask (filename); if (m1 == NULL) return NULL; /* Nature of mask: Distance, MedialAxis, Convolution, Unknown */ nat = NpicMaskGetPropD (m1, "Nature", "Unknown"); if (strcmp (nat, "MedialAxis") != 0) { NpicError (__func__, NPIC_ERROR, ": file \"%s\".\n Bad property value in \"Nature: %s\", expect \"MedialAxis\"\n", filename, nat); NpicDestroyMask (m1); return NULL; } /* Check and update the RVerified property */ rad = NpicMaskGetPropD (m1, "RVerified", "0"); switch (m1->type) { case NPIC_MASK_2L : { Npic_mask_2l *mq = NpicCastMask (m1); Npic_l a = atoi(rad); for (i = 0; i < mq->nb; i++) if (mq->v[i].h > a) a = mq->v[i].h; sprintf (s, "%" NPIC_PL, a); } break; case NPIC_MASK_3L : { Npic_mask_3l *mq = NpicCastMask (m1); Npic_l a = atoi(rad); for (i = 0; i < mq->nb; i++) if (mq->v[i].h > a) a = mq->v[i].h; sprintf (s, "%" NPIC_PL, a); } break; case NPIC_MASK_4L : { Npic_mask_4l *mq = NpicCastMask (m1); Npic_l a = atoi(rad); for (i = 0; i < mq->nb; i++) if (mq->v[i].h > a) a = mq->v[i].h; sprintf (s, "%" NPIC_PL, a); } break; case NPIC_MASK_5L : { Npic_mask_5l *mq = NpicCastMask (m1); Npic_l a = atoi(rad); for (i = 0; i < mq->nb; i++) if (mq->v[i].h > a) a = mq->v[i].h; sprintf (s, "%" NPIC_PL, a); } break; case NPIC_MASK_6L : { Npic_mask_6l *mq = NpicCastMask (m1); Npic_l a = atoi(rad); for (i = 0; i < mq->nb; i++) if (mq->v[i].h > a) a = mq->v[i].h; sprintf (s, "%" NPIC_PL, a); } break; case NPIC_MASK_2D : { Npic_mask_2d *mq = NpicCastMask (m1); Npic_d a = atof(rad); for (i = 0; i < mq->nb; i++) if (mq->v[i].h > a) a = mq->v[i].h; sprintf (s, "%lf", a); } break; case NPIC_MASK_3D : { Npic_mask_3d *mq = NpicCastMask (m1); Npic_d a = atof(rad); for (i = 0; i < mq->nb; i++) if (mq->v[i].h > a) a = mq->v[i].h; sprintf (s, "%lf", a); } break; case NPIC_MASK_4D : { Npic_mask_4d *mq = NpicCastMask (m1); Npic_d a = atof(rad); for (i = 0; i < mq->nb; i++) if (mq->v[i].h > a) a = mq->v[i].h; sprintf (s, "%lf", a); } break; case NPIC_MASK_5D : { Npic_mask_5d *mq = NpicCastMask (m1); Npic_d a = atof(rad); for (i = 0; i < mq->nb; i++) if (mq->v[i].h > a) a = mq->v[i].h; sprintf (s, "%lf", a); } break; case NPIC_MASK_6D : { Npic_mask_6d *mq = NpicCastMask (m1); Npic_d a = atof(rad); for (i = 0; i < mq->nb; i++) if (mq->v[i].h > a) a = mq->v[i].h; sprintf (s, "%lf", a); } break; default: sprintf (s, "0"); } NpicMaskAddProp (m1, "RVerified", s); return m1; } /*----------------------------------------------------------------------------*/ /* * Save Npic_mask mask in a file in NMASK format. * If comp != NPIC_COMPRESS_NONE, the file is directly compressed using * the appropriate command (see files_hints.h for available formats). * Do nothing if mask is not ok. * * Return NPIC_SUCCESS, else error code. Verbose. * * USAGE : * Npic_mask *m; int err; * ... * err = NpicWriteNMASK (&m, "example.nmask", NPIC_COMPRESS_NONE); * or err = NpicWriteNMASK (&m, "example.nmask.gz", NPIC_COMPRESS_GZ); * if (err < 0) return err; * .... * NpicDestroyMask (m); */ int NpicWriteNMASK (Npic_mask *m, const char *filename, Npic_file_compress comp) { Npic_file_gz fgz; if (NpicMaskIsOK (m, __func__) != NPIC_SUCCESS) return NPIC_ERR_NOT_OK; NpicWriteGZ_Open (&fgz, filename, __func__, 0, comp); if (fgz.res == NPIC_SUCCESS) fgz.res = NpicNMASKWriteFile (m, fgz.f2, filename, __func__); NpicWriteGZ_Close (&fgz); return fgz.res; } /* * Read mask file in NMASK format and create Npic_mask mask. * If comp != NPIC_COMPRESS_NONE, the file is uncompressed in memory using * the appropriate command (but stay compressed on disk). * Return mask on success, else return NULL. Verbose. * * USAGE : * Npic_mask *m; * m = NpicReadNMASK ("example.nmask" , NPIC_COMPRESS_NONE); * or m = NpicReadNMASK ("example.nmask.gz", NPIC_COMPRESS_GZ); * if (m == NULL) return; * .... * NpicDestroyMask (m); */ Npic_mask *NpicReadNMASK (const char *filename, Npic_file_compress comp) { Npic_mask *m = NULL; Npic_file_gz fgz; NpicReadGZ_Open (&fgz, filename, __func__, 0, comp); if (fgz.res == NPIC_SUCCESS) m = NpicNMASKReadFile (fgz.f2, filename, __func__); NpicReadGZ_Close (&fgz); return m; } /* * Print infos of a file in NMASK format * * Return NPIC_SUCCESS, else error code. Verbose. */ int NpicInfoNMASK (const char *filename, Npic_file_compress comp) { Npic_file_gz fgz; Npic_nmask_info info; NpicReadGZ_Open (&fgz, filename, __func__, 0, comp); if (fgz.res == NPIC_SUCCESS) { fgz.res = NPicNMASKReadInfo (fgz.f2, &info); if (fgz.res == NPIC_SUCCESS) fgz.res = NpicNMASKPrintInfo (filename, &info); NpicError (__func__, fgz.res, ": file \"%s\"", filename); NpicFreeProps (&info.props); } NpicReadGZ_Close (&fgz); return fgz.res; } /*-------------------- P R I V A T E - F U N C T I O N S ---------------------*/ /* * Save Npic_mask mask in a file in NMASK format. * The file is already fopen. * Return NPIC_SUCCESS, else error code. Verbose. */ int NpicNMASKWriteFile (Npic_mask *m, FILE *f1, const char *filename, const char *funcname) { time_t tm; int i; if (NpicMaskIsOK (m, funcname) != NPIC_SUCCESS) return NPIC_ERR_NOT_OK; fprintf (f1, "NMASK-11\n"); fprintf (f1, "# Mask file generated by libNpic - "); time(&tm); fprintf (f1, "%s", ctime(&tm)); fprintf (f1, "TYPE "); switch (m->type) { case NPIC_MASK_2L : fprintf (f1, "NPIC_MASK_2L\n"); break; case NPIC_MASK_3L : fprintf (f1, "NPIC_MASK_3L\n"); break; case NPIC_MASK_4L : fprintf (f1, "NPIC_MASK_4L\n"); break; case NPIC_MASK_5L : fprintf (f1, "NPIC_MASK_5L\n"); break; case NPIC_MASK_6L : fprintf (f1, "NPIC_MASK_6L\n"); break; case NPIC_MASK_2D : fprintf (f1, "NPIC_MASK_2D\n"); break; case NPIC_MASK_3D : fprintf (f1, "NPIC_MASK_3D\n"); break; case NPIC_MASK_4D : fprintf (f1, "NPIC_MASK_4D\n"); break; case NPIC_MASK_5D : fprintf (f1, "NPIC_MASK_5D\n"); break; case NPIC_MASK_6D : fprintf (f1, "NPIC_MASK_6D\n"); break; default : fprintf (f1, "ERROR\n"); break; } /* Write properties */ for (i = 0; i < m->gen.props.nb; i++) fprintf (f1, "PROP %s: %s\n", m->gen.props.list[i].key, m->gen.props.list[i].val); switch (m->type) { case NPIC_MASK_2L: fprintf (f1, "# y x h\n"); break; case NPIC_MASK_3L: fprintf (f1, "# z y x h\n"); break; case NPIC_MASK_4L: fprintf (f1, "# t z y x h\n"); break; case NPIC_MASK_5L: fprintf (f1, "# s t z y x h\n"); break; case NPIC_MASK_6L: fprintf (f1, "# r s t z y x h\n"); break; case NPIC_MASK_2D: fprintf (f1, "# y x h\n"); break; case NPIC_MASK_3D: fprintf (f1, "# z y x h\n"); break; case NPIC_MASK_4D: fprintf (f1, "# t z y x h\n"); break; case NPIC_MASK_5D: fprintf (f1, "# s t z y x h\n"); break; case NPIC_MASK_6D: fprintf (f1, "# r s t z y x h\n"); break; } fprintf (f1, "DATA\n"); switch (m->type) { case NPIC_MASK_2L: { Npic_mask_2l *dm = NpicCastMask (m); for (i = 0; i < dm->nb; i++) fprintf (f1, "%4d %4d %6" NPIC_PL "\n", dm->v[i].y, dm->v[i].x, dm->v[i].h); } break; case NPIC_MASK_3L: { Npic_mask_3l *dm = NpicCastMask (m); for (i = 0; i < dm->nb; i++) fprintf (f1, "%4d %4d %4d %6" NPIC_PL "\n", dm->v[i].z, dm->v[i].y, dm->v[i].x, dm->v[i].h); } break; case NPIC_MASK_4L: { Npic_mask_4l *dm = NpicCastMask (m); for (i = 0; i < dm->nb; i++) fprintf (f1, "%4d %4d %4d %4d %6" NPIC_PL "\n", dm->v[i].t, dm->v[i].z, dm->v[i].y, dm->v[i].x, dm->v[i].h); } break; case NPIC_MASK_5L: { Npic_mask_5l *dm = NpicCastMask (m); for (i = 0; i < dm->nb; i++) fprintf (f1, "%4d %4d %4d %4d %4d %6" NPIC_PL "\n", dm->v[i].s, dm->v[i].t, dm->v[i].z, dm->v[i].y, dm->v[i].x, dm->v[i].h); } break; case NPIC_MASK_6L: { Npic_mask_6l *dm = NpicCastMask (m); for (i = 0; i < dm->nb; i++) fprintf (f1, "%4d %4d %4d %4d %4d %4d %6" NPIC_PL "\n", dm->v[i].r, dm->v[i].s, dm->v[i].t, dm->v[i].z, dm->v[i].y, dm->v[i].x, dm->v[i].h); } break; case NPIC_MASK_2D: { Npic_mask_2d *dm = NpicCastMask (m); for (i = 0; i < dm->nb; i++) fprintf (f1, "%4d %4d %18.10lf\n", dm->v[i].y, dm->v[i].x, dm->v[i].h); } break; case NPIC_MASK_3D: { Npic_mask_3d *dm = NpicCastMask (m); for (i = 0; i < dm->nb; i++) fprintf (f1, "%4d %4d %4d %18.10lf\n", dm->v[i].z, dm->v[i].y, dm->v[i].x, dm->v[i].h); } break; case NPIC_MASK_4D: { Npic_mask_4d *dm = NpicCastMask (m); for (i = 0; i < dm->nb; i++) fprintf (f1, "%4d %4d %4d %4d %18.10lf\n", dm->v[i].t, dm->v[i].z, dm->v[i].y, dm->v[i].x, dm->v[i].h); } break; case NPIC_MASK_5D: { Npic_mask_5d *dm = NpicCastMask (m); for (i = 0; i < dm->nb; i++) fprintf (f1, "%4d %4d %4d %4d %4d %18.10lf\n", dm->v[i].s, dm->v[i].t, dm->v[i].z, dm->v[i].y, dm->v[i].x, dm->v[i].h); } break; case NPIC_MASK_6D: { Npic_mask_6d *dm = NpicCastMask (m); for (i = 0; i < dm->nb; i++) fprintf (f1, "%4d %4d %4d %4d %4d %4d %18.10lf\n", dm->v[i].r, dm->v[i].s, dm->v[i].t, dm->v[i].z, dm->v[i].y, dm->v[i].x, dm->v[i].h); } break; default: NpicError (__func__, NPIC_ERR_UNEX_TYPE, ""); } return NPIC_SUCCESS; } /* * Read mask file in NMASK format and create Npic_mask mask. * The file is already fopen. * Return mask on success, else return NULL. Verbose. */ Npic_mask *NpicNMASKReadFile (FILE *f1, const char *filename, const char *funcname) { Npic_nmask_info info; Npic_mask *m; int k; k = NPicNMASKReadInfo (f1, &info); if (k != NPIC_SUCCESS) { NpicError (funcname, k, ": file \"%s\"", filename); return NULL; } /* Allocate Mask */ m = NpicCreateMask (info.type); if (m == NULL) { NpicFreeProps (&info.props); NpicError (funcname, NPIC_ERROR, ": file \"%s\"", filename); return NULL; } /* We put info.props in m->gen.props (which was empty before); the properties will be freed on m destruction. */ memmove (&m->gen.props, &info.props, sizeof(Npic_props)); k = NpicNMASKReadDatas (m, f1); if (k != NPIC_SUCCESS) { NpicDestroyMask (m); m = NULL; NpicError (funcname, k, ": file \"%s\"", filename); } return m; } /* * Read infos (i.e text props) in a NMASK file, * then store results in struct info. * The file is already fopen. * Return NPIC_SUCCESS, else error code. Silent. * On success, properties have to be freed with NpicPropsFree. */ int NPicNMASKReadInfo (FILE *f1, Npic_nmask_info *info) { char buf[MAXBUF], tok[32]; if (f1 == NULL) return NPIC_ERR_BAD_FD; if (info == NULL) return NPIC_ERR_NULL_PTR; /* Init */ info->version = -1; info->type = info->dim = -1; NpicInitProps (&info->props); /* Read MagicValue */ if (fscanf (f1, "%6s", buf) <= 0) return NPIC_ERR_HEADER; if (strncmp (buf, "NMASK-", 6) != 0) return NPIC_ERR_MAGIC; /* Read version on same line */ if (fscanf (f1, "%d", &info->version) <= 0) return NPIC_ERR_HEADER; if (info->version != 11) return NPIC_ERR_VERSION; /* * Read tokens and values in header */ while (1) { /* Ignore a comment; see NpicPNMReadInt() */ if (fscanf (f1, " %1[#]%*[^\n]\n", tok) > 0) continue; /* Read token */ if (fscanf (f1, "%30s", tok) == 1) { if (strcmp (tok, "TYPE") == 0) { if (fscanf (f1, "%30s", buf) == 1) { if (strcmp (buf, "NPIC_MASK_2L") == 0) { info->type = NPIC_MASK_2L; info->dim = 2; } else if (strcmp (buf, "NPIC_MASK_3L") == 0) { info->type = NPIC_MASK_3L; info->dim = 3; } else if (strcmp (buf, "NPIC_MASK_4L") == 0) { info->type = NPIC_MASK_4L; info->dim = 4; } else if (strcmp (buf, "NPIC_MASK_5L") == 0) { info->type = NPIC_MASK_5L; info->dim = 5; } else if (strcmp (buf, "NPIC_MASK_6L") == 0) { info->type = NPIC_MASK_6L; info->dim = 6; } else if (strcmp (buf, "NPIC_MASK_2D") == 0) { info->type = NPIC_MASK_2D; info->dim = 2; } else if (strcmp (buf, "NPIC_MASK_3D") == 0) { info->type = NPIC_MASK_3D; info->dim = 3; } else if (strcmp (buf, "NPIC_MASK_4D") == 0) { info->type = NPIC_MASK_4D; info->dim = 4; } else if (strcmp (buf, "NPIC_MASK_5D") == 0) { info->type = NPIC_MASK_5D; info->dim = 5; } else if (strcmp (buf, "NPIC_MASK_6D") == 0) { info->type = NPIC_MASK_6D; info->dim = 6; } if (info->type != -1) continue; } } else if (strcmp (tok, "PROP") == 0) { /* The line we expect after "PROP" is " key: val\n". */ /* Jump one space */ if (fscanf (f1, "%*c") == EOF) ; /* Read property and store it */ if (NpicPropRead (&info->props, f1, NULL) == NPIC_SUCCESS) continue; } else if (strcmp (tok, "DATA") == 0) { /* After the header there is exactly one char to read before binary datas. The '*' in fscanf suppresses assignment */ if (fscanf (f1, "%*c") == EOF) ; break; /* stop loop */ } } /* Bad header */ NpicFreeProps (&info->props); return NPIC_ERR_HEADER; } return NPIC_SUCCESS; } /* * Read datas from f1. * * Return NPIC_SUCCESS, else error code. Silent. */ int NpicNMASKReadDatas (Npic_mask *m, FILE *f1) { if (m == NULL) return NPIC_ERR_NULL_PTR; if (f1 == NULL) return NPIC_ERR_BAD_FD; switch (m->type) { case NPIC_MASK_2L : { int k, y, x; Npic_l h; while (! feof (f1)) { k = fscanf (f1, "%d %d %" NPIC_PL "\n", &y, &x, &h); if (k == EOF) break; /* not an error */ if (k != 2+1) return NPIC_ERR_READ; NpicMaskInsert_2l (m, y, x, h); } } break; case NPIC_MASK_3L : { int k, z, y, x; Npic_l h; while (! feof (f1)) { k = fscanf (f1, "%d %d %d %" NPIC_PL "\n", &z, &y, &x, &h); if (k == EOF) break; /* not an error */ if (k != 3+1) return NPIC_ERR_READ; NpicMaskInsert_3l (m, z, y, x, h); } } break; case NPIC_MASK_4L : { int k, t, z, y, x; Npic_l h; while (! feof (f1)) { k = fscanf (f1, "%d %d %d %d %" NPIC_PL "\n", &t, &z, &y, &x, &h); if (k == EOF) break; /* not an error */ if (k != 4+1) return NPIC_ERR_READ; NpicMaskInsert_4l (m, t, z, y, x, h); } } break; case NPIC_MASK_5L : { int k, s, t, z, y, x; Npic_l h; while (! feof (f1)) { k = fscanf (f1, "%d %d %d %d %d %" NPIC_PL "\n", &s, &t, &z, &y, &x, &h); if (k == EOF) break; /* not an error */ if (k != 5+1) return NPIC_ERR_READ; NpicMaskInsert_5l (m, s, t, z, y, x, h); } } break; case NPIC_MASK_6L : { int k, r, s, t, z, y, x; Npic_l h; while (! feof (f1)) { k = fscanf (f1, "%d %d %d %d %d %d %" NPIC_PL "\n", &r, &s, &t, &z, &y, &x, &h); if (k == EOF) break; /* not an error */ if (k != 6+1) return NPIC_ERR_READ; NpicMaskInsert_6l (m, r, s, t, z, y, x, h); } } break; case NPIC_MASK_2D : { int k, y, x; Npic_d h; while (! feof (f1)) { k = fscanf (f1, "%d %d %lf\n", &y, &x, &h); if (k == EOF) break; /* not an error */ if (k != 2+1) return NPIC_ERR_READ; NpicMaskInsert_2d (m, y, x, h); } } break; case NPIC_MASK_3D : { int k, z, y, x; Npic_d h; while (! feof (f1)) { k = fscanf (f1, "%d %d %d %lf\n", &z, &y, &x, &h); if (k == EOF) break; /* not an error */ if (k != 3+1) return NPIC_ERR_READ; NpicMaskInsert_3d (m, z, y, x, h); } } break; case NPIC_MASK_4D : { int k, t, z, y, x; Npic_d h; while (! feof (f1)) { k = fscanf (f1, "%d %d %d %d %lf\n", &t, &z, &y, &x, &h); if (k == EOF) break; /* not an error */ if (k != 4+1) return NPIC_ERR_READ; NpicMaskInsert_4d (m, t, z, y, x, h); } } break; case NPIC_MASK_5D : { int k, s, t, z, y, x; Npic_d h; while (! feof (f1)) { k = fscanf (f1, "%d %d %d %d %d %lf\n", &s, &t, &z, &y, &x, &h); if (k == EOF) break; /* not an error */ if (k != 5+1) return NPIC_ERR_READ; NpicMaskInsert_5d (m, s, t, z, y, x, h); } } break; case NPIC_MASK_6D : { int k, r, s, t, z, y, x; Npic_d h; while (! feof (f1)) { k = fscanf (f1, "%d %d %d %d %d %d %lf\n", &r, &s, &t, &z, &y, &x, &h); if (k == EOF) break; /* not an error */ if (k != 6+1) return NPIC_ERR_READ; NpicMaskInsert_6d (m, r, s, t, z, y, x, h); } } break; default : return NPIC_ERR_UNEX_NPIC; } return NPIC_SUCCESS; } /* * Print infos on file. * Return NPIC_SUCCESS, else error code. Verbose. */ int NpicNMASKPrintInfo (const char *filename, Npic_nmask_info *info) { int i; printf ("FILENAME \"%s\"\n", filename); if (info == NULL) return NPIC_ERR_NULL_PTR; printf ("MAGIC NMASK-%d\n", info->version); printf ("TYPE %s\n", NpicMaskTypeName(info->type)); printf ("DIM %d\n", info->dim); for (i = 0; i < info->props.nb; i++) printf ("PROP %s: %s\n", info->props.list[i].key, info->props.list[i].val); return NPIC_SUCCESS; } /*----------------------------------------------------------------------------*/