/* set initial values for the next level */ static void imageid_next_level() { gc_bar_set_level(gcomprisBoard); imageid_destroy_all_items(); selected_button = NULL; gamewon = FALSE; destroy_board_list(); init_xml(gcomprisBoard->level); gcomprisBoard->number_of_sublevel = g_list_length(board_list); gc_score_end(); gc_score_start(SCORESTYLE_NOTE, BOARDWIDTH - 195, BOARDHEIGHT - 30, gcomprisBoard->number_of_sublevel); gc_score_set(gcomprisBoard->sublevel); /* Try the next level */ imageid_create_item(goo_canvas_get_root_item(gcomprisBoard->canvas)); }
/* ===================================================================== * * =====================================================================*/ static void start_board (GcomprisBoard *agcomprisBoard) { if(agcomprisBoard!=NULL) { gcomprisBoard=agcomprisBoard; gcomprisBoard->level=1; gcomprisBoard->maxlevel=LAST_BOARD; gcomprisBoard->sublevel = 1; gcomprisBoard->number_of_sublevel = 8; gc_bar_set(GC_BAR_LEVEL); gc_score_start(SCORESTYLE_NOTE, BOARDWIDTH - 195, BOARDHEIGHT - 30, gcomprisBoard->number_of_sublevel); gamewon = FALSE; init_xml(); g_signal_connect(goo_canvas_get_root_item(gcomprisBoard->canvas), "button_press_event", (GtkSignalFunc) item_event, NULL); colors_next_level(); pause_board(FALSE); } }
/* ===================================================================== * * =====================================================================*/ static void set_level (guint level) { if(gcomprisBoard!=NULL) { gcomprisBoard->level=level; gcomprisBoard->sublevel=1; init_xml(); colors_next_level(); } }
void init_sys_tasks(SimulationController& sc ) throw() { init_random_sequence(); init_basic_tasks( sc ); init_world_tasks( sc ); init_misc( sc ); init_edge_models( sc ); init_transmission_models( sc ); init_communication_models( sc ); init_distance_estimates( sc ); init_taggings( sc ); init_node_movements( sc ); init_logging( sc ); init_xml( sc ); }
static gboolean conf_ok(GHashTable *table) { if (!table){ if (gcomprisBoard_missing) pause_board(FALSE); return TRUE; } g_hash_table_foreach(table, (GHFunc) save_table, NULL); if (gcomprisBoard_missing){ GHashTable *config; if (profile_conf) config = gc_db_get_board_conf(); else config = table; gc_locale_set(g_hash_table_lookup( config, "locale")); gchar *up_init_str = g_hash_table_lookup( config, "uppercase_only"); if (up_init_str) { if(strcmp(up_init_str, "True")==0) uppercase_only = TRUE; else uppercase_only = FALSE; } if (profile_conf) g_hash_table_destroy(config); missing_destroy_board_list(board_list); board_list = NULL; init_xml(gcomprisBoard_missing->level); missing_letter_next_level(); } board_conf = NULL; profile_conf = NULL; pause_board(FALSE); return TRUE; }
/* * Traverse the graph and draw all the elements. The order of edges vs nodes * doesn't matter here since the groups are already in the correct order. */ void SVG_Image::drawGraph(const Graph& g, unsigned int layoutGridSize) { gridSize = layoutGridSize; hexWidth = getHexagonWidth(gridSize); std::cout << "Drawing a graph, gridsize = " << gridSize << std::endl; // Try to come up with good size for nodes and edges. nodeRadius = 0.2*hexWidth; nodeThickness = 0*nodeRadius; edgeThickness = 0.1*nodeRadius; init_xml(); for(auto node : g.nodes) { drawNode(node.first); for(auto to : node.second) { drawEdge(node.first, to); } } }
int main (int argc, char** argv) { gchar* hostname; gint port; GMainLoop* main_loop; GConn* conn; gnet_init (); /* Parse args */ if (argc != 4) { g_print ("usage: %s <server> <port> <output-directory>\n", argv[0]); exit(EXIT_FAILURE); } hostname = argv[1]; port = atoi(argv[2]); out_dir = argv[3]; check_dir (out_dir); update_filename (); /* Create the main loop */ main_loop = g_main_new(FALSE); /* Create connection object */ conn = gnet_conn_new (hostname, port, ob_conn_func, NULL); g_assert (conn); /* Connect */ gnet_conn_connect (conn); gnet_conn_set_watch_error (conn, TRUE); gnet_conn_timeout (conn, 30000); /* 30 second timeout */ //open the xml file init_xml (); atexit (flush_xml); /* Start the main loop */ g_main_run (main_loop); exit (EXIT_SUCCESS); return 0; }
/* ===================================================================== * * =====================================================================*/ static void game_won() { listColors = g_list_remove(listColors, g_list_nth_data(listColors,0)); if( g_list_length(listColors) <= 0 ) { // the current board is finished gcomprisBoard->level++; gcomprisBoard->sublevel = 1; if (gcomprisBoard->level > gcomprisBoard->maxlevel) { gcomprisBoard->level = gcomprisBoard->maxlevel; return; } init_xml(); } else { // the current board is not finished gcomprisBoard->sublevel++; } colors_next_level(); }
/* maintain a rolling log file */ static void update_filename (void) { static int first_run = 1; static int current_number = -1; static int nodes = ENTRIES_PER_FILE -1; nodes++; if (nodes == ENTRIES_PER_FILE) { nodes = 0; current_number++; snprintf (current_file, sizeof (current_file), "%s/log-%.10d.xml", out_dir, current_number); printf ("Setting current file to '%s'\n", current_file); if (!first_run) { flush_xml (); init_xml (); } else first_run = 0; } }
static gboolean conf_ok(GHashTable *table) { if (!table){ if (gcomprisBoard) pause_board(FALSE); return TRUE; } g_hash_table_foreach(table, (GHFunc) save_table, NULL); if (gcomprisBoard) { GHashTable *config; if (profile_conf) config = gc_db_get_board_conf(); else config = table; gc_locale_set(g_hash_table_lookup( config, "locale")); if (profile_conf) g_hash_table_destroy(config); destroy_board_list(); init_xml(gcomprisBoard->level); imageid_next_level(); pause_board(FALSE); } board_conf = NULL; profile_conf = NULL; return TRUE; }
int film::process () { int audioSize; uint8_t *buffer; uint8_t *buffer2; int frameFinished; int numBytes; shot s; static struct SwsContext *img_convert_ctx = NULL; create_main_dir (); string graphpath = this->global_path + "/"; g = new graph (600, 400, graphpath, threshold, this); g->set_title ("Motion quantity"); /* * Register all formats and codecs */ av_register_all (); if (av_open_input_file (&pFormatCtx, input_path.c_str (), NULL, 0, NULL) != 0) { string error_msg = "Impossible to open file"; error_msg += input_path; shotlog (error_msg); return -1; // Couldn't open file } /* * Retrieve stream information */ if (av_find_stream_info (pFormatCtx) < 0) return -1; // Couldn't find stream information // dump_format (pFormatCtx, 0, path.c_str (), false); videoStream = -1; audioStream = -1; /* * Detect streams types */ for (int j = 0; j < pFormatCtx->nb_streams; j++) { switch (pFormatCtx->streams[j]->codec->codec_type) { case AVMEDIA_TYPE_VIDEO: videoStream = j; break; case AVMEDIA_TYPE_AUDIO: audioStream = j; break; default: break; } } /* * Get a pointer to the codec context for the video stream */ if (audioStream != -1) { if (audio_set) { string xml_audio = graphpath + "/" + "audio.xml"; init_xml (xml_audio); } pCodecCtxAudio = pFormatCtx->streams[audioStream]->codec; pCodecAudio = avcodec_find_decoder (pCodecCtxAudio->codec_id); if (pCodecAudio == NULL) return -1; // Codec not found if (avcodec_open (pCodecCtxAudio, pCodecAudio) < 0) return -1; // Could not open codec } update_metadata (); /* * Find the decoder for the video stream */ if (videoStream != -1) { pCodecCtx = pFormatCtx->streams[videoStream]->codec; pCodec = avcodec_find_decoder (pCodecCtx->codec_id); if (pCodec == NULL) return -1; // Codec not found if (avcodec_open (pCodecCtx, pCodec) < 0) return -1; // Could not open codec /* * Allocate video frame */ pFrame = avcodec_alloc_frame (); pFrameRGB = avcodec_alloc_frame (); pFrameRGBprev = avcodec_alloc_frame (); /* * Determine required buffer size and allocate buffer */ numBytes = avpicture_get_size (PIX_FMT_RGB24, width, height); buffer = (uint8_t *) malloc (sizeof (uint8_t) * numBytes); buffer2 = (uint8_t *) malloc (sizeof (uint8_t) * numBytes); /* * Assign appropriate parts of buffer to image planes in pFrameRGB */ avpicture_fill ((AVPicture *) pFrameRGB, buffer, PIX_FMT_RGB24, width, height); avpicture_fill ((AVPicture *) pFrameRGBprev, buffer2, PIX_FMT_RGB24, width, height); /* * Mise en place du premier plan */ s.fbegin = 0; s.msbegin = 0; s.myid = 0; shots.push_back (s); } checknumber = (samplerate * samplearg) / 1000; /* * Boucle de traitement principale du flux */ this->frame_number = 0; while (av_read_frame (pFormatCtx, &packet) >= 0) { if (packet.stream_index == videoStream) { AVPacket pkt; av_init_packet (&pkt); pkt.data = packet.data; pkt.size = packet.size; avcodec_decode_video2 (pCodecCtx, pFrame, &frameFinished, &pkt); if (frameFinished) { // Convert the image into RGB24 if (! img_convert_ctx) { img_convert_ctx = sws_getContext(width, height, pCodecCtx->pix_fmt, width, height, PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL); if (! img_convert_ctx) { fprintf(stderr, "Cannot initialize the conversion context!\n"); exit(1); } } /* API: int sws_scale(SwsContext *c, uint8_t *src, int srcStride[], int srcSliceY, int srcSliceH, uint8_t dst[], int dstStride[] ) */ sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize); /* Old API doc (cf http://www.dranger.com/ffmpeg/functions.html ) int img_convert(AVPicture *dst, int dst_pix_fmt, const AVPicture *src, int src_pix_fmt, int src_width, int src_height) */ /* img_convert ((AVPicture *) pFrameRGB, PIX_FMT_RGB24, (AVPicture *) pFrame, pCodecCtx->pix_fmt, width, height); */ this->frame_number ++; /* Si ce n'est pas la permiere image */ if ( this->frame_number > 2) { CompareFrame (pFrameRGB, pFrameRGBprev); } else { /* * Cas ou c'est la premiere image, on cree la premiere image dans tous les cas */ image *begin_i = new image (this, width, height, s.myid, BEGIN); begin_i->create_img_dir (); begin_i->SaveFrame (pFrameRGB); shots.back ().img_begin = begin_i; } memcpy (buffer2, buffer, numBytes); } } if (audio_set && (packet.stream_index == audioStream)) { process_audio (); } /* * Free the packet that was allocated by av_read_frame */ if (packet.data != NULL) av_free_packet (&packet); } if (videoStream != -1) { /* Mise en place de la dernière image */ int lastFrame = this->frame_number; shots.back ().fduration = lastFrame - shots.back ().fbegin; shots.back ().msduration = int (((shots.back ().fduration) * 1000) / fps); duration.mstotal = int (shots.back ().msduration + shots.back ().msbegin); image *end_i = new image (this, width, height, shots.back ().myid, END); end_i->SaveFrame (pFrameRGB); shots.back ().img_end = end_i; /* * Graphe de la qté de mvmt */ g->init_gd (); g->draw_all_canvas (); g->draw_color_datas (); g->draw_datas (); if (video_set) { string xml_color = graphpath + "/" + "video.xml"; g->write_xml (xml_color); } g->save (); /* * Free the RGB images */ free (buffer); free (buffer2); av_free (pFrameRGB); av_free (pFrame); av_free (pFrameRGBprev); avcodec_close (pCodecCtx); } /* * Close the codec */ if (audioStream != -1) { /* Fermetrure du fichier xml */ if (audio_set) close_xml (); avcodec_close (pCodecCtxAudio); } /* * Close the video file */ av_close_input_file (pFormatCtx); }
/* Manage the whole stuff. */ void makeit() { checkstruct *check; picstruct *dfield, *field,*pffield[MAXFLAG], *wfield,*dwfield; catstruct *imacat; tabstruct *imatab; patternstruct *pattern; static time_t thetime1, thetime2; struct tm *tm; unsigned int modeltype; int nflag[MAXFLAG], nparam2[2], i, nok, ntab, next, ntabmax, forcextflag, nima0,nima1, nweight0,nweight1, npsf0,npsf1, npat,npat0; next = 0; nok = 1; /* Processing start date and time */ dtime = counter_seconds(); thetimet = time(NULL); tm = localtime(&thetimet); sprintf(prefs.sdate_start,"%04d-%02d-%02d", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday); sprintf(prefs.stime_start,"%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec); NFPRINTF(OUTPUT, ""); QPRINTF(OUTPUT, "----- %s %s started on %s at %s with %d thread%s\n\n", BANNER, MYVERSION, prefs.sdate_start, prefs.stime_start, prefs.nthreads, prefs.nthreads>1? "s":""); /* Initialize globals variables */ initglob(); NFPRINTF(OUTPUT, "Setting catalog parameters"); readcatparams(prefs.param_name); useprefs(); /* update things accor. to prefs parameters */ /* Check if a specific extension should be loaded */ /* Never true for an NDF, although we could through all NDFs in a container, */ /* so we make selectext go away. */ nima0 = -1; forcextflag = 0; /* Do the same for other data (but do not force single extension mode) */ nima1 = -1; /* selectext(prefs.image_name[1]) */ nweight0 = -1; /* selectext(prefs.wimage_name[0]) */ nweight1 = -1; /* selectext(prefs.wimage_name[1]) */ if (prefs.dpsf_flag) { npsf0 = -1; /* selectext(prefs.psf_name[0]) */ npsf1 = -1; /* selectext(prefs.psf_name[1]) */ } else npsf0 = -1; /* selectext(prefs.psf_name[0]) */ for (i=0; i<prefs.nfimage_name; i++) nflag[i] = -1; /* selectext(prefs.fimage_name[i]) */ if (prefs.psf_flag) { /*-- Read the first PSF extension to set up stuff such as context parameters */ NFPRINTF(OUTPUT, "Reading PSF information"); if (prefs.dpsf_flag) { thedpsf = psf_load(prefs.psf_name[0],nima0<0? 1 :(npsf0<0? 1:npsf0)); thepsf = psf_load(prefs.psf_name[1], nima1<0? 1 :(npsf1<0? 1:npsf1)); } else thepsf = psf_load(prefs.psf_name[0], nima0<0? 1 :(npsf0<0? 1:npsf0)); /*-- Need to check things up because of PSF context parameters */ updateparamflags(); useprefs(); } if (prefs.prof_flag) { #ifdef USE_MODEL fft_init(prefs.nthreads); /* Create profiles at full resolution */ NFPRINTF(OUTPUT, "Preparing profile models"); modeltype = (FLAG(obj2.prof_offset_flux)? MODEL_BACK : MODEL_NONE) |(FLAG(obj2.prof_dirac_flux)? MODEL_DIRAC : MODEL_NONE) |(FLAG(obj2.prof_spheroid_flux)? (FLAG(obj2.prof_spheroid_sersicn)? MODEL_SERSIC : MODEL_DEVAUCOULEURS) : MODEL_NONE) |(FLAG(obj2.prof_disk_flux)? MODEL_EXPONENTIAL : MODEL_NONE) |(FLAG(obj2.prof_bar_flux)? MODEL_BAR : MODEL_NONE) |(FLAG(obj2.prof_arms_flux)? MODEL_ARMS : MODEL_NONE); theprofit = profit_init(thepsf, modeltype); changecatparamarrays("VECTOR_MODEL", &theprofit->nparam, 1); changecatparamarrays("VECTOR_MODELERR", &theprofit->nparam, 1); nparam2[0] = nparam2[1] = theprofit->nparam; changecatparamarrays("MATRIX_MODELERR", nparam2, 2); if (prefs.dprof_flag) thedprofit = profit_init(thedpsf, modeltype); if (prefs.pattern_flag) { npat0 = prefs.prof_disk_patternvectorsize; if (npat0<prefs.prof_disk_patternmodvectorsize) npat0 = prefs.prof_disk_patternmodvectorsize; if (npat0<prefs.prof_disk_patternargvectorsize) npat0 = prefs.prof_disk_patternargvectorsize; /*---- Do a copy of the original number of pattern components */ prefs.prof_disk_patternncomp = npat0; pattern = pattern_init(theprofit, prefs.pattern_type, npat0); if (FLAG(obj2.prof_disk_patternvector)) { npat = pattern->size[2]; changecatparamarrays("DISK_PATTERN_VECTOR", &npat, 1); } if (FLAG(obj2.prof_disk_patternmodvector)) { npat = pattern->ncomp*pattern->nfreq; changecatparamarrays("DISK_PATTERNMOD_VECTOR", &npat, 1); } if (FLAG(obj2.prof_disk_patternargvector)) { npat = pattern->ncomp*pattern->nfreq; changecatparamarrays("DISK_PATTERNARG_VECTOR", &npat, 1); } pattern_end(pattern); } QPRINTF(OUTPUT, "Fitting model: "); for (i=0; i<theprofit->nprof; i++) { if (i) QPRINTF(OUTPUT, "+"); QPRINTF(OUTPUT, "%s", theprofit->prof[i]->name); } QPRINTF(OUTPUT, "\n"); if (FLAG(obj2.prof_concentration)|FLAG(obj2.prof_concentration)) { thepprofit = profit_init(thepsf, MODEL_DIRAC); theqprofit = profit_init(thepsf, MODEL_EXPONENTIAL); } #else error(EXIT_FAILURE, "*Error*: model-fitting is not supported in this build.\n", " Please check your configure options"); #endif } if (prefs.filter_flag) { NFPRINTF(OUTPUT, "Reading detection filter"); getfilter(prefs.filter_name); /* get the detection filter */ } if (FLAG(obj2.sprob)) { NFPRINTF(OUTPUT, "Initializing Neural Network"); neurinit(); NFPRINTF(OUTPUT, "Reading Neural Network Weights"); getnnw(); } if (prefs.somfit_flag) { int margin; thesom = som_load(prefs.som_name); if ((margin=(thesom->inputsize[1]+1)/2) > prefs.cleanmargin) prefs.cleanmargin = margin; if (prefs.somfit_vectorsize>thesom->neurdim) { prefs.somfit_vectorsize = thesom->neurdim; sprintf(gstr,"%d", prefs.somfit_vectorsize); warning("Dimensionality of the SOM-fit vector limited to ", gstr); } } /* Prepare growth-curve buffer */ if (prefs.growth_flag) initgrowth(); /* Allocate memory for multidimensional catalog parameter arrays */ alloccatparams(); useprefs(); /*-- Init the CHECK-images */ if (prefs.check_flag) { checkenum c; NFPRINTF(OUTPUT, "Initializing check-image(s)"); for (i=0; i<prefs.ncheck_type; i++) if ((c=prefs.check_type[i]) != CHECK_NONE) { if (prefs.check[c]) error(EXIT_FAILURE,"*Error*: 2 CHECK_IMAGEs cannot have the same ", " CHECK_IMAGE_TYPE"); prefs.check[c] = initcheck(prefs.check_name[i], prefs.check_type[i], next); free(prefs.check_name[i]); } } NFPRINTF(OUTPUT, "Initializing catalog"); initcat(); /* Initialize XML data */ if (prefs.xml_flag || prefs.cat_type==ASCII_VO) init_xml(next); /* Go through all images */ /* for all images in an MEF */ /*---- Initial time measurement*/ time(&thetime1); thecat.currext = nok+1; dfield = field = wfield = dwfield = NULL; /*---- Init the Detection and Measurement-images */ if (prefs.dimage_flag) { dfield = newfield(prefs.image_name[0], DETECT_FIELD, nok); field = newfield(prefs.image_name[1], MEASURE_FIELD, nok); if ((field->width!=dfield->width) || (field->height!=dfield->height)) error(EXIT_FAILURE, "*Error*: Frames have different sizes",""); /*---- Prepare interpolation */ if (prefs.dweight_flag && prefs.interp_type[0] == INTERP_ALL) init_interpolate(dfield, -1, -1); if (prefs.interp_type[1] == INTERP_ALL) init_interpolate(field, -1, -1); } else { field = newfield(prefs.image_name[0], DETECT_FIELD | MEASURE_FIELD, nok); /*-- Prepare interpolation */ if ((prefs.dweight_flag || prefs.weight_flag) && prefs.interp_type[0] == INTERP_ALL) init_interpolate(field, -1, -1); /* 0.0 or anything else */ } /*-- Init the WEIGHT-images */ if (prefs.dweight_flag || prefs.weight_flag) { weightenum wtype; PIXTYPE interpthresh; if (prefs.nweight_type>1) { /*------ Double-weight-map mode */ if (prefs.weight_type[1] != WEIGHT_NONE) { /*-------- First: the "measurement" weights */ wfield = newweight(prefs.wimage_name[1],field,prefs.weight_type[1], nok); wtype = prefs.weight_type[1]; interpthresh = prefs.weight_thresh[1]; /*-------- Convert the interpolation threshold to variance units */ weight_to_var(wfield, &interpthresh, 1); wfield->weight_thresh = interpthresh; if (prefs.interp_type[1] != INTERP_NONE) init_interpolate(wfield, prefs.interp_xtimeout[1], prefs.interp_ytimeout[1]); } /*------ The "detection" weights */ if (prefs.weight_type[0] != WEIGHT_NONE) { interpthresh = prefs.weight_thresh[0]; if (prefs.weight_type[0] == WEIGHT_FROMINTERP) { dwfield=newweight(prefs.wimage_name[0],wfield,prefs.weight_type[0], nok); weight_to_var(wfield, &interpthresh, 1); } else { dwfield = newweight(prefs.wimage_name[0], dfield?dfield:field, prefs.weight_type[0], nok); weight_to_var(dwfield, &interpthresh, 1); } dwfield->weight_thresh = interpthresh; if (prefs.interp_type[0] != INTERP_NONE) init_interpolate(dwfield, prefs.interp_xtimeout[0], prefs.interp_ytimeout[0]); } } else { /*------ Single-weight-map mode */ wfield = newweight(prefs.wimage_name[0], dfield?dfield:field, prefs.weight_type[0], nok); wtype = prefs.weight_type[0]; interpthresh = prefs.weight_thresh[0]; /*------ Convert the interpolation threshold to variance units */ weight_to_var(wfield, &interpthresh, 1); wfield->weight_thresh = interpthresh; if (prefs.interp_type[0] != INTERP_NONE) init_interpolate(wfield, prefs.interp_xtimeout[0], prefs.interp_ytimeout[0]); } } /*-- Init the FLAG-images */ for (i=0; i<prefs.nimaflag; i++) { pffield[i] = newfield(prefs.fimage_name[i], FLAG_FIELD, nok); if ((pffield[i]->width!=field->width) || (pffield[i]->height!=field->height)) error(EXIT_FAILURE, "*Error*: Incompatible FLAG-map size in ", prefs.fimage_name[i]); } /*-- Compute background maps for `standard' fields */ QPRINTF(OUTPUT, dfield? "Measurement image:" : "Detection+Measurement image: "); makeback(field, wfield, prefs.wscale_flag[1]); QPRINTF(OUTPUT, (dfield || (dwfield&&dwfield->flags^INTERP_FIELD))? "(M) " "Background: %-10g RMS: %-10g / Threshold: %-10g \n" : "(M+D) " "Background: %-10g RMS: %-10g / Threshold: %-10g \n", field->backmean, field->backsig, (field->flags & DETECT_FIELD)? field->dthresh: field->thresh); if (dfield) { QPRINTF(OUTPUT, "Detection image: "); makeback(dfield, dwfield? dwfield : (prefs.weight_type[0] == WEIGHT_NONE?NULL:wfield), prefs.wscale_flag[0]); QPRINTF(OUTPUT, "(D) " "Background: %-10g RMS: %-10g / Threshold: %-10g \n", dfield->backmean, dfield->backsig, dfield->dthresh); } else if (dwfield && dwfield->flags^INTERP_FIELD) { makeback(field, dwfield, prefs.wscale_flag[0]); QPRINTF(OUTPUT, "(D) " "Background: %-10g RMS: %-10g / Threshold: %-10g \n", field->backmean, field->backsig, field->dthresh); } /*-- For interpolated weight-maps, copy the background structure */ if (dwfield && dwfield->flags&(INTERP_FIELD|BACKRMS_FIELD)) copyback(dwfield->reffield, dwfield); if (wfield && wfield->flags&(INTERP_FIELD|BACKRMS_FIELD)) copyback(wfield->reffield, wfield); /*-- Prepare learn and/or associations */ if (prefs.assoc_flag) init_assoc(field); /* initialize assoc tasks */ /*-- Update the CHECK-images */ if (prefs.check_flag) for (i=0; i<MAXCHECK; i++) if ((check=prefs.check[i])) reinitcheck(field, check); if (!forcextflag && nok>1) { if (prefs.psf_flag) { /*------ Read other PSF extensions */ NFPRINTF(OUTPUT, "Reading PSF information"); psf_end(thepsf, thepsfit); if (prefs.dpsf_flag) { psf_end(thedpsf, thedpsfit); thedpsf = psf_load(prefs.psf_name[0], nok); thepsf = psf_load(prefs.psf_name[1], nok); } else thepsf = psf_load(prefs.psf_name[0], nok); } #ifdef USE_MODEL if (prefs.prof_flag) { /*------ Create profiles at full resolution */ profit_end(theprofit); theprofit = profit_init(thepsf, modeltype); if (prefs.dprof_flag) { profit_end(thedprofit); thedprofit = profit_init(thedpsf, modeltype); } if (prefs.pattern_flag) { pattern = pattern_init(theprofit, prefs.pattern_type, npat0); pattern_end(pattern); } if (FLAG(obj2.prof_concentration)|FLAG(obj2.prof_concentration)) { profit_end(thepprofit); profit_end(theqprofit); thepprofit = profit_init(thepsf, MODEL_DIRAC); theqprofit = profit_init(thepsf, MODEL_EXPONENTIAL); } } #endif } /*-- Initialize PSF contexts and workspace */ if (prefs.psf_flag) { psf_readcontext(thepsf, field); psf_init(); if (prefs.dpsf_flag) { psf_readcontext(thepsf, dfield); psf_init(); } } /*-- Copy field structures to static ones (for catalog info) */ if (dfield) { thefield1 = *field; thefield2 = *dfield; } else thefield1 = thefield2 = *field; if (wfield) { thewfield1 = *wfield; thewfield2 = dwfield? *dwfield: *wfield; } else if (dwfield) thewfield2 = *dwfield; reinitcat(field); /*-- Start the extraction pipeline */ NFPRINTF(OUTPUT, "Scanning image"); scanimage(field, dfield, pffield, prefs.nimaflag, wfield, dwfield); NFPRINTF(OUTPUT, "Closing files"); /*-- Finish the current CHECK-image processing */ if (prefs.check_flag) for (i=0; i<MAXCHECK; i++) if ((check=prefs.check[i])) reendcheck(field, check); /*-- Final time measurements*/ if (time(&thetime2)!=-1) { if (!strftime(thecat.ext_date, 12, "%d/%m/%Y", localtime(&thetime2))) error(EXIT_FAILURE, "*Internal Error*: Date string too long ",""); if (!strftime(thecat.ext_time, 10, "%H:%M:%S", localtime(&thetime2))) error(EXIT_FAILURE, "*Internal Error*: Time/date string too long ",""); thecat.ext_elapsed = difftime(thetime2, thetime1); } reendcat(); /* Update XML data */ if (prefs.xml_flag || prefs.cat_type==ASCII_VO) update_xml(&thecat, dfield? dfield:field, field, dwfield? dwfield:wfield, wfield); /*-- Close ASSOC routines */ end_assoc(field); for (i=0; i<prefs.nimaflag; i++) endfield(pffield[i]); endfield(field); if (dfield) endfield(dfield); if (wfield) endfield(wfield); if (dwfield) endfield(dwfield); QPRINTF(OUTPUT, " Objects: detected %-8d / sextracted %-8d \n\n", thecat.ndetect, thecat.ntotal); /* End look around all images in an MEF */ if (nok<0) error(EXIT_FAILURE, "Not enough valid FITS image extensions in ", prefs.image_name[0]); NFPRINTF(OUTPUT, "Closing files"); /* End CHECK-image processing */ if (prefs.check_flag) for (i=0; i<MAXCHECK; i++) { if ((check=prefs.check[i])) endcheck(check); prefs.check[i] = NULL; } if (prefs.filter_flag) endfilter(); if (prefs.somfit_flag) som_end(thesom); if (prefs.growth_flag) endgrowth(); #ifdef USE_MODEL if (prefs.prof_flag) { profit_end(theprofit); if (prefs.dprof_flag) profit_end(thedprofit); if (FLAG(obj2.prof_concentration)|FLAG(obj2.prof_concentration)) { profit_end(thepprofit); profit_end(theqprofit); } fft_end(); } #endif if (prefs.psf_flag) psf_end(thepsf, thepsfit); if (prefs.dpsf_flag) psf_end(thedpsf, thedpsfit); if (FLAG(obj2.sprob)) neurclose(); /* Processing end date and time */ thetimet2 = time(NULL); tm = localtime(&thetimet2); sprintf(prefs.sdate_end,"%04d-%02d-%02d", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday); sprintf(prefs.stime_end,"%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec); prefs.time_diff = counter_seconds() - dtime; /* Write XML */ if (prefs.xml_flag) write_xml(prefs.xml_name); endcat((char *)NULL); if (prefs.xml_flag || prefs.cat_type==ASCII_VO) end_xml(); /* Free FITS headers (now catalogues are closed). */ if (field->fitsheadsize > 0) { free(field->fitshead); } return; }
void makeit(void) { wcsstruct *wcs; fieldstruct **fields, *field; psfstruct **cpsf, *psf; setstruct *set, *set2; contextstruct *context, *fullcontext; struct tm *tm; char str[MAXCHAR]; char **incatnames, *pstr; float **psfbasiss, *psfsteps, *psfbasis, *basis, psfstep, step; int c,i,p, ncat, ext, next, nmed, nbasis; /* Install error logging */ error_installfunc(write_error); incatnames = prefs.incat_name; ncat = prefs.ncat; /* Processing start date and time */ thetime = time(NULL); tm = localtime(&thetime); sprintf(prefs.sdate_start,"%04d-%02d-%02d", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday); sprintf(prefs.stime_start,"%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec); NFPRINTF(OUTPUT, ""); QPRINTF(OUTPUT, "----- %s %s started on %s at %s with %d thread%s\n\n", BANNER, MYVERSION, prefs.sdate_start, prefs.stime_start, prefs.nthreads, prefs.nthreads>1? "s":""); /* End here if no filename has been provided */ if (!ncat) { /*-- Processing end date and time */ thetime2 = time(NULL); tm = localtime(&thetime2); sprintf(prefs.sdate_end,"%04d-%02d-%02d", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday); sprintf(prefs.stime_end,"%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec); prefs.time_diff = difftime(thetime2, thetime); /*-- Write XML */ if (prefs.xml_flag) { init_xml(0); write_xml(prefs.xml_name); end_xml(); } return; } /* Create an array of PSFs (one PSF for each extension) */ QMALLOC(fields, fieldstruct *, ncat); NFPRINTF(OUTPUT, ""); QPRINTF(OUTPUT, "----- %d input catalogues:\n", ncat); for (c=0; c<ncat; c++) { fields[c] = field_init(incatnames[c]); QPRINTF(OUTPUT, "%-20.20s: \"%-16.16s\" %3d extension%s %7d detection%s\n", fields[c]->rcatname, fields[c]->ident, fields[c]->next, fields[c]->next>1 ? "s":"", fields[c]->ndet, fields[c]->ndet>1 ? "s":""); } QPRINTF(OUTPUT, "\n"); if (prefs.xml_flag) init_xml(ncat); makeit_body(fields, &context, &fullcontext, 1); next = fields[0]->next; /* Write XML */ if (prefs.xml_flag) { NFPRINTF(OUTPUT, "Writing XML file..."); write_xml(prefs.xml_name); end_xml(); } /* Save result */ for (c=0; c<ncat; c++) { sprintf(str, "Saving PSF model and metadata for %s...", fields[c]->rtcatname); NFPRINTF(OUTPUT, str); /*-- Create a file name with a "PSF" extension */ if (*prefs.psf_dir) { if ((pstr = strrchr(incatnames[c], '/'))) pstr++; else pstr = incatnames[c]; sprintf(str, "%s/%s", prefs.psf_dir, pstr); } else strcpy(str, incatnames[c]); if (!(pstr = strrchr(str, '.'))) pstr = str+strlen(str); sprintf(pstr, "%s", prefs.psf_suffix); field_psfsave(fields[c], str); /* Create homogenisation kernels */ if (prefs.homobasis_type != HOMOBASIS_NONE) { for (ext=0; ext<next; ext++) { if (next>1) sprintf(str, "Computing homogenisation kernel for %s[%d/%d]...", fields[c]->rtcatname, ext+1, next); else sprintf(str, "Computing homogenisation kernel for %s...", fields[c]->rtcatname); NFPRINTF(OUTPUT, str); if (*prefs.homokernel_dir) { if ((pstr = strrchr(incatnames[c], '/'))) pstr++; else pstr = incatnames[c]; sprintf(str, "%s/%s", prefs.homokernel_dir, pstr); } else strcpy(str, incatnames[c]); if (!(pstr = strrchr(str, '.'))) pstr = str+strlen(str); sprintf(pstr, "%s", prefs.homokernel_suffix); psf_homo(fields[c]->psf[ext], str, prefs.homopsf_params, prefs.homobasis_number, prefs.homobasis_scale, ext, next); } } #ifdef HAVE_PLPLOT /* Plot diagnostic maps for all catalogs */ cplot_ellipticity(fields[c]); cplot_fwhm(fields[c]); cplot_moffatresi(fields[c]); cplot_asymresi(fields[c]); cplot_counts(fields[c]); cplot_countfrac(fields[c]); cplot_modchi2(fields[c]); cplot_modresi(fields[c]); #endif /*-- Update XML */ if (prefs.xml_flag) update_xml(fields[c]); } /* Processing end date and time */ thetime2 = time(NULL); tm = localtime(&thetime2); sprintf(prefs.sdate_end,"%04d-%02d-%02d", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday); sprintf(prefs.stime_end,"%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec); prefs.time_diff = difftime(thetime2, thetime); /* Free memory */ for (c=0; c<ncat; c++) field_end(fields[c]); free(fields); if (context->npc) context_end(fullcontext); context_end(context); return; }