The Museum of HP Calculators

HP Forum Archive 16

[ Return to Index | Top of Index ]

hp 50g sort order in Filer
Message #1 Posted by Rich Messeder (US) on 26 Nov 2006, 11:16 a.m.

I was sure that I had seen the Filer sort my dir entries in dir-name-sorted followed by filename-sorted when I pressed the Order key. But now I cannot get this to work. Is there a method for doing this?

What I am looking for:
[DIR a]
[DIR b] etc.
followed by (for example}
{} list A
"" text B

I have the regular soft key options available, but not a 1-button sort as above.

Rich

      
Re: hp 50g sort order in Filer
Message #2 Posted by Gerson W. Barbosa on 26 Nov 2006, 3:53 p.m.,
in response to message #1 by Rich Messeder (US)

I don't know if the filer has an option for this kind of sorting. Meanwhile try this:

<< VARS SORT ORDER 15 TVARS ORDER
>>

Gerson.

      
Re: hp 50g sort order in Filer
Message #3 Posted by James M. Prange (Michigan) on 26 Nov 2006, 3:54 p.m.,
in response to message #1 by Rich Messeder (US)

After you've chosen a port or directory from the "tree" view, press NXT twice to get SORT as the last menu item on that page; TYPE is the closest to what you want. I think that even then, within each type, objects are sorted according to their "storage order" rather than alphabetically.

You can use some "keyboard shortcuts" within the filer too. Instead of choosing the sort option from a choosebox you can press:

  • T or RightShift T for Type
  • LeftShift T for inverse Type
  • Rightshift N for Name
  • LeftShift N for inverse Name
  • S or RightShift S for Size
  • LeftShift S for inverse Size
  • I don't know of a shortcut to get back to "Original" or "Unsorted".
Personally, I prefer Wolfgang's Filer6, available at http://page.mi.fu-berlin.de/~raut/WR49/index.htm#General.

Regards,
James

Edited: 26 Nov 2006, 4:01 p.m.

            
Re: hp 50g sort order in Filer
Message #4 Posted by James M. Prange (Michigan) on 27 Nov 2006, 3:48 a.m.,
in response to message #3 by James M. Prange (Michigan)

PS:

Within the Filer, pressing unshifted N does EVAL, which is on the same key, which is the reason for requiring the RightShift N for sorting by name.

Regards,
James

      
Re: hp 50g sort order in Filer
Message #5 Posted by Rich Messeder (US) on 26 Nov 2006, 7:22 p.m.,
in response to message #1 by Rich Messeder (US)

Thanks for the code. I tried it, and it works fine for me. If there are no dirs in the list, then it errors, but that's OK because it has already sorted the files.

This code appears to work (I'm new to programming this class of calculator) because all the entries, irrespective of type, are sorted in the first pass; then the second specifies only dir-type entries and those are ORDERed, bubbling the non-dir-types to the bottom of the list, but still sorted.

My references do not show a type 15 for dir types.

I tried Filer6, and I can see that it is more powerful than the builtin Files command, but is will not do what I want. I am likely to use it to manage my SD card, however, as it appears to do what the builtin program will not do.

Thanks to both for your help. Rich

            
Re: hp 50g sort order in Filer
Message #6 Posted by James M. Prange (Michigan) on 26 Nov 2006, 8:11 p.m.,
in response to message #5 by Rich Messeder (US)

Ah, I was thinking that you wanted the display of objects sorted in the filer. Note that if you want to make it permanent, the filer also has the ORDER operation.

But for permanent sorting, Gerson's program seems better. If you care to avoid the possible error, then change it to:

%%HP: T(3);
\<< 
   VARS SORT ORDER 
   15 TVARS DUP
   IF
     SIZE
   THEN
     ORDER
   ELSE
     DROP
   END
\>>

Regards,
James

Edited: 26 Nov 2006, 8:40 p.m.

                  
Re: hp 50g sort order in Filer
Message #7 Posted by Gerson W. Barbosa on 26 Nov 2006, 8:57 p.m.,
in response to message #6 by James M. Prange (Michigan)

Hello James,

Thanks for the improvement! I will use it from now on. I had noticed the error Rich mentioned but then I didn't care about it because I use this mostly to keep my HOME directory sorted that way, and there's always other directories therein. I once wrote a program that avoided the double sorting, but I can't find it anymore. I remember it was much longer. Anyway, the 50G is so fast this is not a problem.

Regards,

Gerson.

                        
Sorted directories
Message #8 Posted by James M. Prange (Michigan) on 27 Nov 2006, 3:33 a.m.,
in response to message #7 by Gerson W. Barbosa

Hello Gerson,

You're welcome, of course.

A possible disadvantage is that often I don't really want a directory stored in ASCII order. For example, I usually keep reserved variables and "special" variables such as a list of flags that I want easily accessible at the end of the directory.

Note that the 28 series and 48SX/S don't have a built-in SORT command, so for those models a sorting program would have to be called or a sorting routine substituted for SORT.

Also note that these programs can take a long time to execute. Neither VARS nor TVARS is particularly fast, and ORDER can take a long time if a lot of variables have to be moved.

To avoid an error if used on an empty directory, we could use:

%%HP: T(3);
@ Download to 49 series in exact mode.
@ Results from the BYTES command:
@ 48G series:
@   Checksum: # B9F0h
@   Size:          76
@ 49 series:
@   Checksum: # 991Bh
@   Size:         72.
\<<                     @ Begin program.
   VARS                 @ Get list of variables.
   DUP                  @ Copy of variables list.
   IF
     SIZE               @ Variables list not empty?
   THEN
     SORT               @ Sort list to ASCII order.
     ORDER              @ Reorder variables.
     15 TVARS           @ Get list of subdirectories.
     DUP                @ Copy of subdirectories list.
     IF
       SIZE             @ Subdirectories list not empty?
     THEN
       ORDER            @ Move subdirectories to front.
     ELSE
       DROP             @ Discard empty subdirectory list.
     END
   ELSE
     DROP               @ Discard empty variables list.
   END
\>>
But one wouldn't be likely to want to use such a program on an empty directory anyway, so why bother? Well, I did so as a step in developing a recursive sorted order program that will work on the current directory and any subdirectories (which may happen to be empty):
%%HP: T(3);
@ Download to 49 series in exact mode.
@ Recursive program; change ProgName within program to whatever
@ name is chosen for storing the program.
@ Results from the BYTES command:
@ 48G series:
@   Checksum: # 5394h
@   Size:         129
@ 49 series:
@   Checksum: # C209h
@   Size:        125.
\<<                     @ Begin program.
    VARS                @ Get list of variables.
    DUP                 @ Copy of variables list.
    IF                  @
      SIZE              @ Variables list not empty?
    THEN
      SORT              @ Sort list to ASCII order.
      ORDER             @ Reorder variables.
      15 TVARS          @ Get list of subdirectories.
      DUP               @ Copy of subdirectories list
      SIZE              @ Number of subdirectories.
      IF                @
        DUP             @ Subdirectories list not empty?
      THEN              @
        OVER            @ Copy of subdirectory list.
        ORDER           @ Move subdirectories to front.
        1               @ Loop begin index.
        SWAP            @ Move down number of subdirectories.
        FOR n           @ For each subdirectory.
          DUP           @ Copy of subdirectory list.
          n GET         @ Get subdirectory name.
          EVAL          @ Make subdirectory current.
          ProgName      @ Call this program recursively.
          UPDIR         @ Return to parent directory.
        NEXT            @
        DROP            @ Discard subdirectories list.
      ELSE              @
        DROP2           @ Discard empty subdirectories list and size 0.
      END               @
    ELSE                @
      DROP              @ Discard empty variables list.
    END
\>>                     @ End program.
Or one could use a subprogram stored in a local variable which calls itself recursively. In this case, the program can be stored with any global name without changing the name within the program. Note that a "compiled local name" is used because I use the name in the subprogram before the local variable actually exists.
%%HP: T(3);
@ Download to 49 series in exact mode.
@ Results from the BYTES command:
@ 48G series:
@   Checksum: # A5A5h
@   Size:         159
@ 49 series:
@   Checksum: # 5367h
@   Size:        155.
\<<                     @ Begin program.
  \<<                   @ Begin recursive subprogram.
    VARS                @ Get list of variables.
    DUP                 @ Copy of variables list.
    IF                  @
      SIZE              @ Variables list not empty?
    THEN
      SORT              @ Sort list to ASCII order.
      ORDER             @ Reorder variables.
      15 TVARS          @ Get list of subdirectories.
      DUP               @ Copy of subdirectories list.
      SIZE              @ Number of subdirectories.
      IF                @
        DUP             @ Subdirectories list not empty?
      THEN              @
        OVER            @ Copy of subdirectory list.
        ORDER           @ Move subdirectories to front.
        1               @ Loop begin index.
        SWAP            @ Move down number of subdirectories.
        FOR n           @ For each subdirectory.
          DUP           @ Copy of subdirectory list.
          n GET         @ Get subdirectory name.
          EVAL          @ Make subdirectory current.
          \<-s          @ Put this recursive subprogram on stack.
          EVAL          @ Execute recursive subprogram.
          UPDIR         @ Return to parent directory.
        NEXT            @
        DROP            @ Discard subdirectories list.
      ELSE              @
        DROP2           @ Discard empty subdirectories list and size 0.
      END               @
    ELSE                @
      DROP              @ Discard empty variables list.
    END                 @
  \>>                   @ End recursive subprogram.
  \-> \<-s              @ Bind recursive subprogram.
  \<<                   @ Begin defining procedure
    \<-s                @ Put recursive subprogram on stack.
    EVAL                @ Execute recursive subprogram.
  \>>                   @ End defining procedure.
\>>                     @ End program.

Other, perhaps better, programs could be made, for example perhaps using the DOLIST command.

Oh, by the way, for the Classic RPN aficionados who feel that putting the loop index numbers before the FOR itself is overdoing the postfix notation, the above recursive programs demonstrate the reason.

Regards,
James

                              
Re: Sorted directories
Message #9 Posted by Antonio Maschio (Italy) on 27 Nov 2006, 6:31 a.m.,
in response to message #8 by James M. Prange (Michigan)

Why don't you put this as an article?

-- Antonio

                  
Re: hp 50g sort order in Filer
Message #10 Posted by Rich Messeder (US) on 26 Nov 2006, 10:29 p.m.,
in response to message #6 by James M. Prange (Michigan)

Quote:
Ah, I was thinking that you wanted the display of objects sorted in the filer. Note that if you want to make it permanent, the filer also has the ORDER operation.

I could have lived with the display, I suppose. Although I can see an additional benefit to having the directory sorted so that the VAR key gives me predictable results. But in any event, I couldn't get any keystroke combination in either the builtin or Filer6 to give me the results I wanted. Thanks to your input, though, I tried this...

%%HP: T(3)A(R)F(.);
\<< 
  VARS SORT ORDER
  15 TVARS 
  IFERR
    ORDER
  THEN
    DROP
  END
\>>

...and it seems to work just fine.

Rich

                        
Re: hp 50g sort order in Filer
Message #11 Posted by James M. Prange (Michigan) on 27 Nov 2006, 1:01 a.m.,
in response to message #10 by Rich Messeder (US)

Yes, that should work; just two different approaches to dealing with the possibility of an empty list. Assuming that last arguments saves are enabled, LASTARG may give different results.

Regards,
James


[ Return to Index | Top of Index ]

Go back to the main exhibit hall