예제 #1
0
void
toplevel_obj_free (obj_t *obj)
{
  switch (obj->type)
    {
    case TL_TYPE_DISP:
      disp_free (obj->cont.disp);
      break;
    case TL_TYPE_STACK:
      stack_free (obj->cont.stack);
      break;
    case TL_TYPE_STRATEGY:
      strategy_free (obj->cont.strategy);
      break;
    case TL_TYPE_SAMPLE:
      str_free (obj->cont.sample_info->spectrum_name);
      free (obj->cont.sample_info->constraints);
      free (obj->cont.sample_info->individual);
      free (obj->cont.sample_info);
      break;
    case TL_TYPE_MULTI_FIT:
      multi_fit_info_free (obj->cont.multi_fit);
    default:
      /* */ ;
    }
  free (obj);
}
예제 #2
0
static inline void Fb_unmap_video_memory(struct fb_info *info)
{
#ifndef FB_RESERVED_MEM
	unsigned map_size = PAGE_ALIGN(info->fix.smem_len);

	free_pages((unsigned long)info->screen_base,get_order(map_size));
#else
	disp_free((void *)info->screen_base, (void*)info->fix.smem_start, info->fix.smem_len);
#endif
}
예제 #3
0
static inline void Fb_unmap_video_memory(struct fb_info *info)
{
#ifndef CONFIG_FB_SUNXI_RESERVED_MEM
	unsigned map_size = PAGE_ALIGN(info->fix.smem_len);

	free_pages((unsigned long)info->screen_base, get_order(map_size));
#else
	disp_free((void __kernel __force *) info->screen_base);
#endif
}
예제 #4
0
long fx_disp_lookup_window::on_cmd_replace_comp(FXObject *, FXSelector, void *)
{
    const int i = selected_component;
    disp_lookup *lookup = &disp->disp.lookup;
    disp_t *new_disp = ui_choose_dispersion(this);
    if (!new_disp) return 1;
    disp_free(lookup->component[i].disp);
    lookup->component[i].disp = new_disp;
    FXTextField *tf = (FXTextField *) matrix->childAtRowCol(i + 1, 1);
    tf->setText(CSTR(new_disp->name));
    return 1;
}
예제 #5
0
int disp_mem_release(int sel)
{
#ifndef FB_RESERVED_MEM
	unsigned map_size = PAGE_ALIGN(g_disp_mm[sel].mem_len);
	unsigned page_size = map_size;

	if(g_disp_mm[sel].info_base == 0)
		return -EINVAL;

	free_pages((unsigned long)(g_disp_mm[sel].info_base),get_order(page_size));
	memset(&g_disp_mm[sel],0,sizeof(struct info_mm));
#else
	if(g_disp_mm[sel].info_base == 0)
		return -EINVAL;

    disp_free((void *)g_disp_mm[sel].info_base);
    memset(&g_disp_mm[sel],0,sizeof(struct info_mm));
#endif

	return 0;

}
예제 #6
0
disp_t *
disp_sample_table_new_from_mat_file(const char * filename, str_ptr *error_msg)
{
    FILE * f;
    str_t row;
    disp_t *disp = NULL;
    enum disp_type dtype;
    unsigned int wl_unit_conv = 0;
    int provide_diel_k = 0;

    f = fopen(filename, "r");

    if(f == NULL) {
        *error_msg = new_error_message(LOADING_FILE_ERROR, "File \"%s\" does not exists or cannot be opened", filename);
        return NULL;
    }

    str_t name;
    str_init(name, 64);
    str_init(row, 64);
    str_getline(name, f);
    str_getline(row, f);

    if(strncasecmp(CSTR(row), "CAUCHY", 6) == 0) {
        dtype = DISP_CAUCHY;
    } else if(strncasecmp(CSTR(row), "ev", 2) == 0) {
        wl_unit_conv |= WL_UNIT_CONVERT_EV;
    } else if(strncasecmp(CSTR(row), "ANGSTROMS", 9) == 0) {
        wl_unit_conv |= WL_UNIT_CONVERT_ANGSTROMS;
    } else if(strncasecmp(CSTR(row), "nm", 2) != 0) {
        *error_msg = new_error_message(LOADING_FILE_ERROR, "Invalide MAT file: \"%s\"", filename);
        goto close_exit;
    }

    str_getline(row, f);
    if(strncasecmp(CSTR(row), "nk", 2) == 0) {
        dtype = DISP_SAMPLE_TABLE;
    } else if(strncasecmp(CSTR(row), "e1e2", 4) == 0) {
        dtype = DISP_SAMPLE_TABLE;
        provide_diel_k = 1;
    } else {
        *error_msg = new_error_message(LOADING_FILE_ERROR, "Invalide MAT file: \"%s\"", filename);
        goto close_exit;
    }

    switch(dtype) {
    case DISP_SAMPLE_TABLE: {
        struct disp_sample_table *dt;
        long start_pos = ftell(f);
        int j, lines;

        disp = disp_new(DISP_SAMPLE_TABLE);
        str_copy(disp->name, name);
        dt = & disp->disp.sample_table;
        clear(dt);

        start_pos = ftell(f);

        for(lines = 0; ;) {
            float xd[3];
            int read_status = fscanf(f, "%f %f %f\n", xd, xd+1, xd+2);
            if(read_status == 3) {
                lines ++;
            }
            if(read_status == EOF) {
                break;
            }
        }

        if(lines < 2) {
            disp_free(disp);
            disp = NULL;
            break;
        }

        fseek(f, start_pos, SEEK_SET);

        init(dt, lines);

        double *wptr = wavelength_array(dt);
        double *nptr = n_array(dt);
        double *kptr = k_array(dt);
        for(j = 0; j < lines; j++, wptr++, nptr++, kptr++) {
            int read_status;
            do {
                read_status = fscanf(f, "%lf %lf %lf\n", wptr, nptr, kptr);
            } while(read_status < 3 && read_status != EOF);

            if(wl_unit_conv & WL_UNIT_CONVERT_EV) {
                *wptr = 1239.8 / *wptr;
            } else if(wl_unit_conv & WL_UNIT_CONVERT_ANGSTROMS) {
                *wptr /= 10.0;
            }

            if(provide_diel_k) {
                double e1 = *nptr, e2 = *kptr;
                double ne = sqrt(e1*e1 + e2*e2);
                *nptr = sqrt((ne + e1) / 2.0);
                *kptr = sqrt((ne - e1) / 2.0);
            }

            if(read_status == EOF) {
                break;
            }
        }
        prepare_interp(dt);
        break;
    }
    case DISP_CAUCHY:
        *error_msg = new_error_message(LOADING_FILE_ERROR, "cauchy MAT format is unsupported");
        break;
#if 0
        cn = disp->disp.cauchy.n;
        ck = disp->disp.cauchy.k;
        fscanf(f, "%lf %lf %lf %*f %*f %*f\n", cn, cn+1, cn+2);
        cn[1] *= 1e3;
        cn[2] *= 1e6;
        ck[0] = ck[1] = ck[2] = 0.0;
        break;
#endif
    default:
        *error_msg = new_error_message(LOADING_FILE_ERROR, "corrupted material card");
        break;
    }

close_exit:
    fclose(f);
    str_free(name);
    str_free(row);
    return disp;
}
예제 #7
0
disp_t *
disp_sample_table_new_from_mat_file (const char * filename)
{
  FILE * f;
  str_t row;
  disp_t *disp = NULL;
  enum disp_type dtype;
  int convert_ev = 0;
  int provide_diel_k = 0;

  f = fopen (filename, "r");

  if (f == NULL)
    {
      notify_error_msg (LOADING_FILE_ERROR, "Cannot open %s", filename);
      return NULL;
    }

  str_init (row, 64);

  str_getline (row, f);
  str_getline (row, f);

  if (strncasecmp (CSTR(row), "CAUCHY", 6) == 0)
    {
      dtype = DISP_CAUCHY;
    }
  else if (strncasecmp (CSTR(row), "ev", 2) == 0)
    {
      convert_ev = 1;
    }
  else if (strncasecmp (CSTR(row), "nm", 2) != 0)
    {
      notify_error_msg (LOADING_FILE_ERROR, "Invalide MAT format: %s",
			filename);
      goto close_exit;
    }

  str_getline (row, f);
  if (strncasecmp (CSTR(row), "nk", 2) == 0)
    {
      dtype = DISP_SAMPLE_TABLE;
    }
  else if (strncasecmp (CSTR(row), "e1e2", 4) == 0)
    {
      dtype = DISP_SAMPLE_TABLE;
      provide_diel_k = 1;
    }
  else
    {
      notify_error_msg (LOADING_FILE_ERROR, "Invalide MAT format: %s",
			filename);
      goto close_exit;
    }
    
  switch (dtype)
    {
    case DISP_SAMPLE_TABLE:
      {
	struct disp_sample_table *dt;
	struct data_table *table;
	long start_pos = ftell (f);
	int j, lines;

	disp = disp_new (DISP_SAMPLE_TABLE);
	dt = & disp->disp.sample_table;
	disp_sample_table_clear (dt);

	start_pos = ftell (f);

	for (lines = 0; ; )
	  {
	    float xd[3];
	    int read_status = fscanf (f, "%f %f %f\n", xd, xd+1, xd+2);
	    if (read_status == 3)
	      lines ++;
	    if (read_status == EOF)
	      break;
	  }

	if (lines < 2)
	  {
	    disp_free (disp);
	    disp = NULL;
	    break;
	  }

	fseek (f, start_pos, SEEK_SET);
	
	disp_sample_table_init (dt, lines);
	
	table = dt->table_ref;

	for (j = 0; j < lines; j++)
	  {
	    float *dptr = table->heap + 3 * j;
	    int read_status;
	    do
	      read_status = fscanf (f, "%f %f %f\n", dptr, dptr+1, dptr+2);
	    while (read_status < 3 && read_status != EOF);

	    if (convert_ev)
	      dptr[0] = 1239.8 / dptr[0];

	    if (provide_diel_k)
	      {
		double e1 = dptr[1], e2 = dptr[2];
		double ne = sqrt(e1*e1 + e2*e2);
		dptr[1] = sqrt((ne + e1) / 2.0);
		dptr[2] = sqrt((ne - e1) / 2.0);
	      }

	    if (read_status == EOF)
	      break;
	  }

	break;
      }	  
    case DISP_CAUCHY:
      notify_error_msg (LOADING_FILE_ERROR, "cauchy MAT files");
      break;
#if 0
      cn = disp->disp.cauchy.n;
      ck = disp->disp.cauchy.k;
      fscanf (f, "%lf %lf %lf %*f %*f %*f\n", cn, cn+1, cn+2);
      cn[1] *= 1e3;
      cn[2] *= 1e6;
      ck[0] = ck[1] = ck[2] = 0.0;
      break;
#endif
    default:
      notify_error_msg (LOADING_FILE_ERROR, "corrupted material card");
      break;
    }

 close_exit:
  fclose (f);
  str_free (row);
  return disp;
}