-
Notifications
You must be signed in to change notification settings - Fork 359
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
WIP: Add option to not create a temporary EPS file but instead edit the original PS. #8417
base: master
Are you sure you want to change the base?
Conversation
May I ask why things are done this way? (Doing the EPS-stuff, instead of using the PS, as is the goal here) |
There are things I don't know. Namely, why GMT PS have a |
Thanks @joa-quim. |
Not sure if I'm using it correctly, but it crashes for the following command:
|
Oh ghrrr. That works fine for me on Windows. Can you try it with a debug build. Maybe the stack trace will be more informative. |
Just tried the debug build. The stack trace is the same. One question: even if it doesn't crash, does it mean that the original PS file on the disk will be broken since it's edited when calling psconvert? Or the editing is done to the PS file in memory? |
The -! should not break the original PS file but changes it to become equal to what we get with -Te. No in-memory processing though that is already possible when called from Matlab & Julia but I have not tried this in long time.
One idea is that would be useful to the wrappers that don't really care about the original PS. |
Can you check the beginning of the map.ps file and see if any of the BoungingBoxes have been changed? Original
After change
|
There are no changes in the PS file. |
So it must have crashed on lines 2366 or 2368
I'm opening the PS file with |
I tried to add a print statement in the |
Please try again. It was a dumb error in the |
Yes, now it works on Linux, but as I asked before, now I can confirm that the original PS file is actually a EPS file after editing. I'm wondering can we just read the PS file and send it to Ghostscript via stdin, like https://stackoverflow.com/questions/70706765/passing-stdin-to-ghostscript-in-php-proc-open. |
How to test this? Just running a bunch of scripts? |
Well, yes but what I did was to hardwire the -! option by adding a line (~line 1735 of psconvert.c)
and run all the tests. But even all the tests do not probably test everything. |
The The still-in-the-air idea is to one day be able to call the Ghostscript API directly to do these operations. This would free us from the system calls and popen/popen2 troubles. |
And not using popen/popen2 have what benefits? |
The |
Instead of adding
|
@@ -813,6 +816,7 @@ static int usage (struct GMTAPI_CTRL *API, int level) { | |||
"Escape any +? modifier inside strings with \\."); | |||
if (API->GMT->current.setting.run_mode == GMT_CLASSIC) | |||
GMT_Usage (API, 1, "\n-Z Remove input PostScript file(s) after successful conversion."); | |||
GMT_Usage (API, 1, "\n-! Modify the input PS file instead of creating a temp EPS. Some options like -Ng will disable it."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GMT_Usage (API, 1, "\n-! Modify the input PS file instead of creating a temp EPS. Some options like -Ng will disable it."); | |
GMT_Usage (API, 1, "\n-! Modify the input PS file instead of creating a temp EPS. Some options like -Wg will disable it."); |
I think you mean -Wg
, right?
I've tried this branch in PyGMT. Without adding the -!
option, most tests still work, but with -Wg
, I see errors like:
Error: rt [ERROR]: Could not find the 'PROJ' tag in the PS file. No world file created.
Error: rt [ERROR]: This situation occurs when one of the two next cases is true:
Error: rt [ERROR]: 1) the PS file was created with a pre-GMT v4.5.0 version
Error: rt [ERROR]: 2) the PS file was not created by GMT
Is the -!
option enabled by default? I didn't add -!
, so it should not affect any existing tests, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's -Ng
. This and other have to disable the -!
(not possible given the particular option requirements). But we need it better explained and to create a dedicated option to specifically ignore what -!
does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the error is real, thanks. Have to see what to do about it.
It's been a while since I did this. Details are no longer fresh. I'll revisit it later today. |
If I was not wrong at the time I wrote it, yes.
|
Build GMT with /DPS_NO_DUP or use add_definitions(/DPS_NO_DUP) in ConfigUser.cmake
The point is that I was thinking in making this the future behavior, thus independent of any option. |
I thought it was, but it turns out that it wasn't. I set it on by default temporarily to run the test and must have unset it after. But now, with my last commit, we can set this the default behavior by adding Run the tests locally and got a couple more failures but I'm confused because I don't even see why they fail. Another not investigated thing is the effect that this may have on what we talked the other day about the |
This is totally unrelated to this branch as you saw it when |
@seisman Do you understand what is going on with these failures? This branch builds fine for me. |
It has always annoyed me (e., g. #1435) that for running
psconvert
(and before,ps2raster
) we must create a temporary EPS file that is the one we sent through the Ghostscript guts to get our raster file (I hate solutions based on temporary disk files). No big deal if the PS file is small, but far from ideal if it's a hundreds MB file.This PR adds an option to
psconvert
that avoids that by editing the original PS turning it into what before we obtained with EPS temporary file. Due to shortage of letters, excluding the global options we have no more alphabet letters available, that option was made -!, which inspired in the Julia convention that bang (!) symbol is used for data modifying functions.I have also added run time reports via the -Vt option and, a bit disappointingly, it takes big PS files to show small run times differences between master and this PR (I do have a fast SSD disk, is it it?).
Run the tests with an hard-coded -! so that also the modern mode scripts use it and saw no obvious failures, but certainly not all
psconvert
paths were tested. So I would like to ask for more testing on this. If it proves reliable, the idea is to make this PR the default behavior and add some flag as a modifier of an existing option to keep the ancient behavior.PLEASE TEST