[2696] | 1 | /* |
---|
| 2 | #include <stdio.h> |
---|
| 3 | #include <stdlib.h> |
---|
| 4 | #include <math.h> |
---|
| 5 | */ |
---|
| 6 | KPP_REAL min( KPP_REAL x, KPP_REAL y ) |
---|
| 7 | { |
---|
| 8 | return ( x <= y ) ? x : y; |
---|
| 9 | } |
---|
| 10 | |
---|
| 11 | KPP_REAL max( KPP_REAL x, KPP_REAL y ) |
---|
| 12 | { |
---|
| 13 | return ( x >= y ) ? x : y; |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | static FILE *fpDat = 0; |
---|
| 17 | |
---|
| 18 | int InitSaveData() |
---|
| 19 | { |
---|
| 20 | fpDat = fopen("KPP_ROOT.dat", "w"); |
---|
| 21 | if( fpDat == 0 ) { |
---|
| 22 | printf("\n Can't create file : KPP_ROOT.dat"); |
---|
| 23 | exit(1); |
---|
| 24 | } |
---|
| 25 | return 0; |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | int SaveData() |
---|
| 29 | { |
---|
| 30 | int i; |
---|
| 31 | |
---|
| 32 | fprintf( fpDat, "%6.1f ", TIME/3600.0 ); |
---|
| 33 | for( i = 0; i < NLOOKAT; i++ ) |
---|
| 34 | fprintf( fpDat, "%24.16e ", C[ LOOKAT[i] ]/CFACTOR ); |
---|
| 35 | fprintf( fpDat, "\n"); |
---|
| 36 | return 0; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | int CloseSaveData() |
---|
| 40 | { |
---|
| 41 | fclose( fpDat ); |
---|
| 42 | return 0; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | int GenerateMatlab( char * prefix ) |
---|
| 46 | { |
---|
| 47 | int i; |
---|
| 48 | FILE *fpMatlab; |
---|
| 49 | |
---|
| 50 | fpMatlab = fopen("KPP_ROOT.m", "w"); |
---|
| 51 | if( fpMatlab == 0 ) { |
---|
| 52 | printf("\n Can't create file : KPP_ROOT.m"); |
---|
| 53 | exit(1); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | fprintf(fpMatlab, "load KPP_ROOT.dat;\n"); |
---|
| 57 | fprintf(fpMatlab, "%sc = KPP_ROOT;\n", prefix); |
---|
| 58 | fprintf(fpMatlab, "clear KPP_ROOT;\n"); |
---|
| 59 | fprintf(fpMatlab, "%st=%sc(:,1);\n", prefix, prefix); |
---|
| 60 | fprintf(fpMatlab, "%sc(:,1)=[];\n", prefix); |
---|
| 61 | |
---|
| 62 | for( i = 0; i < NLOOKAT; i++ ) |
---|
| 63 | fprintf( fpMatlab, "%s%s = %sc(:,%d);\n", |
---|
| 64 | prefix, SPC_NAMES[LOOKAT[i]], |
---|
| 65 | prefix, i+1 ); |
---|
| 66 | |
---|
| 67 | fclose( fpMatlab ); |
---|
| 68 | return 0; |
---|
| 69 | } |
---|
| 70 | |
---|