Example #1
0
/* do measurements: load density, ploop, etc. and phases onto lattice */
void measure() {
   register int i,j,k, c, is_even;
   register site *s;
   int dx,dy,dz;	/* separation for correlated observables */
   int dir;		/* direction of separation */
   msg_tag *tag;
   register complex cc,dd;	/*scratch*/
   complex ztr, zcof, znum, zdet, TC, zd, density, zphase;
   complex p[4]; /* probabilities of n quarks at a site */
   complex np[4]; /* probabilities at neighbor site */
   complex pp[4][4]; /* joint probabilities of n here and m there */
   complex zplp, plp_even, plp_odd;
   Real locphase, phase;


   /* First make T (= timelike P-loop) from s->ploop_t 
      T stored in s->tempmat1
   */
   ploop_less_slice(nt-1,EVEN);
   ploop_less_slice(nt-1,ODD);

   phase = 0.;
   density = plp_even = plp_odd = cmplx(0.0, 0.0);
   for(j=0;j<4;j++){
	p[j]=cmplx(0.0,0.0);
	for(k=0;k<4;k++)pp[j][k]=cmplx(0.0,0.0);
   }
   FORALLSITES(i,s) {
      if(s->t != nt-1) continue;
      if( ((s->x+s->y+s->z)&0x1)==0 ) is_even=1; else is_even=0;
      mult_su3_nn(&(s->link[TUP]), &(s->ploop_t), &(s->tempmat1));

      zplp = trace_su3(&(s->tempmat1));
      if( is_even){CSUM(plp_even, zplp)}
      else        {CSUM(plp_odd, zplp)}

      ztr = trace_su3(&(s->tempmat1));
      CONJG(ztr, zcof);

      if(is_even){
        for(c=0; c<3; ++c) s->tempmat1.e[c][c].real += C;
        zdet = det_su3(&(s->tempmat1));
        znum = numer(C, ztr, zcof);
        CDIV(znum, zdet, zd);
        CSUM(density, zd);

        /* store n_quark probabilities at this site in lattice variable
	  qprob[], accumulate sum over lattice in p[] */
        cc= cmplx(C*C*C,0.0); CDIV(cc,zdet,s->qprob[0]); CSUM(p[0],s->qprob[0]);
        CMULREAL(ztr,C*C,cc); CDIV(cc,zdet,s->qprob[1]); CSUM(p[1],s->qprob[1]);
        CMULREAL(zcof,C,cc); CDIV(cc,zdet,s->qprob[2]); CSUM(p[2],s->qprob[2]);
        cc = cmplx(1.0,0.0); CDIV(cc,zdet,s->qprob[3]); CSUM(p[3],s->qprob[3]);
  
        locphase = carg(&zdet);
        phase += locphase;
      }

   }
Example #2
0
void imx233_pwm_setup(int channel, int period, int cdiv, int active,
    int active_state, int inactive, int inactive_state)
{
    /* stop */
    bool enable = imx233_pwm_is_enabled(channel);
    if(enable)
        imx233_pwm_enable(channel, false);
    /* setup pin */
    imx233_pinctrl_setup_vpin(VPIN_PWM(channel), "pwm", PINCTRL_DRIVE_4mA, false);
    /* watch the order ! active THEN period
     * NOTE: the register value is period-1 */
    HW_PWM_ACTIVEn(channel) = BF_OR2(PWM_ACTIVEn, ACTIVE(active), INACTIVE(inactive));
    HW_PWM_PERIODn(channel) = BF_OR4(PWM_PERIODn, PERIOD(period - 1),
        ACTIVE_STATE(active_state), INACTIVE_STATE(inactive_state), CDIV(cdiv));
    /* restore */
    imx233_pwm_enable(channel, enable);
}
Example #3
0
/* do measurements: load density, ploop, etc. and phases onto lattice */
void measure() {
   register int i,j,k, c;
   register site *s;
   int dx,dy,dz;	/* separation for correlated observables */
   int dir;		/* direction of separation */
   msg_tag *tag;
   register complex cc,dd;	/*scratch*/
   complex ztr, zcof, znum, zdet, TC, zd, density, zphase;
   complex p[4]; /* probabilities of n quarks at a site */
   complex np[4]; /* probabilities at neighbor site */
   complex pp[4][4]; /* joint probabilities of n here and m there */
   complex zplp, plp;
   Real locphase, phase;


   /* First make T (= timelike P-loop) from s->ploop_t 
      T stored in s->tempmat1
   */
   ploop_less_slice(nt-1,EVEN);
   ploop_less_slice(nt-1,ODD);

   phase = 0.;
   density = plp = cmplx(0.0, 0.0);
   for(j=0;j<4;j++){
	p[j]=cmplx(0.0,0.0);
	for(k=0;k<4;k++)pp[j][k]=cmplx(0.0,0.0);
   }
   FORALLSITES(i,s) {
      if(s->t != nt-1) continue;
      mult_su3_nn(&(s->link[TUP]), &(s->ploop_t), &(s->tempmat1));

      zplp = trace_su3(&(s->tempmat1));
      CSUM(plp, zplp);

      ztr = trace_su3(&(s->tempmat1));
      CONJG(ztr, zcof);

      for(c=0; c<3; ++c) s->tempmat1.e[c][c].real += C;
      zdet = det_su3(&(s->tempmat1));
      znum = numer(C, ztr, zcof);
      CDIV(znum, zdet, zd);
      CSUM(density, zd);

      /* store n_quark probabilities at this site in lattice variable
	qprob[], accumulate sum over lattice in p[] */
      cc = cmplx(C*C*C,0.0); CDIV(cc,zdet,s->qprob[0]); CSUM(p[0],s->qprob[0]);
      CMULREAL(ztr,C*C,cc); CDIV(cc,zdet,s->qprob[1]); CSUM(p[1],s->qprob[1]);
      CMULREAL(zcof,C,cc); CDIV(cc,zdet,s->qprob[2]); CSUM(p[2],s->qprob[2]);
      cc = cmplx(1.0,0.0); CDIV(cc,zdet,s->qprob[3]); CSUM(p[3],s->qprob[3]);

      locphase = carg(&zdet);
      phase += locphase;

   }
   g_floatsum( &phase );
   g_complexsum( &density );
   g_complexsum( &p[0] );
   g_complexsum( &p[1] );
   g_complexsum( &p[2] );
   g_complexsum( &p[3] );
   g_complexsum( &plp );
   CDIVREAL(density,(Real)(nx*ny*nz),density);
   CDIVREAL(p[0],(Real)(nx*ny*nz),p[0]);
   CDIVREAL(p[1],(Real)(nx*ny*nz),p[1]);
   CDIVREAL(p[2],(Real)(nx*ny*nz),p[2]);
   CDIVREAL(p[3],(Real)(nx*ny*nz),p[3]);
   CDIVREAL(plp,(Real)(nx*ny*nz),plp);

   zphase = ce_itheta(phase);
   if(this_node == 0) {
      printf("ZMES\t%e\t%e\t%e\t%e\t%e\t%e\n", zphase.real, zphase.imag, 
	                               density.real, density.imag,
	                               plp.real, plp.imag);
      printf("PMES\t%e\t%e\t%e\t%e\t%e\t%e\t%e\t%e\n",
				p[0].real, p[0].imag, p[1].real, p[1].imag,
				p[2].real, p[2].imag, p[3].real, p[3].imag );
   }

#ifdef PPCORR
   dx=1; dy=0; dz=0;	/* Temporary - right now we just do nearest neighbor */
   for(dir=XUP;dir<=ZUP;dir++){
      tag = start_gather_site( F_OFFSET(qprob[0]), 4*sizeof(complex), dir,
	   EVENANDODD, gen_pt[0] );
      wait_gather(tag);
      FORALLSITES(i,s)if(s->t==nt-1){
        for(j=0;j<4;j++)for(k=0;k<4;k++){
	   CMUL( (s->qprob)[j],((complex *)gen_pt[0][i])[k],cc);
           CSUM(pp[j][k],cc);
        }
      }
      cleanup_gather(tag);
   }

   /* density correlation format:
	PP dx dy dz n1 n2 real imag */
   for(j=0;j<4;j++)for(k=0;k<4;k++){
     g_complexsum( &pp[j][k] );
     CDIVREAL(pp[j][k],(Real)(3*nx*ny*nz),pp[j][k]);
     if(this_node==0)
       printf("PP %d %d %d   %d %d   %e   %e\n",dx,dy,dz,j,k,
	  pp[j][k].real,pp[j][k].imag);
   }
#endif /*PPCORR*/
}
Example #4
0
main(int argc, char *argv[])
{
  #define SECTOR_MODE1_BLKLEN 2048
  #define SECTOR_RAW_BLKLEN   2352

  ULONG filelen, data_blkcnt, blk;
  UWORD cur_percent = 0;

  FILE *isofile, *rawfile;

  SECTORSUBHEADER subheader;

  // Parse the command line arguments.

  ParseCommandLine (argc, argv);

  // Allocate input and output buffers.

  IOBUF *inbufP  = new IOBUF;
  IOBUF *outbufP = new IOBUF;

  // Open the input ISO file.

  if ((isofile = fopen (isofilnam, "rb")) == NULL) {
    fprintf (stderr, "Error opening \"%s\"\n", isofilnam);
    exit (1);
    }

  // Create the output RAW file.

  if ((rawfile = fopen (rawfilnam, "wb")) == NULL) {
    fprintf (stderr, "Error creating \"%s\"\n", rawfilnam);
    exit (1);
    }

  // Get the length of the input file and make sure that it is
  // a multiple of 2048 bytes.

  filelen = filelength (fileno (isofile));

  if (filelen % SECTOR_MODE1_BLKLEN) {
    fprintf (stderr, "Error: Input file length is not a multiple of 2048!\n");
    exit (1);
    }

  data_blkcnt = filelen / SECTOR_MODE1_BLKLEN;

  printf ("File contains %luMb of data (%lu blocks)\n",
    CDIV (filelen, 0x100000), data_blkcnt);

  // Calculate the I/O lengths (base this on the amount of data
  // that can be written from the output buffer).

  UWORD blocks_per_io = sizeof(outbufP->data) / SECTOR_RAW_BLKLEN;

  // Convert the ISO file to a RAW (2352 byte sector) file.

  SLONG lba = 0;
  ULONG blocks_written = 0;

  printf ("Processing...\n");
  printf (" 0%% completed.\r");

  for (blk = 0; blk < data_blkcnt; blk += blocks_per_io)
    {
    UWORD blocks = MIN (blocks_per_io, data_blkcnt - blk);

    // Read the ISO file.

    if (fread (inbufP->data, SECTOR_MODE1_BLKLEN, blocks, isofile) != blocks) {
      fprintf (stderr, "\nUnexpected error reading input file!\n");
      exit (1);
      }

    // If the sector type is MODE2 FORM1, then generate a default subheader.

    if (sectortype == SECTORTYPE_MODE2FORM1)
      {
      MEMCLEAR (&subheader, sizeof(SECTORSUBHEADER));
      subheader.submode.data_flag = TRUE;
      }

    // Convert the blocks to raw CDROM sectors.

    UBYTE *dataP = (UBYTE *)inbufP->data;
    CDSector *sectorP = (CDSector *)outbufP->data;

    for (UWORD b = 0; b < blocks; b++)
      {
      sectorP->Format (
        sectortype, lba, &subheader, dataP, TRUE, FALSE, scramble_flag);

      dataP += SECTOR_MODE1_BLKLEN; sectorP++; lba++;
      }

    // Write the buffer to the output file.

    if (fwrite (outbufP->data, sizeof(CDSector), blocks, rawfile) != blocks) {
      fprintf (stderr, "\nUnexpected error writing output file!\n");
      exit (1);
      }

    // Increment the number of blocks written.

    blocks_written += blocks;

    // Percent complete status change?

    UWORD percent = (blocks_written * 100) / data_blkcnt;

    if (percent > cur_percent) {
      printf (" %u%% completed.\r", percent);
      cur_percent = percent;
      }
    }

  printf ("Conversion completed!\n");

  // Write postgap?

  if (postgap_flag)
    {
    printf ("Writing POSTGAP (150 blocks)...");

    CDSector *sectorP = (CDSector *)outbufP->data;

    for (int i = 0; i < 150; i++)
      {
      sectorP->Format (
        sectortype, lba++, NULL, NULL, TRUE, FALSE, scramble_flag);

      if (fwrite (sectorP, sizeof(CDSector), 1, rawfile) != 1) {
        fprintf (stderr, "\nUnexpected error writing output file!\n");
        exit (1);
        }
      }

    printf ("\n");
    }

  // Close the files.

  fclose (isofile);
  fclose (rawfile);

  // Free the I/O buffers.

  delete inbufP;
  delete outbufP;

  return (0);
}
Example #5
0
main(int argc, char *argv[])
{
  CDReader *cdreaderP;
  FILEHANDLE image_file;

  UWORD audio_blklen, mode1_blklen, mode2_blklen;

  TCHAR image_filnam[_MAX_PATH + 1];
  TCHAR cue_filnam[_MAX_PATH + 1];
  TCHAR cdtext_filnam[_MAX_PATH + 1];

  TCHAR *image_filnamP = NULL, *cue_filnamP = NULL, *cdtext_filnamP = NULL;

  // Enable exception handling.

  EXCEPTION_HANDLER_START

  // Initialize and check the protection.

  ProtInitialize (NULL, FALSE);

  // Get the environment variables.

  GetEnvironmentVariables();

  // Parse the command line arguments.

  ParseCommandLine (argc, argv);

  // Register the event callback function.

  EventRegisterCallback (ConsoleEventCallback);

  // Startup the ASPI manager.

  ASPIAdapter::StartupManager (FALSE, FALSE, TRUE);

  // Find a CDROM device...

  if (cdreader_id_specified)
    {
    if ((cdreaderP = (CDReader *)ASPIAdapter::FindDeviceObject (
          ASPI_M_DEVTYPE_CDROM | ASPI_M_DEVTYPE_WORM,
          cdreader_adapter, cdreader_id, cdreader_lun)) == NULL)
      {
      fprintf (stderr,
        "\nError: Specified device (%u:%u:%u) is not a CDROM!\n",
        cdreader_adapter, cdreader_id, cdreader_lun);
      exit (1);
      }
    }
  else
    {
    if ((cdreaderP = (CDReader *)ASPIAdapter::FindDeviceObject (
          ASPI_M_DEVTYPE_CDROM | ASPI_M_DEVTYPE_WORM)) == NULL) {
      fprintf (stderr,
        "\nError: Unable to find a known CDROM device!\n");
      exit (1);
      }
    }

  if (log_flag)
    {
    printf ("CDROM device found...\n");
    printf ("  HA #%u - ASPI ID #%u - %-8s %-16s %-4s\n\n",
      cdreaderP->GetAdapter(), cdreaderP->GetId(),
      cdreaderP->GetVendorId(), cdreaderP->GetProductId(),
      cdreaderP->GetFirmwareLevel());
    }

  if (cdreaderP->GetModel() == GENERIC_CDROM_SCSI) {
    fprintf (stderr, "Warning: CDROM device model is unknown to this program!\n");
    fprintf (stderr, "The generic CDROM device driver will be used...\n\n");
    }

  // If necessary, check that this device supports the reading of SUBCODEs.

  if ((scan_subcode_mode == SCAN_SUBCODE_QUICK) ||
      (scan_subcode_mode == SCAN_SUBCODE_FULL))
    {
    if (! cdreaderP->IsFlagSet(CDReader::crfReadSUBQ))
      {
      fprintf (stderr,
        "Error: CDROM device does not support the reading of subcodes!\n");
      exit (1);
      }
    }

  // If necessary, check that this device supports the reading of CD+G discs.

  if (cdg_flag && (! cdreaderP->IsFlagSet(CDReader::crfReadCDG))) {
    fprintf (stderr,
      "Error: CDROM device does not support the reading of CD+G discs!\n");
    exit (1);
    }

  // Analyze the disc layout.

  auto_ptr<DiscLayout> disclayoutP(new DiscLayout (
    cdreaderP, read_speed, scan_subcode_mode,
    mcn_isrc_flag, cdtext_flag, log_flag));

  if (log_flag)
    {
    printf ("\nDisc Statistics:\n");
    printf ("  Audio track count      - %u\n", disclayoutP->m_nAudioTrackCount);
    printf ("  Mode1 data track count - %u\n", disclayoutP->m_nMode1TrackCount);
    printf ("  Mode2 data track count - %u\n", disclayoutP->m_nMode2TrackCount);
    }

  // Is the disc too long?

  if (disclayoutP->m_nLastLBA > CDROM_80MIN_BLKCNT)
    fprintf (stderr, "\nWARNING: Disc is longer than 80 minutes!\n");

  // Check the disc layout.

  if (! disclayoutP->Check())
    {
    fprintf (stderr, "\nWARNING: Disc contains one or more tracks that are shorter than \n");
    fprintf (stderr, "four seconds. This is a violation of the CDROM specification.\n");
    }

  // Determine the block lengths.

  audio_blklen = (cdg_flag ? SECTOR_CDDA_SUBPW_BLKLEN : SECTOR_CDDA_BLKLEN);

  if (cooked_flag)
    {mode1_blklen = SECTOR_MODE1_BLKLEN; mode2_blklen = SECTOR_MODE2_BLKLEN;}
  else
    {mode1_blklen = SECTOR_RAW_BLKLEN; mode2_blklen = SECTOR_RAW_BLKLEN;}

  // Set the block length for each track.

  DiscInfo *discinfoP = disclayoutP->m_pDiscInfo;

  for (int i = 0; i < discinfoP->m_nTrackCount; i++)
    {
    TRACKINFO *trackinfoP = &discinfoP->m_TrackInfo[i];

    switch (trackinfoP->datatype)
      {
      case DATATYPE_CDDA:
        trackinfoP->blklen = audio_blklen; break;
      case DATATYPE_CDROM:
        trackinfoP->blklen = mode1_blklen; break;
      case DATATYPE_CDROMXA:
      case DATATYPE_CDI:
        trackinfoP->blklen = mode2_blklen; break;
      }
    }
  
  // Build the cuesheet filename.

  StringCopy (cue_filnam, base_filnamP);
  FileAddExtension (cue_filnam, ".cue", (! cueonly_flag));
  cue_filnamP = cue_filnam;

  // If we're not just writing a cuesheet, then build the image and CD-TEXT filenames.

  if (! cueonly_flag)
    {
    StringCopy (image_filnam, base_filnamP);
    FileAddExtension (image_filnam, ".bin", FALSE);
    image_filnamP = image_filnam;

    if (cdtext_flag && (discinfoP->m_pCDTextPackVec != NULL))
      {
      StringCopy (cdtext_filnam, base_filnamP);
      FileAddExtension (cdtext_filnam, ".cdt", TRUE);
      cdtext_filnamP = cdtext_filnam;
      }

    // Display image file stats?

    if (log_flag)
      {
      // Compute the amount of disc space required.
      ULONG blkcnt = disclayoutP->m_nLastLBA + 1;

      printf ("\nImage file will require approximately %luMb of disk space.\n",
        CDIV (blkcnt * SECTOR_RAW_BLKLEN, 0x100000));
      }

    // Prompt to begin copy?

    if (confirm_flag)
      {
      printf ("\nHit <ENTER> to copy disc (or CTRL/C to exit)...");
      getchar ();
      printf ("\n");
      }
    }

  // Generate the CUE SHEET file.

  disclayoutP->GenerateCuesheetFile (cue_filnamP, image_filnamP, cdtext_filnamP);

  // Generate the CD-TEXT data file?

  if (cdtext_filnamP != NULL)
    {
    FILEHANDLE handle;
    ULONG null = 0;

    if ((handle = FileCreate (cdtext_filnamP)) == NULL)
      SignalException (E_CreateFile, 1, 0, 0, HeapString(cdtext_filnamP));

    FileWrite (
      handle, discinfoP->m_pCDTextPackVec, discinfoP->m_nCDTextPackCount * sizeof(CDTEXTPACK));

    FileWrite (handle, &null, 1);

    FileClose (handle);
    }

  // Generate the image file?

  if (image_filnamP != NULL)
    {
    // Make sure the device is ready.

    cdreaderP->LoadDisc (TRUE);

    // Create the output image file.

    if ((image_file = FileCreate (image_filnamP)) == NULL) {
      fprintf (stderr, "\nError creating image file \"%s\"\n", image_filnamP);
      exit (1);
      }

    // Loop through the "copy instructions"...

    for (int i = 0; i < disclayoutP->m_nCopyInstrCount; i++)
      {
      COPYINSTR *copyinstrP = &disclayoutP->m_CopyInstr[i];

      // Set the block length.

      UWORD blklen = ((copyinstrP->datatype == DATATYPE_CDDA) ? audio_blklen :
        ((copyinstrP->datatype == DATATYPE_CDROM) ? mode1_blklen : mode2_blklen));

      // Select operation...

      switch (copyinstrP->opcode)
        {
        // Read a range of audio/data sectors.

        case CI_READ_SECTORS:
          {
          if (copyinstrP->datatype == DATATYPE_CDDA)
            {
            // Set the reading speed.
            cdreaderP->SetSpindleSpeed (read_speed, FALSE, FALSE);

            // Extract the audio sectors.
            cdreaderP->ExtractSectorsToFile (
              image_file, DATATYPE_CDDA, blklen, copyinstrP->lba, copyinstrP->blkcnt,
              jitter_mode, 0, error_mode, FALSE, log_flag);
            }
          else
            {
            // Set the reading speed to maximum.
            cdreaderP->SetSpindleSpeed (SPEED_MAX, TRUE, FALSE);

            // Extract the data sectors.
            cdreaderP->ExtractSectorsToFile (
              image_file, copyinstrP->datatype, blklen, copyinstrP->lba, copyinstrP->blkcnt,
              JITTER_MODE_DISABLE, 0, error_mode, FALSE, log_flag);
            }

          break;
          }

        // Generate replacements for unreadable blocks at the end of a track.

        case CI_GENERATE_SECTORS:
          {
          WriteEmptySectors (
            image_file, copyinstrP->datatype, blklen, copyinstrP->lba, copyinstrP->blkcnt);
          break;
          }

        // Ignore PREGAP instructions.

        case CI_GENERATE_PREGAP:
        case CI_GENERATE_PREGAP2:
          break;

        default: SignalException (E_BugCheck);
        }
      }

    // Reset the reading speed.

    cdreaderP->SetSpindleSpeed (SPEED_MAX, FALSE, FALSE);

    // Close the image file.

    FileClose (image_file);

    // Success!

    if (log_flag) printf ("\nCopy completed successfully!\n");

    // Notify user of completion?

    if (beep_flag) BeepUser();
    }

  // Shutdown the ASPI manager.

  ASPIAdapter::ShutdownManager();

  // End exception handling.

  EXCEPTION_HANDLER_EXIT

  return (0);
}