1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
#include <iostream>
#include <string.h>
#include <vector>
#include <fstream>
#include <math.h>
using namespace std;
int main()
{
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Définition des variables et constantes
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int i,j;
const double J=24000;
const double L1= 8;
const double L2= 8;
const double l= 0.196;
const double dx = 0.001;
const double dy = 0.001;
const double S01=0.010;
const double S02=0.015;
const double S03=0.020;
double tabX[24000];
double tabY[196];
double tabZ[24000][196];
string nom_fichier;
const string chemin = "C://Users//anais//Desktop//STAGE GE4 HYDRO-INFO//";
const string extension = ".txt";
string dossier;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Corps du programme
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
i=0;
j=0;
// Calcul de la topographie du canal
// Boucle sur les X
for (i=0;i<=J;i++)
{
tabX[i]=tabZ[i-1][0]*dx+(dx/2);
if (tabX[i]<=L1)
{
tabZ[i][0]=tabZ[i-1][0]-S03;
}
else if (tabX[i]<L1+L2)
{
tabZ[i][0]=tabZ[i-1][0]-S01;
}
else
{
tabZ[i][0]=tabZ[i-1][0]-S02;
}
}
// Boucle sur les Y
for (j=0;i<=l;i++)
{
tabY[j]=tabZ[0][j-1]*dy+(dy/2);
for (i=1;i<=J;i++)
{
tabZ[i][j]=tabZ[i][0];
}
}
// Création du fichier
cout << "Vous allez créer un fichier .txt de topographie du canal en 3D avec les conditions B." << endl;
cout << "Comment voulez-vous l'appeler ?" << endl;
cin >> nom_fichier;
dossier = chemin + nom_fichier + extension;
// Ouverture
ofstream fichier;
fichier.open(dossier.c_str(), ios::out | ios::trunc); //ouvre le fichier en ecriture
if(fichier)//permet de tester la validité du fichier
{
// En-tête du fichier
string titre = "#Topographie condition du canal B modele 3D";
string colonne[3];
colonne[0] = "#X Longueur (m) ";
colonne[1] = " Y Largeur (m) ";
colonne[2] = " Z Topo (m)";
// Mise en forme du fichier
fichier << titre << endl;
fichier << colonne[0] << colonne[1] << colonne[2] << endl;
// Mise en forme
for (i=0;i>=J;i++)
{
for (j=0;j<=l;i++)
{
fichier << tabX[i] << " " << tabY[j] << " " << tabZ[i][j] << endl;
}
}
fichier.close(); //on ferme le fichier
}
else
cerr << "Impossible d'ouvrir le fichier !" << endl;
return 0;
} |
Partager