Index: palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/create_kpp_module.C
===================================================================
--- palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/create_kpp_module.C	(revision 2768)
+++ palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/create_kpp_module.C	(revision 3298)
@@ -17,7 +17,24 @@
 //-----------------
 //$Id: create_kpp_module.C 2470 2017-09-14 13:56:42Z forkel $
+// forkel 25.09.2018:  added  automatic line with meechanism name (read mech_list)
+// forkel 20.09.2018:  added  vl_glo = size(tempi,1)
+// ketelsen 18.09.2018: Removed creation of fill_ Subroutine and creation of calls thereof
+//
+// forkel 12.09.2018: Fix in order not to loose the values of qvap and fakt
+//
+// forkel 03.09.2018: Bug fix: moved kppi.add_line("    CALL initialize after fakt = fakti(is)
+// forkel June 2018: added qvap and fakt, re-established original uppercase/lowercase 
+//                    Deleted definition of qvap,fakt in create_kpp_integrate again
+//
+// ketelsen July 2018: Changes for vector mode (edit_WAXPY, edit_FunTemplate, edit_JacTemplate, 
+//                            some cleanup of comments, various changes in create_kpp_integrate)
+//
+// forkel June 2018: Added qvap and fakt, re-established original uppercase/lowercase 
+//
+//
+/ 2017-09-14 13:56:42Z forkel $
 // Removed preprocessor directive __chem again 
 //
-/ 2017-09-14 13:56:42Z forkel $
+// 2017-09-14 13:56:42Z forkel $
 //
 // 
@@ -25,5 +42,5 @@
 //change of some output to lowercase with uppercase Fortran
 //
-// Nov 2016: Intial version (Klaus Ketelsen)
+// Nov 2016: Intial version of KP4 adapted to PALM (Klaus Ketelsen)
 //
 
@@ -49,15 +66,13 @@
    cout << "Create " << module_name << " from kpp Fortran sources" <<endl;
    cout << "Vector mode " << kpp_switches.is_vector() <<endl;
+   cout << "De_indexing " << kpp_switches.de_indexing() <<endl;
 
    create_fortran_files_and_read();
-   cout << "## after create_fortran_files_and_read " <<endl;
 
 // Generate first module lines 
 
      string first_line="MODULE " + module_name;
-     mz_kpp.add_line(first_line);
-     mz_kpp.add_line("!");
-//   mz_kpp.add_line("#if defined( __chem )");
-//   mz_kpp.add_line(" ");
+   mz_kpp.add_line(first_line);
+   mz_kpp.add_line(" ");
 
 //    string e5_line = first_line +"_e5";
@@ -93,5 +108,4 @@
      it->edit_fortran ();
    }
-   cout << "## after edit FORTRAN files            " <<endl;
 
 // Generate a list of single subroutines from kpp-files
@@ -109,7 +123,7 @@
    }
 
-
-   if(kpp_switches.is_vector()) {
-
+   if(kpp_switches.is_vector()) {
+
+   cout << "##### Hier kpp_switches.is_vector          " <<endl;
 //   Change header section
      for(it=kpp_includes.begin();it!=kpp_includes.end();it++) {
@@ -138,6 +152,15 @@
          it->edit_Fun();
        }
-     }
-   cout << "## after Edit individual subroutines    " <<endl;
+       if(it->get_name() == "WAXPY" ) {
+         it->edit_WAXPY();
+       }
+       if(it->get_name() == "FunTemplate" ) {
+         it->edit_FunTemplate();
+       }
+       if(it->get_name() == "JacTemplate" ) {
+         it->edit_JacTemplate();
+       }
+     }
+// cout << "## after Edit individual subroutines    " <<endl;
 
    }
@@ -146,7 +169,12 @@
 
    for(it=kpp_subroutines.begin();it!=kpp_subroutines.end();it++) {
-     if(it->get_name() == "update_rconst") {
+     if(it->get_name() == "Update_RCONST") {
        it->edit_Update_RCONST(Vvar_list);
      }
+
+     if(it->get_name() == "Initialize") {
+       it->edit_Initialize(Vvar_list);
+     }
+
    }
 
@@ -184,32 +212,15 @@
      }
 
-     buf = prefix + "INTERFACE            " + it->get_name() ;
+     buf = prefix + "interface            " + it->get_name() ;
      mz_kpp.add_line(buf);
-     buf = prefix + "  MODULE PROCEDURE   " + it->get_name();
+     buf = prefix + "  module procedure   " + it->get_name();
      mz_kpp.add_line(buf);
-     buf = prefix + "END INTERFACE        " + it->get_name();
+     buf = prefix + "end interface        " + it->get_name();
      mz_kpp.add_line(buf);
      mz_kpp.add_line(" ");
    }
-   for(iv=Vvar_list.begin();iv!=Vvar_list.end();iv++) {
-     string          buf;
-
-     string sub_name = "fill_" + iv->name;
-     buf = "  INTERFACE            " + sub_name;
-     mz_kpp.add_line(buf);
-     buf = "    MODULE PROCEDURE   " + sub_name;
-     mz_kpp.add_line(buf);
-     buf = "  END INTERFACE        " + sub_name;
-     mz_kpp.add_line(buf);
-     buf = "  PUBLIC               " + sub_name;
-     mz_kpp.add_line(buf);
-     mz_kpp.add_line(" ");
-   }
 
    mz_kpp.add_line(" ");
 
-   for(iv=Vvar_list.begin();iv!=Vvar_list.end();iv++) {
-     create_fill_routine(kpp_subroutines, *iv);
-   }
 
 // Copy FORTRAN subroutines to mz_kpp
@@ -224,19 +235,7 @@
 // Finish module
 
-//   mz_kpp.add_line("#endif");
-     string last_line="END MODULE " + module_name;
-     mz_kpp.add_line("");
-     mz_kpp.add_line(last_line);
-
-// Handle e5 module
-
-//    for(it=e5_subroutines.begin();it!=e5_subroutines.end();it++) {
-//      e5_kpp.add_line(" ");
-//      it->copy_to_MZ_KPP(e5_kpp);
-//    }
-
-//    last_line = last_line + "_e5";
-//    e5_kpp.add_line(" ");
-//    e5_kpp.add_line(last_line);
+   string last_line="end module " + module_name;
+   mz_kpp.add_line("");
+   mz_kpp.add_line(last_line);
 
 // Write the complete module to file: mz_kpp.f
@@ -376,4 +375,21 @@
    string                          diline;
 
+// Read mechanism from mech_list
+
+   in.open("mech_list");
+   if( !in ) {
+      cout << "cannot open " << endl; my_abort("mech_list");
+   }
+
+   while ( 1 ) {
+     getline (in, buf);
+     if( in.eof() ) break;
+     if( in.bad() ) my_abort("ERROR_READ_4");
+     line.set_line(buf);
+     mz_kpp.add_line(line);
+   }
+   in.close();
+
+
 // Read Modul Header from file $MZ_KPP_HOME/templates/module_header
 
@@ -394,40 +410,27 @@
    mz_kpp.add_line("                                                                 "); 
    if(kpp_switches.is_vector()) {
-       mz_kpp.add_line("  LOGICAL,  PARAMETER          :: l_vector = .TRUE.             ");
-   } else {
-       mz_kpp.add_line("  LOGICAL,  PARAMETER          :: l_vector = .FALSE.            ");
+       mz_kpp.add_line("  logical,parameter          :: L_VECTOR = .TRUE.             ");
+   } else {
+       mz_kpp.add_line("  logical,parameter          :: L_VECTOR = .FALSE.            ");
    }
 //  mz_pj_20070531+
    sprintf(distr,"%i",kpp_switches.de_indexing());
    diline = distr ;
-   mz_kpp.add_line("  INTEGER,  PARAMETER          :: i_lu_di = " + diline );
+   mz_kpp.add_line("  integer,parameter          :: I_LU_DI = " + diline );
 //  mz_pj_20070531-
 
-   mz_kpp.add_line("  INTEGER,  PARAMETER          :: vl_dim = " 
-                   + kpp_switches.get_vector_length() ); 
-   mz_kpp.add_line("  INTEGER                     :: vl                              "); 
+   mz_kpp.add_line("  integer,parameter          :: VL_DIM = " 
+                 + kpp_switches.get_vector_length() ); 
+   mz_kpp.add_line("  integer                     :: vl                              "); 
    mz_kpp.add_line("                                                                 "); 
-   mz_kpp.add_line("  INTEGER                     :: vl_glo                          "); 
-   mz_kpp.add_line("  INTEGER                     :: is,ie                           "); 
+   mz_kpp.add_line("  integer                     :: VL_glo                          "); 
+   mz_kpp.add_line("  integer                     :: is,ie                           "); 
    mz_kpp.add_line("                                                                 "); 
-   mz_kpp.add_line("  INTEGER,  DIMENSION(vl_dim)  :: kacc, krej                      "); 
-   mz_kpp.add_line("  INTEGER,  DIMENSION(vl_dim)  :: ierrv                           "); 
-   mz_kpp.add_line("  LOGICAL                     :: data_loaded = .false.             "); 
-   
+   mz_kpp.add_line("                                                                 "); 
+   mz_kpp.add_line("  integer, dimension(VL_dim)   :: Kacc,Krej                       "); 
+   mz_kpp.add_line("  integer, dimension(VL_dim)   :: IERRV                           "); 
+   mz_kpp.add_line("  logical                     :: data_loaded = .false.             "); 
+
    in.close();
-
-//    in_e5.open("module_header_e5");
-//    if( !in_e5 ) {
-//       cout << "cannot open " << endl; my_abort("module_header_e5");
-//    }
-
-//    while ( 1 ) {
-//      getline (in_e5, buf);
-//      if( in_e5.eof() ) break;
-//      if( in_e5.bad() ) my_abort("ERROR_READ_4");
-//      line.set_line(buf);
-//      e5_kpp.add_line(line);
-//    }
-//    in_e5.close();
 
    return;
@@ -448,13 +451,4 @@
    out.close();
    
-//    out_file  = "kk_mecca_kpp_e5.f90";
-//    out_e5.open(out_file.c_str(), ios::out);
-//    if( !out_e5 ) {
-//       cout << "cannot open " << endl; my_abort(out_file);
-//    }
-
-//    e5_kpp.write_file (out_e5);
-
-//    out_e5.close();
 
    return;
@@ -468,48 +462,73 @@
    kppi.set_name("chem_gasphase_integrate");
 
-   kppi.add_line("SUBROUTINE chem_gasphase_integrate (time_step_len, conc, tempk, photo, ierrf, xnacc, xnrej, istatus, l_debug, pe )  ");
+   kppi.add_line("SUBROUTINE chem_gasphase_integrate (time_step_len, conc, tempi, qvapi, fakti, photo, ierrf, xnacc, xnrej, istatus, l_debug, pe, icntrl_i, rcntrl_i )  ");
    kppi.add_line("                                                                    ");
    kppi.add_line("  IMPLICIT NONE                                                     ");
    kppi.add_line("                                                                    ");
 
-   kppi.add_line("  REAL(dp),  INTENT(IN)                    :: time_step_len           ");
+   kppi.add_line("  REAL(dp), INTENT(IN)                   :: time_step_len           ");
    kppi.add_line("  REAL(dp),  DIMENSION(:,:),  INTENT(INOUT) :: conc                    ");
-   kppi.add_line("  REAL(dp),  DIMENSION(:,:),  INTENT(INOUT) :: photo                   ");
-   kppi.add_line("  REAL(dp),  DIMENSION(:),  INTENT(IN)      :: tempk                   ");
-   kppi.add_line("  INTEGER,  INTENT(OUT),  OPTIONAL          :: ierrf(:)                ");
-   kppi.add_line("  INTEGER,  INTENT(OUT),  OPTIONAL          :: xnacc(:)                ");
-   kppi.add_line("  INTEGER,  INTENT(OUT),  OPTIONAL          :: xnrej(:)                ");
-   kppi.add_line("  INTEGER,  INTENT(INOUT),  OPTIONAL        :: istatus(:)              ");
-   kppi.add_line("  INTEGER,  INTENT(IN),  OPTIONAL           :: pe                      ");
-   kppi.add_line("  LOGICAL,  INTENT(IN),  OPTIONAL           :: l_debug                 ");
+   kppi.add_line("  REAL(dp),  DIMENSION(:,:),  INTENT(IN)    :: photo                   ");
+   kppi.add_line("  REAL(dp),  DIMENSION(:),  INTENT(IN)      :: tempi                   ");
+   kppi.add_line("  REAL(dp),  DIMENSION(:),  INTENT(IN)      :: qvapi                   ");
+   kppi.add_line("  REAL(dp),  DIMENSION(:),  INTENT(IN)      :: fakti                   ");
+   kppi.add_line("  INTEGER,  INTENT(OUT), OPTIONAL        :: ierrf(:)                ");
+   kppi.add_line("  INTEGER,  INTENT(OUT), OPTIONAL        :: xNacc(:)                ");
+   kppi.add_line("  INTEGER,  INTENT(OUT), OPTIONAL        :: xNrej(:)                ");
+   kppi.add_line("  INTEGER,  INTENT(INOUT), OPTIONAL      :: istatus(:)              ");
+   kppi.add_line("  INTEGER,  INTENT(IN), OPTIONAL         :: PE                      ");
+   kppi.add_line("  LOGICAL,  INTENT(IN), OPTIONAL         :: l_debug                 ");
+   kppi.add_line("  INTEGER,  DIMENSION(nkppctrl),INTENT(IN), OPTIONAL  :: icntrl_i         ");
+   kppi.add_line("  REAL(dp), DIMENSION(nkppctrl),INTENT(IN), OPTIONAL  :: rcntrl_i         ");
    kppi.add_line("                                                                    ");
    kppi.add_line("  INTEGER                                 :: k   ! loop variable     ");
    kppi.add_line("  REAL(dp)                                :: dt                      ");
-   kppi.add_line("  INTEGER,  DIMENSION(20)                  :: istatus_u               ");
-   kppi.add_line("  INTEGER                                 :: ierr_u                  ");
-   kppi.add_line("                                                                    ");
-   kppi.add_line("                                                                    ");
-   kppi.add_line("  if (present (istatus) )  istatus = 0                              ");
-   kppi.add_line("                                                                    ");
-// kppi.add_line("  vk_glo = size(tempk,1)                                            ");
-// kppi.add_line("                                                                    ");
-
-   kppi.add_line("  DO k=1,vl_glo,vl_dim                                              ");
+   kppi.add_line("  integer, dimension(20)                 :: istatus_u               ");
+   kppi.add_line("  integer                                :: ierr_u                  ");
+   kppi.add_line("  integer                                :: istatf                  ");
+   kppi.add_line("  integer                                :: vl_dim_lo               ");
+   kppi.add_line("                                                                    ");
+   kppi.add_line("                                                                    ");
+   kppi.add_line("  if (present (istatus) )   istatus = 0                             ");
+   kppi.add_line("  if (present (icntrl_i) )  icntrl  = icntrl_i                      ");
+   kppi.add_line("  if (present (rcntrl_i) )  rcntrl  = rcntrl_i                      ");
+   kppi.add_line("                                                                    ");
+   kppi.add_line("  vl_glo = size(tempi,1)                                            ");
+   kppi.add_line("                                                                    ");
+   kppi.add_line("  vl_dim_lo = VL_DIM                                                ");
+   kppi.add_line("  DO k=1,VL_glo,vl_dim_lo                                           ");
    kppi.add_line("    is = k                                                          ");
-   kppi.add_line("    ie = min(k+vl_dim-1,vl_glo)                                     ");
+   kppi.add_line("    ie = min(k+vl_dim_lo-1,VL_glo)                                  ");
    kppi.add_line("    vl = ie-is+1                                                    ");
 
    kppi.add_line("                                                                    ");
    if(kpp_switches.is_vector()) {
-     kppi.add_line("    c(1:vl,:) = conc(is:ie,:)                                     ");
-   } else {
-     kppi.add_line("    c(:) = conc(is,:)                                             ");
-   }
-   kppi.add_line("                                                                    ");
-   if(kpp_switches.is_vector()) {
-     kppi.add_line("    temp(1:vl) = tempk(is:ie)                                     ");
-   } else {
-     kppi.add_line("    temp = tempk(is)                                              ");
-   }
+     kppi.add_line("    C(1:vl,:) = Conc(is:ie,:)                                     ");
+   } else {
+     kppi.add_line("    C(:) = Conc(is,:)                                             ");
+   }
+
+   kppi.add_line("                                                                    ");
+   if(kpp_switches.is_vector()) {
+     kppi.add_line("    temp(1:vl) = tempi(is:ie)                                     ");
+   } else {
+     kppi.add_line("    temp = tempi(is)                                              ");
+   }
+   kppi.add_line("                                                                    ");
+   if(kpp_switches.is_vector()) {
+     kppi.add_line("    qvap(1:vl) = qvapi(is:ie)                                     ");
+   } else {
+     kppi.add_line("    qvap = qvapi(is)                                              ");
+   }
+   kppi.add_line("                                                                    ");
+   if(kpp_switches.is_vector()) {
+     kppi.add_line("    fakt(1:vl) = fakti(is:ie)                                     ");
+   } else {
+     kppi.add_line("    fakt = fakti(is)                                              ");
+   }
+
+   kppi.add_line("                                                                    ");
+   kppi.add_line("    CALL initialize                                                 ");
+
    kppi.add_line("                                                                    ");
    if(kpp_switches.is_vector()) {
@@ -528,10 +547,11 @@
    kppi.add_line("                                                                    ");
    if(kpp_switches.is_vector()) {
-     kppi.add_line("    conc(is:ie,:) = c(1:VL,:)                                     ");
-   } else {
-     kppi.add_line("    IF (PRESENT(l_debug) .AND. PRESENT(pe)) THEN                       ");
-     kppi.add_line("       IF (l_debug) CALL error_output(conc(is,:),ierr_u, pe)           ");
-     kppi.add_line("    ENDIF                                                              ");
-     kppi.add_line("    conc(is,:) = c(:)                                                  ");
+     kppi.add_line("    Conc(is:ie,:) = C(1:VL,:)                                     ");
+   } else {
+     kppi.add_line("   IF (PRESENT(l_debug) .AND. PRESENT(PE)) THEN                       ");
+     kppi.add_line("      IF (l_debug) CALL error_output(Conc(is,:),ierr_u, PE)           ");
+     kppi.add_line("   ENDIF                                                              ");
+     kppi.add_line("                                                                      ");
+     kppi.add_line("    Conc(is,:) = C(:)                                                 ");
    }
 
@@ -540,17 +560,17 @@
    kppi.add_line("                                                                    ");
    if(kpp_switches.is_vector()) {
-     kppi.add_line("    if(PRESENT(ierrf))    ierrf(is:ie) = ierrv(1:vl)              ");
-     kppi.add_line("    if(PRESENT(xnacc))    xnacc(is:ie) = kacc(1:vl)               ");
-     kppi.add_line("    if(PRESENT(xnrej))    xnrej(is:ie) = krej(1:vl)               ");
-   } else {
-     kppi.add_line("    if(PRESENT(ierrf))    ierrf(is) = ierr_u                      ");
-     kppi.add_line("    if(PRESENT(xnacc))    xnacc(is) = istatus_u(4)                ");
-     kppi.add_line("    if(PRESENT(xnrej))    xnrej(is) = istatus_u(5)                ");
-   }
-   kppi.add_line("                                                                    ");
-   kppi.add_line("    if (PRESENT (istatus) )  then                                   ");
-   if(kpp_switches.is_vector()) {
-     kppi.add_line("      istatus(4) =   istatus(4) + sum(kacc(1:vl))                  ");
-     kppi.add_line("      istatus(5) =   istatus(5) + sum(krej(1:vl))                  ");
+     kppi.add_line("    if(Present(ierrf))    ierrf(is:ie) = IERRV(1:VL)              ");
+     kppi.add_line("    if(Present(xNacc))    xNacc(is:ie) = Kacc(1:VL)               ");
+     kppi.add_line("    if(Present(xNrej))    xNrej(is:ie) = Krej(1:VL)               ");
+   } else {
+     kppi.add_line("    if(Present(ierrf))    ierrf(is) = IERR_U                      ");
+     kppi.add_line("    if(Present(xNacc))    xNacc(is) = istatus_u(4)                ");
+     kppi.add_line("    if(Present(xNrej))    xNrej(is) = istatus_u(5)                ");
+   }
+   kppi.add_line("                                                                    ");
+   kppi.add_line("    if (present (istatus) )  then                                   ");
+   if(kpp_switches.is_vector()) {
+     kppi.add_line("      istatus(4) =   istatus(4) + sum(Kacc(1:VL))                  ");
+     kppi.add_line("      istatus(5) =   istatus(5) + sum(Krej(1:VL))                  ");
      kppi.add_line("      istatus(3) =   istatus(4) + istatus(5)                       ");
      kppi.add_line("      istatus(6) =   istatus(6) + istatus_u(6)                     ");
@@ -559,5 +579,5 @@
      kppi.add_line("      istatus(1:8) = istatus(1:8) + istatus_u(1:8)                 ");
    }
-   kppi.add_line("    ENDIF                                                          ");
+   kppi.add_line("    end if                                                          ");
    kppi.add_line("                                                                    ");
    kppi.add_line("  END DO                                                            ");
@@ -568,5 +588,5 @@
    kppi.add_line("                                                                    ");
    for(iv=Vvar_list.begin();iv!=Vvar_list.end();iv++) {
-     kppi.add_line("  if (ALLOCATED("+ iv->name +"))   DEALLOCATE("+ iv->name +" )    ");
+//     kppi.add_line("  if (allocated("+ iv->name +"))   deallocate("+ iv->name +" )    ");
    }
 
@@ -574,5 +594,5 @@
    kppi.add_line("  data_loaded = .false.                                             ");
    kppi.add_line("                                                                    ");
-   kppi.add_line("  RETURN                                                            ");
+   kppi.add_line("  return                                                            ");
    kppi.add_line("END SUBROUTINE chem_gasphase_integrate                                        ");
 
@@ -583,60 +603,2 @@
 }
 
-void create_kpp_module::create_fill_routine(vector<fortran_file> &fi_list, Vvar & var) {
-   fortran_file                         fi;
-   vector<string>::iterator             is;
-   string                               line;
-
-   cout << "Generate fill subroutine for " << var.name << endl;
-
-   fi.set_name(var.name);
-   line = "  SUBROUTINE fill_" + var.name;
-   fi.add_line(line + "(status, array) ");
-     fi.add_line(" ");
-     fi.add_line("    INTEGER,  INTENT(OUT)               :: status ");
-   if(var.nr_dim() == 0) {
-     fi.add_line("    REAL(dp),  INTENT(IN),  DIMENSION(:) :: array ");
-     fi.add_line(" ");
-     fi.add_line("    status = 0");
-     fi.add_line("    IF (.not. ALLOCATED("+var.name+")) & ");
-     fi.add_line("       ALLOCATE("+var.name+"(size(array))) ");
-   } else if(var.nr_dim() == 1) {
-     fi.add_line("    REAL (dp), INTENT(IN), DIMENSION(:,:) :: array ");
-     fi.add_line(" ");
-     fi.add_line("    status = 0 ");
-     fi.add_line("    if (.not. ALLOCATED("+var.name+")) & ");
-     fi.add_line("        ALLOCATE("+var.name+"(size(array,1),"+var.dim_var[0]+")) ");
-   } else if(var.nr_dim() == 2) {
-     fi.add_line(" ");
-     fi.add_line("    REAL (dp), INTENT(IN), DIMENSION(:,:,:) :: array ");
-     fi.add_line(" ");
-     fi.add_line("    status = 0 ");
-     fi.add_line("    if (.not. ALLOCATED("+var.name+")) & ");
-     fi.add_line("        ALLOCATE("+var.name+"(size(array,1),"+var.dim_var[0]+var.dim_var[1]+")) ");
-   } else {
-     fi.add_line("    REAL (dp), INTENT(IN), DIMENSION(:,:,:,:) :: array ");
-     fi.add_line(" ");
-     fi.add_line("    status = 0 ");
-     fi.add_line("    IF (.not. ALLOCATED("+var.name+")) & ");
-     fi.add_line("        ALLOCATE("+var.name+"(size(array,1),"+var.dim_var[0]
-                               +var.dim_var[1]+var.dim_var[3]+")) ");
-   }
-
-   fi.add_line(" ");
-   fi.add_line("    IF (data_loaded .AND. (vl_glo /= size(array,1)) )  THEN ");
-   fi.add_line("       status = 1 ");
-   fi.add_line("       RETURN ");
-   fi.add_line("    END IF ");
-   fi.add_line(" ");
-   fi.add_line("    vl_glo = size(array,1) ");
-   fi.add_line("    "+var.name+ " = array ");
-   fi.add_line("    data_loaded = .TRUE. ");
-   fi.add_line(" ");
-   fi.add_line("    RETURN");
-   fi.add_line(" ");
-   fi.add_line("  END " + line);
-
-   fi_list.push_back(fi);
-
-   return;
-}
Index: palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/create_kpp_module.h
===================================================================
--- palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/create_kpp_module.h	(revision 2768)
+++ palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/create_kpp_module.h	(revision 3298)
@@ -1,14 +1,20 @@
 #ifndef mecca
-#define mecca 1
+// ketelsen 18.09.2018: Removed create_fill_routine
 
-// ############################################################################
-//
-//     create_mz_kpp_module 
-//
-//     create scalar code from .f90 sources created by KPP to be used in MESSy
-//
-//     COPYRIGHT Klaus Ketelsen and MPI-CH   April 2007
-//
-// ############################################################################
+#include <iostream>
+#include <fstream>
+
+#include <string>
+#include <list>
+#include <vector>
+
+#include "fortran_file.h"
+#include "expand_decomp.h"
+
+// Class to create module which contains code generated by kpp.
+
+/ 
+/ 
+// ketelsen 18.09.2018: Removed create_fill_routine
 
 #include <iostream>
@@ -48,6 +54,6 @@
 
   void create_kpp_integrate();
-  void create_fill_routine(vector<fortran_file> &e5_list, Vvar &var );
- public:
+
+public:
 
   void do_work (string s) ;
Index: palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/expand_decomp.C
===================================================================
--- palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/expand_decomp.C	(revision 2768)
+++ palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/expand_decomp.C	(revision 3298)
@@ -165,5 +165,5 @@
   vector<fortran_file>::iterator  it;
   fortran_file                    de;
-  int                             k,kk,j,jj,i,ii;
+  int                             k,kk,j,jj,i;
   string                          line;
   char                            cline[80];
Index: palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/fortran_file.C
===================================================================
--- palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/fortran_file.C	(revision 2768)
+++ palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/fortran_file.C	(revision 3298)
@@ -13,9 +13,19 @@
 //Current revisions:
 //------------------
-// 
-// 
+/ 
+/ 
 //Former revisions:
 //-----------------
 //$Id: fortran_file.C 2470 2017-09-14 13:56:42Z forkel $
+//  ketelsen 18.09.2018: (Rev 3260) added vector switch and creation of dimension statement
+//  forkel Sept.2018:  'fill_' routine applied to qvap and fakt
+//                      removal of unnecessary variables (LOOKAT, monitor etc. from Fortran code)
+//  forkel June 2018:  Moved adaption to PALM conventions to the end of the process
+//                     in order to make future use of vector code adaptations possible
+//  forkel 20.04.2018: Replace Roundoff = WLAMCH('E') by Roundoff = epsilon(one)
+// 
+// 
+// 
+/ 2017-09-14 13:56:42Z forkel $
 //
 // 
@@ -26,5 +36,5 @@
 //
 //
-// Nov 2016: Intial version (Klaus Ketelsen)
+// Nov 2016: Intial version of KP4 adapted to PALM (Klaus Ketelsen)
 //
 
@@ -62,7 +72,24 @@
      }
 
-// Now do some cosmetics to adapt the KPP generated output a bit o the looks of PALM, 
-// i.e. add some blanks, convert all to lowercase except Fortran language elements, etc.
-       if(line.find("'",0) == string::npos)  {     // No substitution in line with strings
+     if(line.find("'",0) == string::npos)  {     // No substitution in line with strings
+//     if(line.substr(0,4) !="!KPP") {
+//      global_substitute(line,"!"," ! ");
+//     if(line.substr(0,2) =="! ")   continue;           // No Substitute of Comments
+//     global_substitute(line,"("," ( ");
+//     global_substitute(line,")"," ) ");
+//     global_substitute(line,",",", ");
+//     global_substitute(line,"*","* ");
+//     global_substitute(line,"* *","**");
+//     global_substitute(line,"/JVS","/ JVS");
+//     global_substitute(line,"-","- ");
+//     global_substitute(line,"e- ","e-");
+//     global_substitute(line,"+","+ ");
+//     global_substitute(line,"d- ","d-");
+//     global_substitute(line,"D- ","D-");
+//     global_substitute(line,"e+ ","e+");
+//     global_substitute(line,"E+ ","E+");
+//     global_substitute(line,"E- ","E-");
+//      }
+
         if(line.substr(0,2) =="! ") {
          global_substitute(line,"#","#");      // just a dummy so comments do not get lost
@@ -77,48 +104,7 @@
          global_substitute(line,"/JVS","/ JVS");
          global_substitute(line,"-","- ");
-         global_substitute(line,"e- ","e-");
          global_substitute(line,"+","+ ");
          global_substitute(line,"+  ","+ ");
-         global_substitute(line,"d- ","d-");
-         global_substitute(line,"D- ","D-");
-         global_substitute(line,"e+ ","e+");
-         global_substitute(line,"E+ ","E+");
-         global_substitute(line,"E- ","E-");
-         global_substitute(line,")=",") =");
-         global_subtolower(line);
-         global_substitute(line,"call ","CALL ");
-         global_substitute(line,"case","CASE");
-         global_substitute(line,"character","CHARACTER");
-         global_substitute(line,"contains","CONTAINS");
-         global_substitute(line,"dimension","DIMENSION");
-         global_substitute(line,"do ","DO ");
-         global_substitute(line,"elseif","ELSEIF");
-         global_substitute(line,"else","ELSE");
-         global_substitute(line,"#ELSE","#else");
-         global_substitute(line,"end do","ENDDO");
-         global_substitute(line,"end if","ENDIF");
-         global_substitute(line,"end ","END ");    // Modify "end" after all other strings containing "end..." are done!
-         global_substitute(line,"#ENDIF","#endif");
-         global_substitute(line,"function","FUNCTION");
-         global_substitute(line,"if(","IF (");
-         global_substitute(line," if "," IF ");
-         global_substitute(line,"implicit","IMPLICIT");
-         global_substitute(line,"include","INCLUDE");
-         global_substitute(line,"intent","INTENT");
-         global_substitute(line,"integer","INTEGER");
-         global_substitute(line,"logical","LOGICAL");
-         global_substitute(line,"module","MODULE");
-         global_substitute(line,"none","NONE");
-         global_substitute(line,"optional","OPTIONAL");
-         global_substitute(line,"parameter","PARAMETER");
-         global_substitute(line,"public","PUBLIC");
-         global_substitute(line,"real","REAL");
-         global_substitute(line,"return","RETURN");
-         global_substitute(line,"use ","USE ");
-         global_substitute(line,"save","SAVE");
-         global_substitute(line,"subroutine","SUBROUTINE");
-         global_substitute(line,"then","THEN");
-         global_substitute(line,"while","WHILE");
-       }
+         }
      }
 
@@ -167,6 +153,5 @@
 //  Update_RCONST has only to be called once per outer timeloop in KPP_FOR_PALM
 
-//  if(ip->get_token(0) == "CALL" && ip->get_token(1) == "Update_RCONST" ) {
-    if(ip->get_token(0) == "CALL" && ip->get_token(1) == "update_rconst" ) {
+    if(ip->get_token(0) == "CALL" && ip->get_token(1) == "Update_RCONST" ) {
       lo_line.insert(0,"!DELETE ");
     cout << lo_line << endl;
@@ -175,6 +160,12 @@
 //  Update_SUN must not be called within in KPP_FOR_PALM
 
-//  if(ip->get_token(0) == "CALL" && ip->get_token(1) == "Update_SUN" ) {
-    if(ip->get_token(0) == "CALL" && ip->get_token(1) == "update_sun" ) {
+    if(ip->get_token(0) == "CALL" && ip->get_token(1) == "Update_SUN" ) {
+      lo_line.insert(0,"!DELETE ");
+    cout << lo_line << endl;
+    }
+
+//  Remove "    var(i) = x"  (Make sure  that var does not occur as first token anywhere else)
+
+    if(ip->get_token(0) == "VAR") {
       lo_line.insert(0,"!DELETE ");
     cout << lo_line << endl;
@@ -338,4 +329,93 @@
     }
 
+//  Remove  REAL(kind=dp):: sun
+
+    if(ip->get_token_number_from_string("SUN") > 0) {
+      lo_line.insert(0,"!DELETE ");
+    cout << lo_line << endl;
+    }
+
+//  Remove    INTEGER :: ddmtype
+
+    if(ip->get_token_number_from_string("DDMTYPE") > 0) {
+    cout << lo_line << endl;
+      lo_line.insert(0,"!DELETE ");
+    cout << lo_line << endl;
+    }
+
+//  Remove    REAL(kind=dp) :: dt
+
+    if(ip->get_token_number_from_string("DT") > 0) {
+    cout << lo_line << endl;
+      lo_line.insert(0,"!DELETE ");
+    cout << lo_line << endl;
+    }
+
+//  Remove    LOOKAT
+
+    if(ip->get_token_number_from_string("LOOKAT") > 0) {
+    cout << lo_line << endl;
+      lo_line.insert(0,"!DELETE ");
+    cout << lo_line << endl;
+    }
+
+//  Remove    NLOOKAT
+
+    if(ip->get_token_number_from_string("NLOOKAT") > 0) {
+    cout << lo_line << endl;
+      lo_line.insert(0,"!DELETE ");
+    cout << lo_line << endl;
+    }
+
+//  Remove    MONITOR
+
+    if(ip->get_token_number_from_string("MONITOR") > 0) {
+    cout << lo_line << endl;
+      lo_line.insert(0,"!DELETE ");
+    cout << lo_line << endl;
+    }
+
+//  Remove    NMONITOR
+
+    if(ip->get_token_number_from_string("NMONITOR") > 0) {
+    cout << lo_line << endl;
+      lo_line.insert(0,"!DELETE ");
+    cout << lo_line << endl;
+    }
+
+//  Remove    SMASS
+
+    if(ip->get_token_number_from_string("SMASS") > 0) {
+    cout << lo_line << endl;
+      lo_line.insert(0,"!DELETE ");
+    cout << lo_line << endl;
+    }
+
+//  Remove    RTOLS
+
+    if(ip->get_token_number_from_string("RTOLS") > 0) {
+    cout << lo_line << endl;
+      lo_line.insert(0,"!DELETE ");
+    cout << lo_line << endl;
+    }
+
+//  Remove    TEND
+
+    if(ip->get_token_number_from_string("TEND") > 0) {
+    cout << lo_line << endl;
+      lo_line.insert(0,"!DELETE ");
+    cout << lo_line << endl;
+    }
+
+//  Remove    STEPMAX
+
+    if(ip->get_token_number_from_string("STEPMAX") > 0) {
+    cout << lo_line << endl;
+      lo_line.insert(0,"!DELETE ");
+    cout << lo_line << endl;
+    }
+
+
+
 //  Make ind_ variables public
     if(ip->get_token(3).substr(0,4) == "ind_") {
@@ -464,8 +544,16 @@
        to_do = false;
     }
-    if(ip->get_token(0).substr(0,1) != "!" && ip->get_token_number_from_string("temp") > 2) {
-//  if(ip->get_token(0).substr(0,1) != "!" && ip->get_token_number_from_string("XXXX") > 2) {
-      todo_1 = true;
-    }
+    if(kpp_switches.is_vector()) {
+       if(ip->get_token(0).substr(0,1) != "!" && ip->get_token_number_from_string("TEMP") > 2) {
+         todo_1 = true;
+       }
+       if(ip->get_token(0).substr(0,1) != "!" && ip->get_token_number_from_string("QVAP") > 2) {
+         todo_1 = true;
+       }
+       if(ip->get_token(0).substr(0,1) != "!" && ip->get_token_number_from_string("FAKT") > 2) {
+         todo_1 = true;
+       }
+    }
+
     if(to_do || todo_1) {
       if(ip->get_token(0).substr(0,1) == "!") continue;       // skip comment limes
@@ -499,19 +587,24 @@
       cout << "Vector variable " << ip->get_token(pos+1) <<" " << vari.nr_dim() <<endl;
       lo_line = ip->get_line() ;
-      if(vari.nr_dim() == 0) {
-        lo_line.clear();
-        lo_line = "  REAL(dp),dimension(:),allocatable             :: " + vari.name;
-      }
-      if(vari.nr_dim() == 1) {
-        lo_line.clear();
-        lo_line = "  REAL(dp),dimension(:,:),allocatable           :: " + vari.name;
-      }
-      if(vari.nr_dim() == 2) {
-        lo_line.clear();
-        lo_line = "  REAL(dp),dimension(:,:,:),allocatable         :: " + vari.name;
-      }
-      if(vari.nr_dim() == 3) {
-        lo_line.clear();
-        lo_line = "  REAL(dp),dimension(:,:,:,:),allocatable       :: " + vari.name;
+      if(todo_1)   {
+          lo_line.clear();
+          lo_line = "  REAL(dp),dimension(VL_DIM)                  :: " + vari.name;
+      } else {
+         if(vari.nr_dim() == 0) {
+           lo_line.clear();
+           lo_line = "  REAL(dp),dimension(:),allocatable             :: " + vari.name;
+         }
+         if(vari.nr_dim() == 1) {
+           lo_line.clear();
+           lo_line = "  REAL(dp),dimension(:,:),allocatable           :: " + vari.name;
+         }
+         if(vari.nr_dim() == 2) {
+           lo_line.clear();
+           lo_line = "  REAL(dp),dimension(:,:,:),allocatable         :: " + vari.name;
+         }
+         if(vari.nr_dim() == 3) {
+           lo_line.clear();
+           lo_line = "  REAL(dp),dimension(:,:,:,:),allocatable       :: " + vari.name;
+         }
       }
       ip->set_line(lo_line);
@@ -541,5 +634,7 @@
 
   vector<program_line>::iterator     ip;
+  program_line                    pl;
   string                             lo_line;
+  string                             line;
 
   for (ip=pline.begin(); ip != pline.end(); ip++) {
@@ -555,6 +650,6 @@
     ip->global_substitute("* ","*");
     ip->global_substitute("* ","*");
-    ip->global_substitute("d- ","d-");
-    ip->global_substitute("d+ ","d+");
+//  ip->global_substitute("d- ","d-");
+//  ip->global_substitute("d+ ","d+");
     ip->global_substitute(", ",",");
     ip->global_substitute(")=",") =");
@@ -562,9 +657,108 @@
     ip->global_substitute(", - ",", -");
 
+// Now do some cosmetics to adapt the KPP generated output a bit o the looks of PALM, 
+// i.e. add some blanks, convert all to lowercase except Fortran language elements, etc.
+//  Replace Roundoff = WLAMCH('E') by Roundoff = epsilon(one)
+       ip->global_substitute("Roundoff = WLAMCH('E')","roundoff = epsilon(one)");
+       lo_line = ip->get_line();
+       if(lo_line.find("'",0) == string::npos)  {     // No substitution in line with strings
+        if(lo_line.substr(0,2) =="! ") {
+         ip->global_substitute("#","#");      // just a dummy so comments do not get lost
+         } else {
+//       cout << "HIER0 " << lo_line <<endl;
+//       global_substitute(lo_line,"("," ( ");
+//       global_substitute(lo_line,")"," ) ");
+         global_substitute(lo_line,",",", ");
+         global_substitute(lo_line,",  ",", ");
+         global_substitute(lo_line,")  ",") ");
+         global_substitute(lo_line,"*","* ");
+         global_substitute(lo_line,"* *","**");
+         global_substitute(lo_line,")+",") +");
+         global_substitute(lo_line,")-",") -");
+         global_substitute(lo_line,")/",") /");
+         global_substitute(lo_line,")*",") *");
+         global_substitute(lo_line,")=",") =");
+//       global_substitute(lo_line,"-","- ");
+         global_substitute(lo_line,"-  ","- ");
+         global_substitute(lo_line,"+","+ ");
+         global_substitute(lo_line,"+  ","+ ");
+         global_substitute(lo_line,"=- ","= -");
+         global_substitute(lo_line,"/JVS","/ JVS");
+         global_substitute(lo_line,"d- ","d-");
+         global_substitute(lo_line,"d+ ","d+");
+         global_substitute(lo_line,"D- ","D-");
+         global_substitute(lo_line,"D+ ","D+");
+         global_substitute(lo_line,"e- ","e-");
+         global_substitute(lo_line,"e+ ","e+");
+         global_substitute(lo_line,"E+ ","E+");
+         global_substitute(lo_line,"E- ","E-");
+         ip->global_subtolower(lo_line);
+         global_substitute(lo_line,"allocated","ALLOCATED");
+         global_substitute(lo_line,"allocatable","ALLOCATABLE");
+         global_substitute(lo_line,".and. ",".AND. ");
+         global_substitute(lo_line,"call ","CALL ");
+         global_substitute(lo_line,"case","CASE");
+         global_substitute(lo_line,"character","CHARACTER");
+         global_substitute(lo_line,"contains","CONTAINS");
+         global_substitute(lo_line,"deallocate","DEALLOCATE");
+         global_substitute(lo_line,"allocate","ALLOCATE");
+         global_substitute(lo_line,"dimension","DIMENSION");
+         global_substitute(lo_line,"do ","DO ");
+         global_substitute(lo_line,"elseif","ELSEIF");
+         global_substitute(lo_line,"else","ELSE");
+         global_substitute(lo_line,"#ELSE","#else");
+         global_substitute(lo_line,"end do","ENDDO");
+         global_substitute(lo_line,"end if","ENDIF");
+         global_substitute(lo_line,"endif","ENDIF");
+         global_substitute(lo_line,"endwhere","ENDWHERE");
+         global_substitute(lo_line,"end ","END ");    // Modify "end" after all other strings containing "end..." are done!
+         global_substitute(lo_line,"tEND","tend");
+         global_substitute(lo_line,"#ENDIF","#endif");
+         global_substitute(lo_line,"equivalence","EQUIVALENCE");
+         global_substitute(lo_line,"function","FUNCTION");
+         global_substitute(lo_line,"if(","IF (");
+         global_substitute(lo_line," if "," IF ");
+         global_substitute(lo_line,"implicit","IMPLICIT");
+         global_substitute(lo_line,"include","INCLUDE");
+         global_substitute(lo_line,"intent","INTENT");
+         global_substitute(lo_line,"integer","INTEGER");
+         global_substitute(lo_line,"interface","INTERFACE");
+         global_substitute(lo_line,"logical","LOGICAL");
+         global_substitute(lo_line,"module","MODULE");
+         global_substitute(lo_line,"none","NONE");
+         global_substitute(lo_line,"only","ONLY");
+         global_substitute(lo_line,"optional","OPTIONAL");
+         global_substitute(lo_line,"parameter","PARAMETER");
+         global_substitute(lo_line,"present","PRESENT");
+         global_substitute(lo_line,"private","PRIVATE");
+         global_substitute(lo_line,"procedure","PROCEDURE");
+         global_substitute(lo_line,"public","PUBLIC");
+         global_substitute(lo_line,"real","REAL");
+         global_substitute(lo_line,"return","RETURN");
+         global_substitute(lo_line,"use ","USE ");
+         global_substitute(lo_line,"save","SAVE");
+         global_substitute(lo_line,"subroutine","SUBROUTINE");
+         global_substitute(lo_line,"then","THEN");
+         global_substitute(lo_line,"where","WHERE");
+         global_substitute(lo_line,"while","WHILE");
+         global_substitute(lo_line,".false.",".FALSE.");
+         global_substitute(lo_line,".true.",".TRUE.");
+         global_substitute(lo_line,"(in)","(IN)");
+         global_substitute(lo_line,"(out)","(OUT)");
+         global_substitute(lo_line,"(inout)","(INOUT)");
+         global_substitute(lo_line,"\t","      ");
+//       cout << "HIER1 " << lo_line <<endl;
+       }
+     }
+//   pl.set_line(lo_line);
+//   pline.push_back(pl);
+
+
 //  line break if more than 130 character
 
-    lo_line = ip->get_line();
+//  lo_line = ip->get_line();
     if( lo_line.size() < 130 ) {
-      out << ip->get_line() <<endl;
+//    out << ip->get_line() <<endl;
+      out <<  lo_line    <<endl;
     } else {
       int cp  = lo_line.rfind("!",129);
Index: palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/fortran_file.h
===================================================================
--- palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/fortran_file.h	(revision 2768)
+++ palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/fortran_file.h	(revision 3298)
@@ -12,6 +12,16 @@
 // ############################################################################
 //
-//  Modifications:
-//    RFo added global_subtolower
+//Current revisions:
+//------------------
+/ 
+/ 
+//Former revisions:
+//-----------------
+// Nov 2016: Intial version of KP4 adapted to PALM (Klaus Ketelsen)
+//  forkel Sept.2018:  added edit_Initialize
+//  forkel          :  added global_subtolower
+//
+/ Intial version of KP4
+
 
 #include <iostream>
@@ -42,6 +52,10 @@
   void edit_KppSolve () ;
   void edit_Fun () ;
+  void edit_WAXPY () ;
+  void edit_FunTemplate () ;
+  void edit_JacTemplate () ;
   void edit_FUNC () ;
   void edit_Update_RCONST (vector <Vvar> &var_list) ;
+  void edit_Initialize (vector <Vvar> &var_list) ;
   void edit_inc (fortran_file & header_var) ;
   void create_species_list(vector <string> &species_list);
Index: palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/fortran_file_vec.C
===================================================================
--- palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/fortran_file_vec.C	(revision 2768)
+++ palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/fortran_file_vec.C	(revision 3298)
@@ -9,4 +9,21 @@
 //
 // ############################################################################
+//Current revisions:
+//------------------
+/ 
+/ 
+//Former revisions:
+//-----------------
+//$Id: fortran_file.C 2470 2017-09-14 13:56:42Z forkel $
+//  ketelsen 18.09.2018: Line 112: do k=is,ie bydo k=1,vl; line 156 ff: replaced index k by j
+//
+//  forkel Sept.2018:  added edit_Initialize
+//                     changed loop direction for update_rconst in edit_Update_RCONST
+/ 2017-09-14 13:56:42Z forkel $
+//
+//
+// Nov 2016: Intial version of KP4 adapted to PALM (Klaus Ketelsen)
+//
+
 
 #include <fstream>
@@ -77,8 +94,19 @@
     }
   }
+
+  for (ip=pline.begin(); ip != pline.end(); ip++) {
+      if(kpp_switches.is_vector() ) {
+    	  ip->global_substitute ("phot (","phot(j,");
+      }
+  }
+
   ip = pline.begin()+1 ;
   lo_line = ip->get_line() ;
   lo_line.erase();
-  lo_line = " INTEGER         :: j,k";
+  if(kpp_switches.is_vector() ) {
+    lo_line = " INTEGER         :: j,k";
+  } else {
+    lo_line = " INTEGER         :: k";
+  }
   ip->set_line(lo_line);
   
@@ -87,5 +115,5 @@
     lo_line = ip->get_line() ;
     lo_line.erase();
-    lo_line = " do k=is,ie";
+    lo_line = " do k=1,vl";
     ip->set_line(lo_line);
 
@@ -93,5 +121,5 @@
     lo_line = ip->get_line() ;
     lo_line.erase();
-    lo_line = "  j = k-is+1";
+    lo_line = "  j = k";
     ip->set_line(lo_line);
 
@@ -103,4 +131,68 @@
   } else {
     ip = pline.begin()+3 ;
+    lo_line = ip->get_line() ;
+    lo_line.erase();
+    lo_line = "  k = is";
+    ip->set_line(lo_line);
+  }
+
+  return;
+}
+
+void fortran_file::edit_Initialize (vector <Vvar> &var_list) {
+  vector<program_line>::iterator     ip;
+  vector<Vvar>::iterator             iv;
+  string                             lo_line;
+
+  for (ip=pline.begin(); ip != pline.end(); ip++) {
+    ip->global_substitute ("*"," *");
+    ip->global_substitute ("* *","**");
+    ip->global_substitute (","," , ");
+    ip->global_substitute ("/"," / ");
+    ip->global_substitute ("1:VL","j");
+  }
+  for (ip=pline.begin(); ip != pline.end(); ip++) {
+    for (iv=var_list.begin(); iv != var_list.end(); iv++) {
+      ip->change_variable_to_vector_g (*iv);
+    }
+  }
+
+  for (ip=pline.begin(); ip != pline.end(); ip++) {
+    if(kpp_switches.is_vector() ) {
+          ip->global_substitute ("qvap","qvap(j)");
+    }
+  }
+  for (ip=pline.begin(); ip != pline.end(); ip++) {
+    if(kpp_switches.is_vector() ) {
+          ip->global_substitute ("fakt","fakt(j)");
+    }
+  }
+
+  ip = pline.begin()+3 ;
+  lo_line = ip->get_line() ;
+  lo_line.erase();
+  lo_line = "  INTEGER         :: j,k";
+  ip->set_line(lo_line);
+
+  if(kpp_switches.is_vector() ) {
+    ip = pline.begin()+9 ;
+    lo_line = ip->get_line() ;
+    lo_line.erase();
+    lo_line = " do k = is,ie";
+    ip->set_line(lo_line);
+
+    ip = pline.begin()+10 ;
+    lo_line = ip->get_line() ;
+    lo_line.erase();
+    lo_line = "  j = k - is +1";
+    ip->set_line(lo_line);
+
+    ip = pline.end()-2 ;
+    lo_line = ip->get_line() ;
+//  lo_line.erase();
+    lo_line = " end do";
+    ip->set_line(lo_line);
+  } else {
+    ip = pline.begin()+7 ;
     lo_line = ip->get_line() ;
     lo_line.erase();
@@ -236,2 +328,73 @@
 }
 
+void fortran_file::edit_WAXPY () {
+
+  vector<program_line>::iterator     ip;
+
+  cout << "Handling subroutine: WAXPY" <<endl;
+
+  for (ip=pline.begin(); ip != pline.end(); ip++) {
+
+    if(ip->get_token(0) == "REAL") {
+       ip->substitute("N",":,:");
+       ip->substitute("N",":,:");
+       ip->substitute("Alpha","Alpha(:)");
+    } else {
+        ip->change_variable_to_vector ("Y");
+        ip->change_variable_to_vector ("X");
+        if(ip->get_token(0) != "SUBROUTINE") {
+        	if(ip->get_token(0) == "IF")  {
+        		ip->substitute("Alpha","SUM(alpha(1:VL))");
+        	} else {
+        		ip->substitute("Alpha","alpha(1:VL)");
+        	}
+        }
+    }
+
+
+  }
+
+  return;
+}
+
+void fortran_file::edit_FunTemplate () {
+
+  vector<program_line>::iterator     ip;
+
+  cout << "Handling subroutine: FunTemplate" <<endl;
+
+  for (ip=pline.begin(); ip != pline.end(); ip++) {
+
+    if(ip->get_token(0) == "REAL") {
+       ip->substitute("NVAR",":,:");
+       ip->substitute("T,","T(:),");
+       ip->substitute("Told","Told(size(T)),Time(size(T))");
+    }
+
+
+  }
+
+  return;
+}
+
+void fortran_file::edit_JacTemplate () {
+
+  vector<program_line>::iterator     ip;
+
+  cout << "Handling subroutine: JacTemplate" <<endl;
+
+  for (ip=pline.begin(); ip != pline.end(); ip++) {
+
+    if(ip->get_token(0) == "REAL") {
+        ip->substitute("NVAR",":,:");
+        ip->substitute("T,","T(:),");
+        ip->substitute("Told","Told(size(T)),Time(size(T))");
+        ip->substitute("LU_NONZERO",":,:");
+    }
+
+
+  }
+
+  return;
+}
+
Index: palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/program_line.C
===================================================================
--- palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/program_line.C	(revision 2768)
+++ palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/program_line.C	(revision 3298)
@@ -134,3 +134,17 @@
   return;
 }
+void   program_line::global_subtolower(string &line) {
 
+   int start = line.size()-1;
+   char c;
+
+    int i = 0;
+    while (line[i])
+    {
+      c = line[i];
+      line[i] = tolower(c);
+      i++;
+    }
+   return;
+}
+
Index: palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/program_line.h
===================================================================
--- palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/program_line.h	(revision 2768)
+++ palm/trunk/UTIL/chemistry/gasphase_preproc/kpp4palm/src/program_line.h	(revision 3298)
@@ -11,4 +11,6 @@
 //
 // ############################################################################
+//
+// forkel June 2018: added    void   global_subtolower(string &line);
 
 #include <iostream>
@@ -42,4 +44,5 @@
    void   change_variable_to_vector    (string var);
    void   change_variable_to_vector_g  (Vvar  &var);
+   void   global_subtolower(string &line);
 };
 
