Re: Generating filenames



Joli.LeChat@xxxxxxxxx wrote:
Hi.

I wrote a program that does a simulation in function of a parameter.
This parameter is variable inside a DO loop.
I'd like to ask you if there's a way to generate a filename for each
step of the loop, so I can store the results. Something like
result1.dat, result2.dat, etc.

For filenames like result001.dat, result002.dat, ..., result010.dat, ... result100.dat, etc you can do:


  character(256) :: filename
  integer :: i

  do i = 1, 20
    write(filename,'("result",i3.3,".dat")' ) i
    ....
  end do

For filenames like result1.dat, result2.dat, ..., result10.dat, ... result100.dat, i.e. no leading zeroes, you can do

  character(256) :: filename
  character(10)  :: result_number
  integer :: i

  do i = 1, 100
    write(result_number,'(i10)') i
    filename = 'result' // TRIM(ADJUSTL(result_number)) // '.dat'
    ....
  end do

I'm not sure if the ADJUSTL is required in the second example, but the first example is clearer (IMO). The first example also makes the files easier to sort in *nix too.

cheers,

paulv

--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
.



Relevant Pages

  • Re: PWM Amp Design
    ... > [Garbage Spice Simulation Snipped] ... >> is replaced by the PWM IC. ... > gives you indications about ERRORS in your circuit. ... > closed loop response rather than measuring the loop response. ...
    (sci.electronics.design)
  • looping through directories
    ... simulation run). ... The code, right now, works, but I'd like to be able to "loop" through a ... select one directory at a time (because the amounts of runs we are ... rather than go through the manual process of ...
    (comp.soft-sys.matlab)
  • Controlling Execution of Simulink
    ... controls between Simulink and my Matlab script. ... I have a main loop that runs in my script file. ... extract some information from my simulation ... but it seems like execution isn't ...
    (comp.soft-sys.matlab)
  • Re: Out of Range - simulation vs. synthesis
    ... case Addr is ... When using cCLUSTER=3 the simulation is aborted with the error ... for i in ls_addr_cluster'range loop ... of if statements (the exit statements turns it into one big if-elsif- ...
    (comp.lang.vhdl)
  • Re: Memory Leaks with pointers
    ... for i in 1 to 10 loop ... or just end the simulation? ... all their component objects before deallocating the ... DOULOS - Developing Design Know-how ...
    (comp.lang.vhdl)