main(arg=string[]) Now, how do I use that array as an argument in my program?

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

main(arg=string[]) Now, how do I use that array as an argument in my program?

kenner
    function main(String[])
  23 +++  say "arg ===>" arg
     +++                ^
     +++ Error: Cannot use this operation on an array (type 'java.lang.String[]')

import java.text.SimpleDateFormat
class Filter_Date
        properties public static
                Start_Time = long
                inhandle=BufferedReader
                outhandle=OutputStreamWriter
                linesep=System.getProperty('line.separator') -- be platform-neutral
                fin = string
                Debug_Level = 100
                trace methods
method main(arg=String[]) static public
        if Debug_Level > 90 then trace var fin Delta fName fileName
        if Debug_Level > 50 then trace results
        say "arg ===>" arg
        parse arg fin -- get the arguments: input and output files
        if fin='' then do
                say '# Please specify input file.'
                exit 1
        end
        Start_Time = reset()
        Filter_Date(fin)

method Filter_Date(fName)
        if Debug_Level > 30 then trace results
        FileHandles(fName)
        FileScanned()
        say "Elapsed time:" elapsed()

/* Open and check the files */
Method FileHandles(fileName)
        if Debug_Level > 30 then trace results
        say "Current time:" Start_Time
        say "Elapsed time:" elapsed()
        do
  infile=File(fileName)
  instream=FileInputStream(infile)
  inhandle=BufferedReader(InputStreamReader(instream))
  outfile=File(fileName || ".new")
  outstream=FileOutputStream(outfile)
  outhandle=OutputStreamWriter(outstream)
  say 'Processing' infile'...'
catch e=IOException
  say '# error opening file' e.getMessage
  exit
end

/* The main processing loop */
method FileScanned()
        if Debug_Level > 30 then trace results
loop linenum=1 by 1 -- to 1000
  theLine=Rexx inhandle.readLine           -- get next line [as Rexx string]
  if theLine=null then leave linenum       -- normal end of file
  parse theLine sysId dateIn timeIn theRest -- process the line
  fd = SimpleDateFormat("E")  /* day of the week */
  dt = fd.format(Date(dateIn))
  if Debug_Level > 70 then say dt
-- //formatting Month in MMM format like Jan, Feb etc.
     
         strDateFormat = "MMM";
     sdf = SimpleDateFormat(strDateFormat);
     theMonth = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Month in MMM format : " theMonth
     
     strDateFormat = "YY";
     sdf = SimpleDateFormat(strDateFormat);
     theYear = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Year in YY format : " theYear
     
     strDateFormat = "w";
     sdf = SimpleDateFormat(strDateFormat);
     theWeek = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Week in 1-53 format : " theWeek
     
  if dt="Sat" then iterate linenum       -- skip the wkends
  if dt="Sun" then iterate linenum       -- skip the wkends
  if (theMonth = "May") & (theYear \= 12) then iterate linenum       -- skip May in 2011 and 2013
 
  if linenum>1 then outhandle.write(linesep, 0, linesep.length)
  outLine = sysId dateIn theWeek timeIn theRest
  outhandle.write(outLine, 0, outLine.length)
 
catch e=IOException
  say '# error reading or writing file' e.getMessage
catch RuntimeException
  say '# processing ended due to -RuntimeException-.'
finally do                              -- close files
    if inhandle\=null  then inhandle.close
    if outhandle\=null then outhandle.close
  catch IOException
    -- ignore errors during close
  end
end linenum

say linenum-1 'lines written'

method reset() public static returns long
        if Debug_Level > 30 then trace results
        TimeNow = System.currentTimeMillis()
        say Date()
        return TimeNow
method elapsed() public static returns int
    if Debug_Level > 30 then trace results
         current=System.currentTimeMillis()
         numeric digits 16
         delta = current - Start_Time
         delta=delta/60000
         numeric digits 9
         delta=delta.format(null,3) %1
-- delta=(delta+totalMinutes) %1
         return delta

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: main(arg=string[]) Now, how do I use that array as an argument in my program?

measel
Dude, you can't pass a string array to your main.  Pass a string and parse it.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Kenneth Klein (TEMA TPC)
Sent: Friday, May 17, 2013 9:25 AM
To: IBM Netrexx
Subject: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

    function main(String[])
  23 +++  say "arg ===>" arg
     +++                ^
     +++ Error: Cannot use this operation on an array (type 'java.lang.String[]')

import java.text.SimpleDateFormat
class Filter_Date
        properties public static
                Start_Time = long
                inhandle=BufferedReader
                outhandle=OutputStreamWriter
                linesep=System.getProperty('line.separator') -- be platform-neutral
                fin = string
                Debug_Level = 100
                trace methods
method main(arg=String[]) static public
        if Debug_Level > 90 then trace var fin Delta fName fileName
        if Debug_Level > 50 then trace results
        say "arg ===>" arg
        parse arg fin -- get the arguments: input and output files
        if fin='' then do
                say '# Please specify input file.'
                exit 1
        end
        Start_Time = reset()
        Filter_Date(fin)

method Filter_Date(fName)
        if Debug_Level > 30 then trace results
        FileHandles(fName)
        FileScanned()
        say "Elapsed time:" elapsed()

/* Open and check the files */
Method FileHandles(fileName)
        if Debug_Level > 30 then trace results
        say "Current time:" Start_Time
        say "Elapsed time:" elapsed()
        do
  infile=File(fileName)
  instream=FileInputStream(infile)
  inhandle=BufferedReader(InputStreamReader(instream))
  outfile=File(fileName || ".new")
  outstream=FileOutputStream(outfile)
  outhandle=OutputStreamWriter(outstream)
  say 'Processing' infile'...'
catch e=IOException
  say '# error opening file' e.getMessage
  exit
end

/* The main processing loop */
method FileScanned()
        if Debug_Level > 30 then trace results
loop linenum=1 by 1 -- to 1000
  theLine=Rexx inhandle.readLine           -- get next line [as Rexx string]
  if theLine=null then leave linenum       -- normal end of file
  parse theLine sysId dateIn timeIn theRest -- process the line
  fd = SimpleDateFormat("E")  /* day of the week */
  dt = fd.format(Date(dateIn))
  if Debug_Level > 70 then say dt
-- //formatting Month in MMM format like Jan, Feb etc.
     
         strDateFormat = "MMM";
     sdf = SimpleDateFormat(strDateFormat);
     theMonth = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Month in MMM format : " theMonth
     
     strDateFormat = "YY";
     sdf = SimpleDateFormat(strDateFormat);
     theYear = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Year in YY format : " theYear
     
     strDateFormat = "w";
     sdf = SimpleDateFormat(strDateFormat);
     theWeek = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Week in 1-53 format : " theWeek
     
  if dt="Sat" then iterate linenum       -- skip the wkends
  if dt="Sun" then iterate linenum       -- skip the wkends
  if (theMonth = "May") & (theYear \= 12) then iterate linenum       -- skip May in 2011 and 2013
 
  if linenum>1 then outhandle.write(linesep, 0, linesep.length)
  outLine = sysId dateIn theWeek timeIn theRest
  outhandle.write(outLine, 0, outLine.length)
 
catch e=IOException
  say '# error reading or writing file' e.getMessage catch RuntimeException
  say '# processing ended due to -RuntimeException-.'
finally do                              -- close files
    if inhandle\=null  then inhandle.close
    if outhandle\=null then outhandle.close
  catch IOException
    -- ignore errors during close
  end
end linenum

say linenum-1 'lines written'

method reset() public static returns long
        if Debug_Level > 30 then trace results
        TimeNow = System.currentTimeMillis()
        say Date()
        return TimeNow
method elapsed() public static returns int
    if Debug_Level > 30 then trace results
         current=System.currentTimeMillis()
         numeric digits 16
         delta = current - Start_Time
         delta=delta/60000
         numeric digits 9
         delta=delta.format(null,3) %1
-- delta=(delta+totalMinutes) %1
         return delta

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: main(arg=string[]) Now, how do I use that array as an argument in my program?

alansam
In reply to this post by kenner
Try this:

method main(args = String[]) public static
  arg = Rexx(args)
  parse arg ...

The method signature is nominally equivalent to Java's standard signature for a main method:

public stativ void main(String[] args) {
  ...
}

Regards,
Alan.


On 17 May 2013 07:25, Kenneth Klein (TEMA TPC) <[hidden email]> wrote:
    function main(String[])
  23 +++  say "arg ===>" arg
     +++                ^
     +++ Error: Cannot use this operation on an array (type 'java.lang.String[]')

import java.text.SimpleDateFormat
class Filter_Date
        properties public static
                Start_Time = long
                inhandle=BufferedReader
                outhandle=OutputStreamWriter
                linesep=System.getProperty('line.separator') -- be platform-neutral
                fin = string
                Debug_Level = 100
                trace methods
method main(arg=String[]) static public
        if Debug_Level > 90 then trace var fin Delta fName fileName
        if Debug_Level > 50 then trace results
        say "arg ===>" arg
        parse arg fin -- get the arguments: input and output files
        if fin='' then do
                say '# Please specify input file.'
                exit 1
        end
        Start_Time = reset()
        Filter_Date(fin)

method Filter_Date(fName)
        if Debug_Level > 30 then trace results
        FileHandles(fName)
        FileScanned()
        say "Elapsed time:" elapsed()

/* Open and check the files */
Method FileHandles(fileName)
        if Debug_Level > 30 then trace results
        say "Current time:" Start_Time
        say "Elapsed time:" elapsed()
        do
  infile=File(fileName)
  instream=FileInputStream(infile)
  inhandle=BufferedReader(InputStreamReader(instream))
  outfile=File(fileName || ".new")
  outstream=FileOutputStream(outfile)
  outhandle=OutputStreamWriter(outstream)
  say 'Processing' infile'...'
catch e=IOException
  say '# error opening file' e.getMessage
  exit
end

/* The main processing loop */
method FileScanned()
        if Debug_Level > 30 then trace results
loop linenum=1 by 1 -- to 1000
  theLine=Rexx inhandle.readLine           -- get next line [as Rexx string]
  if theLine=null then leave linenum       -- normal end of file
  parse theLine sysId dateIn timeIn theRest -- process the line
  fd = SimpleDateFormat("E")  /* day of the week */
  dt = fd.format(Date(dateIn))
  if Debug_Level > 70 then say dt
-- //formatting Month in MMM format like Jan, Feb etc.

         strDateFormat = "MMM";
     sdf = SimpleDateFormat(strDateFormat);
     theMonth = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Month in MMM format : " theMonth

     strDateFormat = "YY";
     sdf = SimpleDateFormat(strDateFormat);
     theYear = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Year in YY format : " theYear

     strDateFormat = "w";
     sdf = SimpleDateFormat(strDateFormat);
     theWeek = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Week in 1-53 format : " theWeek

  if dt="Sat" then iterate linenum       -- skip the wkends
  if dt="Sun" then iterate linenum       -- skip the wkends
  if (theMonth = "May") & (theYear \= 12) then iterate linenum       -- skip May in 2011 and 2013

  if linenum>1 then outhandle.write(linesep, 0, linesep.length)
  outLine = sysId dateIn theWeek timeIn theRest
  outhandle.write(outLine, 0, outLine.length)

catch e=IOException
  say '# error reading or writing file' e.getMessage
catch RuntimeException
  say '# processing ended due to -RuntimeException-.'
finally do                              -- close files
    if inhandle\=null  then inhandle.close
    if outhandle\=null then outhandle.close
  catch IOException
    -- ignore errors during close
  end
end linenum

say linenum-1 'lines written'

method reset() public static returns long
        if Debug_Level > 30 then trace results
        TimeNow = System.currentTimeMillis()
        say Date()
        return TimeNow
method elapsed() public static returns int
    if Debug_Level > 30 then trace results
         current=System.currentTimeMillis()
         numeric digits 16
         delta = current - Start_Time
         delta=delta/60000
         numeric digits 9
         delta=delta.format(null,3) %1
--       delta=(delta+totalMinutes) %1
         return delta

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/




--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Alan

--
Needs more cowbell.
Reply | Threaded
Open this post in threaded view
|

Re: main(arg=string[]) Now, how do I use that array as an argument in my program?

alansam
In reply to this post by measel
Not quite true; Java passes the program arguments to main as an array of String objects.

Alan.


On 17 May 2013 09:11, Measel, Mike <[hidden email]> wrote:
Dude, you can't pass a string array to your main.  Pass a string and parse it.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Kenneth Klein (TEMA TPC)
Sent: Friday, May 17, 2013 9:25 AM
To: IBM Netrexx
Subject: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

    function main(String[])
  23 +++  say "arg ===>" arg
     +++                ^
     +++ Error: Cannot use this operation on an array (type 'java.lang.String[]')

import java.text.SimpleDateFormat
class Filter_Date
        properties public static
                Start_Time = long
                inhandle=BufferedReader
                outhandle=OutputStreamWriter
                linesep=System.getProperty('line.separator') -- be platform-neutral
                fin = string
                Debug_Level = 100
                trace methods
method main(arg=String[]) static public
        if Debug_Level > 90 then trace var fin Delta fName fileName
        if Debug_Level > 50 then trace results
        say "arg ===>" arg
        parse arg fin -- get the arguments: input and output files
        if fin='' then do
                say '# Please specify input file.'
                exit 1
        end
        Start_Time = reset()
        Filter_Date(fin)

method Filter_Date(fName)
        if Debug_Level > 30 then trace results
        FileHandles(fName)
        FileScanned()
        say "Elapsed time:" elapsed()

/* Open and check the files */
Method FileHandles(fileName)
        if Debug_Level > 30 then trace results
        say "Current time:" Start_Time
        say "Elapsed time:" elapsed()
        do
  infile=File(fileName)
  instream=FileInputStream(infile)
  inhandle=BufferedReader(InputStreamReader(instream))
  outfile=File(fileName || ".new")
  outstream=FileOutputStream(outfile)
  outhandle=OutputStreamWriter(outstream)
  say 'Processing' infile'...'
catch e=IOException
  say '# error opening file' e.getMessage
  exit
end

/* The main processing loop */
method FileScanned()
        if Debug_Level > 30 then trace results
loop linenum=1 by 1 -- to 1000
  theLine=Rexx inhandle.readLine           -- get next line [as Rexx string]
  if theLine=null then leave linenum       -- normal end of file
  parse theLine sysId dateIn timeIn theRest -- process the line
  fd = SimpleDateFormat("E")  /* day of the week */
  dt = fd.format(Date(dateIn))
  if Debug_Level > 70 then say dt
-- //formatting Month in MMM format like Jan, Feb etc.

         strDateFormat = "MMM";
     sdf = SimpleDateFormat(strDateFormat);
     theMonth = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Month in MMM format : " theMonth

     strDateFormat = "YY";
     sdf = SimpleDateFormat(strDateFormat);
     theYear = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Year in YY format : " theYear

     strDateFormat = "w";
     sdf = SimpleDateFormat(strDateFormat);
     theWeek = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Week in 1-53 format : " theWeek

  if dt="Sat" then iterate linenum       -- skip the wkends
  if dt="Sun" then iterate linenum       -- skip the wkends
  if (theMonth = "May") & (theYear \= 12) then iterate linenum       -- skip May in 2011 and 2013

  if linenum>1 then outhandle.write(linesep, 0, linesep.length)
  outLine = sysId dateIn theWeek timeIn theRest
  outhandle.write(outLine, 0, outLine.length)

catch e=IOException
  say '# error reading or writing file' e.getMessage catch RuntimeException
  say '# processing ended due to -RuntimeException-.'
finally do                              -- close files
    if inhandle\=null  then inhandle.close
    if outhandle\=null then outhandle.close
  catch IOException
    -- ignore errors during close
  end
end linenum

say linenum-1 'lines written'

method reset() public static returns long
        if Debug_Level > 30 then trace results
        TimeNow = System.currentTimeMillis()
        say Date()
        return TimeNow
method elapsed() public static returns int
    if Debug_Level > 30 then trace results
         current=System.currentTimeMillis()
         numeric digits 16
         delta = current - Start_Time
         delta=delta/60000
         numeric digits 9
         delta=delta.format(null,3) %1
--       delta=(delta+totalMinutes) %1
         return delta

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/




--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Alan

--
Needs more cowbell.
Reply | Threaded
Open this post in threaded view
|

Re: main(arg=string[]) Now, how do I use that array as an argument in my program?

measel

Yeah, ok but you don’t have to use it that way.

 

method main(arg = Rexx) public static

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Alan Sampson
Sent: Friday, May 17, 2013 11:13 AM
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

 

Not quite true; Java passes the program arguments to main as an array of String objects.

 

Alan.

 

On 17 May 2013 09:11, Measel, Mike <[hidden email]> wrote:

Dude, you can't pass a string array to your main.  Pass a string and parse it.


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Kenneth Klein (TEMA TPC)
Sent: Friday, May 17, 2013 9:25 AM
To: IBM Netrexx
Subject: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

    function main(String[])
  23 +++  say "arg ===>" arg
     +++                ^
     +++ Error: Cannot use this operation on an array (type 'java.lang.String[]')

import java.text.SimpleDateFormat
class Filter_Date
        properties public static
                Start_Time = long
                inhandle=BufferedReader
                outhandle=OutputStreamWriter
                linesep=System.getProperty('line.separator') -- be platform-neutral
                fin = string
                Debug_Level = 100
                trace methods
method main(arg=String[]) static public
        if Debug_Level > 90 then trace var fin Delta fName fileName
        if Debug_Level > 50 then trace results
        say "arg ===>" arg
        parse arg fin -- get the arguments: input and output files
        if fin='' then do
                say '# Please specify input file.'
                exit 1
        end
        Start_Time = reset()
        Filter_Date(fin)

method Filter_Date(fName)
        if Debug_Level > 30 then trace results
        FileHandles(fName)
        FileScanned()
        say "Elapsed time:" elapsed()

/* Open and check the files */
Method FileHandles(fileName)
        if Debug_Level > 30 then trace results
        say "Current time:" Start_Time
        say "Elapsed time:" elapsed()
        do
  infile=File(fileName)
  instream=FileInputStream(infile)
  inhandle=BufferedReader(InputStreamReader(instream))
  outfile=File(fileName || ".new")
  outstream=FileOutputStream(outfile)
  outhandle=OutputStreamWriter(outstream)
  say 'Processing' infile'...'
catch e=IOException
  say '# error opening file' e.getMessage
  exit
end

/* The main processing loop */
method FileScanned()
        if Debug_Level > 30 then trace results
loop linenum=1 by 1 -- to 1000
  theLine=Rexx inhandle.readLine           -- get next line [as Rexx string]
  if theLine=null then leave linenum       -- normal end of file
  parse theLine sysId dateIn timeIn theRest -- process the line
  fd = SimpleDateFormat("E")  /* day of the week */
  dt = fd.format(Date(dateIn))
  if Debug_Level > 70 then say dt
-- //formatting Month in MMM format like Jan, Feb etc.

         strDateFormat = "MMM";
     sdf = SimpleDateFormat(strDateFormat);
     theMonth = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Month in MMM format : " theMonth

     strDateFormat = "YY";
     sdf = SimpleDateFormat(strDateFormat);
     theYear = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Year in YY format : " theYear

     strDateFormat = "w";
     sdf = SimpleDateFormat(strDateFormat);
     theWeek = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Week in 1-53 format : " theWeek

  if dt="Sat" then iterate linenum       -- skip the wkends
  if dt="Sun" then iterate linenum       -- skip the wkends
  if (theMonth = "May") & (theYear \= 12) then iterate linenum       -- skip May in 2011 and 2013

  if linenum>1 then outhandle.write(linesep, 0, linesep.length)
  outLine = sysId dateIn theWeek timeIn theRest
  outhandle.write(outLine, 0, outLine.length)

catch e=IOException
  say '# error reading or writing file' e.getMessage catch RuntimeException
  say '# processing ended due to -RuntimeException-.'
finally do                              -- close files
    if inhandle\=null  then inhandle.close
    if outhandle\=null then outhandle.close
  catch IOException
    -- ignore errors during close
  end
end linenum

say linenum-1 'lines written'

method reset() public static returns long
        if Debug_Level > 30 then trace results
        TimeNow = System.currentTimeMillis()
        say Date()
        return TimeNow
method elapsed() public static returns int
    if Debug_Level > 30 then trace results
         current=System.currentTimeMillis()
         numeric digits 16
         delta = current - Start_Time
         delta=delta/60000
         numeric digits 9
         delta=delta.format(null,3) %1
--       delta=(delta+totalMinutes) %1
         return delta

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



 

--
Can't tweet, won't tweet!


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: main(arg=string[]) Now, how do I use that array as an argument in my program?

alansam
Doesn't work for me.  This program compiles but doesn't run:

/* NetRexx */
options replace

method main(arg = Rexx) public static
  parse arg aaa
  say aaa
  return

NetRexx portable processor, version NetRexx 3.01, build 40-20120823-0156
Copyright (c) RexxLA, 2011,2012.  All rights reserved.
Parts Copyright (c) IBM Corporation, 1995,2008.
Program zArgTest.nrx
    function main(Rexx)
Compilation of 'zArgTest.nrx' successful
allendale:netrexx developer$ java zArgTest
Error: Main method not found in class zArgTest, please define the main method as:
   public static void main(String[] args)


On 17 May 2013 10:14, Measel, Mike <[hidden email]> wrote:

Yeah, ok but you don’t have to use it that way.

 

method main(arg = Rexx) public static

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Alan Sampson
Sent: Friday, May 17, 2013 11:13 AM
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

 

Not quite true; Java passes the program arguments to main as an array of String objects.

 

Alan.

 

On 17 May 2013 09:11, Measel, Mike <[hidden email]> wrote:

Dude, you can't pass a string array to your main.  Pass a string and parse it.


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Kenneth Klein (TEMA TPC)
Sent: Friday, May 17, 2013 9:25 AM
To: IBM Netrexx
Subject: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

    function main(String[])
  23 +++  say "arg ===>" arg
     +++                ^
     +++ Error: Cannot use this operation on an array (type 'java.lang.String[]')

import java.text.SimpleDateFormat
class Filter_Date
        properties public static
                Start_Time = long
                inhandle=BufferedReader
                outhandle=OutputStreamWriter
                linesep=System.getProperty('line.separator') -- be platform-neutral
                fin = string
                Debug_Level = 100
                trace methods
method main(arg=String[]) static public
        if Debug_Level > 90 then trace var fin Delta fName fileName
        if Debug_Level > 50 then trace results
        say "arg ===>" arg
        parse arg fin -- get the arguments: input and output files
        if fin='' then do
                say '# Please specify input file.'
                exit 1
        end
        Start_Time = reset()
        Filter_Date(fin)

method Filter_Date(fName)
        if Debug_Level > 30 then trace results
        FileHandles(fName)
        FileScanned()
        say "Elapsed time:" elapsed()

/* Open and check the files */
Method FileHandles(fileName)
        if Debug_Level > 30 then trace results
        say "Current time:" Start_Time
        say "Elapsed time:" elapsed()
        do
  infile=File(fileName)
  instream=FileInputStream(infile)
  inhandle=BufferedReader(InputStreamReader(instream))
  outfile=File(fileName || ".new")
  outstream=FileOutputStream(outfile)
  outhandle=OutputStreamWriter(outstream)
  say 'Processing' infile'...'
catch e=IOException
  say '# error opening file' e.getMessage
  exit
end

/* The main processing loop */
method FileScanned()
        if Debug_Level > 30 then trace results
loop linenum=1 by 1 -- to 1000
  theLine=Rexx inhandle.readLine           -- get next line [as Rexx string]
  if theLine=null then leave linenum       -- normal end of file
  parse theLine sysId dateIn timeIn theRest -- process the line
  fd = SimpleDateFormat("E")  /* day of the week */
  dt = fd.format(Date(dateIn))
  if Debug_Level > 70 then say dt
-- //formatting Month in MMM format like Jan, Feb etc.

         strDateFormat = "MMM";
     sdf = SimpleDateFormat(strDateFormat);
     theMonth = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Month in MMM format : " theMonth

     strDateFormat = "YY";
     sdf = SimpleDateFormat(strDateFormat);
     theYear = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Year in YY format : " theYear

     strDateFormat = "w";
     sdf = SimpleDateFormat(strDateFormat);
     theWeek = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Week in 1-53 format : " theWeek

  if dt="Sat" then iterate linenum       -- skip the wkends
  if dt="Sun" then iterate linenum       -- skip the wkends
  if (theMonth = "May") & (theYear \= 12) then iterate linenum       -- skip May in 2011 and 2013

  if linenum>1 then outhandle.write(linesep, 0, linesep.length)
  outLine = sysId dateIn theWeek timeIn theRest
  outhandle.write(outLine, 0, outLine.length)

catch e=IOException
  say '# error reading or writing file' e.getMessage catch RuntimeException
  say '# processing ended due to -RuntimeException-.'
finally do                              -- close files
    if inhandle\=null  then inhandle.close
    if outhandle\=null then outhandle.close
  catch IOException
    -- ignore errors during close
  end
end linenum

say linenum-1 'lines written'

method reset() public static returns long
        if Debug_Level > 30 then trace results
        TimeNow = System.currentTimeMillis()
        say Date()
        return TimeNow
method elapsed() public static returns int
    if Debug_Level > 30 then trace results
         current=System.currentTimeMillis()
         numeric digits 16
         delta = current - Start_Time
         delta=delta/60000
         numeric digits 9
         delta=delta.format(null,3) %1
--       delta=(delta+totalMinutes) %1
         return delta

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



 

--
Can't tweet, won't tweet!


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Alan

--
Needs more cowbell.
Reply | Threaded
Open this post in threaded view
|

Re: main(arg=string[]) Now, how do I use that array as an argument in my program?

George Hovey-2
The language ref says

   Rexx(arg=String[])

will concatenate all the String(s) in the array.


On Fri, May 17, 2013 at 1:22 PM, Alan Sampson <[hidden email]> wrote:
Doesn't work for me.  This program compiles but doesn't run:

/* NetRexx */
options replace

method main(arg = Rexx) public static
  parse arg aaa
  say aaa
  return

NetRexx portable processor, version NetRexx 3.01, build 40-20120823-0156
Copyright (c) RexxLA, 2011,2012.  All rights reserved.
Parts Copyright (c) IBM Corporation, 1995,2008.
Program zArgTest.nrx
    function main(Rexx)
Compilation of 'zArgTest.nrx' successful
allendale:netrexx developer$ java zArgTest
Error: Main method not found in class zArgTest, please define the main method as:
   public static void main(String[] args)


On 17 May 2013 10:14, Measel, Mike <[hidden email]> wrote:

Yeah, ok but you don’t have to use it that way.

 

method main(arg = Rexx) public static

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Alan Sampson
Sent: Friday, May 17, 2013 11:13 AM
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

 

Not quite true; Java passes the program arguments to main as an array of String objects.

 

Alan.

 

On 17 May 2013 09:11, Measel, Mike <[hidden email]> wrote:

Dude, you can't pass a string array to your main.  Pass a string and parse it.


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Kenneth Klein (TEMA TPC)
Sent: Friday, May 17, 2013 9:25 AM
To: IBM Netrexx
Subject: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

    function main(String[])
  23 +++  say "arg ===>" arg
     +++                ^
     +++ Error: Cannot use this operation on an array (type 'java.lang.String[]')

import java.text.SimpleDateFormat
class Filter_Date
        properties public static
                Start_Time = long
                inhandle=BufferedReader
                outhandle=OutputStreamWriter
                linesep=System.getProperty('line.separator') -- be platform-neutral
                fin = string
                Debug_Level = 100
                trace methods
method main(arg=String[]) static public
        if Debug_Level > 90 then trace var fin Delta fName fileName
        if Debug_Level > 50 then trace results
        say "arg ===>" arg
        parse arg fin -- get the arguments: input and output files
        if fin='' then do
                say '# Please specify input file.'
                exit 1
        end
        Start_Time = reset()
        Filter_Date(fin)

method Filter_Date(fName)
        if Debug_Level > 30 then trace results
        FileHandles(fName)
        FileScanned()
        say "Elapsed time:" elapsed()

/* Open and check the files */
Method FileHandles(fileName)
        if Debug_Level > 30 then trace results
        say "Current time:" Start_Time
        say "Elapsed time:" elapsed()
        do
  infile=File(fileName)
  instream=FileInputStream(infile)
  inhandle=BufferedReader(InputStreamReader(instream))
  outfile=File(fileName || ".new")
  outstream=FileOutputStream(outfile)
  outhandle=OutputStreamWriter(outstream)
  say 'Processing' infile'...'
catch e=IOException
  say '# error opening file' e.getMessage
  exit
end

/* The main processing loop */
method FileScanned()
        if Debug_Level > 30 then trace results
loop linenum=1 by 1 -- to 1000
  theLine=Rexx inhandle.readLine           -- get next line [as Rexx string]
  if theLine=null then leave linenum       -- normal end of file
  parse theLine sysId dateIn timeIn theRest -- process the line
  fd = SimpleDateFormat("E")  /* day of the week */
  dt = fd.format(Date(dateIn))
  if Debug_Level > 70 then say dt
-- //formatting Month in MMM format like Jan, Feb etc.

         strDateFormat = "MMM";
     sdf = SimpleDateFormat(strDateFormat);
     theMonth = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Month in MMM format : " theMonth

     strDateFormat = "YY";
     sdf = SimpleDateFormat(strDateFormat);
     theYear = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Year in YY format : " theYear

     strDateFormat = "w";
     sdf = SimpleDateFormat(strDateFormat);
     theWeek = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Week in 1-53 format : " theWeek

  if dt="Sat" then iterate linenum       -- skip the wkends
  if dt="Sun" then iterate linenum       -- skip the wkends
  if (theMonth = "May") & (theYear \= 12) then iterate linenum       -- skip May in 2011 and 2013

  if linenum>1 then outhandle.write(linesep, 0, linesep.length)
  outLine = sysId dateIn theWeek timeIn theRest
  outhandle.write(outLine, 0, outLine.length)

catch e=IOException
  say '# error reading or writing file' e.getMessage catch RuntimeException
  say '# processing ended due to -RuntimeException-.'
finally do                              -- close files
    if inhandle\=null  then inhandle.close
    if outhandle\=null then outhandle.close
  catch IOException
    -- ignore errors during close
  end
end linenum

say linenum-1 'lines written'

method reset() public static returns long
        if Debug_Level > 30 then trace results
        TimeNow = System.currentTimeMillis()
        say Date()
        return TimeNow
method elapsed() public static returns int
    if Debug_Level > 30 then trace results
         current=System.currentTimeMillis()
         numeric digits 16
         delta = current - Start_Time
         delta=delta/60000
         numeric digits 9
         delta=delta.format(null,3) %1
--       delta=(delta+totalMinutes) %1
         return delta

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



 

--
Can't tweet, won't tweet!


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
"One can live magnificently in this world if one knows how to work and how to love."  --  Leo Tolstoy

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: main(arg=string[]) Now, how do I use that array as an argument in my program?

alansam
That's what I showed in my 1st reply.

method main(args = String[]) public static
  arg = Rexx(args)
  parse arg ...

Alan.


On 17 May 2013 10:40, George Hovey <[hidden email]> wrote:
The language ref says

   Rexx(arg=String[])

will concatenate all the String(s) in the array.


On Fri, May 17, 2013 at 1:22 PM, Alan Sampson <[hidden email]> wrote:
Doesn't work for me.  This program compiles but doesn't run:

/* NetRexx */
options replace

method main(arg = Rexx) public static
  parse arg aaa
  say aaa
  return

NetRexx portable processor, version NetRexx 3.01, build 40-20120823-0156
Copyright (c) RexxLA, 2011,2012.  All rights reserved.
Parts Copyright (c) IBM Corporation, 1995,2008.
Program zArgTest.nrx
    function main(Rexx)
Compilation of 'zArgTest.nrx' successful
allendale:netrexx developer$ java zArgTest
Error: Main method not found in class zArgTest, please define the main method as:
   public static void main(String[] args)


On 17 May 2013 10:14, Measel, Mike <[hidden email]> wrote:

Yeah, ok but you don’t have to use it that way.

 

method main(arg = Rexx) public static

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Alan Sampson
Sent: Friday, May 17, 2013 11:13 AM
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

 

Not quite true; Java passes the program arguments to main as an array of String objects.

 

Alan.

 

On 17 May 2013 09:11, Measel, Mike <[hidden email]> wrote:

Dude, you can't pass a string array to your main.  Pass a string and parse it.


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Kenneth Klein (TEMA TPC)
Sent: Friday, May 17, 2013 9:25 AM
To: IBM Netrexx
Subject: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

    function main(String[])
  23 +++  say "arg ===>" arg
     +++                ^
     +++ Error: Cannot use this operation on an array (type 'java.lang.String[]')

import java.text.SimpleDateFormat
class Filter_Date
        properties public static
                Start_Time = long
                inhandle=BufferedReader
                outhandle=OutputStreamWriter
                linesep=System.getProperty('line.separator') -- be platform-neutral
                fin = string
                Debug_Level = 100
                trace methods
method main(arg=String[]) static public
        if Debug_Level > 90 then trace var fin Delta fName fileName
        if Debug_Level > 50 then trace results
        say "arg ===>" arg
        parse arg fin -- get the arguments: input and output files
        if fin='' then do
                say '# Please specify input file.'
                exit 1
        end
        Start_Time = reset()
        Filter_Date(fin)

method Filter_Date(fName)
        if Debug_Level > 30 then trace results
        FileHandles(fName)
        FileScanned()
        say "Elapsed time:" elapsed()

/* Open and check the files */
Method FileHandles(fileName)
        if Debug_Level > 30 then trace results
        say "Current time:" Start_Time
        say "Elapsed time:" elapsed()
        do
  infile=File(fileName)
  instream=FileInputStream(infile)
  inhandle=BufferedReader(InputStreamReader(instream))
  outfile=File(fileName || ".new")
  outstream=FileOutputStream(outfile)
  outhandle=OutputStreamWriter(outstream)
  say 'Processing' infile'...'
catch e=IOException
  say '# error opening file' e.getMessage
  exit
end

/* The main processing loop */
method FileScanned()
        if Debug_Level > 30 then trace results
loop linenum=1 by 1 -- to 1000
  theLine=Rexx inhandle.readLine           -- get next line [as Rexx string]
  if theLine=null then leave linenum       -- normal end of file
  parse theLine sysId dateIn timeIn theRest -- process the line
  fd = SimpleDateFormat("E")  /* day of the week */
  dt = fd.format(Date(dateIn))
  if Debug_Level > 70 then say dt
-- //formatting Month in MMM format like Jan, Feb etc.

         strDateFormat = "MMM";
     sdf = SimpleDateFormat(strDateFormat);
     theMonth = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Month in MMM format : " theMonth

     strDateFormat = "YY";
     sdf = SimpleDateFormat(strDateFormat);
     theYear = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Year in YY format : " theYear

     strDateFormat = "w";
     sdf = SimpleDateFormat(strDateFormat);
     theWeek = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Week in 1-53 format : " theWeek

  if dt="Sat" then iterate linenum       -- skip the wkends
  if dt="Sun" then iterate linenum       -- skip the wkends
  if (theMonth = "May") & (theYear \= 12) then iterate linenum       -- skip May in 2011 and 2013

  if linenum>1 then outhandle.write(linesep, 0, linesep.length)
  outLine = sysId dateIn theWeek timeIn theRest
  outhandle.write(outLine, 0, outLine.length)

catch e=IOException
  say '# error reading or writing file' e.getMessage catch RuntimeException
  say '# processing ended due to -RuntimeException-.'
finally do                              -- close files
    if inhandle\=null  then inhandle.close
    if outhandle\=null then outhandle.close
  catch IOException
    -- ignore errors during close
  end
end linenum

say linenum-1 'lines written'

method reset() public static returns long
        if Debug_Level > 30 then trace results
        TimeNow = System.currentTimeMillis()
        say Date()
        return TimeNow
method elapsed() public static returns int
    if Debug_Level > 30 then trace results
         current=System.currentTimeMillis()
         numeric digits 16
         delta = current - Start_Time
         delta=delta/60000
         numeric digits 9
         delta=delta.format(null,3) %1
--       delta=(delta+totalMinutes) %1
         return delta

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



 

--
Can't tweet, won't tweet!


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
"One can live magnificently in this world if one knows how to work and how to love."  --  Leo Tolstoy

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Alan

--
Needs more cowbell.
Reply | Threaded
Open this post in threaded view
|

Re: main(arg=string[]) Now, how do I use that array as an argument in my program?

George Hovey-2

Alan,
Sorry, just spelling it out.  I see that NetRexx will do it for you under certain circumstances.

When the NetRexx reference implementation provides the main
method instruction by default, it also constructs a NetRexx string of type Rexx from this array of words, with a blank added between words, and assigns the string to the variable arg.




On Fri, May 17, 2013 at 1:43 PM, Alan Sampson <[hidden email]> wrote:
That's what I showed in my 1st reply.

method main(args = String[]) public static
  arg = Rexx(args)
  parse arg ...

Alan.


On 17 May 2013 10:40, George Hovey <[hidden email]> wrote:
The language ref says

   Rexx(arg=String[])

will concatenate all the String(s) in the array.


On Fri, May 17, 2013 at 1:22 PM, Alan Sampson <[hidden email]> wrote:
Doesn't work for me.  This program compiles but doesn't run:

/* NetRexx */
options replace

method main(arg = Rexx) public static
  parse arg aaa
  say aaa
  return

NetRexx portable processor, version NetRexx 3.01, build 40-20120823-0156
Copyright (c) RexxLA, 2011,2012.  All rights reserved.
Parts Copyright (c) IBM Corporation, 1995,2008.
Program zArgTest.nrx
    function main(Rexx)
Compilation of 'zArgTest.nrx' successful
allendale:netrexx developer$ java zArgTest
Error: Main method not found in class zArgTest, please define the main method as:
   public static void main(String[] args)


On 17 May 2013 10:14, Measel, Mike <[hidden email]> wrote:

Yeah, ok but you don’t have to use it that way.

 

method main(arg = Rexx) public static

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Alan Sampson
Sent: Friday, May 17, 2013 11:13 AM
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

 

Not quite true; Java passes the program arguments to main as an array of String objects.

 

Alan.

 

On 17 May 2013 09:11, Measel, Mike <[hidden email]> wrote:

Dude, you can't pass a string array to your main.  Pass a string and parse it.


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Kenneth Klein (TEMA TPC)
Sent: Friday, May 17, 2013 9:25 AM
To: IBM Netrexx
Subject: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

    function main(String[])
  23 +++  say "arg ===>" arg
     +++                ^
     +++ Error: Cannot use this operation on an array (type 'java.lang.String[]')

import java.text.SimpleDateFormat
class Filter_Date
        properties public static
                Start_Time = long
                inhandle=BufferedReader
                outhandle=OutputStreamWriter
                linesep=System.getProperty('line.separator') -- be platform-neutral
                fin = string
                Debug_Level = 100
                trace methods
method main(arg=String[]) static public
        if Debug_Level > 90 then trace var fin Delta fName fileName
        if Debug_Level > 50 then trace results
        say "arg ===>" arg
        parse arg fin -- get the arguments: input and output files
        if fin='' then do
                say '# Please specify input file.'
                exit 1
        end
        Start_Time = reset()
        Filter_Date(fin)

method Filter_Date(fName)
        if Debug_Level > 30 then trace results
        FileHandles(fName)
        FileScanned()
        say "Elapsed time:" elapsed()

/* Open and check the files */
Method FileHandles(fileName)
        if Debug_Level > 30 then trace results
        say "Current time:" Start_Time
        say "Elapsed time:" elapsed()
        do
  infile=File(fileName)
  instream=FileInputStream(infile)
  inhandle=BufferedReader(InputStreamReader(instream))
  outfile=File(fileName || ".new")
  outstream=FileOutputStream(outfile)
  outhandle=OutputStreamWriter(outstream)
  say 'Processing' infile'...'
catch e=IOException
  say '# error opening file' e.getMessage
  exit
end

/* The main processing loop */
method FileScanned()
        if Debug_Level > 30 then trace results
loop linenum=1 by 1 -- to 1000
  theLine=Rexx inhandle.readLine           -- get next line [as Rexx string]
  if theLine=null then leave linenum       -- normal end of file
  parse theLine sysId dateIn timeIn theRest -- process the line
  fd = SimpleDateFormat("E")  /* day of the week */
  dt = fd.format(Date(dateIn))
  if Debug_Level > 70 then say dt
-- //formatting Month in MMM format like Jan, Feb etc.

         strDateFormat = "MMM";
     sdf = SimpleDateFormat(strDateFormat);
     theMonth = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Month in MMM format : " theMonth

     strDateFormat = "YY";
     sdf = SimpleDateFormat(strDateFormat);
     theYear = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Year in YY format : " theYear

     strDateFormat = "w";
     sdf = SimpleDateFormat(strDateFormat);
     theWeek = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Week in 1-53 format : " theWeek

  if dt="Sat" then iterate linenum       -- skip the wkends
  if dt="Sun" then iterate linenum       -- skip the wkends
  if (theMonth = "May") & (theYear \= 12) then iterate linenum       -- skip May in 2011 and 2013

  if linenum>1 then outhandle.write(linesep, 0, linesep.length)
  outLine = sysId dateIn theWeek timeIn theRest
  outhandle.write(outLine, 0, outLine.length)

catch e=IOException
  say '# error reading or writing file' e.getMessage catch RuntimeException
  say '# processing ended due to -RuntimeException-.'
finally do                              -- close files
    if inhandle\=null  then inhandle.close
    if outhandle\=null then outhandle.close
  catch IOException
    -- ignore errors during close
  end
end linenum

say linenum-1 'lines written'

method reset() public static returns long
        if Debug_Level > 30 then trace results
        TimeNow = System.currentTimeMillis()
        say Date()
        return TimeNow
method elapsed() public static returns int
    if Debug_Level > 30 then trace results
         current=System.currentTimeMillis()
         numeric digits 16
         delta = current - Start_Time
         delta=delta/60000
         numeric digits 9
         delta=delta.format(null,3) %1
--       delta=(delta+totalMinutes) %1
         return delta

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



 

--
Can't tweet, won't tweet!


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
"One can live magnificently in this world if one knows how to work and how to love."  --  Leo Tolstoy

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
"One can live magnificently in this world if one knows how to work and how to love."  --  Leo Tolstoy

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: main(arg=string[]) Now, how do I use that array as an argument in my program?

rvjansen
I think Alan refers to the fact that any java class that is to be run from the shell needs to have an entrypoint main that needs to be static and has a signature of one argument of type String[] - otherwise the JVM cannot start it. 

René.

On 18 mei 2013, at 09:09, George Hovey <[hidden email]> wrote:


Alan,
Sorry, just spelling it out.  I see that NetRexx will do it for you under certain circumstances.

When the NetRexx reference implementation provides the main
method instruction by default, it also constructs a NetRexx string of type Rexx from this array of words, with a blank added between words, and assigns the string to the variable arg.




On Fri, May 17, 2013 at 1:43 PM, Alan Sampson <[hidden email]> wrote:
That's what I showed in my 1st reply.

method main(args = String[]) public static
  arg = Rexx(args)
  parse arg ...

Alan.


On 17 May 2013 10:40, George Hovey <[hidden email]> wrote:
The language ref says

   Rexx(arg=String[])

will concatenate all the String(s) in the array.


On Fri, May 17, 2013 at 1:22 PM, Alan Sampson <[hidden email]> wrote:
Doesn't work for me.  This program compiles but doesn't run:

/* NetRexx */
options replace

method main(arg = Rexx) public static
  parse arg aaa
  say aaa
  return

NetRexx portable processor, version NetRexx 3.01, build 40-20120823-0156
Copyright (c) RexxLA, 2011,2012.  All rights reserved.
Parts Copyright (c) IBM Corporation, 1995,2008.
Program zArgTest.nrx
    function main(Rexx)
Compilation of 'zArgTest.nrx' successful
allendale:netrexx developer$ java zArgTest
Error: Main method not found in class zArgTest, please define the main method as:
   public static void main(String[] args)


On 17 May 2013 10:14, Measel, Mike <[hidden email]> wrote:

Yeah, ok but you don’t have to use it that way.

 

method main(arg = Rexx) public static

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Alan Sampson
Sent: Friday, May 17, 2013 11:13 AM
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

 

Not quite true; Java passes the program arguments to main as an array of String objects.

 

Alan.

 

On 17 May 2013 09:11, Measel, Mike <[hidden email]> wrote:

Dude, you can't pass a string array to your main.  Pass a string and parse it.


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Kenneth Klein (TEMA TPC)
Sent: Friday, May 17, 2013 9:25 AM
To: IBM Netrexx
Subject: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

    function main(String[])
  23 +++  say "arg ===>" arg
     +++                ^
     +++ Error: Cannot use this operation on an array (type 'java.lang.String[]')

import java.text.SimpleDateFormat
class Filter_Date
        properties public static
                Start_Time = long
                inhandle=BufferedReader
                outhandle=OutputStreamWriter
                linesep=System.getProperty('line.separator') -- be platform-neutral
                fin = string
                Debug_Level = 100
                trace methods
method main(arg=String[]) static public
        if Debug_Level > 90 then trace var fin Delta fName fileName
        if Debug_Level > 50 then trace results
        say "arg ===>" arg
        parse arg fin -- get the arguments: input and output files
        if fin='' then do
                say '# Please specify input file.'
                exit 1
        end
        Start_Time = reset()
        Filter_Date(fin)

method Filter_Date(fName)
        if Debug_Level > 30 then trace results
        FileHandles(fName)
        FileScanned()
        say "Elapsed time:" elapsed()

/* Open and check the files */
Method FileHandles(fileName)
        if Debug_Level > 30 then trace results
        say "Current time:" Start_Time
        say "Elapsed time:" elapsed()
        do
  infile=File(fileName)
  instream=FileInputStream(infile)
  inhandle=BufferedReader(InputStreamReader(instream))
  outfile=File(fileName || ".new")
  outstream=FileOutputStream(outfile)
  outhandle=OutputStreamWriter(outstream)
  say 'Processing' infile'...'
catch e=IOException
  say '# error opening file' e.getMessage
  exit
end

/* The main processing loop */
method FileScanned()
        if Debug_Level > 30 then trace results
loop linenum=1 by 1 -- to 1000
  theLine=Rexx inhandle.readLine           -- get next line [as Rexx string]
  if theLine=null then leave linenum       -- normal end of file
  parse theLine sysId dateIn timeIn theRest -- process the line
  fd = SimpleDateFormat("E")  /* day of the week */
  dt = fd.format(Date(dateIn))
  if Debug_Level > 70 then say dt
-- //formatting Month in MMM format like Jan, Feb etc.

         strDateFormat = "MMM";
     sdf = SimpleDateFormat(strDateFormat);
     theMonth = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Month in MMM format : " theMonth

     strDateFormat = "YY";
     sdf = SimpleDateFormat(strDateFormat);
     theYear = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Year in YY format : " theYear

     strDateFormat = "w";
     sdf = SimpleDateFormat(strDateFormat);
     theWeek = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Week in 1-53 format : " theWeek

  if dt="Sat" then iterate linenum       -- skip the wkends
  if dt="Sun" then iterate linenum       -- skip the wkends
  if (theMonth = "May") & (theYear \= 12) then iterate linenum       -- skip May in 2011 and 2013

  if linenum>1 then outhandle.write(linesep, 0, linesep.length)
  outLine = sysId dateIn theWeek timeIn theRest
  outhandle.write(outLine, 0, outLine.length)

catch e=IOException
  say '# error reading or writing file' e.getMessage catch RuntimeException
  say '# processing ended due to -RuntimeException-.'
finally do                              -- close files
    if inhandle\=null  then inhandle.close
    if outhandle\=null then outhandle.close
  catch IOException
    -- ignore errors during close
  end
end linenum

say linenum-1 'lines written'

method reset() public static returns long
        if Debug_Level > 30 then trace results
        TimeNow = System.currentTimeMillis()
        say Date()
        return TimeNow
method elapsed() public static returns int
    if Debug_Level > 30 then trace results
         current=System.currentTimeMillis()
         numeric digits 16
         delta = current - Start_Time
         delta=delta/60000
         numeric digits 9
         delta=delta.format(null,3) %1
--       delta=(delta+totalMinutes) %1
         return delta

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



 

--
Can't tweet, won't tweet!


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
"One can live magnificently in this world if one knows how to work and how to love."  --  Leo Tolstoy

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
"One can live magnificently in this world if one knows how to work and how to love."  --  Leo Tolstoy
_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: main(arg=string[]) Now, how do I use that array as an argument in my program?

ThSITC
In reply to this post by George Hovey-2
Exactly, all!

When the *main* class is *automatically* generated, then:

parse arg param1 ...

is all You have to do!

When You are having Your *own class* statement, e.g.:

class myclass(args=String[]) ...  --- then You shall have to code next two lines:

arg=args   --- this does, by DEFAULT, convert the args Array to a simple Rexx Var arg
parse arg param1 .... -- then has to be the *next* (or, more exactly, *one of the next* statement !)

Hope that might be helpful ...
Happy Pfingsten !

The Wholy Ghost ;-) ;-) ;-)
====================================================================
Am 18.05.2013 15:09, schrieb George Hovey:

Alan,
Sorry, just spelling it out.  I see that NetRexx will do it for you under certain circumstances.

When the NetRexx reference implementation provides the main
method instruction by default, it also constructs a NetRexx string of type Rexx from this array of words, with a blank added between words, and assigns the string to the variable arg.




On Fri, May 17, 2013 at 1:43 PM, Alan Sampson <[hidden email]> wrote:
That's what I showed in my 1st reply.

method main(args = String[]) public static
  arg = Rexx(args)
  parse arg ...

Alan.


On 17 May 2013 10:40, George Hovey <[hidden email]> wrote:
The language ref says

   Rexx(arg=String[])

will concatenate all the String(s) in the array.


On Fri, May 17, 2013 at 1:22 PM, Alan Sampson <[hidden email]> wrote:
Doesn't work for me.  This program compiles but doesn't run:

/* NetRexx */
options replace

method main(arg = Rexx) public static
  parse arg aaa
  say aaa
  return

NetRexx portable processor, version NetRexx 3.01, build 40-20120823-0156
Copyright (c) RexxLA, 2011,2012.  All rights reserved.
Parts Copyright (c) IBM Corporation, 1995,2008.
Program zArgTest.nrx
    function main(Rexx)
Compilation of 'zArgTest.nrx' successful
allendale:netrexx developer$ java zArgTest
Error: Main method not found in class zArgTest, please define the main method as:
   public static void main(String[] args)


On 17 May 2013 10:14, Measel, Mike <[hidden email]> wrote:

Yeah, ok but you don’t have to use it that way.

 

method main(arg = Rexx) public static

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Alan Sampson
Sent: Friday, May 17, 2013 11:13 AM
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

 

Not quite true; Java passes the program arguments to main as an array of String objects.

 

Alan.

 

On 17 May 2013 09:11, Measel, Mike <[hidden email]> wrote:

Dude, you can't pass a string array to your main.  Pass a string and parse it.


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Kenneth Klein (TEMA TPC)
Sent: Friday, May 17, 2013 9:25 AM
To: IBM Netrexx
Subject: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

    function main(String[])
  23 +++  say "arg ===>" arg
     +++                ^
     +++ Error: Cannot use this operation on an array (type 'java.lang.String[]')

import java.text.SimpleDateFormat
class Filter_Date
        properties public static
                Start_Time = long
                inhandle=BufferedReader
                outhandle=OutputStreamWriter
                linesep=System.getProperty('line.separator') -- be platform-neutral
                fin = string
                Debug_Level = 100
                trace methods
method main(arg=String[]) static public
        if Debug_Level > 90 then trace var fin Delta fName fileName
        if Debug_Level > 50 then trace results
        say "arg ===>" arg
        parse arg fin -- get the arguments: input and output files
        if fin='' then do
                say '# Please specify input file.'
                exit 1
        end
        Start_Time = reset()
        Filter_Date(fin)

method Filter_Date(fName)
        if Debug_Level > 30 then trace results
        FileHandles(fName)
        FileScanned()
        say "Elapsed time:" elapsed()

/* Open and check the files */
Method FileHandles(fileName)
        if Debug_Level > 30 then trace results
        say "Current time:" Start_Time
        say "Elapsed time:" elapsed()
        do
  infile=File(fileName)
  instream=FileInputStream(infile)
  inhandle=BufferedReader(InputStreamReader(instream))
  outfile=File(fileName || ".new")
  outstream=FileOutputStream(outfile)
  outhandle=OutputStreamWriter(outstream)
  say 'Processing' infile'...'
catch e=IOException
  say '# error opening file' e.getMessage
  exit
end

/* The main processing loop */
method FileScanned()
        if Debug_Level > 30 then trace results
loop linenum=1 by 1 -- to 1000
  theLine=Rexx inhandle.readLine           -- get next line [as Rexx string]
  if theLine=null then leave linenum       -- normal end of file
  parse theLine sysId dateIn timeIn theRest -- process the line
  fd = SimpleDateFormat("E")  /* day of the week */
  dt = fd.format(Date(dateIn))
  if Debug_Level > 70 then say dt
-- //formatting Month in MMM format like Jan, Feb etc.

         strDateFormat = "MMM";
     sdf = SimpleDateFormat(strDateFormat);
     theMonth = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Month in MMM format : " theMonth

     strDateFormat = "YY";
     sdf = SimpleDateFormat(strDateFormat);
     theYear = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Year in YY format : " theYear

     strDateFormat = "w";
     sdf = SimpleDateFormat(strDateFormat);
     theWeek = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Week in 1-53 format : " theWeek

  if dt="Sat" then iterate linenum       -- skip the wkends
  if dt="Sun" then iterate linenum       -- skip the wkends
  if (theMonth = "May") & (theYear \= 12) then iterate linenum       -- skip May in 2011 and 2013

  if linenum>1 then outhandle.write(linesep, 0, linesep.length)
  outLine = sysId dateIn theWeek timeIn theRest
  outhandle.write(outLine, 0, outLine.length)

catch e=IOException
  say '# error reading or writing file' e.getMessage catch RuntimeException
  say '# processing ended due to -RuntimeException-.'
finally do                              -- close files
    if inhandle\=null  then inhandle.close
    if outhandle\=null then outhandle.close
  catch IOException
    -- ignore errors during close
  end
end linenum

say linenum-1 'lines written'

method reset() public static returns long
        if Debug_Level > 30 then trace results
        TimeNow = System.currentTimeMillis()
        say Date()
        return TimeNow
method elapsed() public static returns int
    if Debug_Level > 30 then trace results
         current=System.currentTimeMillis()
         numeric digits 16
         delta = current - Start_Time
         delta=delta/60000
         numeric digits 9
         delta=delta.format(null,3) %1
--       delta=(delta+totalMinutes) %1
         return delta

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



 

--
Can't tweet, won't tweet!


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
"One can live magnificently in this world if one knows how to work and how to love."  --  Leo Tolstoy

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
"One can live magnificently in this world if one knows how to work and how to love."  --  Leo Tolstoy


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



--
Thomas Schneider, IT Consulting; http://www.thsitc.com; Vienna, Austria, Europe

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Thomas Schneider, Vienna, Austria (Europe) :-)

www.thsitc.com
www.db-123.com
Reply | Threaded
Open this post in threaded view
|

Re: main(arg=string[]) Now, how do I use that array as an argument in my program?

alansam
That doesn't work either.  This program:

/* NetRexx */
options replace java format comments

method main(args = String[]) public static
  arg = args
  parse arg aaa
  say aaa
  return

compiles but doesn't produce the desired results:

NetRexx portable processor, version NetRexx 3.01, build 40-20120823-0156
Copyright (c) RexxLA, 2011,2012.  All rights reserved.
Parts Copyright (c) IBM Corporation, 1995,2008.
Program zMainExplicit.nrx
    function main(String[])
Compilation of 'zMainExplicit.nrx' successful
$ java zMainExplicit aaa
[Ljava.lang.String;@7afa0094

because the Java that gets created is:

public class zMainExplicit{
 private static final char[] $01={1,10,1,0,0};
 private static final java.lang.String $0="zMainExplicit.nrx";
 
 public static void main(java.lang.String args[]){
  java.lang.String arg[];  // <<-- This is not what you want
  netrexx.lang.Rexx aaa=null;
  arg=args;
  {netrexx.lang.Rexx $1[]=new netrexx.lang.Rexx[1];
  netrexx.lang.RexxParse.parse(new netrexx.lang.Rexx(java.lang.String.valueOf(arg)),$01,$1);
  aaa=$1[0];}
  netrexx.lang.RexxIO.Say(aaa);
  return;
  }
 
 private zMainExplicit(){return;}
 }

You need to coerce the args String array into a Rexx object by using the appropriate constructor [Rexx(String[])] as I presented first.

/* NetRexx */
options replace java format comments

method main(args = String[]) public static
  arg = Rexx(args)
  parse arg aaa
  say aaa
  return

which creates the following Java:

public class zMainExplicit{
 private static final char[] $01={1,10,1,0,0};
 private static final java.lang.String $0="zMainExplicit.nrx";
 
 public static void main(java.lang.String args[]){
  netrexx.lang.Rexx arg;
  netrexx.lang.Rexx aaa=null;
  arg=new netrexx.lang.Rexx(args); // <<-- The Rexx(String[]) constructor
  {netrexx.lang.Rexx $1[]=new netrexx.lang.Rexx[1];
  netrexx.lang.RexxParse.parse(arg,$01,$1);
  aaa=$1[0];}
  netrexx.lang.RexxIO.Say(aaa);
  return;
  }
 
 private zMainExplicit(){return;}
 }

and runs as follows:

NetRexx portable processor, version NetRexx 3.01, build 40-20120823-0156
Copyright (c) RexxLA, 2011,2012.  All rights reserved.
Parts Copyright (c) IBM Corporation, 1995,2008.
Program zMainExplicit.nrx
    function main(String[])
Compilation of 'zMainExplicit.nrx' successful
$ java zMainExplicit aaa bbb
aaa bbb

Conversely; if you don't specify a main method then NetRexx creates one for you and handles all the heavy lifting:

/* NetRexx */
options replace java format comments
  parse arg aaa
  say aaa
  return

creates Java:

public class zMainImplicit{
 private static final char[] $01={1,10,1,0,0};
 private static final java.lang.String $0="zMainImplicit.nrx";
 
 public static void main(java.lang.String $0s[]){
  netrexx.lang.Rexx aaa=null;
  netrexx.lang.Rexx arg=new netrexx.lang.Rexx($0s); // <<-- same as above
  {netrexx.lang.Rexx $1[]=new netrexx.lang.Rexx[1];
  netrexx.lang.RexxParse.parse(arg,$01,$1);
  aaa=$1[0];}
  netrexx.lang.RexxIO.Say(aaa);
  return;
  }
 
 private zMainImplicit(){return;}
 }

a sample run:

NetRexx portable processor, version NetRexx 3.01, build 40-20120823-0156
Copyright (c) RexxLA, 2011,2012.  All rights reserved.
Parts Copyright (c) IBM Corporation, 1995,2008.
Program zMainImplicit.nrx
Compilation of 'zMainImplicit.nrx' successful
$ java zMainImplicit aaa bbb
aaa bbb

Alan.



On 18 May 2013 11:03, Thomas Schneider <[hidden email]> wrote:
Exactly, all!

When the *main* class is *automatically* generated, then:

parse arg param1 ...

is all You have to do!

When You are having Your *own class* statement, e.g.:

class myclass(args=String[]) ...  --- then You shall have to code next two lines:

arg=args   --- this does, by DEFAULT, convert the args Array to a simple Rexx Var arg
parse arg param1 .... -- then has to be the *next* (or, more exactly, *one of the next* statement !)

Hope that might be helpful ...
Happy Pfingsten !

The Wholy Ghost ;-) ;-) ;-)
====================================================================
Am 18.05.2013 15:09, schrieb George Hovey:

Alan,
Sorry, just spelling it out.  I see that NetRexx will do it for you under certain circumstances.

When the NetRexx reference implementation provides the main
method instruction by default, it also constructs a NetRexx string of type Rexx from this array of words, with a blank added between words, and assigns the string to the variable arg.




On Fri, May 17, 2013 at 1:43 PM, Alan Sampson <[hidden email]> wrote:
That's what I showed in my 1st reply.

method main(args = String[]) public static
  arg = Rexx(args)
  parse arg ...

Alan.


On 17 May 2013 10:40, George Hovey <[hidden email]> wrote:
The language ref says

   Rexx(arg=String[])

will concatenate all the String(s) in the array.


On Fri, May 17, 2013 at 1:22 PM, Alan Sampson <[hidden email]> wrote:
Doesn't work for me.  This program compiles but doesn't run:

/* NetRexx */
options replace

method main(arg = Rexx) public static
  parse arg aaa
  say aaa
  return

NetRexx portable processor, version NetRexx 3.01, build 40-20120823-0156
Copyright (c) RexxLA, 2011,2012.  All rights reserved.
Parts Copyright (c) IBM Corporation, 1995,2008.
Program zArgTest.nrx
    function main(Rexx)
Compilation of 'zArgTest.nrx' successful
allendale:netrexx developer$ java zArgTest
Error: Main method not found in class zArgTest, please define the main method as:
   public static void main(String[] args)


On 17 May 2013 10:14, Measel, Mike <[hidden email]> wrote:

Yeah, ok but you don’t have to use it that way.

 

method main(arg = Rexx) public static

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Alan Sampson
Sent: Friday, May 17, 2013 11:13 AM
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

 

Not quite true; Java passes the program arguments to main as an array of String objects.

 

Alan.

 

On 17 May 2013 09:11, Measel, Mike <[hidden email]> wrote:

Dude, you can't pass a string array to your main.  Pass a string and parse it.


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Kenneth Klein (TEMA TPC)
Sent: Friday, May 17, 2013 9:25 AM
To: IBM Netrexx
Subject: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

    function main(String[])
  23 +++  say "arg ===>" arg
     +++                ^
     +++ Error: Cannot use this operation on an array (type 'java.lang.String[]')

import java.text.SimpleDateFormat
class Filter_Date
        properties public static
                Start_Time = long
                inhandle=BufferedReader
                outhandle=OutputStreamWriter
                linesep=System.getProperty('line.separator') -- be platform-neutral
                fin = string
                Debug_Level = 100
                trace methods
method main(arg=String[]) static public
        if Debug_Level > 90 then trace var fin Delta fName fileName
        if Debug_Level > 50 then trace results
        say "arg ===>" arg
        parse arg fin -- get the arguments: input and output files
        if fin='' then do
                say '# Please specify input file.'
                exit 1
        end
        Start_Time = reset()
        Filter_Date(fin)

method Filter_Date(fName)
        if Debug_Level > 30 then trace results
        FileHandles(fName)
        FileScanned()
        say "Elapsed time:" elapsed()

/* Open and check the files */
Method FileHandles(fileName)
        if Debug_Level > 30 then trace results
        say "Current time:" Start_Time
        say "Elapsed time:" elapsed()
        do
  infile=File(fileName)
  instream=FileInputStream(infile)
  inhandle=BufferedReader(InputStreamReader(instream))
  outfile=File(fileName || ".new")
  outstream=FileOutputStream(outfile)
  outhandle=OutputStreamWriter(outstream)
  say 'Processing' infile'...'
catch e=IOException
  say '# error opening file' e.getMessage
  exit
end

/* The main processing loop */
method FileScanned()
        if Debug_Level > 30 then trace results
loop linenum=1 by 1 -- to 1000
  theLine=Rexx inhandle.readLine           -- get next line [as Rexx string]
  if theLine=null then leave linenum       -- normal end of file
  parse theLine sysId dateIn timeIn theRest -- process the line
  fd = SimpleDateFormat("E")  /* day of the week */
  dt = fd.format(Date(dateIn))
  if Debug_Level > 70 then say dt
-- //formatting Month in MMM format like Jan, Feb etc.

         strDateFormat = "MMM";
     sdf = SimpleDateFormat(strDateFormat);
     theMonth = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Month in MMM format : " theMonth

     strDateFormat = "YY";
     sdf = SimpleDateFormat(strDateFormat);
     theYear = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Year in YY format : " theYear

     strDateFormat = "w";
     sdf = SimpleDateFormat(strDateFormat);
     theWeek = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Week in 1-53 format : " theWeek

  if dt="Sat" then iterate linenum       -- skip the wkends
  if dt="Sun" then iterate linenum       -- skip the wkends
  if (theMonth = "May") & (theYear \= 12) then iterate linenum       -- skip May in 2011 and 2013

  if linenum>1 then outhandle.write(linesep, 0, linesep.length)
  outLine = sysId dateIn theWeek timeIn theRest
  outhandle.write(outLine, 0, outLine.length)

catch e=IOException
  say '# error reading or writing file' e.getMessage catch RuntimeException
  say '# processing ended due to -RuntimeException-.'
finally do                              -- close files
    if inhandle\=null  then inhandle.close
    if outhandle\=null then outhandle.close
  catch IOException
    -- ignore errors during close
  end
end linenum

say linenum-1 'lines written'

method reset() public static returns long
        if Debug_Level > 30 then trace results
        TimeNow = System.currentTimeMillis()
        say Date()
        return TimeNow
method elapsed() public static returns int
    if Debug_Level > 30 then trace results
         current=System.currentTimeMillis()
         numeric digits 16
         delta = current - Start_Time
         delta=delta/60000
         numeric digits 9
         delta=delta.format(null,3) %1
--       delta=(delta+totalMinutes) %1
         return delta

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



 

--
Can't tweet, won't tweet!


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
"One can live magnificently in this world if one knows how to work and how to love."  --  Leo Tolstoy

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
"One can live magnificently in this world if one knows how to work and how to love."  --  Leo Tolstoy


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



--
Thomas Schneider, IT Consulting; http://www.thsitc.com; Vienna, Austria, Europe

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Alan

--
Needs more cowbell.
Reply | Threaded
Open this post in threaded view
|

Re: main(arg=string[]) Now, how do I use that array as an argument in my program?

kenner
In reply to this post by George Hovey-2

I eventually followed the advice of the error message,  please define the main method as:

   public static void main(String[] args), and came up with this, which compiles and runs.

 

method main(arg=String[]) static public

            if Debug_Level > 90 then trace var fin Delta fName fileName

            if Debug_Level > 50 then trace results

            if arg.length = 0 then do

                        say '# Please specify input file.'

                        exit 1

            end

            fin = arg[0]

            loop letterNum = 1 by 1 to arg.length - 1

                        fin = fin || arg[letterNum]

            end

            say "arg ===>" fin

--          parse arg fin -- get the arguments: input and output files

            if fin='' then do

                        say '# Please specify input file.'

                        exit 1

            end

 

C:\Program Files\Java\jre7\bin\javaw.exe  -cp  .;C:\Users\KEKLEIN\REXX\NetRexx\jEdit\jars\NetRexxC.jar;C:\Program Files\Java\jdk1.7.0_05\lib\tools.jar;C:\Users\KEKLEIN\REXX\NetRexx\jEdit\jedit.jar  Filter_Date  rmf.report.rolledup.txt 

arg ===> rmf.report.rolledup.txt

Mon May 20 10:22:26 EDT 2013

Current time: 1369059746310

Elapsed time: 0.001

Processing rmf.report.rolledup.txt...

 

Now if I could just run it on a BBB.

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of George Hovey
Sent: Friday, May 17, 2013 1:41 PM
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

 

The language ref says

   Rexx(arg=String[])

will concatenate all the String(s) in the array.

 

On Fri, May 17, 2013 at 1:22 PM, Alan Sampson <[hidden email]> wrote:

Doesn't work for me.  This program compiles but doesn't run:

 

/* NetRexx */

options replace

 

method main(arg = Rexx) public static

  parse arg aaa

  say aaa

  return

 

NetRexx portable processor, version NetRexx 3.01, build 40-20120823-0156

Copyright (c) RexxLA, 2011,2012.  All rights reserved.

Parts Copyright (c) IBM Corporation, 1995,2008.

Program zArgTest.nrx

    function main(Rexx)

Compilation of 'zArgTest.nrx' successful

allendale:netrexx developer$ java zArgTest

Error: Main method not found in class zArgTest, please define the main method as:

   public static void main(String[] args)

 

On 17 May 2013 10:14, Measel, Mike <[hidden email]> wrote:

Yeah, ok but you don’t have to use it that way.

 

method main(arg = Rexx) public static

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Alan Sampson
Sent: Friday, May 17, 2013 11:13 AM
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

 

Not quite true; Java passes the program arguments to main as an array of String objects.

 

Alan.

 

On 17 May 2013 09:11, Measel, Mike <[hidden email]> wrote:

Dude, you can't pass a string array to your main.  Pass a string and parse it.


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Kenneth Klein (TEMA TPC)
Sent: Friday, May 17, 2013 9:25 AM
To: IBM Netrexx
Subject: [Ibm-netrexx] main(arg=string[]) Now, how do I use that array as an argument in my program?

    function main(String[])
  23 +++  say "arg ===>" arg
     +++                ^
     +++ Error: Cannot use this operation on an array (type 'java.lang.String[]')

import java.text.SimpleDateFormat
class Filter_Date
        properties public static
                Start_Time = long
                inhandle=BufferedReader
                outhandle=OutputStreamWriter
                linesep=System.getProperty('line.separator') -- be platform-neutral
                fin = string
                Debug_Level = 100
                trace methods
method main(arg=String[]) static public
        if Debug_Level > 90 then trace var fin Delta fName fileName
        if Debug_Level > 50 then trace results
        say "arg ===>" arg
        parse arg fin -- get the arguments: input and output files
        if fin='' then do
                say '# Please specify input file.'
                exit 1
        end
        Start_Time = reset()
        Filter_Date(fin)

method Filter_Date(fName)
        if Debug_Level > 30 then trace results
        FileHandles(fName)
        FileScanned()
        say "Elapsed time:" elapsed()

/* Open and check the files */
Method FileHandles(fileName)
        if Debug_Level > 30 then trace results
        say "Current time:" Start_Time
        say "Elapsed time:" elapsed()
        do
  infile=File(fileName)
  instream=FileInputStream(infile)
  inhandle=BufferedReader(InputStreamReader(instream))
  outfile=File(fileName || ".new")
  outstream=FileOutputStream(outfile)
  outhandle=OutputStreamWriter(outstream)
  say 'Processing' infile'...'
catch e=IOException
  say '# error opening file' e.getMessage
  exit
end

/* The main processing loop */
method FileScanned()
        if Debug_Level > 30 then trace results
loop linenum=1 by 1 -- to 1000
  theLine=Rexx inhandle.readLine           -- get next line [as Rexx string]
  if theLine=null then leave linenum       -- normal end of file
  parse theLine sysId dateIn timeIn theRest -- process the line
  fd = SimpleDateFormat("E")  /* day of the week */
  dt = fd.format(Date(dateIn))
  if Debug_Level > 70 then say dt
-- //formatting Month in MMM format like Jan, Feb etc.

         strDateFormat = "MMM";
     sdf = SimpleDateFormat(strDateFormat);
     theMonth = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Month in MMM format : " theMonth

     strDateFormat = "YY";
     sdf = SimpleDateFormat(strDateFormat);
     theYear = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Year in YY format : " theYear

     strDateFormat = "w";
     sdf = SimpleDateFormat(strDateFormat);
     theWeek = sdf.format(Date(dateIn));
     if Debug_Level > 40 then say "Current Week in 1-53 format : " theWeek

  if dt="Sat" then iterate linenum       -- skip the wkends
  if dt="Sun" then iterate linenum       -- skip the wkends
  if (theMonth = "May") & (theYear \= 12) then iterate linenum       -- skip May in 2011 and 2013

  if linenum>1 then outhandle.write(linesep, 0, linesep.length)
  outLine = sysId dateIn theWeek timeIn theRest
  outhandle.write(outLine, 0, outLine.length)

catch e=IOException
  say '# error reading or writing file' e.getMessage catch RuntimeException
  say '# processing ended due to -RuntimeException-.'
finally do                              -- close files
    if inhandle\=null  then inhandle.close
    if outhandle\=null then outhandle.close
  catch IOException
    -- ignore errors during close
  end
end linenum

say linenum-1 'lines written'

method reset() public static returns long
        if Debug_Level > 30 then trace results
        TimeNow = System.currentTimeMillis()
        say Date()
        return TimeNow
method elapsed() public static returns int
    if Debug_Level > 30 then trace results
         current=System.currentTimeMillis()
         numeric digits 16
         delta = current - Start_Time
         delta=delta/60000
         numeric digits 9
         delta=delta.format(null,3) %1
--       delta=(delta+totalMinutes) %1
         return delta

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



 

--
Can't tweet, won't tweet!


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



 

--
Can't tweet, won't tweet!


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/




--
"One can live magnificently in this world if one knows how to work and how to love."  --  Leo Tolstoy


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: main(arg=string[]) Now, how do I use that array as an argument in my program?

Tom Maynard

On 05/20/2013 09:30 AM, Kenneth Klein (TEMA TPC) wrote:

 

Now if I could just run it on a BBB.

 

I expect you might, but I had to tweak it just a little:

root@beaglebone ~/NetRexx
# nrc foo
NetRexx portable processor, version NetRexx 3.02, build 11-20130323-1551
Copyright (c) RexxLA, 2011,2013.  All rights reserved.
Parts Copyright (c) IBM Corporation, 1995,2008.
Program foo.nrx
    function main(String[])
  2 +++ if Debug_Level > 90 then trace var fin Delta fName fileName
    +++    ^^^^^^^^^^^
    +++ Error: Unknown variable
  3 +++ if Debug_Level > 50 then trace results
    +++    ^^^^^^^^^^^
    +++ Error: Unknown variable
Compilation of 'foo.nrx' failed [2 errors]
root@beaglebone ~/NetRexx
#

So, I just got rid of the offending bits:

root@beaglebone ~/NetRexx
# vim foo.nrx 
root@beaglebone ~/NetRexx
# nrc foo
NetRexx portable processor, version NetRexx 3.02, build 11-20130323-1551
Copyright (c) RexxLA, 2011,2013.  All rights reserved.
Parts Copyright (c) IBM Corporation, 1995,2008.
Program foo.nrx
    function main(String[])
Compilation of 'foo.nrx' successful
root@beaglebone ~/NetRexx
# java foo
# Please specify input file.
root@beaglebone ~/NetRexx
# java foo noexist.txt
arg ===> noexist.txt
root@beaglebone ~/NetRexx
#

I presume that the rest of it would work, but I only bothered to copy over the first 17 lines.

The only time anything like this should fail is if it relied on some fancy, modern Java feature. In my "installation"

root@beaglebone ~/NetRexx
# java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.12pre) (6b24-1.11.1+1.11.2-devel+hg1+54ceda20a02c)
OpenJDK Zero VM (build 20.0-b12, mixed mode)

So no rough stuff, mister!


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: main(arg=string[]) Now, how do I use that array as an argument in my program?

George Hovey-2
As shown by Alan, the Rexx constructor Rexx(String[]) is a highly useful way to gain access to main's String[] arguments.  However, it is not exactly equivalent to the original arguments, as shown here:

https://docs.google.com/file/d/0B6Aj2d0fHs8cU0ZNYzJXTkRMOVk/edit?usp=sharing



On Mon, May 20, 2013 at 11:21 AM, Tom Maynard <[hidden email]> wrote:

On 05/20/2013 09:30 AM, Kenneth Klein (TEMA TPC) wrote:

 

Now if I could just run it on a BBB.

 

I expect you might, but I had to tweak it just a little:

root@beaglebone ~/NetRexx
# nrc foo
NetRexx portable processor, version NetRexx 3.02, build 11-20130323-1551
Copyright (c) RexxLA, 2011,2013.  All rights reserved.
Parts Copyright (c) IBM Corporation, 1995,2008.
Program foo.nrx
    function main(String[])
  2 +++ if Debug_Level > 90 then trace var fin Delta fName fileName
    +++    ^^^^^^^^^^^
    +++ Error: Unknown variable
  3 +++ if Debug_Level > 50 then trace results
    +++    ^^^^^^^^^^^
    +++ Error: Unknown variable
Compilation of 'foo.nrx' failed [2 errors]
root@beaglebone ~/NetRexx
#

So, I just got rid of the offending bits:

root@beaglebone ~/NetRexx
# vim foo.nrx 
root@beaglebone ~/NetRexx
# nrc foo
NetRexx portable processor, version NetRexx 3.02, build 11-20130323-1551
Copyright (c) RexxLA, 2011,2013.  All rights reserved.
Parts Copyright (c) IBM Corporation, 1995,2008.
Program foo.nrx
    function main(String[])
Compilation of 'foo.nrx' successful
root@beaglebone ~/NetRexx
# java foo
# Please specify input file.
root@beaglebone ~/NetRexx
# java foo noexist.txt
arg ===> noexist.txt
root@beaglebone ~/NetRexx
#

I presume that the rest of it would work, but I only bothered to copy over the first 17 lines.

The only time anything like this should fail is if it relied on some fancy, modern Java feature. In my "installation"

root@beaglebone ~/NetRexx
# java -version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.12pre) (6b24-1.11.1+1.11.2-devel+hg1+54ceda20a02c)
OpenJDK Zero VM (build 20.0-b12, mixed mode)

So no rough stuff, mister!


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





--
"One can live magnificently in this world if one knows how to work and how to love."  --  Leo Tolstoy

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/