Example #1
0
void PrintTestRunSummary()
{
	LOGI("Done. %d tests run. %d passed, of which %d succeeded with warnings. %d failed.", numTestsRun, numTestsPassed, numTestsWarnings, numTestsFailed);
	if (numTestsFailed > 0)
	{
		LOGE("The following tests failed:");
		std::vector<Test> &tests = Tests();
		for (size_t i = 0; i < tests.size(); ++i)
		{
			if (tests[i].result == TestFailed)
				LOGE("   %s", tests[i].name.c_str());
		}
	}
	if (numTestsWarnings > 0)
	{
		LOGW("The following tests had some failures:");
		std::vector<Test> &tests = Tests();
		int totalFailureCount = 0;
		int totalPassCount = 0;
		for (size_t i = 0; i < tests.size(); ++i)
		{
			Test &t = tests[i];
			if (t.numFails > 0 && tests[i].result != TestFailed)
			{
				float successRate = (t.numPasses + t.numFails > 0) ? (float)t.numPasses * 100.f / (t.numPasses + t.numFails) : 0.f;
				LOGW("   %s: %d failures, %d passes (%.2f%% success rate).", tests[i].name.c_str(), tests[i].numFails, tests[i].numPasses, successRate);
				totalFailureCount += t.numFails;
			}
			totalPassCount += t.numPasses;
		}
		LOGW("Total failure count: %d/%d (%f%% of all iterations)", totalFailureCount, totalFailureCount + totalPassCount, totalFailureCount * 100.0 / (totalFailureCount+totalPassCount));
	}
}
Example #2
0
int RunOneTest(int numTimes, int numTrials, const char * const *prefixes, JSONReport &jsonReport)
{
	std::vector<Test> &tests = Tests();
	while(nextTestToRun < (int)tests.size())
	{
		if (StringBeginsWithOneOf(tests[nextTestToRun].name.c_str(), prefixes) || StringContainsOneOf(tests[nextTestToRun].description.c_str(), prefixes)
			|| StringContainsOneOf(tests[nextTestToRun].file.c_str(), prefixes))
		{
			int ret = RunTest(tests[nextTestToRun], numTimes, numTrials, jsonReport);

			if (ret == 0 || ret == 1)
				++numTestsPassed;
			if (ret == 1)
				++numTestsWarnings;
			if (ret == -1)
				++numTestsFailed;

			++nextTestToRun;
			++numTestsRun;
			return ret;
		}
		++nextTestToRun;
	}

	return -2; // No tests left to run
}
Example #3
0
int main(int argc, char ** argv) {
#ifdef DEBUG_
    Tests().run();
#else
    QApplication app(argc, argv);
    convex_hull_viewer viewer;
    visualization::run_viewer(&viewer, "Convex Hull");
#endif
}
Example #4
0
// Returns the number of failures.
int RunTests(int numTimes, int numTrials, const char * const *prefixes, JSONReport &jsonReport)
{
	numTestsRun = numTestsPassed = numTestsWarnings = numTestsFailed = 0;

	for(size_t i = 0; i < Tests().size(); ++i)
		RunOneTest(numTimes, numTrials, prefixes, jsonReport);

	PrintTestRunSummary();
	return numTestsFailed;
}
Example #5
0
void AddBenchmark(std::string name, TestFunctionPtr function, std::string file, std::string description)
{
	Test t;
	t.name = name;
	t.description = description;
	t.function = function;
	t.isRandomized = false;
	t.runOnlyOnce = true;
	t.isBenchmark = true;
	t.file = file;
	Tests().push_back(t);
}
bool LovecraftApp::UserInit()
{
    SetupApplicationConfiguration();

    m_pAppController = new AppController(*this);

    Tests();

    AddTMXDecoder();

    return true;
}
Example #7
0
	void Run()
	{	
		
		BfDev::SysProperties::InitFromProjectOptions();
		//BfDev::SysProperties::InitSysFreq118750kHz();
		
		std::cout << BfDev::SysProperties::Instance().ToString();
/*
		// тестирование таймера
		while(true)
		{
			TestTimer(100);
		}
*/		
	    Sleep(10);

		Tests(BfDev::SysProperties::Instance().getFrequencyCpu()).RunAll();
		
	    std::cout << "Done!" << endl;
	}	  
Example #8
0
int main() {
 Tests();
}
/**
 *  Application entry point.  All VOApps tasks MUST contain this 
 *  method signature.
 */
int
votopic (int argc, char **argv, size_t *reslen, void **result)
{
    int    i, nres_arg = 0, ndat_arg = 0, status = OK, term = 0;
    char  *res_argv[MAX_ARGS], *dat_argv[MAX_ARGS], *topic = NULL;
    char  *resname;


    memset (res_argv, 0, argc+2);	/* initialize	*/
    memset (dat_argv, 0, argc+2);
    resname = vot_mktemp ("votopic");


    /*  Parse the argument list.
     */
    if ((isDecimal (argv[argc-1]) || isSexagesimal (argv[argc-1])) &&
        (isDecimal (argv[argc-2]) || isSexagesimal (argv[argc-2])) &&
        (isDecimal (argv[argc-3]) || isSexagesimal (argv[argc-3])) )
	    term = argc - 4;
    if ((isDecimal (argv[argc-1]) || isSexagesimal (argv[argc-1])) &&
        !(isDecimal (argv[argc-2]) || isSexagesimal (argv[argc-2])) )
	    term = argc - 3;
    if (!(isDecimal (argv[argc-1]) || isSexagesimal (argv[argc-1])) )
	    term = argc - 2;

    /*  Initialize the VOREGISTRY arguments.
     */
    vot_setArg (res_argv, &nres_arg, "voregistry");

    /*  Initialize the VODATA arguments.
     */
    vot_setArg (dat_argv, &ndat_arg, "vodata");
    for (i=1; i < argc; i++) {
	if (i == term) {
            vot_setArg (dat_argv, &ndat_arg, resname);
	    topic = argv[i];
	} else {
	    if (strcmp(argv[i],"-h")==0 || strcmp(argv[i],"--help")==0) {
		Usage (); return (0);
	    } else if (strcmp(argv[i],"-%")==0 || strcmp(argv[i],"--test")==0) {
		Tests (NULL); return (0);
	    } else if (strcmp(argv[i],"-d")==0 || strcmp(argv[i],"--dbg")==0) {
		debug++;

	    } else if ((strcmp(argv[i],"-b")==0 || 
		        strcmp(argv[i],"--bpass")==0) ||
	               (strcmp(argv[i],"-t")==0 || 
		        strcmp(argv[i],"--type")==0)) {
    		vot_setArg (res_argv, &nres_arg, argv[  i]);	/* -b | -t  */
    		vot_setArg (res_argv, &nres_arg, argv[++i]);	/* val      */
	    } else
                vot_setArg (dat_argv, &ndat_arg, argv[i]);
	}
    }


    /*  Create the list of VOREGISTRY arguments.
     */
    vot_setArg (res_argv, &nres_arg, "-d");		/* dalOnly 	*/
    vot_setArg (res_argv, &nres_arg, "-o");		/* output name	*/
    vot_setArg (res_argv, &nres_arg, resname);
    if (by_subj)
        vot_setArg (res_argv, &nres_arg, "-s");
    vot_setArg (res_argv, &nres_arg, topic);

    if (1||debug) {
	for (i=0; i < nres_arg; i++) 
	    printf ("'%s' ", res_argv[i]);
	printf ("\n");
	for (i=0; i < ndat_arg; i++) 
	    printf ("'%s' ", dat_argv[i]);
	printf ("\n");
    }


    /*  Run the Registry query to get the resource list of topics.
     */
    status = voregistry (nres_arg, res_argv, reslen, result);


    /*  Initialize result object whether we return an object or not.
     */
    *reslen = 0;	
    *result = NULL;

   /*  The VODATA task does all the real work, execute it on the list of
    *  resources we just obtained.
    */
    status = vodata (ndat_arg, dat_argv, reslen, result);


    /*  Clean up.  Rememebr to free whatever pointers were created when
     *  parsing arguments.
     */
    for (i=0; i < nres_arg; i++)
	if (res_argv[i]);
	    free ((void *) res_argv[i]);
    for (i=0; i < ndat_arg; i++)
	if (dat_argv[i]);
	    free ((void *) dat_argv[i]);
    unlink (resname);

    return (status);
}
/**
 *  Application entry point.
 */
int
vosesame (int argc, char *argv[], size_t *reslen, void **result)
{
    char **pargv, optval[SZ_FNAME];
    register int  ch=0, arg_index=1, narg=0;
    int    pos=0;


    /*  Process command line arguments and initialize.
     */
    nflags   = 0;
    out	     = stdout;
    *reslen  = 0;
    *result  = NULL;
    memset (flags, 0, MAX_FLAGS);

    pargv = vo_paramInit (argc, argv, opts, long_opts);
    while ((ch = vo_paramNext (opts,long_opts,argc,pargv,optval,&pos)) != 0) {
	if (ch > 0) {
	    switch (ch) {
	    case '%':    Tests (optval);  		return (self.nfail);
	    case 'h':    Usage();     			return (OK);
	    case 'v':    verbose++; quiet=0;		break;
	    case 'q':    quiet++;   verbose=0;		break;

	    case 'a':    all_flags++; 			break;
	    case 'i':    invert++; 			break;
	    case 'd':    flags[nflags++] = F_DEC; 	break;
	    case 'e':    flags[nflags++] = F_ERR; 	break;
	    case 'n':    flags[nflags++] = F_NAM; 	break;
	    case 's':    flags[nflags++] = F_SEX; 	break;
	    case 't':    flags[nflags++] = F_TYP; 	break;

	    case 'p':
		/* Check for a comma-separate position, break it up
		** if necessary.
		*/
		user_pos++;
		if ((sep = (char *) strchr (optval, (int)','))) {
		    *sep = '\0';
		    u_dec = strdup (++sep);
		    u_ra  = strdup (optval);
		}
		if (debug) fprintf (stderr, "ra='%s' dec='%s'\n",  u_ra,u_dec);
		if (u_ra == NULL || u_dec == NULL) {
		    fprintf (stderr, "ERROR: Invalid '-p' syntax\n");
		    return (ERR);
		}

		/* Process a 'fake record' based on the position given.
		** Note this is done using the other options given up to
		** this point.
		*/
		procUserCoord (u_ra, u_dec);
		break;

	    case 'f':
		if (voc_initVOClient("runid=voc.vosesame,use_cache=no") != OK) {
		    fprintf (stderr, "ERROR: cannot open VOClient\n");
		    return (ERR);
		}
		break;

	    case 'o':    
		output = strdup (optval);
		if ((out = fopen (output, "w+")) == (FILE *)NULL) {
		    fprintf (stderr, "Cannot open file '%s'\n", output);
		    return (ERR);
		}
		break;

	    case 'A':    delim = ' ';			break;
	    case 'C':    delim = ',',  format = 0;	break;
	    case 'F':    format++;			break;
	    case 'H':    header++;			break;
	    case 'T':    delim = '\t', format = 0;	break;

	    case 'I':    /*  FIXME  */
			 system ("/bin/rm -f ~/.voclient/cache/sesame/*");
			 exit (0);;
	    }

        } else if (ch == PARG_ERR) {
            return (ERR);

	} else {
	    /* Arguments without a leading '-' are assumed to be either
	    ** target names or @-files.  We let the processing routine
	    ** figure out how to handle it.
	    */
	    if ((status = process_target (optval)) != OK) {
		if (!quiet) {
		    fprintf (stderr, "Warning: Cannot resolve target '%s'\n",
		        optval);
		}
	    }
	    narg++;
	}
	arg_index++;

	/* Final error check for argument overflow -- should never happen.
	if (arg_index > argc)
	    break;
	*/
        if (narg > MAX_FLAGS) {
	    fprintf (stderr, "ERROR: Too many arguments specified\n");
	    return (1);
        }
    }


    /* Process the arguments from the standard input. 
    */
    if (!ntargets) {
        char *name = calloc (1, SZ_FNAME);

        while (fgets (name, SZ_FNAME, stdin)) {
	    name[strlen(name)-1] = '\0';		/* kill newline	*/
	    if ((status += process_target (name)) != OK) {
		if (!quiet) {
		    fprintf (stderr, 
			"Warning: cannot resolve target/access file '%s'\n",
			name);
		}
	    } else
		ntargets++;
	}
        free (name);
    }

    if (!ntargets)
	fprintf (stderr, "Warning: No target name specified.\n");

    if (u_ra)   free ((void *) u_ra);
    if (u_dec)  free ((void *) u_dec);
    if (output) free ((void *) output);

    if (out != stdout)
	fclose (out);

    return ( status );
}
/**
 *  Application entry point.
 */
int
votstat (int argc, char **argv, size_t *reslen, void **result)
{
    /*  These declarations are required for the VOApps param interface.
     */
    char **pargv, optval[SZ_FNAME];

    /*  These declarations are specific to the task.
     */
    char  *iname, *oname, *name, *id, *fstr;
    int    ch = 0, status = OK, numeric = 0;
    int    res, tab, data, tdata, field;
    int    i, ncols, nrows, pos = 0;


    /* Initialize result object	whether we return an object or not.
     */
    *reslen = 0;	
    *result = NULL;

    iname  = NULL; 		/* initialize local task values  	*/
    oname  = NULL;


    /*  Parse the argument list.  
     */
    pargv = vo_paramInit (argc, argv);
    while ((ch = vo_paramNext(opts,long_opts,argc,pargv,optval,&pos)) != 0) {
        if (ch > 0) {
	    switch (ch) {
	    case '%':  Tests (optval);			return (OK);
	    case 'h':  Usage ();			return (OK);
	    case 'a':  do_all++;			break;
	    case 'o':  oname = strdup (optval);		break;
	    case 'r':  do_return=1;	    	    	break;
	    default:
		fprintf (stderr, "Invalid option '%s'\n", optval);
		return (1);
	    }
	} else {
	    /*  Process the positional arguments.
	     */
	    iname = strdup (optval);
	    break;
	}
    }


    /*  Sanity checks.  Tasks should validate input and accept stdin/stdout
     *  where it makes sense.
     */
    if (iname == NULL) iname = strdup ("stdin");
    if (oname == NULL) oname = strdup ("stdout");
    if (strcmp(iname, "-") == 0) { free (iname), iname = strdup ("stdin");  }
    if (strcmp(oname, "-") == 0) { free (oname), oname = strdup ("stdout"); }



    /* Open the table.  This also parses it.
    */
    if ( (vot = vot_openVOTABLE (iname) ) <= 0) {
        fprintf (stderr, "Error opening VOTable '%s'\n", iname);
        return (1);
    }

    res   = vot_getRESOURCE (vot);      /* get handles          */
    tab   = vot_getTABLE (res);
    data  = vot_getDATA (tab);
    tdata = vot_getTABLEDATA (data);
    nrows = vot_getNRows (tdata);
    ncols = vot_getNCols (tdata);


    printf ("# %3s  %-20.20s  %9.9s  %9.9s  %9.9s  %9.9s\n#\n",
	"Col", "Name", "Min", "Max", "Mean", "StdDev");

    for (i=0,field=vot_getFIELD(tab); field; field=vot_getNext (field), i++) {
        name  = vot_getAttr (field, "name");
        id    = vot_getAttr (field, "id");

	numeric = vot_isNumericField (field);
	fstr = (name ? name : (id ? id : "(none)"));

	if (do_all && !numeric)		/* non-numeric column		*/
            printf ("  %3d  %-20.20s\n", i, fstr);

	else if (do_all || numeric) {	/* numeric column		*/
	    double  min, max, mean, stddev;

	    vot_colStat (tdata, i, nrows, &min, &max, &mean, &stddev);

	    if (mean > 1.0e6)
                printf ("  %3d  %-20.20s  %9.4g  %9.4g  %9.4g  %9.4g\n",
                    i, fstr, min, max, mean, stddev);
	    else
                printf ("  %3d  %-20.20s  %9.2f  %9.2f  %9.2f  %9.2f\n",
                    i, fstr, min, max, mean, stddev);
	}
    }


    /*  Clean up.  Rememebr to free whatever pointers were created when
     *  parsing arguments.
     */
    if (iname) free (iname);
    if (oname) free (oname);

    vo_paramFree (argc, pargv);
    vot_closeVOTABLE (vot);

    return (status);	/* status must be OK or ERR (i.e. 0 or 1)     	*/
}
/**
 *  Application entry point.
 */
int
voiminfo (int argc, char **argv, size_t *reslen, void **result)
{
    /*  These declarations are required for the VOApps param interface.
     */
    char **pargv, optval[SZ_FNAME], resbuf[SZ_RESBUF];
    char   imname[SZ_LINE];


    /*  These declarations are specific to the task.
     */
    char   *oname = NULL, *imlist[MAX_IMAGES], *nimlist[MAX_IMAGES];
    int     i, ch = 0, status = OK, pos = 0, nfiles = 0, narg = 0;;
    size_t  maxlen = SZ_RESBUF;
    FILE   *fd = (FILE *) NULL;
    ImInfo *im;


    /* Initialize result object	whether we return an object or not.
     */
    *reslen = 0;	
    *result = NULL;
    memset (imlist,  0, MAX_IMAGES);
    memset (nimlist, 0, MAX_IMAGES);


    /*  Parse the argument list.  The use of vo_paramInit() is required to
     *  rewrite the argv[] strings in a way vo_paramNext() can be used to
     *  parse them.  The programmatic interface allows "param=value" to
     *  be passed in, but the getopt_long() interface requires these to
     *  be written as "--param=value" so they are not confused with 
     *  positional parameters (i.e. any param w/out a leading '-').
     */
    pargv = vo_paramInit (argc, argv, opts, long_opts);
    while ((ch = vo_paramNext(opts,long_opts,argc,pargv,optval,&pos)) != 0) {
        if (ch > 0) {
	    /*  If the 'ch' value is > 0 we are parsing a single letter
	     *  flag as defined in the 'opts string.
	     */
	    switch (ch) {
	    case '%':  Tests (optval);			return (self.nfail);
	    case 'h':  Usage ();			return (OK);
	    case 'r':  do_return=1;	    	    	break;
	    case 'd':  debug++;				break;
	    case 'v':  verbose++;			break;

	    case 'a':  do_all++;			break;
	    case 'b':  do_box++;			break;
	    case 'c':  do_corners++;			break;
	    case 'e':  do_extns++;			break;
	    case 'i':  do_info++;			break;
	    case 's':  do_sex++;			break;
	    case 'n':  do_naxis++;			break;
	    case 'o':  oname = strdup (optval);		break;
	    default:
		fprintf (stderr, "Invalid option '%s'\n", optval);
		return (1);
	    }

        } else if (ch == PARG_ERR) {
            return (ERR);

	} else {
	    /*  This code processes the positional arguments.  The 'optval'
	     *  string contains the value but since this string is
	     *  overwritten w/ each arch we need to make a copy (and must
	     *  remember to free it later.
	     */
	    imlist[nfiles++] = strdup (optval);
	    narg++;
	}

	if (narg > MAX_IMAGES) {
            fprintf (stderr, "ERROR: Too many images to process\n");
            return (1);
	}
    }


    /*  Sanity checks.
     */
    if (imlist[0] == NULL || strcmp (imlist[0], "-") == 0) { 
	free (imlist[0]);
	imlist[0] = strdup ("stdin");  
	nfiles = 1;
    }
    if (do_all && strcasecmp (imlist[0], "stdin") == 0) {
	fprintf (stderr, "Error: Option not supported with standard input\n");
	return (ERR);
    }
    if (oname == NULL) oname = strdup ("stdout");
    if (strcmp (oname, "-") == 0) { free (oname), oname = strdup ("stdout"); }


    /*  Open the output file.
     */
    if (strcmp (oname, "stdout") != 0) {
	if ((fd = fopen (oname, "w+")) == (FILE *) NULL) {
	    fprintf (stderr, "Error: Cannot open output file '%s'\n", oname);
	    return (ERR);
	}
    } else
	fd = stdout;

    /* Default to printing all info if we're not given a specific option.
    if (!do_box && !do_corners && !do_info && !do_naxis)
	do_info = 1;
     */


    /**
     *  Main body of task
     */
    for (i=0; i < nfiles; i++) {

	memset (imname, 0, SZ_LINE);
	if (strncmp ("http://", imlist[i], 7) == 0) {
	    if (access ("/tmp/voiminfo.fits", F_OK) == 0)
		unlink ("/tmp/voiminfo.fits");
	    strcpy (imname, "/tmp/voiminfo.fits");
	    if (vos_getURL (imlist[i], imname) <= 0)
		continue;
	} else
	    strcpy (imname, imlist[i]);

	if ((im = vot_imageInfo (imname, do_all)) ) {
    	    memset (resbuf,  0, SZ_RESBUF);
	    if (do_info) {
                vot_printImageInfo (fd, im);
	    } else if (do_naxis) {
		strcpy (resbuf, fmt_naxis (imname, im, do_all));
	    } else if (do_box) {
		strcpy (resbuf, fmt_box (imname, im, do_all));
	    } else if (do_corners) {
		strcpy (resbuf, fmt_corners (imname, im, do_all));
	    } else {
                sprintf (resbuf, "%s\t%s\t%s\t%s\n", imlist[i], 
		    fmt (im->frame.cx,1), fmt (im->frame.cy,0), 
		    fmt (im->frame.radius,0));
	    }

	    if (do_return)
		vo_appendResultFromString (resbuf, reslen, result, &maxlen);
	    else
                fprintf (fd, "%s", resbuf);

            vot_freeImageInfo (im);

	    if (strncmp ("http://", imlist[i], 7) == 0)
	        unlink (imname);
	}
    }


    /*  Clean up.  Rememebr to free whatever pointers were created when
     *  parsing arguments.
     */
    for (i=0; i < MAX_IMAGES; i++) {
        if (imlist[i])  
	    free (imlist[i]);
        if (nimlist[i]) 
	    free (nimlist[i]);
	else
	    break;
    }
    if (oname) free (oname);
    if (fd != stdout)
	fclose (fd);

    vo_paramFree (argc, pargv);

    return (status);	/* status must be OK or ERR (i.e. 0 or 1)     	*/
}
Example #13
0
/**
 *  Application entry point.
 */
int 
voatlas (int argc, char **argv, size_t *reslen, void **result)
{
    char **pargv, optval[SZ_FNAME], ch;
    char  *iname = NULL, *oname = NULL, *dlname = NULL;
    char   tmp[SZ_FNAME], buf[SZ_FNAME];
    int    i=0, status = OK, apos = 0, samp = -1, naxis = 512;


    /*  Initialize.
     */
    memset (buf, 0, SZ_FNAME);
    memset (tmp, 0, SZ_FNAME);
    memset (survey, 0, SZ_FNAME);
    memset (svc_url, 0, SZ_URL);

    *reslen = 0;
    *result = NULL;


    /*  Parse the argument list.
     */
    pargv = vo_paramInit (argc, argv);
    while ((ch = vo_paramNext (opts,long_opts,argc,pargv,optval,&apos)) != 0) {
	i++;
        if (ch > 0) {
            switch (ch) {
	    case '%':  Tests (optval);			return (OK);
	    case 'h':  Usage ();			return (OK);
	    case 'r':  do_return++;			break;

	    case 'b':  bpass  = strdup (optval);   	break;
	    case 'g':  graphic++;			break;
	    case 'p':  strcpy (survey, optval);		break;
	    case 'n':  naxis = atoi (optval);		break;

	    case 'F':  field  = strdup (optval);   	break;
	    case 'R':  if (strchr (optval, (int)':'))
	    		  ra = (15. * (double) sexa (optval));
		       else
	    		  ra = (double) atof (optval);
		       break;
	    case 'D':  if (strchr (optval, (int)':'))
	    		  dec = (double) sexa (optval);
		       else
	    		  dec = (double) atof (optval);
		       break;
	    case 'P':  sscanf (optval, "%lf,%lf", &ra, &dec);
		       break;

	    case 's':  size   = voa_getSize (optval); 	break;
	    case 'o':  oname  = strdup (optval);   	break;

	    case 'S':  do_samp = 1;			break;
	    case 'v':  verbose = 1;			break;

	    default:
		fprintf (stderr, "Invalid argument '%c'\n", ch);
		return (ERR);
	    }
	} else {
	    /*  FIXME -- Doesn't handle e.g. 3c273 properly.
	    if (isdigit(optval[0]))
	     */
	    if (i == (argc-2)) {
		sprintf (buf, "%s %s", optval, argv[i+1]);
		pos = strdup (buf);
	    } else
		field = strdup (optval);
	    break;
	}
    }

    /*  Setup the output name.
     */
    if (oname) {
	dlname = oname;			    /* output name specified	*/
    } else if (do_samp) {
	strcpy (tmp, "/tmp/voatlasXXXXXX");    /* temp download name	*/
	mktemp (tmp);
	dlname = tmp;
    } else {
	if (field)
	    sprintf (buf, "%s.%s", field, (graphic ? "jpg" : "fits"));
	else if (pos) {
	    char *ip, *op;

	    memset (buf, 0, SZ_FNAME);
	    for (op=buf, ip=pos; *ip; ip++)
		*op++ = (*ip == ' ' ? '_' : *ip);
	    strcat (buf, ".");
	    strcat (buf, (graphic ? "jpg" : "fits"));
	} else {
	    fprintf (stderr, "Error: no output name specified.\n");
	    status = ERR;
	    goto done_;
	}
	dlname = oname = strdup (buf);
    }

    if (!survey[0]) {
	/*  No survey specified so go by the bandpass.
	 */
        if (!bpass)
	    strcpy (survey, "dss2b");
        else {
	    if (strncasecmp (bpass, "optical", 3) == 0)
	        strcpy (survey, "dss");
	    else if (strncasecmp (bpass, "infrared", 3) == 0 ||
		   strncasecmp (bpass, "ir", 2) == 0)
	        strcpy (survey, "2massk");
	    else if (strncasecmp (bpass, "x-ray", 1) == 0)
	        strcpy (survey, "pspc2int");
	    else if (strncasecmp (bpass, "euv", 3) == 0)
	        strcpy (survey, "euv83");
	    else if (strncasecmp (bpass, "gamma-ray", 5) == 0)
	        strcpy (survey, "egret1000");
	    else if (strncasecmp (bpass, "radio", 3) == 0)
	        strcpy (survey, "4850mhz");
        }
    } else if (strcasecmp (survey, "list") == 0) {
	list_surveys = 1;
	memset (survey, 0, SZ_FNAME);
    }
    

    /*  Initialize the VOClient code.  Error messages are printed by the
     *  interface so we just quit if there is a problem.
     */
    if (voc_initVOClient ("runid=voc.voatlas") == ERR) 
        return (ERR);

    /* Sanity checks
     */
    if (iname == NULL) iname = strdup ("stdin");
    if (oname == NULL) oname = strdup ("stdout");
    if (strcmp (iname, "-") == 0) { free (iname), iname = strdup ("stdin");  }
    if (strcmp (oname, "-") == 0) { free (oname), oname = strdup ("stdout"); }

    if (field && pos) {
	fprintf (stderr, 
	    "Error: only one of 'field' or 'pos' may be specified.\n");
	return (ERR);
    } else if (field) {
	if (voa_resolveField (field, &ra, &dec) != OK) {
	    fprintf (stderr, "Error: cannot resolve object '%s'\n", field);
	    return (ERR);
	}
    } else if (pos) {
	if (voa_resolvePos (pos, &ra, &dec) != OK) {
	    fprintf (stderr, "Error: cannot convert position '%s'\n", pos);
	    return (ERR);
	}
    }


    /*  Form the service URL.
     */
    memset (svc_url, 0, SZ_URL);
    sprintf (svc_url, "%snaxis=%d&", base_url, naxis);
    if (survey[0]) {
	strcat (svc_url, "survey=");
	strcat (svc_url, survey);
	strcat (svc_url, "&");
    }


    /*  Call the SkyView SIA service.
     */
    if (voa_callService (svc_url, ra, dec, size, dlname, 
	(graphic ? "jpeg" : "fits"), 1) == ERR) 
	    return (ERR);

    /*  Broadcast the image as a message if requested.
     */
    if (do_samp) {
	if ((samp = sampInit ("voatlas", "VOClient Task")) >= 0) {
	    char url[SZ_LINE], cwd[SZ_LINE];

	    samp_setASyncMode (samp);	/* use asynchronous mode	*/
	    sampStartup (samp);		/* register w/ Hub		*/

	    memset (url, 0, SZ_LINE);
	    memset (cwd, 0, SZ_LINE);
	    getcwd (cwd, SZ_LINE);
	    if (tmp[0])
	        sprintf (url, "file://%s", dlname);
	    else
	        sprintf (url, "file://%s/%s", cwd, oname);

            (void) samp_imageLoadFITS (samp, "all", url, "", field);

	    sampShutdown (samp);
	}
    }


    /*  See if we're returning the image.
     */
    if (do_return) {
	vo_setResultFromFile (dlname, reslen, result);
        unlink (dlname);
    }


    /*  Clean up and shutdown.
     */
done_:
    if (pos)    free (pos);
    if (field)  free (field);
    if (iname)  free (iname);
    if (oname)  free (oname);

    voc_closeVOClient (1);
    vo_paramFree (argc, pargv);

    return (status);
}
Example #14
0
int main(int argc, char** argv)
{
	logLevel = 2;

	int atFile = 0;
	int romSize = 1024 * 1024 * 16;
	unsigned addr = 0;
	bool debugSymbols = false;

	const char* files[2] = {NULL, NULL};
	const char* usage = "usage: %s (-vX | -h | -sX | -d | -eX) [hasm file] [out binary]";

	for(int i = 1; i < argc; i++){
		char* v = argv[i];
		if(STARTSWITH(v, '-')){
			if(!strcmp(v, "-h")){
				LogI(usage, argv[0]);
				LogI(" ");
				LogI("Available flags:");
				LogI("  -vX   set log level, where X is [0-5] - default: 2");
				LogI("  -sX   set assembly start address [0-FFFF] - default 0");
				LogI("  -h    show this help message");
				LogI("  -d    generate debug symbols");
				LogI("  -t    unit tests");
				return 0;
			}
			else if(sscanf(v, "-v%d", &logLevel) == 1){}
			else if(sscanf(v, "-s%x", &addr) == 1){}
			else if(!strcmp(v, "-d")){ debugSymbols = true; }
			else if(!strcmp(v, "-t")){ return Tests(argc, argv); }
			else{
				LogF("No such flag: %s", v);
				return 1;
			}
		}else{
			LAssert(atFile < 2, "Please specify exactly one input file and one output file");
			files[atFile++] = v;
		}
	}

	LAssert(argc >= 3 && files[0] && files[1], usage, argv[0]);
	
	// Allocate 16 MB ROM
	uint8_t* ram = calloc(1, romSize);

	Hasm* d = Hasm_Create();
	
	if(debugSymbols){
		char tmp[4096];
		sprintf(tmp, "%s.dbg", files[1]);
		d->debugFile = fopen(tmp, "w");
		LogV("Opening debug file: %s", tmp);
		LAssert(d->debugFile, "could not open file: %s", tmp);
	}

	uint32_t len = Hasm_Assemble(d, files[0], ram, addr, romSize - 1);

	if(d->debugFile) fclose(d->debugFile);

	Hasm_Destroy(&d);

	if(logLevel == 0 && len) DumpRam(ram, len - 1);

	LogV("Writing to: %s", files[1]);
	WriteFile(ram, len ? len - 1 : 0, files[1]);

	LAssertWarn(len, "produced empty file");

	free(ram);
	return 0;
}
Example #15
0
void header()
{
     /*************************************************************************
     
     The following part implements a new and easy-to-use salt-scripting language.
     The script can be used to attain the follwing tasks :
         1. Add a new salt
         2. Remove a salt
         3. Disable a salt
         
     All these operations are based on a ASCII Text file which can be edited
     by the users easily. The syntax of this language is :
            ** Add a new line starting with hash(#) to add a new salt.
                   Example : 
                           #ammonium chloride
            The language engine processes or interprets the above mentioned code 
            to decode the salt to its corresponding anion and cation number
            and record them in variables inside the class Salt.
            
            I would like to call this scripting language as 'SAScode'. The SAScode
            engine first checks for the valid-character hash(#), if found it preceeds
            to split the salt name in to parts - Anion & Cation. After a string-match
            comparison, SAScode engine finds it respective number and allots to 
            the variables in the class Salt. 
                           
            ** Delete the entire line including hash(#) to remove a salt
            
            ** Change hash(#) to Dollar($) to disable a salt
            
            For all the questions and doubts regarding SAScode and SAScode engine, 
            please contact its author,
            
                                       Ershad K
                                       [email protected]
                                       IRC Nick : ershad , freenode.net    
     
     // SAScode Engine starts here..
    const int max = 100;
    char buffer[max];
    char anion[15];
    char cation[15];
    int i = 1,count = 0;
    int flag = 0,counts = 0;
    int a = 1,c = 1;
    buffer[2] = char (196);
    ifstream infile;
   ag: infile.open ("salts.txt");
    while (infile)
  {
	infile.getline(buffer,max);

	if ( buffer[0] == '#' )
	{
	   for ( i = 1,count = 0; buffer[i] != ' '; i++,count++)
	    {
		   cation[count] = buffer[i];
	    }
	    cation [count] = '\0';

       for ( ++i, count = 0; buffer[i] != ';'; i++,count++)
       {
       	anion[count] = buffer[i];
       }
       anion[count] = '\0';

       cout << cation <<":"<<anion<<"\n";

//$ Available cations :       
//$   ammonium , lead , copper
//$   aluminium , manganese , zinc
//$   barium , calcium , magnesium

//$ Available anions :
//$   carbonate , sulphide , sulphate
//$   nitrate , chloride , bromide
//$   iodide , acetate 


       if ( strcmpi (cation,"ammonium") == 0 ) c = 1;
       if ( strcmpi (cation,"lead") == 0 ) c = 2;
       if ( strcmpi (cation,"copper") == 0 ) c = 3;
       if ( strcmpi (cation,"aluminium") == 0 ) c = 4;
       if ( strcmpi (cation,"manganese") == 0 ) c = 5;
       if ( strcmpi (cation,"zinc") == 0 ) c = 6;
       if ( strcmpi (cation,"barium") == 0 ) c = 7;
       if ( strcmpi (cation,"calcium") == 0 ) c = 8;
       if ( strcmpi (cation,"magnesium") == 0 ) c = 9;

       if ( strcmpi (anion,"carbonate") == 0 ) a = 1;
       if ( strcmpi (cation,"sulphide") == 0 ) a = 2;
       if ( strcmpi (cation,"sulphate") == 0 ) a = 3;
       if ( strcmpi (cation,"nitrate") == 0 ) a = 4;
       if ( strcmpi (cation,"chloride") == 0 ) a = 5;
       if ( strcmpi (cation,"bromide") == 0 ) a = 6;
       if ( strcmpi (cation,"iodide") == 0 ) a = 7;
       if ( strcmpi (cation,"acetate") == 0 ) a = 8;
       
       s[counts++].record(c,a," "); 

  	 }

  }

    infile.close();

    if (buffer[2]==char(196))
    {
     ofstream outfile("salts.txt");
     char txt[] = "$ Edit this file to add or remove salts\n$ Please use small letters\n$ Make sure the spelling is right, using wrong spellings result in errors\n$ Delete the entire line including hash(#) to remove a salt\n"    ;
     char line1[]= "$ Change hash(#) to Dollar($) to disable a salt\n";
     char line2[]= "$ Format to add a new salt is :\n"                   ;
     char line3[]= "$            #<cation><space><anion><semi colon>\n"   ;
     char line4[]= "$     Example :-       #ammonium carbonate;\n"         ;
     char line5[]= "\n"                                                     ;
     char line6[]= "$ Available cations :\n"                                 ;
     char line7[]= "$   ammonium , lead , copper\n"                           ;
     char line8[]= "$   aluminium , manganese , zinc\n"                        ;
     char line9[]= "$   barium , calcium , magnesium\n"                         ;
     char line10[]= "\n"                                                        ;
     char line11[]= "$ Available anions :\n"                                     ;
     char line12[]= "$   carbonate , sulphide , sulphate\n"                      ;
     char line13[]= "$   nitrate , chloride , bromide\n"           ;
     char line14[]= "$   iodide , acetate\n"                        ;
     char line15[]= "\n"                                             ;
     char line16[]= "$ ---------   List of salts starts here ---------\n";
     char line17[]= "\n"                                                  ;
     char line18[]= "#ammonium carbonate;\n"                               ;
     char line19[]= "#ammonium nitrate;\n"                                  ;
     char line20[]= "#ammonium chloride;\n"                                  ;
     char line21[]= "#ammonium acetate;\n"                                    ;
     char line22[]= "#barium chloride;\n"             ;

     outfile << txt << line1 << line2 << line3 << line4 << line5 << line6 << line7   ;
     outfile << line8 << line9 << line10 << line11 << line12 << line13 << line14 << line15 << line16;
   outfile <<  line17 << line18 << line19 << line20 << line21 << line22;
   //  outfile << "\n\n Written using the program ";
     outfile.close();
     goto ag;
    } */
    
    /*
   Cations
#define AMMONIUM 1
#define LEAD 2
#define COPPER 3
#define ALUMINIUM 4
#define MANGANESE 5
#define ZINC 6
#define BARIUM 7
#define CALCIUM 8
#define MAGNESIUM 9


#define CARBONATE 1
#define SULPHIDE 2
#define SULPHATE 3
#define NITRATE 4
#define CHLORIDE 5
#define BROMIDE 6
#define IODIDE 7
#define ACETATE 8
*/
   
    s[1].record(1,1,""); //Ammonium carbonate 
    s[2].record(2,5,""); //Lead carbonate
    s[3].record(6,3,""); //Zinc Sulphate
    s[4].record(7,5,""); //Barium Chloride
    s[5].record(8,1,""); //Calcium Carbonate
    s[6].record(4,5,""); //Aluminium Chloride
    s[7].record(8,7,""); //Calcium Iodide
    s[8].record(6,4,""); //Zinc Nitrate
    s[9].record(3,3,""); //Copper Sulphate
    s[10].record(2,8,""); //Lead Acetate
   // s[11].record(4,8,""); //Aluminium Acetate
    
    
    
    srand(time(0));
    n = (rand() % 10) ;  
   // n = 5;
     
     char ch;
     char input[5];
     int r = 0,t = 0;
     int numflag = 0;
     
     startagain:
                
     /* n must be given a random number */
     
     
     
     redo:
     system ("cls");
     
     
     cout << "\n  Salt Analysis Simulator v 1.0";
     //cout <<"\t\t\t\t\t Salt No - ";
     cout << "\n  -----------------------------\n";
     
     for (i = 0; i < 80; i++ ) {cout << char(196);} 
     cout << " Add reagents <a>     Tests <t>     Answer <k>     About <h>     Exit <e>\n";
     for (i = 0; i < 80; i++ ) {cout << char(196);}
     
     /*
     gotoxy (7,11);
     for (i = 0; t < 30; i++ ) cout <<" ";
     gotoxy (6,10);
     for (i = 0; t < 30; i++ ) cout <<" ";*/
     
     
     cout <<"\n\n Observation : ";
     
     gotoxy (6,11);
     s[n].TestSalt(r);
     gotoxy (7,20);
     s[n].DoTest(t);
     gotoxy (1,16);
     cout << "--------------------------------------------------------------------------------";
     cout <<"\n Last Test Result (" << s[n].lasttest << "): ";
     

     //r = 0;
     
     
     //i = rand();
    // cout <<endl << i << endl << RAND_MAX;
     
	 gotoxy (1,24);
     cout <<" Add reagents directly (code)  <space> ";
     ch = getch(); 
     switch(ch)
     {
               case 'a': r = AddReagent(); break;
               case 'A': r = AddReagent(); break;
               case 'k': answer();break;
               case 'K': answer();break;
               case 'H': about();break;
               case 'h': about();break;
               case 'e':exit(0);
               case 'E':exit(0);
               case 't': t = Tests();break;
               case 'T': t = Tests();break;
               case ' ': 
                          gotoxy (1,24);
                          cout <<"                                                 ";
                          gotoxy (1,24);
                          cout <<" Add reagents directly (code) >> ";
                          cin >>input;
                          for (int x = 0; input[x] != '\0'; x++ )
                          {
                              switch(input[x])
                              {
                                              case '1': numflag = 0;break;
                                              case '2': numflag = 0;break;
                                              case '3': numflag = 0;break;
                                              case '4': numflag = 0;break;
                                              case '5': numflag = 0;break;
                                              case '6': numflag = 0;break;
                                              case '7': numflag = 0;break;
                                              case '8': numflag = 0;break;
                                              case '9': numflag = 0;break;
                                              case '0': numflag = 0;break;
                                              default: numflag = 1;break;
                              }
                          }
                          if (numflag == 0)
                          r = atoi(input);
                          else
                          break;
               
     }
     
      //getchar();
     
     goto redo;
     
               
//     getch();
           
}
Example #16
0
void PrintTestRunSummary()
{
	LOGI("Done. %d tests run. %d passed, of which %d succeeded with warnings. %d failed.", (int)Tests().size(), numTestsPassed, numTestsWarnings, numTestsFailed);
}