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

Allow batch -F to set a more specific naming template #6934

Merged
merged 12 commits into from Aug 3, 2022

Conversation

PaulWessel
Copy link
Member

Rather than have a single running number as the product prefix we may optionally build one from a C-style template and the data columns provided via the -T timefile. This allows products to be named to reflect more than just a running number. E.g. -FE_obl_flex_G%4.2lf_I%4.0lf_%4.1lfk will let me use ${BATCH_NAME}.grd to make more meaningful product names.

This PR also fixes the bug mentioned in #6932 which assumed all product files must have extensions.

Documentation has been updated to reflect the enhancements. Apart from the bug fix, no default behavior has changed.

See #6932 for discussion.  This PR implements a -D option that stops any copying.  This solution does not preempt further consideration of the other suggestion which is to generalize the naming of product files via a -Ftemplate option.
Rather than have a single running number as the product prefix we build one from this template and the -T data.
@PaulWessel PaulWessel added the new core module feature PR that implements a new core module feature label Aug 3, 2022
@PaulWessel PaulWessel added this to the 6.5.0 milestone Aug 3, 2022
@PaulWessel PaulWessel self-assigned this Aug 3, 2022
@PaulWessel PaulWessel changed the title Allow batch _F to set a more specific naming template Allow batch -F to set a more specific naming template Aug 3, 2022
@PaulWessel
Copy link
Member Author

Happy to report that my command

gmt batch main.sh -IE_constants2.sh -Sbpre.sh -W -Tthis_flx_job.txt -NEFLX3 -FE_obl_flex_G%04.2lf_I%04.0lf_%04.1lfk -D

relatively quickly produced 2970 grids with the new naming convention. The batch module is great for these things.

@Esteban82
Copy link
Member

If I use -Fmy_data_%s, it should take the trailing test from the timefile as used as part of the name, right?

@PaulWessel
Copy link
Member Author

Yes, not tested but if your input file has trailing text and there are no other % except %s then that should be what it uses. Let me know if otherwise.

@PaulWessel
Copy link
Member Author

YOu might even be able to give the template as -F%s and have the trialing text have the names you wanted, for example

@Esteban82
Copy link
Member

Ok, I try this script to make a png map for every european country.

If I use -FCountries_%s, then I should get the name of each country with the prefix "Countries_"? Because I didn't

Also, I only could get a map for countries with name with only one word (like "Andorra"), It failed with country like "San Marino".

I got this error

begin [ERROR]: Unrecognized graphics format Marino
gmt [ERROR]: Shared GMT module not found: coast

ERROR: No module named coast was found.  This could mean one of four cases:
  1. There actually is no such module; please check your spelling.
  2. You used a modern mode module name while running in GMT classic mode.
  3. Module exists in the GMT supplemental library, but the library could not be found.
  4. Module exists in a GMT custom library, but none was specified via GMT_CUSTOM_LIBS.
Shared libraries must be in standard system paths or set via environmental parameter LD_LIBRARY_PATH.

gmt [ERROR]: Shared GMT module not found: text

ERROR: No module named text was found.  This could mean one of four cases:
  1. There actually is no such module; please check your spelling.
  2. You used a modern mode module name while running in GMT classic mode.
  3. Module exists in the GMT supplemental library, but the library could not be found.
  4. Module exists in a GMT custom library, but none was specified via GMT_CUSTOM_LIBS.
Shared libraries must be in standard system paths or set via environmental parameter LD_LIBRARY_PATH.

gmt [ERROR]: Not available in classic mode

Full script:

Title=Europe

cat << EOF > pre.sh
gmt begin
    gmt coast -E=EU+l > $Title
gmt end
EOF

cat << EOF > main.sh
gmt begin \${BATCH_WORD1} png
    gmt coast -R\${BATCH_WORD0}+e0.5 -JM10c -Glightgray -Slightblue -B -B+t"\${BATCH_WORD1}" -E\${BATCH_WORD0}+gred+p0.5p
    echo \${BATCH_WORD0} | gmt text -F+f16p+jTL+cTL -Gwhite -W1p
gmt end
EOF

gmt batch main.sh -Sbpre.sh -T$Title+w"\t" -N$Title -Wd -V -Q -FCountries_%s

@PaulWessel
Copy link
Member Author

I dont see you using BATCH_NAME anywhere though?

@PaulWessel
Copy link
Member Author

I would think you need to do

gmt begin ${BATCH_NAME} png
...

@PaulWessel
Copy link
Member Author

The space issue is something I was thinking about for regular numerical stuff too. My first effort had things like %4.1lf and once the argument was < 10 I got a space. So using %04.1lf fixed that. But I was thinking that when -F is used perhaps we should replace any resulting space with underscore.

@PaulWessel
Copy link
Member Author

Now the spaces in BATCH_NAME become underscrores.

@Esteban82
Copy link
Member

Nop. I try with gmt begin \${BATCH_NAME} png and I got:

begin [ERROR]: Unrecognized graphics format San_Marino
gmt [ERROR]: Shared GMT module not found: text

ERROR: No module named text was found.  This could mean one of four cases:
  1. There actually is no such module; please check your spelling.
  2. You used a modern mode module name while running in GMT classic mode.
  3. Module exists in the GMT supplemental library, but the library could not be found.
  4. Module exists in a GMT custom library, but none was specified via GMT_CUSTOM_LIBS.
Shared libraries must be in standard system paths or set via environmental parameter LD_LIBRARY_PATH.

gmt [ERROR]: Not available in classic mode

@PaulWessel
Copy link
Member Author

Right. So the problem is that the input -T file is of course all trailing text but that means you have a single word with a tab in it. I did not consider that case. Now, I replace both spaces and tabs with undercores. Now the parameter file look like this, e.g.

# Parameter file for job 15
BATCH_DIR=Europe_15
BATCH_NAME=Countries_FI_Finland
BATCH_JOB=15
BATCH_ITEM=15
BATCH_TEXT="FI  Finland"
BATCH_WORD0=FI
BATCH_WORD1=Finland

@Esteban82
Copy link
Member

Great.

Now I only got an error with the Vatican City becuse the name has ():

batch_params_51.sh: línea 3: error sintáctico cerca del elemento inesperado `('
batch_params_51.sh: línea 3: `BATCH_NAME=Country_VA_Holy_See_(Vatican_City_State)'
coast [ERROR]: Could not decode +e0.5, return NaN.

@Esteban82
Copy link
Member

# Parameter file for job 51
BATCH_DIR=Europe_51
BATCH_NAME=Country_VA_Holy_See_(Vatican_City_State)
BATCH_JOB=51
BATCH_ITEM=51
BATCH_TEXT="VA	Holy See (Vatican City State)"
BATCH_WORD0=VA
BATCH_WORD1="Holy See (Vatican City State)"

@PaulWessel
Copy link
Member Author

That I cannot fix - needs to be a user fix I think.

@Esteban82
Copy link
Member

Ok. So I think it can be approved.

@PaulWessel PaulWessel merged commit e800da1 into master Aug 3, 2022
@PaulWessel PaulWessel deleted the batch-name-template branch August 3, 2022 20:07
@maxrjones maxrjones added the add-changelog Add PR to the changelog label Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
add-changelog Add PR to the changelog new core module feature PR that implements a new core module feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants