Exemple #1
0
//--------------------------------------------------------------------------------------
// GPU Bitonic Sort
//--------------------------------------------------------------------------------------
void GPUSort()
{
    // Upload the data
    g_pd3dImmediateContext->UpdateSubresource( g_pBuffer1, 0, NULL, &data[0], 0, 0 );

    // Sort the data
    // First sort the rows for the levels <= to the block size
    for( UINT level = 2 ; level <= BITONIC_BLOCK_SIZE ; level = level * 2 )
    {
        SetConstants( level, level, MATRIX_HEIGHT, MATRIX_WIDTH );

        // Sort the row data
        g_pd3dImmediateContext->CSSetUnorderedAccessViews( 0, 1, &g_pBuffer1UAV, NULL );
        g_pd3dImmediateContext->CSSetShader( g_pComputeShaderBitonic, NULL, 0 );
        g_pd3dImmediateContext->Dispatch( NUM_ELEMENTS / BITONIC_BLOCK_SIZE, 1, 1 );
    }
    
    // Then sort the rows and columns for the levels > than the block size
    // Transpose. Sort the Columns. Transpose. Sort the Rows.
    for( UINT level = (BITONIC_BLOCK_SIZE * 2) ; level <= NUM_ELEMENTS ; level = level * 2 )
    {
        SetConstants( (level / BITONIC_BLOCK_SIZE), (level & ~NUM_ELEMENTS) / BITONIC_BLOCK_SIZE, MATRIX_WIDTH, MATRIX_HEIGHT );

        // Transpose the data from buffer 1 into buffer 2
        ID3D11ShaderResourceView* pViewNULL = NULL;
        g_pd3dImmediateContext->CSSetShaderResources( 0, 1, &pViewNULL );
        g_pd3dImmediateContext->CSSetUnorderedAccessViews( 0, 1, &g_pBuffer2UAV, NULL );
        g_pd3dImmediateContext->CSSetShaderResources( 0, 1, &g_pBuffer1SRV );
        g_pd3dImmediateContext->CSSetShader( g_pComputeShaderTranspose, NULL, 0 );
        g_pd3dImmediateContext->Dispatch( MATRIX_WIDTH / TRANSPOSE_BLOCK_SIZE, MATRIX_HEIGHT / TRANSPOSE_BLOCK_SIZE, 1 );

        // Sort the transposed column data
        g_pd3dImmediateContext->CSSetShader( g_pComputeShaderBitonic, NULL, 0 );
        g_pd3dImmediateContext->Dispatch( NUM_ELEMENTS / BITONIC_BLOCK_SIZE, 1, 1 );

        SetConstants( BITONIC_BLOCK_SIZE, level, MATRIX_HEIGHT, MATRIX_WIDTH );

        // Transpose the data from buffer 2 back into buffer 1
        g_pd3dImmediateContext->CSSetShaderResources( 0, 1, &pViewNULL );
        g_pd3dImmediateContext->CSSetUnorderedAccessViews( 0, 1, &g_pBuffer1UAV, NULL );
        g_pd3dImmediateContext->CSSetShaderResources( 0, 1, &g_pBuffer2SRV );
        g_pd3dImmediateContext->CSSetShader( g_pComputeShaderTranspose, NULL, 0 );
        g_pd3dImmediateContext->Dispatch( MATRIX_HEIGHT / TRANSPOSE_BLOCK_SIZE, MATRIX_WIDTH / TRANSPOSE_BLOCK_SIZE, 1 );

        // Sort the row data
        g_pd3dImmediateContext->CSSetShader( g_pComputeShaderBitonic, NULL, 0 );
        g_pd3dImmediateContext->Dispatch( NUM_ELEMENTS / BITONIC_BLOCK_SIZE, 1, 1 );
    }

    // Download the data
    D3D11_MAPPED_SUBRESOURCE MappedResource = {0}; 
    g_pd3dImmediateContext->CopyResource( g_pReadBackBuffer, g_pBuffer1 );
    g_pd3dImmediateContext->Map( g_pReadBackBuffer, 0, D3D11_MAP_READ, 0, &MappedResource );       
    memcpy( &results[0], MappedResource.pData, NUM_ELEMENTS * sizeof(UINT) );
    g_pd3dImmediateContext->Unmap( g_pReadBackBuffer, 0 );
}
Exemple #2
0
void BriefGo(char *MissionName)
{
    SetConstants();
    LinksSeq[0] = (char*)memalloc(8);
    
    strcpy(LinksSeq[0], MissionName);
    
    BriefInit(LinksSeq[0]);

  DrawOnScreen(1);
  FadeIn(Palette, 0);
  
  int BriefEvent; 
    // -7: Exit, -4: Up, -3: Down, -2: PgUp, -1: PgDown, 1..n: Odkazy HT
    do {
      BriefEvent = BriefGetEvent();
      BriefHandleEvent(BriefEvent);
  } while (BriefEvent != -7);
  
    BriefDone();
    FadeOut(Palette, 0);
    {
        TEvent e;
        do {GetEvent(&e);} while (e.What != evNothing);
    }
}
Exemple #3
0
        void UpdateMagnetic(GaugeLinks *U){
            
            //SET CONSTANTS TO COMPUTE ENERGY MOMENTUM TENSOR
            SetConstants(U);
            
            UpdateMagnetic(0,U->N[0]-1,0,U->N[1]-1,0,U->N[2]-1,U);

        }
Exemple #4
0
 void Update(GaugeLinks *U,ElectricFields *E){
     
     //SET CONSTANTS TO COMPUTE ENERGY MOMENTUM TENSOR
     SetConstants(U);
     
     //UPDATE INDIVIDUAL CONTRIBUTIONS
     UpdateMagnetic(0,U->N[0]-1,0,U->N[1]-1,0,U->N[2]-1,U);
     UpdateElectric(0,E->N[0]-1,0,E->N[1]-1,0,E->N[2]-1,E);
     
     
 }
Exemple #5
0
/// Activate the effect
void TSRD3D11Effect::Activate()
{
    /// reset all ps textures ( mutes d3d warning ), is this a performance issue?
    static ID3DShaderResourceView* s_ClearShaderResourceViews[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
    g_pD3DDeviceContext->PSSetShaderResources( 0, 8, s_ClearShaderResourceViews );

    SetConstants();
#ifdef D3D11_RENDERER
    m_pPass->Apply( 0, g_pD3DDeviceContext );
#endif 
#ifdef D3D10_RENDERER
    m_pPass->Apply( 0 );
#endif 
    m_NeedRefresh = false;
}
Exemple #6
0
int main(void)
{
	//int Value = 0;
	
	DDRC  = 0x7F;
	PORTC = 0x7D;
	serial_initialize(57600);				// USART Initialize
	//serial_initialize(250000);				// USART Initialize
	dxl_initialize( 0, 7 ); // Not using device index
	sei();
	SetUpServos();
	SetConstants();
	SetKConstants();

	printf("ARMS CONTROL - Left \r" );
	printf("Ver1.0 - Last Moddification 23-03-15\r" );

	while (1)
	{
	
		
	if(cmdReady)
	{
		 if(!execCommand()) printf("Unknown command\r");
	}
	
	
	if(doLoop)
	{
		executeControl();
		count = count + 100;
	}
	
	if(doGripper)
	{
		executeGripper();
	}
		
		_delay_ms(3);
	

	Leds();

	}

	return 1;
}
Exemple #7
0
int main(int argc, char** argv)
{

	int narg;
	int nPhases;


	/* set program name */

	strcpy(prog_name, PNAME);


	/* check command line for correct usage */

	fprintf(stdout, "%s Arguments: ", prog_name);
	for (narg = 0; narg < argc; narg++)
		fprintf(stdout, "<%s> ", argv[narg]);
	fprintf(stdout, "\n");

	if (argc < 5) {
		puterr("ERROR wrong number of command line arguments.");
		disp_usage(PNAME,
"<nll_hyp_target> <nll_hyp_phs_source> <nll_hyp_out> dist_max_fract");
		exit(0);
	}

	SetConstants();
	message_flag = 1;
	DispProgInfo();
	message_flag = 0;

	if ((nPhases = doFindEquivPhases(argc, argv)) < 0) {
		puterr("ERROR doing Phase Equivalence process.");
		exit(0);
	}



	exit(nPhases);

}
Exemple #8
0
int main(int argc, char** argv)
{

	int istat, narg;


	/* set program name */

	strcpy(prog_name, PNAME);


	/* check command line for correct usage */

	fprintf(stdout, "%s Arguments: ", prog_name);
	for (narg = 0; narg < argc; narg++)
		fprintf(stdout, "<%s> ", argv[narg]);
	fprintf(stdout, "\n");

	if (argc < 5) {
		puterr("ERROR wrong number of command line arguments.");
		disp_usage(PNAME,
"hypfile1 hypfile2 time_tolerance nobs_tolerance");
		exit(-1);
	}

	SetConstants();
	message_flag = 1;
	DispProgInfo();
	message_flag = 0;

	if ((istat = DiffHypocenters(argc, argv)) < 0) {
		puterr("ERROR doing difference process.");
		exit(-1);
	}



	exit(0);

}
void MultiDrawIndirect::SetupMultiDrawIndirectData( GLint                       PositionHandle,
                                                    GLint                       NormalHandle,
                                                    GLint                       TexcoordHandle,
                                                    GLint                       InstanceHandle)
{
    GLuint                              BufferID;
    NvModel*                            pData;
    int32_t                             PositionSize;
    int32_t                             NormalSize;
    int32_t                             TexCoordSize;

    pData = m_Model->getModel();

    PositionSize = pData->getPositionSize();
    NormalSize = pData->getNormalSize();
    TexCoordSize = pData->getTexCoordSize();

    SetConstants();

    glBindVertexArray(m_VertexArrayObject);

    glGenBuffers(1, &BufferID);
    glBindBuffer(GL_ARRAY_BUFFER, BufferID);

    glBufferData(   GL_ARRAY_BUFFER,
                    m_SizeofVertexBuffer,
                    NULL,
                    GL_STATIC_DRAW);
    glGenBuffers(1, &BufferID);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, BufferID);

    glBufferData(   GL_ELEMENT_ARRAY_BUFFER,
                    m_SizeofIndexBuffer,
                    NULL,
                    GL_STATIC_DRAW);

    SetupMultipleModelData();

    glVertexAttribPointer(  PositionHandle,
                            PositionSize,
                            GL_FLOAT,
                            GL_FALSE,
                            m_VertexSize,
                            0);
    glEnableVertexAttribArray(PositionHandle);

    glVertexAttribPointer(  NormalHandle,
                            NormalSize,
                            GL_FLOAT,
                            GL_FALSE,
                            m_VertexSize,
                            OFFSET(pData->getCompiledNormalOffset() * sizeof(float)));
    glEnableVertexAttribArray(NormalHandle);

    glVertexAttribPointer(  TexcoordHandle,
                            TexCoordSize,
                            GL_FLOAT,
                            GL_FALSE,
                            m_VertexSize,
                            OFFSET(pData->getCompiledTexCoordOffset() * sizeof(float)));
    glEnableVertexAttribArray(TexcoordHandle);
    
    if (InstanceHandle >= 0) {
        glVertexAttribPointer(  InstanceHandle,
                                2,
                                GL_FLOAT,
                                GL_FALSE,
                                0,
                               OFFSET(m_OffsetofInstanceBuffer));
        glEnableVertexAttribArray(InstanceHandle);
        glVertexAttribDivisor(InstanceHandle,1);
    }

    glBindVertexArray(0);
    CHECK_GL_ERROR();
}
Exemple #10
0
int NLLoc
(

        // calling parameters
        char *pid_main, // CUSTOM_ETH only: snap id
        char *fn_control_main, // NLLoc control file: full path and name (set to NULL if *param_line_array not NULL)
        char **param_line_array, // array of NLLoc control file lines (set to NULL if fn_control_main not NULL)
        int n_param_lines, // number of elements (parameter lines) in array param_line_array (use 0 if fn_control_main not NULL)
        char **obs_line_array, // array of observations file lines (set to NULL if obs file name is read from NLLoc control file)
        int n_obs_lines, // number of elements (obs file lines) in array obs_line_array (set to 0 if obs file name is read from NLLoc control file)
        int return_locations, // if = 1, return Locations with basic information (HypoDesc* phypo, ArrivalDesc* parrivals, int narrivals, GridDesc* pgrid
        int return_oct_tree_grid, // if = 1 and LOCSEARCH OCT used, includes location probabily density oct-tree structure in Locations (Tree3D* poctTree)
        int return_scatter_sample, // if = 1, includes location location scatter sample data in Locations (float* pscatterSample)

        // returned parameters
        LocNode **ploc_list_head // pointer to pointer to head of list of LocNodes containing Location's for located events (see phaseloclist.h), *ploc_list_head must be initialized to NULL on first call to NLLoc()

        ) {

    int istat, n;
    int i_end_of_input, iLocated;
    int narr, ngrid, nObsFile;
    int numArrivalsIgnore, numSArrivalsLocation;
    int numArrivalsReject;
    int maxArrExceeded = 0;
    int n_file_root_count = 1;
    char fn_root_out[FILENAME_MAX], fname[FILENAME_MAX], fn_root_out_last[FILENAME_MAX];
    char sys_command[MAXLINE_LONG];
    char *chr;
    FILE *fp_obs = NULL, *fpio;

    char *ppath;

    int return_value = EXIT_NORMAL;


    /* set program name */
    strcpy(prog_name, PNAME);


    // DD
    nll_mode = MODE_ABSOLUTE;

    /* set constants */

    SetConstants();
    NumLocGrids = 0;
    NumEvents = NumEventsLocated = NumLocationsCompleted = 0;
    NumCompDesc = 0;
    NumLocAlias = 0;
    NumLocExclude = 0;
    NumTimeDelays = 0;
    NumPhaseID = 0;
    DistStaGridMax = 0.0;
    MinNumArrLoc = 0;
    MinNumSArrLoc = 0;
    MaxNumArrLoc = MAX_NUM_ARRIVALS;
    FixOriginTimeFlag = 0;
    Scatter.npts = -1;
    for (n = 0; n < MAX_NUM_MAG_METHODS; n++)
        Magnitude[n].type = MAG_UNDEF;
    NumMagnitudeMethods = 0;
    ApplyCrustElevCorrFlag = 0;
    MinDistCrustElevCorr = 2.0; // deg
    ApplyElevCorrFlag = 0;
    NumTimeDelaySurface = 0;
    topo_surface_index = -1;
    iRejectDuplicateArrivals = 1;
    strcpy(fn_root_out_last, "");
    ;

    // Arrival prior weighting  (NLL_FORMAT_VER_2)
    iUseArrivalPriorWeights = 1;

    // station distance weighting
    iSetStationDistributionWeights = 0;
    stationDistributionWeightCutoff = -1;

    // GridMemLib
    MaxNum3DGridMemory = -1;
    GridMemList = NULL;
    GridMemListSize = 0;
    GridMemListNumElements = 0;

    // otime limits
    OtimeLimitList = NULL;
    NumOtimeLimit = 0;

    // GLOBAL
    NumSources = 0;
    NumStations = 0;

    // Gauss2
    iUseGauss2 = 0;


    // output
    iSaveNLLocEvent = iSaveNLLocSum = iSaveHypo71Event = iSaveHypo71Sum
            = iSaveHypoEllEvent = iSaveHypoEllSum
            = iSaveHypoInvSum = iSaveHypoInvY2KArc
            = iSaveAlberto4Sum = iSaveNLLocOctree = iSaveNone = 0;

    /* open control file */

    if (fn_control_main != NULL) {
        strcpy(fn_control, fn_control_main);
        if ((fp_control = fopen(fn_control, "r")) == NULL) {
            nll_puterr("FATAL ERROR: opening control file.");
            return_value = EXIT_ERROR_FILEIO;
            goto cleanup_return;
        } else {
            NumFilesOpen++;
        }
    } else {
        fp_control = NULL;
    }


#ifdef CUSTOM_ETH
    /* SH 02/27/2004
    added snap_pid   */
    strcpy(snap_pid, pid_main);
    /* SH 02AUG2004 not needed any more
    // AJL 20040527 added snap param file
    if (argc > 3)
    strcpy(snap_param_file, argv[3]);
    else
    strcpy(snap_param_file, "snap_param.txt");
     */
#endif


    /* read NLLoc control statements from control file */

    if ((istat = ReadNLLoc_Input(fp_control, param_line_array, n_param_lines)) < 0) {
        nll_puterr("FATAL ERROR: reading control file.");
        return_value = EXIT_ERROR_FILEIO;
        goto cleanup_return;
    }
    if (fp_control != NULL) {
        fclose(fp_control);
        NumFilesOpen--;
    }


    /* read observation lines into memory stream (must read control file first) */

    char *bp_memory_stream = NULL;
    if (n_obs_lines > 0) {
#ifdef _GNU_SOURCE
        size_t memory_stream_size;
        FILE *fp_memory_stream = NULL;
        // read lines into memory memory stream
        fp_memory_stream = open_memstream(&bp_memory_stream, &memory_stream_size);
        if (fp_memory_stream == NULL) {
            nll_puterr("FATAL ERROR: Cannot pass observations file lines as string array to NLLoc function: GNU C library extensions needed to support memory streams (function open_memstream).");
            return_value = EXIT_ERROR_MEMORY;
            goto cleanup_return;
        }
        for (n = 0; n < n_obs_lines; n++) {
            fprintf(fp_memory_stream, "%s", obs_line_array[n]);
            /*DEBUG*///printf("%s", obs_line_array[n]);
        }
        fclose(fp_memory_stream);
        //
        fp_obs = fmemopen(bp_memory_stream, memory_stream_size, "r");

        NumObsFiles = 1;
#else
        nll_puterr("FATAL ERROR: Cannot pass observations file lines as string array to NLLoc function: GNU C library extensions needed to support memory streams (function open_memstream(); see compiler define _GNU_SOURCE).");
        return_value = EXIT_ERROR_MEMORY;
        goto cleanup_return;
#endif
    }



    // get path to output files
    strcpy(f_outpath, fn_path_output);
    if ((ppath = strrchr(f_outpath, '/')) != NULL
            || (ppath = strrchr(f_outpath, '\\')) != NULL)
        *(ppath + 1) = '\0';
    else
        strcpy(f_outpath, "");


    // copy control file to output directory

    if (!iSaveNone && fp_control != NULL) {
        chr = strrchr(fn_control, '/');
        if (chr != NULL)
            strcpy(fname, chr + 1);
        else
            strcpy(fname, fn_control);
        sprintf(sys_command, "cp -p %s %s_%s", fn_control, fn_path_output, fname);
        system(sys_command);
        sprintf(sys_command, "cp -p %s %slast.in", fn_control, f_outpath);
        system(sys_command);
        //printf("sys_command: %s\n", sys_command);
    }


    /* convert source location coordinates  */
    istat = ConvertSourceLoc(0, Source, NumSources, 1, 1);


    /* initialize random number generator */

    SRAND_FUNC(RandomNumSeed);
    if (message_flag >= 4)
        test_rand_int();


    /* open summary output file */

    if (!iSaveNone) {
        if ((istat = OpenSummaryFiles(fn_path_output, "grid")) < 0) {
            nll_puterr("FATAL ERROR: opening hypocenter summary files.");
            return_value = EXIT_ERROR_FILEIO;
            goto cleanup_return;
        }
    }

    // 20101005 AJL
    // open velocity files if needed
    fp_model_grid_P = fp_model_hdr_P = NULL;
    fp_model_grid_S = fp_model_hdr_S = NULL;
    if (LocMethod == METH_OT_STACK) {
        sprintf(fname, "%s.%s", fn_loc_grids, "P.mod");
        if ((istat = OpenGrid3dFile(fname, &fp_model_grid_P, &fp_model_hdr_P,
                &model_grid_P, " ", NULL, iSwapBytesOnInput)) < 0) {
            sprintf(MsgStr, "WARNING: LocMethod == OT_STACK, but cannot open velocity model file %s.*", fname);
            nll_putmsg(1, MsgStr);
        } else {
            sprintf(MsgStr, "INFO: LocMethod == OT_STACK, sucessfully opened velocity model file %s.*", fname);
            nll_putmsg(1, MsgStr);

        }
        sprintf(fname, "%s.%s", fn_loc_grids, "S.mod");
        if ((istat = OpenGrid3dFile(fname, &fp_model_grid_S, &fp_model_hdr_S,
                &model_grid_S, " ", NULL, iSwapBytesOnInput)) < 0) {
            sprintf(MsgStr, "WARNING: LocMethod == OT_STACK, but cannot open velocity model file %s.*", fname);
            nll_putmsg(1, MsgStr);
        } else {
            sprintf(MsgStr, "INFO: LocMethod == OT_STACK, sucessfully opened velocity model file %s.*", fname);
            nll_putmsg(1, MsgStr);

        }
    }


    /* perform location for each observation file */

    for (nObsFile = 0; nObsFile < NumObsFiles; nObsFile++) {

        i_end_of_input = 0;

        nll_putmsg(2, "");
        sprintf(MsgStr, "... Reading observation file %s",
                fn_loc_obs[nObsFile]);
        nll_putmsg(1, MsgStr);

        // check if observations are read from file(s)
        if ((n_obs_lines <= 0)) {
            /* open observation file */
            if ((fp_obs = fopen(fn_loc_obs[nObsFile], "r")) == NULL) {
                nll_puterr2("ERROR: opening observations file",
                        fn_loc_obs[nObsFile]);
                continue;
            } else {
                NumFilesOpen++;
            }
            /* extract info from filename */
            if ((istat = ExtractFilenameInfo(fn_loc_obs[nObsFile], ftype_obs)) < 0)
                nll_puterr("WARNING: error extractng information from filename.");
        }


        /* read arrivals and locate event for each  */
        /*		event (set of observations) in file */

        NumArrivals = 0;
        while (1) {

            iLocated = 0;

            if (i_end_of_input)
                break;

            if (NumArrivals != OBS_FILE_SKIP_INPUT_LINE) {
                nll_putmsg(2, "");
                sprintf(MsgStr,
                        "Reading next set of observations (Files open: Tot:%d Buf:%d Hdr:%d  Alloc: %d) ...",
                        NumFilesOpen, NumGridBufFilesOpen, NumGridHdrFilesOpen, NumAllocations);
                nll_putmsg(1, MsgStr);
            }


            /* read next set of observations */

            NumArrivalsLocation = 0;
            if ((NumArrivals = GetObservations(fp_obs,
                    ftype_obs, fn_loc_grids, Arrival,
                    &i_end_of_input, &numArrivalsIgnore,
                    &numArrivalsReject,
                    MaxNumArrLoc, &Hypocenter,
                    &maxArrExceeded, &numSArrivalsLocation, 0)) == 0)
                break;

            if (NumArrivals < 0)
                goto cleanup;


            /* set number of arrivals to be used in location */

            NumArrivalsLocation = NumArrivals - numArrivalsIgnore;
            NumArrivalsRead = NumArrivals + numArrivalsReject;

            nll_putmsg(2, "");
            // AJL 20040720 SetOutName(Arrival + 0, fn_path_output, fn_root_out, fn_root_out_last, 1);
            SetOutName(Arrival + 0, fn_path_output, fn_root_out, fn_root_out_last, iSaveDecSec, &n_file_root_count);
            //strcpy(fn_root_out_last, fn_root_out); /* save filename */
            sprintf(MsgStr,
                    "... %d observations read, %d will be used for location (%s).",
                    NumArrivalsRead, NumArrivalsLocation, fn_root_out);
            nll_putmsg(1, MsgStr);


            /* sort to get rejected arrivals at end of arrivals array */

            if ((istat = SortArrivalsIgnore(Arrival, NumArrivalsRead)) < 0) {
                nll_puterr("ERROR: sorting arrivals by ignore flag.");
                goto cleanup;
            }


            /* check for minimum number of arrivals */

            if (NumArrivalsLocation < MinNumArrLoc) {
                sprintf(MsgStr,
                        "WARNING: too few observations to locate (%d available, %d needed), skipping event.", NumArrivalsLocation, MinNumArrLoc);
                nll_putmsg(1, MsgStr);
                sprintf(MsgStr,
                        "INFO: %d observations needed (specified in control file entry LOCMETH).",
                        MinNumArrLoc);
                nll_putmsg(2, MsgStr);
                goto cleanup;
            }


            /* check for minimum number of S arrivals */

            if (numSArrivalsLocation < MinNumSArrLoc) {
                sprintf(MsgStr,
                        "WARNING: too few S observations to locate (%d available, %d needed), skipping event.", numSArrivalsLocation, MinNumSArrLoc);
                nll_putmsg(1, MsgStr);
                sprintf(MsgStr,
                        "INFO: %d S observations needed (specified in control file entry LOCMETH).",
                        MinNumSArrLoc);
                nll_putmsg(2, MsgStr);
                goto cleanup;
            }


            /* process arrivals */

            /* add stations to station list */

            // station distribution weighting
            if (iSetStationDistributionWeights || iSaveNLLocSum || octtreeParams.use_stations_density) {
                //printf(">>>>>>>>>>> NumStations %d, NumArrivals %d, numArrivalsReject %d\n", NumStations, NumArrivals, numArrivalsReject);
                NumStations = addToStationList(StationList, NumStations, Arrival, NumArrivalsRead);
                if (iSetStationDistributionWeights)
                    setStationDistributionWeights(StationList, NumStations, Arrival, NumArrivals);

            }

            /* sort to get location arrivals in time order */

            if ((istat = SortArrivalsIgnore(Arrival, NumArrivals)) < 0) {
                nll_puterr("ERROR: sorting arrivals by ignore flag.");
                goto cleanup;
            }
            if ((istat = SortArrivalsTime(Arrival, NumArrivalsLocation)) < 0) {
                nll_puterr("ERROR: sorting arrivals by time.");
                goto cleanup;
            }


            /* construct weight matrix (TV82, eq. 10-9; MEN92, eq. 12) */

            if ((istat = ConstWeightMatrix(NumArrivalsLocation, Arrival, &Gauss)) < 0) {
                nll_puterr("ERROR: constructing weight matrix - NLLoc requires non-zero observation or modelisation errors.");
                /* close time grid files and continue */
                goto cleanup;
            }


            /* calculate weighted mean of obs arrival times   */
            /*	(TV82, eq. A-38) */

            CalcCenteredTimesObs(NumArrivalsLocation, Arrival, &Gauss, &Hypocenter);


            /* preform location for each grid */

            sprintf(MsgStr,
                    "Locating... (Files open: Tot:%d Buf:%d Hdr:%d  Alloc: %d  3DMem: %d) ...",
                    NumFilesOpen, NumGridBufFilesOpen, NumGridHdrFilesOpen, NumAllocations, Num3DGridReadToMemory);
            nll_putmsg(1, MsgStr);

            for (ngrid = 0; ngrid < NumLocGrids; ngrid++) {
                if ((istat = Locate(ngrid, fn_loc_obs[nObsFile], fn_root_out, numArrivalsReject, return_locations, return_oct_tree_grid, return_scatter_sample, ploc_list_head)) < 0) {
                    if (istat == GRID_NOT_INSIDE)
                        break;
                    else {
                        nll_puterr("ERROR: location failed.");
                        goto cleanup;
                    }
                }
            }

            NumEventsLocated++;
            if (istat == 0 && ngrid == NumLocGrids)
                NumLocationsCompleted++;
            iLocated = 1;

cleanup:
            ;

            NumEvents++;
            //n_file_root_count++;

            /* release grid buffer or sheet storage */

            // 20130413 AJL - bug? fix, release memory for all arrivals read
            //for (narr = 0; narr < NumArrivalsLocation; narr++) {
            for (narr = 0; narr < NumArrivals; narr++) {
                //printf("DEBUG: FREE: narr %d Arrival[narr].n_time_grid %d\n", narr, Arrival[narr].n_time_grid);
                if (Arrival[narr].n_time_grid < 0) { // check has opened time grid
                    DestroyGridArray(&(Arrival[narr].sheetdesc));
                    FreeGrid(&(Arrival[narr].sheetdesc));
                    NLL_DestroyGridArray(&(Arrival[narr].gdesc));
                    NLL_FreeGrid(&(Arrival[narr].gdesc));
                }
            }
            //  20141219 AJL - bug fix, should be outside events/obs loop!
            //NLL_FreeGridMemory();

            /* close time grid files (opened in function GetObservations) */

            // 20130413 AJL - bug? fix, release memory for all arrivals read
            //for (narr = 0; narr < NumArrivalsLocation; narr++) {
            for (narr = 0; narr < NumArrivals; narr++) {
                CloseGrid3dFile(&(Arrival[narr].fpgrid), &(Arrival[narr].fphdr));
            }

            if (iLocated) {
                nll_putmsg(2, "");
                sprintf(MsgStr,
                        "Finished event location, output files: %s.* <%s.grid0.loc.hyp>",
                        fn_root_out, fn_root_out);
                nll_putmsg(0, MsgStr);
            } else
                nll_putmsg(2, "");

            // 201101013 AJL - Bug fix - this cleanup was done in NLLocLib.c->clean_memory() which puts the cleanup incorrectly inside the Locate loop
            CleanWeightMatrix();

        } /* next event */

        nll_putmsg(2, "");
        sprintf(MsgStr, "...end of observation file detected.");
        nll_putmsg(1, MsgStr);

        if ((n_obs_lines <= 0)) { // observations are read from file(s)
            fclose(fp_obs);
            NumFilesOpen--;
        } else { // observation lines are read from memory stream (20101110 AJL)
            // AJL 20101110 - Bug fix for function version
            fclose(fp_obs);
        }

    } /* next observation file */

    nll_putmsg(2, "");
    sprintf(MsgStr,
            "No more observation files.  %d events read,  %d events located,  %d locations completed.",
            NumEvents, NumEventsLocated, NumLocationsCompleted);
    nll_putmsg(0, MsgStr);
    nll_putmsg(2, "");


    /* write cumulative arrival statistics */
    if (!iSaveNone) {
        for (ngrid = 0; ngrid < NumLocGrids; ngrid++) {
            if (LocGridSave[ngrid]) {
                sprintf(fname, "%s.sum.grid%d.loc.stat", fn_path_output, ngrid);
                if ((fpio = fopen(fname, "w")) == NULL) {
                    nll_puterr2(
                            "ERROR: opening cumulative phase statistics output file", fname);
                    return_value = EXIT_ERROR_FILEIO;
                    goto cleanup_return;
                } else {
                    NumFilesOpen++;
                }
                WriteStaStatTable(ngrid, fpio,
                        RMS_Max, NRdgs_Min, Gap_Max,
                        P_ResidualMax, S_ResidualMax, Ell_Len3_Max, Hypo_Depth_Min, Hypo_Depth_Max, Hypo_Dist_Max, WRITE_RESIDUALS);
                WriteStaStatTable(ngrid, fpio,
                        RMS_Max, NRdgs_Min, Gap_Max,
                        P_ResidualMax, S_ResidualMax, Ell_Len3_Max, Hypo_Depth_Min, Hypo_Depth_Max, Hypo_Dist_Max, WRITE_RES_DELAYS);
                WriteStaStatTable(ngrid, fpio,
                        RMS_Max, NRdgs_Min, Gap_Max,
                        P_ResidualMax, S_ResidualMax, Ell_Len3_Max, Hypo_Depth_Min, Hypo_Depth_Max, Hypo_Dist_Max, WRITE_PDF_RESIDUALS);
                WriteStaStatTable(ngrid, fpio,
                        RMS_Max, NRdgs_Min, Gap_Max,
                        P_ResidualMax, S_ResidualMax, Ell_Len3_Max, Hypo_Depth_Min, Hypo_Depth_Max, Hypo_Dist_Max, WRITE_PDF_DELAYS);
                fclose(fpio);
                // save to last
                sprintf(sys_command, "cp %s %slast.stat", fname, f_outpath);
                system(sys_command);
                // write delays only
                sprintf(fname, "%s.sum.grid%d.loc.stat_totcorr", fn_path_output, ngrid);
                if ((fpio = fopen(fname, "w")) == NULL) {
                    nll_puterr2(
                            "ERROR: opening total phase corrections output file", fname);
                    return_value = EXIT_ERROR_FILEIO;
                    goto cleanup_return;
                } else {
                    NumFilesOpen++;
                }
                WriteStaStatTable(ngrid, fpio,
                        RMS_Max, NRdgs_Min, Gap_Max,
                        P_ResidualMax, S_ResidualMax, Ell_Len3_Max, Hypo_Depth_Min, Hypo_Depth_Max, Hypo_Dist_Max, WRITE_RES_DELAYS);
                fclose(fpio);
                // save to last
                sprintf(sys_command, "cp %s %slast.stat_totcorr", fname, f_outpath);
                system(sys_command);
            }
        }
    }

    /* write station list */
    if (!iSaveNone) {
        for (ngrid = 0; ngrid < NumLocGrids; ngrid++)
            if (LocGridSave[ngrid]) {
                sprintf(fname, "%s.sum.grid%d.loc.stations", fn_path_output, ngrid);
                if ((fpio = fopen(fname, "w")) == NULL) {
                    nll_puterr2(
                            "ERROR: opening cumulative phase statistics output file", fname);
                    return_value = EXIT_ERROR_FILEIO;
                    goto cleanup_return;
                } else {
                    NumFilesOpen++;
                }
                WriteStationList(fpio, StationList, NumStations);
                fclose(fpio);
                // save to last
                sprintf(sys_command, "cp %s %slast.stations", fname, f_outpath);
                system(sys_command);
            }
    }


    // clean up before leaving NLLoc function
cleanup_return:

    //  20141219 AJL - bug? fix, moved here from inside events/obs loop!
    NLL_FreeGridMemory();

    if (!iSaveNone)
        CloseSummaryFiles();

    if (fp_model_grid_P != NULL) {
        CloseGrid3dFile(&fp_model_grid_P, &fp_model_hdr_P);
    }
    if (fp_model_grid_S != NULL) {
        CloseGrid3dFile(&fp_model_grid_S, &fp_model_hdr_S);
    }

    // AEH/AJL 20080709
    if (Arrival != NULL) {
        free(Arrival);
        Arrival = NULL;
    }

    // AJL 20101110 - Bug fix for function version
    for (ngrid = 0; ngrid < NumLocGrids; ngrid++) {
        // 20100607 AJL added to prevent valgrind error of not-freed blocks
        FreeStaStatTable(ngrid);
    }

    // AJL 20100929 - Bug fix for function version
    // free any allocated surface data
    if (topo_surface_index >= 0) {
        free_surface(topo_surface);
    }
    for (n = 0; n < NumTimeDelaySurface; n++) {
        free_surface(model_surface + n);
    }


    if (bp_memory_stream != NULL) {
        free(bp_memory_stream);
        bp_memory_stream = NULL;
    }


    return (return_value);

}
Exemple #11
0
int Init(lua_State *L)
{
	if(g_Curl.empty())
	{
		curl_global_init(CURL_GLOBAL_ALL);
	}

	g_Curl[L] = std::vector<CThreadedCurl *>();


	Lua()->SetGlobal("Curly", Curly::__new);

	CAutoUnRef meta = Lua()->GetMetaTable(MT_CURLY, TYPE_CURLY);
	{
		CAutoUnRef __index = Lua()->GetNewTable();

		__index->SetMember("Perform", Curly::Perform);
		__index->SetMember("SetCallback", Curly::SetCallback);
		__index->SetMember("SetBinaryMode", Curly::SetBinaryMode);
		__index->SetMember("SetCookies", Curly::SetCookies);
		__index->SetMember("SetOptNumber", Curly::SetOptNumber);
		__index->SetMember("SetPassword", Curly::SetPassword);
		__index->SetMember("SetPostFields", Curly::SetPostFields);
		__index->SetMember("SetUrl", Curly::SetUrl);
		__index->SetMember("SetUsername", Curly::SetUsername);

		meta->SetMember("__index", __index);
	}
	meta->SetMember("__gc", Curly::__delete);


	CAutoUnRef metaBinRead = Lua()->GetMetaTable(MT_BINREAD, TYPE_BINREAD);
	{
		CAutoUnRef __index = Lua()->GetNewTable();

		__index->SetMember("GetReadPosition", BinRead::GetReadPosition);
		__index->SetMember("GetSize", BinRead::GetSize);
		__index->SetMember("PeekByte", BinRead::PeekByte);
		__index->SetMember("ReadByte", BinRead::ReadByte);
		__index->SetMember("ReadDouble", BinRead::ReadDouble);
		__index->SetMember("ReadInt", BinRead::ReadInt);
		__index->SetMember("Rewind", BinRead::Rewind);
		__index->SetMember("ReadFloat", BinRead::ReadFloat);
		__index->SetMember("ReadString", BinRead::ReadString);

		metaBinRead->SetMember("__index", __index);
	}
	metaBinRead->SetMember("__gc", BinRead::__delete);


	CAutoUnRef hookSystem = Lua()->GetGlobal("hook");
	CAutoUnRef hookAdd = hookSystem->GetMember("Add");
	
	hookAdd->Push();
	Lua()->Push("Think");
	Lua()->Push("__CURLY_CALLBACKHOOK__");
	Lua()->Push(Curly::STATIC_CallbackHook);

	Lua()->Call(3, 0);

	SetConstants(L);

	return 0;
}
Exemple #12
0
main(int argc, char *argv[])
{

	int istat, narg;
	char fngrid_control[MAXLINE], fn_input[MAXLINE], fn_outroot[MAXLINE];
	FILE *fp_grid_control, *fp_outroot, *fp_gmt;
	char filename[MAXLINE], fn_xy_out[MAXLINE];


	// set program name

	strcpy(prog_name, PNAME);


	// check command line for correct usage

	fprintf(stdout, "\n%s Arguments: ", prog_name);
	for (narg = 0; narg < argc; narg++)
		fprintf(stdout, "<%s> ", argv[narg]);
	fprintf(stdout, "\n");

	if (argc != 4)
	{
		puterr("ERROR wrong number of command line arguments.");
		disp_usage(PNAME, 
		    "<controlfile> <punfile> <outroot>");
		exit(-1);
	}


	// read command line arguments

	strcpy(fngrid_control, argv[1]);
	strcpy(fn_input, argv[2]);
	strcpy(fn_outroot, argv[3]);



	// set constants

	SetConstants();


	// read control file

	if ((fp_grid_control = fopen(fngrid_control, "r")) == NULL) {
		puterr("ERROR opening control file.");
		exit(EXIT_ERROR_FILEIO);
	}


	if ((istat = ReadPun2GMT_Input(fp_grid_control)) < 0) {
		puterr("ERROR reading control file.");
		exit(EXIT_ERROR_FILEIO);
	}


	// open GMT command file

	sprintf(filename, "%s.gmt", fn_outroot);
	if ((fp_gmt = fopen(filename, "w")) == NULL) {
		puterr("ERROR opening output GMT script file.");
		exit(EXIT_ERROR_FILEIO);
	}


	// convert .pun to xy

	ConvertPun2GMT(fn_input, "XZ", fn_outroot, fn_xy_out);
	fprintf(fp_gmt, 
		"psxy %s $JVAL $RVAL -W1/0/0/0 -M -K -O >> %s.ps\n\n",
		fn_xy_out, "${POSTSCRIPT_NAME}");
	ConvertPun2GMT(fn_input, "XY", fn_outroot, fn_xy_out);
	fprintf(fp_gmt, 
		"psxy %s $JVAL $RVAL -W1/0/0/0 -M -K -O >> %s.ps\n\n",
		fn_xy_out, "${POSTSCRIPT_NAME}");
	ConvertPun2GMT(fn_input, "ZY", fn_outroot, fn_xy_out);
	fprintf(fp_gmt, 
		"psxy %s $JVAL $RVAL -W1/0/0/0 -M -K -O >> %s.ps\n\n",
		fn_xy_out, "${POSTSCRIPT_NAME}");


	exit(0);

}
Exemple #13
0
int main (int argc, char **argv)
{
	int n;
	float reftime;
	int projection;

	Vect3D pexpect;
	Ellipsoid3D pellipsoid;

	int npts_ellipse;
	Vect3D axis1, axis2, axis3;
	Vect3D *ellArray12, *ellArray13, *ellArray23;

	Vect2D* ellipse_array;

	if ( argc < 4) {
		fprintf(stderr, "Usage: %s statfile time projection (12|13|32)\n", argv[0]);
		exit(1);
	}
	sscanf(argv[2], "%f", &reftime);
	sscanf(argv[3], "%d", &projection);
	if (projection!=12 && projection!=13 && projection!=32) {
		fprintf(stderr, "Invalid projection: %d\n", projection);
		exit(1);
	}


	SetConstants();
	SetGraphicConstants();

	readStatFile(argv[1], reftime, &pexpect, &pellipsoid);

	initEllipsiodAxes(&pellipsoid, &axis1, &axis2, &axis3);

#ifdef DEBUG
fprintf(stderr, "%f %f %f\n", 
		pexpect.x, pexpect.y, pexpect.z);
fprintf(stderr, "%f %f %f\n%f %f %f\n%f\n", 
		pellipsoid.az1, pellipsoid.dip1, pellipsoid.len1,
		pellipsoid.az2, pellipsoid.dip2, pellipsoid.len2,
		pellipsoid.len3);
fprintf(stderr, "%f %f %f\n", axis1.x, axis1.y, axis1.z);
fprintf(stderr, "%f %f %f\n", axis2.x, axis2.y, axis2.z);
fprintf(stderr, "%f %f %f\n", axis3.x, axis3.y, axis3.z);
#endif



	npts_ellipse = NPTS_ELLIPSE;
	ellipse_array = 
		(Vect2D *) malloc((size_t) npts_ellipse * sizeof(Vect2D));
	
	ellArray12 = toEllipsoid3D(axis1, axis2, pexpect, npts_ellipse);
	ellipse_array = Vect3D2To2D(
				ellArray12, ellipse_array, npts_ellipse, projection);
	for (n=0; n<npts_ellipse; n++) {
		//fprintf(stderr, "%f %f %f\n", ellArray12[n].x, ellArray12[n].y, ellArray12[n].z);
		printf("%f %f\n", ellipse_array[n].x, ellipse_array[n].y);
	}
#ifdef GNUPLOT
	printf("\n");
#else
	printf(">\n");
#endif

	ellArray13 = toEllipsoid3D(axis1, axis3, pexpect, npts_ellipse);
	ellipse_array = Vect3D2To2D(
				ellArray13, ellipse_array, npts_ellipse, projection);
	for (n=0; n<npts_ellipse; n++) {
		//fprintf(stderr, "%f %f %f\n", ellArray13[n].x, ellArray13[n].y, ellArray13[n].z);
		printf("%f %f\n", ellipse_array[n].x, ellipse_array[n].y);
	}
#ifdef GNUPLOT
	printf("\n");
#else
	printf(">\n");
#endif

	ellArray23 = toEllipsoid3D(axis2, axis3, pexpect, npts_ellipse);
	ellipse_array = Vect3D2To2D(
				ellArray23, ellipse_array, npts_ellipse, projection);
	for (n=0; n<npts_ellipse; n++) {
		//fprintf(stderr, "%f %f %f\n", ellArray23[n].x, ellArray23[n].y, ellArray23[n].z);
		printf("%f %f\n", ellipse_array[n].x, ellipse_array[n].y);
	}
#ifdef GNUPLOT
	printf("\n");
#else
	printf(">\n");
#endif

	return 0;
}