/*----------------------------------------------------------------------*/ extern int ls_main(int argc, char **argv) { struct dnode **dnf, **dnd; int dnfiles, dndirs; struct dnode *dn, *cur, **dnp; int i, nfiles; int opt; int oi, ac; char **av; #ifdef BB_FEATURE_AUTOWIDTH struct winsize win = { 0, 0, 0, 0 }; #endif disp_opts= DISP_NORMAL; style_fmt= STYLE_AUTO; list_fmt= LIST_SHORT; #ifdef BB_FEATURE_LS_SORTFILES sort_opts= SORT_NAME; sort_order= SORT_FORWARD; #endif #ifdef BB_FEATURE_LS_TIMESTAMPS time_fmt= TIME_MOD; #endif #ifdef BB_FEATURE_AUTOWIDTH ioctl(fileno(stdout), TIOCGWINSZ, &win); if (win.ws_row > 4) column_width = win.ws_row - 2; if (win.ws_col > 0) terminal_width = win.ws_col - 1; #endif nfiles=0; /* process options */ while ((opt = getopt(argc, argv, "1AaCdgilnsx" #ifdef BB_FEATURE_AUTOWIDTH "T:w:" #endif #ifdef BB_FEATURE_LS_FILETYPES "Fp" #endif #ifdef BB_FEATURE_LS_RECURSIVE "R" #endif #ifdef BB_FEATURE_LS_SORTFILES "rSvX" #endif #ifdef BB_FEATURE_LS_TIMESTAMPS "cetu" #endif #ifdef BB_FEATURE_LS_FOLLOWLINKS "L" #endif #ifdef BB_FEATURE_HUMAN_READABLE "h" #endif "k")) > 0) { switch (opt) { case '1': style_fmt = STYLE_SINGLE; break; case 'A': disp_opts |= DISP_HIDDEN; break; case 'a': disp_opts |= DISP_HIDDEN | DISP_DOT; break; case 'C': style_fmt = STYLE_COLUMNS; break; case 'd': disp_opts |= DISP_NOLIST; break; case 'g': /* ignore -- for ftp servers */ break; case 'i': list_fmt |= LIST_INO; break; case 'l': style_fmt = STYLE_LONG; list_fmt |= LIST_LONG; #ifdef BB_FEATURE_HUMAN_READABLE ls_disp_hr = FALSE; #endif break; case 'n': list_fmt |= LIST_ID_NUMERIC; break; case 's': list_fmt |= LIST_BLOCKS; break; case 'x': disp_opts = DISP_ROWS; break; #ifdef BB_FEATURE_LS_FILETYPES case 'F': list_fmt |= LIST_FILETYPE | LIST_EXEC; break; case 'p': list_fmt |= LIST_FILETYPE; break; #endif #ifdef BB_FEATURE_LS_RECURSIVE case 'R': disp_opts |= DISP_RECURSIVE; break; #endif #ifdef BB_FEATURE_LS_SORTFILES case 'r': sort_order |= SORT_REVERSE; break; case 'S': sort_opts= SORT_SIZE; break; case 'v': sort_opts= SORT_VERSION; break; case 'X': sort_opts= SORT_EXT; break; #endif #ifdef BB_FEATURE_LS_TIMESTAMPS case 'e': list_fmt |= LIST_FULLTIME; break; case 'c': time_fmt = TIME_CHANGE; #ifdef BB_FEATURE_LS_SORTFILES sort_opts= SORT_CTIME; #endif break; case 'u': time_fmt = TIME_ACCESS; #ifdef BB_FEATURE_LS_SORTFILES sort_opts= SORT_ATIME; #endif break; case 't': #ifdef BB_FEATURE_LS_SORTFILES sort_opts= SORT_MTIME; #endif break; #endif #ifdef BB_FEATURE_LS_FOLLOWLINKS case 'L': follow_links= TRUE; break; #endif #ifdef BB_FEATURE_AUTOWIDTH case 'T': tabstops= atoi(optarg); break; case 'w': terminal_width= atoi(optarg); break; #endif #ifdef BB_FEATURE_HUMAN_READABLE case 'h': ls_disp_hr = TRUE; break; #endif case 'k': break; default: goto print_usage_message; } } /* sort out which command line options take precedence */ #ifdef BB_FEATURE_LS_RECURSIVE if (disp_opts & DISP_NOLIST) disp_opts &= ~DISP_RECURSIVE; /* no recurse if listing only dir */ #endif #if defined (BB_FEATURE_LS_TIMESTAMPS) && defined (BB_FEATURE_LS_SORTFILES) if (time_fmt & TIME_CHANGE) sort_opts= SORT_CTIME; if (time_fmt & TIME_ACCESS) sort_opts= SORT_ATIME; #endif if (style_fmt != STYLE_LONG) list_fmt &= ~LIST_ID_NUMERIC; /* numeric uid only for long list */ #ifdef BB_FEATURE_LS_USERNAME if (style_fmt == STYLE_LONG && (list_fmt & LIST_ID_NUMERIC)) list_fmt &= ~LIST_ID_NAME; /* don't list names if numeric uid */ #endif /* choose a display format */ if (style_fmt == STYLE_AUTO) style_fmt = isatty(fileno(stdout)) ? STYLE_COLUMNS : STYLE_SINGLE; /* * when there are no cmd line args we have to supply a default "." arg. * we will create a second argv array, "av" that will hold either * our created "." arg, or the real cmd line args. The av array * just holds the pointers- we don't move the date the pointers * point to. */ ac= argc - optind; /* how many cmd line args are left */ if (ac < 1) { av= (char **)xcalloc((size_t)1, (size_t)(sizeof(char *))); av[0]= "."; ac=1; } else { av= (char **)xcalloc((size_t)ac, (size_t)(sizeof(char *))); for (oi=0 ; oi < ac; oi++) { av[oi]= argv[optind++]; /* copy pointer to real cmd line arg */ } } /* now, everything is in the av array */ if (ac > 1) disp_opts |= DISP_DIRNAME; /* 2 or more items? label directories */ /* stuff the command line file names into an dnode array */ dn=NULL; for (oi=0 ; oi < ac; oi++) { cur= (struct dnode *)xmalloc(sizeof(struct dnode)); cur->fullname= xstrdup(av[oi]); cur->name= cur->fullname; if (my_stat(cur)) continue; cur->next= dn; dn= cur; nfiles++; } /* now that we know how many files there are ** allocate memory for an array to hold dnode pointers */ dnp= dnalloc(nfiles); for (i=0, cur=dn; i<nfiles; i++) { dnp[i]= cur; /* save pointer to node in array */ cur= cur->next; } if (disp_opts & DISP_NOLIST) { #ifdef BB_FEATURE_LS_SORTFILES shellsort(dnp, nfiles); #endif if (nfiles > 0) showfiles(dnp, nfiles); } else { dnd= splitdnarray(dnp, nfiles, SPLIT_DIR); dnf= splitdnarray(dnp, nfiles, SPLIT_FILE); dndirs= countdirs(dnp, nfiles); dnfiles= nfiles - dndirs; if (dnfiles > 0) { #ifdef BB_FEATURE_LS_SORTFILES shellsort(dnf, dnfiles); #endif showfiles(dnf, dnfiles); } if (dndirs > 0) { #ifdef BB_FEATURE_LS_SORTFILES shellsort(dnd, dndirs); #endif showdirs(dnd, dndirs); } if (dnd) free(dnd); if (dnf) free(dnf); } free(av); if (dnp) dfree(dnp, nfiles); return(status); print_usage_message: show_usage(); }
void reallyBuildMatrices(temp_t** data_array, int* n_data_array, int n_n_data_array, int** dates_array, int* n_dates_array, int n_n_dates_array, double* new_spatial_table, int n_new_spatial_table1, int n_new_spatial_table2, float* map, int n_map, int* near_index, int n_near_index, real* t_res, int n_t_res, real* b_res, int n_b_res, real sigma, real sigma_full, bool first, berkeleyAverageOptions* options, double** base_weightsIO, int* n_base_weightsIO, double** base_constantsIO, int* n_base_constantsIO, double** temperature_mapIO, int* n_temperature_mapIO, double** temperature_constantsIO, int* n_temperature_constantsIO, double** record_weightIO, int* n_record_weightIO) { // Helper function used to efficiently divide the solution into parallel work blocks // for parallel processing. double local_outlier_limit; double global_outlier_limit; if ( options->useIterativeReweighting ) if ( options->useOutlierWeighting ) { local_outlier_limit= options->outlierWeightingCutoffMultiplier; global_outlier_limit= options->outlierWeightingCutoffMultiplier; } int len_t= n_new_spatial_table2; int len_s= n_new_spatial_table1; // Prepare matrix equation data holders double* base_weights= dnalloc(len_s); int n_base_weights= len_s; setd(base_weights, n_base_weights, 0); double* base_constants= dnalloc(len_s); int n_base_constants= len_s; setd(base_constants, n_base_constants, 0); double* temperature_map= dnalloc(len_t*len_t); int n_temperature_map, n_temperature_map1, n_temperature_map2; n_temperature_map= n_temperature_map1= n_temperature_map2= len_t; setd(temperature_map, n_temperature_map*n_temperature_map, 0); double* temperature_constant= dnalloc(len_t); int n_temperature_constant= len_t; setd(temperature_constant, n_temperature_constant, 0); // Loop over stations double* record_weight= dnalloc(len_s); int n_record_weight= len_s; setd(record_weight, n_record_weight, 0); int temp_blocking_size= 2500; int i, j, k; double* sp_weight_temp; int n_sp_weight_temp1; int n_sp_weight_temp2; double* s; int n_s1; int n_s2; int n_s; for ( j= 0; j < len_s; ++j ) { if ( j % temp_blocking_size == 0 ) { int max= (j + temp_blocking_size) < n_new_spatial_table1 ? (j + temp_blocking_size) : n_new_spatial_table1; sp_weight_temp= dnalloc(n_new_spatial_table2 * (max - j)); int ii; for ( i= j; i < max; ++i ) { ii= i - j; for ( k= 0; k < n_new_spatial_table2; ++k ) { sp_weight_temp[ii*n_new_spatial_table2 + k]= new_spatial_table[i*n_new_spatial_table2 + k]; } } n_sp_weight_temp1= max - j; n_sp_weight_temp2= n_new_spatial_table2; } if ( !first && b_res[j] == -FLT_MAX ) continue; // Load data from station int* monthnum= dates_array[j]; int n_monthnum= n_dates_array[j]; temp_t* data= data_array[j]; int n_data= n_data_array[j]; if ( !first ) { // TODO } real* outlier_weight= rnalloc(n_data); int n_outlier_weight= n_data; set(outlier_weight, n_outlier_weight, 1); if ( !first && options->useOutlierWeighting ) { // Perform outlier adjustments // TODO } temp_t* local_table; int n_local_table; if ( !first && options->localMode ) { //Improve paramter fit by reducing data by the local anomaly field. // TODO } else { local_table= data; n_local_table= n_data; } // Add entries corresponding to // (spatial correlation_table)*(data(t,x) - baseline(x) - mean_temp(t)) s= dnalloc(n_monthnum); n_s= n_monthnum; int idx= j%temp_blocking_size; for ( i= 0; i < n_monthnum; ++i ) s[i]= sp_weight_temp[idx*n_sp_weight_temp2 + monthnum[i]]; double sum= 0; for ( i= 0; i < n_s; ++i ) sum+= fabs(s[i]) * outlier_weight[i]; record_weight[j]= sum; base_weights[j]= base_weights[j] + n_s; sum= 0; for ( i= 0; i < n_local_table; ++i ) sum+= local_table[i]; base_constants[j]= base_constants[j] + sum; for ( i= 0; i < n_monthnum; ++i ) temperature_map[(int)(monthnum[i])*n_temperature_map + (int)(monthnum[i])]+= s[i]; for ( i= 0; i < n_monthnum; ++i ) temperature_constant[(int)(monthnum[i])]+= s[i]*data[i]; } *record_weightIO= record_weight; *base_weightsIO= base_weights; *base_constantsIO= base_constants; *temperature_mapIO= temperature_map; *temperature_constantsIO= temperature_constant; *n_record_weightIO= n_record_weight; *n_base_weightsIO= n_base_weights; *n_base_constantsIO= n_base_constants; *n_temperature_mapIO= n_temperature_map; *n_temperature_constantsIO= n_temperature_constant; }
extern int ls_main(int argc, char **argv) { struct dnode **dnd; struct dnode **dnf; struct dnode **dnp; struct dnode *dn; struct dnode *cur; long opt; int nfiles = 0; int dnfiles; int dndirs; int oi; int ac; int i; char **av; #ifdef CONFIG_FEATURE_AUTOWIDTH char *tabstops_str = NULL; char *terminal_width_str = NULL; #endif #ifdef CONFIG_SELINUX is_flask_enabled_flag = is_flask_enabled(); #endif all_fmt = LIST_SHORT | DISP_NORMAL | STYLE_AUTO #ifdef CONFIG_FEATURE_LS_TIMESTAMPS | TIME_MOD #endif #ifdef CONFIG_FEATURE_LS_SORTFILES | SORT_NAME | SORT_ORDER_FORWARD #endif ; #ifdef CONFIG_FEATURE_AUTOWIDTH /* Obtain the terminal width. */ get_terminal_width_height(0, &terminal_width, NULL); /* Go one less... */ terminal_width--; #endif #ifdef CONFIG_FEATURE_LS_COLOR if (isatty(fileno(stdout))) show_color = 1; #endif /* process options */ #ifdef CONFIG_FEATURE_AUTOWIDTH opt = bb_getopt_ulflags(argc, argv, ls_options, &tabstops_str, &terminal_width_str); if (tabstops_str) { tabstops = atoi(tabstops_str); } if (terminal_width_str) { terminal_width = atoi(terminal_width_str); } #else opt = bb_getopt_ulflags(argc, argv, ls_options); #endif /* 16 = maximum options minus tabsize and screewn width */ for (i = 0; i < 16; i++) { if (opt & (1 << i)) { unsigned int flags = opt_flags[i]; if (flags & LIST_MASK_TRIGGER) { all_fmt &= ~LIST_MASK; } if (flags & STYLE_MASK_TRIGGER) { all_fmt &= ~STYLE_MASK; } #ifdef CONFIG_FEATURE_LS_SORTFILES if (flags & SORT_MASK_TRIGGER) { all_fmt &= ~SORT_MASK; } #endif if (flags & DISP_MASK_TRIGGER) { all_fmt &= ~DISP_MASK; } #ifdef CONFIG_FEATURE_LS_TIMESTAMPS if (flags & TIME_MASK_TRIGGER) { all_fmt &= ~TIME_MASK; } #endif if (flags & LIST_CONTEXT) { all_fmt |= STYLE_SINGLE; } #ifdef CONFIG_FEATURE_HUMAN_READABLE if (opt == 'l') { all_fmt &= ~LS_DISP_HR; } #endif all_fmt |= flags; } } /* sort out which command line options take precedence */ #ifdef CONFIG_FEATURE_LS_RECURSIVE if (all_fmt & DISP_NOLIST) all_fmt &= ~DISP_RECURSIVE; /* no recurse if listing only dir */ #endif #if defined (CONFIG_FEATURE_LS_TIMESTAMPS) && defined (CONFIG_FEATURE_LS_SORTFILES) if (all_fmt & TIME_CHANGE) all_fmt = (all_fmt & ~SORT_MASK) | SORT_CTIME; if (all_fmt & TIME_ACCESS) all_fmt = (all_fmt & ~SORT_MASK) | SORT_ATIME; #endif if ((all_fmt & STYLE_MASK) != STYLE_LONG) /* only for long list */ all_fmt &= ~(LIST_ID_NUMERIC|LIST_FULLTIME|LIST_ID_NAME|LIST_ID_NUMERIC); #ifdef CONFIG_FEATURE_LS_USERNAME if ((all_fmt & STYLE_MASK) == STYLE_LONG && (all_fmt & LIST_ID_NUMERIC)) all_fmt &= ~LIST_ID_NAME; /* don't list names if numeric uid */ #endif /* choose a display format */ if ((all_fmt & STYLE_MASK) == STYLE_AUTO) #if STYLE_AUTO != 0 all_fmt = (all_fmt & ~STYLE_MASK) | (isatty(fileno(stdout)) ? STYLE_COLUMNS : STYLE_SINGLE); #else all_fmt |= (isatty(fileno(stdout)) ? STYLE_COLUMNS : STYLE_SINGLE); #endif /* * when there are no cmd line args we have to supply a default "." arg. * we will create a second argv array, "av" that will hold either * our created "." arg, or the real cmd line args. The av array * just holds the pointers- we don't move the date the pointers * point to. */ ac = argc - optind; /* how many cmd line args are left */ if (ac < 1) { av = (char **) xcalloc((size_t) 1, (size_t) (sizeof(char *))); av[0] = bb_xstrdup("."); ac = 1; } else { av = (char **) xcalloc((size_t) ac, (size_t) (sizeof(char *))); for (oi = 0; oi < ac; oi++) { av[oi] = argv[optind++]; /* copy pointer to real cmd line arg */ } } /* now, everything is in the av array */ if (ac > 1) all_fmt |= DISP_DIRNAME; /* 2 or more items? label directories */ /* stuff the command line file names into an dnode array */ dn = NULL; for (oi = 0; oi < ac; oi++) { char *fullname = bb_xstrdup(av[oi]); cur = my_stat(fullname, fullname); if (!cur) continue; cur->next = dn; dn = cur; nfiles++; } /* now that we know how many files there are ** allocate memory for an array to hold dnode pointers */ dnp = dnalloc(nfiles); for (i = 0, cur = dn; i < nfiles; i++) { dnp[i] = cur; /* save pointer to node in array */ cur = cur->next; } if (all_fmt & DISP_NOLIST) { #ifdef CONFIG_FEATURE_LS_SORTFILES shellsort(dnp, nfiles); #endif if (nfiles > 0) showfiles(dnp, nfiles); } else { dnd = splitdnarray(dnp, nfiles, SPLIT_DIR); dnf = splitdnarray(dnp, nfiles, SPLIT_FILE); dndirs = countdirs(dnp, nfiles); dnfiles = nfiles - dndirs; if (dnfiles > 0) { #ifdef CONFIG_FEATURE_LS_SORTFILES shellsort(dnf, dnfiles); #endif showfiles(dnf, dnfiles); } if (dndirs > 0) { #ifdef CONFIG_FEATURE_LS_SORTFILES shellsort(dnd, dndirs); #endif showdirs(dnd, dndirs); } } return (status); }