8 Replies Latest reply on Nov 10, 2010 5:07 AM by Rasale

    openf95 INTERNAL ERROR

    pjjr

      Whilst trying to compile a suite of Fortran custom programs on my 6168 Opteron Linux box running Centos 2.6, I was met with the following error message:

      ### Compiler Error in file ../calc_fplanes.f90 during Global Optimization -- Mainopt Lowering phase:
      ### process_inqvar, LDA: unexpected var type (M) in I/O processing
      openf95 INTERNAL ERROR: /opt/x86_open64-4.2.4/lib/gcc-lib/x86_64-open64-linux/4.2.4/be returned non-zero status 1

      Has anyone come across this one or have any advice for how to get over this problem?

      Thanks in advance

       

        • openf95 INTERNAL ERROR
          Rasale

          Hi,

                          Thanks for reaching the support desk. Can you please share with us the code that is causing this error  along with the command line/flag sets you have used to compile?

           

          Thanks

          Anupama

            • openf95 INTERNAL ERROR
              pjjr

              Dear Anupama,

               

              Thanks for getting back so fast. I'm not actually the author of the code but the owner of the machine. I could send you the whole fortran library since the problematic procedure (calc_fplanes.f90) is compiled with all it's dependencies in the package.

              The compilation attempt was performed using the following perl script:

              ./simple_compile.pl openf95 1 0 1

              ####################################

              #!/usr/bin/perl

              use warnings;
              use strict;

              if( @ARGV != 5 ){
                  die "Need five command line arg:s\n(1) SIMPLE program name\n(2) compiler (ifort or openf95)\n(3) optimized code or not (1 or 0)\n(4) mac or not (1 or 0)\n(5) clean or not (1 or 0)\n";  
              }

              my$prog     = $ARGV[0];
              my$compiler = $ARGV[1];
              my$opt      = $ARGV[2];
              my$mac      = $ARGV[3];
              my$clean    = $ARGV[4];

              if($prog eq "all"){
                  chdir("evol_align_seq");
                  system("../fmkmf.pl -f90 $compiler -openmp 0 -opt $opt -mac $mac evol_align.f90 > makefile");
                  ($clean == 1) && (($clean == 1) && (system("make clean")));
                  system("make");
                  chdir("../");
                  chdir("evol_align_para");
                  system("../fmkmf.pl -f90 $compiler -openmp 1 -opt $opt -mac $mac evol_align.f90 > makefile");
                  ($clean == 1) && (system("make clean"));
                  system("make");
                  chdir("../");
                  chdir("rfpclust_seq");
                  system("../fmkmf.pl -f90 $compiler -openmp 0 -opt $opt -mac $mac rfpclust.f90 > makefile");
                  ($clean == 1) && (system("make clean"));
                  system("make");
                  chdir("../");
                  chdir("rfpclust_para");
                  system("../fmkmf.pl -f90 $compiler -openmp 1 -opt $opt -mac $mac rfpclust.f90 > makefile");
                  ($clean == 1) && (system("make clean"));
                  system("make");
                  chdir("../");
                  chdir("make_rnd_classes");
                  system("../fmkmf.pl -f90 $compiler -openmp 0 -opt $opt -mac $mac make_rnd_classes.f90 > makefile");
                  ($clean == 1) && (system("make clean"));
                  system("make");
                  chdir("../");
                  chdir("make_rnd_eulers");
                  system("../fmkmf.pl -f90 $compiler -openmp 0 -opt $opt -mac $mac make_rnd_eulers.f90 > makefile");
                  ($clean == 1) && (system("make clean"));
                  system("make");
                  chdir("../");
                  chdir("rotmat2euler");
                  system("../fmkmf.pl -f90 $compiler -openmp 0 -opt $opt -mac $mac rotmat2euler.f90 > makefile");
                  ($clean == 1) && (system("make clean"));
                  system("make");
                  chdir("../");
                  chdir("stack_fouriers");
                  system("../fmkmf.pl -f90 $compiler -openmp 0 -opt $opt -mac $mac stack_fouriers.f90 > makefile");
                  ($clean == 1) && (system("make clean"));
                  system("make");
                  chdir("../");
                  chdir("stack_rfp_amps");
                  system("../fmkmf.pl -f90 $compiler -openmp 0 -opt $opt -mac $mac stack_rfp_amps.f90 > makefile");
                  ($clean == 1) && (system("make clean"));
                  system("make");
                  chdir("../");
                  chdir("stack_rfps");
                  system("../fmkmf.pl -f90 $compiler -openmp 0 -opt $opt -mac $mac stack_rfps.f90 > makefile");
                  ($clean == 1) && (system("make clean"));
                  system("make");
                  chdir("../");
              }else{
                  my$para_prog    = $prog."_para";
                  my$seq_prog     = $prog."_seq";
                  my$fortran_prog = $prog.".f90";

                  if($prog eq 'make_rnd_classes'){
                  $para_prog = $prog;
                  $seq_prog  = $prog;
                  }
                  if($prog eq 'rotmat2euler'){
                  $para_prog = $prog;
                  $seq_prog  = $prog;
                  }
                  if($prog eq 'stack_fouriers'){
                  $para_prog = $prog;
                  $seq_prog  = $prog;
                  }
                  if($prog eq 'stack_rfp_amps'){
                  $para_prog = $prog;
                  $seq_prog  = $prog;
                  }
                  if($prog eq 'stack_rfps'){
                  $para_prog = $prog;
                  $seq_prog  = $prog;
                  }

                  chdir("$seq_prog");
                  print "compiling $fortran_prog in folder $seq_prog\n";
                  system("../fmkmf.pl -f90 $compiler -openmp 0 -opt $opt -mac $mac $fortran_prog > makefile");
                  ($clean == 1) && (system("make clean"));
                  system("make");
                  chdir("../");
                  chdir("$para_prog");
                  print "compiling $fortran_prog in folder $para_prog\n";
                  system("../fmkmf.pl -f90 $compiler -openmp 1 -opt $opt -mac $mac $fortran_prog > makefile");
                  ($clean == 1) && (system("make clean"));
                  system("make");
                  chdir("../");
              }

              ####################################

              I'll send the entire package for diagnosis if you let me know an address to send it to.

               

              Thanks in advance,

               

                • openf95 INTERNAL ERROR
                  pjjr

                  Below is the code for the problematic class (calc_fplanes)

                   

                  ##########################################

                  !==Class calc_fplanes
                  !
                  ! calc_fplanes handles 2D Fourier transforms in Spider format. Functionality includes reading, writing
                  ! individual FT files to to stack and sinc interpolation of Fourier components at arbitrary grid positions.
                  ! The code is distributed with the hope that it will be useful, but _WITHOUT_ _ANY_ _WARRANTY_. Redistribution
                  ! or modification is regulated by the GNU General Public License. *Author:* Hans Elmlund, 2009-05-25.
                  !
                  !==Changes are documented below
                  !
                  !* changed interface of _read_fplane_file_
                  !* changed interface of _read_fplane_file_from_stack_
                  !* changed interface of _write_fplane_files_to_stack_
                  !* restructured, needs debugging, HE 2009-05-26
                  !* deugged and incorporated in the _SIMPLE_ library, HE 2009-06-25
                  !
                  module calc_fplanes
                  use calc_math
                  use calc_abstr_vec
                  use calc_cvec
                  implicit none

                  type fplanes
                  ! contains a 4-dim matrix for storing 2D Fourier transforms (FTs).
                  ! Dim 1 is ptcl index, dim 2 is 1 for amplitude and 2 for phase, dim 3 & 4 are
                  ! the two reciprocal dimensions (h,k). _N_fplanes_ is the number of transforms,
                  ! _xdim_ is the Fourier dimension (-_xdim_:_xdim_, -_xdim_:_xdim_), _ftsize_
                  ! holds the size of one FT, and _exists_ indicates existence of an instance (_num_)
                      private
                      real, allocatable :: cmat(:,:,:,
                      integer           :: N_fplanes=0, xdim=0, ftsize=0
                      logical           :: exists=.false.
                  end type fplanes

                  contains

                      function new_fplanes( xdim, numpart ) result( num )
                      ! The new_fplanes constructor allocates space for _numpart_ 2D Fourier transforms (FTs) of
                      ! dimension (-_xdim_:_xdim_,-_xdim_:_xdim_) and calculates the size (file record length) of one FT
                          integer, intent(in) :: xdim, numpart
                          type(fplanes)       :: num
                          integer             :: alloc_stat
                          allocate( num%cmat( numpart,2,-xdim:xdim,-xdim:xdim ), stat=alloc_stat )
                          if ( alloc_stat /= 0 ) then
                              write( *,* ) 'Aborting, memory allocation of cmat failed'
                              write( *,* ) 'In: new_fplanes, module: calc_fplanes.f95'
                              stop
                          end if
                          num%cmat = 0.
                          num%N_fplanes = numpart
                          num%xdim      = xdim
                          inquire( iolength=num%ftsize ) num%cmat(1,:,:,
                          num%exists = .true.
                      end function new_fplanes
                     
                      subroutine kill_fplanes( num )
                      ! is a destructor
                          type(fplanes), intent(inout) :: num 
                          if( num%exists )then
                              deallocate( num%cmat )
                              num%N_fplanes = 0
                              num%exists    = .false.
                          endif
                      end subroutine kill_fplanes
                    
                      subroutine read_fplane_file( num, filename, i )
                      ! reads a Spider Fourier transform file into position _i_ of _num_
                          type(fplanes), intent(inout) :: num
                          character(len=*), intent(in)  :: filename
                          integer, intent(in)           :: i
                          integer                       :: fildim     
                          fildim = 2*num%xdim+2
                          call readfourier( filename, num%xdim, fildim, num%cmat(i,1,:,, num%cmat(i,2,:, )
                      end subroutine read_fplane_file
                    
                      subroutine write_fplane_files_to_stack( filetable, xdim, norm, stack, stack_head )
                      ! makes a stack (unformatted direct access file) of
                      ! all Spider Fourier transforms listed in _filetable_. _stack_ is the data and _stack_head_
                      ! is the associated header. Remember that the file format is dependent on the CPU architecture.
                          character(len=*), intent(in) :: filetable(
                          integer, intent(in)          :: xdim, norm
                          character(len=*), intent(in) :: stack, stack_head
                          real, allocatable            :: cmat(:,:,
                          integer                      :: i, file_stat, ftsize, alloc_stat, fildim, nfiles
                          allocate(cmat(2,-xdim:xdim,-xdim:xdim),stat=alloc_stat)
                          if ( alloc_stat /= 0 ) then
                              write(*,*) 'Aborting, memory allocation of arrays failed'
                              write(*,*) 'In: write_fplane_files_to_stack, module: calc_fplanes.f95'
                              stop
                          end if
                          nfiles = size(filetable,1)
                          fildim = 2*xdim+2
                          inquire( iolength=ftsize ) cmat
                          open( unit=19, file=stack_head, status='replace',&
                          iostat=file_stat, action='write', form='formatted')
                          if (file_stat/=0) then ! cannot open file
                              write(*,*) 'Cannot open file: ', stack_head
                              write(*,*) 'In: write_fplane_files_to_stack, module: calc_fplanes.f95'
                              stop
                          endif
                          write( 19,'(A)' ) 'INFO ABOUT DIRECT ACCESS FILE:'
                          write( 19,'(A)' ) stack
                          write( 19,'(A,I7,A,I7)' ) '>>>contains ', nfiles, ' records of length ', ftsize
                          write( 19,'(A)' ) '>>>each record corresponds to the real matrix cmat(1:2,-xdim:xdim,-xdim:xdim)'
                          write( 19,'(A,I4,A)' ) '>>>with xdim  =', xdim, '  &  1:2  =  real:imaginary values'
                          write( 19,'(A)' ) 'FILES THAT WHERE USED TO BUILD THE STACK ARE LISTED BELOW:'           
                          open( unit=20, file=stack, status='replace', iostat=file_stat,&
                          access='direct', action='write', form='unformatted', recl=ftsize )
                          if (file_stat/=0) then ! cannot open file
                              write(*,*) 'Cannot open file: ', stack
                              write(*,*) 'In: write_fplane_files_to_stack, module: calc_fplanes.f95'
                              stop
                          endif
                          do i=1,nfiles
                              call readfourier(filetable(i), xdim, fildim, cmat(1,:,, cmat(2,:,)
                              if( norm == 1 ) then
                   !               call fplane_amp_norm( cmat, xdim )
                              else if( norm == 0 ) then
                                  ! do nothing
                              else
                                  write(*,*) 'norm variable must be either 0 or 1!'
                                  write(*,*) 'In: write_fplane_files_to_stack, module: calc_fplanes.f90'
                                  stop
                              endif      
                              write( 20, rec=i ) cmat(:,:,
                              write( 19,'(A)' ) filetable(i)
                          end do
                          close(20)
                          close(19)
                          deallocate(cmat)
                      end subroutine write_fplane_files_to_stack

                      subroutine read_fplane_file_from_stack( num, stackname, stackindex, cmatindex )
                      ! is for reading a single FT from stack into position _cmatindex_ of _num_.
                          type(fplanes), intent(inout) :: num
                          character(len=*), intent(in) :: stackname
                          integer, intent(in)          :: stackindex, cmatindex
                          integer                      :: file_stat
                          open( unit=20, file=stackname, status='old', iostat=file_stat,&
                          access='direct', action='read', form='unformatted', recl=num%ftsize )
                          if (file_stat/=0) then ! cannot open file
                              write(*,*) 'Cannot open file: ', stackname
                              write(*,*) 'In: read_fplane_file_from_stack, module: calc_fplanes.f95'
                              stop
                          endif
                          read( unit=20, rec=stackindex ) num%cmat(cmatindex,:,:,
                          close(20)
                      end subroutine read_fplane_file_from_stack

                      function get_N_fplanes( num ) result( N_fplanes )
                      ! is a getter
                          type(fplanes), intent(in) :: num
                          integer                   :: N_fplanes
                          N_fplanes = num%N_fplanes
                      end function get_N_fplanes

                      subroutine get_fcomp( num, i, h, k, amp, phase )
                      ! is for getting individual Fourier component out of _num_.
                      ! _h_ & _k_ are the reciprocal indices, and _amp_ & _pase_ is the ouptut comp.
                          type(fplanes), intent(in) :: num
                          integer, intent(in)       :: i, h, k
                          real, intent(out)         :: amp, phase
                          amp   = num%cmat(i,1,h,k)
                          phase = num%cmat(i,2,h,k) 
                      end subroutine get_fcomp

                      subroutine get_fplane_line( num, ptcl, winsize, from, to, line, lin_in, ang, x, y )
                      ! is for interpolating a complex vector along a line in the _ptcl_ FT.
                      ! _ang_ is the in-plane rotation angle, _x_ and _y_ is the origin shift vec, _winsize_ is the
                      ! window size used in sinc interpolation. _from_ and _to_ are the Fourier index limits. The components
                      ! are stored in the complex vector _line_, see calc_cvec for definition.
                          type(fplanes), intent(in)  :: num
                          integer, intent(in)        :: ptcl, winsize, from, to
                          type(cvec), intent(inout)  :: line
                          real, intent(in), optional :: lin_in(2), ang, x, y
                          real                       :: lin(2), amp, phase
                          integer                    :: k
                          if( present(ang) ) then
                              call get_radial_line(ang, lin)
                          else if( present(lin_in) ) then
                              lin = lin_in
                          else
                              write(*,*) 'ERROR, either lin or ang need to be specified!'
                              write(*,*) 'In: get_fplane_line, module: calc_fplanes.f90'
                          endif
                          do k=from,to
                              if( present(x) )then
                                  if( present(y) )then
                                      call interpolate_line_comp( num, ptcl, lin, winsize, k, amp, phase, x, y )
                                  endif
                              else
                                  call interpolate_line_comp( num, ptcl, lin, winsize, k, amp, phase )
                              endif
                              call set_cvec_comp( line, k, amp, phase )
                          end do
                      end subroutine get_fplane_line

                      subroutine get_fplane_line_comp( num, ptcl, ang, k, winsize, amp, phase, x, y )
                      ! is for interpolating a complex vector along a line in the _ptcl_ FT.
                      ! _ang_ is the in-plane rotation angle, _x_ and _y_ is the origin shift vec, _winsize_ is the
                      ! window size used in sinc interpolation. _from_ and _to_ are the Fourier index limits. The components
                      ! are stored in the complex vector _line_, see calc_cvec for definition.
                          type(fplanes), intent(in)  :: num
                          real, intent(in)           :: ang
                          integer, intent(in)        :: ptcl, k, winsize
                          real, intent(out)          :: amp, phase
                          real, intent(in), optional :: x, y
                          real                       :: lin(2)
                          call get_radial_line( ang, lin )
                          if( present(x) )then
                              if( present(y) )then
                                  call interpolate_line_comp( num, ptcl, lin, winsize, k, amp, phase, x, y )
                              endif
                          else
                              call interpolate_line_comp( num, ptcl, lin, winsize, k, amp, phase )
                          endif
                      end subroutine get_fplane_line_comp
                     
                      subroutine interpolate_line_comp( num, ptcl, lin, winsize, step, amp, phase, x, y )
                      ! is for interpolating Fourier components along a line _lin_ in FT ptcl.
                      ! _winsize_ is the window size used in sinc interpolation, _step_ is the resolution step along the line,
                      ! _x_ & _y_ is the origin shift vec, and _amp_ & _phase_ is the output comp
                          type(fplanes), intent(in)  :: num
                          real, intent(in)           :: lin(2)
                          integer, intent(in)        :: ptcl, winsize, step
                          real, intent(out)          :: amp, phase
                          real, intent(in), optional :: x, y
                          real                       :: xa, xb, rsh, imsh, r_temp, im_temp      
                          xa = real(step)*lin(1)
                          xb = real(step)*lin(2)
                          call calcsinc( num, ptcl, amp, phase, xa, xb, winsize )
                          if( present(x) )then
                              if( present(y) )then
                                  call origshift( num%xdim, xa, xb, x, y, rsh, imsh )
                                  r_temp  = amp
                                  im_temp = phase
                                  amp     = r_temp*rsh-im_temp*imsh
                                  phase   = r_temp*imsh+im_temp*rsh
                              endif
                          endif
                      end subroutine interpolate_line_comp
                      
                      subroutine calcsinc( num, ptcl, rout, imout, x, y, winsize )
                      ! calculates the sinc-weighted
                      ! value of the _ptcl_ fourier transform in point _x_,_y_
                          type(fplanes), intent(in) :: num
                          integer, intent(in)       :: ptcl, winsize
                          real, intent(out)         :: rout, imout
                          real, intent(in)          :: x, y
                          integer                   :: i, j, istart, istop, jstart, jstop
                          real                      :: tmp1, tmp2
                          rout  = 0.
                          imout = 0.
                          call window_2d( x, y, winsize, istart, istop, jstart, jstop )
                          do i=istart,istop
                              do j=jstart,jstop
                                  tmp1  = sinc(x-real(i))
                                  tmp2  = sinc(y-real(j))
                                  rout  = rout+num%cmat(ptcl,1,i,j)*tmp1*tmp2
                                  imout = imout+num%cmat(ptcl,2,i,j)*tmp1*tmp2
                              end do
                          end do
                      end subroutine calcsinc

                      subroutine readfourier( filnam, xdim, fildim, realpart, impart )
                      ! is for reading a Spider FT. The subroutine is coded according to the file format
                      ! description on the Spider web page: http://www.wadsworth.org/spider_doc/spider/docs/fourier.html
                          character(len=*), intent(in) :: filnam
                          integer, intent(in)          :: xdim, fildim
                          real, intent(inout), dimension( -xdim:xdim, -xdim:xdim ):: realpart, impart
                          integer, parameter :: filnum = 50
                          real, allocatable  :: vec(
                          real :: re, im
                          integer :: xp, nrow, nsam, labrec, j, i, ix, ind1, ind2, xdim2, ydim2, lenbyt ! nr
                          integer :: yj, xi, ier, failtoallocate, vecsize
                          ! from spider doc:
                          lenbyt = fildim*4
                          labrec = 1024/lenbyt
                          if ( mod(1024,lenbyt) /= 0 ) then
                              labrec=labrec+1
                          endif
                          ! allocate vec as fildim reals:
                          allocate( vec( 1:fildim ), stat=failtoallocate )
                          if ( failtoallocate /= 0 ) then
                              write(*,*) 'Failed to allocate arrays!'
                              write( *,* ) 'In: readfourier, module: calc_fplanes.f95'
                              stop
                          endif
                          ! open the fourier-file:
                          inquire( iolength=vecsize ) vec
                          open( unit = filnum, status = 'unknown', action = 'read', file = filnam,&
                          access = 'direct', form = 'unformatted', recl = vecsize, iostat = ier)
                          if (ier/=0) then ! cannot open file
                              write(*,*) 'Cannot open file: ', filnam
                              write(*,*) 'In: readfourier, module: calc_fplanes.f95'
                              stop
                          endif
                          nrow  = 2*xdim
                          nsam  = fildim
                          xdim2 = nsam
                          ydim2 = nrow     
                          xp    = xdim2/2
                          do j=1,ydim2
                              ix = j+labrec
                              read( filnum, rec=ix ) vec(
                              do i=1,xp
                                  ind1 = 2*i
                                  ind2 = 2*i-1
                                  re   = vec(ind2)
                                  im   = vec(ind1)
                                  if ( j > 1+ydim2/2 ) then
                                      yj = j-1-ydim2
                                  else
                                      yj= j-1
                                  endif
                                  xi = i-1
                                  realpart(xi,yj) = re
                                  impart(xi,yj)   = im
                                  ! expand according to friedels law:
                                  if (xi > 0) then
                                      xi = -xi
                                      yj = -yj
                                      realpart(xi,yj) = re
                                      impart(xi,yj)   = -im
                                  endif
                              end do
                          end do
                          close(unit=filnum)
                          deallocate( vec, stat=failtoallocate)
                      end subroutine readfourier
                     
                      subroutine write_rfp_amps_to_disk( filetable, amp_stack, hed, xdim, dstep, lowpass, norm )
                          character(len=*), intent(in) :: filetable(, amp_stack, hed
                          integer, intent(in)          :: xdim
                          real, intent(in)             :: dstep, lowpass
                          logical, intent(in)          :: norm
                          real(double), allocatable    :: rfp_amp(:,
                          type(cvec)                   :: vec
                          type(fplanes)                :: f   
                          integer                      :: rfp_recsz, file_stat, alloc_stat, i, j, nfiles, to       
                          to = int(dstep/lowpass)
                          write(*,'(A)') '>>> STACKING ROTATIONAL FOOTPRINT AMPLITUDES'
                          allocate( rfp_amp(0:179,2:to), stat=alloc_stat )
                          if( alloc_stat /= 0 )then
                              write(*,*) 'Aborting, memory allocation failed'
                              write(*,*) 'In: write_amps_to_disk, module: calc_fplanes.f90'
                              stop
                          end if
                          ! Build Fourier planes object
                          f = new_fplanes(xdim, 1)
                          ! build complex vector
                          vec = new_cvec(2,to)
                          ! check nr of files
                          nfiles = size(filetable,1)
                          ! Check rec-lengths and open files
                          inquire(iolength=rfp_recsz) rfp_amp
                          open(unit=12, file=amp_stack, status='replace', iostat=file_stat,&
                          access='direct', action='write', form='unformatted', recl=rfp_recsz )
                          if( file_stat /= 0 )then ! cannot open file
                              write(*,*) 'Cannot open file: ', amp_stack
                              write(*,*) 'In: write_rfp_amps_to_disk, module: calc_fplanes.f90'
                              stop
                          endif
                          do i=1,nfiles
                              write(*,*) 'Stacking rfp nr: ', i
                              ! read file into fplanes object
                              call read_fplane_file(f, filetable(i), 1)
                              ! make the rotational footprint
                              do j=0,179
                                  ! interpolate the line
                                  call get_fplane_line(f, 1, 1, 2, to, vec, ang=real(j))
                                  rfp_amp(j, = get_real_part(vec)
                              end do
                              if( norm ) call normalize(0, 179, 2, to, rfp_amp)
                              ! write it to the stack file
                              write(12, rec=i) rfp_amp
                          end do
                          close(12)
                          ! make a header with constants info
                          open(unit=14, file=hed, status='replace', iostat=file_stat,&
                          action='write', form='formatted' )
                          if( file_stat /= 0 )then ! cannot open file
                              write(*,*) 'Cannot open file: ', hed
                              write(*,*) 'In: write_rfp_amps_to_disk, module: calc_fplanes.f90'
                              stop
                          endif
                          write(14,*) nfiles, to
                          close(14)
                          deallocate(rfp_amp)
                          call kill_fplanes(f)
                          call kill_cvec(vec)
                      end subroutine write_rfp_amps_to_disk
                     
                      subroutine write_rfps_to_disk( filetable, stack, hed, xdim, dstep, lowpass, norm )
                          character(len=*), intent(in) :: filetable(, stack, hed
                          integer, intent(in)          :: xdim
                          real, intent(in)             :: dstep, lowpass
                          logical, intent(in)          :: norm
                          real(double), allocatable    :: rfp(:,:,
                          type(cvec)                   :: vec
                          type(fplanes)                :: f   
                          integer                      :: rfp_recsz, file_stat, alloc_stat, i, j, nfiles, to       
                          to = int(dstep/lowpass)
                          write(*,'(A)') '>>> STACKING COMPLEX ROTATIONAL FOOTPRINTS'
                          allocate( rfp(2,0:359,2:to), stat=alloc_stat )
                          if( alloc_stat /= 0 )then
                              write(*,*) 'Aborting, memory allocation failed'
                              write(*,*) 'In: write_rfps_to_disk, module: calc_fplanes.f90'
                              stop
                          end if
                          ! Build Fourier planes object
                          f = new_fplanes(xdim, 1)
                          ! build complex vector
                          vec = new_cvec(2,to)
                          ! check nr of files
                          nfiles = size(filetable,1)
                          ! Check rec-lengths and open files
                          inquire(iolength=rfp_recsz) rfp
                          open(unit=12, file=stack, status='replace', iostat=file_stat,&
                          access='direct', action='write', form='unformatted', recl=rfp_recsz )
                          if( file_stat /= 0 )then ! cannot open file
                              write(*,*) 'Cannot open file: ', stack
                              write(*,*) 'In: write_rfps_to_disk, module: calc_fplanes.f90'
                              stop
                          endif
                          do i=1,nfiles
                              write(*,*) 'Stacking rfp nr: ', i
                              ! read file into fplanes object
                              call read_fplane_file(f, filetable(i), 1)
                              ! make the rotational footprint
                              do j=0,359
                                  ! interpolate the line
                                  call get_fplane_line(f, 1, 1, 2, to, vec, ang=real(j))
                                  rfp(1,j, = get_real_part(vec)
                                  rfp(2,j, = get_complex_part(vec)
                              end do
                              if( norm ) call normalize(0, 359, 2, to, rfp(1,:,)
                              ! write it to the stack file
                              write(12, rec=i) rfp
                          end do
                          close(12)
                          ! make a header with constants info
                          open(unit=14, file=hed, status='replace', iostat=file_stat,&
                          action='write', form='formatted' )
                          if( file_stat /= 0 )then ! cannot open file
                              write(*,*) 'Cannot open file: ', hed
                              write(*,*) 'In: write_rfps_to_disk, module: calc_fplanes.f90'
                              stop
                          endif
                          write(14,*) nfiles, to
                          close(14)
                          deallocate(rfp)
                          call kill_fplanes(f)
                          call kill_cvec(vec)
                      end subroutine write_rfps_to_disk
                     
                      subroutine read_rfp_amps_from_disk( n, records, amp_stack, hed, dstep, lowpass, rfp_amps  )
                          integer, intent(in)          :: n
                          integer, intent(in)          :: records(n) ! file records to read
                          character(len=*), intent(in) :: amp_stack, hed
                          real, intent(in)             :: dstep, lowpass
                          real(double)                 :: rfp_amps(n,0:179,2:int(dstep/lowpass))
                          real(double), allocatable    :: rfp_amp(:,
                          integer                      :: rfp_recsz, i
                          integer                      :: file_stat, nfiles, alloc_stat, to_here, to
                          to = int(dstep/lowpass)
                          ! begin with reading the header
                          open(unit=14, file=hed, status='old', iostat=file_stat,&
                          action='read', form='formatted')
                          if( file_stat /= 0 )then ! cannot open file
                              write(*,*) 'Cannot open file: ', hed
                              write(*,*) 'In: read_rfp_amps_from_disk, module: calc_fplanes.f90'
                              stop
                          endif
                          read(14,*) nfiles, to_here
                          close(14)
                          if( to /= to_here ) then
                              write(*,*) 'Aborting, wrong array dimension (conflicting lowpass Fourier index)!'
                              write(*,*) 'In: read_rfp_amps_from_disk, module: calc_fplanes.f90'
                              stop
                          endif
                          allocate( rfp_amp(0:179,2:to), stat=alloc_stat )
                          if( alloc_stat /= 0 )then
                              write(*,*) 'Aborting, memory allocation failed'
                              write(*,*) 'In: read_rfp_amps_from_disk, module: calc_fplanes.f90'
                              stop
                          end if
                          ! Check rec-lengths and open files
                          inquire(iolength=rfp_recsz) rfp_amp
                          open(unit=12, file=amp_stack, status='old', iostat=file_stat,&
                          access='direct', action='read', form='unformatted', recl=rfp_recsz )
                          if( file_stat /= 0 )then ! cannot open file
                              write(*,*) 'Cannot open file: ', amp_stack
                              write(*,*) 'In: read_rfp_amps_from_disk, module: calc_fplanes.f90'
                              stop
                          endif
                          do i=1,n
                              read(12, rec=records(i)) rfp_amps(i,:,
                          end do
                          close(12)
                          close(14)
                          deallocate(rfp_amp)
                      end subroutine read_rfp_amps_from_disk
                     
                      subroutine read_rfps_from_disk( n, records, stack, hed, dstep, lowpass, rfps  )
                          integer, intent(in)          :: n
                          integer, intent(in)          :: records(n) ! file records to read
                          character(len=*), intent(in) :: stack, hed
                          real, intent(in)             :: dstep, lowpass
                          real(double)                 :: rfps(n,2,0:359,2:int(dstep/lowpass))
                          real(double), allocatable    :: rfp(:,:,
                          integer                      :: rfp_recsz, i
                          integer                      :: file_stat, nfiles, alloc_stat, to_here, to
                          to = int(dstep/lowpass)
                          ! begin with reading the header
                          open(unit=14, file=hed, status='old', iostat=file_stat,&
                          action='read', form='formatted')
                          if( file_stat /= 0 )then ! cannot open file
                              write(*,*) 'Cannot open file: ', hed
                              write(*,*) 'In: read_rfps_from_disk, module: calc_fplanes.f90'
                              stop
                          endif
                          read(14,*) nfiles, to_here
                          close(14)
                          if( to /= to_here ) then
                              write(*,*) 'Aborting, wrong array dimension (conflicting lowpass Fourier index)!'
                              write(*,*) 'In: read_rfps_from_disk, module: calc_fplanes.f90'
                              stop
                          endif
                          allocate( rfp(2,0:359,2:to), stat=alloc_stat )
                          if( alloc_stat /= 0 )then
                              write(*,*) 'Aborting, memory allocation failed'
                              write(*,*) 'In: read_rfps_from_disk, module: calc_fplanes.f90'
                              stop
                          end if
                          ! Check rec-lengths and open files
                          inquire(iolength=rfp_recsz) rfp
                          open(unit=12, file=stack, status='old', iostat=file_stat,&
                          access='direct', action='read', form='unformatted', recl=rfp_recsz )
                          if( file_stat /= 0 )then ! cannot open file
                              write(*,*) 'Cannot open file: ', stack
                              write(*,*) 'In: read_rfps_from_disk, module: calc_fplanes.f90'
                              stop
                          endif
                          do i=1,n
                              read(12, rec=records(i)) rfps(i,:,:,
                          end do
                          close(12)
                          close(14)
                          deallocate(rfp)
                      end subroutine read_rfps_from_disk
                     
                  end module calc_fplanes

                    • openf95 INTERNAL ERROR
                      pjjr

                       real(double), allocatable    :: rfp_amp(:,
                              type(cvec)                   :: vec
                              type(fplanes)                :: f   
                              integer                      :: rfp_recsz, file_stat, alloc_stat, i, j, nfiles, to       
                              to = int(dstep/lowpass)
                              write(*,'(A)') '>>> STACKING ROTATIONAL FOOTPRINT AMPLITUDES'
                              allocate( rfp_amp(0:179,2:to), stat=alloc_stat )
                              if( alloc_stat /= 0 )then
                                  write(*,*) 'Aborting, memory allocation failed'
                                  write(*,*) 'In: write_amps_to_disk, module: calc_fplanes.f90'
                                  stop
                              end if
                              ! Build Fourier planes object
                              f = new_fplanes(xdim, 1)
                              ! build complex vector
                              vec = new_cvec(2,to)
                              ! check nr of files
                              nfiles = size(filetable,1)
                              ! Check rec-lengths and open files
                              inquire(iolength=rfp_recsz) rfp_amp
                              open(unit=12, file=amp_stack, status='replace', iostat=file_stat,&
                              access='direct', action='write', form='unformatted', recl=rfp_recsz )
                              if( file_stat /= 0 )then ! cannot open file
                                  write(*,*) 'Cannot open file: ', amp_stack
                                  write(*,*) 'In: write_rfp_amps_to_disk, module: calc_fplanes.f90'
                                  stop
                              endif
                              do i=1,nfiles
                                  write(*,*) 'Stacking rfp nr: ', i
                                  ! read file into fplanes object
                                  call read_fplane_file(f, filetable(i), 1)
                                  ! make the rotational footprint
                                  do j=0,179
                                      ! interpolate the line
                                      call get_fplane_line(f, 1, 1, 2, to, vec, ang=real(j))
                                      rfp_amp(j, = get_real_part(vec)
                                  end do
                                  if( norm ) call normalize(0, 179, 2, to, rfp_amp)
                                  ! write it to the stack file
                                  write(12, rec=i) rfp_amp
                              end do
                              close(12)
                              ! make a header with constants info
                              open(unit=14, file=hed, status='replace', iostat=file_stat,&
                              action='write', form='formatted' )
                              if( file_stat /= 0 )then ! cannot open file
                                  write(*,*) 'Cannot open file: ', hed
                                  write(*,*) 'In: write_rfp_amps_to_disk, module: calc_fplanes.f90'
                                  stop
                              endif
                              write(14,*) nfiles, to
                              close(14)
                              deallocate(rfp_amp)
                              call kill_fplanes(f)
                              call kill_cvec(vec)
                          end subroutine write_rfp_amps_to_disk
                         
                          subroutine write_rfps_to_disk( filetable, stack, hed, xdim, dstep, lowpass, norm )
                              character(len=*), intent(in) :: filetable(, stack, hed
                              integer, intent(in)          :: xdim
                              real, intent(in)             :: dstep, lowpass
                              logical, intent(in)          :: norm
                              real(double), allocatable    :: rfp(:,:,
                              type(cvec)                   :: vec
                              type(fplanes)                :: f   
                              integer                      :: rfp_recsz, file_stat, alloc_stat, i, j, nfiles, to       
                              to = int(dstep/lowpass)
                              write(*,'(A)') '>>> STACKING COMPLEX ROTATIONAL FOOTPRINTS'
                              allocate( rfp(2,0:359,2:to), stat=alloc_stat )
                              if( alloc_stat /= 0 )then
                                  write(*,*) 'Aborting, memory allocation failed'
                                  write(*,*) 'In: write_rfps_to_disk, module: calc_fplanes.f90'
                                  stop
                              end if
                              ! Build Fourier planes object
                              f = new_fplanes(xdim, 1)
                              ! build complex vector
                              vec = new_cvec(2,to)
                              ! check nr of files
                              nfiles = size(filetable,1)
                              ! Check rec-lengths and open files
                              inquire(iolength=rfp_recsz) rfp
                              open(unit=12, file=stack, status='replace', iostat=file_stat,&
                              access='direct', action='write', form='unformatted', recl=rfp_recsz )
                              if( file_stat /= 0 )then ! cannot open file
                                  write(*,*) 'Cannot open file: ', stack
                                  write(*,*) 'In: write_rfps_to_disk, module: calc_fplanes.f90'
                                  stop
                              endif
                              do i=1,nfiles
                                  write(*,*) 'Stacking rfp nr: ', i
                                  ! read file into fplanes object
                                  call read_fplane_file(f, filetable(i), 1)
                                  ! make the rotational footprint
                                  do j=0,359
                                      ! interpolate the line
                                      call get_fplane_line(f, 1, 1, 2, to, vec, ang=real(j))
                                      rfp(1,j, = get_real_part(vec)
                                      rfp(2,j, = get_complex_part(vec)
                                  end do
                                  if( norm ) call normalize(0, 359, 2, to, rfp(1,:,)
                                  ! write it to the stack file
                                  write(12, rec=i) rfp
                              end do
                              close(12)
                              ! make a header with constants info
                              open(unit=14, file=hed, status='replace', iostat=file_stat,&
                              action='write', form='formatted' )
                              if( file_stat /= 0 )then ! cannot open file
                                  write(*,*) 'Cannot open file: ', hed
                                  write(*,*) 'In: write_rfps_to_disk, module: calc_fplanes.f90'
                                  stop
                              endif
                              write(14,*) nfiles, to
                              close(14)
                              deallocate(rfp)
                              call kill_fplanes(f)
                              call kill_cvec(vec)
                          end subroutine write_rfps_to_disk
                         
                          subroutine read_rfp_amps_from_disk( n, records, amp_stack, hed, dstep, lowpass, rfp_amps  )
                              integer, intent(in)          :: n
                              integer, intent(in)          :: records(n) ! file records to read
                              character(len=*), intent(in) :: amp_stack, hed
                              real, intent(in)             :: dstep, lowpass
                              real(double)                 :: rfp_amps(n,0:179,2:int(dstep/lowpass))
                              real(double), allocatable    :: rfp_amp(:,
                              integer                      :: rfp_recsz, i
                              integer                      :: file_stat, nfiles, alloc_stat, to_here, to
                              to = int(dstep/lowpass)
                              ! begin with reading the header
                              open(unit=14, file=hed, status='old', iostat=file_stat,&
                              action='read', form='formatted')
                              if( file_stat /= 0 )then ! cannot open file
                                  write(*,*) 'Cannot open file: ', hed
                                  write(*,*) 'In: read_rfp_amps_from_disk, module: calc_fplanes.f90'
                                  stop
                              endif
                              read(14,*) nfiles, to_here
                              close(14)
                              if( to /= to_here ) then
                                  write(*,*) 'Aborting, wrong array dimension (conflicting lowpass Fourier index)!'
                                  write(*,*) 'In: read_rfp_amps_from_disk, module: calc_fplanes.f90'
                                  stop
                              endif
                              allocate( rfp_amp(0:179,2:to), stat=alloc_stat )
                              if( alloc_stat /= 0 )then
                                  write(*,*) 'Aborting, memory allocation failed'
                                  write(*,*) 'In: read_rfp_amps_from_disk, module: calc_fplanes.f90'
                                  stop
                              end if
                              ! Check rec-lengths and open files
                              inquire(iolength=rfp_recsz) rfp_amp
                              open(unit=12, file=amp_stack, status='old', iostat=file_stat,&
                              access='direct', action='read', form='unformatted', recl=rfp_recsz )
                              if( file_stat /= 0 )then ! cannot open file
                                  write(*,*) 'Cannot open file: ', amp_stack
                                  write(*,*) 'In: read_rfp_amps_from_disk, module: calc_fplanes.f90'
                                  stop
                              endif
                              do i=1,n
                                  read(12, rec=records(i)) rfp_amps(i,:,
                              end do
                              close(12)
                              close(14)
                              deallocate(rfp_amp)
                          end subroutine read_rfp_amps_from_disk
                         
                          subroutine read_rfps_from_disk( n, records, stack, hed, dstep, lowpass, rfps  )
                              integer, intent(in)          :: n
                              integer, intent(in)          :: records(n) ! file records to read
                              character(len=*), intent(in) :: stack, hed
                              real, intent(in)             :: dstep, lowpass
                              real(double)                 :: rfps(n,2,0:359,2:int(dstep/lowpass))
                              real(double), allocatable    :: rfp(:,:,
                              integer                      :: rfp_recsz, i
                              integer                      :: file_stat, nfiles, alloc_stat, to_here, to
                              to = int(dstep/lowpass)
                              ! begin with reading the header
                              open(unit=14, file=hed, status='old', iostat=file_stat,&
                              action='read', form='formatted')
                              if( file_stat /= 0 )then ! cannot open file
                                  write(*,*) 'Cannot open file: ', hed
                                  write(*,*) 'In: read_rfps_from_disk, module: calc_fplanes.f90'
                                  stop
                              endif
                              read(14,*) nfiles, to_here
                              close(14)
                              if( to /= to_here ) then
                                  write(*,*) 'Aborting, wrong array dimension (conflicting lowpass Fourier index)!'
                                  write(*,*) 'In: read_rfps_from_disk, module: calc_fplanes.f90'
                                  stop
                              endif
                              allocate( rfp(2,0:359,2:to), stat=alloc_stat )
                              if( alloc_stat /= 0 )then
                                  write(*,*) 'Aborting, memory allocation failed'
                                  write(*,*) 'In: read_rfps_from_disk, module: calc_fplanes.f90'
                                  stop
                              end if
                              ! Check rec-lengths and open files
                              inquire(iolength=rfp_recsz) rfp
                              open(unit=12, file=stack, status='old', iostat=file_stat,&
                              access='direct', action='read', form='unformatted', recl=rfp_recsz )
                              if( file_stat /= 0 )then ! cannot open file
                                  write(*,*) 'Cannot open file: ', stack
                                  write(*,*) 'In: read_rfps_from_disk, module: calc_fplanes.f90'
                                  stop
                              endif
                              do i=1,n
                                  read(12, rec=records(i)) rfps(i,:,:,
                              end do
                              close(12)
                              close(14)
                              deallocate(rfp)
                          end subroutine read_rfps_from_disk
                         
                      end module calc_fplanes