/* * The Npic library and tools * * Copyright (C) 2003 Edouard Thiel * * This program 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 "npic-new.ct" */ /* * npic-new.c - 02/10/2008 * */ #include void ShowUsage () { printf ( "npic-new - Create an image, with all pixels set to 0.\n" "Usage:\n" " npic-new -h | -help | --help : print help\n" " npic-new out1 -2c|-2l|-2d|-2q y:x : create y*x 2D image\n" " npic-new out1 -3c|-3l|-3d|-3q z:y:x : create z*y*x 3D image\n" " npic-new out1 -4c|-4l|-4d|-4q t:z:y:x : create t*z*y*x 4D image\n" " npic-new out1 -5c|-5l|-5d|-5q s:t:z:y:x : create s*t*z*y*x 5D image\n" " npic-new out1 -6c|-6l|-6d|-6q r:s:t:z:y:x : create r*s*t*z*y*x 6D image\n" "\n" "out1 : image file in " NPIC_KNOWN_IMAGE_EXT " format\n" "\n" "r, s, t, z, y, x : positive integers.\n" "\n" "pixel types : c = unsigned char, d = double,\n" " q = 4 unsigned shorts, l = signed long.\n" ); } void ArgcExit (int argc, int n) { if (argc < n) { fprintf (stderr, "ERROR: %d argument(s) missing, " "type \"npic-new -h\" to get help.\n", n-argc); exit (1); } } int main (int argc, char *argv[]) { Npic_image *np1 = NULL; char *out1, *what, *size; ArgcExit (argc, 2); if (strcmp (argv[1], "-h") == 0 || strcmp (argv[1], "-help") == 0 || strcmp (argv[1], "--help") == 0) { ShowUsage (); exit (0); } ArgcExit (argc, 4); out1 = argv[1]; what = argv[2]; size = argv[3]; if (strcmp (what, "-2c") == 0) { int y, x; if (sscanf (size, "%d:%d", &y, &x) == 2) { printf ("Creating 2c image\n"); np1 = NpicCreateImage_2c (y, x, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else if (strcmp (what, "-2l") == 0) { int y, x; if (sscanf (size, "%d:%d", &y, &x) == 2) { printf ("Creating 2l image\n"); np1 = NpicCreateImage_2l (y, x, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else if (strcmp (what, "-2d") == 0) { int y, x; if (sscanf (size, "%d:%d", &y, &x) == 2) { printf ("Creating 2d image\n"); np1 = NpicCreateImage_2d (y, x, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else if (strcmp (what, "-2q") == 0) { int y, x; if (sscanf (size, "%d:%d", &y, &x) == 2) { printf ("Creating 2q image\n"); np1 = NpicCreateImage_2q (y, x, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else if (strcmp (what, "-3c") == 0) { int z, y, x; if (sscanf (size, "%d:%d:%d", &z, &y, &x) == 3) { printf ("Creating 3c image\n"); np1 = NpicCreateImage_3c (z, y, x, 0, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else if (strcmp (what, "-3l") == 0) { int z, y, x; if (sscanf (size, "%d:%d:%d", &z, &y, &x) == 3) { printf ("Creating 3l image\n"); np1 = NpicCreateImage_3l (z, y, x, 0, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else if (strcmp (what, "-3d") == 0) { int z, y, x; if (sscanf (size, "%d:%d:%d", &z, &y, &x) == 3) { printf ("Creating 3d image\n"); np1 = NpicCreateImage_3d (z, y, x, 0, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else if (strcmp (what, "-3q") == 0) { int z, y, x; if (sscanf (size, "%d:%d:%d", &z, &y, &x) == 3) { printf ("Creating 3q image\n"); np1 = NpicCreateImage_3q (z, y, x, 0, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else if (strcmp (what, "-4c") == 0) { int t, z, y, x; if (sscanf (size, "%d:%d:%d:%d", &t, &z, &y, &x) == 4) { printf ("Creating 4c image\n"); np1 = NpicCreateImage_4c (t, z, y, x, 0, 0, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else if (strcmp (what, "-4l") == 0) { int t, z, y, x; if (sscanf (size, "%d:%d:%d:%d", &t, &z, &y, &x) == 4) { printf ("Creating 4l image\n"); np1 = NpicCreateImage_4l (t, z, y, x, 0, 0, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else if (strcmp (what, "-4d") == 0) { int t, z, y, x; if (sscanf (size, "%d:%d:%d:%d", &t, &z, &y, &x) == 4) { printf ("Creating 4d image\n"); np1 = NpicCreateImage_4d (t, z, y, x, 0, 0, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else if (strcmp (what, "-4q") == 0) { int t, z, y, x; if (sscanf (size, "%d:%d:%d:%d", &t, &z, &y, &x) == 4) { printf ("Creating 4q image\n"); np1 = NpicCreateImage_4q (t, z, y, x, 0, 0, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else if (strcmp (what, "-5c") == 0) { int s, t, z, y, x; if (sscanf (size, "%d:%d:%d:%d:%d", &s, &t, &z, &y, &x) == 5) { printf ("Creating 5c image\n"); np1 = NpicCreateImage_5c (s, t, z, y, x, 0, 0, 0, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else if (strcmp (what, "-5l") == 0) { int s, t, z, y, x; if (sscanf (size, "%d:%d:%d:%d:%d", &s, &t, &z, &y, &x) == 5) { printf ("Creating 5l image\n"); np1 = NpicCreateImage_5l (s, t, z, y, x, 0, 0, 0, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else if (strcmp (what, "-5d") == 0) { int s, t, z, y, x; if (sscanf (size, "%d:%d:%d:%d:%d", &s, &t, &z, &y, &x) == 5) { printf ("Creating 5d image\n"); np1 = NpicCreateImage_5d (s, t, z, y, x, 0, 0, 0, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else if (strcmp (what, "-5q") == 0) { int s, t, z, y, x; if (sscanf (size, "%d:%d:%d:%d:%d", &s, &t, &z, &y, &x) == 5) { printf ("Creating 5q image\n"); np1 = NpicCreateImage_5q (s, t, z, y, x, 0, 0, 0, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else if (strcmp (what, "-6c") == 0) { int r, s, t, z, y, x; if (sscanf (size, "%d:%d:%d:%d:%d:%d", &r, &s, &t, &z, &y, &x) == 6) { printf ("Creating 6c image\n"); np1 = NpicCreateImage_6c (r, s, t, z, y, x, 0, 0, 0, 0, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else if (strcmp (what, "-6l") == 0) { int r, s, t, z, y, x; if (sscanf (size, "%d:%d:%d:%d:%d:%d", &r, &s, &t, &z, &y, &x) == 6) { printf ("Creating 6l image\n"); np1 = NpicCreateImage_6l (r, s, t, z, y, x, 0, 0, 0, 0, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else if (strcmp (what, "-6d") == 0) { int r, s, t, z, y, x; if (sscanf (size, "%d:%d:%d:%d:%d:%d", &r, &s, &t, &z, &y, &x) == 6) { printf ("Creating 6d image\n"); np1 = NpicCreateImage_6d (r, s, t, z, y, x, 0, 0, 0, 0, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else if (strcmp (what, "-6q") == 0) { int r, s, t, z, y, x; if (sscanf (size, "%d:%d:%d:%d:%d:%d", &r, &s, &t, &z, &y, &x) == 6) { printf ("Creating 6q image\n"); np1 = NpicCreateImage_6q (r, s, t, z, y, x, 0, 0, 0, 0, 0, 0); } else { fprintf (stderr, "ERROR: bad size\n"); exit (1); } } else { fprintf (stderr, "ERROR: -2c|-2l|-2d|-2q|-3c|-3l|-3d|-3q|-4c|-4l|-4d|-4q|-5c|-5l|-5d|-5q|-6c|-6l|-6d|-6q expected\n"); exit (1); } printf ("Saving \"%s\"\n", out1); if (NpicWriteImage (np1, out1) != NPIC_SUCCESS) exit(1); NpicDestroyImage (np1); exit (0); }