Example #1
0
int main(int argc, char **argv) {
  int length = 1024;
  double *x = malloc(length*sizeof(double));
  double *y = malloc(length*sizeof(double));
  double dy;

  if (argc < 2) {
    printf("Argument missing.\n");
    exit(-1);
  }

  dy = atof(argv[1]);

  if (dy <= 0.0) {
    printf("Argument invalid.\n");
    exit(-1);
  }

  int i;

  for (i = 0; i < length; ++i) {
    y[i] = (double)i*dy;
  }

  x[0] = 0;

  for (i = 1; i < length; ++i) {
    x[i] = find_minimum(x, y, i);
    printf("%f, %f\n", x[i], y[i]);
  }

  free(x);
  free(y);
}
Example #2
0
int main() {
	int i, j, s, sum=0;
	UNDIRECTED first=NULL, min;
	printf("Enter number of vertices\n");
	scanf("%d", &n);
	for(i=0;i<n;i++) {
		for(j=0;j<n;j++) {
			scanf("%d", &input[i][j]);
		}
	}
	printf("Enter source\n");
	scanf("%d", &s);
	reset_all();
	remove_element_array(vertex, &vindex, s);
	push_array(finished, &findex, s);
	while(findex<n-1) {
		for(i=0;i<=findex;i++) {
			for(j=0;j<=vindex;j++) {
				first=insert_ll(first, new_connection(finished[i], vertex[j]));
			
			}
		}
		min=find_minimum(first);
		push_array(finished, &findex, min->d);
		remove_element_array(vertex, &vindex, min->d);
		first=destroy_ll(first);
		sum+=distance(min->s, min->d);
		printf("%d->%d = %d\n", min->s, min->d, distance(min->s, min->d));
	}
	printf("Total distance = %d\n", sum);
	return 0;
}
Example #3
0
static t_btree_node	*find_minimum(t_btree_node *node)
{
	if (node->left == NULL)
		return (node);
	else
		return (find_minimum(node->left));
}
Example #4
0
extern void sort(ITEM* nodes,int n){
    int i;
    ITEM* aux1, aux2;
    for(i=0;i,n;i++){
        aux1 = find_minimum(nodes, n-i);
        aux2 = nodes[i];
        nodes++; 
        nodes = aux1;
    }
}
int main(int argc, char *argv[]) {
    tree *root = NULL;
    insert_tree(&root, 33/*, root*/);
    insert_tree(&root, 622/*, root*/);
    insert_tree(&root, 22/*, root*/);
    insert_tree(&root, 17/*, root*/);
    insert_tree(&root, 441/*, root*/);
    insert_tree(&root, 91/*, root*/);

    printf("Find minimum = %d\n", (find_minimum(root))->item );
    printf("Inorder Traversal of Tree:\n");
    traverse_tree(root);
}
Example #6
0
static t_btree_node	*successor(t_btree_node *node)
{
	t_btree_node	*it;

	if (node->right)
		return (find_minimum(node->right));
	it = node->parent;
	while (it && node != it->right)
	{
		node = it;
		it = it->parent;
	}
	return (it);
}
Example #7
0
void dynprog(int i0 /* starting velocity */,
	     float** weight /* [n1][n2] */)
/*< apply >*/
{
    float d, c, w, w2;
    int i1, i2, i, ic, ib, ie, it;
    
    if (NULL != ttime) {
	for (i2=0; i2 < n2; i2++) {
	    w = 0.5*(weight[0][i2]+weight[0][i0]);
	    ttime[0][i2] = SF_ABS(i2-i0)*w;
	}
    }
    
    for (i2=0; i2 < n2; i2++) {
	w = 0.5*(weight[1][i2]+weight[0][i0]);
	prev[i2] = dist[SF_ABS(i2-i0)]*w;
	what[1][i2] = i0;

	if (NULL != ttime) ttime[1][i2]=prev[i2];
    }

    for (i1=2; i1 < n1; i1++) {
	for (i2=0; i2 < n2; i2++) {
	    w = weight[i1][i2];
	    ib = SF_MAX(i2-gt,-1);
	    ie = SF_MIN(i2+gt,n2);
	    c = FLT_MAX;
	    ic = -1;
	    for (i=ib+1; i < ie; i++) {
		w2 = 0.5*(w+weight[i1-1][i]);
		d = dist[SF_ABS(i2-i)]*w2+prev[i];
		it = i-ib-1;
		if (d < c) {
		    c =	d;
		    ic = it;
		}
		prob[it]=d;
	    }

	    next[i2]=find_minimum(ic,ie-ib-1,ib+1,c,&what[i1][i2]);
	}
	for (i2=0; i2 < n2; i2++) {
	    prev[i2]=next[i2];
	    if (NULL != ttime) ttime[i1][i2]=prev[i2];
	}
    }
}
Example #8
0
int main (int argc, char const *argv[]) {
  tree root;
  int node_1_data = 1;
  int node_2_data = 2;
  
  root.data = 0;
  
  // Adding stuff
  add_to_tree(&root, node_1_data);
  add_to_tree(&root, node_2_data);
  
  // Search
  int find_data = 2;
  tree *result;
  result = find(&root, find_data);    
  
  // Finding min
  tree *min;
  min = find_minimum(&root);
  
  return 0;
}
Example #9
0
/*-------------------------------------------------------------------------------------------*/
int cross_correlation(struct Map_info *Map, double passWE, double passNS)
    /*
       Map: Vector map from which cross-crorrelation will take values
       passWE: spline step in West-East direction
       passNS: spline step in North-South direction

       RETURN:
       TRUE on success
       FALSE on failure
     */
{
    int bilin = TRUE;		/*booleans */
    int nsplx, nsply, nparam_spl, ndata;
    double *mean, *rms, *stdev;

    /* double lambda[PARAM_LAMBDA] = { 0.0001, 0.001, 0.01, 0.1, 1.0, 10.0 }; */	/* Fixed values (by the moment) */
    double lambda[PARAM_LAMBDA] = { 0.0001, 0.001, 0.005, 0.01, 0.02, 0.05 };	/* Fixed values (by the moment) */
    /* a more exhaustive search:
    #define PARAM_LAMBDA 11
    double lambda[PARAM_LAMBDA] = { 0.0001, 0.0005, 0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1.0, 5.0, 10.0 }; */

    double *TN, *Q, *parVect;	/* Interpolation and least-square vectors */
    double **N, **obsVect;	/* Interpolation and least-square matrix */

    struct Point *observ;
    struct Stats stat_vect;

    /*struct line_pnts *points; */
    /*struct line_cats *Cats; */
    struct Cell_head region;

    G_get_window(&region);

    extern int bspline_field;
    extern char *bspline_column;
    dbCatValArray cvarr;

    G_debug(5,
	    "CrossCorrelation: Some tests using different lambda_i values will be done");

    ndata = Vect_get_num_lines(Map);

    if (ndata > NDATA_MAX)
	G_warning(_("%d are too many points. "
		    "The cross validation would take too much time."), ndata);

    /*points = Vect_new_line_struct (); */
    /*Cats = Vect_new_cats_struct (); */

    /* Current region is read and points recorded into observ */
    observ = P_Read_Vector_Region_Map(Map, &region, &ndata, 1024, 1);
    G_debug(5, "CrossCorrelation: %d points read in region. ", ndata);
    G_verbose_message(_("%d points read in region"),
		      ndata);

    if (ndata > 50)
	G_warning(_("Maybe it takes too long. "
		    "It will depend on how many points you are considering."));
    else
	G_debug(5, "CrossCorrelation: It shouldn't take too long.");

    if (ndata > 0) {		/* If at least one point is in the region */
	int i, j, lbd;		/* lbd: lambda index */
	int BW;	
	double mean_reg, *obs_mean;

	int nrec, ctype = 0, verbosity;
	struct field_info *Fi;
	dbDriver *driver_cats;

	mean = G_alloc_vector(PARAM_LAMBDA);	/* Alloc as much mean, rms and stdev values as the total */
	rms = G_alloc_vector(PARAM_LAMBDA);	/* number of parameter used used for cross validation */
	stdev = G_alloc_vector(PARAM_LAMBDA);

	verbosity = G_verbose(); /* store for later reset */

	/* Working with attributes */
	if (bspline_field > 0) {
	    db_CatValArray_init(&cvarr);

	    Fi = Vect_get_field(Map, bspline_field);
	    if (Fi == NULL)
	      G_fatal_error(_("Database connection not defined for layer %d"),
			    bspline_field);

	    driver_cats =
		db_start_driver_open_database(Fi->driver, Fi->database);
	    G_debug(1, _("CrossCorrelation: driver=%s db=%s"), Fi->driver,
		    Fi->database);

	    if (driver_cats == NULL)
		G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
			      Fi->database, Fi->driver);

	    nrec =
		db_select_CatValArray(driver_cats, Fi->table, Fi->key,
				      bspline_column, NULL, &cvarr);
	    G_debug(3, "nrec = %d", nrec);

	    ctype = cvarr.ctype;
	    if (ctype != DB_C_TYPE_INT && ctype != DB_C_TYPE_DOUBLE)
		G_fatal_error(_("Column type not supported"));

	    if (nrec < 0)
		G_fatal_error(_("No records selected from table <%s> "),
			      Fi->table);

	    G_debug(1, "%d records selected from table",
		    nrec);

	    db_close_database_shutdown_driver(driver_cats);
	}

	/* Setting number of splines as a function of WE and SN spline steps */
	nsplx = ceil((region.east - region.west) / passWE);
	nsply = ceil((region.north - region.south) / passNS);
	nparam_spl = nsplx * nsply;	/* Total number of splines */

	if (nparam_spl > 22900)
	    G_fatal_error(_("Too many splines (%d x %d). "
			    "Consider changing spline steps \"ew_step=\" \"ns_step=\"."),
			  nsplx, nsply);

	BW = P_get_BandWidth(bilin, nsply);
	/**/
	/*Least Squares system */
	N = G_alloc_matrix(nparam_spl, BW);	/* Normal matrix */
	TN = G_alloc_vector(nparam_spl);	/* vector */
	parVect = G_alloc_vector(nparam_spl);	/* Parameters vector */
	obsVect = G_alloc_matrix(ndata, 3);	/* Observation vector */
	Q = G_alloc_vector(ndata);		/* "a priori" var-cov matrix */

	obs_mean = G_alloc_vector(ndata);
	stat_vect = alloc_Stats(ndata);

	for (lbd = 0; lbd < PARAM_LAMBDA; lbd++) {	/* For each lambda value */

	    G_message(_("Beginning cross validation with "
		        "lambda_i=%.4f ... (%d of %d)"), lambda[lbd],
		      lbd+1, PARAM_LAMBDA);

	    /*
	       How the cross correlation algorithm is done:
	       For each cycle, only the first ndata-1 "observ" elements are considered for the 
	       interpolation. Within every interpolation mean is calculated to lowering edge 
	       errors. The point left out will be used for an estimation. The error between the 
	       estimation and the observation is recorded for further statistics.
	       At the end of the cycle, the last point, that is, the ndata-1 index, and the point 
	       with j index are swapped.
	     */
	    for (j = 0; j < ndata; j++) {	/* Cross Correlation will use all ndata points */
		double out_x, out_y, out_z;	/* This point is left out */

		for (i = 0; i < ndata; i++) {	/* Each time, only the first ndata-1 points */
		    double dval;		/* are considered in the interpolation */

		    /* Setting obsVect vector & Q matrix */
		    Q[i] = 1;	/* Q=I */
		    obsVect[i][0] = observ[i].coordX;
		    obsVect[i][1] = observ[i].coordY;

		    if (bspline_field > 0) {
			int cat, ival, ret;

			/*type = Vect_read_line (Map, points, Cats, observ[i].lineID); */
			/*if ( !(type & GV_POINTS ) ) continue; */

			/*Vect_cat_get ( Cats, bspline_field, &cat ); */
			cat = observ[i].cat;

			if (cat < 0)
			    continue;

			if (ctype == DB_C_TYPE_INT) {
			    ret =
				db_CatValArray_get_value_int(&cvarr, cat,
							     &ival);
			    obsVect[i][2] = ival;
			    obs_mean[i] = ival;
			}
			else {	/* DB_C_TYPE_DOUBLE */
			    ret =
				db_CatValArray_get_value_double(&cvarr, cat,
								&dval);
			    obsVect[i][2] = dval;
			    obs_mean[i] = dval;
			}
			if (ret != DB_OK) {
			    G_warning(_("No record for point (cat = %d)"),
				      cat);
			    continue;
			}
		    }
		    else {
			obsVect[i][2] = observ[i].coordZ;
			obs_mean[i] = observ[i].coordZ;
		    }
		}		/* i index */

		/* Mean calculation for every point less the last one */
		mean_reg = calc_mean(obs_mean, ndata - 1);

		for (i = 0; i < ndata; i++)
		    obsVect[i][2] -= mean_reg;

		/* This is left out */
		out_x = observ[ndata - 1].coordX;
		out_y = observ[ndata - 1].coordY;
		out_z = obsVect[ndata - 1][2];

		if (bilin) {	/* Bilinear interpolation */
		    normalDefBilin(N, TN, Q, obsVect, passWE, passNS, nsplx,
				   nsply, region.west, region.south,
				   ndata - 1, nparam_spl, BW);
		    nCorrectGrad(N, lambda[lbd], nsplx, nsply, passWE,
				 passNS);
		}
		else {		/* Bicubic interpolation */
		    normalDefBicubic(N, TN, Q, obsVect, passWE, passNS, nsplx,
				     nsply, region.west, region.south,
				     ndata - 1, nparam_spl, BW);
		    nCorrectGrad(N, lambda[lbd], nsplx, nsply, passWE,
				 passNS);
		}

		/* 
		   if (bilin) interpolation (&interp, P_BILINEAR);
		   else interpolation (&interp, P_BICUBIC);
		 */
		G_set_verbose(G_verbose_min());
		G_math_solver_cholesky_sband(N, parVect, TN, nparam_spl, BW);
		G_set_verbose(verbosity);

		/* Estimation of j-point */
		if (bilin)
		    stat_vect.estima[j] =
			dataInterpolateBilin(out_x, out_y, passWE, passNS,
					     nsplx, nsply, region.west,
					     region.south, parVect);

		else
		    stat_vect.estima[j] =
			dataInterpolateBilin(out_x, out_y, passWE, passNS,
					     nsplx, nsply, region.west,
					     region.south, parVect);

		/* Difference between estimated and observated i-point */
		stat_vect.error[j] = out_z - stat_vect.estima[j];
		G_debug(1, "CrossCorrelation: stat_vect.error[%d]  =  %lf", j,
			stat_vect.error[j]);

		/* Once the last value is left out, it is swapped with j-value */
		observ = swap(observ, j, ndata - 1);

		G_percent(j, ndata, 2);
	    }

	    mean[lbd] = calc_mean(stat_vect.error, stat_vect.n_points);
	    rms[lbd] =
		calc_root_mean_square(stat_vect.error, stat_vect.n_points);
	    stdev[lbd] =
		calc_standard_deviation(stat_vect.error, stat_vect.n_points);

	    G_message(_("Mean = %.5lf"), mean[lbd]);
	    G_message(_("Root Mean Square (RMS) = %.5lf"),
		      rms[lbd]);
	    G_message("---");
	}			/* ENDFOR each lambda value */

	G_free_matrix(N);
	G_free_vector(TN);
	G_free_vector(Q);
	G_free_matrix(obsVect);
	G_free_vector(parVect);
#ifdef nodef
	/*TODO: if the minimum lambda is wanted, the function declaration must be changed */
	/* At this moment, consider rms only */
	rms_min = find_minimum(rms, &lbd_min);
	stdev_min = find_minimum(stdev, &lbd_min);

	/* Writing some output */
	G_message(_("Different number of splines and lambda_i values have "
		    "been taken for the cross correlation"));
	G_message(_("The minimum value for the test (rms=%lf) was "
		    "obtained with: lambda_i = %.3f"),
		  rms_min,
		  lambda[lbd_min]);

	*lambda_min = lambda[lbd_min];
#endif

	G_message(_("Table of results:"));
	fprintf(stdout, _("    lambda |       mean |        rms |\n"));
	for (lbd = 0; lbd < PARAM_LAMBDA; lbd++) {
	    fprintf(stdout, " %9.5f | %10.4f | %10.4f |\n", lambda[lbd],
		    mean[lbd], rms[lbd]);
	}
	
	G_free_vector(mean);
	G_free_vector(rms);
    }				/* ENDIF (ndata > 0) */
    else
	G_warning(_("No point lies into the current region"));

    G_free(observ);
    return TRUE;
}
Example #10
0
int main(int argc, char** argv) {

    int size,aux;
    int estadoHeap;
    HEAP* h;
    h = (HEAP*)malloc(sizeof(HEAP));
    printf("arguments: %d\n",argc);
    
    //LEO ENTRADA
    FILE* inFile = fopen(argv[1],"r" );
    fscanf(inFile,"%d\n", &size);
    
    printf("size= %d\n",size);
    
    int entrada[size];
    int i;
    for(i=0;i<size;i++){
        fscanf(inFile,"%d\n",&aux);
        entrada[i] = aux;
    }
    
    #ifndef PR
    //IMPRIMO ENTRADA
    printf("Entrada\n");
    for(i=0;i<size;i++)
        printf("%d\n",entrada[i]);
    #endif
    
    //GUARDO ENTRADA EN ARRAY DE ITEMS
    ITEM datos[size];
    for(i=0;i<size;i++){
        datos[i].value=entrada[i];
    }
   
    ITEM* min;
    min = find_minimum(datos,size);
    #ifndef PR
    printf("Min = %d\n", min->value);
    #endif

    //INICIALIZO HEAP
    heap_init(h,size);
    
    //CHEQUEO ESTADO HEAP
    estadoHeap = heap_isEmpty(h);
    #ifndef PR
    printf("HEAP VACIO: %d\n", estadoHeap);
    #endif
    
    //LLENO HEAP
    build_heap_lin(h,datos,size);
    //build_heap(h,datos,size);   

    #ifndef PR
    //VUELVO A CHEQUEAR ESTADO HEAP
    estadoHeap = heap_isEmpty(h);
    printf("HEAP VACIO: %d\n", estadoHeap);
    
    estadoHeap = heap_isFull(h);
    printf("HEAP LLENO: %d\n", estadoHeap);
    #endif
    
    //IMPRIMO HEAP LLENO
    #ifndef PR
    printHeap(h);
    printf("\nIndice: %d\n",(int)h->index);
    #endif

    while(h->index>=0){
      //SACO DEL HEAP EL ITEM MAS CHICO
      ITEM* a; 
      a = heap_extractMin(h);
    
      #ifndef PR
      //IMPRIMO EL VALOR DEL ITEM QUE SAQUE
      printf("\nVALOR: %d\n",a->value);
      
      //IMPRIMO HEAP
      printHeap(h);
      printf("\nIndice: %d\n",(int)h->index);
      //VUELVO A CHEQUEAR ESTADO
      estadoHeap = heap_isEmpty(h);
      printf("HEAP VACIO: %d\n", estadoHeap);
    
      estadoHeap = heap_isFull(h);
      printf("HEAP LLENO: %d\n", estadoHeap);
      #endif
    }
    
    heap_delete(h);
    
}
Example #11
0
double *call_map_model(double la,double lo,double lambda0, double phi0,int brightness_model,double *brightness_params,double **bb_g,int make_grid,double theta1, double theta2, double r1, double r2, double star_bright,double la_cen,double lo_cen, double *lo_2d, double *la_2d, double **T_2d, double **y1_grid, double **y2_grid, double **y12_grid){
    double point_T,mu,p_t_bright,point_b;
    double l1,l2;
    double *output;

    double R = 1.0;
    int n_bb_seg = 10;

    point_T = 0.0;
    point_b = 0.0;

//    printf("bb_g %f\n",bb_g[0][1]);

    if(brightness_model == 1 || brightness_model == 3 || brightness_model == 4 || brightness_model == 6|| brightness_model == 8|| brightness_model == 10|| brightness_model == 11|| brightness_model == 12) {
        l1 = brightness_params[1];
        l2 = brightness_params[2];
    }
    if(brightness_model == 0){
        point_b = Uniform_b(brightness_params[0]);
    }
    else if(brightness_model == 1){
        point_T = Uniform_T(brightness_params[3]);
        point_b = bb_interp(point_T, bb_g);
    }

//    if(brightness_model == 2){
//        double p_day = brightness_params[0];
//        double p_night = brightness_params[1];
//        point_b = Two_b(la,lo,p_day,p_night);
//    }
//    if(brightness_model == 3){
//        double p_day = brightness_params[3];
//        double p_night = brightness_params[4];
//        double point_T = p_night;
//        point_T = Two_T(la,lo,p_day,p_night);
//        point_b = bb_interp(point_T, bb_g);
//    }

    else if(brightness_model == 4){
        double xi =brightness_params[3];
        double T_n =brightness_params[4];
        double delta_T =brightness_params[5];
        point_T = zhang_2016(la,lo,xi,T_n,delta_T);
        point_b = bb_interp(point_T, bb_g);
    }
    else if(brightness_model == 5){

        point_b = spherical(la,lo,brightness_params,0);
    }

    else if(brightness_model == 14){

        point_T = spherical(la,lo,brightness_params,1);
        point_b = bb_interp(point_T, bb_g); 
    }

    else if(brightness_model == 6){
       double insol = brightness_params[3];
       double albedo = brightness_params[4];
       double redist = brightness_params[5];
       point_T = kreidberg_2016(la, lo, insol, albedo, redist);
       point_b = bb_interp(point_T, bb_g); 
    }

    else if(brightness_model == 2 || brightness_model == 7){
        double la0 = brightness_params[0];
        double lo0 = brightness_params[1];
        double p_b = brightness_params[2];
        double spot_b = brightness_params[4];
        double size = brightness_params[5];
//        printf("%f %f %f %f %f\n",la0,lo0,p_b,spot_b,size);
        point_b = Hotspot_b(la, lo, la0,lo0,p_b,spot_b,size,make_grid ,theta1,theta2,r1,r2,lambda0,phi0,la_cen,lo_cen);
     }

    else if(brightness_model == 3 || brightness_model == 8){
        double la0 = brightness_params[4];
        double lo0 = brightness_params[5];
        double p_T = brightness_params[6];
        double spot_T = brightness_params[7];
        double size = brightness_params[8];
        double b1 = bb_interp(p_T, bb_g); 
        double b2 = bb_interp(spot_T, bb_g); 
        point_T = Hotspot_b(la, lo, la0,lo0,p_T,spot_T,size,make_grid ,theta1,theta2,r1,r2,lambda0,phi0,la_cen,lo_cen);
        point_b = Hotspot_b(la, lo, la0,lo0,b1,b2,size,make_grid ,theta1,theta2,r1,r2,lambda0,phi0,la_cen,lo_cen);
    }
    else if(brightness_model == 9){
        double albedo = brightness_params[3];
        double ars = pow(brightness_params[4],2);
        double insol = ars*star_bright;
//        printf("%f \n",insol*M_PI);
        point_b = lambertian(la,lo,insol,albedo);
    }
    else if(brightness_model == 10){
        double xi =brightness_params[3];
        double T_n =brightness_params[4];
        double delta_T =brightness_params[5];
        point_T = zhang_2016(la,lo,xi,T_n,delta_T);
        point_b = bb_interp(point_T, bb_g);

        double albedo = brightness_params[6];
        double ars = pow(brightness_params[7],2);
        double insol = ars*star_bright;
        point_b = point_b + lambertian(la,lo,insol,albedo);
    }

    else if(brightness_model == 11){
        double xi =brightness_params[3];
        double T_n =brightness_params[4];
        double delta_T =brightness_params[5];
        double clouds = brightness_params[6];

        point_T = zhang_2016(la,lo,xi,T_n,delta_T);

        point_b = bb_interp(point_T, bb_g);

        if(pow(lo,2) > pow(M_PI/2.0,2)){
            point_b = point_b - clouds;
        }
    }

    else if(brightness_model == 12 || brightness_model == 13){

/*        printf("\n");
        printf("%f\n",lo*180.0/M_PI);
        printf("%i\n",find_minimum(lo_2d, lo*180.0/M_PI, (int) brightness_params[3]));
        printf("%f\n",lo_2d[find_minimum(lo_2d, lo*180.0/M_PI, (int) brightness_params[3])]);
        printf("\n");*/

        int *out1;
        out1 = malloc(sizeof(int) * 2);

        int *out2;
        out2 = malloc(sizeof(int) * 2);

        int nlo, nla, nearest;

        if(brightness_model == 12){
            nlo = brightness_params[3];
            nla = brightness_params[4];
            nearest = brightness_params[5];
        }
        if(brightness_model == 13){
            nlo = brightness_params[0];
            nla = brightness_params[1];
            nearest = brightness_params[2];
        }

        find_top_two(lo_2d, lo*180.0/M_PI, (int) nlo, out1);

//        printf("before second %i\n",(int) brightness_params[4]);
        find_top_two(la_2d, la*180.0/M_PI, (int) nla, out2);

//        printf("positions %i %i %i %i %i %i\n",out1[0],out1[1],out2[0],out2[1],nlo,nla);
//        printf("positions %f %f %f %f\n",lo_2d[out1[0]],lo_2d[out1[1]],la_2d[out2[0]],la_2d[out2[1]]);

        float *ansy, *ansy1, *ansy2;

        ansy = malloc(sizeof(float) * 1);
        ansy1 = malloc(sizeof(float) * 1);
        ansy2 = malloc(sizeof(float) * 1);

        float *y,*y1,*y2,*y12;
        y = malloc(sizeof(float) * 5);
        y1 = malloc(sizeof(float) * 5);
        y2 = malloc(sizeof(float) * 5);
        y12 = malloc(sizeof(float) * 5);

        y[1] = T_2d[out1[0]][out2[0]];
        y[2] = T_2d[out1[1]][out2[0]];
        y[3] = T_2d[out1[1]][out2[1]];
        y[4] = T_2d[out1[0]][out2[1]];

        y1[1] = y1_grid[out1[0]][out2[0]];
        y1[2] = y1_grid[out1[1]][out2[0]];
        y1[3] = y1_grid[out1[1]][out2[1]];
        y1[4] = y1_grid[out1[0]][out2[1]];

        y2[1] = y2_grid[out1[0]][out2[0]];
        y2[2] = y2_grid[out1[1]][out2[0]];
        y2[3] = y2_grid[out1[1]][out2[1]];
        y2[4] = y2_grid[out1[0]][out2[1]];

        y12[1] = y12_grid[out1[0]][out2[0]];
        y12[2] = y12_grid[out1[1]][out2[0]];
        y12[3] = y12_grid[out1[1]][out2[1]];
        y12[4] = y12_grid[out1[0]][out2[1]];


//        printf("%f %f %f %f %f %f\n",lo_2d[out1[0]],lo_2d[out1[1]], la_2d[out2[0]], la_2d[out2[1]], lo*180.0/M_PI, la*180.0/M_PI);
        bcuint(y, y1, y2, y12, lo_2d[out1[0]],lo_2d[out1[1]], la_2d[out2[0]], la_2d[out2[1]], lo*180.0/M_PI, la*180.0/M_PI, ansy, ansy1, ansy2);

        if (nearest == 1) {
            int c_lo = find_minimum(lo_2d, lo*180.0/M_PI, (int) nlo);
            int c_la = find_minimum(la_2d, la*180.0/M_PI, (int) nla);
            *ansy = T_2d[c_lo][c_la];
        }

        if(brightness_model == 12){
            point_T = *ansy;
            point_b = bb_interp(point_T, bb_g);
        }
        if(brightness_model == 13){
            point_b = *ansy;
        }

        free(out1);
        free(out2);

        free(y);
        free(y1);
        free(y2);
        free(y12);

        free(ansy);
        free(ansy1);
        free(ansy2);

        }
    else{
        printf("BRIGHTNESS MODEL NOT RECOGNISED\n");
    }

//        printf("%f %f %f\n",ars, star_bright,insol);
    output = malloc(sizeof(double) * 2); // dynamic `array (size 2) of pointers to double`

    output[0] = point_b;
    output[1] = point_T;

    return output;

}
Example #12
0
inline T find_minimum( const T a, const T b, const T c )
{
    T ab = find_minimum( a, b );
    return find_minimum( ab, c );
}