Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

...

06.2.3.1 "put" and "putSlice" functions

putputSlice


Code Block
languagecpp
titleIMAS C++ :: put
linenumberstrue
#include "UALClasses.h"
using namespace IdsNs;

int main(int argc, char *argv[])
{
int number = 10; //number of elements


    IDS::core_profiles ids;  // <= IDS object

    const char* treename = "ids";
    const char* database = "test";
    int shot = 13;
    int run = 22;
    char*  userName;
    char*  imasVersion;

    // Gets user name and data version
    userName = getenv("USER");
    imasVersion = getenv("IMAS_VERSION");

    //Create a new instance of database
   
 IdsNs::IDS imas(
123
shot, 
1
run, 
123
-1, -1);
    
imas.
create(
createEnv(userName, database, imasVersion);
   
IDS::core_profiles
 ids = imas._core_profiles;

    // Mandatory to define this property
    ids.ids_properties.homogeneous_time = 
1;
IDS_TIME_MODE_HOMOGENEOUS;

    ids.ids_properties.comment = "IDS stored by put (CPP)";

    // allocate the 
CPO
IDS structures
 - vector of size N
    ids.time.resize(
number
10);
    ids.global_quantities.ip.resize(
number
10);

//
 
Fill
 
IDS
 
time-independent
 
fields ids.ids_properties.comment = "IDS created by C++ PUT";
// Fill IDS time-dependent fields
 
    for(int i=0; i < 
number
10; i++)
    {
  
ids.x.y
      // Do not forget time!!
        ids.time(i) = 
VALUE(
i
)
;

        // 
Do
Setting 
not
values 
forget
of 
time!!   ids.time
data
        ids.global_quantities.ip(i) = 
TIME
2*i;
    }

    // Save data in the database
    
ids.put();

 
   // Close the pulse file
  
  imas.close();
}



Code Block
languagecpp
titleIMAS C++ :: putSlice
linenumberstrue
#include "UALClasses.h"
using namespace IdsNs;
 
int main(int argc, char *argv[])
{

    IDS::core_profiles ids;  // <= IDS object

    const char* treename = "ids";
    const char* database = "test";
    int shot = 13;
    int run = 22;
    char*  userName;
    char*  imasVersion;


    // Gets user name and data version
    userName = getenv("USER");
    imasVersion = getenv("IMAS_VERSION");

    //Create a new instance of database
    IdsNs::IDS imas(
12
shot, 
2
run, -1, -1);
 
   imas.
create(
createEnv(userName, database, imasVersion);
IDS::core_profiles
    ids = imas._core_profiles;

    //
!
 Mandatory to define this property
    ids.ids_properties.homogeneous_time = 
1;
IDS_TIME_MODE_HOMOGENEOUS;

//
 
Fill
 
IDS
 
time-independent
 
fields
ids.ids_properties.comment = "IDS 
created
stored by 
C++ PUT
putSlice (CPP)";
ids.putNonTimed();

     // 
Fill
allocate the IDS structures 
time-dependent fields
- vector of size 1
    ids.global_quantities.ip.resize(1);
 
   
ids.
global_quantities
time.
ip
resize(
0) = VALUE;
1);

    // Fill IDS time-dependent fields
    for(int i=0; i < 10; i++)
    {
        // Do not forget time!!
        ids.time
.resize
(
1
0) = i;
ids.time


        // Setting values of data
        ids.global_quantities.ip(0) = 
TIME
2*i;

        // Save data in the database
 

        if( i == 0)
            ids.put();
        else
            ids.putSlice();

    }

    // Close the pulse file
    
imas.close();
}

 



...

06.2.3.2 "get" and "getSlice" functions

getgetSlice


Code Block
languagecpp
titleIMAS C++ :: get
linenumberstrue
#include  <iostream>

#include "UALClasses.h"
using namespace IdsNs;

int main(int argc, char *argv[])
{
    IDS::core_profiles ids;  // <= IDS object

    const char* treename = "ids";
    const char* database = "test";
   
int number; //Open the database  
 int shot = 13;
    int run = 22;
    char*  userName;
    char*  imasVersion;


    // Gets user name and data version
    userName = getenv("USER");
    imasVersion = getenv("IMAS_VERSION");

    //Open database
    IdsNs::IDS imas(
12
shot, 
2
run, -1, -1);
    imas.
open(); //Open the database
openEnv(userName, database, imasVersion);
    
IdsNs::IDS::core_profiles
ids = imas._core_profiles;
ids.get();


   
number
 
=
ids.
time.extent
get(
0
);

   
for
 
(int j=0; j< number; j++) { printf(
cout << "Time: " << 
%g",
ids.time
(j))
 << endl;
    cout << 
printf(
"Value:
%g",
 " << ids.
x.y(j));
global_quantities.ip << endl;

    
}
// Close the pulse file
 imas
    imas.close();
}



Code Block
languagecpp
titleIMAS C++ :: getSlice
linenumberstrue
#include  <iostream>

#include "UALClasses.h"
using namespace IdsNs;

int main(int argc, char *argv[])
{

    IDS::core_profiles ids;  // <= IDS object

    const char* treename = "ids";
    const char* database = "test";
    int shot = 13;
    int run = 22;
    char*  userName;
    char*  imasVersion;


    // Gets user name and data version
    userName = getenv("USER");
    imasVersion = getenv("IMAS_VERSION");

    //Open 
the
database
    IdsNs::IDS imas(
12
shot, 
2
run, -1, -1);
   
 imas.
open(
openEnv(userName, database, imasVersion);

   
IDS::core_profiles
 ids = imas._core_profiles;

    
//Get the slice corresponding to the passed time
    ids.getSlice(
1
2.0, 2);
printf("Time %g",ids.time(0)); printf("Value: %g",ids.x.y(0));

    cout << "Time: " << ids.time << endl;
    cout << "Value: " << ids.global_quantities.ip << endl;

    // Close the pulse file
 
    imas.close();
}
}



Code Block
languagecpp
titleBuilding the code
linenumberstrue
CXX=g++
COPTS = -g `pkg-config imas-cpp --cflags`
LIBS =`pkg-config imas-cpp --libs`

all: ids_get.exe ids_put.exe ids_getSlice.exe ids_putSlice.exe

%.exe: %.cpp
$(CXX) $(COPTS) -o $@ $< $(LIBS)

clean:
rm -f *.o *.exe