• 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 21571
  • 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
  • Charlie Davies
    Charlie Davies over 16 years ago
    Evan,

    The printf function is buffered.  Try using axlMsgPut.

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

     Hi Charlie,

    Hmm, axlMsgPut still doesn't print if it's the first line, but it does print before axlEnterPath (when printf doesn't). So I'm satisfied. So is axlMsgPut best suited for displaying in the Command window and printf is best used for anything else (external file, buffer, etc)? Thanks!

     

    For my second issue, %g doesn't work in the other code I was referring to - it barfs on integers there too. I don't know what I was thinking. So, how can I place either integers or fp numbers in a certain width of field without having zeros padded?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Charlie Davies
    Charlie Davies over 16 years ago
    Evan,

    The only way I know to control formatting of mix types (integers and floats) in the same column would require you to preprocess the list of items, determine their values (character width), then dynamically create a formatted print statement suitable for what you’re trying to print.  Just to be clear I assume you want to print an integer as 1000 and not 1000.00.  Remember you can always turn an integer into a float (float function).

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

     Hi Charlie,

    You're correct, I wanted to print floats with only sig digs, and integers without anything the decimal or anything to the right of the decimal.

    Another smart guy out there pointed me toward using sprintf to assign the number to a string. That did it.

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

     Not bring able to figure out how to format numbers like I want is starting to pile up on me and really trip me up. Consider these following 3 examples where I am currently stuck:

     

     Example 1 (the situation I've been describing in this thread):

    I am printing a report of component heights (reading PACKAGE_HEIGHT_MAX). As the components could be built in various units, and I want to convert to a single unit system (in my case MILS), I will end up with heights in various formats. Footprints built in MILS will likely be integers, but footprints built in MM will almost certainly be floating point numbers, as will footprints built in INCHES (for example, 2 INCHES = 2.000 MILS).

    To make the report much cleaner, I'd like footprints built in MILS to appear as integers. Footprints in MM and INCHES will almost certainly be fp numbers, but I'd prefer not to have trailing zeros.

    Question: How can I take a variable that is either an integer or fp number and format it without any trailing zeros so it can be printed as a number?

     

    Example 2:

    I want to accept user input and print it back to the user. As the design could be done in MILS, MM, or INCHES, the value the user inputs could be an integer or fp.

     Furthermore, I when I print the input back to the user, I want to append the units. So I need to take the number (either integer or fp) and make it a string then append the units. Now, I can use sprintf to make the number a string, and strcat to tie the number and units together, if I could just get the number properly formatted. It looks silly when the user puts in "2" (for example, in INCHES) and gets back "2.000 INCHES". If I was the user, I'd expect "2 INCHES". Similarly, if the user puts in "25" in MILS, you don't want to get back "25.000 MILS" since the trailing zeros are so small they're generally irrelevant.

    Question: How can I accept user input that is either integer or fp, and get that into a string without any trailing zeros (note similarity to above)?

     

    Example 3:

    I am creating a report in which one column is a property that is defined by the footprint symbol, but which is brought from the schematic ("Create user-defined properties" must be checked in the Export Physical form to annotate this property to Allegro). This property, the distance between through holes, is not present on SMT or irrelevant parts (property is "nil") and the property is "NA" for through hole parts where the pad spacing doesn't matter. Where pad spacing does matter, it is a fp number (for example, ".200" in MILS). I am using Extracta to get this property into my SKILL routine and then nth(...) to pull out the desired value from the Extracta output file.

      So, when the report is printed I am using "%L" format specification to be able to print either "nil", "NA", or a fp number without any errors but I am having problems with the resulting data. When the property doesn't exist, I get "nil" without quotes. When the property value is "NA" (without quotes), I get "NA" with quotes, which I assume is because this is a two-letter string. And if there is a number, I get the number surrounded by quotes.

    The program that needs this report cannot accept the quotes, so I must first remove the quotes. But how? Also, I'd prefer to have nothing in the report column if the property doesn't exist (or if it's "NA"), and (ideally) the only condition that would place something in this column would be if there is a value for this property that is not "NA" (without quotes). I can visualize how to do this, but I can't seem to figure out the right way to make it happen. I am able to detect "NA" as the value, but I'm not able to change it to "nil". I get a "left hand assignment error" when I try to set the nth(...) variable equal to "" (doube quotes) or "nil".

    Question: How can I accept a variable with a value of nothing (nil), a string, or a fp number, and print the variable without any errors? Bonus points if I can wipe out the value of the variable (make it nil) if it meets my criteria.

     

    Summary:

    Wow, I am long winded! Thank you if you could trudge through all that. I'm sure it's a bit harder to figure out without seeing the code, but I have to believe this is a fairly common problem. Ever since the first programs were written, I can imagine similar situations. There has to be a way  to achieve the formatting I desire or else programs I regularly use wouldn't display numbers the way they do. I know this type of formatting can be done.

    So, in short, if I have a variable that is an integer or fp number, how can I print it without trailing zeros?

    The second part of the question is similar to the first: if the variable may not have any value, or might be a string, or might be a fp number, how can I accept any of those and print out (optionally discarding strings and nil values) only the fp number, so I get nothing if the value of the variable is nothing?

    • 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