Formatted thermo keyword in print file-name

Hi!

I want to 'print' to a file, with a name that includes the number of particles
in the system. Additionally, I want to pad it with zeroes, so that the name of
the file is always of a fixed length.

What I need is something like this:

    print "abc" append file_$(atoms:%05d).dat

But that gives me the following error:
"Substitution for illegal variable size (src/input.cpp:545)"

I also tried doing this by defining a 'format' style variable:

    variable size format \(atoms\) %05d     print {size}

But that also results in the same error.

How do I achieve this?

Thanks!
Vishnu

Hi!

I want to ‘print’ to a file, with a name that includes the number of particles
in the system. Additionally, I want to pad it with zeroes, so that the name of
the file is always of a fixed length.

What I need is something like this:

print “abc” append file_$(atoms:%05d).dat

But that gives me the following error:
“Substitution for illegal variable size (src/input.cpp:545)”

the print line from above CANNOT produce the error message you quote, since it does not contain any reference to a variable named ‘size’

I also tried doing this by defining a ‘format’ style variable:

variable size format (atoms) %05d print {size}

yes, because that is not the correct syntax. instead of using an immediate variable ‘$(atoms)’ you must use a proper variable, e.g. equal style.

But that also results in the same error.

yes, this will create the error, since your definition of ‘size’ is illegal.

axel.

>
> What I need is something like this:
>
> print "abc" append file_$(atoms:%05d).dat
>
> But that gives me the following error:
> "Substitution for illegal variable size (src/input.cpp:545)"
>
>
the print line from above *CANNOT* produce the error message you quote,
since it does not contain any reference to a variable named 'size'

Yes, correct; sorry, I pasted the output of the next command. The actual error
was:

    ERROR on proc 0: Substitution for illegal variable atoms:%05d
(src/input.cpp:545)

Can it not be done this way?

> I also tried doing this by defining a 'format' style variable:
>
> variable size format \(atoms\) %05d > print {size}
>

yes, because that is not the correct syntax. instead of using an immediate
variable '$(atoms)' you must use a proper variable, e.g. equal style.

Okay, so I'm now attempting this:

    variable nums equal atoms
    variable size format nums %05d
    print ${size}

But I must be doing something seriously wrong, because what I get are large,
arbitrary numbers, like: 1318092096, 248134976, -1398260416, 1610366272, etc.

I'm using LAMMPS (15 May 2019).

I'm also attaching a minimal input script that produces this.

in.format (817 Bytes)

please file this as a bug report issue on the LAMMPS github project. thanks in advance, axel.

on second thought, this is not a bug.
the problem is, that you are applying a %d format, i.e. an 32-bit integer format to a double precision floating point number. you must use %f.

axel.

Thanks a lot! It works now!! This gives me exactly what I want:

    variable nums equal atoms
    variable size format nums %05.0f
    print ${size}

But isn't it odd to use floats for the 'atoms' thermo keyword?

all equal or atom style variables evaluate to doubles. that saves having to store type information and complicate the already complicated code even more.

i am adding a small test to the code in variable.cpp and input.cpp so that incorrect conversions will trigger an error in the future.

axel.