MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / GMT_batch

Function GMT_batch

src/batch.c:473–1101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

471#define Return(code) {Free_Ctrl (GMT, Ctrl); gmt_end_module (GMT, GMT_cpy); bailout (code);}
472
473EXTERN_MSC int GMT_batch (void *V_API, int mode, void *args) {
474 int error = 0, precision;
475 int (*run_script)(const char *); /* pointer to system function or a dummy */
476
477 size_t P_len = 0;
478
479 unsigned int n_values = 0, n_jobs = 0, job, i_job, col, k, n_cores_unused, n_to_run, n_fmts = 0;
480 unsigned int n_jobs_not_started = 0, n_jobs_completed = 0, first_i_job = 0, data_job;
481
482 bool done = false, n_written = false, has_text = false, is_classic = false, has_conf = false;
483 bool got_time_file = false, issue_col0_par = false;
484
485 static char *extension[3] = {"sh", "csh", "bat"}, *load[3] = {"source", "source", "call"}, var_token[4] = "$$%";
486 static char *rmdir[3] = {"rm -rf", "rm -rf", "rd /s /q"}, *export[3] = {"export ", "setenv ", ""};
487 static char *mvfile[3] = {"mv -f", "mv -f", "move /Y"};
488 static char *createfile[3] = {"touch", "touch", "copy /b NUL"}, *rmfile[3] = {"rm -f", "rm -f", "del"};
489 static char *cpconf[3] = {"\tcp -f %s .\n", "\tcp -f %s .\n", "\tcopy %s .\n"};
490 static char *sys_cmd_nowait[3] = {"bash", "csh", "start /B"}, *sys_cmd_wait[3] = {"bash", "csh", "cmd /C"};
491
492 char init_file[PATH_MAX] = {""}, state_tag[GMT_LEN16] = {""}, state_prefix[GMT_LEN64] = {""}, param_file[PATH_MAX] = {""};
493 char pre_file[PATH_MAX] = {""}, post_file[PATH_MAX] = {""}, main_file[PATH_MAX] = {""}, line[PATH_MAX] = {""}, tmpwpath[PATH_MAX] = {""};
494 char string[GMT_LEN128] = {""}, cmd[GMT_LEN256] = {""}, cwd[PATH_MAX] = {""}, conf_file[PATH_MAX];
495 char completion_file[PATH_MAX] = {""}, topdir[PATH_MAX] = {""}, workdir[PATH_MAX] = {""}, datadir[PATH_MAX] = {""};
496
497 char **work_files = NULL;
498
499 double percent = 0.0;
500
501 FILE *fp = NULL;
502
503 struct GMT_CTRL *GMT = NULL, *GMT_cpy = NULL;
504 struct GMT_DATASET *D = NULL;
505 struct GMT_OPTION *options = NULL;
506 struct BATCH_STATUS *status = NULL;
507 struct BATCH_CTRL *Ctrl = NULL;
508 struct GMTAPI_CTRL *API = gmt_get_api_ptr (V_API); /* Cast from void to GMTAPI_CTRL pointer */
509
510 /*----------------------- Standard module initialization and parsing ----------------------*/
511
512 if (API == NULL) return (GMT_NOT_A_SESSION);
513 if (mode == GMT_MODULE_PURPOSE) return (usage (API, GMT_MODULE_PURPOSE)); /* Return the purpose of program */
514 options = GMT_Create_Options (API, mode, args); if (API->error) return (API->error); /* Set or get option list */
515
516 if ((error = gmt_report_usage (API, options, 0, usage)) != GMT_NOERROR) bailout (error); /* Give usage if requested */
517
518 /* Parse the command-line arguments */
519
520 if ((GMT = gmt_init_module (API, THIS_MODULE_LIB, THIS_MODULE_CLASSIC_NAME, THIS_MODULE_KEYS, THIS_MODULE_NEEDS, module_kw, &options, &GMT_cpy)) == NULL) bailout (API->error); /* Save current state */
521 if (GMT_Parse_Common (API, THIS_MODULE_OPTIONS, options)) Return (API->error);
522 Ctrl = New_Ctrl (GMT); /* Allocate and initialize a new control structure */
523 if ((error = parse (GMT, Ctrl, options)) != 0) Return (error);
524
525 /*---------------------------- This is the batch main code ----------------------------*/
526
527 if (Ctrl->Q.scripts) { /* No batch will be run, but scripts will be produced */
528 GMT_Report (API, GMT_MSG_INFORMATION, "Dry-run enabled - Processing scripts will be created and any pre/post-flight scripts will be executed.\n");
529 if (Ctrl->M.active) GMT_Report (API, GMT_MSG_INFORMATION, "A single script for job %d will be created and executed\n", Ctrl->M.job);
530 run_script = gmt_dry_run_only; /* This prevents the main job loop from executing the script */

Callers

nothing calls this directly

Calls 15

gmt_get_api_ptrFunction · 0.85
GMT_Create_OptionsFunction · 0.85
gmt_report_usageFunction · 0.85
gmt_init_moduleFunction · 0.85
GMT_Parse_CommonFunction · 0.85
GMT_ReportFunction · 0.85
gmt_accessFunction · 0.85
GMT_Read_DataFunction · 0.85
batch_close_filesFunction · 0.85
gmt_strrepcFunction · 0.85
gmt_mkdirFunction · 0.85

Tested by

no test coverage detected