Commit 12a0cd6a authored by skripvic's avatar skripvic
Browse files

Final changes for 1.00

parent 76defcdd
......@@ -9,24 +9,24 @@ char *ca1;
char *ca2;
int CAT_Cell_number4(caFileHeader *fileHeader, int i, int j, int k, int l){
int CAT_CellNumber4(caFileHeader *fileHeader, int i, int j, int k, int l){
return i * (int)fileHeader->arraySizeJ * (int)fileHeader->arraySizeK * (int)fileHeader->arraySizeL +
j * (int)fileHeader->arraySizeK * (int)fileHeader->arraySizeL +
k * (int)fileHeader->arraySizeL + l;
}
int CAT_Cell_number3(caFileHeader *fileHeader, int i, int j, int k){
return CAT_Cell_number4(fileHeader, i, j, k, 0);
int CAT_CellNumber3(caFileHeader *fileHeader, int i, int j, int k){
return CAT_CellNumber4(fileHeader, i, j, k, 0);
}
int CAT_Cell_number2(caFileHeader *fileHeader, int i, int j){
return CAT_Cell_number4(fileHeader, i, j, 0, 0);
int CAT_CellNumber2(caFileHeader *fileHeader, int i, int j){
return CAT_CellNumber4(fileHeader, i, j, 0, 0);
}
uint64_t CAT_Control_sum(unsigned int size, unsigned int arraySize, caFileHeader* header, char *ca){ //!!! 64
uint64_t CAT_ControlSum(unsigned int size, unsigned int arraySize, caFileHeader* header, char *ca){
uint16_t *header_temp = (uint16_t*) header;
uint16_t controlSum = 0;
for (unsigned long i = 0; i < size >> 1; i++){
......@@ -39,7 +39,7 @@ uint64_t CAT_Control_sum(unsigned int size, unsigned int arraySize, caFileHeader
}
int CAT_File_read(char *filename, caFileHeader **fileHeader, char **caArray){
int CAT_FileRead(char *filename, caFileHeader **fileHeader, char **caArray){
FILE *fp;
*fileHeader = malloc(sizeof(caFileHeader));
if (*fileHeader == NULL){
......@@ -76,7 +76,7 @@ int CAT_File_read(char *filename, caFileHeader **fileHeader, char **caArray){
fclose(fp);
return -3;
}
uint16_t controlSumCur = CAT_Control_sum(sizeof(caFileHeader), arraySize, *fileHeader, *caArray);
uint16_t controlSumCur = CAT_ControlSum(sizeof(caFileHeader), arraySize, *fileHeader, *caArray);
if (controlSumFile != controlSumCur){
fclose(fp);
return -4;
......@@ -86,7 +86,7 @@ int CAT_File_read(char *filename, caFileHeader **fileHeader, char **caArray){
}
int CAT_File_save(char *filename, caFileHeader **fileHeader1, char **caArray1){
int CAT_FileSave(char *filename, caFileHeader **fileHeader1, char **caArray1){
caFileHeader *fileHeader = *fileHeader1;
char *caArray = *caArray1;
FILE *fp;
......@@ -110,7 +110,7 @@ int CAT_File_save(char *filename, caFileHeader **fileHeader1, char **caArray1){
fclose(fp);
return 2;
}
uint16_t controlSum = CAT_Control_sum(size, arraySize, fileHeader, caArray);
uint16_t controlSum = CAT_ControlSum(size, arraySize, fileHeader, caArray);
flag = fwrite(&controlSum, 1, 2, fp);
if (flag != 2){
fclose(fp);
......@@ -121,43 +121,43 @@ int CAT_File_save(char *filename, caFileHeader **fileHeader1, char **caArray1){
}
void CAT_Get_neighbors(int i, int j, char *n){
void CAT_GetNeighbors(int i, int j, char *n){
int sizeI = header->arraySizeI;
int sizeJ = header->arraySizeJ;
int sizeK = header->arraySizeK;
int sizeL = header->arraySizeL;
if (header->arrayTopology == 21){
n[0] = ca1[CAT_Cell_number2(header, i, j)];
n[1] = ca1[CAT_Cell_number2(header, (i-1+sizeI)%sizeI, j)];
n[2] = ca1[CAT_Cell_number2(header, (i-1+sizeI)%sizeI, (j+1)%sizeJ)];
n[3] = ca1[CAT_Cell_number2(header, i, (j+1)%sizeJ)];
n[4] = ca1[CAT_Cell_number2(header, (i+1)%sizeI, (j+1)%sizeJ)];
n[5] = ca1[CAT_Cell_number2(header, (i+1)%sizeI, j)];
n[6] = ca1[CAT_Cell_number2(header, (i+1)%sizeI, (j-1+sizeJ)%sizeJ)];
n[7] = ca1[CAT_Cell_number2(header, i, (j-1+sizeJ)%sizeJ)];
n[8] = ca1[CAT_Cell_number2(header, (i-1+sizeI)%sizeI, (j-1+sizeJ)%sizeJ)];
n[0] = ca1[CAT_CellNumber2(header, i, j)];
n[1] = ca1[CAT_CellNumber2(header, (i-1+sizeI)%sizeI, j)];
n[2] = ca1[CAT_CellNumber2(header, (i-1+sizeI)%sizeI, (j+1)%sizeJ)];
n[3] = ca1[CAT_CellNumber2(header, i, (j+1)%sizeJ)];
n[4] = ca1[CAT_CellNumber2(header, (i+1)%sizeI, (j+1)%sizeJ)];
n[5] = ca1[CAT_CellNumber2(header, (i+1)%sizeI, j)];
n[6] = ca1[CAT_CellNumber2(header, (i+1)%sizeI, (j-1+sizeJ)%sizeJ)];
n[7] = ca1[CAT_CellNumber2(header, i, (j-1+sizeJ)%sizeJ)];
n[8] = ca1[CAT_CellNumber2(header, (i-1+sizeI)%sizeI, (j-1+sizeJ)%sizeJ)];
}
if (header->arrayTopology == 22){
n[0] = ca1[CAT_Cell_number2(header, i, j)];
n[1] = ca1[CAT_Cell_number2(header, (i-1+sizeI)%sizeI, (j+i&1)%sizeJ)];
n[2] = ca1[CAT_Cell_number2(header, i, (j+1)%sizeJ)];
n[3] = ca1[CAT_Cell_number2(header, (i+1)%sizeI, (j+i&1)%sizeJ)];
n[4] = ca1[CAT_Cell_number2(header, (i+1)%sizeI, (j-1+i&1+sizeJ)%sizeJ)];
n[5] = ca1[CAT_Cell_number2(header, i, (j-1+sizeJ)%sizeJ)];
n[6] = ca1[CAT_Cell_number2(header, (i-1+sizeI)%sizeI, (j-1+i&1+sizeJ)%sizeJ)];
n[0] = ca1[CAT_CellNumber2(header, i, j)];
n[1] = ca1[CAT_CellNumber2(header, (i-1+sizeI)%sizeI, (j+i&1)%sizeJ)];
n[2] = ca1[CAT_CellNumber2(header, i, (j+1)%sizeJ)];
n[3] = ca1[CAT_CellNumber2(header, (i+1)%sizeI, (j+i&1)%sizeJ)];
n[4] = ca1[CAT_CellNumber2(header, (i+1)%sizeI, (j-1+i&1+sizeJ)%sizeJ)];
n[5] = ca1[CAT_CellNumber2(header, i, (j-1+sizeJ)%sizeJ)];
n[6] = ca1[CAT_CellNumber2(header, (i-1+sizeI)%sizeI, (j-1+i&1+sizeJ)%sizeJ)];
}
}
int CAT_Get_neighbor_number(caFileHeader *fileHeader){
int CAT_GetNeighborNumber(caFileHeader *fileHeader){
if (fileHeader->arrayTopology == 21) return 9;
if (fileHeader->arrayTopology == 22) return 6;
}
int CAT_Init(char *filename){
int CAT_InitSimulator(char *filename){
if (filename == NULL) return -5;
int flag = CAT_File_read(filename, &header, &ca1);
int flag = CAT_FileRead(filename, &header, &ca1);
if (flag != 0) return flag;
unsigned int cellSize = header->cellSize;
unsigned int arraySize = header->arraySizeI *
......@@ -174,13 +174,13 @@ int CAT_Init(char *filename){
int CAT_Iterate(int (*cellTransition)(char*)){
int countChanged = 0;
int neighborNumber = CAT_Get_neighbor_number(header);
int neighborNumber = CAT_GetNeighborNumber(header);
char *n = malloc((neighborNumber + 1) * sizeof(char));
for (int i = 0; i < header->arraySizeI; i++)
for (int j = 0; j < header->arraySizeJ; j++) {
CAT_Get_neighbors(i, j, n);
CAT_GetNeighbors(i, j, n);
countChanged += (*cellTransition)(n);
ca2[CAT_Cell_number2(header, i, j)] = n[0];
ca2[CAT_CellNumber2(header, i, j)] = n[0];
}
if (countChanged == 0)
return 1;
......@@ -193,8 +193,8 @@ int CAT_Iterate(int (*cellTransition)(char*)){
}
int CAT_Finalize(char *filename){
CAT_File_save(filename, &header, &ca1);
int CAT_FinalizeSimulator(char *filename){
CAT_FileSave(filename, &header, &ca1);
free(ca1);
free(ca2);
free(header);
......
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "CATlib-data-operation.h"
#include "CATlib-base.h"
#define MAX_DIM 4
......@@ -14,7 +13,7 @@ const double oneHalf = 0.5;
caFileHeader *header;
char *ca;
int CAT_Init_preprocessor(enum cellularArrayType arrayTopology, enum modelType modelType, int
int CAT_InitPreprocessor(enum cellularArrayType arrayTopology, enum modelType modelType, int
cellSize, int globalSize, double cellsPerMeter, ...){
int dim = (int)arrayTopology / 10;
int arraySize[MAX_DIM] = {1,1,1,1};
......@@ -56,9 +55,9 @@ cellSize, int globalSize, double cellsPerMeter, ...){
return 0;
}
int CAT_Init_postprocessor(char *filename){
int CAT_InitPostprocessor(char *filename){
if (filename == NULL) return -5;
return CAT_File_read(filename, &header, &ca);
return CAT_FileRead(filename, &header, &ca);
}
int CAT_ArrayTopology_not_acceptable(){
......@@ -347,7 +346,7 @@ int CAT_GetMaxL(){
return header->arraySizeL - 1;
}
int CAT_Put_cell(char *cellValue, int i, ...){
int CAT_PutCell(char *cellValue, int i, ...){
int inx[MAX_DIM] = {0,0,0,0};
inx[0] = i;
va_list factor;
......@@ -366,7 +365,7 @@ int CAT_Put_cell(char *cellValue, int i, ...){
}
int CAT_Get_cell(char *cellValue, int i, ...){
int CAT_GetCell(char *cellValue, int i, ...){
int inx[MAX_DIM] = {0,0,0,0};
inx[0] = i;
va_list factor;
......@@ -385,15 +384,15 @@ int CAT_Get_cell(char *cellValue, int i, ...){
}
int CAT_Finalize_preprocessor(char *filename){
CAT_File_save(filename, &header, &ca);
int CAT_FinalizePreprocessor(char *filename){
CAT_FileSave(filename, &header, &ca);
free(header);
free(ca);
return 0;
}
int CAT_Finalize_postprocessor(){
int CAT_FinalizePostprocessor(){
free(header);
free(ca);
return 0;
......
#include "CATlib-base.h"
int CAT_Init_preprocessor(enum cellularArrayType arrayTopology, enum modelType modelType, int
cellSize, int globalSize, double cellsPerMeter, ...);
int CAT_Init_postprocessor(char *filename);
double CAT_SquareDistance(int i1, ...);
double CAT_GetX(int i, ...);
double CAT_GetY(int i, ...);
double CAT_GetZ(int i, ...);
double CAT_GetT(int i, ...);
int CAT_GetI(double x, ...);
int CAT_GetJ(double x, ...);
int CAT_GetK(double x, ...);
int CAT_GetL(double x, ...);
int CAT_GetMaxI();
int CAT_GetMaxJ();
int CAT_GetMaxK();
int CAT_GetMaxL();
int CAT_Put_cell(char *cellValue, int i, ...);
int CAT_Get_cell(char *cellValue, int i, ...);
int CAT_Finalize_preprocessor(char *filename);
int CAT_Finalize_postprocessor();
# CAT Library
### CAT_Init_preprocessor
int CAT_Init_preprocessor(int arrayTopology, int modelType, int
### CAT_InitPreprocessor
int CAT_InitPreprocessor(int arrayTopology, int modelType, int
cellSize, int globalSize, double cellsPerMeter, int arraySizeI, ...)
#### Input variables
......@@ -34,8 +34,8 @@
Dimension is equal to arrayTopology / 10
>
### CAT_Init_postprocessor
int CAT_Init_postprocessor(char *filename)
### CAT_InitPostprocessor
int CAT_InitPostprocessor(char *filename)
#### Input variables
filename
......@@ -52,8 +52,8 @@
>
### CAT_Init
int CAT_Init(char *filename)
### CAT__InitSimulator
int CAT_InitSimulator(char *filename)
#### Input variables
filename
......@@ -70,8 +70,8 @@
>
### CAT_Put_cell
int CAT_Put_cell(char *cellValue, int i, ...)
### CAT_PutCell
int CAT_PutCell(char *cellValue, int i, ...)
#### Input variables
i, ...
......@@ -91,8 +91,8 @@
>
### CAT_Get_cell
int CAT_Get_cell(char *cellValue, int i, ...)
### CAT_GetCell
int CAT_GetCell(char *cellValue, int i, ...)
#### Input variables
i, ...
......@@ -199,8 +199,8 @@
>
### CAT_Finalize
int CAT_Finalize(char *filename)
### CAT_FinalizePreprocessor
int CAT_FinalizePreprocessor(char *filename)
#### Input variables
filename
......@@ -211,3 +211,31 @@
returns 0 in case of success
returns 1 if error occurred during opening file
returns 2 if error occurred during writing in the file
>
### CAT_FinalizeSimulator
int CAT_FinalizeSimulator(char *filename)
#### Input variables
filename
pointer to name of file for saving caFileHeader
#### Description
Saves caFileHeader and Cellular Array into file, frees memory.
returns 0 in case of success
returns 1 if error occurred during opening file
returns 2 if error occurred during writing in the file
>
### CAT_FinalizePostprocessor
int CAT_FinalizePostprocessor(char *filename)
#### Input variables
filename
pointer to name of file for saving caFileHeader
#### Description
Saves caFileHeader and Cellular Array into file, frees memory.
returns 0 in case of success
......@@ -54,11 +54,37 @@ enum modelType{
GAS_FLOW_MODEL = 2
};
int CAT_Init(char *filename);
int CAT_FileRead(char *filename, caFileHeader **fileHeader, char **caArray);
int CAT_FileSave(char *filename, caFileHeader **fileHeader, char **caArray);
int CAT_InitPreprocessor(enum cellularArrayType arrayTopology, enum modelType modelType, int
cellSize, int globalSize, double cellsPerMeter, ...);
int CAT_InitSimulator(char *filename);
int CAT_InitPostprocessor(char *filename);
double CAT_SquareDistance(int i1, ...);
double CAT_GetX(int i, ...);
double CAT_GetY(int i, ...);
double CAT_GetZ(int i, ...);
double CAT_GetT(int i, ...);
int CAT_GetI(double x, ...);
int CAT_GetJ(double x, ...);
int CAT_GetK(double x, ...);
int CAT_GetL(double x, ...);
int CAT_GetMaxI();
int CAT_GetMaxJ();
int CAT_GetMaxK();
int CAT_GetMaxL();
int CAT_PutCell(char *cellValue, int i, ...);
int CAT_GetCell(char *cellValue, int i, ...);
int CAT_Iterate(int (*cellTransition)(char*));
int CAT_Finalize();
int CAT_File_read(char *filename, caFileHeader **fileHeader, char **caArray);
int CAT_File_save(char *filename, caFileHeader **fileHeader, char **caArray);
//int CAT_Cell_number4(caFileHeader *caHeader, int i, int j, int k, int l);
//int CAT_Cell_number3(caFileHeader *caHeader, int i, int j, int k);
//int CAT_Cell_number2(caFileHeader *caHeader, int i, int j);
int CAT_FinalizePreprocessor(char *filename);
int CAT_FinalizeSimulator(char *filename);
int CAT_FinalizePostprocessor();
No preview for this file type
#include <stdio.h>
#include <stdlib.h>
#include "CATlib-data-operation.h"
#include "CATlib-base.h"
#define FILENAME "data-files/file_test.dat"
int main(){
int I = 20, J = 20, K = 1, L = 1;
CAT_Init_postprocessor((char *)FILENAME);
CAT_InitPostprocessor((char *)FILENAME);
printf("This is postprocessor\n");
char value;
for (int i = 0; i < I; i++)
for (int j = 0; j < J; j++)
for (int k = 0; k < K; k++)
for (int l = 0; l < L; l++){
CAT_Get_cell(&value, i, j, k, l);
CAT_GetCell(&value, i, j, k, l);
printf("%d ", (int)value);
if (j == 19) printf("\n");
}
CAT_Finalize_postprocessor();
CAT_FinalizePostprocessor();
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include "CATlib-data-operation.h"
#include "CATlib-base.h"
#define FILENAME "data-files/file_test.dat"
......@@ -10,18 +10,18 @@ int main(){
enum modelType mod = ABSTRACT_MODEL;
int cell = 1, glob = 0;
double cPm = 1.0;
CAT_Init_preprocessor(arTop, mod, cell, glob, cPm, I, J);
CAT_InitPreprocessor(arTop, mod, cell, glob, cPm, I, J);
printf("This is preprocessor\n");
char value = 1;
for (int i = 0; i < I; i++)
for (int j = 0; j < J; j++)
CAT_Put_cell(&value, i, j, 0, 0);
CAT_PutCell(&value, i, j, 0, 0);
//value = 1;
//CAT_Put_cell(&value, I-1, J-1, 0, 0);
for(int i=0;i<10;i++)
for(int i=0;i<5;i++)
{
for(int j=0;j<10;j++)
for(int j=0;j<5;j++)
{
double x=CAT_GetX(i,j);
double y=CAT_GetY(i,j);
......@@ -31,10 +31,10 @@ int main(){
}
/* print i,j by x,y from (0.0,0.0) to (10.0,10.0) */
for(double x=0;x<=10;x+=0.3)
for(double x=0;x<=3;x+=0.3)
{
int i,j;
for(double y=0;y<=10;y+=0.3)
for(double y=0;y<=3;y+=0.3)
{
i = CAT_GetI(x,y);
j = CAT_GetJ(x,y);
......@@ -42,6 +42,6 @@ int main(){
}
printf("\n");
}
CAT_Finalize_preprocessor((char *) FILENAME);
CAT_FinalizePreprocessor((char *) FILENAME);
return 0;
}
......@@ -32,7 +32,7 @@ int cellTransitionForFHP(char *n){
}
int main(int argc, char * argv[]){
int flag = CAT_Init((char *) FILE_IN);
int flag = CAT_InitSimulator((char *) FILE_IN);
if (flag){
printf("Error while initializing");
return 1;
......@@ -45,7 +45,7 @@ int main(int argc, char * argv[]){
}
}
printf("SIZE OF DOUBLE %ld\nSIZE OF CAFILEHEADER %ld\n", sizeof(double), sizeof(caFileHeader));
flag = CAT_Finalize((char *) FILE_OUT);
flag = CAT_FinalizeSimulator((char *) FILE_OUT);
if (flag){
printf("Error while finalizing");
return 1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment