source: palm/trunk/UTIL/chemistry/gasphase_preproc/kpp/util/util.c

Last change on this file was 2696, checked in by kanani, 6 years ago

Merge of branch palm4u into trunk

File size: 1.2 KB
Line 
1/*
2#include <stdio.h>
3#include <stdlib.h>
4#include <math.h>
5*/
6KPP_REAL min( KPP_REAL x, KPP_REAL y )
7{
8  return ( x <= y ) ? x : y;
9}
10
11KPP_REAL max( KPP_REAL x, KPP_REAL y )
12{
13  return ( x >= y ) ? x : y;
14}
15
16static FILE *fpDat = 0;
17
18int 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
28int SaveData()
29{
30int 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
39int CloseSaveData()
40{
41  fclose( fpDat );
42  return 0;
43}
44
45int GenerateMatlab( char * prefix )
46{
47int i;
48FILE *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
Note: See TracBrowser for help on using the repository browser.