CCS Modul   R_ARRAY_WERT
 
   $Id: r_array_wert.C,v 1.18 2005/09/28 13:50:37 cvs Exp $
   ---------------------------------------------------------------------
   Kurzbeschreibung: 	lesen/schreiben eine Feldelementes
   ---------------------------------------------------------------------
   Projekt:		CCS
   Sourcefile:		r_array_wert.C
   Autor:			RtW/TEF72-Juilfs (20.10.2001)
   Zielsystem:		HP9000/V743 (HP-RT 2.0x), /Sxxx (HP-UX 9.0x)
   Sprache:		C++ 
   ---------------------------------------------------------------------
   Prototyp:
   MPI Schnittstelle
   void r_array_wert(
	   ,shm_stringpointer   *zeilen_wert 
	   ,long index1
	   ,long anzahl)
   
   ---------------------------------------------------------------------
   Aufruf: im Vectorinterpreter
   
	 (*funktionen[modulnummer])
	    (Ssp_expand_zeile
	     ,Ssp_expand_wert
	     ,p_verwaltung->begin_modulblock
	     ,p_verwaltung->anzahl_modulparameter);

   ---------------------------------------------------------------------
   Funktionsbeschreibung:
   Über dieses Modul kann der Wert eines Feldelementes gelesen bzw. 
   beschrieben werden.
   
   Beschreibung der Modulübergabeparameter:
1 PRUEFSCHRITT
   GAUDI Prüfschritt
   ------------------------------
2 POSITION
   PAV- Position
   ------------------------------
3 ARRAY_MODE
   R = lesen  eines Feldelementes
   W = setzen eines Feldelementes
   
   Hinweis zu String-Feldern:
   Modus "R" bei String-Feldern nicht moeglich; hier ist das Modul P_ZERLEGE_STR 
   einzusetzen. Der Grund hierfuer liegt darin, dass in diesem Modul kein Bereich
   fuer Strings angegeben werden kann.
   Im Mode "W" bei String-Feldern wird der komplette Inhalt der uebergebenen Variablen
   ab der Stelle, die mit ARRAY_INDEX bezeichnet ist, eingefuegt. Sind Feld-Elemente 
   vor dem einzufuegendem Element nicht belegt, so werden diese mit dem Wert "F" 
   belegt!
   ------------------------------
4 ARRAY
   Variablen Name		
   ------------------------------
5 ARRAY_INDEX
   Feldinindex auf das Feldelement das gelesen bzw. beschrieben werden soll.
   Der Index beginnt bei 1
   ------------------------------
6 ERGEBNIS
   Wert der gelesen wurde (R Mode)
   Wert mit dem ein Feldelement belegt werden soll (W Mode)
   ------------------------------
7 FEHLERFLAG
   Fehlerflag 
   <userdoc>
   ---------------------------------------------------------------------

-- pragmas -----------------------------------------------------------
#pragma  COPYRIGHT "Robert Bosch GmbH Reutlingen, RtW/TEF72"
#pragma  VERSIONID "$Id: r_array_wert.C,v 1.18 2005/09/28 13:50:37 cvs Exp $"

-- defines -----------------------------------------------------------
#define HEADER "$Id: r_array_wert.C,v 1.18 2005/09/28 13:50:37 cvs Exp $" 
#define EXTERN extern	 Bei allen Subroutinen 

#define IND_PRUEFSCHRITT	1
#define IND_MODE  		3
#define IND_ARRAY		4
#define IND_ARRAY_INDEX		5
#define IND_WERT		6
#define IND_FEHLERFLAG		7
-- includes ----------------------------------------------------------
#include "shm_syscom.H"
#include <stdlib.h> 
#include <string.h>  
#include "libstr.H"  
#include "libccs.H"
#include "ccl_defines.H"         ccl_definition   PREINT              
#include <math.h>
#include "libtestmodul_pool.H"	// Modul Lib

-- external functions / variables ------------------------------------
long round_wert(double wert_d, STRING rundungsart, STRING &ergebnis );
-- global variables (nur im  "main" erlaubt) -------------------------
 -Begin---------------------------------------------------------------
   ---------------------------------------------------------------------

//#define test_ra
#ifdef test_ra
void xxx(shm_stringpointer *zeilen_wert
	   ,long index1
	   ,long anzahl)
{
   int			i;
   int    		ind;
   bool			bOk;
   STRING   		w_hilf;
   QString   		w_strHilf;
   char   		w_szHilf[1000];
   STRING   		r_hilf;
   QString   		r_strHilf;
   char   		r_szHilf[1000];
   Variablenverwaltung	*v_address;   
   
   ind       = index1 - 1;
   v_address = (Variablenverwaltung *)(zeilen_wert->ptr[ind+IND_ARRAY]); 

   r_strHilf = "W";
   r_hilf    = "W";
   if (*zeilen_wert->ptr[ind+IND_MODE] == "W")
      cout<<"== W  true"<<endl;
   else
      cout<<"== W  false"<<endl;
   if (*zeilen_wert->ptr[ind+IND_MODE] == (const char*)r_strHilf)
      cout<<"== W  true"<<endl;
   else
      cout<<"== W  false"<<endl;
   if (*zeilen_wert->ptr[ind+IND_MODE] == r_hilf)
      cout<<"== W  true"<<endl;
   else
      cout<<"== W  false"<<endl;
   
   if (*zeilen_wert->ptr[ind+IND_MODE] != "W")
      cout<<"!= W  true"<<endl;
   else
      cout<<"!= W  false"<<endl;
   if (*zeilen_wert->ptr[ind+IND_MODE] != (const char*)r_strHilf)
      cout<<"!= W  true"<<endl;
   else
      cout<<"!= W  false"<<endl;
   if (*zeilen_wert->ptr[ind+IND_MODE] != r_hilf)
      cout<<"!= W  true"<<endl;
   else
      cout<<"!= W  false"<<endl;
   
   w_strHilf = "";
   for (i = 0; i < 8; i++)
      w_strHilf += "1234567890";
   strcpy(w_szHilf,w_strHilf.latin1());
   w_hilf = w_strHilf;
   
   cout<<"1. kurzer Wert setzen QSTRING "<<endl;
   w_strHilf[0] = 'A';
   v_address->put_wert(w_strHilf);
   v_address->get_wert(r_hilf);
   cout<<"   read Wert STRING: "<<(char*)r_hilf<<endl;
   v_address->get_wert(r_strHilf);
   cout<<"   read Wert QSTRING: "<<(const char*)r_strHilf<<endl;
   strcpy(r_szHilf, *zeilen_wert->ptr[ind+IND_ARRAY]);
   cout<<"   read Wert Zuweisung: "<<(const char*)r_szHilf<<endl;
   
   cout<<"2. kurzer Wert setzen const char "<<endl;
   w_szHilf[0] = 'B';
   v_address->put_wert(w_szHilf);
   v_address->get_wert(r_hilf);
   cout<<"   read Wert STRING: "<<(char*)r_hilf<<endl;
   v_address->get_wert(r_strHilf);
   cout<<"   read Wert QSTRING: "<<(const char*)r_strHilf<<endl;
   strcpy(r_szHilf, *zeilen_wert->ptr[ind+IND_ARRAY]);
   cout<<"   read Wert Zuweisung: "<<(const char*)r_szHilf<<endl;
   
   cout<<"3. kurzer Wert setzen Zusweisung const char*"<<endl;
   w_szHilf[0] = 'C';
   *zeilen_wert->ptr[ind+IND_ARRAY] = w_szHilf;
   v_address->get_wert(r_hilf);
   cout<<"   read Wert STRING: "<<(char*)r_hilf<<endl;
   v_address->get_wert(r_strHilf);
   cout<<"   read Wert QSTRING: "<<(const char*)r_strHilf<<endl;
   strcpy(r_szHilf, *zeilen_wert->ptr[ind+IND_ARRAY]);
   cout<<"   read Wert Zuweisung: "<<(const char*)r_szHilf<<endl;

   cout<<"4. kurzer Wert setzen Zusweisung const char*"<<endl;
   w_strHilf[0] = 'D';
   *zeilen_wert->ptr[ind+IND_ARRAY] = w_strHilf;
   v_address->get_wert(r_hilf);
   cout<<"   read Wert STRING: "<<(char*)r_hilf<<endl;
   v_address->get_wert(r_strHilf);
   cout<<"   read Wert QSTRING: "<<(const char*)r_strHilf<<endl;
   strcpy(r_szHilf, *zeilen_wert->ptr[ind+IND_ARRAY]);
   cout<<"   read Wert Zuweisung: "<<(const char*)r_szHilf<<endl;

   cout<<"5. kurzer Wert setzen Zusweisung STRING"<<endl;
   w_hilf[0] = 'E';
   *zeilen_wert->ptr[ind+IND_ARRAY] = w_hilf;
   v_address->get_wert(r_hilf);
   cout<<"   read Wert STRING: "<<(char*)r_hilf<<endl;
   v_address->get_wert(r_strHilf);
   cout<<"   read Wert QSTRING: "<<(const char*)r_strHilf<<endl;
   strcpy(r_szHilf, *zeilen_wert->ptr[ind+IND_ARRAY]);
   cout<<"   read Wert Zuweisung: "<<(const char*)r_szHilf<<endl;

   cout<<"6. kurzer Wert setzen STRING "<<endl;
   w_hilf[0] = 'F';
   v_address->put_wert(w_hilf);
   v_address->get_wert(r_hilf);
   cout<<"   read Wert STRING: "<<(char*)r_hilf<<endl;
   v_address->get_wert(r_strHilf);
   cout<<"   read Wert QSTRING: "<<(const char*)r_strHilf<<endl;
   strcpy(r_szHilf, *zeilen_wert->ptr[ind+IND_ARRAY]);
   cout<<"   read Wert Zuweisung: "<<(const char*)r_szHilf<<endl;
      
   if (v_address->isArrayVariable())
   {
      w_strHilf = "";
      for (i = 0; i < 10; i++)
         w_strHilf += "1234567890";
      strcpy(w_szHilf,w_strHilf.latin1());
      
      cout<<"7. langer Wert setzen QSTRING "<<endl;
      w_strHilf[0] = 'G';
      v_address->put_wert(w_strHilf);
      v_address->get_wert(r_strHilf);
      cout<<"   read Wert QSTRING: "<<(const char*)r_strHilf<<endl;
      strcpy(r_szHilf, *zeilen_wert->ptr[ind+IND_ARRAY]);
      cout<<"   read Wert Zuweisung: "<<(const char*)r_szHilf<<endl;
      
      cout<<"8. langer Wert setzen const char "<<endl;
      w_szHilf[0] = 'H';
      v_address->put_wert(w_szHilf);
      v_address->get_wert(r_strHilf);
      cout<<"   read Wert QSTRING: "<<(const char*)r_strHilf<<endl;
      strcpy(r_szHilf, *zeilen_wert->ptr[ind+IND_ARRAY]);
      cout<<"   read Wert Zuweisung: "<<(const char*)r_szHilf<<endl;
      
      cout<<"9. langer Wert setzen Zusweisung const char*"<<endl;
      w_szHilf[0] = 'I';
      *zeilen_wert->ptr[ind+IND_ARRAY] = w_szHilf;
      v_address->get_wert(r_strHilf);
      cout<<"   read Wert QSTRING: "<<(const char*)r_strHilf<<endl;
      strcpy(r_szHilf, *zeilen_wert->ptr[ind+IND_ARRAY]);
      cout<<"   read Wert Zuweisung: "<<(const char*)r_szHilf<<endl;

      cout<<"10. langer Wert setzen Zusweisung qstring "<<endl;
      w_strHilf[0] = 'J';
      *zeilen_wert->ptr[ind+IND_ARRAY] = w_strHilf;
      v_address->get_wert(r_strHilf);
      cout<<"   read Wert QSTRING: "<<(const char*)r_strHilf<<endl;
      strcpy(r_szHilf, *zeilen_wert->ptr[ind+IND_ARRAY]);
      cout<<"   read Wert Zuweisung: "<<(const char*)r_szHilf<<endl;
   }
}
#endif





int r_array_wert(shm_stringpointer *zeilen_wert
	   ,long index1
	   ,long anzahl)
{

-- local variables --------------------------------------------------- 
   int			loop1;
   int			laenge_eingabe;
   int			laenge_gesamt;

   varmem_typen		dat_in;		// Feldpointer auf die Daten
   long			ind;			// index 
   long			ind_wert;		// index auf den Wert
   long			ind_wert_ext;	// externer index auf den Wert
   long			Anzahl;			// Anzahl
   long			MaxAnzahl;		// maximale Anzahl
   STRING		mode;			// Modus
   STRING		name;			// name der Variablen
   long			schritt;		// Schritt
   long			typ;			// Datenfeldtyp
   Variablenverwaltung	*v_array;   	// Variablenpointer 
   long			erg;		// ergebnis funktion

   //------------------------------------------------------------------
   // Schrittbetriebshandler
   // Dieser kann je nach ModulfunktionalitÌt auch im Modul
   // spÌter aufgerufen werden
   //------------------------------------------------------------------ 
   
   ind = index1 - 1;
   *zeilen_wert->ptr[ind + IND_FEHLERFLAG] = "0"; 

   schritt = schrittbetrieb(zeilen_wert,index1);   
   if(schritt!=1) return 0; 
   if (*zeilen_wert->ptr[ind+IND_MODE] == "R")  
   {
    if(strcmp(Ssp_vi->job.liststate,PREINT)==0) return 0; 
   }
   // Abfrage ob im Rüstlauf der Index 0 übergeben wird (&Variable) dann darf die funktion nicht durchlaufen werden  
   if(strcmp(Ssp_vi->job.liststate,PREINT)==0  ) 
   {
     ind_wert_ext = atoi((const char*)*zeilen_wert->ptr[ind+IND_ARRAY_INDEX]);
     if(ind_wert_ext<=0) return 0;
   }  
#ifdef test_ra
   xxx(zeilen_wert, index1, anzahl);
   return 0;
#endif

   v_array = (Variablenverwaltung *)zeilen_wert->ptr[ind + IND_ARRAY]; 
   v_array->get_name(name);
   if (!v_array->mem_getpoi (dat_in, typ, Anzahl, MaxAnzahl))
   {  
      error_message (ERR_ERROR_TTNR, HEADER,__LINE__,
         "variable: %s is not a array", (char*)name );
      return -1;
   }
   // externer Index beginnt bei 1, interner bei 0
   ind_wert_ext = atoi((const char*)*zeilen_wert->ptr[ind+IND_ARRAY_INDEX]);
   ind_wert     = ind_wert_ext - 1;
//cout<<"ind_wert: "<<ind_wert<<" Anzahl: "<<Anzahl<<" MaxAnzahl: "<<MaxAnzahl<<endl;
   if (*zeilen_wert->ptr[ind+IND_MODE] == "R")
   {
      erg = 0;
      if ((ind_wert < 0) || (ind_wert >= Anzahl))
      {
	 error_message (ERR_ERROR_TTNR, HEADER,__LINE__,
            "illegal index: %d there are only %d elements", ind_wert_ext, Anzahl );
	 return -1;
      }
      if (typ == VARMEM_TYP_BYTE)
      {
         int		iValue;
         QString 	strNum;
         
         iValue = (unsigned char)dat_in.c[ind_wert];
         strNum.setNum(iValue);
         zeilen_wert->ptr[ind+IND_WERT]->put_wertTyp(strNum, typ);
      }
      else if (typ == VARMEM_TYP_INT)
      {
         char szHil[80];
	 sprintf(szHil, "%ld", dat_in.i[ind_wert]);
         zeilen_wert->ptr[ind+IND_WERT]->put_wertTyp(szHil, typ);
      }
      else if (typ == VARMEM_TYP_DOUBLE)
      {
         STRING	hil;
         erg = round_wert(dat_in.d[ind_wert], "0",  hil);
         zeilen_wert->ptr[ind+IND_WERT]->put_wertTyp(hil, typ);
      }
      else if (typ == VARMEM_TYP_STRING)
      {
         error_message (ERR_ERROR_TTNR, HEADER,__LINE__,
                   "Lesen des Feldes %s nur mit P_ZERLEGE_STR !!", (char*)name );
         return -1;
      }
      return erg;
   }
   else if (*zeilen_wert->ptr[ind+IND_MODE] == "W")
   {
      if ((ind_wert < 0) || (ind_wert >= MaxAnzahl))
      {
	 error_message (ERR_ERROR_TTNR, HEADER,__LINE__,
            "illegal index: %d max. array dimension: %d", ind_wert_ext, MaxAnzahl );
	 return -1;
      }
      if (typ == VARMEM_TYP_BYTE)
      {
         int 	iValue;
         
         iValue = atoi((const char*)*zeilen_wert->ptr[ind+IND_WERT]);
         if (iValue > 255)
         {
            error_message (ERR_ERROR_TTNR, HEADER,__LINE__,
               "value > 255: %i", iValue );
            iValue = 255;
         }
	 dat_in.c[ind_wert] = iValue;
         if (ind_wert >= Anzahl)
         {
             v_array->mem_setanzahl ( ind_wert+1 );
         }
      }
      else if (typ == VARMEM_TYP_INT)
      {
	 dat_in.i[ind_wert] = atoi((const char*)*zeilen_wert->ptr[ind+IND_WERT]);
         if (ind_wert >= Anzahl)
         {
             v_array->mem_setanzahl ( ind_wert+1 );
         }
      }
      else if (typ == VARMEM_TYP_DOUBLE)
      {
	 dat_in.d[ind_wert] = atof((const char*)*zeilen_wert->ptr[ind+IND_WERT]);
//printf("ind_wert: %d offset: %d\n",ind_wert,xx);
         if (ind_wert >= Anzahl)
         {
             v_array->mem_setanzahl ( ind_wert+1 );
         }
      }
      else if (typ == VARMEM_TYP_STRING)
      {
         laenge_eingabe = strlen((const char *)*zeilen_wert->ptr[ind+IND_WERT]);
         laenge_gesamt = laenge_eingabe + ind_wert;
         
         if (laenge_gesamt > MaxAnzahl)
         {
              error_message (ERR_ERROR_TTNR, HEADER,__LINE__,
                "illegal index: Var %s has %d Digits, max. array dimension: %d",(char*)name, ind_wert+laenge_eingabe, MaxAnzahl );
               return -1;
         }
         debug_message (__FILE__,__LINE__,DEB_DATA,
             " Feld %s hat Inhalt %s vor schreiben und ist %i Zeichen lang",
                    (char*)name, dat_in.c, strlen(dat_in.c));
         if ( Anzahl <= ind_wert)       // Uebergabewert an Feld anhaengen
         {
               for (loop1=Anzahl; loop1<ind_wert; loop1++)
               {
                    str_cat(dat_in.c,"F",ind_wert+1);
               }  
               v_array->mem_setanzahl (ind_wert);            
               str_cat(dat_in.c, (const char *)*zeilen_wert->ptr[ind+IND_WERT],laenge_gesamt+1); 
               v_array->mem_setanzahl (laenge_gesamt); 
         } 
         else  if ( laenge_gesamt <=  Anzahl )  // vorhandenen Wert mit Uebergabewert ueberschreiben 
         {
              memmove(dat_in.c+ind_wert,(const char *)*zeilen_wert->ptr[ind+IND_WERT],laenge_eingabe);
         }
         else 
         {
              memmove(dat_in.c+ind_wert,(const char *)*zeilen_wert->ptr[ind+IND_WERT],laenge_eingabe);  
              v_array->mem_setanzahl (laenge_gesamt); 
         }
         debug_message (__FILE__,__LINE__,DEB_DATA,
             " Feld %s hat Inhalt %s nach schreiben und ist %i Zeichen lang",
                    (char*)name, dat_in.c, strlen(dat_in.c));
// cout << "Feld " << (char*)name  << " hat Inhalt " << dat_in.c << " und ist lang: " << strlen(dat_in.c) << endl;       
      }     
   }
   else
   {
      error_message (ERR_ERROR_TTNR, HEADER,__LINE__,
         "illegal mode: %s", (const char*)*zeilen_wert->ptr[ind+IND_MODE] );
      return -1;
   }

   return 0;
}
 -End of file---------------------------------------------------------
   Historie: