<commit_before>/*
  Teem: Tools to process and visualize scientific data and images              
  Copyright (C) 2012, 2011, 2010, 2009  University of Chicago
  Copyright (C) 2008, 2007, 2006, 2005  <NAME>
  Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998  University of Utah

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public License
  (LGPL) as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  The terms of redistributing and/or modifying this software also
  include exceptions to the LGPL that facilitate static linking.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public License
  along with this library; if not, write to Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "teem/nrrd.h"
#include <testDataPath.h>

/* 
** Tests: 
** nrrdLoad
*/

int
main(int argc, const char **argv) {
  const char *me;
  Nrrd *nin;
  airArray *mop;
  char *fullname;

  AIR_UNUSED(argc);
  me = argv[0];
  mop = airMopNew();
  int differ;

  nin = nrrdNew();
  airMopAdd(mop, nin, (airMopper)nrrdNuke, airMopAlways);
  fullname = testDataPathPrefix("fmob-c4h.nrrd");
  airMopAdd(mop, fullname, airFree, airMopAlways);
  if (nrrdLoad(nin, fullname, NULL)) {
    char *err;
    airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
    fprintf(stderr, "%s: trouble reading data \"%s\":\n%s",
            me, fullname, err);
    airMopError(mop); return 1;
  }

  {
    Nrrd *ncopy;
    char *blah, *blah1L, explain[AIR_STRLEN_LARGE];
    size_t ii, blen;
    int cmperr;
    ncopy = nrrdNew();
    airMopAdd(mop, ncopy, (airMopper)nrrdNuke, airMopAlways);
    /* HEY: actually a larger length will cause a segfault, but
       debugging it with valgrind was extremely slow (15 minutes or
       so for error to occur) and thwarted by its endless production
       of "Signal 11 being dropped" messages */
    blen = AIR_STRLEN_HUGE*42;
    blah = AIR_CALLOC(blen, char);
    airMopAdd(mop, blah, airFree, airMopAlways);
    for (ii=0; ii<blen-1; ii++) {
      /* NOTE: a more rigorous test would put things in here that can't
         be directly written to file, like \r \v \f, but fixing that bug
         is enough of a significant change to functionality that it should
         be discussed with users first */
      blah[ii] = ("abcdefghijklmnopqrtsuvzwyz\n\"\\ "
                  "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n\"\\ ")
        [airRandInt((26 + 4)*2)]; /* 4 other characters */
    }
    blah[ii] = '\0';
    /* NOTE: this blah1L is to overcome a long-stanging bug that \n's
       were permitted in labels and units, but can't be written.  Same
       as NOTE above.  New code now prevents generating broken NRRD files,
       but it means that the comparison test between in-memory vs the
       saved-and-read nrrd would fail */
    blah1L = airOneLinify(airStrdup(blah));
    airMopAdd(mop, blah1L, airFree, airMopAlways);
    nrrdAxisInfoSet_va(nin, nrrdAxisInfoLabel, 
                       "first axis label", "2nd axis label",
                       blah1L);
    nin->spaceUnits[0] = airOneLinify(airStrdup("\nsp\"\nu0\n"));
    nin->spaceUnits[1] = airStrdup("bob");
    nin->spaceUnits[2] = airStrdup(blah1L);  /* see NOTE above */
    if (nrrdCommentAdd(nin, "the first comment")
        || nrrdCommentAdd(nin, "very long comment follows")
        || nrrdCommentAdd(nin, blah)
        || nrrdKeyValueAdd(nin, "first key", "first value")
        || nrrdKeyValueAdd(nin, "2nd key", "2nd value")
        || nrrdKeyValueAdd(nin, "big key", blah)) {
      char *err;
      airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
      fprintf(stderr, "%s: trouble w/ comments or KVPs:\n%s",
              me, err);
      airMopError(mop); return 1;
    }
    if (nrrdCopy(ncopy, nin)
        || nrrdCompare(nin, ncopy, AIR_FALSE /* onlyData */,
                       &differ, explain)) {
      char *err;
      airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
      fprintf(stderr, "%s: trouble w/ copy or compare:\n%s\n", me, err);
      airMopError(mop); return 1;
    }
    if (differ) {
      fprintf(stderr, "%s: difference in in-memory copy: %s\n", me, explain);
      airMopError(mop); return 1;
    }
    if (nrrdSave("tloadTest.nrrd", nin, NULL)
        || nrrdLoad(ncopy, "tloadTest.nrrd", NULL)
        || nrrdCompare(nin, ncopy, AIR_FALSE /* onlyData */,
                       &differ, explain)) {
      char *err;
      airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
      fprintf(stderr, "%s: trouble w/ save, load, compare:\n%s\n", me, err);
      airMopError(mop); return 1;
    }
    if (differ) {
      fprintf(stderr, "%s: difference in on-disk copy: %s\n", me, explain);
      airMopError(mop); return 1;
    }
  }

  airMopOkay(mop);
  return 0;
}
<commit_msg>removing unused variable<commit_after>/*
  Teem: Tools to process and visualize scientific data and images              
  Copyright (C) 2012, 2011, 2010, 2009  University of Chicago
  Copyright (C) 2008, 2007, 2006, 2005  <NAME>
  Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998  University of Utah

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public License
  (LGPL) as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  The terms of redistributing and/or modifying this software also
  include exceptions to the LGPL that facilitate static linking.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public License
  along with this library; if not, write to Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "teem/nrrd.h"
#include <testDataPath.h>

/* 
** Tests: 
** nrrdLoad
*/

int
main(int argc, const char **argv) {
  const char *me;
  Nrrd *nin;
  airArray *mop;
  char *fullname;

  AIR_UNUSED(argc);
  me = argv[0];
  mop = airMopNew();
  int differ;

  nin = nrrdNew();
  airMopAdd(mop, nin, (airMopper)nrrdNuke, airMopAlways);
  fullname = testDataPathPrefix("fmob-c4h.nrrd");
  airMopAdd(mop, fullname, airFree, airMopAlways);
  if (nrrdLoad(nin, fullname, NULL)) {
    char *err;
    airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
    fprintf(stderr, "%s: trouble reading data \"%s\":\n%s",
            me, fullname, err);
    airMopError(mop); return 1;
  }

  {
    Nrrd *ncopy;
    char *blah, *blah1L, explain[AIR_STRLEN_LARGE];
    size_t ii, blen;
    ncopy = nrrdNew();
    airMopAdd(mop, ncopy, (airMopper)nrrdNuke, airMopAlways);
    /* HEY: actually a larger length will cause a segfault, but
       debugging it with valgrind was extremely slow (15 minutes or
       so for error to occur) and thwarted by its endless production
       of "Signal 11 being dropped" messages */
    blen = AIR_STRLEN_HUGE*42;
    blah = AIR_CALLOC(blen, char);
    airMopAdd(mop, blah, airFree, airMopAlways);
    for (ii=0; ii<blen-1; ii++) {
      /* NOTE: a more rigorous test would put things in here that can't
         be directly written to file, like \r \v \f, but fixing that bug
         is enough of a significant change to functionality that it should
         be discussed with users first */
      blah[ii] = ("abcdefghijklmnopqrtsuvzwyz\n\"\\ "
                  "ABCDEFGHIJKLMNOPQRSTUVWXYZ\n\"\\ ")
        [airRandInt((26 + 4)*2)]; /* 4 other characters */
    }
    blah[ii] = '\0';
    /* NOTE: this blah1L is to overcome a long-stanging bug that \n's
       were permitted in labels and units, but can't be written.  Same
       as NOTE above.  New code now prevents generating broken NRRD files,
       but it means that the comparison test between in-memory vs the
       saved-and-read nrrd would fail */
    blah1L = airOneLinify(airStrdup(blah));
    airMopAdd(mop, blah1L, airFree, airMopAlways);
    nrrdAxisInfoSet_va(nin, nrrdAxisInfoLabel, 
                       "first axis label", "2nd axis label",
                       blah1L);
    nin->spaceUnits[0] = airOneLinify(airStrdup("\nsp\"\nu0\n"));
    nin->spaceUnits[1] = airStrdup("bob");
    nin->spaceUnits[2] = airStrdup(blah1L);  /* see NOTE above */
    if (nrrdCommentAdd(nin, "the first comment")
        || nrrdCommentAdd(nin, "very long comment follows")
        || nrrdCommentAdd(nin, blah)
        || nrrdKeyValueAdd(nin, "first key", "first value")
        || nrrdKeyValueAdd(nin, "2nd key", "2nd value")
        || nrrdKeyValueAdd(nin, "big key", blah)) {
      char *err;
      airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
      fprintf(stderr, "%s: trouble w/ comments or KVPs:\n%s",
              me, err);
      airMopError(mop); return 1;
    }
    if (nrrdCopy(ncopy, nin)
        || nrrdCompare(nin, ncopy, AIR_FALSE /* onlyData */,
                       &differ, explain)) {
      char *err;
      airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
      fprintf(stderr, "%s: trouble w/ copy or compare:\n%s\n", me, err);
      airMopError(mop); return 1;
    }
    if (differ) {
      fprintf(stderr, "%s: difference in in-memory copy: %s\n", me, explain);
      airMopError(mop); return 1;
    }
    if (nrrdSave("tloadTest.nrrd", nin, NULL)
        || nrrdLoad(ncopy, "tloadTest.nrrd", NULL)
        || nrrdCompare(nin, ncopy, AIR_FALSE /* onlyData */,
                       &differ, explain)) {
      char *err;
      airMopAdd(mop, err = biffGetDone(NRRD), airFree, airMopAlways);
      fprintf(stderr, "%s: trouble w/ save, load, compare:\n%s\n", me, err);
      airMopError(mop); return 1;
    }
    if (differ) {
      fprintf(stderr, "%s: difference in on-disk copy: %s\n", me, explain);
      airMopError(mop); return 1;
    }
  }

  airMopOkay(mop);
  return 0;
}

{'fraction_non_alphanumeric': 0.11428845600230304, 'fraction_numerical': 0.02091929757220996, 'mean_word_length': 2.901909397229502, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3995861', 'n_tokens_mistral': 3773, 'n_tokens_neox': 3554, 'n_words': 1124}