Back to home page

MITgcm

 
 

    


File indexing completed on 2023-05-28 05:10:54 UTC

view on githubraw file Latest commit b4daa243 on 2023-05-28 03:53:22 UTC
b4daa24319 Shre*0001 /*
                0002  * TAPENADE Automatic Differentiation Engine
                0003  * Copyright (C) 1999-2021 Inria
                0004  * See the LICENSE.md file in the project root for more information.
                0005  *
                0006  */
                0007 
                0008 #include <string.h>
                0009 #include <stdio.h>
                0010 #include <stdlib.h>
                0011 #include "adContext.h"
                0012 
                0013 #include "adComplex.h"
                0014 
                0015 static int dbad_mode, dbad_phase ;
                0016 static double dbad_ddeps = 1.e-6 ;
                0017 static double dbad_seed = 0.137 ;
                0018 static double dbad_currentSeed = 0.0 ;
                0019 static double dbad_condensed_val, dbad_condensed_tgt, dbad_condensed_adj ;
                0020 
                0021 double dbad_nextRandom() {
                0022   dbad_currentSeed += dbad_seed ;
                0023   if (dbad_currentSeed>=1.0) dbad_currentSeed-=1.0 ;
                0024   /* Return a value in range [1.0 2.0[ */
                0025   return dbad_currentSeed+1.0 ;
                0026 }
                0027 
                0028 void adContextTgt_init(double epsilon, double seed) {
                0029   dbad_mode = 1 ;
                0030   dbad_ddeps = epsilon ;
                0031   dbad_seed = seed ;
                0032   char* phase = getenv("DBAD_PHASE") ;
                0033   if (phase==NULL) {
                0034     printf("Please set DBAD_PHASE environment variable to 1 (perturbed) or 2 (tangent)\n") ;
                0035     exit(0) ;
                0036   } else if (strcmp(phase,"2")==0) {
                0037     printf("Tangent code,  seed=%7.1e\n", seed) ;
                0038     printf("=============================================\n") ;
                0039     dbad_phase = 2 ;
                0040     dbad_currentSeed = 0.0 ;
                0041   } else if (strcmp(phase,"1")==0) {
                0042     printf("Perturbed run, seed=%7.1e, epsilon=%7.1e\n", seed, epsilon) ;
                0043     printf("=============================================\n") ;
                0044     dbad_phase = 1 ;
                0045     dbad_currentSeed = 0.0 ;
                0046   } else if (strcmp(phase,"99")==0) {
                0047     printf("INTERNAL INTERFACE TESTS, seed=%7.1e, epsilon=%7.1e\n", seed, epsilon) ;
                0048     printf("=============================================\n") ;
                0049     dbad_phase = 99 ;
                0050   } else {
                0051     printf("DBAD_PHASE environment variable must be set to 1 or 2\n") ;
                0052     exit(0) ;
                0053   }
                0054 }
                0055 
                0056 void adContextTgt_initReal8(char* varname, double *indep, double *indepd) {
                0057   *indepd = dbad_nextRandom() ;
                0058   if (dbad_phase==1)
                0059     *indep = (*indep)+dbad_ddeps*(*indepd) ;
                0060   else if (dbad_phase==99)
                0061     printf("initReal8 of %s: %24.16e //%24.16e\n", varname, *indep, *indepd) ;
                0062 }
                0063 
                0064 void adContextTgt_initReal8Array(char* varname, double *indep, double *indepd, int length) {
                0065   int i ;
                0066   for (i=0 ; i<length ; ++i) {
                0067     indepd[i] = dbad_nextRandom() ;
                0068   }
                0069   if (dbad_phase==1) {
                0070     for (i=0 ; i<length ; ++i) {
                0071       indep[i] = indep[i]+dbad_ddeps*indepd[i] ;
                0072     }
                0073   } else if (dbad_phase==99) {
                0074     printf("initReal8Array of %s, length=%i:\n", varname, length) ;
                0075     for (i=0 ; i<length ; ++i)
                0076       printf("    %i:%24.16e //%24.16e",i,indep[i],indepd[i]) ;
                0077     printf("\n") ;
                0078   }
                0079 }
                0080 
                0081 void adContextTgt_initReal4(char* varname, float *indep, float *indepd) {
                0082   *indepd = (float)dbad_nextRandom() ;
                0083   if (dbad_phase==1)
                0084     *indep = (*indep)+dbad_ddeps*(*indepd) ;
                0085   else if (dbad_phase==99)
                0086     printf("initReal4 of %s: %24.16e //%24.16e\n", varname, *indep, *indepd) ;
                0087 }
                0088 
                0089 void adContextTgt_initReal4Array(char* varname, float *indep, float *indepd, int length) {
                0090   int i ;
                0091   for (i=0 ; i<length ; ++i) {
                0092     indepd[i] = (float)dbad_nextRandom() ;
                0093   }
                0094   if (dbad_phase==1) {
                0095     for (i=0 ; i<length ; ++i) {
                0096       indep[i] = indep[i]+dbad_ddeps*indepd[i] ;
                0097     }
                0098   } else if (dbad_phase==99) {
                0099     printf("initReal4Array of %s, length=%i:\n", varname, length) ;
                0100     for (i=0 ; i<length ; ++i)
                0101       printf("    %i:%24.16e //%24.16e",i,indep[i],indepd[i]) ;
                0102     printf("\n") ;
                0103   }
                0104 }
                0105 
                0106 void adContextTgt_initComplex16(char* varname, double complex *indep, double complex *indepd) {
                0107   double rdot =  dbad_nextRandom() ;
                0108   double idot =  dbad_nextRandom() ;
                0109   *indepd = rdot + I*idot ;
                0110   if (dbad_phase==1) {
                0111     *indep = *indep + dbad_ddeps*(*indepd) ;
                0112   } else if (dbad_phase==99)
                0113     printf("initComplex16 of %s: %24.16e+i%24.16e //%24.16e+i%24.16e\n",
                0114            varname, creal(*indep), cimag(*indep), creal(*indepd), cimag(*indepd)) ;
                0115 }
                0116 
                0117 void adContextTgt_initComplex16Array(char* varname, double complex *indep, double complex *indepd, int length) {
                0118   double rdot, idot ;
                0119   int i ;
                0120   for (i=0 ; i<length ; ++i) {
                0121     rdot =  dbad_nextRandom() ;
                0122     idot =  dbad_nextRandom() ;
                0123     indepd[i] = rdot + I*idot ;
                0124   }
                0125   if (dbad_phase==1) {
                0126     for (i=0 ; i<length ; ++i) {
                0127       indep[i] = indep[i] + dbad_ddeps*indepd[i] ;
                0128     }
                0129   } else if (dbad_phase==99) {
                0130     printf("initComplex16Array of %s, length=%i:\n", varname, length) ;
                0131     for (i=0 ; i<length ; ++i)
                0132       printf("    %i:%24.16e+i%24.16e //%24.16e+i%24.16e",
                0133              i,creal(indep[i]),cimag(indep[i]),creal(indepd[i]),cimag(indepd[i])) ;
                0134     printf("\n") ;
                0135   }
                0136 }
                0137 
                0138 void adContextTgt_initComplex8(char* varname, ccmplx *indep, ccmplx *indepd) {
                0139   indepd->r = (float)dbad_nextRandom() ;
                0140   indepd->i = (float)dbad_nextRandom() ;
                0141   if (dbad_phase==1) {
                0142     indep->r = indep->r + dbad_ddeps*indepd->r ;
                0143     indep->i = indep->i + dbad_ddeps*indepd->i ;
                0144   } else if (dbad_phase==99)
                0145     printf("initComplex8 of %s: %24.16e+i%24.16e //%24.16e+i%24.16e\n",
                0146            varname, indep->r, indep->i, indepd->r, indepd->i) ;
                0147 }
                0148 
                0149 void adContextTgt_initComplex8Array(char* varname, ccmplx *indep, ccmplx *indepd, int length) {
                0150   int i ;
                0151   for (i=0 ; i<length ; ++i) {
                0152     indepd[i].r = (float)dbad_nextRandom() ;
                0153     indepd[i].i = (float)dbad_nextRandom() ;
                0154   }
                0155   if (dbad_phase==1) {
                0156     for (i=0 ; i<length ; ++i) {
                0157       indep[i].r = indep[i].r+dbad_ddeps*indepd[i].r ;
                0158       indep[i].i = indep[i].i+dbad_ddeps*indepd[i].i ;
                0159     }
                0160   } else if (dbad_phase==99) {
                0161     printf("initComplex8Array of %s, length=%i:\n", varname, length) ;
                0162     for (i=0 ; i<length ; ++i)
                0163       printf("    %i:%24.16e+i%24.16e //%24.16e+i%24.16e",
                0164              i,indep[i].r,indep[i].i,indepd[i].r,indepd[i].i) ;
                0165     printf("\n") ;
                0166   }
                0167 }
                0168 
                0169 void adContextTgt_startConclude() {
                0170   dbad_currentSeed= 0.0 ;
                0171   dbad_condensed_val = 0.0 ;
                0172   dbad_condensed_tgt = 0.0 ;
                0173 }
                0174 
                0175 void adContextTgt_concludeReal8(char* varname, double dep, double depd) {
                0176   double depb = dbad_nextRandom() ;
                0177   dbad_condensed_val += depb*(dep) ;
                0178   if (dbad_phase==2 || dbad_phase==1)
                0179     dbad_condensed_tgt += depb*(depd) ;
                0180   else if (dbad_phase==99)
                0181     printf("concludeReal8 of %s [%24.16e *] %24.16e //%24.16e\n", varname, depb, dep, depd) ;
                0182 }
                0183 
                0184 void adContextTgt_concludeReal8Array(char* varname, double *dep, double *depd, int length) {
                0185   int i ;
                0186   double depb ;
                0187   if (dbad_phase==99) printf("concludeReal8Array of %s, length=%i:\n", varname, length) ;
                0188   for (i=0 ; i<length ; ++i) {
                0189     depb = dbad_nextRandom() ;
                0190     dbad_condensed_val += depb*dep[i] ;
                0191     if (dbad_phase==2 || dbad_phase==1) {
                0192        dbad_condensed_tgt += depb*depd[i] ;
                0193     } else if (dbad_phase==99) {
                0194       printf("    %i:[%24.16e *] %24.16e //%24.16e",i,depb,dep[i],depd[i]) ;
                0195     }
                0196   }
                0197   if (dbad_phase==99) printf("\n") ;
                0198 }
                0199 
                0200 void adContextTgt_concludeReal4(char* varname, float dep, float depd) {
                0201   float depb = (float)dbad_nextRandom() ;
                0202   dbad_condensed_val += depb*(dep) ;
                0203   if (dbad_phase==2 || dbad_phase==1)
                0204     dbad_condensed_tgt += depb*(depd) ;
                0205   else if (dbad_phase==99)
                0206     printf("concludeReal4 of %s [%24.16e *] %24.16e //%24.16e\n", varname, depb, dep, depd) ;
                0207 }
                0208 
                0209 void adContextTgt_concludeReal4Array(char* varname, float *dep, float *depd, int length) {
                0210   int i ;
                0211   float depb ;
                0212   if (dbad_phase==99) printf("concludeReal4Array of %s, length=%i:\n", varname, length) ;
                0213   for (i=0 ; i<length ; ++i) {
                0214     depb = (float)dbad_nextRandom() ;
                0215     dbad_condensed_val += depb*dep[i] ;
                0216     if (dbad_phase==2 || dbad_phase==1) {
                0217        dbad_condensed_tgt += depb*depd[i] ;
                0218     } else if (dbad_phase==99) {
                0219       printf("    %i:[%24.16e *] %24.16e //%24.16e",i,depb,dep[i],depd[i]) ;
                0220     }
                0221   }
                0222   if (dbad_phase==99) printf("\n") ;
                0223 }
                0224 
                0225 void adContextTgt_concludeComplex16(char* varname, double complex dep, double complex depd) {
                0226   double depbr = dbad_nextRandom() ;
                0227   double depbi = dbad_nextRandom() ;
                0228   dbad_condensed_val += depbr*creal(dep) + depbi*cimag(dep);
                0229   if (dbad_phase==2 || dbad_phase==1)
                0230     dbad_condensed_tgt += depbr*creal(depd) + depbi*cimag(depd) ;
                0231   else if (dbad_phase==99)
                0232     printf("concludeComplex16 of %s [%24.16e;%24.16e *] %24.16e+i%24.16e //%24.16e+i%24.16e\n",
                0233            varname, depbr, depbi, creal(dep), cimag(dep), creal(depd), cimag(depd)) ;
                0234 }
                0235 
                0236 void adContextTgt_concludeComplex16Array(char* varname, double complex *dep, double complex *depd, int length) {
                0237   int i ;
                0238   double depbr, depbi ;
                0239   if (dbad_phase==99) printf("concludeComplex16Array of %s, length=%i:\n", varname, length) ;
                0240   for (i=0 ; i<length ; ++i) {
                0241     depbr = dbad_nextRandom() ;
                0242     depbi = dbad_nextRandom() ;
                0243     dbad_condensed_val += depbr*creal(dep[i]) + depbi*cimag(dep[i]);
                0244     if (dbad_phase==2 || dbad_phase==1) {
                0245       dbad_condensed_tgt += depbr*creal(depd[i]) + depbi*cimag(depd[i]) ;
                0246     } else if (dbad_phase==99) {
                0247       printf("    %i:[%24.16e;%24.16e *] %24.16e //%24.16e",
                0248              i, depbr, depbi, creal(dep[i]), cimag(dep[i]), creal(depd[i]), cimag(depd[i])) ;
                0249     }
                0250   }
                0251   if (dbad_phase==99) printf("\n") ;
                0252 }
                0253 
                0254 void adContextTgt_concludeComplex8(char* varname, ccmplx *dep, ccmplx *depd) {
                0255   float depbr = (float)dbad_nextRandom() ;
                0256   float depbi = (float)dbad_nextRandom() ;
                0257   dbad_condensed_val += depbr*(dep->r) + depbi*(dep->i) ;
                0258   if (dbad_phase==2 || dbad_phase==1)
                0259     dbad_condensed_tgt += depbr*(depd->r) + depbi*(depd->i) ;
                0260   else if (dbad_phase==99)
                0261     printf("concludeComplex8 of %s [%24.16e;%24.16e *] %24.16e+i%24.16e //%24.16e+i%24.16e\n",
                0262            varname, depbr, depbi, dep->r, dep->i, depd->r, depd->i) ;
                0263 }
                0264 
                0265 void adContextTgt_concludeComplex8Array(char* varname, ccmplx *dep, ccmplx *depd, int length) {
                0266   int i ;
                0267   float depbr, depbi ;
                0268   if (dbad_phase==99) printf("concludeComplex8Array of %s, length=%i:\n", varname, length) ;
                0269   for (i=0 ; i<length ; ++i) {
                0270     depbr = (float)dbad_nextRandom() ;
                0271     depbi = (float)dbad_nextRandom() ;
                0272     dbad_condensed_val += depbr*(dep[i].r) + depbi*(dep[i].i) ;
                0273     if (dbad_phase==2 || dbad_phase==1) {
                0274       dbad_condensed_tgt += depbr*(depd[i].r) + depbi*(depd[i].i) ;
                0275     } else if (dbad_phase==99) {
                0276       printf("    %i:[%24.16e;%24.16e *] %24.16e+i%24.16e //%24.16e+i%24.16e",
                0277              i, depbr, depbi, dep[i].r, dep[i].i, depd[i].r, depd[i].i) ;
                0278     }
                0279   }
                0280   if (dbad_phase==99) printf("\n") ;
                0281 }
                0282 
                0283 void adContextTgt_conclude() {
                0284   if (dbad_phase==2) {
                0285     printf("[seed:%7.1e] Condensed result : %24.16e\n", dbad_seed, dbad_condensed_val) ;
                0286     printf("[seed:%7.1e] Condensed tangent: %24.16e\n", dbad_seed, dbad_condensed_tgt) ;
                0287   } else if (dbad_phase==1) {
                0288     printf("[seed:%7.1e] Condensed perturbed result : %24.16e (epsilon:%7.1e)\n",
                0289            dbad_seed, dbad_condensed_val, dbad_ddeps) ;
                0290     printf("[seed:%7.1e] Condensed perturbed tangent: %24.16e\n", dbad_seed, dbad_condensed_tgt) ;
                0291   }
                0292 }
                0293 
                0294 void adContextAdj_init(double seed) {
                0295   dbad_mode = 0 ;
                0296   dbad_seed = seed ;
                0297   char* phase = getenv("DBAD_PHASE") ;
                0298   if (phase==NULL) {
                0299     dbad_phase = 0 ;
                0300   } else if (strcmp(phase,"99")==0) {
                0301     dbad_phase = 99 ;
                0302     printf("INTERNAL INTERFACE TESTS, seed=%7.1e\n", seed) ;
                0303   } else {
                0304     dbad_phase = 0 ;
                0305   }
                0306   printf("Adjoint code,  seed=%7.1e\n", seed) ;
                0307   printf("===================================\n") ;
                0308   dbad_currentSeed = 0.0 ;
                0309 }
                0310 
                0311 void adContextAdj_initReal8(char* varname, double *dep, double *depb) {
                0312   *depb = dbad_nextRandom() ;
                0313   if (dbad_phase==99)
                0314     printf("initReal8 of %s %24.16e\n", varname, *depb) ;
                0315 }
                0316 
                0317 void adContextAdj_initReal8Array(char* varname, double *dep, double *depb, int length) {
                0318   int i ;
                0319   for (i=0 ; i<length ; ++i) {
                0320     depb[i] = dbad_nextRandom() ;
                0321   }
                0322   if (dbad_phase==99) {
                0323     printf("initReal8Array of %s, length=%i\n", varname, length) ;
                0324     for (i=0 ; i<length ; ++i)
                0325       printf("    %i:%24.16e", i, depb[i]) ;
                0326     printf("\n") ;
                0327   }
                0328 }
                0329 
                0330 void adContextAdj_initReal4(char* varname, float *dep, float *depb) {
                0331   *depb = (float)dbad_nextRandom() ;
                0332   if (dbad_phase==99)
                0333     printf("initReal4 of %s %24.16e\n", varname, *depb) ;
                0334 }
                0335 
                0336 void adContextAdj_initReal4Array(char* varname, float *dep, float *depb, int length) {
                0337   int i ;
                0338   for (i=0 ; i<length ; ++i) {
                0339     depb[i] = (float)dbad_nextRandom() ;
                0340   }
                0341   if (dbad_phase==99) {
                0342     printf("initReal4Array of %s, length=%i\n", varname, length) ;
                0343     for (i=0 ; i<length ; ++i)
                0344       printf("    %i:%24.16e",i, depb[i]) ;
                0345     printf("\n") ;
                0346   }
                0347 }
                0348 
                0349 void adContextAdj_initComplex16(char* varname, double complex *dep, double complex *depb) {
                0350   double rbar =  dbad_nextRandom() ;
                0351   double ibar =  dbad_nextRandom() ;
                0352   *depb = rbar + I*ibar ;
                0353   if (dbad_phase==99)
                0354     printf("initComplex16 of %s %24.16e+i%24.16e\n", varname, creal(*depb), cimag(*depb)) ;
                0355 }
                0356 
                0357 void adContextAdj_initComplex16Array(char* varname, double complex *dep, double complex *depb, int length) {
                0358   double rbar, ibar ;
                0359   int i ;
                0360   for (i=0 ; i<length ; ++i) {
                0361     rbar = dbad_nextRandom() ;
                0362     ibar = dbad_nextRandom() ;
                0363     depb[i] = rbar + I*ibar ;
                0364   }
                0365   if (dbad_phase==99) {
                0366     printf("initComplex16Array of %s, length=%i\n", varname, length) ;
                0367     for (i=0 ; i<length ; ++i)
                0368       printf("    %i:%24.16e+i%24.16e",i, creal(depb[i]), cimag(depb[i])) ;
                0369     printf("\n") ;
                0370   }
                0371 }
                0372 
                0373 void adContextAdj_initComplex8(char* varname, ccmplx *dep, ccmplx *depb) {
                0374   depb->r = (float)dbad_nextRandom() ;
                0375   depb->i = (float)dbad_nextRandom() ;
                0376   if (dbad_phase==99)
                0377     printf("initComplex8 of %s %24.16e+i%24.16e\n", varname, depb->r, depb->i) ;
                0378 }
                0379 
                0380 void adContextAdj_initComplex8Array(char* varname, ccmplx *dep, ccmplx *depb, int length) {
                0381   int i ;
                0382   for (i=0 ; i<length ; ++i) {
                0383     depb[i].r = (float)dbad_nextRandom() ;
                0384     depb[i].i = (float)dbad_nextRandom() ;
                0385   }
                0386   if (dbad_phase==99) {
                0387     printf("initComplex8Array of %s, length=%i\n", varname, length) ;
                0388     for (i=0 ; i<length ; ++i)
                0389       printf("    %i:%24.16e+i%24.16e", i, depb[i].r, depb[i].i) ;
                0390     printf("\n") ;
                0391   }
                0392 }
                0393 
                0394 void adContextAdj_startConclude() {
                0395   dbad_currentSeed= 0.0 ;
                0396   dbad_condensed_adj = 0.0 ;
                0397 }
                0398 
                0399 void adContextAdj_concludeReal8(char* varname, double dep, double depb) {
                0400   double depd = dbad_nextRandom() ;
                0401   dbad_condensed_adj += depd*depb ;
                0402   if (dbad_phase==99)
                0403     printf("concludeReal8 of %s [%24.16e *]%24.16e\n", varname, depd, depb) ;
                0404 }
                0405 
                0406 void adContextAdj_concludeReal8Array(char* varname, double *dep, double *depb, int length) {
                0407   int i ;
                0408   double depd ;
                0409   if (dbad_phase==99) printf("concludeReal8Array of %s, length=%i:\n", varname, length) ;
                0410   for (i=0 ; i<length ; ++i) {
                0411     depd = dbad_nextRandom() ;
                0412     dbad_condensed_adj += depd*depb[i] ;
                0413     if (dbad_phase==99) printf("    %i:[%24.16e *] %24.16e",i,depd,depb[i]) ;
                0414   }
                0415   if (dbad_phase==99) printf("\n") ;
                0416 }
                0417 
                0418 void adContextAdj_concludeReal4(char* varname, float dep, float depb) {
                0419   float depd = (float)dbad_nextRandom() ;
                0420   dbad_condensed_adj += depd*depb ;
                0421   if (dbad_phase==99)
                0422     printf("concludeReal4 of %s [%24.16e *]%24.16e\n", varname, depd, depb) ;
                0423 }
                0424 
                0425 void adContextAdj_concludeReal4Array(char* varname, float *dep, float *depb, int length) {
                0426   int i ;
                0427   float depd ;
                0428   if (dbad_phase==99) printf("concludeReal4Array of %s, length=%i:\n", varname, length) ;
                0429   for (i=0 ; i<length ; ++i) {
                0430     depd = (float)dbad_nextRandom() ;
                0431     dbad_condensed_adj += depd*depb[i] ;
                0432     if (dbad_phase==99) printf("    %i:[%24.16e *] %24.16e",i,depd,depb[i]) ;
                0433   }
                0434   if (dbad_phase==99) printf("\n") ;
                0435 }
                0436 
                0437 void adContextAdj_concludeComplex16(char* varname, double complex dep, double complex depb) {
                0438   double depdr = dbad_nextRandom() ;
                0439   double depdi = dbad_nextRandom() ;
                0440   dbad_condensed_adj += depdr*creal(depb) + depdi*cimag(depb) ;
                0441   if (dbad_phase==99)
                0442     printf("concludeComplex16 of %s [%24.16e+i%24.16e *]%24.16e+i%24.16e\n", varname, depdr, depdi, creal(depb), cimag(depb)) ;
                0443 }
                0444 
                0445 void adContextAdj_concludeComplex16Array(char* varname, double complex *dep, double complex *depb, int length) {
                0446   int i ;
                0447   double depdr, depdi ;
                0448   if (dbad_phase==99) printf("concludeComplex16Array of %s, length=%i:\n", varname, length) ;
                0449   for (i=0 ; i<length ; ++i) {
                0450     depdr = dbad_nextRandom() ;
                0451     depdi = dbad_nextRandom() ;
                0452     dbad_condensed_adj += depdr*creal(depb[i]) + depdi*cimag(depb[i]) ;
                0453     if (dbad_phase==99) printf("    %i:[%24.16e+i%24.16e *] %24.16e+i%24.16e",i,depdr,depdi,creal(depb[i]),cimag(depb[i])) ;
                0454   }
                0455   if (dbad_phase==99) printf("\n") ;
                0456 }
                0457 
                0458 void adContextAdj_concludeComplex8(char* varname, ccmplx *dep, ccmplx *depb) {
                0459   float depdr = (float)dbad_nextRandom() ;
                0460   float depdi = (float)dbad_nextRandom() ;
                0461   dbad_condensed_adj += depdr*depb->r + depdi*depb->i ;
                0462   if (dbad_phase==99)
                0463     printf("concludeComplex8 of %s [%24.16e+i%24.16e *]%24.16e+i%24.16e\n", varname, depdr, depdi, depb->r, depb->i) ;
                0464 }
                0465 
                0466 void adContextAdj_concludeComplex8Array(char* varname, ccmplx *dep, ccmplx *depb, int length) {
                0467   int i ;
                0468   float depdr, depdi ;
                0469   if (dbad_phase==99) printf("concludeComplex8Array of %s, length=%i:\n", varname, length) ;
                0470   for (i=0 ; i<length ; ++i) {
                0471     depdr = (float)dbad_nextRandom() ;
                0472     depdi = (float)dbad_nextRandom() ;
                0473     dbad_condensed_adj += depdr*depb[i].r + depdi*depb[i].i ;
                0474     if (dbad_phase==99) printf("    %i:[%24.16e+i%24.16e *] %24.16e+i%24.16e",i,depdr,depdi,depb[i].r,depb[i].i) ;
                0475   }
                0476   if (dbad_phase==99) printf("\n") ;
                0477 }
                0478 
                0479 void adContextAdj_conclude() {
                0480   printf("[seed:%7.1e] Condensed adjoint: %24.16e\n", dbad_seed, dbad_condensed_adj) ;
                0481 }
                0482 
                0483 //############## INTERFACE PROCEDURES CALLED FROM FORTRAN ################
                0484 
                0485 void adcontexttgt_init_(double *epsilon, double *seed) {
                0486   adContextTgt_init(*epsilon, *seed) ;
                0487 }
                0488 
                0489 void adcontexttgt_initreal8_(char* varname, double *indep, double *indepd) {
                0490   adContextTgt_initReal8(varname, indep, indepd) ;
                0491 }
                0492 
                0493 void adcontexttgt_initreal8array_(char* varname, double *indep, double *indepd, int *length) {
                0494   adContextTgt_initReal8Array(varname, indep, indepd, *length) ;
                0495 }
                0496 
                0497 void adcontexttgt_initreal4_(char* varname, float *indep, float *indepd) {
                0498   adContextTgt_initReal4(varname, indep, indepd) ;
                0499 }
                0500 
                0501 void adcontexttgt_initreal4array_(char* varname, float *indep, float *indepd, int *length) {
                0502   adContextTgt_initReal4Array(varname, indep, indepd, *length) ;
                0503 }
                0504 
                0505 void adcontexttgt_initcomplex16_(char* varname, cdcmplx *indep, cdcmplx *indepd) {
                0506   adContextTgt_initComplex16(varname, (double complex *)indep, (double complex *)indepd) ;
                0507 }
                0508 
                0509 void adcontexttgt_initcomplex16array_(char* varname, cdcmplx *indep, cdcmplx *indepd, int *length) {
                0510   adContextTgt_initComplex16Array(varname, (double complex *)indep, (double complex *)indepd, *length) ;
                0511 }
                0512 
                0513 void adcontexttgt_initcomplex8_(char* varname, ccmplx *indep, ccmplx *indepd) {
                0514   adContextTgt_initComplex8(varname, indep, indepd) ;
                0515 }
                0516 
                0517 void adcontexttgt_initcomplex8array_(char* varname, ccmplx *indep, ccmplx *indepd, int *length) {
                0518   adContextTgt_initComplex8Array(varname, indep, indepd, *length) ;
                0519 }
                0520 
                0521 void adcontexttgt_startconclude_() {
                0522   adContextTgt_startConclude() ;
                0523 }
                0524 
                0525 void adcontexttgt_concludereal8_(char* varname, double *dep, double *depd) {
                0526   if (dbad_phase==99)
                0527       printf("concludereal8_ of %s: \n", varname);
                0528   adContextTgt_concludeReal8(varname, *dep, *depd) ;
                0529 }
                0530 
                0531 void adcontexttgt_concludereal8array_(char* varname, double *dep, double *depd, int *length) {
                0532   if (dbad_phase==99)
                0533       printf("concludereal8array_ of %s: \n", varname);
                0534   adContextTgt_concludeReal8Array(varname, dep, depd, *length) ;
                0535 }
                0536 
                0537 void adcontexttgt_concludereal4_(char* varname, float *dep, float *depd) {
                0538   adContextTgt_concludeReal4(varname, *dep, *depd) ;
                0539 }
                0540 
                0541 void adcontexttgt_concludereal4array_(char* varname, float *dep, float *depd, int *length) {
                0542   adContextTgt_concludeReal4Array(varname, dep, depd, *length) ;
                0543 }
                0544 
                0545 void adcontexttgt_concludecomplex16_(char* varname, cdcmplx *dep, cdcmplx *depd) {
                0546   adContextTgt_concludeComplex16(varname, *((double complex *)dep), *((double complex *)depd)) ;
                0547 }
                0548 
                0549 void adcontexttgt_concludecomplex16array_(char* varname, cdcmplx *dep, cdcmplx *depd, int *length) {
                0550   adContextTgt_concludeComplex16Array(varname, (double complex *)dep, (double complex *)depd, *length) ;
                0551 }
                0552 
                0553 void adcontexttgt_concludecomplex8_(char* varname, ccmplx *dep, ccmplx *depd) {
                0554   if (dbad_phase==99)
                0555       printf("concludecomplex8_ of %s: \n", varname);
                0556   adContextTgt_concludeComplex8(varname, dep, depd) ;
                0557 }
                0558 
                0559 void adcontexttgt_concludecomplex8array_(char* varname, ccmplx *dep, ccmplx *depd, int *length) {
                0560   if (dbad_phase==99)
                0561       printf("concludecomplex8array_ of %s: \n", varname);
                0562   adContextTgt_concludeComplex8Array(varname, dep, depd, *length) ;
                0563 }
                0564 
                0565 void adcontexttgt_conclude_() {
                0566   adContextTgt_conclude() ;
                0567 }
                0568 
                0569 void adcontextadj_init_(double *seed) {
                0570   adContextAdj_init(*seed) ;
                0571 }
                0572 
                0573 void adcontextadj_initreal8_(char* varname, double *dep, double *depb) {
                0574   if (dbad_phase==99)
                0575     printf("initreal8_ of %s \n", varname) ;
                0576   adContextAdj_initReal8(varname, dep, depb) ;
                0577 }
                0578 
                0579 void adcontextadj_initreal8array_(char* varname, double *dep, double *depb, int *length) {
                0580   if (dbad_phase==99)
                0581     printf("initreal8array_ of %s \n", varname) ;
                0582   adContextAdj_initReal8Array(varname, dep, depb, *length) ;
                0583 }
                0584 
                0585 void adcontextadj_initreal4_(char* varname, float *dep, float *depb) {
                0586   adContextAdj_initReal4(varname, dep, depb) ;
                0587 }
                0588 
                0589 void adcontextadj_initreal4array_(char* varname, float *dep, float *depb, int *length) {
                0590   adContextAdj_initReal4Array(varname, dep, depb, *length) ;
                0591 }
                0592 
                0593 void adcontextadj_initcomplex16_(char* varname, cdcmplx *dep, cdcmplx *depb) {
                0594   adContextAdj_initComplex16(varname, (double complex *)dep, (double complex *)depb) ;
                0595 }
                0596 
                0597 void adcontextadj_initcomplex16array_(char* varname, cdcmplx *dep, cdcmplx *depb, int *length) {
                0598   adContextAdj_initComplex16Array(varname, (double complex *)dep, (double complex *)depb, *length) ;
                0599 }
                0600 
                0601 void adcontextadj_initcomplex8_(char* varname, ccmplx *dep, ccmplx *depb) {
                0602   adContextAdj_initComplex8(varname, dep, depb) ;
                0603 }
                0604 
                0605 void adcontextadj_initcomplex8array_(char* varname, ccmplx *dep, ccmplx *depb, int *length) {
                0606   adContextAdj_initComplex8Array(varname, dep, depb, *length) ;
                0607 }
                0608 
                0609 void adcontextadj_startconclude_() {
                0610   adContextAdj_startConclude() ;
                0611 }
                0612 
                0613 void adcontextadj_concludereal8_(char* varname, double *dep, double *depb) {
                0614   if (dbad_phase==99)
                0615     printf("concludereal8_ of %s \n", varname) ;
                0616   adContextAdj_concludeReal8(varname, *dep, *depb) ;
                0617 }
                0618 
                0619 void adcontextadj_concludereal8array_(char* varname, double *dep, double *depb, int *length) {
                0620   if (dbad_phase==99)
                0621     printf("concludereal8array_ of %s \n", varname) ;
                0622   adContextAdj_concludeReal8Array(varname, dep, depb, *length) ;
                0623 }
                0624 
                0625 void adcontextadj_concludereal4_(char* varname, float *dep, float *depb) {
                0626   if (dbad_phase==99)
                0627     printf("concludereal4_ of %s \n", varname) ;
                0628   adContextAdj_concludeReal4(varname, *dep, *depb) ;
                0629 }
                0630 
                0631 void adcontextadj_concludereal4array_(char* varname, float *dep, float *depb, int *length) {
                0632   if (dbad_phase==99)
                0633     printf("concludereal4array_ of %s \n", varname) ;
                0634   adContextAdj_concludeReal4Array(varname, dep, depb, *length) ;
                0635 }
                0636 
                0637 void adcontextadj_concludecomplex16_(char* varname, cdcmplx *dep, cdcmplx *depb) {
                0638   adContextAdj_concludeComplex16(varname, *((double complex *)dep), *((double complex *)depb)) ;
                0639 }
                0640 
                0641 void adcontextadj_concludecomplex16array_(char* varname, cdcmplx *dep, cdcmplx *depb, int *length) {
                0642   adContextAdj_concludeComplex16Array(varname, (double complex *)dep, (double complex *)depb, *length) ;
                0643 }
                0644 
                0645 void adcontextadj_concludecomplex8_(char* varname, ccmplx *dep, ccmplx *depb) {
                0646   adContextAdj_concludeComplex8(varname, dep, depb) ;
                0647 }
                0648 
                0649 void adcontextadj_concludecomplex8array_(char* varname, ccmplx *dep, ccmplx *depb, int *length) {
                0650   adContextAdj_concludeComplex8Array(varname, dep, depb, *length) ;
                0651 }
                0652 
                0653 void adcontextadj_conclude_() {
                0654   adContextAdj_conclude() ;
                0655 }