• 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 21565
  • 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
Parents
  • 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
Reply
  • 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
Children
No Data
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