!
!     CalculiX - A 3-dimensional finite element program
!              Copyright (C) 1998-2005 Guido Dhondt
!
!     This program is free software; you can redistribute it and/or
!     modify it under the terms of the GNU General Public License as
!     published by the Free Software Foundation(version 2);
!     
!
!     This program is distributed in the hope that it will be useful,
!     but WITHOUT ANY WARRANTY; without even the implied warranty of 
!     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
!     GNU General Public License for more details.
!
!     You should have received a copy of the GNU General Public License
!     along with this program; if not, write to the Free Software
!     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
!
      subroutine calinput(co,nk,kon,ipkon,lakon,nkon,
     &  ne,nodeboun,ndirboun,xboun,nboun,
     &  ipompc,nodempc,coefmpc,nmpc,nmpc_,nodeforc,ndirforc,xforc,nforc,
     &  nforc_,nelemload,sideload,xload,nload,nload_,
     &  nprint,prlab,prset,mpcfree,nboun_,
     &  mei,set,istartset,iendset,ialset,nset,nalset,elcon,nelcon,rhcon,
     &  nrhcon,alcon,nalcon,alzero,t0,t1,
     &  matname,ielmat,orname,orab,ielorien,amname,amta,namta,nam,
     &  nmethod,iamforc,iamload,iamt1,
     &  ithermal,iperturb,istat,istep,nmat,ntmat_,norien,
     &  prestr,iprestr,isolver,fei,veold,tinc,tper,
     &  xmodal,filab,jout,nlabel,idrct,jmax,
     &  tmin,tmax,iexpl,alpha,haftol,iamboun,plicon,nplicon,plkcon,
     &  nplkcon,iplas,npmat_,mint_,nk_,trab,inotr,ntrans,ikboun,
     &  ilboun,ikmpc,ilmpc,ics,dcs,ncs_,namtot_,cs,nstate_,ncmat_,iumat,
     &  mcs,labmpc,iponor,xnor,knor,thickn,thicke,ikforc,ilforc,
     &  offset,iponoel,inoel,rig,infree,nshcon,shcon,cocon,ncocon,
     &  physcon,nflow,ctrl,memmpc_,
     &  maxlenmpc,ne1d,
     &  ne2d,nener,vold,nodebounold,ndirbounold,xbounold,
     &  xforcold,xloadold,t1old,eme,sti,ener,xstate,jobnamec,
     &  nnn,irstrt,ttime,qaold,output,typeboun,inpc,
     &  nline,ipoinp,inp,tieset,tietol,ntie,fmpc,cbody,ibody,xbody,
     &  nbody,nbody_,xbodyold,nam_,ielprop,nprop,nprop_,prop)
!
      implicit none
!
!     nmethod: 0:no analysis; 1:static; 2:frequency; 3:buckling;
!              4:linear dynamic
!     ithermal: 0:no thermal stresses; 1:thermal stresses;
!     iprestr: 0: no residual stresses; 1: residual stresses;
!     iperturb: 0:no perturbation; 1:perturbation; 2: nonlinear
!               geometric analysis; 3: material and geometrical
!               nonlinearities
!     istep: step number
!     istat: error indicator (<0:EOF, >0: input error)
!
      logical boun_flag,cload_flag,dload_flag,temp_flag,elprint_flag,
     &  nodeprint_flag,elfile_flag,nodefile_flag,node_flag,
     &  dflux_flag,cflux_flag,film_flag,radiate_flag,out3d,axial
!
      character*1 typeboun(*)
      character*3 output
      character*6 filab(*)
      character*6 prlab(*)
      character*8 lakon(*)
      character*20 labmpc(*),sideload(*)
      character*80 matname(*),orname(*),amname(*)
      character*81 set(*),prset(*),tieset(3,*),cbody(*)
      character*132 jobnamec,inpc(*),textpart(16)
!
      integer kon(*),nodeboun(*),ndirboun(*),ipompc(*),nodempc(3,*),
     &  nodeforc(2,*),ndirforc(*),nelemload(2,*),
     &  istartset(*),iendset(*),ialset(*),ipkon(*),ics(*),
     &  nelcon(2,*),nrhcon(*),nalcon(2,*),ielmat(*),ielorien(*),
     &  namta(3,*),iamforc(*),iamload(2,*),iamt1(*),
     &  iamboun(*),inotr(2,*),ikboun(*),ilboun(*),ikmpc(*),ilmpc(*),
     &  iponor(2,*),knor(*),ikforc(*),ilforc(*),iponoel(*),inoel(3,*),
     &  infree(4),ixfree,ikfree,inoelfree,iponoelmax,rig(*),nshcon(*),
     &  ncocon(2,*),nodebounold(*),ielprop(*),nprop,nprop_,
     &  ndirbounold(*),nnn(*),nline,ipoinp(2,*),inp(3,*),j,nentries
!
      integer nalset,nalset_,nmat,nmat_,ntmat_,norien,norien_,
     &  nmethod,nk,ne,nboun,nmpc,nmpc_,mpcfree,i,istat,n,
     &  key,nk_,ne_,nboun_,ncs_,namtot_,nstate_,
     &  isolver,ithermal,iperturb,iprestr,istep,mei(4),nkon,
     &  nprint,nload,nload_,nforc,nforc_,nlabel,iumat,
     &  nset,nset_,nprint_,nam,nam_,jout,ncmat_,
     &  ierror,idrct,jmax,iexpl,iplas,npmat_,mint_,ntrans,ntrans_,
     &  M_or_SPC,nplicon(0:ntmat_,*),nplkcon(0:ntmat_,*),nflow,
     &  memmpc_,ne1d,ne2d,nener,irstrt,ii,maxlenmpc,inl,ipol,
     &  iline,mcs,ntie,ntie_,lprev,newstep,nbody,nbody_,ibody(2,*)
!
      real*8 co(3,*),xboun(*),coefmpc(*),xforc(*),fmpc(*),
     &  xload(2,*),alzero(*),offset(2,*),prop(*),
     &  elcon(0:ncmat_,ntmat_,*),rhcon(0:1,ntmat_,*),
     &  alcon(0:6,ntmat_,*),thicke(2,*),thickn(2,*),xnor(*),
     &  t1(*),orab(7,*),prestr(6,mint_,*),amta(2,*),
     &  veold(0:3,*),t0(*),plicon(0:2*npmat_,ntmat_,*),
     &  plkcon(0:2*npmat_,ntmat_,*),trab(7,*),dcs(*),
     &  shcon(0:1,ntmat_,*),cocon(0:6,ntmat_,*),
     &  ctrl(26),vold(0:3,*),xbounold(*),xforcold(*),
     &  xloadold(*),t1old(*),eme(*),sti(*),ener(*),
     &  xstate(*),ttime,qaold,cs(17,*),tietol(*),
     &  xbody(7,*),xbodyold(7,*)
!
      real*8 fei(3),tinc,tper,xmodal(6),tmin,tmax,
     &  alpha,haftol,physcon(3)
!
      save axial
!
      nentries=12
      newstep=0
!
      do i=1,nentries
         if(ipoinp(1,i).ne.0) then
            ipol=i
            inl=ipoinp(1,i)
            iline=inp(1,inl)-1
            exit
         endif
      enddo
!
      ixfree=infree(1)
      ikfree=infree(2)
      inoelfree=infree(3)
      iponoelmax=infree(4)
!
      iexpl=0
!
!     the following flag is used to check whether any SPC's or MPC's
!     are used before transformation definitions
!
      M_or_SPC=0
!
!     the flags indicate whether some specific keyword cards already
!     occurred (needed to determine the effect of OP=NEW or to check
!     whether the element or nodal output selection should be reset)
!
      boun_flag=.false.
      cload_flag=.false.
      dload_flag=.false.
      temp_flag=.false.
      elprint_flag=.false.
      nodeprint_flag=.false.
      elfile_flag=.false.
      nodefile_flag=.false.
      film_flag=.false.
      dflux_flag=.false.
      radiate_flag=.false.
      cflux_flag=.false.
!
      nprint_=nprint
!
      nprint=0
!
      if(istep.eq.0) then
!
!        initializing the maxima
!
         ne_=ne
         nset_=nset
         nalset_=nalset
         nmat_=nmat
         norien_=norien
         ntrans_=ntrans
         ntie_=ntie
!
         nmethod=0
!
         ne=0
         nset=0
         nalset=0
         nmat=0
         norien=0
         ntrans=0
         ntie=0
!
         lprev=0
!
         do i=1,ne_
            ipkon(i)=-1
         enddo
!
         if((ne1d.gt.0).or.(ne2d.gt.0)) then
            do i=1,nlabel
               filab(i)='    I '
            enddo
            out3d=.false.
         else
            do i=1,nlabel
               filab(i)='      '
            enddo
            out3d=.true.
         endif
!
         axial=.false.
!
      endif
!
      call getnewline(inpc,textpart,istat,n,key,iline,ipol,inl,
     &    ipoinp,inp)
!
      loop: do
!
         if(istat.lt.0) then
               call frdclose()
               write(*,*)
               write(*,*) 'Job finished'
               stop
         endif
!
         if(textpart(1)(1:10).eq.'*AMPLITUDE') then
            call amplitudes(inpc,textpart,amname,amta,namta,nam,
     &        nam_,namtot_,irstrt,istep,istat,n,iline,ipol,inl,ipoinp,
     &        inp)
!
         elseif(textpart(1)(1:12).eq.'*BEAMSECTION') then
            call beamsections(inpc,textpart,set,istartset,iendset,
     &           ialset,nset,ielmat,matname,nmat,ielorien,orname,norien,
     &           thicke,kon,ipkon,nk,nk_,iponor,xnor,ixfree,
     &           offset,lakon,irstrt,istep,istat,n,iline,ipol,inl,
     &           ipoinp,inp)
!
         elseif(textpart(1)(1:9).eq.'*BOUNDARY') then
            M_or_SPC=1
            call boundaries(inpc,textpart,set,istartset,iendset,
     &        ialset,nset,nodeboun,ndirboun,xboun,nboun,nboun_,nk,
     &        iamboun,amname,nam,ipompc,nodempc,coefmpc,nmpc,nmpc_,
     &        mpcfree,inotr,trab,ntrans,ikboun,ilboun,ikmpc,ilmpc,
     &        nk_,co,labmpc,boun_flag,typeboun,istep,istat,n,iline,
     &        ipol,inl,ipoinp,inp,nam_,namtot_,namta,amta,nmethod,
     &        iperturb,axial)
            boun_flag=.true.
!
         elseif(textpart(1)(1:7).eq.'*BUCKLE') then
            call buckles(inpc,textpart,nmethod,mei,fei,
     &        nforc,nload,ithermal,iprestr,nbody,t0,t1,nk,iperturb,
     &        istep,istat,n,iline,ipol,inl,ipoinp,inp,isolver)
!
         elseif(textpart(1)(1:6).eq.'*CFLUX') then
            call cfluxes(inpc,textpart,set,istartset,iendset,
     &        ialset,nset,nodeforc,ndirforc,xforc,nforc,nforc_,iamforc,
     &        amname,nam,ntrans,trab,inotr,co,ikforc,ilforc,nk,
     &        cflux_flag,istep,istat,n,iline,ipol,inl,ipoinp,inp,nam_,
     &        namtot_,namta,amta,axial)
            cflux_flag=.true.

         elseif(textpart(1)(1:6).eq.'*CLOAD') then
            call cloads(inpc,textpart,set,istartset,iendset,
     &        ialset,nset,nodeforc,ndirforc,xforc,nforc,nforc_,
     &        iamforc,amname,nam,ntrans,trab,inotr,co,ikforc,ilforc,
     &        nk,cload_flag,istep,istat,n,iline,ipol,inl,ipoinp,inp,
     &        nam_,namtot_,namta,amta,nmethod,axial,iperturb)
            cload_flag=.true.
!
         elseif(textpart(1)(1:13).eq.'*CONDUCTIVITY') then
            call conductivities(inpc,textpart,cocon,ncocon,
     &           nmat,ntmat_,irstrt,istep,istat,n,iline,ipol,inl,
     &           ipoinp,inp)
!
         elseif(textpart(1)(1:9).eq.'*CONTROLS') then
            call controlss(inpc,textpart,ctrl,istep,istat,n,iline,
     &           ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:32).eq.'*COUPLEDTEMPERATURE-DISPLACEMENT')
     &           then
            call couptempdisps(inpc,textpart,nmethod,iperturb,isolver,
     &           istep,istat,n,tinc,tper,tmin,tmax,idrct,ithermal,iline,
     &           ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:6).eq.'*CREEP') then
            call creeps(inpc,textpart,nelcon,nmat,ntmat_,npmat_,
     &        plicon,nplicon,elcon,iplas,iperturb,nstate_,ncmat_,
     &        matname,irstrt,istep,istat,n,iline,ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:16).eq.'*CYCLICHARDENING') then
            call cychards(inpc,textpart,nelcon,nmat,ntmat_,
     &        npmat_,plicon,nplicon,ncmat_,elcon,matname,
     &        irstrt,istep,istat,n,iline,ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:20).eq.'*CYCLICSYMMETRYMODEL') then
            call cycsymmods(inpc,textpart,set,istartset,iendset,
     &        ialset,nset,tieset,tietol,co,nk,ipompc,nodempc,
     &        coefmpc,nmpc,nmpc_,ikmpc,ilmpc,mpcfree,dcs(lprev+1),
     &        dcs(ncs_+lprev+1),ics(lprev+1),ics(ncs_+lprev+1),
     &        ics(2*ncs_+lprev+1),dcs(2*ncs_+lprev+1),
     &        dcs(3*ncs_+lprev+1),ncs_,cs,labmpc,istep,istat,n,iline,
     &        ipol,inl,ipoinp,inp,ntie,mcs,lprev,ithermal,
     &        dcs(4*ncs_),dcs(6*ncs_),dcs(8*ncs_),dcs(10*ncs_),
     &        ics(3*ncs_),ics(5*ncs_),ics(7*ncs_),ics(8*ncs_),
     &        dcs(12*ncs_),ne,ipkon,kon,lakon,ics(14*ncs_),
     &        ics(15*ncs_))
!
         elseif(textpart(1)(1:22).eq.'*DEFORMATIONPLASTICITY') then
            call defplasticities(inpc,textpart,elcon,nelcon,
     &        nmat,ntmat_,ncmat_,irstrt,istep,istat,n,iperturb,
     &        iline,ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:8).eq.'*DENSITY') then
            call densities(inpc,textpart,rhcon,nrhcon,
     &        nmat,ntmat_,irstrt,istep,istat,n,iline,ipol,
     &        inl,ipoinp,inp)
!
         elseif(textpart(1)(1:7).eq.'*DEPVAR') then
            call depvars(inpc,textpart,nelcon,nmat,
     &           nstate_,irstrt,istep,istat,n,iline,ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:6).eq.'*DFLUX') then
            call dfluxes(inpc,textpart,set,istartset,iendset,
     &        ialset,nset,nelemload,sideload,xload,nload,nload_,
     &        ielmat,ntmat_,iamload,amname,nam,lakon,ne,dflux_flag,
     &        istep,istat,n,iline,ipol,inl,ipoinp,inp,nam_,namtot_,
     &        namta,amta)
            dflux_flag=.true.
!
         elseif(textpart(1)(1:6).eq.'*DLOAD') then
            call dloads(inpc,textpart,set,istartset,iendset,
     &        ialset,nset,nelemload,sideload,xload,nload,nload_,
     &        ielmat,ntmat_,iamload,
     &        amname,nam,lakon,ne,dload_flag,istep,istat,n,
     &        iline,ipol,inl,ipoinp,inp,cbody,ibody,xbody,nbody,nbody_,
     &        xbodyold,iperturb,physcon,nam_,namtot_,namta,amta,nmethod)
            dload_flag=.true.
!
         elseif(textpart(1)(1:8).eq.'*DYNAMIC') then
            call dynamics(inpc,textpart,nmethod,iperturb,tinc,tper,
     &        tmin,tmax,idrct,alpha,haftol,iexpl,isolver,istep,
     &        istat,n,iline,ipol,inl,ipoinp,inp,ithermal)
!
         elseif(textpart(1)(1:8).eq.'*ELASTIC') then
            call elastics(inpc,textpart,elcon,nelcon,
     &        nmat,ntmat_,ncmat_,irstrt,istep,istat,n,
     &        iline,ipol,inl,ipoinp,inp)
!
         elseif((textpart(1)(1:8).eq.'*ELEMENT').and.
     &          (textpart(1)(1:14).ne.'*ELEMENTOUTPUT')) then
            call elements(inpc,textpart,kon,ipkon,lakon,nkon,
     &        ne,ne_,set,istartset,iendset,ialset,nset,nset_,nalset,
     &        nalset_,mint_,ixfree,iponor,xnor,istep,istat,n,iline,
     &        ipol,inl,ipoinp,inp,axial)
!
         elseif(textpart(1)(1:7).eq.'*ELFILE') then
            node_flag=.false.
            call noelfiles(inpc,textpart,jout,filab,nmethod,
     &           nodefile_flag,elfile_flag,node_flag,nener,ithermal,
     &           istep,istat,n,iline,ipol,inl,ipoinp,inp,out3d,nlabel)
            elfile_flag=.true.
!
         elseif(textpart(1)(1:8).eq.'*ELPRINT') then
            call elprints(inpc,textpart,set,istartset,iendset,ialset,
     &        nset,nset_,nalset,nprint,nprint_,jout,
     &        prlab,prset,nmethod,elprint_flag,nener,ithermal,
     &        istep,istat,n,iline,ipol,inl,ipoinp,inp)
            elprint_flag=.true.
!
         elseif(textpart(1)(1:6).eq.'*ELSET') then
            call noelsets(inpc,textpart,set,istartset,iendset,ialset,
     &        nset,nset_,nalset,nalset_,nk,ne,irstrt,istep,istat,n,
     &        iline,ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:8).eq.'*ENDSTEP') then
            exit
!
         elseif(textpart(1)(1:9).eq.'*EQUATION') then
            M_or_SPC=1
            call equations(inpc,textpart,ipompc,nodempc,coefmpc,
     &        nmpc,nmpc_,mpcfree,nk,co,trab,inotr,ntrans,ikmpc,ilmpc,
     &        labmpc,istep,istat,n,iline,ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:10).eq.'*EXPANSION') then
            call expansions(inpc,textpart,alcon,nalcon,
     &        alzero,nmat,ntmat_,irstrt,istep,istat,n,iline,
     &        ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:5).eq.'*FILM') then
            call films(inpc,textpart,set,istartset,iendset,
     &        ialset,nset,nelemload,sideload,xload,nload,nload_,
     &        ielmat,ntmat_,iamload,amname,nam,lakon,ne,film_flag,
     &        istep,istat,n,iline,ipol,inl,ipoinp,inp,nam_,namtot_,
     &        namta,amta)
            film_flag=.true.
!
         elseif(textpart(1)(1:10).eq.'*FREQUENCY') then
            call frequencies(inpc,textpart,nmethod,
     &        mei,fei,iperturb,istep,istat,n,iline,ipol,
     &        inl,ipoinp,inp,ithermal,isolver,xboun,nboun)
!
         elseif(textpart(1)(1:4).eq.'*GAP') then
            call gaps(inpc,textpart,set,istartset,iendset,
     &           ialset,nset,nset_,nalset,nalset_,ipompc,nodempc,
     &           coefmpc,labmpc,nmpc,nmpc_,mpcfree,ikmpc,ilmpc,lakon,
     &           ipkon,kon,nk,nk_,nodeboun,ndirboun,ikboun,ilboun,
     &           nboun,nboun_,iperturb,ne_,co,xboun,ctrl,typeboun,
     &           istep,istat,n,iline,ipol,inl,ipoinp,inp,iamboun,nam,
     &           inotr,trab,ntrans,nmethod)
!
         elseif(textpart(1)(1:13).eq.'*FLUIDSECTION') then
            call fluidsections(inpc,textpart,set,istartset,iendset,
     &        ialset,nset,ielmat,matname,nmat,
     &        kon,ipkon,irstrt,istep,istat,n,
     &        iline,ipol,inl,ipoinp,inp,lakon,ielprop,nprop,
     &        nprop_,prop)
!
         elseif(textpart(1)(1:8).eq.'*HEADING') then
            call headings(inpc,textpart,istat,n,iline,ipol,inl,
     &        ipoinp,inp)
!
         elseif(textpart(1)(1:13).eq.'*HEATTRANSFER') then
            call heattransfers(inpc,textpart,nmethod,iperturb,isolver,
     &           istep,istat,n,tinc,tper,tmin,tmax,idrct,ithermal,iline,
     &           ipol,inl,ipoinp,inp,alpha,mei,fei)
!
         elseif(textpart(1)(1:13).eq.'*HYPERELASTIC') then
            call hyperelastics(inpc,textpart,elcon,nelcon,
     &        nmat,ntmat_,ncmat_,irstrt,istep,istat,n,iperturb,
     &        iline,ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:10).eq.'*HYPERFOAM') then
            call hyperfoams(inpc,textpart,elcon,nelcon,
     &        nmat,ntmat_,ncmat_,irstrt,istep,istat,n,iperturb,iline,
     &        ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:18).eq.'*INITIALCONDITIONS') then
            call initialconditions(inpc,textpart,set,istartset,iendset,
     &        ialset,nset,t0,t1,prestr,iprestr,ithermal,veold,inoelfree,
     &        nk_,mint_,istep,istat,n,iline,ipol,inl,ipoinp,inp,lakon,
     &        kon,co,ne,ipkon,vold)
!
         elseif(textpart(1)(1:9).eq.'*MATERIAL') then
            call materials(inpc,textpart,matname,nmat,nmat_,
     &        irstrt,istep,istat,n,iline,ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:13).eq.'*MODALDAMPING') then
            call modaldampings(inpc,textpart,nmethod,xmodal,istep,
     &        istat,n,iline,ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:13).eq.'*MODALDYNAMIC') then
            call modaldynamics(inpc,textpart,nmethod,tinc,tper,iexpl,
     &        istep,istat,n,iline,ipol,inl,ipoinp,inp,iperturb,
     &        isolver,cs,mcs)
!
         elseif(textpart(1)(1:4).eq.'*MPC') then
            call mpcs(inpc,textpart,set,istartset,iendset,
     &           ialset,nset,nset_,nalset,nalset_,ipompc,nodempc,
     &           coefmpc,labmpc,nmpc,nmpc_,mpcfree,ikmpc,ilmpc,lakon,
     &           ipkon,kon,nk,nk_,nodeboun,ndirboun,ikboun,ilboun,
     &           nboun,nboun_,iperturb,ne_,co,xboun,ctrl,typeboun,
     &           istep,istat,n,iline,ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:11).eq.'*NOANALYSIS') then
            call noanalysis(inpc,textpart,nmethod,iperturb,istep,
     &        istat,n,iline,ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:15).eq.'*NODALTHICKNESS') then
            call nodalthicknesses(inpc,textpart,set,istartset,iendset,
     &           ialset,nset,thickn,nk,istep,istat,n,iline,ipol,inl,
     &           ipoinp,inp)
!
         elseif((textpart(1)(1:5).eq.'*NODE').and.
     &          (textpart(1)(1:10).ne.'*NODEPRINT').and.
     &          (textpart(1)(1:11).ne.'*NODEOUTPUT').and.
     &          (textpart(1)(1:9).ne.'*NODEFILE')) then
            call nodes(inpc,textpart,co,nk,nk_,set,istartset,iendset,
     &        ialset,nset,nset_,nalset,nalset_,istep,istat,n,iline,
     &        ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:9).eq.'*NODEFILE') then
            node_flag=.true.
            call noelfiles(inpc,textpart,jout,filab,nmethod,
     &           nodefile_flag,elfile_flag,node_flag,nener,ithermal,
     &           istep,istat,n,iline,ipol,inl,ipoinp,inp,out3d,nlabel)
            nodefile_flag=.true.
!
         elseif(textpart(1)(1:10).eq.'*NODEPRINT') then
            call nodeprints(inpc,textpart,set,istartset,iendset,ialset,
     &        nset,nset_,nalset,nprint,nprint_,jout,
     &        prlab,prset,nodeprint_flag,ithermal,istep,istat,n,iline,
     &        ipol,inl,ipoinp,inp)
            nodeprint_flag=.true.
!
         elseif(textpart(1)(1:7).eq.'*NORMAL') then
            call normals(inpc,textpart,iponor,xnor,ixfree,
     &           ipkon,kon,nk,nk_,ne,lakon,istep,istat,n,iline,ipol,
     &           inl,ipoinp,inp)
!
         elseif(textpart(1)(1:5).eq.'*NSET') then
            call noelsets(inpc,textpart,set,istartset,iendset,ialset,
     &        nset,nset_,nalset,nalset_,nk,ne,irstrt,istep,istat,n,
     &        iline,ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:12).eq.'*ORIENTATION') then
            call orientations(inpc,textpart,orname,orab,norien,
     &        norien_,istep,istat,n,iline,ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:18).eq.'*PHYSICALCONSTANTS') then
            call physicalconstants(inpc,textpart,physcon,
     &        istep,istat,n,iline,ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:8).eq.'*PLASTIC') then
            call plastics(inpc,textpart,nelcon,nmat,ntmat_,npmat_,
     &        plicon,nplicon,plkcon,nplkcon,iplas,iperturb,nstate_,
     &        ncmat_,elcon,matname,irstrt,istep,istat,n,iline,ipol,
     &        inl,ipoinp,inp)
!
         elseif(textpart(1)(1:8).eq.'*RADIATE') then
            call radiates(inpc,textpart,set,istartset,iendset,
     &        ialset,nset,nelemload,sideload,xload,nload,nload_,
     &        ielmat,ntmat_,iamload,amname,nam,lakon,ne,radiate_flag,
     &        istep,istat,n,iline,ipol,inl,ipoinp,inp,physcon,nam_,
     &        namtot_,namta,amta)
            radiate_flag=.true.
!
         elseif(textpart(1)(1:8).eq.'*RESTART') then
            call restarts(istep,nset,nload,nforc, nboun,nk,ne,
     &           nmpc,nalset,nmat,ntmat_,npmat_,norien,nam,nprint,
     &           mint_,ntrans,ncs_,namtot_,ncmat_,mpcfree,
     &           maxlenmpc,ne1d,
     &           ne2d,nflow,nlabel,iplas,nkon,ithermal,nmethod,
     &           iperturb,nstate_,nener,set,istartset,iendset,ialset,co,
     &           kon,ipkon,lakon,nodeboun,ndirboun,iamboun,xboun,ikboun,
     &           ilboun,ipompc,nodempc,coefmpc,labmpc,ikmpc,ilmpc,
     &           nodeforc,ndirforc,iamforc,xforc,ikforc,ilforc,
     &           nelemload,iamload,sideload,xload,
     &           elcon,nelcon,rhcon,nrhcon,alcon,nalcon,alzero,plicon,
     &           nplicon,plkcon,nplkcon,orname,orab,ielorien,trab,inotr,
     &           amname,amta,namta,t0,t1,iamt1,veold,ielmat,
     &           matname,prlab,prset,filab,vold,nodebounold,
     &           ndirbounold,xbounold,xforcold,xloadold,t1old,eme,
     &           iponor,xnor,knor,thickn,thicke,offset,iponoel,
     &           inoel,rig,shcon,nshcon,cocon,
     &           ncocon,ics,sti,ener,xstate,jobnamec,infree,nnn,
     &           irstrt,inpc,textpart,istat,n,key,prestr,iprestr,
     &           cbody,ibody,xbody,nbody,xbodyold,ttime,qaold,
     &           cs,mcs,output,physcon,ctrl,typeboun,iline,ipol,inl,
     &           ipoinp,inp,fmpc,tieset,ntie)
!
         elseif(textpart(1)(1:10).eq.'*RIGIDBODY') then
            call rigidbodies(inpc,textpart,set,istartset,iendset,
     &           ialset,nset,nset_,nalset,nalset_,ipompc,nodempc,
     &           coefmpc,labmpc,nmpc,nmpc_,mpcfree,ikmpc,ilmpc,lakon,
     &           ipkon,kon,nk,nk_,nodeboun,ndirboun,ikboun,ilboun,
     &           nboun,nboun_,iperturb,ne_,ctrl,typeboun,
     &           istep,istat,n,iline,ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:26).eq.'*SELECTCYCLICSYMMETRYMODES') then
            call selcycsymmods(inpc,textpart,cs,ics,tieset,istartset,
     &        iendset,ialset,ipompc,nodempc,coefmpc,nmpc,nmpc_,ikmpc,
     &        ilmpc,mpcfree,mcs,set,nset,labmpc,istep,istat,n,iline,
     &        ipol,inl,ipoinp,inp,nmethod,key)
!
         elseif(textpart(1)(1:13).eq.'*SHELLSECTION') then
            call shellsections(inpc,textpart,set,istartset,iendset,
     &        ialset,nset,ielmat,matname,nmat,ielorien,orname,
     &        norien,thicke,kon,ipkon,offset,irstrt,istep,istat,n,
     &        iline,ipol,inl,ipoinp,inp,lakon)
!
         elseif(textpart(1)(1:13).eq.'*SOLIDSECTION') then
            call solidsections(inpc,textpart,set,istartset,iendset,
     &        ialset,nset,ielmat,matname,nmat,ielorien,orname,
     &        norien,lakon,thicke,kon,ipkon,irstrt,istep,istat,n,iline,
     &        ipol,inl,ipoinp,inp,cs,mcs,axial)
!
         elseif(textpart(1)(1:13).eq.'*SPECIFICHEAT') then
            call specificheats(inpc,textpart,shcon,nshcon,
     &           nmat,ntmat_,irstrt,istep,istat,n,iline,ipol,
     &           inl,ipoinp,inp)
!
         elseif(textpart(1)(1:7).eq.'*STATIC') then
            call statics(inpc,textpart,nmethod,iperturb,isolver,istep,
     &        istat,n,tinc,tper,tmin,tmax,idrct,iline,ipol,inl,ipoinp,
     &        inp,ithermal,cs,ics,tieset,istartset,
     &        iendset,ialset,ipompc,nodempc,coefmpc,nmpc,nmpc_,ikmpc,
     &        ilmpc,mpcfree,mcs,set,nset,labmpc)
!
         elseif(textpart(1)(1:20).eq.'*STEADYSTATEDYNAMICS') then
            call steadystatedynamics(inpc,textpart,nmethod,
     &        iexpl,istep,istat,n,iline,ipol,inl,ipoinp,inp,iperturb,
     &        isolver,xmodal,cs,mcs)
!
         elseif(textpart(1)(1:5).eq.'*STEP') then
            call steps(inpc,textpart,iperturb,iprestr,nbody,nforc,
     &                 nload,ithermal,t0,t1,nk,irstrt,istep,istat,n,
     &                 jmax,ctrl,iline,ipol,inl,ipoinp,inp,newstep)
!
         elseif(textpart(1)(1:8).eq.'*SURFACE') then
            call surfaces(inpc,textpart,set,istartset,iendset,ialset,
     &           nset,nset_,nalset,nalset_,nk,ne,istep,istat,n,iline,
     &           ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:12).eq.'*TEMPERATURE') then
            call temperatures(inpc,textpart,set,istartset,iendset,
     &        ialset,nset,t0,t1,nk,ithermal,iamt1,amname,nam,
     &        inoelfree,nk_,nmethod,temp_flag,istep,istat,n,iline,
     &        ipol,inl,ipoinp,inp,nam_,namtot_,namta,amta)
            temp_flag=.true.
!
         elseif(textpart(1)(1:4).eq.'*TIE') then
            call ties(inpc,textpart,tieset,tietol,istep,
     &           istat,n,iline,ipol,inl,ipoinp,inp,ntie,ntie_)
!
         elseif(textpart(1)(1:10).eq.'*TRANSFORM') then
            if(M_or_SPC.eq.1) then
               write(*,*) '*WARNING in calinput: SPCs or MPCs have'
               write(*,*) '         been defined before the definition'
               write(*,*) '         of a transformation'
            endif
            call transforms(inpc,textpart,trab,ntrans,ntrans_,
     &        inotr,set,istartset,iendset,ialset,nset,istep,istat,
     &        n,iline,ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:13).eq.'*USERMATERIAL') then
            call usermaterials(inpc,textpart,elcon,nelcon,
     &        nmat,ntmat_,ncmat_,iperturb,iumat,irstrt,istep,istat,n,
     &        iline,ipol,inl,ipoinp,inp)
!
         elseif(textpart(1)(1:7).eq.'*VISCO') then
            call viscos(inpc,textpart,nmethod,iperturb,isolver,istep,
     &        istat,n,tinc,tper,tmin,tmax,idrct,iline,ipol,inl,ipoinp,
     &        inp)
!
         elseif(inpc(iline)(1:40).eq.
     &       '                                        '.and.
     &       inpc(iline)(41:80).eq.
     &       '                                        '.and.
     &       inpc(iline)(81:120).eq.
     &       '                                        '.and.
     &       inpc(iline)(121:132).eq.
     &       '            ')then
            call getnewline(inpc,textpart,istat,n,key,iline,ipol,inl,
     &         ipoinp,inp)
!     
         else
            write(*,*) '*WARNING in calinput. Card image cannot be inter
     &preted:'
            write(*,'(a132)') inpc(iline)
            call getnewline(inpc,textpart,istat,n,key,iline,ipol,inl,
     &         ipoinp,inp)
         endif
!           
      enddo loop
!
!     check whether the *END STEP card was preceded by a *STEP card    
!
      if(newstep.eq.0) then
         write(*,*) '*ERROR in calinput: *END STEP card in step ',
     &           istep+1
         write(*,*) '       was not preceded by a *STEP card'
      endif
!
!     reorganizing the input in field inpc
!
      j=1
      do
         if(j.eq.1) then
            inp(1,j)=1
         else
            inp(1,j)=inp(1,inl)-iline
         endif
         inp(2,j)=inp(2,inl)-iline
         if(inp(3,inl).eq.0) then
            inp(3,j)=0
            ipoinp(2,nentries)=j
            exit
         else
            inl=inp(3,inl)
            inp(3,j)=j+1
            j=j+1
         endif
      enddo
      do j=1,nentries-1
         ipoinp(1,j)=0
      enddo
      ipoinp(1,nentries)=1
      do j=iline+1,nline
         inpc(j-iline)=inpc(j)
      enddo
      nline=nline-iline
c      call writeinput(inpc,ipoinp,inp,nline,ipoinp(2,12))
!
!     expanding the 1-D and 2-D elements to volume elements
!     treating the incompressibility constraint
!
      call gen3delem(kon,ipkon,lakon,ne,ipompc,nodempc,coefmpc,
     &  nmpc,nmpc_,mpcfree,ikmpc,ilmpc,labmpc,ikboun,ilboun,nboun,
     &  nboun_,nodeboun,ndirboun,xboun,iamboun,nam,
     &  inotr,trab,nk,nk_,iponoel,inoel,iponor,xnor,thicke,thickn,
     &  knor,istep,offset,t0,t1,ikforc,ilforc,rig,nforc,
     &  nforc_,nodeforc,ndirforc,xforc,iamforc,nelemload,sideload,
     &  nload,ithermal,ntrans,co,ixfree,ikfree,inoelfree,iponoelmax,
     &  iperturb,tinc,tper,tmin,tmax,ctrl,typeboun,nmethod)
!
      infree(1)=ixfree
      infree(2)=ikfree
      infree(3)=inoelfree
      infree(4)=iponoelmax
!
!     default file printing options and check of the selected options
!
c      i=0
c      do
c         i=i+1
c         if(i.gt.nlabel) then
c            filab(1)='U   '
c            filab(3)='S   '
c            jout=max(jout,1)
c            exit
c         endif
c         if(filab(i).ne.'    ') exit
c      enddo
!
      if(iplas.eq.0) then
         if(filab(6)(1:2).eq.'PE') then
            write(*,*) '*WARNING in calinput: PE-output requested'
            write(*,*) '         yet no (visco)plastic calculation'
            filab(6)='      '
         endif
         ii=0
         do i=1,nprint
            if(prlab(i)(1:4).eq.'PE  ') then
               write(*,*) '*WARNING in calinput: PE-output requested'
               write(*,*) '         yet no (visco)plastic calculation'
               cycle
            endif
            ii=ii+1
            prlab(ii)=prlab(i)
            prset(ii)=prset(i)
         enddo
         nprint=ii
      endif
!
      if(ithermal.eq.0) then
         if(filab(2)(1:2).eq.'NT') then
            write(*,*) '*WARNING in calinput: temperature output'
            write(*,*) '         requested, yet no thermal loading'
            write(*,*) '         active'
            filab(2)='      '
         endif
         ii=0
         do i=1,nprint
            if(prlab(i)(1:4).eq.'NT  ') then
               write(*,*) '*WARNING in calinput: temperature output'
               write(*,*) '         requested, yet no thermal loading'
               write(*,*) '         active'
               cycle
            endif
            ii=ii+1
            prlab(ii)=prlab(i)
            prset(ii)=prset(i)
         enddo
         nprint=ii
      endif
!
      if(ithermal.le.1) then
         if(filab(9)(1:3).eq.'HFL') then
            write(*,*) '*WARNING in calinput: heat flux output'
            write(*,*) '         requested, yet no heat transfer'
            write(*,*) '         calculation'
         endif
         if(filab(10)(1:3).eq.'RFL') then
            write(*,*) '*WARNING in calinput: heat source output'
            write(*,*) '         requested, yet no heat transfer'
            write(*,*) '         calculation'
         endif
      endif
!
!     check whether a material was assigned to each active element
!
      ierror=0
      do i=1,ne
         if(ipkon(i).lt.0) cycle
         if(lakon(i)(1:1).eq.'G') cycle
         if(ielmat(i).eq.0) then
            ierror=1
            write(*,*) '*ERROR in calinput: no material was assigned'
            write(*,*) '       to element ',i
         endif
      enddo
      if(ierror.eq.1) stop
!
!     check whether the density was defined for dynamic calculations
!     check whether the density and specific heat were defined for 
!     transient thermal calculations
!
      if((nbody.gt.0).or.
     &   (nmethod.eq.2).or.(nmethod.eq.4)) then
         ierror=0
         do i=1,nmat
            if(nrhcon(i).eq.0) then
               ierror=1
               write(*,*) '*ERROR in calinput: no density was assigned'
               write(*,*) '       to material ',matname(i),
     &              ' in a dynamic'
               write(*,*) '       calculation or a calculation with'
               write(*,*) '       centrifugal or gravitational loads'
            endif
         enddo
         if(ithermal.gt.1) then
            do i=1,nmat
               if(nshcon(i).eq.0) then
                  ierror=1
                  write(*,*) '*ERROR in calinput: no specific heat'
                  write(*,*) '       was assigned to material ',
     &                        matname(i)
                  write(*,*) '       in a transient heat transfer'
                  write(*,*) '       calculation'
               endif  
            enddo
         endif
         if(ierror.eq.1) stop
      endif
!
!     check whether the conductivity was defined for thermal calculations
!
      if(ithermal.ge.2) then
         ierror=1
         do i=1,nmat
            if(ncocon(1,i).ne.0) then
               ierror=0
               exit
            endif
         enddo
         if(ierror.eq.1) then
            write(*,*) '*ERROR in calinput: no conductivity'
            write(*,*) '       was assigned to any material'
            write(*,*) '       in a heat transfer calculation'
            stop
         endif
      endif
!
      write(*,*)
      write(*,*) 'STEP ',istep
      write(*,*)
      if(nmethod.eq.0) then
         write(*,*) 'No analysis was selected'
      elseif(nmethod.eq.1) then
         write(*,*) 'Static analysis was selected'
      elseif(nmethod.eq.2) then
         write(*,*) 'Frequency analysis was selected'
      elseif(nmethod.eq.3) then
         write(*,*) 'Buckling analysis was selected'
      elseif(nmethod.eq.4) then
         write(*,*) 'Linear dynamic analysis was selected'
      endif
      write(*,*)
      if(iperturb.eq.1) then
         write(*,*) 'Perturbation parameter is active'
         write(*,*)
      elseif(iperturb.eq.2) then
         write(*,*) 'Nonlinear geometric effects are taken into account'
         write(*,*)
      elseif(iperturb.eq.3) then
         write(*,*) 'Nonlinear geometric effects and nonlinear '
         write(*,*) 'material laws are taken into account'
         write(*,*)
      endif
!
c      write(*,*) 'spc'
c      do i=1,nboun
c         write(*,'(4i7,1x,e11.4)') 
c     &        i,nodeboun(i),ndirboun(i),iamboun(i),xboun(i)
c      enddo
c      write(*,*) 'cload'
c      do i=1,nforc
c         write(*,'(4i7,1x,e11.4)')
c     &      i,nodeforc(1,i),ndirforc(i),iamforc(i),xforc(i)
c      enddo
!
      return
      end
