[ncl-talk] Remove white-spaces from write_table output
David Brown
dbrown at ucar.edu
Thu Aug 10 14:31:36 MDT 2017
I am wondering if we could provide a special formatting character that
could be part of the format string, maybe at the beginning, and would
signal that no automatic separator character be used. Of course which
character to use might be an issue, but hopefully that could be
solved.
-dave
On Thu, Aug 10, 2017 at 2:12 PM, Dennis Shea <shea at ucar.edu> wrote:
> Fortran (some other languages too!) has the capability to provide user
> specified granularity in parsing strings of numbers and characters.
>
> fortran: format(i2,5i5)
> 2999999999999999999999999999999
>
> The problem is someone must tell you the structure. You could read as
> follows:
> format(i2,i2,i3,i5,i4,i1,.......)
>
> However, any 'automatic' software must have some separator between the
> numbers.
>
> --
> NCDC has text files the include letters, numbers, periods (76.5) all
> together.
>
> ====
> fortran: format(i2,5(1x,i5))
> 2 99999 99999 99999 99999 99999 99999
>
> Just a comment
> D
>
> On Thu, Aug 10, 2017 at 12:02 PM, Rabah Hachelaf <hachelaf at sca.uqam.ca>
> wrote:
>>
>> Hi Mary and Karin,
>>
>> Adding white-spaces by default is a limitation if we need to write some
>> data using a FORTRAN format.
>> We could bypass this "issue" by removing one character starting from the
>> 2nd variable but we would have liked to keep the same format between FORTRAN
>> and NCL
>>
>> Regards,
>>
>> Rabah
>>
>> 2017-08-10 13:15 GMT-04:00 Mary Haley <haley at ucar.edu>:
>>>
>>> Hi Rabah,
>>>
>>> I see Karin already responded, and had the same response I was just about
>>> to send!
>>>
>>> I'll go ahead and include my response here. I've updated the
>>> documentation to indicate this behavior, and also created a ticket just in
>>> case.
>>>
>>> Unfortunately, I think this is a "feature" of write_table. Even if
>>> there's a case for declaring this a bug, we probably couldn't change the
>>> behavior because we'd likely break a bunch of existing scripts that depend
>>> on the space being there.
>>>
>>> I created a ticket on this (NCL-2646), in case it's an issue for other
>>> users.
>>>
>>> Meanwhile, as Karin pointed out, I think the only way around this is to
>>> concatenate the strings yourself:
>>>
>>> int1 = 2
>>> int2 = "99999"
>>> int3 = "99999"
>>> int4 = "99999"
>>> int5 = "99999"
>>> int6 = "99999"
>>> int7 = "99999"
>>> int_cat = int2+int3+int4+int5+int6+int7
>>> sounding_check = [/int1,int_cat/]
>>> write_table(outfile,"w",sounding_check,"%2i%s")
>>>
>>> In general, I would caution against writing numbers to a file without any
>>> spaces, because this makes it potentially very difficult for somebody else
>>> looking at the file to know how to read it. However, I do understand that
>>> some of these files have historically been written this way for other
>>> purposes
>>>
>>> --Mary
>>>
>>>
>>>
>>> On Wed, Aug 9, 2017 at 3:13 PM, Rabah Hachelaf <hachelaf at sca.uqam.ca>
>>> wrote:
>>>>
>>>>
>>>> Hello,
>>>> I am wounding why there is a systematic white-spaces between values
>>>> although they are removed from the format specifier.
>>>> How can i remove white spaces from in this case.
>>>>
>>>> Thank you
>>>>
>>>>
>>>> begin
>>>> outfile = "test.txt"
>>>> sounding_check = [/2,"99999","99999","99999","99999","99999","99999"/]
>>>> write_table(outfile,"a",sounding_check,"%2i%s%s%s%s%s%s")
>>>>
>>>> end
>>>>
>>>>
>>>> output :
>>>> 2 99999 99999 99999 99999 99999 99999
>>>> --
>>>> ------------------------------
>>>> Best regards,
>>>> Rabah Hachelaf
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> ncl-talk mailing list
>>>> ncl-talk at ucar.edu
>>>> List instructions, subscriber options, unsubscribe:
>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>
>>>
>>
>>
>>
>> --
>> ------------------------------
>> Cordialement,
>> Best regards,
>> Rabah Hachelaf
>>
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
More information about the ncl-talk
mailing list