-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParameter_FILE.c
121 lines (94 loc) · 3.03 KB
/
Parameter_FILE.c
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
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "CPGPLOT_HEADER.h"
#include "include.FILES_to_READ.extern.h"
void P_A_R_A_M_E_T_E_R___F_I_L_E___A_L_L_O_C( Parameter_FILE * T )
{
int i;
/* Input Model Parameter Control */
T->Code_Parameters = (char **)malloc( MAX_No_of_FILES * sizeof(char *) );
for (i=0; i<MAX_No_of_FILES; i++){
T->Code_Parameters[i] = (char *)malloc( 100 * sizeof(char) );
}
T->Name_Parameters = (char **)malloc( MAX_No_of_FILES * sizeof(char *) );
for (i=0; i<MAX_No_of_FILES; i++){
T->Name_Parameters[i] = (char *)malloc( 500 * sizeof(char) );
}
}
void P_A_R_A_M_E_T_E_R___F_I_L_E___U_P_L_O_A_D( Parameter_FILE * T )
{
int i;
T->No_of_FILES = No_of_FILES;
T->Name_of_FILE = Name_of_FILE;
T->F_x_GRID = F_x_GRID;
T->F_y_GRID = F_y_GRID;
/* BEGIN: Names and codes for model parameters */
for(i = 0; i<MAX_No_of_FILES; i++){
AssignLabel_to_Parameter_FILE(i, T->Name_Parameters[i], T);
AssignCodes_to_Parameter_FILE(i, T->Code_Parameters[i], T);
}
/* END: Names and codes for model parameter */
}
void P_A_R_A_M_E_T_E_R___F_I_L_E___F_R_E_E( Parameter_FILE * T )
{
int i;
for (i=0; i < MAX_No_of_FILES; i++){
free( T->Code_Parameters[i] );
}
free(T->Code_Parameters);
for (i=0; i < MAX_No_of_FILES; i++){
free( T->Name_Parameters[i] );
}
free(T->Name_Parameters);
}
void AssignLabel_to_Parameter_FILE(int j, char * Label, Parameter_FILE *P)
{
char * p;
char num[12];
if (j < MAX_No_of_FILES ) {
Label[0] = '\0';
p = strcat(Label, "File_Number: ");
sprintf(num, "%d", j);
p = strcat(Label, num);
p = strcat(Label, "; Name: ");
p = strcat( Label, P->Name_of_FILE[j]);
}
else {
printf(".... INVALID PARAMETER KEY [key = %d]\n", j);
printf(" The maximum number of parameters is %d\n", MAX_No_of_FILES);
printf("\n");
exit(0);
}
}
void AssignCodes_to_Parameter_FILE(int j, char * Label, Parameter_FILE *P)
{
char * p;
char num[12];
if (j < MAX_No_of_FILES ) {
sprintf(num, "%d", j);
Label[0] = '\0';
p = strcat(Label, "-F"); p = strcat(Label, num);
p = strcat(Label, " [File Name] ");
p = strcat(Label, "-X"); p = strcat(Label, num);
p = strcat(Label, " [X dimension] ");
p = strcat(Label, "-Y"); p = strcat(Label, num);
p = strcat(Label, " [Y dimension]");
}
else {
printf(".... INVALID PARAMETER KEY [key = %d]\n", j);
printf(" The maximum number of parameters is %d\n", MAX_No_of_FILES);
printf("\n");
exit(0);
}
}
void fprintf_Input_Parameter_FILE(FILE * fp, Parameter_FILE * P)
{
int i;
fprintf(fp, "------------------------------------------------\n");
for(i=0; i < P->No_of_FILES; i++){
fprintf(fp, "FILES: %d: %s:\t %s\n",
i, P->Name_Parameters[i], P->Code_Parameters[i] );
}
int No_of_FILES_maximum = MAX_No_of_FILES;
fprintf(fp, "No of FILES (maximum): %d\t", No_of_FILES_maximum);
fprintf(fp, "-N [No of FILES: %d]\n", P->No_of_FILES);
fprintf(fp, "------------------------------------------------\n");
}