Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy gmt.conf if movie or batch detects one in current directory #4781

Merged
merged 2 commits into from Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/rst/source/batch.rst
Expand Up @@ -177,6 +177,15 @@ as well as any new files produced by *mainscript* or the optional scripts set vi
No path specification is needed to access these files. Other files may
require full paths unless their directories were already included in the :term:`DIR_DATA` setting.

Custom gmt.conf files
---------------------

If you have a gmt.conf file in the top directory with your main script prior to running **batch** then it will be
used and shared across all the scripts created and executed *unless* your scripts use **-C** when starting a new
modern mode session. The preferred ways of changing GMT defaults is via :doc:`gmtset` calls in your input scripts.
**Note**: Each script is run in isolation (modern) mode so trying to create a gmt.conf file via the *preflight*
script to be used by other scripts is futile.

Constructing the Main Script
----------------------------

Expand Down
9 changes: 9 additions & 0 deletions doc/rst/source/movie.rst
Expand Up @@ -326,6 +326,15 @@ as well as any new files produced by *mainscript* or the optional scripts set vi
No path specification is needed to access these files. Other files may
require full paths unless their directories were already included in the :term:`DIR_DATA` setting.

Custom gmt.conf files
---------------------

If you have a gmt.conf file in the top directory with your main script prior to running **movie** then it will be
used and shared across all the scripts created and executed *unless* your scripts use **-C** when starting a new
modern mode session. The preferred ways of changing GMT defaults is via :doc:`gmtset` calls in your input scripts.
**Note**: Each script is run in isolation (modern) mode so trying to create a gmt.conf file via the *preflight*
script to be used by other scripts is futile.

Plotting Temporal Changes
-------------------------

Expand Down
14 changes: 12 additions & 2 deletions src/batch.c
Expand Up @@ -396,16 +396,17 @@ EXTERN_MSC int GMT_batch (void *V_API, int mode, void *args) {
unsigned int n_values = 0, n_jobs = 0, job, i_job, col, k, n_cores_unused, n_to_run;
unsigned int n_jobs_not_started = 0, n_jobs_completed = 0, first_job = 0, data_job;

bool done = false, n_written = false, has_text = false, is_classic = false;
bool done = false, n_written = false, has_text = false, is_classic = false, has_conf = false;

static char *extension[3] = {"sh", "csh", "bat"}, *load[3] = {"source", "source", "call"}, var_token[4] = "$$%";
static char *rmdir[3] = {"rm -rf", "rm -rf", "rd /s /q"}, *export[3] = {"export ", "setenv ", ""};
static char *mvfile[3] = {"mv -f", "mv -f", "move /Y"}, *sc_call[3] = {"bash ", "csh ", "start /B"};
static char *createfile[3] = {"touch", "touch", "copy /b NUL"}, *rmfile[3] = {"rm -f", "rm -f", "del"};
static char *cpconf[3] = {"cp -f %s .", "cp -f %s .", "copy %s ."};

char init_file[PATH_MAX] = {""}, state_tag[GMT_LEN16] = {""}, state_prefix[GMT_LEN64] = {""}, param_file[PATH_MAX] = {""};
char pre_file[PATH_MAX] = {""}, post_file[PATH_MAX] = {""}, main_file[PATH_MAX] = {""}, line[PATH_MAX] = {""};
char string[GMT_LEN128] = {""}, cmd[GMT_LEN256] = {""}, cleanup_file[PATH_MAX] = {""}, cwd[PATH_MAX] = {""};
char string[GMT_LEN128] = {""}, cmd[GMT_LEN256] = {""}, cleanup_file[PATH_MAX] = {""}, cwd[PATH_MAX] = {""}, conf_file[PATH_MAX];
char completion_file[PATH_MAX] = {""}, topdir[PATH_MAX] = {""}, workdir[PATH_MAX] = {""}, datadir[PATH_MAX] = {""};

double percent = 0.0;
Expand Down Expand Up @@ -483,6 +484,12 @@ EXTERN_MSC int GMT_batch (void *V_API, int mode, void *args) {
}
gmt_replace_backslash_in_path (topdir);

if (!access ("gmt.conf", R_OK)) { /* User has a gmt.conf file in the top directory that needs to be shared with the jobs */
has_conf = true;
sprintf (conf_file, "%s/gmt.conf", topdir);
gmt_replace_backslash_in_path (conf_file);
}

/* Create a working directory which will house every local file and all subdirectories created */
if (gmt_mkdir (workdir)) {
GMT_Report (API, GMT_MSG_ERROR, "An old directory named %s exists OR we were unable to create new working directory %s - exiting.\n", workdir, workdir);
Expand Down Expand Up @@ -570,6 +577,7 @@ EXTERN_MSC int GMT_batch (void *V_API, int mode, void *args) {
while (gmt_fgets (GMT, line, PATH_MAX, Ctrl->S[BATCH_PREFLIGHT].fp)) { /* Read the preflight script and copy to the temporary preflight script with some exceptions */
if (gmt_is_gmtmodule (line, "begin")) { /* Need to insert the DIR_DATA statement */
fprintf (fp, "%s", line);
if (has_conf && !strstr (line, "-C")) fprintf (fp, cpconf[Ctrl->In.mode], conf_file);
fprintf (fp, "\tgmt set DIR_DATA \"%s\"\n", datadir);
}
else if (!strstr (line, "#!/")) { /* Skip any leading shell incantation since already placed by gmt_set_script */
Expand Down Expand Up @@ -705,6 +713,7 @@ EXTERN_MSC int GMT_batch (void *V_API, int mode, void *args) {
while (gmt_fgets (GMT, line, PATH_MAX, Ctrl->S[BATCH_POSTFLIGHT].fp)) { /* Read the postflight script and copy to the temporary postflight script with some exceptions */
if (gmt_is_gmtmodule (line, "begin")) {
fprintf (fp, "%s", line); /* Allow args since the script may make a plot */
if (has_conf && !strstr (line, "-C")) fprintf (fp, cpconf[Ctrl->In.mode], conf_file);
fprintf (fp, "\tgmt set DIR_DATA \"%s\"\n", datadir);
}
else if (!strstr (line, "#!/")) { /* Skip any leading shell incantation since already placed */
Expand Down Expand Up @@ -794,6 +803,7 @@ EXTERN_MSC int GMT_batch (void *V_API, int mode, void *args) {
while (gmt_fgets (GMT, line, PATH_MAX, Ctrl->In.fp)) { /* Read the main script and copy to loop script, with some exceptions */
if (gmt_is_gmtmodule (line, "begin")) { /* Must insert DIR_DATA setting */
fprintf (fp, "%s", line);
if (has_conf && !strstr (line, "-C")) fprintf (fp, cpconf[Ctrl->In.mode], conf_file);
fprintf (fp, "\tgmt set DIR_DATA \"%s\"\n", datadir);
}
else if (!strstr (line, "#!/")) { /* Skip any leading shell incantation since already placed */
Expand Down
17 changes: 15 additions & 2 deletions src/movie.c
Expand Up @@ -1221,19 +1221,20 @@ EXTERN_MSC int GMT_movie (void *V_API, int mode, void *args) {
unsigned int n_frames_not_started = 0, n_frames_completed = 0, first_frame = 0, data_frame, n_cores_unused, n_fade_frames = 0;
unsigned int dd, hh, mm, ss, start, flavor[2] = {0, 0};

bool done = false, layers = false, one_frame = false, upper_case[2] = {false, false};
bool done = false, layers = false, one_frame = false, upper_case[2] = {false, false}, has_conf = false;
bool n_written = false, has_text = false, is_classic = false, place_background = false;

static char *movie_raster_format[2] = {"png", "PNG"}, *img_type[2] = {"opaque", "transparent"};
static char *extension[3] = {"sh", "csh", "bat"}, *load[3] = {"source", "source", "call"}, *rmfile[3] = {"rm -f", "rm -f", "del"};
static char *rmdir[3] = {"rm -rf", "rm -rf", "rd /s /q"}, *export[3] = {"export ", "setenv ", ""};
static char *mvfile[3] = {"mv -f", "mv -f", "move"}, *sc_call[3] = {"bash ", "csh ", "start /B"}, var_token[4] = "$$%";
static char *cpconf[3] = {"cp -f %s .", "cp -f %s .", "copy %s ."};

char init_file[PATH_MAX] = {""}, state_tag[GMT_LEN16] = {""}, state_prefix[GMT_LEN64] = {""}, param_file[PATH_MAX] = {""}, cwd[PATH_MAX] = {""};
char pre_file[PATH_MAX] = {""}, post_file[PATH_MAX] = {""}, main_file[PATH_MAX] = {""}, line[PATH_MAX] = {""}, version[GMT_LEN32] = {""};
char string[GMT_LEN128] = {""}, extra[GMT_LEN256] = {""}, cmd[GMT_LEN256] = {""}, cleanup_file[PATH_MAX] = {""}, L_txt[GMT_LEN128] = {""};
char png_file[PATH_MAX] = {""}, topdir[PATH_MAX] = {""}, workdir[PATH_MAX] = {""}, datadir[PATH_MAX] = {""}, frame_products[GMT_LEN32] = {""};
char intro_file[PATH_MAX] = {""}, *script_file = NULL, dir_sep = '/', which[2] = {"LP"}, spacer;
char intro_file[PATH_MAX] = {""}, conf_file[PATH_MAX], *script_file = NULL, dir_sep = '/', which[2] = {"LP"}, spacer;

double percent = 0.0, L_col = 0, sx, sy, fade_level = 0.0;

Expand Down Expand Up @@ -1417,6 +1418,12 @@ EXTERN_MSC int GMT_movie (void *V_API, int mode, void *args) {
}
}

if (!access ("gmt.conf", R_OK)) { /* User has a gmt.conf file in the top directory that needs to be shared with the jobs */
has_conf = true;
sprintf (conf_file, "%s/gmt.conf", topdir);
gmt_replace_backslash_in_path (conf_file);
}

/* Create a working directory which will house every local file and all subdirectories created */
if (gmt_mkdir (workdir)) {
GMT_Report (API, GMT_MSG_ERROR, "Unable to create new working directory %s - exiting.\n", workdir);
Expand Down Expand Up @@ -1510,6 +1517,7 @@ EXTERN_MSC int GMT_movie (void *V_API, int mode, void *args) {
while (gmt_fgets (GMT, line, PATH_MAX, Ctrl->S[MOVIE_PREFLIGHT].fp)) { /* Read the background script and copy to preflight script with some exceptions */
if (gmt_is_gmtmodule (line, "begin")) { /* Need to insert gmt figure after this line (or as first line) in case a background plot will be made */
fprintf (fp, "gmt begin\n"); /* To ensure there are no args here since we are using gmt figure instead */
if (has_conf && !strstr (line, "-C")) fprintf (fp, cpconf[Ctrl->In.mode], conf_file);
gmt_set_comment (fp, Ctrl->In.mode, "\tSet fixed background output ps name");
fprintf (fp, "\tgmt figure movie_background ps\n");
fprintf (fp, "\tgmt set PS_MEDIA %g%cx%g%c\n", Ctrl->C.dim[GMT_X], Ctrl->C.unit, Ctrl->C.dim[GMT_Y], Ctrl->C.unit);
Expand Down Expand Up @@ -1665,6 +1673,7 @@ EXTERN_MSC int GMT_movie (void *V_API, int mode, void *args) {
while (gmt_fgets (GMT, line, PATH_MAX, Ctrl->S[MOVIE_POSTFLIGHT].fp)) { /* Read the foreground script and copy to postflight script with some exceptions */
if (gmt_is_gmtmodule (line, "begin")) { /* Need to insert gmt figure after this line */
fprintf (fp, "gmt begin\n"); /* Ensure there are no args here since we are using gmt figure instead */
if (has_conf && !strstr (line, "-C")) fprintf (fp, cpconf[Ctrl->In.mode], conf_file);
gmt_set_comment (fp, Ctrl->In.mode, "\tSet fixed foreground output ps name");
fprintf (fp, "\tgmt figure movie_foreground ps\n");
fprintf (fp, "\tgmt set PS_MEDIA %g%cx%g%c\n", Ctrl->C.dim[GMT_X], Ctrl->C.unit, Ctrl->C.dim[GMT_Y], Ctrl->C.unit);
Expand Down Expand Up @@ -1825,6 +1834,7 @@ EXTERN_MSC int GMT_movie (void *V_API, int mode, void *args) {
while (gmt_fgets (GMT, line, PATH_MAX, Ctrl->E.fp)) { /* Read the main script and copy to loop script, with some exceptions */
if (gmt_is_gmtmodule (line, "begin")) { /* Need to insert a gmt figure call after this line */
fprintf (fp, "gmt begin\n"); /* Ensure there are no args here since we are using gmt figure instead */
if (has_conf && !strstr (line, "-C")) fprintf (fp, cpconf[Ctrl->In.mode], conf_file);
gmt_set_comment (fp, Ctrl->In.mode, "\tSet output PNG name and plot conversion parameters");
fprintf (fp, "\tgmt set PS_MEDIA %g%cx%g%c\n", Ctrl->C.dim[GMT_X], Ctrl->C.unit, Ctrl->C.dim[GMT_Y], Ctrl->C.unit);
fprintf (fp, "\tgmt figure ../%s %s", gmt_place_var (Ctrl->In.mode, "MOVIE_NAME"), frame_products);
Expand Down Expand Up @@ -2126,6 +2136,7 @@ EXTERN_MSC int GMT_movie (void *V_API, int mode, void *args) {
while (gmt_fgets (GMT, line, PATH_MAX, Ctrl->E.fp)) { /* Read the main script and copy to loop script, with some exceptions */
if (gmt_is_gmtmodule (line, "begin")) { /* Need to insert a gmt figure call after this line */
fprintf (fp, "gmt begin\n"); /* Ensure there are no args here since we are using gmt figure instead */
if (has_conf && !strstr (line, "-C")) fprintf (fp, cpconf[Ctrl->In.mode], conf_file);
gmt_set_comment (fp, Ctrl->In.mode, "\tSet output name and plot conversion parameters");
fprintf (fp, "\tgmt figure %s %s", Ctrl->N.prefix, Ctrl->M.format);
fprintf (fp, " %s", extra);
Expand All @@ -2148,6 +2159,7 @@ EXTERN_MSC int GMT_movie (void *V_API, int mode, void *args) {
while (gmt_fgets (GMT, line, PATH_MAX, Ctrl->In.fp)) { /* Read the mainscript and copy to loop script, with some exceptions */
if (gmt_is_gmtmodule (line, "begin")) { /* Need to insert a gmt figure call after this line */
fprintf (fp, "gmt begin\n"); /* Ensure there are no args here since we are using gmt figure instead */
if (has_conf && !strstr (line, "-C")) fprintf (fp, cpconf[Ctrl->In.mode], conf_file);
gmt_set_comment (fp, Ctrl->In.mode, "\tSet output name and plot conversion parameters");
fprintf (fp, "\tgmt figure %s %s", Ctrl->N.prefix, Ctrl->M.format);
fprintf (fp, " %s", extra);
Expand Down Expand Up @@ -2276,6 +2288,7 @@ EXTERN_MSC int GMT_movie (void *V_API, int mode, void *args) {
while (gmt_fgets (GMT, line, PATH_MAX, Ctrl->In.fp)) { /* Read the main script and copy to loop script, with some exceptions */
if (gmt_is_gmtmodule (line, "begin")) { /* Need to insert a gmt figure call after this line */
fprintf (fp, "gmt begin\n"); /* Ensure there are no args here since we are using gmt figure instead */
if (has_conf && !strstr (line, "-C")) fprintf (fp, cpconf[Ctrl->In.mode], conf_file);
gmt_set_comment (fp, Ctrl->In.mode, "\tSet output PNG name and plot conversion parameters");
fprintf (fp, "\tgmt figure ../%s %s", gmt_place_var (Ctrl->In.mode, "MOVIE_NAME"), frame_products);
fprintf (fp, " E%s,%s", gmt_place_var (Ctrl->In.mode, "MOVIE_DPU"), extra);
Expand Down