ADMB Documentation  11.1.2490
 All Classes Files Functions Variables Typedefs Friends Defines
cmpdif3.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: cmpdif3.cpp 2417 2014-09-26 23:28:32Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include <fvar.hpp>
00012 
00013 #ifdef __TURBOC__
00014   #pragma hdrstop
00015   #include <iostream.h>
00016 #endif
00017 
00018 #ifdef __ZTC__
00019   #include <iostream.hpp>
00020 #endif
00021 
00022 #include <string.h>
00023 
00024 #ifndef OPT_LIB
00025   #define CHK_ID_STRING
00026 #endif
00027 
00028 extern ofstream clogf;
00029 
00034 void report_gradstack_flag(void)
00035 {
00036   verify_identifier_string("stack");
00037   // Back up the stream and read the number of bytes written in the
00038   // ``write function'' corresponding to this ``read function''
00039   int num_bytes;
00040   gradient_structure::get_fp()->fread(&num_bytes,sizeof(int));
00041   char str1[100];
00042   str1[0]='\0';
00043   gradient_structure::get_fp()->fread(str1,num_bytes);
00044   cout << "in report_gradstack_flag  " << str1 << endl;
00045 }
00046 
00047 #if defined(CHK_ID_STRING)
00048 
00052 static void report_gradstack_flag2(void)
00053 {
00054   verify_identifier_string("stack");
00055   // Back up the stream and read the number of bytes written in the
00056   // ``write function'' corresponding to this ``read function''
00057   int num_bytes;
00058   gradient_structure::get_fp()->fread(&num_bytes,sizeof(int));
00059   char str1[100];
00060   str1[0]='\0';
00061   gradient_structure::get_fp()->fread(str1,num_bytes);
00062   int i,j;
00063   gradient_structure::get_fp()->fread(&j,sizeof(int));
00064   gradient_structure::get_fp()->fread(&i,sizeof(int));
00065   cout << "in report_gradstack_flag  " << str1 << endl;
00066   if (i==3 && j==91)
00067     cout << "HERE" << endl;
00068 }
00069 #endif
00070 
00075 void set_gradstack_flag(char* str)
00076 {
00077 #if defined(CHK_ID_STRING)
00078   //int wsize=sizeof(char);
00079   int length=strlen(str);
00080   gradient_structure::get_fp()->fwrite(str,length);
00081   gradient_structure::get_fp()->fwrite(&length,sizeof(int));
00082   gradient_structure::GRAD_STACK1->
00083     set_gradient_stack(report_gradstack_flag);
00084   save_identifier_string("stack");
00085 #endif
00086 }
00087 
00092 void set_gradstack_flag(char* _str,int i,int j)
00093 {
00094 #if defined(CHK_ID_STRING)
00095   adstring ads=_str;
00096   ads+=" ";
00097   ads+=str(i);
00098   ads+=" ";
00099   ads+=str(j);
00100   //int wsize=sizeof(char);
00101   char * str=(char*)(ads);
00102   int length=strlen(str);
00103   gradient_structure::get_fp()->fwrite(&i,sizeof(int));
00104   gradient_structure::get_fp()->fwrite(&j,sizeof(int));
00105   gradient_structure::get_fp()->fwrite(str,length);
00106   gradient_structure::get_fp()->fwrite(&length,sizeof(int));
00107   gradient_structure::GRAD_STACK1->
00108     set_gradient_stack(report_gradstack_flag2);
00109   save_identifier_string("stack");
00110 #endif
00111 }
00112 
00122 void verify_identifier_string(const char* str1)
00123 {
00124 #if defined(CHK_ID_STRING)
00125   // Back up the stream and read the number of bytes written in the
00126   // ``write function'' corresponding to this ``read function''
00127   size_t num_bytes=strlen(str1);
00128   char str[10];
00129   str[num_bytes]='\0';
00130   gradient_structure::get_fp()->fread(str,num_bytes);
00131   //clogf << "in verify_id_string " << str1 << endl;
00132   if(strcmp(str1,str))
00133   {
00134     cerr << "Error reading stack identifer for " << str1 << endl;
00135     ad_exit(1);
00136   }
00137 #endif
00138 }
00139 
00144 adstring get_string_marker(void)
00145 {
00146   adstring str1;
00147 #if defined(CHK_ID_STRING)
00148   // Back up the stream and read the number of bytes written in the
00149   // ``write function'' corresponding to this ``read function''
00150   long int num_bytes=5;
00151   char str[10];
00152   str[num_bytes]='\0';
00153   gradient_structure::get_fp()->fread(str,num_bytes);
00154   //clogf << "in verify_id_string " << str1 << endl;
00155   str1=str;
00156 #endif
00157  return str1;
00158 }
00159 
00164 void ivector::save_ivector_position(void) const
00165 {
00166   // saves the size and address information for a ivector
00167   unsigned wsize=sizeof(ivector_position);
00168   ivector_position tmp(*this);
00169   gradient_structure::get_fp()->fwrite(&tmp,wsize);
00170 }
00171 
00176 void dvar_vector::save_dvar_vector_position(void) const
00177 {
00178   // saves the size and address information for a dvar_vector
00179   unsigned wsize=sizeof(dvar_vector_position);
00180   dvar_vector_position tmp(*this);
00181   gradient_structure::get_fp()->fwrite(&tmp,size_t(wsize));
00182 }
00183 
00188 void save_ad_pointer(void * p)
00189 {
00190   // saves the size and address information for a dvar_vector
00191   unsigned wsize=sizeof(void *);
00192   gradient_structure::get_fp()->fwrite(&p,size_t(wsize));
00193 }
00194 
00199 void * restore_ad_pointer(void)
00200 {
00201   void * p=0;
00202   // saves the size and address information for a dvar_vector
00203   unsigned wsize=sizeof(void *);
00204   gradient_structure::get_fp()->fread(&p,size_t(wsize));
00205   return p;
00206 }