Error: identifier “cout” is undefined

I ran across the following issue when trying to compile my AztecOO source code outside of Trilinous.

example/AztecOO/adapt_main.cpp(94): error: identifier "cout" is undefined
cout << comm << endl;
^
example/AztecOO/adapt_main.cpp(94): error: identifier "endl" is undefined
cout << comm << endl;
^
example/AztecOO/adapt_main.cpp(96): error: identifier "cerr" is undefined
if(argc != 2) cerr << "error: enter name of data file on command line" << endl;

Fix
The compiler doesn’t recognize that these methods come from the standard library. Therefore, I must tell it with the following commands:

using std::cout;
using std::endl;
using std::cerr;

Credit goes to http://stackoverflow.com/questions/13208547/the-includeiostream-exists-but-i-get-an-error-identifier-cout-is-undefine.

AztecOO catastrophic error: cannot open source file “Epetra_Map.h”

A while back I was trying to compile the AztecOO library outside of Trilinous. See this early post for more details. In doing so, I received the following error:

catastrophic error: cannot open source file "Epetra_Map.h"

Solution
Aztec requires quite a few of the additional tilinous header files. I copied a couple addition src directories from trilinous to my Aztec src folder. The list below shows everything I copied into source. I recommend you keep your AztecOO src directory organized and make folders for the external libraries. Also make sure to have correctly included directories with –I in the compile statement to ensure that the compiler looks into the Aztec src directory for the correct files.

Directories I copied:
trilinos-11.10.1-Source/packages/epetra/src
trilinos-11.10.1-Source/packages/teuchos/core/src
trilinos-11.10.1-Source/packages/teuchos/comm/src
trilinos-11.10.1-Source/packages/teuchos/parameterlist /src
trilinos-11.10.1-Source/packages/epetraext/src

Files
trilinos-11.10.1-Source/packages/triutils/src/Trilinos_Util.h
trilinos-11.10.1-Source/packages/triutils/src/Trilinos_Util_ReadMatrixMarket2Epetra.h
trilinos-11.10.1-Source/packages/epetraext/src/inout/EpetraExt_OperatorOut.h
trilinos-11.10.1-Source/packages/epetraext/src/EpetraExt_ConfigDefs.h

I also copied the additional files from the build version of trilinous (these files are generated upon ‘make’ in Trilinous).

trilinos.build/packages/epetra/src/Epetra_config.h
trilinos.build/packages/epetra/src/Epetra_DLLExportMacro.h
trilinos.build>/packages/teuchos/core/src/Teuchos_config.h
trilinos.build/Trilinos_version.h
trilinos.build/packages/triutils/src/Triutils_config.h
trilinos.build/packages/teuchos/core/src/Teuchos_config.h

I also had to remove some directories
aztecoo/example

Catastrophic error: cannot open source file

A while back I was trying to compile the AztecOO library outside of Trilinous. See this early post for more details. In doing so, I received the following error:

catastrophic error: cannot open source file "az_aztec.h"

Solution
This was a simple oversight on my part. To fix this, I added –I./src to the compile statement to make sure it looked in the Aztec src directory for header files, etc. Same goes for anyone experiencing a similar error.

AztecOO: error: identifier “sswap_” is undefined

Error
I’ve been trying to compile the AztecOO library outside of Trilinous. In doing so, I pulled the package Aztec source code from the Trilinous source code and opted to write my own Makefile to then compile it. My Makefile included the same settings reported in the Trilinous Makefile.export.AztecOO file.

To prepare this build, I needed to fetch the AztecOO_config.h file from a built version of Trilinous and place it in the source directory of the Aztec directory I was compiling (this file is generated upon ‘make’ in Trilinous). With that in place, I had the files I needed to compile Aztec, however, I ran into the following error.

error: identifier "sswap_" is undefined

Solution
SWAP_F77 is a defined module that points to the F77_BLAS_MANGLE module at the top of az_c_util.c. This second module is defined in AztecOO_config.h. All this module does, is add a “_” to the end of the name provided in the parameters and defines it with the provided value. This works when you are using the Fortran Blas library, but I am using the C version. To fix this, I edited all F77 functions in the AztecOO_config.h file to just return “name” instead of “name ## _”.

I also added this include statement to the file that errors src/az_c_util.c which required that I add –I to the compile statement in order for the compiler to find the right header files.

#include "mkl_blas.h"

Python URL Term Scrapper (Kind of Like a Very Dumb/Simple Watson)

I wrote this a while back to scrape a given URL page for all links it contains and then search those links for term relations. The Python scrapper first finds all links in a given url. It then searches all the links found for a list of search terms provided. It will return stats on the number of times specific provided terms show up.

This may come in handy while trying to find more information on a given topic. I’ve used it on Google searches (be careful, you can only scrape google once ever 8 or so seconds before you are locked out) and wikipedia pages to gather correlation statistics between topics.

It is old code… so there might be some errors. Keep me posted!

#!/usr/bin/env python
#ENSURE permissions are 755 in order to have script run as executable

import os, sys, re, datetime
from optparse import OptionParser
import logging, urllib2

def parsePage(link, list):
    searchList = {}
    try:
        f = urllib2.urlopen(link)
        data = f.read()
        for item in list:
            if (item.title() in data) or (item.upper() in data) or (item.lower() in data):
                searchList[item]=searchList[item]+1
                searchList["count"]=searchList["count"]+1
        return searchList
    except Exception, e:
        print "An error has occurred while parsing page " +str(link)+"."
        log.error(str(datetime.datetime.now())+" "+str(e))

def searchUrl(search):
    try:
        f = urllib2.urlopen(search)
        data = f.read()
        pattern = r"/wiki(/\S*)?$" #regular expression to find url
        links = re.findall(pattern, data)
        return links
    except Exception, e:
        print "An error has occurred while trying to reach the site."
        log.error(str(datetime.datetime.now())+" "+str(e))

def main():
    try:
        parser = OptionParser() #Help menu options
        parser.add_option("-u", "--url", dest="search", help="String containing URL to search.")
        parser.add_option("-f", "--file", dest="file", help="File containing search terms.")
        (options, args) = parser.parse_args()
        if not options.search or not options.file:
            parser.error('Term file or URL to scrape not given')
        else:
            urls = searchUrl(options.search)
            f = open(options.file, 'r')
            terms = f.readlines()
            for url in urls:
                parsePage(url, terms)
            print "Results:"
            print searchList
    except Exception, e:
        log.error(str(datetime.datetime.now())+" "+str(e))

if __name__ == "__main__":
    log = logging.getLogger("error") #create error log
    log.setLevel(logging.ERROR)
    formatter = logging.Formatter('[%(levelname)s] %(message)s')
    handler = logging.FileHandler('error.log')
    handler.setFormatter(formatter)
    log.addHandler(handler)
    try:
        main()
    except Exception, e:
        print "An error has occurred, please review the error.log for more details."
        log.error(str(datetime.datetime.now())+" "+str(e))

Creating a Sharepoint ‘Like’ through SOAP Requests

Sharepoint is not my most favorite environment to program in but I figure I’d share a cool javascript app I put together that communicates with Sharepoint’s SOAP API to add on to custom ‘like’ buttons (just like facebook!) With this feature, users can ‘like’ sharepoint items without going through the crazy sharepoint interface. This javascript can be added to a web interface, and users can ‘like’ items from there!

None of this garbage
None of this garbage

I wrote some javascript/jquery code that can easily retrieve the number of ‘likes’ for a sharepoint list item or list. The script basically queries Sharepoint’s built in social services for the tag count with SOAP POST calls.

Get Like Count

Here is the script to get ‘like’ count:


<script>

function GetLikeCountFromService(strURL) {

var count = 0;

//change the webMethod var to match up to the correct sharepoint _vti_bin location. (https://msdn.microsoft.com/en-us/library/office/Bb862916(v=office.12).aspx)

var webMethod = \'/_vti_bin/SocialDataService.asmx?op=GetTagTermsOnUrl\';

var soapEnv = "<soap:Envelope xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\' xmlns:xsd=\'http://www.w3.org/2001/XMLSchema\' xmlns:soap=\'http://schemas.xmlsoap.org/soap/envelope/\'> <soap:Body><GetTagTermsOnUrl xmlns=\'http://microsoft.com/webservices/SharePointPortalServer/SocialDataService\'> <url>" + strURL + "</url> <maximumItemsToReturn>1</maximumItemsToReturn> </GetTagTermsOnUrl> </soap:Body> </soap:Envelope>";



$.ajax({

type: "POST",

async: true,

url: webMethod,

data: soapEnv,

contentType: "text/xml; charset=utf-8",

dataType: "xml",

success: function(data, textStatus, XMLHttpRequest) {

count  = $(\'SocialTermDetail\', data).find(\'Count\').text();

}

});

return count;

}

</script>

Called by: GetLikeCountFromService(‘<LIST OR LIST ITEM URL>’)

Example: GetLikeCountFromService(‘http://mysharepoint/list/item’)

Here is the script to post ‘likes’ to an article. Once again it’s a nice javascript that can put into an HTML header or what not.

Emulate a ‘like’

Script to post a ‘like’:


function AddLikeCountFromService(strURL) {

//change the webMethod var to match up to the correct sharepoint _vti_bin location. (https://msdn.microsoft.com/en-us/library/office/Bb862916(v=office.12).aspx)

var webMethod = \'/_vti_bin/SocialDataService.asmx?op=GetAllTagTermsForUrlFolder\';

var soapEnv = "<soap:Envelope xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\' xmlns:xsd=\'http://www.w3.org/2001/XMLSchema\' xmlns:soap=\'http://schemas.xmlsoap.org/soap/envelope/\'><soap:Body><GetAllTagTermsForUrlFolder xmlns=\'http://microsoft.com/webservices/SharePointPortalServer/SocialDataService\'><urlFolder>"+strURL+"</urlFolder><maximumItemsToReturn>1</maximumItemsToReturn></GetAllTagTermsForUrlFolder></soap:Body></soap:Envelope>";

$.ajax({

type: "POST",

async: true,

url: webMethod,

data: soapEnv,

contentType: "text/xml; charset=utf-8",

dataType: "xml",

success: function(data, textStatus, XMLHttpRequest) {

var info  = ($(\'SocialTermDetail\', data).text()).split(" ");

var guid = (info[0]).substring(0, info[0].length - 1);

//change the webMethod var to match up to the correct sharepoint _vti_bin location. (https://msdn.microsoft.com/en-us/library/office/Bb862916(v=office.12).aspx)

webMethod = \'/_vti_bin/SocialDataService.asmx?op=AddTag\';

//In the soapEnv request, you can change the title field to anything. This is the title of the thing the user is liking.

soapEnv = "<soap:Envelope xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\' xmlns:xsd=\'http://www.w3.org/2001/XMLSchema\' xmlns:soap=\'http://schemas.xmlsoap.org/soap/envelope/\'> <soap:Body><AddTag xmlns=\'http://microsoft.com/webservices/SharePointPortalServer/SocialDataService\'><url>"+strURL+"</url><termID>"+guid+"</termID><title>I like it!</title><isPrivate>false</isPrivate></AddTag></soap:Body> </soap:Envelope>";

$.ajax({

type: "POST",

async: true,

url: webMethod,

data: soapEnv,

contentType: "text/xml; charset=utf-8",

dataType: "xml",

success: function(data, textStatus, XMLHttpRequest) {

}

});

}

});

Called By:

Example: AddLikeCountFromService(‘<LIST OR LIST ITEM URL>’)

AddLikeCountFromService(‘http://mysharepoint/list/item’)

Python TypeError: expected a character buffer object

Error

I received the following python error:

TypeError: expected a character buffer object

The below screenshot shows my code.

Python Error

Solution

I was using the replace method, while the better method for my situation would be to use the re.sub(patter, replace, string) method, the new line became:

my_text = re.sub(comp, '#undef SEEK_SET\n#undef SEEK_END\n
#undef SEEK_CUR\n#include ', f)

The replace method expects string parameters (looks for a string within a string), while I wanted to use a regular expression to search a string.

IIS 7.5 WCF Error: Could not find a base address that matches…

Error

I received the following error while trying to run a WCF application built in Visual Studio 2013 running on a Windows 8 IIS 7.5 server.

Could not find a base address that matches scheme http for 
the endpoint with binding MetadataExchangeHttpBinding. 
Registered base address schemes are [https].

IIS Error

Solution

In this instance, my mex statement was wrong, I needed to make it mexHttpsBinding instead of mexHttpBinding. For other cases, double check that your bindings are correct. I was converting everything to HTTPS and had forgotten to change the mex binding to reflect the change.

<endpoint address="mex" binding="mexHttpsBinding" 
contract="IMetadataExchange" />

IIS 7.5 WCF Error: The … does not have a Binding with the None MessageVersion.

Error

I received the following error while trying to run a WCF application built in Visual Studio 2013 running on a Windows 8 IIS 7.5 server.

The … does not have a Binding with the None MessageVersion. ‘System.ServiceModel.Description.WebHttpBehavior’ is only intended for use with WebHttpBinding or similar bindings.

Solution

With help from http://msdn.microsoft.com/en-us/library/hh556232(v=vs.110).aspx and http://stackoverflow.com/questions/7585363/why-does-my-wcf-service-give-the-message-does-not-have-a-binding-with-the-none, I edited my web.config file and added/changed it to include the bolded text. Basically, I was confusing SOAP and REST calls. The below is utilized for REST only, SOAP requires the basicHttpBindings.


<system.serviceModel>
<services>
<service name="XOM.REIT.CNC.ClusterNotificationCenter" behaviorConfiguration="DefaultBehavior">
        <endpoint address="" binding="webHttpBinding" bindingConfiguration="secureHttpBinding" contract="XOM.REIT.CNC.IClusterNotificationCenter" behaviorConfiguration="DefaultEndpointBehavior"/>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="https://localhost:30022/"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
      <webHttpBinding>
        <binding name="secureHttpBinding">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultBehavior">
            <serviceMetadata httpsGetEnabled="true"/>
            <serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="DefaultEndpointBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>