Skip to content
Snippets Groups Projects
toolbox.f90 21.6 KiB
Newer Older
  • Learn to ignore specific revisions
  • 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
    !------------------------------------------------------------------------------|
    !------------------------------------------------------------------------------|
    !                                                                              |
    !              ||===\\                                                         | 
    !              ||    \\                                                        |
    !              ||     ||   //==\\   ||  ||   //==||  ||/==\\                   |
    !              ||     ||  ||    ||  ||  ||  ||   ||  ||    ||                  |
    !              ||    //   ||    ||  ||  ||  ||   ||  ||                        |
    !              ||===//     \\==//    \\==\\  \\==\\  ||                        |
    !                                                                              |
    !------------------------------------------------------------------------------|
    !------------------------------------------------------------------------------|
    !                                                                              |
    !              TOOLBOX    Apr. 2007                                            |
    !                                                                              |
    !------------------------------------------------------------------------------|
    !------------------------------------------------------------------------------|
    
    subroutine show_time (total,step,inc,flag,message)
    
    !------------------------------------------------------------------------------|
    !(((((((((((((((( Purpose of the routine  ))))))))))))))))))))))))))))))))))))))
    !------------------------------------------------------------------------------|
    ! this routine is used to time the main process and track prpgress
    ! of the run by simple output to the maain screen (unit 6)
    ! total is total accumulted time
    ! step is current step accumulated time
    ! inc is time when this routine was called last
    ! flag is 0 means start of a new model run
    ! flag is negative means start of a new time step (-flag)
    ! flag is positive means start of a new operation within the time step
    ! message s message that will be displayed (it must end with a dollar sign)
    ! this routine will print the total time, the time in the step and the last 
    ! operation time depending on the value of flag, the times are reset
    ! to the current time value
    
    !------------------------------------------------------------------------------|
    !((((((((((((((((  declaration of the subroutine arguments  ))))))))))))))))))))
    !------------------------------------------------------------------------------|
    
    implicit none
    
    double precision total,step,inc
    integer flag
    character message*36
    
    !------------------------------------------------------------------------------|
    !(((((((((((((((( declaration of the subroutine internal variables )))))))))))))
    !------------------------------------------------------------------------------|
    
    integer nmessage,i,ierr,iproc,nproc
    double precision tim,dtotal,dstep,dinc
    
    !------------------------------------------------------------------------------|
    !------------------------------------------------------------------------------|
    
    INCLUDE 'mpif.h'
    
    call mpi_comm_size (mpi_comm_world,nproc,ierr)
    call mpi_comm_rank (mpi_comm_world,iproc,ierr)
    
    if (iproc.eq.0) then
       nmessage=36
       do i=36,1,-1
          if (message(i:i).eq.'$') nmessage=i-1
       enddo
       tim=mpi_wtime(ierr)
       dtotal=tim-total
       dstep=tim-step
       dinc=tim-inc
       if (flag.eq.0) then
          write (6,10001) message(1:nmessage),'Total time','Step time','Increment'
    !      write (99,10001) message(1:nmessage),'Total time','Step time','Increment'
          total=tim
          step=tim
          inc=tim
       elseif (flag.lt.0) then
          write (6,10002) message(1:nmessage),-flag,dtotal
    !      write (99,10002) message(1:nmessage),-flag,dtotal
          step=tim
          inc=tim
       else
          write (6,10000) message(1:nmessage),dtotal,dstep,dinc
    !      write (99,10000) message(1:nmessage),dtotal,dstep,dinc
          inc=tim
       endif
    
    10000 format (a36,3f12.4)
    10001 format (a36,3a12)
    10002 format (a29,i7,f12.4)
    
       call flush(6)
    end if
    
    return
    end
    
    
    !------------------------------------------------------------------------------|
    !------------------------------------------------------------------------------|
    !                                                                              |
    !              STOP_RUN    Nov. 2006                                           |
    !                                                                              |
    !------------------------------------------------------------------------------|
    !------------------------------------------------------------------------------|
    
    subroutine stop_run (messsage)
    
    !------------------------------------------------------------------------------|
    !(((((((((((((((( Purpose of the routine  ))))))))))))))))))))))))))))))))))))))
    !------------------------------------------------------------------------------|
    ! subroutine to stop an mpi run properly to ensure that no habged process 
    ! remains and to output a message to the screen
    
    !------------------------------------------------------------------------------|
    !((((((((((((((((  declaration of the subroutine arguments  ))))))))))))))))))))
    !------------------------------------------------------------------------------|
    
    implicit none
    
    character*128 messsage
    
    !------------------------------------------------------------------------------|
    !(((((((((((((((( declaration of the subroutine internal variables )))))))))))))
    !------------------------------------------------------------------------------|
    
    integer iproc, nproc, ierr
    
    !-------------------------------------------------------------------------------
    !-------------------------------------------------------------------------------
    
    INCLUDE 'mpif.h'
    
    call mpi_comm_size (mpi_comm_world,nproc,ierr)
    call mpi_comm_rank (mpi_comm_world,iproc,ierr)
    
    if (iproc.eq.0) print*,messsage(1:index(messsage,'$'))
    
    call mpi_finalize (ierr)
    
    stop 
    end
    
    !------------------------------------------------------------------------------|
    !------------------------------------------------------------------------------|
    !                                                                              |
    !              WRITE_ERROR_VTK    Jan. 2007                                    |
    !                                                                              |
    !------------------------------------------------------------------------------|
    !------------------------------------------------------------------------------|
    
    subroutine write_error_vtk(leaf,volume,icon,x,y,z)
    
    !------------------------------------------------------------------------------|
    !(((((((((((((((( Purpose of the routine  ))))))))))))))))))))))))))))))))))))))
    !------------------------------------------------------------------------------|
    ! routine that prints out the 8 nodes numbers and their coordinates of the 
    ! leaf that has caused a problem in make_matrix, make_pressure, compute_divergence
    ! It also outputs error.vtk that simply contains the 8 nodes coordinates, 
    ! which can be visualised in Mayavi with the Glyph module.
    
    !------------------------------------------------------------------------------|
    !((((((((((((((((  declaration of the subroutine arguments  ))))))))))))))))))))
    !------------------------------------------------------------------------------|
    integer leaf
    double precision volume
    integer, dimension(8) :: icon
    double precision, dimension(8) :: x
    double precision, dimension(8) :: y
    double precision, dimension(8) :: z
    
    
    !------------------------------------------------------------------------------|
    !(((((((((((((((( declaration of the subroutine internal variables )))))))))))))
    !------------------------------------------------------------------------------|
                
    print*,'--------------------------------------------------------------'
    print*,'problematic leaf =',leaf
    print*,'computed volume of the element= ',volume
    print*,'node icon(1,leaf) and its coordinates:',icon(1),x(1),y(1),z(1)
    print*,'node icon(2,leaf) and its coordinates:',icon(2),x(2),y(2),z(2)
    print*,'node icon(3,leaf) and its coordinates:',icon(3),x(3),y(3),z(3)
    print*,'node icon(4,leaf) and its coordinates:',icon(4),x(4),y(4),z(4)
    print*,'node icon(5,leaf) and its coordinates:',icon(5),x(5),y(5),z(5)
    print*,'node icon(6,leaf) and its coordinates:',icon(6),x(6),y(6),z(6)
    print*,'node icon(7,leaf) and its coordinates:',icon(7),x(7),y(7),z(7)
    print*,'node icon(8,leaf) and its coordinates:',icon(8),x(8),y(8),z(8)
       
    open(unit=30,file='error.vtk')
    write(30,'(a)')'# vtk DataFile Version 3.0'
    write(30,'(a)')'velocities'
    write(30,'(a)')'ASCII'
    write(30,'(a)')'DATASET UNSTRUCTURED_GRID'
    write(30,'(a7,i10,a6)')'POINTS ',8,' float'
    write(30,'(3f12.4)') x(1),y(1),z(1)
    write(30,'(3f12.4)') x(2),y(2),z(2)
    write(30,'(3f12.4)') x(3),y(3),z(3)
    write(30,'(3f12.4)') x(4),y(4),z(4)
    write(30,'(3f12.4)') x(5),y(5),z(5)
    write(30,'(3f12.4)') x(6),y(6),z(6)
    write(30,'(3f12.4)') x(7),y(7),z(7)
    write(30,'(3f12.4)') x(8),y(8),z(8)
    write(30,'(a)')'done spheres.vtk'
    close(30)
       
    print*,'file error.vtk produced'
    
    return
    end
    !-------------------------------------------------------------------------------
    !-------------------------------------------------------------------------------
       
    !------------------------------------------------------------------------------|
    !------------------------------------------------------------------------------|
    !                                                                              |
    !              OUTPUT_OCTREE_LSF     Apr. 2007                                 |
    !                                                                              |
    !------------------------------------------------------------------------------|
    !------------------------------------------------------------------------------|
    
    subroutine output_octree_lsf (olsf,surface,is,istep,iter)
    
    !------------------------------------------------------------------------------|
    !(((((((((((((((( Purpose of the routine  ))))))))))))))))))))))))))))))))))))))
    !------------------------------------------------------------------------------|
    ! writes out a triangulated surface and its corresponding octree
    
    !------------------------------------------------------------------------------|
    !((((((((((((((((  declaration of the subroutine arguments  ))))))))))))))))))))
    !------------------------------------------------------------------------------|
    
    use definitions
    
    implicit none
    
    type (octreelsf) olsf
    type (sheet) surface
    integer is
    integer istep
    integer iter
    
    !------------------------------------------------------------------------------|
    !(((((((((((((((( declaration of the subroutine internal variables )))))))))))))
    !------------------------------------------------------------------------------|
    
    integer i,j,k
    integer iproc,nproc,ierr
    character(len=2) cs,citer
    character(len=4) cistep
    
    !------------------------------------------------------------------------------|
    !------------------------------------------------------------------------------|
    
    INCLUDE 'mpif.h'
    
    call mpi_comm_size (mpi_comm_world,nproc,ierr)
    call mpi_comm_rank (mpi_comm_world,iproc,ierr)
    
    if (iproc.eq.0) then
       call int_to_char(cs,2,is)
       call int_to_char(cistep,4,istep)
       call int_to_char(citer,2,iter)
       open (9,file='DEBUG/OLSF/olsf_'//cs//'_'//cistep//'_'//citer//'.txt',status='unknown')
       ! write array lengths
       write (9,*) olsf%octree(3),olsf%nnode,olsf%nleaves 
       ! write info on octree solve nodes (x,y,z,u,v,w,lsf,temp)
       write (9,*) (olsf%x(i),olsf%y(i),olsf%z(i),olsf%lsf(i),i=1,olsf%nnode)
       ! write icon array
       write (9,*) ((olsf%icon(k,i),k=1,8),i=1,olsf%nleaves)
       ! write octree information
       write (9,*) (olsf%octree(i),i=1,olsf%octree(3))
       write (9,*) surface%nsurface,          &
                   surface%activation_time, &
                   surface%nt
       write (9,*) (surface%r(i),  &
                    surface%s(i),  &
                    surface%x(i),  &
                    surface%y(i),  &
                    surface%z(i),  &
                    surface%xn(i) ,&
                    surface%yn(i), &
                    surface%zn(i), &
                    i=1,surface%nsurface)
       write (9,*) (surface%icon(1:3,i),i=1,surface%nt)
       close (9)
    end if
    
    return
    end
    
    !------------------------------------------------------------------------------|
    !------------------------------------------------------------------------------|
    !                                                                              |
    !              OUTPUT_SURF     Apr. 2007                                       |
    !                                                                              |
    !------------------------------------------------------------------------------|
    !------------------------------------------------------------------------------|
    
    subroutine output_surf(surface,is,string,istep,ref_count) 
    
    !------------------------------------------------------------------------------|
    !(((((((((((((((( Purpose of the routine  ))))))))))))))))))))))))))))))))))))))
    !------------------------------------------------------------------------------|
    ! when using the debugging command in DOUAR, this produces vtk files 
    ! of the surface passed as argument.
    
    !------------------------------------------------------------------------------|
    !((((((((((((((((  declaration of the subroutine arguments  ))))))))))))))))))))
    !------------------------------------------------------------------------------|
    
    use definitions
    
    implicit none
    
    type (sheet) surface
    integer is
    character*(*) string
    integer  istep
    integer  ref_count
    
    !------------------------------------------------------------------------------|
    !(((((((((((((((( declaration of the subroutine internal variables )))))))))))))
    !------------------------------------------------------------------------------|
    
    character(len=2) cis,cref_count
    character(len=4) cistep
    integer i,iproc,nproc,ierr
    
    !------------------------------------------------------------------------------|
    !------------------------------------------------------------------------------|
    
    INCLUDE 'mpif.h'
    
    call mpi_comm_size (mpi_comm_world,nproc,ierr)
    call mpi_comm_rank (mpi_comm_world,iproc,ierr)
    
    if (iproc.eq.0) then
       write(cis,'(i2)') is
       if (is.lt.10) cis(1:1)='0'
       if (ref_count>0 .and. istep>0) then
          call int_to_char(cref_count,2,ref_count)
          call int_to_char(cistep,4,istep)
          open(unit=30,file='./DEBUG/SURFACES/surf_'//cis//'_'//string//'_'//cistep //'_'//cref_count//'.vtk')
       else if (istep>0) then
          call int_to_char(cistep,4,istep)
          open(unit=30,file='./DEBUG/SURFACES/surf_'//cis//'_'//string//'_'//cistep//'.vtk')
       else
          open(unit=30,file='./DEBUG/SURFACES/surf_'//cis//'_'//string//'.vtk')
       end if
    
       write(30,'(a)') '# vtk DataFile Version 3.0'
       write(30,'(a)') 'surface'
       write(30,'(a)') 'ASCII'
       write(30,'(a)') 'DATASET UNSTRUCTURED_GRID'
       write(30,'(a7,i10,a6)') 'POINTS',surface%nsurface,'float'
       do i=1,surface%nsurface
          write(30,'(3f16.11)') surface%x(i),surface%y(i),surface%z(i) 
       end do
       write(30,'(a6,2i10)') 'CELLS',surface%nt,(1+3)*surface%nt
       do i=1,surface%nt
          write(30,'(9I10)')3,surface%icon(1:3,i)-1
       enddo
       write(30,'(A11, I10)') 'CELL_TYPES ',surface%nt
       do i=1,surface%nt
          write(30,'(I2)') 5 
       end do
       write(30,'(a11,i10)') 'POINT_DATA ',surface%nsurface
       write(30,'(a)') 'VECTORS normal float'
       do i=1,surface%nsurface
          write(30,'(3f18.13)') surface%xn(i),surface%yn(i),surface%zn(i)
       end do
       close(30)
    end if
    
    return
    end
    
    !------------------------------------------------------------------------------|
    !------------------------------------------------------------------------------|
    
    subroutine write_streepjes(iunit,nb)
    implicit none
    integer iunit,nb,iproc,nproc,ierr,i
    character*72  :: streepjes
    
    INCLUDE 'mpif.h'
    
    call mpi_comm_size (mpi_comm_world,nproc,ierr)
    call mpi_comm_rank (mpi_comm_world,iproc,ierr)
    
    if (iproc.eq.0) then
       streepjes='-----------------------------------------------------------------------'
       do i=1,nb
          write(iunit,*)  streepjes 
       end do
    end if
    
    return
    end
    
    !------------------------------------------------------------------------------|
    !------------------------------------------------------------------------------|
    
    subroutine output_osolve_forces (osolve,nnode,force,istep,iter)
    use definitions
    implicit none
    type (octreesolve) osolve
    integer nnode
    double precision :: force(nnode,3)
    integer istep, iter
    
    integer i,j,is,k,iproc,nproc,ierr
    character*4 cistep
    character*2 citer
    
    
    INCLUDE 'mpif.h'
    
    call mpi_comm_size (mpi_comm_world,nproc,ierr)
    call mpi_comm_rank (mpi_comm_world,iproc,ierr)
    
    if(iproc.eq.0) then
       call int_to_char(cistep,4,istep)
       call int_to_char(citer,2,iter)
       open (9,file='DEBUG/FORCES/osolve_forces_'//cistep//'_'//citer//'.txt',status='unknown')
       write (9,*) osolve%octree(3),osolve%nnode,osolve%nleaves
       write (9,*) (osolve%x(i),osolve%y(i),osolve%z(i),force(i,1),force(i,2),force(i,3),i=1,osolve%nnode)
       write (9,*) ((osolve%icon(k,i),k=1,8),i=1,osolve%nleaves)
       write (9,*) (osolve%octree(i),i=1,osolve%octree(3))
       close (9)
    end if
    
    return
    end
    
    !------------------------------------------------------------------------------|
    !------------------------------------------------------------------------------|
    
    subroutine output_bc (osolve)
    use definitions
    implicit none
    type(octreesolve) osolve
    
    !integer kfix(nnode*3)
    !double precision u(nnode),v(nnode),w(nnode)
    !double precision x(nnode),y(nnode),z(nnode)
    !integer nnode
    !integer kfixt(nnode)
    !double precision temp(nnode)
    integer iproc,nproc,ierr,i,nb,nbt
    INCLUDE 'mpif.h'
    
    call mpi_comm_size (mpi_comm_world,nproc,ierr)
    call mpi_comm_rank (mpi_comm_world,iproc,ierr)
    
    nb=0
    nbt=0
    do i=1,osolve%nnode
       if (osolve%kfix((i-1)*3+1)==1 .or. osolve%kfix((i-1)*3+2)==1 .or. osolve%kfix((i-1)*3+3)==1) then
          nb=nb+1
       end if
       if (osolve%kfixt(i)==1) then
          nbt=nbt+1
       end if
    end do
    
    if (iproc.eq.0) then
       open(unit=30,file='./DEBUG/BC/bc.vtk')
       write(30,'(a)')'# vtk DataFile Version 3.0'
       write(30,'(a)')'velocities'
       write(30,'(a)')'ASCII'
       write(30,'(a)')'DATASET UNSTRUCTURED_GRID'
       write(30,'(a7,i10,a6)')'POINTS ',nb,' float'
       do i=1,osolve%nnode
          if (osolve%kfix((i-1)*3+1)==1 .or. osolve%kfix((i-1)*3+2)==1 .or. osolve%kfix((i-1)*3+3)==1) then
             write(30,'(3f12.4)') osolve%x(i),osolve%y(i),osolve%z(i)
          end if
       end do
       write(30,'(a,i10)')'POINT_DATA', nb
       write(30,'(a)')'VECTORS vel float'
       do i=1,osolve%nnode
          if (osolve%kfix((i-1)*3+1)==1 .or. osolve%kfix((i-1)*3+2)==1 .or. osolve%kfix((i-1)*3+3)==1) then
             write(30,'(3e15.5)') osolve%u(i),osolve%v(i),osolve%w(i) 
          end if
       end do
       write(30,'(a)')'done bc.vtk'
       close(30)
    
       open(unit=30,file='./DEBUG/BC/bct.vtk')
       write(30,'(a)')'# vtk DataFile Version 3.0'
       write(30,'(a)')'velocities'
       write(30,'(a)')'ASCII'
       write(30,'(a)')'DATASET UNSTRUCTURED_GRID'
       write(30,'(a7,i10,a6)')'POINTS ',nbt,' float'
       do i=1,osolve%nnode
          if (osolve%kfixt(i)==1) then
             write(30,'(3e15.5)') osolve%x(i),osolve%y(i),osolve%z(i)
          end if
       end do
       write(30,'(a)')'done bct.vtk'
       close(30)
    end if
    
    return
    end
    
    !------------------------------------------------------------------------------|
    !------------------------------------------------------------------------------|
    
    subroutine int_to_char(charac,ncharac,integ)
    implicit none
    character(len=ncharac) :: charac
    integer integ,ncharac
    
    select case (ncharac)
    case (1)
       write (charac,'(i1)') integ
    case (2)
       write (charac,'(i2)') integ
       if (integ.lt.10) charac(1:1)='0'
    case (3)
       write (charac,'(i3)') integ
       if (integ.lt.100) charac(1:1)='0'
       if (integ.lt.10) charac(1:2)='00'
    case (4)
       write (charac,'(i4)') integ
       if (integ.lt.1000) charac(1:1)='0'
       if (integ.lt.100) charac(1:2)='00'
       if (integ.lt.10) charac(1:3)='000'
    case (5)
       write (charac,'(i5)') integ
       if (integ.lt.10000) charac(1:1)='0'
       if (integ.lt.1000) charac(1:2)='00'
       if (integ.lt.100) charac(1:3)='000'
       if (integ.lt.10) charac(1:4)='0000'
    case (6)
       write (charac,'(i6)') integ
       if (integ.lt.100000) charac(1:1)='0'
       if (integ.lt.10000) charac(1:2)='00'
       if (integ.lt.1000) charac(1:3)='000'
       if (integ.lt.100) charac(1:4)='0000'
       if (integ.lt.10) charac(1:5)='00000'
    case (7)
       write (charac,'(i7)') integ
       if (integ.lt.1000000) charac(1:1)='0'
       if (integ.lt.100000) charac(1:2)='00'
       if (integ.lt.10000) charac(1:3)='000'
       if (integ.lt.1000) charac(1:4)='0000'
       if (integ.lt.100) charac(1:5)='00000'
       if (integ.lt.10) charac(1:6)='000000'
    case (8)
       write (charac,'(i8)') integ
       if (integ.lt.10000000) charac(1:1)='0'
       if (integ.lt.1000000) charac(1:2)='00'
       if (integ.lt.100000) charac(1:3)='000'
       if (integ.lt.10000) charac(1:4)='0000'
       if (integ.lt.1000) charac(1:5)='00000'
       if (integ.lt.100) charac(1:6)='000000'
       if (integ.lt.10) charac(1:7)='0000000'
    case (9)
       write (charac,'(i9)') integ
       if (integ.lt.100000000) charac(1:1)='0'
       if (integ.lt.10000000) charac(1:2)='00'
       if (integ.lt.1000000) charac(1:3)='000'
       if (integ.lt.100000) charac(1:4)='0000'
       if (integ.lt.10000) charac(1:5)='00000'
       if (integ.lt.1000) charac(1:6)='000000'
       if (integ.lt.100) charac(1:7)='0000000'
       if (integ.lt.10) charac(1:8)='00000000'
    case (10)
       write (charac,'(i10)') integ
       if (integ.lt.1000000000) charac(1:1)='0'
       if (integ.lt.100000000) charac(1:2)='00'
       if (integ.lt.10000000) charac(1:3)='000'
       if (integ.lt.1000000) charac(1:4)='0000'
       if (integ.lt.100000) charac(1:5)='00000'
       if (integ.lt.10000) charac(1:6)='000000'
       if (integ.lt.1000) charac(1:7)='0000000'
       if (integ.lt.100) charac(1:8)='00000000'
       if (integ.lt.10) charac(1:9)='000000000'
    case default 
       stop 'value ncharac too big'
    end select
    
    return
    end subroutine int_to_char
    
    !------------------------------------------------------------------------------|
    !------------------------------------------------------------------------------|