• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Allegro X PCB Editor
  3. printf() as first line and number formatting

Stats

  • Replies 14
  • Subscribers 160
  • Views 21557
  • Members are here 0
More Content

printf() as first line and number formatting

EvanShultz
EvanShultz over 16 years ago

OK, here's a weird one for you. I want to print some information for the user into the Command window before I do anything else. So, I figured why not make a printf() statement the very first line of code? I suppose it should work - George does it on lines 25-35 of tekTechFileXML.il (from SourceLink). But for me, nothing is printed in the Command window. If I move the exact same statement as the first line of the procedure(), the text is printed to the Command window.

So what's my problem? Well, farther down in the procedure() a subroutine is called which uses axlEnterPath(). And the "Enter first point" prompt from axlEnterPath() comes BEFORE my printf() text, even though the printf() comes first in the code. My mind is boggled. I changed the prompt for axlEnterPath so I know it is this SKILL function that is creating the prompt which is jumping ahead of my printf() text.

Any ideas why this SKILL function can't wait it's turn? Or, better yet, how can I get the string in a printf() statement to show in the Command window if the printf() statement is the very first line of the SKILL routine?

 

 Secondly, I want to print out a table of information which may be integers or floating point numbers. How can I do this while keeping the table nicely lined up? Here is what I've found:

%-10n - displays both number types, but pads with zeros for floating point numbers

%-10g or %g - barfs on integers

%-10L or %L - displays both number types, no padding zeros for fp, but ignores [width] field (as per page 170 of sklangref.pdf)

So, what options do I have? I want similar to %-10n output, but without zero padding. %-10g would seem to be the right choice. I've used %g in other SKILL programs and it gracefully handled both integer and fp numbers - any ideas why it isn't with integers for me now?

  • Sign in to reply
  • Cancel
  • eDave
    eDave over 16 years ago

    Hi Evan,

     There are plenty of ways to achieve this but these might give you some ideas:

    Eg.1: sprintf(nil, if(integerp(n), "%d", "%2.3f") n)

    Eg. 2: axlMKSStr2UU(sprintf(nil, "%n", readstring(sprintf(nil, "%n", value))))

    Eg. 3: if(value then value = readstring(value), axlMKSStr2UU(sprintf(nil, cond((stringp(value), value)(integerp(value), "%d"), (floatp(value), "%2.3f")) value)) else "")

     

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Ejlersen
    Ejlersen over 16 years ago

    Hi

    As you point out, there are plenty of ways. I've used sprintf a number of times to create the formatting string. You can then just wrap this sprintf command into case or if/then constructs depending on what you're looking at. You just have to keep you head cold when writing the formatting string, it can get complex.

    example: (taken from a pick and place output utility that I've made)

    pn_length > 1 if partnumber is defined for part

    package_length is the length of the package symbol name (strlen)

    value_length is the length of the component value (strlen)

      if( pn_length > 1 then
       sprintf(pp_header "%s%d%s%d%s%d%s" "%-7s %-8s %-8s %-8.3f %-" (package_length +2) "s %-" (value_length +2) "s %-" (pn_length+2) "s\n")
      else
       sprintf(pp_header "%s%d%s%d%s%s" "%-7s %-8s %-8s %-8.3f %-" (package_length +2) "s %-" (value_length +2) "s" "\n")
      )

    then just use the fprintf or printf with the formatting header

         if( pn_length > 1 then
          fprintf(sm_top, pp_header, c_refdes, x_coor, y_coor, c_rotation, c_psm, c_value, c_pn)
         else
          fprintf(sm_top, pp_header, c_refdes, x_coor, y_coor, c_rotation, c_psm, c_value)
         )

    c_refdes=reference designator, x_coor is x coordinate, y_coor is y coordinate, c_rotation is the rotation, c_psm is the package symbol name, c_value is the component value and c_pn is the component partnumber

    Best regards

    Ole 

     

    Hope this helps?

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • EvanShultz
    EvanShultz over 16 years ago

     Hi Dave and Ole,

     Thank you very much! I am getting the formatting I desire now! I knew it could be done and you two showed me a way.

    In case anyone might see this and use it in the future, I'm presenting my solution. I decided to use the cond() function and then checked for the type of object I was dealing with. That way I can print the object differently depending on what it is. Like so:

    cond(                                                                
        (integerp(object) sprintf(object_str "%d" object))
        (floatp(object) sprintf(object_str "%g" object))
    )

    Now, I can use "%s" to print the object. And I don't have any trailing zeros for floats and integers stop at the decimanl point. And I could add a null(object) to see if there was no value, or check for equality within the cond(), etc. So I can cover all the cases I detailed above.

    It seems like a fairly simple concept now, and I appreciate your help in making this concept seem simple. Thanks again!!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • EvanShultz
    EvanShultz over 16 years ago

    I am getting the printing results I want, but SKILL Lint isn't so happy with one line of code. In the case where the input variable is nil, it is being fed to the else clause of an if statement and dealt with using the following code:

    sprintf(object_str "" nil)

     That works just fine and gives me the result I want, so I can print everything with a "%s" format. But although I'm happy with the code and it does just want I want, SKILL Lint doesn't give the program an IQ of 100 due to this line of code.

     What could be the problem with this line of code? Should I ignore SKILL Lint's complaint? Is there a way to make a nil variable into an empty string, printable by "%s", without making SKILL Lint gripe?

     

    As an aside, page 10 of http://www.cadence.com/rl/Resources/conference_papers/stp_cdnlive2006India_AlgroSkill.pdf shows SKILL Lint recommending a replacement of nth(1 ...) with cadr(...). Why? What about be the implications? How much weight can be given to SKILL Lint results?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • skillUser
    skillUser over 16 years ago

    Hi Evan,

    I work with SKILL in the CIC (Custom IC) tools where we have Lint also.  I suspect that the problem is that you do not have any format specifier in the formatting string. Typically you can use as a format specifier %L to print anything including 'nil' which would throw an error if used with a format like %s etc. So your example might now be:

    sprintf(object_str "%L" nil)

    However, I don't understand what you are trying to do. What do you want the string object_str to contain if the variable is nil?  I hope that this is useful information, but if not, explain what you are trying to achieve and we may be able to help you further.

    Regards,

    Lawrence.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
<>
Cadence Guidelines

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information