long settings_get_end_date() { char *s = get_string_from_entry("end_date_entry"); if (strlen(s) > 0) { return atol(s); } else { return -1; } }
SIGNAL_CALLBACK void on_save_button_clicked(GtkWidget *w) { // save the specified subset! const char *dir = get_string_from_entry("dir_entry"); const char *file = get_string_from_entry("filename_entry"); const char *ext = get_format()==FORMAT_CSV ? "csv" : "img"; if (strlen(file) == 0) { message_box("Please provide a name for the file."); return; } char *save_file = MALLOC(sizeof(char)*(strlen(dir)+strlen(file)+strlen(ext)+5)); if (strlen(dir) > 0) { if (dir[strlen(dir)-1] == DIR_SEPARATOR || dir[strlen(dir)-1] == '/') sprintf(save_file, "%s%s.%s", dir, file, ext); else sprintf(save_file, "%s/%s.%s", dir, file, ext); } else sprintf(save_file, "%s.%s", file, ext); int strict_boundary = get_checked("strict_boundary_checkbutton"); int load = get_checked("load_saved_subset_checkbutton"); int ok; if (get_format()==FORMAT_CSV) { ok = save_as_csv(curr, save_file, get_what_to_save(), strict_boundary, load); } else { assert(get_format()==FORMAT_ASF_INTERNAL); ok = save_as_asf(curr, save_file, get_what_to_save(), strict_boundary, load); } free(save_file); if (ok) close_subset_window(curr); }
static int latlon_getls(double *line, double *samp) { int ok = FALSE; meta_parameters *meta = curr->meta; if (meta->projection || (meta->sar&&meta->state_vectors) || meta->transform || meta->airsar) { double lat, lon; char *lat_str = get_string_from_entry("go_to_lat_entry"); if (strchr(lat_str, ',') == NULL) { lat = get_double_from_entry("go_to_lat_entry"); lon = get_double_from_entry("go_to_lon_entry"); } else { char *latlon = STRDUP(lat_str); char *comma = strchr(latlon, ','); *comma = '\0'; lat = atof(latlon); lon = atof(comma+1); // points to character after comma, longitude } if (lat < -90 || lat > 90) { asfPrintWarning("Illegal latitude value: %f\n", lat); } else if (lon < -360 || lon > 360) { asfPrintWarning("Illegal longitude value: %f\n", lon); } else { int bad = meta_get_lineSamp(curr->meta, lat, lon, 0, line, samp); ok = !bad; } } else { asfPrintWarning("No geolocation information available -- GoTo will only\n" "work for GoTo by Line/Sample.\n"); } return ok; }
Settings *settings_new_from_gui() { Settings *s = settings_new(); s->csv_dir = settings_get_csv_dir(); s->output_dir = settings_get_output_dir(); s->obs_req_num = atoi(get_string_from_entry("next_obs_request_number_entry")); s->obs_req_id_aadn = atoi(get_string_from_entry("next_obs_request_id_entry")); s->obs_req_id_tdrs = atoi(get_string_from_entry("next_obs_request_id_tdrs_entry")); s->acq_req_num = atoi(get_string_from_entry("next_acq_request_number_entry")); s->odl0_seq_num = atoi(get_string_from_entry("odl0_sequence_number_entry")); s->odl0_req_id = atoi(get_string_from_entry("next_odl0_request_id_entry")); s->station_code = STRDUP(settings_get_station_code()); int i; for (i=0; i<MAX_STATIONS; ++i) { char widget_name[128]; snprintf(widget_name, 128, "next_acq_request_id_entry%d", i+1); s->acq_req_ids[i] = atoi(get_string_from_entry(widget_name)); } return s; }
void process() { clear_results_message(); child_params_t *cp = MALLOC(sizeof(child_params_t)); strcpy(cp->in_file, get_string_from_entry("input_file_entry")); char *odir = get_string_from_entry("output_directory_entry"); char *ofile = get_string_from_entry("output_file_entry"); if (strlen(odir) > 0) { #ifdef win32 if (odir[strlen(odir)-1]=='/' || odir[strlen(odir)-1]=='\\') #else if (odir[strlen(odir)-1]=='/') #endif sprintf(cp->out_file, "%s%s", odir, ofile); else sprintf(cp->out_file, "%s/%s", odir, ofile); } else { strcpy(cp->out_file, ofile); } if (strlen(cp->in_file)==0) { message_box("No input file specified!"); free(cp); return; } else if (strlen(cp->out_file)==0) { message_box("No output file selected!"); free(cp); return; } else if (!fileExists(cp->in_file)) { message_box("Input file \"%s\" not found!", cp->in_file); free(cp); return; } int input_format = get_combo_box_item("input_format_combobox"); int output_format = get_combo_box_item("output_format_combobox"); if (input_format==INPUT_AUTO) { select_defaults_by_file_type(cp->in_file, FALSE); input_format = get_combo_box_item("input_format_combobox"); if (input_format==INPUT_AUTO) { message_box("Can't figure out which type of data this is.\n" "Please select the input format manually."); free(cp); return; } } strcpy(cp->in_format, input_format_to_str(input_format)); strcpy(cp->out_format, output_format_to_str(output_format)); char *logFile = appendExt(cp->out_file, ".log"); #ifdef win32 STARTUPINFO si; PROCESS_INFORMATION pi; memset(&si, 0, sizeof(si)); memset(&pi, 0, sizeof(pi)); si.cb = sizeof(si); char *cmd = MALLOC(sizeof(char)* (strlen(cp->in_file) + strlen(cp->out_file) + strlen(get_asf_bin_dir_win()) + 512)); sprintf(cmd, "\"%s/convert2vector.exe\" " "-log \"%s\" " "-input-format %s -output-format %s \"%s\" \"%s\"", get_asf_bin_dir_win(), logFile, cp->in_format, cp->out_format, cp->in_file, cp->out_file); // clear out any previously existing log file fLog = fopen(logFile, "a"); FCLOSE(fLog); if (!CreateProcess(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { DWORD dw = GetLastError(); //printf( "CreateProcess failed (%ld)\n", dw ); LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL); printf("CreateProcess() failed with error %ld: %s\n", dw, (char*)lpMsgBuf); printf("Failed command: %s\n", cmd); } DWORD dwWaitResult; // now wait for process to finish do { while (gtk_events_pending()) gtk_main_iteration(); dwWaitResult = WaitForSingleObject(pi.hProcess, 50); } while (dwWaitResult == WAIT_TIMEOUT); #else asfFork(child_func, (void*)cp, parent_func, NULL); #endif char message[1024]; strcpy(message, "-"); int success=FALSE; FILE *lfp = fopen(logFile, "r"); if (!lfp) { sprintf(message, "Error Opening Log File '%s': %s\n", logFile, strerror(errno)); } else { char *output = NULL; char line[1024]; while (fgets(line, 1024, lfp)) { if (output) { output = realloc(output, sizeof(char)*(strlen(output)+strlen(line)+1)); strcat(output, line); } else { output = malloc(sizeof(char)*(strlen(line)+1)); strcpy(output, line); } } fclose(lfp); //unlink(logFile); char *p = output, *q; while (p) { q = strchr(p+1, '\n'); if (q) { *q = '\0'; if (strstr(p, "Error")!=NULL || strstr(p, "ERROR")!=NULL) { *q = '\n'; int i,n = 0; do { p = q + 1; q = strchr(p, '\n') - 1; while (isspace(*q)) --q; if (q - p > 2) { // First 220 characters of the error string, unless line ends // first. Don't cut off in the middle of a word, though strcpy(message, "Error: "); strncat(message, p, 220); while (isalnum(message[strlen(message)-1])) message[strlen(message)-1] = '\0'; for (n=0; n<strlen(message); ++n) if (message[n] == '\n' || message[n] == '*') message[n] = ' '; int eating=FALSE; for (n=0,i=0; n<strlen(message); ++n) { if (isspace(message[n])) { if (!eating) { eating=TRUE; message[i++] = message[n]; } } else { eating=FALSE; message[i++] = message[n]; } } message[i]='\0'; char *eoe = strstr(message, "End of error"); if (eoe) *eoe = '\0'; else if (strlen(message)>200) strcat(message, " ..."); break; } } while (*p != '*' && ++n<5); // * flags the end of the error message } if (strstr(p,"Successful completion!") != NULL) { strcpy(message, "Processed successfully!"); success=TRUE; break; } *q = '\n'; } p=q; } if (strlen(message)==0) { // Did not find an error message, or the success message! // So, assume there was an error, but we don't know why strcpy(message, "Processing failed!"); } FREE(output); } int open_output = get_checked("open_output_checkbutton"); if (!success) open_output = FALSE; put_string_to_label("result_label", message); asfPrintStatus(message); asfPrintStatus("\n\nDone.\n\n"); if (open_output) { switch (output_format) { case OUTPUT_KML: open_in_google_earth(cp->out_file); break; case OUTPUT_ALOS_CSV: open_in_excel(cp->out_file); default: // do nothing, output type has no natural associated app break; } } free(cp); }
SIGNAL_CALLBACK void on_add_file_with_ancillary_ok_button_clicked(GtkWidget * w) { const char *type = get_string_from_label("add_with_ancillary_format_label"); int sel = -1; if (strcmp_case(type, "GAMMA") == 0) sel = ADD_FILE_WITH_ANCILLARY_FORMAT_GAMMA; else if (strcmp_case(type, "PolSARPro") == 0) sel = ADD_FILE_WITH_ANCILLARY_FORMAT_POLSARPRO; else if (strcmp_case(type, "UAVSAR") == 0) sel = ADD_FILE_WITH_ANCILLARY_FORMAT_UAVSAR; GtkTreeIter iter; int ok = TRUE; char *dataFile = NULL, *data = NULL, *ceos = NULL; char *aux_info = ""; switch (sel) { case ADD_FILE_WITH_ANCILLARY_FORMAT_POLSARPRO: { GtkWidget *ok_button = get_widget_checked("add_file_with_ancillary_ok_button"); gtk_widget_set_sensitive(ok_button, FALSE); dataFile = get_string_from_entry("add_file_with_ancillary_polsarpro_image_entry"); char *matrixType=NULL, *error, *decompositionType, *derror; char *serror, *perror; int is_polsarpro_matrix = isPolsarproMatrix(dataFile, &matrixType, &error); int is_polsarpro_decomposition = isPolsarproDecomposition(dataFile, &decompositionType, &derror); int is_polsarpro_segmentation = isPolsarproSegmentation(dataFile, &serror); int is_polsarpro_parameter = isPolsarproParameter(dataFile, &perror); if (is_polsarpro_matrix && !is_polsarpro_decomposition && !is_polsarpro_segmentation && !is_polsarpro_parameter) { data = (char *) MALLOC(sizeof(char) * (strlen(dataFile) + 15)); if (!is_dir(dataFile)) { char *tmp = (char *) MALLOC(sizeof(char) * (strlen(dataFile) + 1)); tmp = get_dirname(dataFile); dataFile[strlen(tmp) - 1] = '\0'; FREE(tmp); } if (strcmp(matrixType, "T3") == 0 || strcmp(matrixType, "T4") == 0) sprintf(data, "%s/T11.bin", dataFile); else if (strcmp(matrixType, "C2") == 0 || strcmp(matrixType, "C3") == 0 || strcmp(matrixType, "C4") == 0) sprintf(data, "%s/C11.bin", dataFile); } else data = STRDUP(dataFile); FREE(matrixType); int is_geocoded = isGeocoded(data); if (!is_geocoded) ceos = get_string_from_entry ("add_file_with_ancillary_polsarpro_ceos_entry"); if (!is_geocoded && (strlen(ceos) == 0 || strlen(data) == 0)) { put_string_to_label("add_with_ancillary_error_label", "Please choose all required files!"); return; } else { GtkWidget *browse_option_menu = get_widget_checked("browse_select_colormap_optionmenu"); GtkWidget *menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(browse_option_menu)); GtkWidget *selected_item = gtk_menu_get_active(GTK_MENU(menu)); GtkWidget *combo = get_widget_checked("browse_select_image_data_type_optionmenu"); int image_data_type = gtk_combo_box_get_active(GTK_COMBO_BOX(combo)); char *lut_basename = g_object_get_data(G_OBJECT(selected_item), "file"); aux_info = encode_polsarpro_aux_info(image_data_type, lut_basename); put_string_to_label("add_with_ancillary_error_label", ""); ok = add_to_files_list_iter(data, ceos, NULL, aux_info, NULL, NULL, NULL, NULL, NULL, &iter); free(aux_info); } break; } case ADD_FILE_WITH_ANCILLARY_FORMAT_GAMMA: { GtkWidget *ok_button = get_widget_checked("add_file_with_ancillary_ok_button"); gtk_widget_set_sensitive(ok_button, TRUE); data = get_string_from_entry("add_file_with_ancillary_gamma_data_entry"); char *meta = get_string_from_entry("add_file_with_ancillary_gamma_metadata_entry"); if (strlen(data) == 0 || strlen(meta) == 0) { put_string_to_label("add_with_ancillary_error_label", "Please choose all required files!"); return; } else { put_string_to_label("add_with_ancillary_error_label", ""); char *interferogram, *coherence, *slave_metadata, *baseline; interferogram = get_string_from_entry("add_file_with_ancillary_gamma_igram_entry"); coherence = get_string_from_entry("add_file_with_ancillary_gamma_coh_entry"); slave_metadata = get_string_from_entry("add_file_with_ancillary_gamma_slave_entry"); baseline = get_string_from_entry("add_file_with_ancillary_gamma_baseline_entry"); if (strlen(interferogram) == 0) { FREE(interferogram); interferogram = NULL; } if (strlen(coherence) == 0) { FREE(coherence); coherence = NULL; } if (strlen(slave_metadata) == 0) { FREE(slave_metadata); slave_metadata = NULL; } if (strlen(baseline) == 0) { FREE(baseline); baseline = NULL; } ok = add_to_files_list_iter(data, ceos, meta, aux_info, NULL, interferogram, coherence, slave_metadata, baseline, &iter); } break; } case ADD_FILE_WITH_ANCILLARY_FORMAT_UAVSAR: { GtkWidget *ok_button = get_widget_checked("add_file_with_ancillary_ok_button"); gtk_widget_set_sensitive(ok_button, TRUE); GtkWidget *ann_file_entry = get_widget_checked("add_file_with_ancillary_uavsar_annotation_file_entry"); const gchar *annotation_file = gtk_entry_get_text(GTK_ENTRY(ann_file_entry)); GList *l, *uavsar_proc_types = get_widgets_prefix_checked("uavsar_proc_type_"); for(l = uavsar_proc_types; l; l = l->next) { gpointer proc_type_check_button = l->data; if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(proc_type_check_button))) { const gchar *name = gtk_widget_get_name(GTK_WIDGET(proc_type_check_button)); ok = add_to_files_list_iter(annotation_file, NULL, NULL, NULL, name + strlen("uavsar_proc_types_") - 1, NULL, NULL, NULL, NULL, &iter); if(!ok) break; } } g_list_free(uavsar_proc_types); } break; } if (!ok) { if (data) { char *msg = MALLOC(sizeof(char) * (strlen(data) + 128)); sprintf(msg, "Unrecognized file:\n %s\n\n" "The file may be of a type not supported by MapReady.\n", data); message_box(msg); free(msg); } else { char *msg = MALLOC(sizeof(char) * 256); sprintf(msg, "Unrecognized file!\n\n" "The file may be of a type not supported by MapReady.\n"); message_box(msg); free(msg); } } else { show_widget("add_file_with_ancillary_dialog", FALSE); clear_entries(); } }
int entry_has_text(const char *widget_name) { return strlen(get_string_from_entry(widget_name)) > 0; }
char *settings_get_output_dir() { return mkstr(get_string_from_entry("output_directory_entry")); }
char *settings_get_csv_dir() { return mkstr(get_string_from_entry("csv_directory_entry")); }