But that results as below
ncap2 -s 'water_sfc=(surface_type\@MetaData == 0)' in.nc out.nc
Command-line script line 1, column 25: unexpected character '\'
But that results as below
ncap2 -s 'water_sfc=(surface_type\@MetaData == 0)' in.nc out.nc
Command-line script line 1, column 25: unexpected character '\'
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Mark,
There is no way in ncap2 to reference a variable with '@' in its name in ncap2 as it uses '@' to denote an attribute e.g time@units.
The best course of action is to rename it to something else , do you ncap2 stuff then rename it back.
....Henry
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That seems definitive. And unfortunate for the user. If it is definitive, please add this restriction to the ncap2 documentation. However, first answer this: Is is possible to modify the ANTLR grammar so that an '@' preceded by a backslash '\@' results in a literal '@' and thus a valid variable name string? At-signs not preceded by a backslash would continue to be treated as the lexical syntax indicating the start of an attribute name.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
HI All,
looking at the NetCDF code - I have extracted the following definitions
Below is from NC_name_check()
And from ncgen3
Looking at the ncap2 Lexer if we keep regular VAR_ID and ATT_ID as they are but modify quoted VAR_ID / ATT_ID.
Charlie since 'th\@' is a valid name - I suggest the following.
Since '/' is an illegal char we could denote a hex code by quoting it with /../ So
'surface_type@MetaData'
becomes
' surface_type/ 0x100/MetaData'
'
And if we wish to rver to the units of the variable it becomes:
' surface_type/ 0x100/MetaData@units'
Also users can use this method for any other UTF8 chars
....Henry
So the conclusion is that an ncname is "kind of UTF8"
Thanks, Henry. That sounds good to me. Please proceed and post back here once you have verified that it works in the current snapshot of master so I can try it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks, Henry. That sounds good to me. Please proceed and post back
here once you have verified that it works in the current snapshot of
master so I can try it.
HI CHarlie,
Don t know what i was thinking !!!! --
We may want to use '/' to reference group variables in ncap2
So I shall have to think soemthing els e up
...Henry
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ye its it fixes the problem at hand but what about a way of inputting a charater code ?
lemme look at the UTF codes - maybe theres another one that netcfd doesnt like .
...Henry
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you've tried the above suggestions and they do not work then I'm afraid you'll need to rename the variable (with ncrename), execute the script, and rename it back. This is why
CF prohibits most special characters (except underscore) in variable names.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
How to handle this kind of variables?
Thanks,
Mark
int surface_type@MetaData(nlocs) ;
ncap2: ERROR att_plain(): Unable to locate attribute surface_type@MetaData in input or output files.
Protect (precede) the
@with a backslash,\@so that ncap2 interprets the@as a literal character and not a syntax character.But that results as below
ncap2 -s 'water_sfc=(surface_type\@MetaData == 0)' in.nc out.nc
Command-line script line 1, column 25: unexpected character '\'
On Thu, Feb 20, 2020 at 1:27 PM Charlie Zender zender@users.sourceforge.net
wrote:
But that results as below
ncap2 -s 'water_sfc=(surface_type\@MetaData == 0)' in.nc out.nc
Command-line script line 1, column 25: unexpected character '\'
try
ncap2 -s 'water_sfc=("surface_type@MetaData" == 0)' in.nc out.nc%ncap2 -s 'water_sfc=("surface_type@MetaData" == 0)' in.nc out.nc
ncap2: ERROR ncap_var_var_op(): Cannot make attribute:~zz@string and variable:~int conform. So cannot perform arithmetic operation.
Sorry, I'm out of ideas. Maybe Henry knows and will chime in.
Hi Mark,
There is no way in ncap2 to reference a variable with '@' in its name in ncap2 as it uses '@' to denote an attribute e.g time@units.
The best course of action is to rename it to something else , do you ncap2 stuff then rename it back.
....Henry
That seems definitive. And unfortunate for the user. If it is definitive, please add this restriction to the ncap2 documentation. However, first answer this: Is is possible to modify the ANTLR grammar so that an '@' preceded by a backslash '\@' results in a literal '@' and thus a valid variable name string? At-signs not preceded by a backslash would continue to be treated as the lexical syntax indicating the start of an attribute name.
ncrename works fine with @ - seems only ncap2 issue
I should add preceded by "\" i.e. needs "\@"
HI All,
looking at the NetCDF code - I have extracted the following definitions
Below is from NC_name_check()
And from ncgen3
Looking at the ncap2 Lexer if we keep regular VAR_ID and ATT_ID as they are but modify quoted VAR_ID / ATT_ID.
Charlie since 'th\@' is a valid name - I suggest the following.
Since '/' is an illegal char we could denote a hex code by quoting it with /../ So
'surface_type@MetaData'
becomes
' surface_type/ 0x100/MetaData'
'
And if we wish to rver to the units of the variable it becomes:
' surface_type/ 0x100/MetaData@units'
Also users can use this method for any other UTF8 chars
....Henry
So the conclusion is that an ncname is "kind of UTF8"
NC_name_check()
Thanks, Henry. That sounds good to me. Please proceed and post back here once you have verified that it works in the current snapshot of master so I can try it.
On 24/02/20 16:25, Charlie Zender wrote:
HI CHarlie,
Don t know what i was thinking !!!! --
We may want to use '/' to reference group variables in ncap2
So I shall have to think soemthing els e up
...Henry
I suggest that double at-signs be converted to a single, literal, at-sign:
@@=@. TeXInfo uses this and it works well.Ye its it fixes the problem at hand but what about a way of inputting a charater code ?
lemme look at the UTF codes - maybe theres another one that netcfd doesnt like .
...Henry
There is alo a problem with variable that have a "period - dot" in their names, such as "RDRS_v2.1_P_P0_SFC".
The following command fails:
Sorry for posting on this old topic.
If you've tried the above suggestions and they do not work then I'm afraid you'll need to rename the variable (with ncrename), execute the script, and rename it back. This is why
CF prohibits most special characters (except underscore) in variable names.