I thought the verb flipOddPages worked, but the reversing of odd pages line
works for neither an odd nor an even number of pages. Let me demonstrate
with the verbs I defined in my construction early in this thread.

   NB. argument is an integer indicating number of pages in a report
   nodd=: >.@-:
   neven=: <.@-:
   odd=: >:@+:@i.@nodd
   even=: 2+|.@:+:@i.@neven
   zero=: '0'&,@":"0

   (,.@i.;zero@ (odd,even)"0) ] 5
┌─┬──┐
│0│01│
│1│03│
│2│05│
│3│04│
│4│02│
└─┴──┘
   (,.@i.;zero@ (odd,even)"0) ] 6
┌─┬──┐
│0│01│
│1│03│
│2│05│
│3│06│
│4│04│
│5│02│
└─┴──┘

In contrast to the above, with the code that "reverses order of odds" in
the verb `flipOddPages` I get the following results below (which I cannot
make agree with the above).

   (+ 2&| * #-+:) i. 6
0 5 2 3 4 1
   >: (+ 2&| * #-+:) i. 6  NB. same as above, but adding 1
1 6 3 4 5 2

   (|@:- 2&| * (- 2&|)@#) i. 6
0 5 2 3 4 1

   (|@:- 2&| * (- 2&|)@#) i. 5
0 3 2 1 4

Actually, to make the verbs `odd` and `even` above work with the order of
the files in my Mac directory, rather than with the indices 0, 1, 2, .. ,
the examples above need to be as follows, where the boxes are rotated to
correspond to the order of the filenames in the directory/

   (,.@i.;&(1&|.)zero@ (odd,even)"0) ] 5
+-+--+
|1|03|
|2|05|
|3|04|
|4|02|
|0|01|
+-+--+
   (,.@i.;&(1&|.)zero@ (odd,even)"0) ] 6
+-+--+
|1|03|
|2|05|
|3|06|
|4|04|
|5|02|
|0|01|
+-+--+

I suspect I can make this work on my own because the rest of the code is so
clear, but I am keeping the discussion open if anyone is keeping up. I hope
I am not wrong in my assessment here, but I do have a less than stellar
history, and may be quite wrong.

Thanks,




On Mon, Dec 16, 2013 at 6:51 AM, Dan Bron <[email protected]> wrote:

> Sorry, I should have tested my code on odd-length arguments as well as
> even.
>
>
> Thanks to Raul's help on twitter, we can fix the bug by using (|@:- 2&| *
> (-
> 2&|)@#) in place of (+ 2&| * #-+:) .
>
> To address the '\' vs '/' issue, I suppose we should standardize by using
> PATHJSEP_j_ (or PATHSEP_j_ in J6-) in place of raw '\'.
>
> I'm not sure what changes to make to the verb, if any, to get it to work
> properly on the example directory you gave.  I suspect you're getting blank
> output because it's not scanning the directory you want it to.  I suggest
> you embed a line like
>
>    smoutput jpath dir,pfx,'*.',sfx
>
> somewhere in the verb, to see what directory J's looking in.  If the
> directory looks right, but you're still getting blank output, then the
> filename pattern may be wrong.
>
> If the directory doesn't look right, remember that ~ is being expanded by
> jpath, not your shell. In your shell, ~ means "home", i.e. your user
> directory.  In J, it means your "J home", which is often a subdirectory of
> your user directory.  Try using an absolute path (starting with '/') to
> force J to look in the right place. If that works, you can experiment with
> jpath and USERFOLDERS to figure out if you can use a shorter synonym.
>
> If the directory looks right, but the pattern doesn't, then you can try
> experimenting with the LHA to flipOddPages. By default, the verb will look
> for files using the pattern 'comb*.png'. You can adjust either the prefix
> ('comb') or the suffix ('png') or both, using the x argument.
>
> For example, in your original message, you listed a number of files whose
> names started with 'combined', (as in 'combined 4.png'), so you could say:
>
>         'combined' flipOddPages some_directory
>
> You also discussed generating PDFs instead of PNG files; in that case, you
> could say:
>
>         'combined pdf' flipOddPages some_directory
>
> or
>
>         ('combined';'pdf') flipOddPages some_directory
>
> In any case, I don't think we're far off. Should just take some
> experimentation and maybe a few adjustments to the code.
>
> -Dan
>
>
> flipOddPages=:verb define
>         'comb png' flipOddPages y
> :
>         NB.y=directory to scan, x=file prefix and suffix
>         'pfx sfx'=.2 {. (;:^:(0=L.) x),<'png'
>         dir =. (,PATHJSEP_j_-.{:)y   NB. Use PATHSEP_j_ in J6 and earlier
> versions
>
> smoutput jpath dir,pfx,'*.',sfx
>
>         NB. Scan directory
>         fn  =. {. |: 1!:0 jpath dir,pfx,'*',sfx
>
>         NB. Zero-fill here will convert comb.png to comb 0.png
>         NB. The increments account for the space after comb and
>         NB. the dot before png respectively.
>         pn=.0 ".&> (1+#pfx) }.&.> (-1+#sfx)}.&.> fn
>
>         NB. Reverse order of odds
>         pn=. (|@:- 2&| * (- 2&|)@#) pn     NB. *************
>
>         NB. Table of old-filename, new-filename
>         fn ,. <@;"1 (<pfx,' '),.(":&.> pn),.<'.',sfx
> )
> NB. Can remove smoutput line once you're done debugging
>
> NB. Usage examples:
> flipOddPages '~temp\archive1'
> 'combined' flipOddPages '~temp\archive1'
> 'combined pdf' flipOddPages '~temp\archive1'
> ('combined';'pdf') flipOddPages '~temp\archive1'
>
>
>
> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Brian Schott
> Sent: Saturday, December 14, 2013 1:17 PM
> To: Chat forum
> Subject: Re: [Jchat] Fwd: Archive j
>
> Raul and Dan,
>
> Yes, when I change '\' to '/' Dan's flipOddPages works great in my j temp
> folder. I am struggling making it work in a folder like the one I showed,
> but that is temporary, I hope. When I do, I get a blank line output.
>
> I also want to see how to deal with an odd number of pages.
>
> Great app, though.
>
> Thanks, again.
>
>
> --
> (B=)
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>



-- 
(B=) <-----my sig
Brian Schott
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to