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

Adding support for NetCDF #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

krijesta
Copy link

NetCDF is a binary data format used generally for storing array based scientific data. It has tools to decode and encode it to a text representation (CDL) so this change allows editing of the binary files from a text editor.

I realise that this is a little off topic for the original image editing use of this plugin but fits very easily into the framework that is there so I thought that it was nicer to add it to this plugin rather than creating a new one. Let me know if you don't want to pull this in and I'll see about creating my own plugin.

@tpope
Copy link
Owner

tpope commented Jul 12, 2012

I suppose I don't see much harm in adding support.

Can your use of cat be replaced with an argument instead? No sense tying to UNIX unnecessarily.

Let's drop the redirect of stderr as well. It only works with the Bourne shell.

@krijesta
Copy link
Author

Unfortunately I can't easily replace cat as ncgen expects ncgen -o out_file in_file and the printf replaces in_file then out_file in the string (out_file needs to be seekable so it can't be stdout/redirected, but in_file looks at stdin if not given on the command line) - changing AfterImageReadPost() to take an argument which specifies the order to replace them in seemed more complex than the cat

I didn't realise that stderr redirections weren't the same in all shell (I've only ever really used bash) so I'll remove it. However that means that an error that occurs on reading the file will just result in a blank page with no error message. When writing out the file you have the following in AfterimageWriteCmd()

call system(printf(a:cmd,s:esc(tmp1),s:esc(tmp2)))
if !v:shell_error
  call rename(tmp2, nm)
  setlocal nomodified
else
  echohl ErrorMsg
  echo "An error occured while trying to convert the file."
  echohl NONE
endif

Should there be a similar check in AfterImageReadPost()?

This adds support to edit NetCDF files, they get converted to cdl when
reading and writen back to NetCDF when writing using the NCO tools. You
will need netcdf installed for this to work
@denzuko
Copy link

denzuko commented Sep 24, 2023

That's going to need a major rewrite of the upstream tool. They expressly create their own file open function. I'm sure there's ways to script around that and even using /dev/stdin but that's locking into UNIX's way of doing things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants