Beispiel #1
0
simData ()
{
    fpConfig_t fp;

    /* Get a Page for the pixel data.  */
    page = smcGetPage (smc, TY_DATA, (im_nx*im_ny*(im_bitpix/8)), TRUE, TRUE);
    if (page == (smcPage_t *) NULL) {
	fprintf (stderr, "Error getting data page.\n");
	return;
    }

    fp.xSize = im_nx;			/* Set the fpConfig struct.	*/
    fp.ySize = im_ny;
    fp.xStart = 0;
    fp.yStart = 0;
    fp.dataType = 1;
    smcSetFPConfig (page, &fp);

    smcSetWho (page, 2);		/* Set the 'who' field		*/
    smcSetExpID (page, 3.141592654);	/* Set the 'expid' field	*/
    smcSetObsetID (page, "3.14159");	/* Set the 'obsetid' field	*/

    /* Create a raster in the shared area 
     */
    make_raster ((int *)smcGetPageData(page), im_nx, im_ny, color_mode++);

    /* Unlock and Detach from the page. 
     */
    smcUnlock (page);
    smcDetach (smc, page, FALSE);
}
Beispiel #2
0
simMetaData ()
{
    fpConfig_t fp;
    mdConfig_t md;
    int i, nkeyw = 256;


    /* Get a Page for the metadata.  */
    page = smcGetPage (smc, TY_META, (80*nkeyw), TRUE, TRUE);
    if (page == (smcPage_t *) NULL) {
	fprintf (stderr, "Error getting metadata page.\n");
	return;
    }

    md.metaType = 1;			/* Set the mdConfig struct.	*/
    md.numFields = nkeyw;
    smcSetMDConfig (page, &md);

    fp.xSize = im_nx;			/* Set the fpConfig struct.	*/
    fp.ySize = im_ny;
    fp.xStart = 0;
    fp.yStart = 0;
    fp.dataType = 1;
    smcSetFPConfig (page, &fp);

    smcSetWho (page, 2);		/* Set the 'who' field		*/
    smcSetExpID (page, 3.141592654);	/* Set the 'expid' field	*/
    smcSetObsetID (page, "3.14159");	/* Set the 'obsetid' field	*/

    /* Create a dummy header in the shared area 
     */
    make_header ((char *)smcGetPageData(page), nkeyw);

    /* Unlock and Detach from the page. 
     */
    smcUnlock (page);
    smcDetach (smc, page, FALSE);
}
Beispiel #3
0
main (int argc, char **argv) 
{
    char   c, fname[64], buf[64], resp[32], val[12], config[128];
    int	   i, j, debug=0, clear = 1, nimages=1, delay=0, interactive=1;
    int    nsegs, pagenum, nvals, imnum=0;
    void   *data;
    char   *cdata, *cp;
    int    *idata, *ip;
    short  *sdata, *sp;
    double stime, etime;


    /* Process command-line arguments.
     */
    strcpy (fname, "\0");
    for (i=1; i < argc; i++) {
        if (strncmp (argv[i], "-cache", 2) == 0) {
	    strcpy (fname, argv[++i]);
        } else if (strncmp (argv[i], "-delay", 2) == 0) {
	    delay = atoi (argv[++i]);
        } else if (strncmp (argv[i], "-x", 2) == 0) {
	    debug++;
        } else if (strncmp (argv[i], "-nimages", 2) == 0) {
	    nimages = atoi (argv[++i]);
        } else if (strncmp (argv[i], "-keep", 2) == 0) {
	    clear = 0;
        } else if (strncmp (argv[i], "-interactive", 2) == 0) {
	    interactive = 1;
        } else if (strncmp (argv[i], "-batch", 2) == 0) {
	    interactive = 0;
        } else if (strncmp (argv[i], "-help", 2) == 0) {
	    printHelp ();
	    exit (0);

	} else
	    printf ("Unrecognized option: %s\n", argv[i]);
    }


    /* Initialize the config string.
     */
    sprintf (config, "debug=%d,cache_file=%s", debug, fname);


    /*  Open/Attach to the cache.
     */
    printf ("Opening cache....\n");
    if ((smc = smcOpen (config)) == (smCache_t *)NULL)
	fprintf (stderr, "Error opening cache, invalid file?.\n");



    /*  Simulate the readout sequence>
     */
    for (i=1; i <= nimages; i++) {
	printf ("Generating image %d ....", i);
        simMetaData ();				/* pre-readout header	*/
        simData ();				/* pixel data		*/
        simMetaData ();				/* post-readout header	*/
	printf ("done.\n");

        sleep (delay); 				/* pause requested time */
    }


    /* Once we're done, see if we want drop into a command mode.
     */
    if (interactive) {
	imnum = nimages;

        /* Command loop */
        printf ("%s (%d)>  ", argv[0], getpid());
        while ((c = getchar())) {

	    switch (c) {
            case 'n':                       /*   new sequence		*/
		stime = smUtilTime();
                nimages = optargi ();
                nimages = max (1, nimages);
		for (i=0; i < nimages; i++) {
		    printf ("Generating readout %d (%d/%d) ....", 
			imnum++, smc->npages, smc->top);
        	    simMetaData ();
		        simData ();
		    simMetaData ();
		    printf ("done.\n");
		}
		etime = smUtilTime();
		printf ("Created %d images in %f sec\n",nimages,(etime-stime));
                break;

            case 'd':                       /*   detach from segment        */
                smcListPages (smc, -1);
                printf ("which page? ");  scanf ("%d", &pagenum);
                page = &smc->pdata[pagenum];
                if (page->ac_locked)
                    printf ("Page is locked for access.\n");
                else
                    smcDetach (smc, page, FALSE);
                break;

            case 'l':                       /*   list segments              */
                nsegs = optargi ();
                if (nsegs < 0 && smc->npages == 0) {
                    printf ("No pages yet allocated, showing first 8.\n");
                    smcListPages (smc, 8);
                } else
                    smcListPages (smc, nsegs);
                break;

            case 'i':                       /*   initialize cache           */
            case 'I':
                if (smc) {
		    int stat;
                    printf ("Initializing cache....\n");
                    stat = smcInitialize (smc);
                    if (stat && debug) 
                        smcPrintCacheInfo (smc, "After Initialize:");
                } else
                    printf ("Cannot initialize() before open()\n");
                break;

	    case '\n':
                printf ("%s (%d)>  ", argv[0], getpid());
	        continue;

            case 'p':                       /*   print cache info           */
                if (smc) {
                    smcPrintCacheInfo (smc, (char *)NULL);
                    smcPrintCfgInfo (&smc->sysConfig, (char *)NULL);
                } else
                    printf ("Null cache ptr, try opening a cache first.\n");
            break;


            case 'q':                       /*   quit                       */
            case 'C':                       /*   close cache                */
                printf ("free cache? ");    scanf ("%s", val);
                smc = smcClose (smc, is_true(val[0]));
                printf ("After smcClose(): smc = 0x%x\n", smc);
                break;

            case 'g':                       /*   print segment data         */
                smcListPages (smc, -1);
                printf ("which page? ");  scanf ("%d", &pagenum);
                page = &smc->pdata[pagenum];
                if (page->ac_locked)
                    printf ("Page is locked for access.\n");
                else {
                    printf ("how many lines? ");  scanf ("%d", &nvals);
                    if (page->type == TY_META) {
                        cdata = (char *)smcGetPageData (page);
                        for (cp=cdata, i=0; i < nvals; i++) {
                            printf ("%.80s", cp);
			    cp += 80;
			}
                    } else {
                        idata = (int *)smcGetPageData (page);
                        for (i=0; i < nvals; i++)
                            printf ("(%d) %s", idata[i],(i&&(i%4==0))?"\n":"");
                    }
                    printf ("\n");
                }
                break;


	    default:
	        printf ("Unknown command: '%c'\n", c);
	    }

            if (c == 'q' || c == 'C')
                break;
        }
    }

    printf ("Done\n");
    if (smc && !interactive) 
	smcClose (smc, clear);
}
Beispiel #4
0
/*  PXFPROCESS -- Process an exposure given the ExpID.
*/
void
pxfProcess (smCache_t *smc, double expID)
{
    char   fname[250], pxfDIR[250], pxfFILENAME[250], resp[SZ_LINE];
    int    i, pcount, fs;
    int    pxfFLAG = 3;  /* indicates that DIR and FILENAME are defined	*/
    XLONG   istat;
    fitsfile *fd;

    smcPage_t *page;
#ifdef DO_TIMINGS
    time_t t1, t2;
#endif


    /*smcSetSeqNo (smc, 0);*/	/* Initialize sequence number		*/

    /* Get Filename and Directory from shared memory.
    */
#ifdef DO_TIMINGS
    t1 = time ((time_t)NULL);
#endif
    bzero (resp, SZ_LINE);
    bzero (fname, 250);
    bzero (pxfDIR, 250);
    bzero (pxfFILENAME, 250);
    strncpy (pxfDIR, (char *)smcGetDir(smc), 250);
    strncpy (pxfFILENAME, (char *)smcGetFRoot(smc), 250);
    strcpy (fname, pxfFILENAME);   		/* save root filename */
    
    if (use_mbus) {
	mbusSend (SUPERVISOR, ANY, MB_STATUS, "active");
        mbusSend (SUPERVISOR, ANY, MB_STATUS, "Processing...");
    }

    /* Open the file */
    if (console)
    	fprintf (stderr, "Opening file '%s'\n", pxfFILENAME);

    if (save_fits) {
        pxfFLAG = 3;
        pxfFileOpen (&istat, resp, &expID, smc, &fd); 
        DPRINTF (10, procDebug, "%s\n", resp);
    }


  for (pcount=0; pcount < 2; pcount++) {
    for (i=0; i < smc->top; i++) {
	page = &smc->pdata[i];

        if (page->memKey == (key_t)NULL)
          continue;

        if (smcEqualExpID(page->expID,expID)) {

	    smcAttach (smc, page); 		/* Attach to the page. */

	    if (console) {
	 	fprintf (stderr, "Processing page %d, %.6lf (%.6lf) ",
    		    i, page->expID, expID);
	    }


	    switch (page->type) { 		/* Process the data.   */
	    case TY_VOID:
	    case TY_DATA:
		if (!noop && pcount == 1) {
		    if (save_fits)
	                procFITSData (page, fd);
		    else
	                procDCAData (page);
		}
	        break;
	    case TY_META:
		if (!noop && pcount == 0) {
		    if (save_fits)
	                procFITSMetaData (page, fd);
		    else
	                procDCAMetaData (page);
		}
	        break;
	    default:
		fprintf (stderr, "Warning: Invalid page type: 0x%x\n", 
		    (int)page);
	        break;
	    }

	    smcDetach (smc, page, FALSE); 	/*  Detach from the page.  */

	} else if (console && verbose) {
	    fprintf (stderr, "Skipping page %d, %.6lf (%.6lf) ",
		i, page->expID, expID);
	     fprintf (stderr, "from=%s page=%d\n", smcGetColID(page),
	        smcGetExpPageNum(page));
	}
    }
  }


#ifdef DO_TIMINGS
    t2 = time ((time_t)NULL);
    fprintf (stderr, "Time [%d] pxfProcess()  expID=%.6lf\n", (t2-t1), expID);
#endif

    if (save_fits) {
        if (console)
	    fprintf (stderr, "Closing file '%s'\n", pxfFILENAME);

        if (fits_close_file ((fitsfile *) fd, &fs)) {
    	    DPRINTF (10, procDebug, "pxf: fits close failed, status = %d\n",fs);
        } else {
    	    DPRINTF (10, procDebug, "pxf: fits close succeeded, status = %d\n",
		fs);
        }
    }
}